import classNames from 'classnames' import React from 'react' import { File, types, Text, RichText } from 'react-bricks/rsc' //import blockNames from '../blockNames' import { AiOutlineFileAdd } from 'react-icons/ai' import { FcDocument } from 'react-icons/fc' import blockNames from '../blockNames' export interface DocumentProps { color?: { color: string; className: string } withSize?: boolean file: types.IFileSource fileName: types.TextValue fileDescription: types.TextValue linkText: types.TextValue } const formatFileSize = (bytes: number) => { if (!bytes) return '' if (bytes < 1) { return `${bytes.toFixed(1)} B` } if (bytes < 1024) { return `${bytes.toFixed(0)} B` } else { return `${(bytes / 1024).toFixed(0)} KB` } } const Document: types.Brick = ({ withSize, file, fileName, fileDescription, linkText, }) => { return (
{ return file ? (
(
{props.children}
)} /> (
{props.children}
)} placeholder="File description..." /> ( {props.children} )} placeholder="" /> {withSize && !!file.size && ( {formatFileSize(file.size)} )}
) : (
Add document
) }} />
) } Document.schema = { name: blockNames.Document, label: 'Document', category: 'documents', hideFromAddMenu: true, playgroundLinkLabel: 'View source code on Github', playgroundLinkUrl: 'https://github.com/ReactBricks/reactbricks-starters/blob/main/packages/reactbricks-ui/nextjs-app/src/Documents/Document.tsx', getDefaultProps: () => ({ fileName: 'Document name', fileDescription: 'Description of this document', linkText: 'Download now', withSize: true, }), sideEditProps: [ { name: 'withSize', label: 'Show document size', type: types.SideEditPropType.Boolean, }, { name: 'fileName', label: 'file name', type: types.SideEditPropType.Text }, { name: 'fileDescription', label: 'File description', type: types.SideEditPropType.Textarea, }, { name: 'linkText', label: 'Link text', type: types.SideEditPropType.Text }, ], } export default Document