diff --git a/modules/masonry/src/brick/design0/components/BrickBlock.tsx b/modules/masonry/src/brick/design0/components/BrickBlock.tsx index 4fa2f1e4..7f81d1d7 100644 --- a/modules/masonry/src/brick/design0/components/BrickBlock.tsx +++ b/modules/masonry/src/brick/design0/components/BrickBlock.tsx @@ -1,46 +1,55 @@ import React from 'react'; -import type { IBrickBlock } from '@/@types/brick'; +import type { TBrickRenderPropsBlock, TCoords } from '@/@types/brick'; -/** - * Props for BrickBlock component. - */ interface BrickBlockProps { - instance: IBrickBlock; + instance: TBrickRenderPropsBlock; + coords?: TCoords; } -/** - * Component to render a BrickBlock. - * @param props - The props for BrickBlock. - * @returns JSX.Element representing the BrickBlock as an SVG. - */ -const BrickBlockComponent: React.FC = ({ instance }) => { - const renderProps = instance.renderProps(); - const { path: SVGpath, label, glyph, colorBg, colorFg, outline, scale } = renderProps; - +const BrickBlock: React.FC = ({ instance, coords = { x: 0, y: 0 } }) => { return ( - + - {glyph && ( - - {glyph} + + {instance.label} + + {instance.labelArgs.map((argLabel, index) => ( + + {argLabel} - )} - {label && ( - - {label} + ))} + {instance.glyph && ( + + {instance.glyph} )} ); }; -export default BrickBlockComponent; +export default BrickBlock; diff --git a/modules/masonry/src/brick/design0/components/BrickData.tsx b/modules/masonry/src/brick/design0/components/BrickData.tsx index d9d362a6..05da3db0 100644 --- a/modules/masonry/src/brick/design0/components/BrickData.tsx +++ b/modules/masonry/src/brick/design0/components/BrickData.tsx @@ -1,46 +1,43 @@ import React from 'react'; -import type { IBrickData } from '@/@types/brick'; +import type { TBrickRenderPropsData, TCoords } from '@/@types/brick'; -/** - * Props for BrickData component. - */ interface BrickDataProps { - instance: IBrickData; // The instance of BrickData + instance: TBrickRenderPropsData; + coords?: TCoords; } -/** - * Component to render a BrickData. - * @param props - The props for BrickData. - * @returns JSX.Element representing the BrickData as an SVG. - */ -const BrickDataComponent: React.FC = ({ instance }) => { - const renderProps = instance.renderProps(); - const { path: SVGpath, label, glyph, colorBg, colorFg, outline, scale } = renderProps; - +const BrickData: React.FC = ({ instance, coords = { x: 0, y: 0 } }) => { return ( - + - {glyph && ( - - {glyph} - - )} - {label && ( - - {label} + + {instance.label} + + {instance.glyph && ( + + {instance.glyph} )} ); }; -export default BrickDataComponent; +export default BrickData; diff --git a/modules/masonry/src/brick/design0/components/BrickExpression.tsx b/modules/masonry/src/brick/design0/components/BrickExpression.tsx index 948bca67..6fd659ae 100644 --- a/modules/masonry/src/brick/design0/components/BrickExpression.tsx +++ b/modules/masonry/src/brick/design0/components/BrickExpression.tsx @@ -1,46 +1,55 @@ import React from 'react'; -import type { IBrickExpression } from '@/@types/brick'; +import type { TBrickRenderPropsExpression, TCoords } from '@/@types/brick'; -/** - * Props for BrickExpression component. - */ interface BrickExpressionProps { - instance: IBrickExpression; + instance: TBrickRenderPropsExpression; + coords?: TCoords; } -/** - * Component to render a BrickExpression. - * @param props - The props for BrickExpression. - * @returns JSX.Element representing the BrickExpression as an SVG. - */ -const BrickExpressionComponent: React.FC = ({ instance }) => { - const renderProps = instance.renderProps(); - const { path: SVGpath, label, glyph, colorBg, colorFg, outline, scale } = renderProps; - +const BrickExpression: React.FC = ({ instance, coords = { x: 0, y: 0 } }) => { return ( - + - {glyph && ( - - {glyph} + + {instance.label} + + {instance.labelArgs.map((argLabel, index) => ( + + {argLabel} - )} - {label && ( - - {label} + ))} + {instance.glyph && ( + + {instance.glyph} )} ); }; -export default BrickExpressionComponent; +export default BrickExpression; diff --git a/modules/masonry/src/brick/design0/components/BrickStatement.tsx b/modules/masonry/src/brick/design0/components/BrickStatement.tsx index 49127520..f1595297 100644 --- a/modules/masonry/src/brick/design0/components/BrickStatement.tsx +++ b/modules/masonry/src/brick/design0/components/BrickStatement.tsx @@ -1,46 +1,55 @@ import React from 'react'; -import type { IBrickStatement } from '@/@types/brick'; +import type { TBrickRenderPropsStatement, TCoords } from '@/@types/brick'; -/** - * Props for BrickStatement component. - */ interface BrickStatementProps { - instance: IBrickStatement; + instance: TBrickRenderPropsStatement; + coords?: TCoords; } -/** - * Component to render a BrickStatement. - * @param props - The props for BrickStatement. - * @returns JSX.Element representing the BrickStatement as an SVG. - */ -const BrickStatementComponent: React.FC = ({ instance }) => { - const renderProps = instance.renderProps(); - const { path: SVGpath, label, glyph, colorBg, colorFg, outline, scale } = renderProps; - +const BrickStatement: React.FC = ({ instance, coords = { x: 0, y: 0 } }) => { return ( - + - {glyph && ( - - {glyph} + + {instance.label} + + {instance.labelArgs.map((argLabel, index) => ( + + {argLabel} - )} - {label && ( - - {label} + ))} + {instance.glyph && ( + + {instance.glyph} )} ); }; -export default BrickStatementComponent; +export default BrickStatement; diff --git a/modules/masonry/src/brick/design0/components/BrickWrapper.tsx b/modules/masonry/src/brick/design0/components/BrickWrapper.tsx index 7ba02052..3a1a0425 100644 --- a/modules/masonry/src/brick/design0/components/BrickWrapper.tsx +++ b/modules/masonry/src/brick/design0/components/BrickWrapper.tsx @@ -5,162 +5,98 @@ import { createBrickExpression, createBrickStatement, } from '../brickFactory'; -import BrickDataComponent from './BrickData'; import BrickBlockComponent from './BrickBlock'; +import BrickDataComponent from './BrickData'; import BrickExpressionComponent from './BrickExpression'; import BrickStatementComponent from './BrickStatement'; -import type { TColor } from '@/@types/brick'; +import type { + TBrickRenderPropsBlock, + TBrickRenderPropsData, + TBrickRenderPropsExpression, + TBrickRenderPropsStatement, + TCoords, +} from '@/@types/brick'; -type BrickType = 'block' | 'data' | 'expression' | 'statement'; +type TBrickWrapperProps = + | { type: 'block'; params: TBrickRenderPropsBlock; coords?: TCoords } + | { type: 'data'; params: TBrickRenderPropsData; coords?: TCoords } + | { type: 'expression'; params: TBrickRenderPropsExpression; coords?: TCoords } + | { type: 'statement'; params: TBrickRenderPropsStatement; coords?: TCoords }; -interface BrickWrapperProps { - type: BrickType; - params: - | { - name: string; - label: string; - glyph: string; - args: { id: string; label: string }[]; - colorBg: TColor; - colorFg: TColor; - colorBgHighlight: TColor; - colorFgHighlight: TColor; - outline: TColor; - scale: number; - connectAbove: boolean; - connectBelow: boolean; - nestLengthY: number; - folded?: boolean; - } - | { - name: string; - label: string; - glyph: string; - dynamic: boolean; - value?: boolean | number | string; - input?: 'boolean' | 'number' | 'string' | 'options'; - colorBg: TColor; - colorFg: TColor; - colorBgHighlight: TColor; - colorFgHighlight: TColor; - outline: TColor; - scale: number; - } - | { - name: string; - label: string; - glyph: string; - args: Record; - colorBg: TColor; - colorFg: TColor; - colorBgHighlight: TColor; - colorFgHighlight: TColor; - outline: TColor; - scale: number; - } - | { - name: string; - label: string; - glyph: string; - args: Record; - colorBg: TColor; - colorFg: TColor; - colorBgHighlight: TColor; - colorFgHighlight: TColor; - outline: TColor; - scale: number; - connectAbove: boolean; - connectBelow: boolean; - }; -} - -/** - * Higher-order component to wrap different brick components. - * @param props - The props for BrickWrapper. - * @returns JSX.Element representing the specific brick component. - */ -const BrickWrapper: React.FC = ({ type, params }) => { +const BrickWrapper: React.FC = ({ type, params, coords }) => { switch (type) { case 'block': { - const instance = createBrickBlock( - params as { - name: string; - label: string; - glyph: string; - args: { id: string; label: string }[]; - colorBg: TColor; - colorFg: TColor; - colorBgHighlight: TColor; - colorFgHighlight: TColor; - outline: TColor; - scale: number; - connectAbove: boolean; - connectBelow: boolean; - nestLengthY: number; - folded?: boolean; - }, - ); - return ; + const instance = createBrickBlock({ + name: params.label, + label: params.label, + glyph: params.glyph || '', + args: params.labelArgs.map((label, index) => ({ id: `arg${index}`, label })), + colorBg: params.colorBg, + colorFg: params.colorFg, + colorBgHighlight: params.colorBg, + colorFgHighlight: params.colorFg, + outline: params.outline, + scale: params.scale, + connectAbove: true, + connectBelow: true, + nestLengthY: 0, + folded: params.folded, + }); + return ; } - case 'data': { - const instance = createBrickData( - params as { - name: string; - label: string; - glyph: string; - dynamic: boolean; - value?: boolean | number | string; - input?: 'boolean' | 'number' | 'string' | 'options'; - colorBg: TColor; - colorFg: TColor; - colorBgHighlight: TColor; - colorFgHighlight: TColor; - outline: TColor; - scale: number; - }, - ); - return ; + const instance = createBrickData({ + name: params.label, + label: params.label, + glyph: params.glyph || '', + dynamic: true, + colorBg: params.colorBg, + colorFg: params.colorFg, + colorBgHighlight: params.colorBg, + colorFgHighlight: params.colorFg, + outline: params.outline, + scale: params.scale, + }); + return ; } - case 'expression': { - const instance = createBrickExpression( - params as { - name: string; - label: string; - glyph: string; - args: Record; - colorBg: TColor; - colorFg: TColor; - colorBgHighlight: TColor; - colorFgHighlight: TColor; - outline: TColor; - scale: number; - }, - ); - return ; + const instance = createBrickExpression({ + name: params.label, + label: params.label, + glyph: params.glyph || '', + args: params.labelArgs.reduce((acc, label, index) => { + acc[`arg${index}`] = { label, dataType: 'unknown', meta: {} }; + return acc; + }, {} as Record), + colorBg: params.colorBg, + colorFg: params.colorFg, + colorBgHighlight: params.colorBg, + colorFgHighlight: params.colorFg, + outline: params.outline, + scale: params.scale, + }); + return ; } - case 'statement': { - const instance = createBrickStatement( - params as { - name: string; - label: string; - glyph: string; - args: Record; - colorBg: TColor; - colorFg: TColor; - colorBgHighlight: TColor; - colorFgHighlight: TColor; - outline: TColor; - scale: number; - connectAbove: boolean; - connectBelow: boolean; - }, - ); - return ; + const instance = createBrickStatement({ + name: params.label, + label: params.label, + glyph: params.glyph || '', + args: params.labelArgs.reduce((acc, label, index) => { + acc[`arg${index}`] = { label, dataType: 'unknown', meta: {} }; + return acc; + }, {} as Record), + colorBg: params.colorBg, + colorFg: params.colorFg, + colorBgHighlight: params.colorBg, + colorFgHighlight: params.colorFg, + outline: params.outline, + scale: params.scale, + connectAbove: true, + connectBelow: true, + }); + return ; } - default: return null; }