-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(masonry): [block] modify React component and Storybook stories
- Loading branch information
1 parent
dfd5501
commit 54a2598
Showing
5 changed files
with
104 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 69 additions & 69 deletions
138
modules/masonry/src/brick/stories/components/BrickBlock.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,122 +1,122 @@ | ||
import BrickWrapper from './BrickWrapper'; | ||
import type { JSX } from 'react'; | ||
import type { IBrickBlock, TBrickArgDataType, TBrickColor } from '@/@types/brick'; | ||
import type { IBrickBlock, TBrickRenderPropsBlock, TColor } from '@/@types/brick'; | ||
|
||
import BrickWrapper from './BrickWrapper'; | ||
|
||
// ------------------------------------------------------------------------------------------------- | ||
|
||
export default function (props: { | ||
Component: (props: { instance: IBrickBlock; visualIndicators?: JSX.Element }) => JSX.Element; | ||
prototype: new (params: { | ||
View: React.FC<TBrickRenderPropsBlock>; | ||
Model: new (params: { | ||
uuid: string; | ||
name: string; | ||
|
||
label: string; | ||
glyph: string; | ||
args: Record< | ||
string, | ||
{ | ||
label: string; | ||
dataType: TBrickArgDataType; | ||
meta: unknown; | ||
} | ||
>; | ||
colorBg: TBrickColor; | ||
colorFg: TBrickColor; | ||
outline: TBrickColor; | ||
scale: number; | ||
glyph?: string; | ||
colorBg: TColor; | ||
colorFg: TColor; | ||
colorBgHighlight: TColor; | ||
colorFgHighlight: TColor; | ||
outline: TColor; | ||
connectAbove: boolean; | ||
connectBelow: boolean; | ||
|
||
args: { | ||
/** unique identifier of the argument */ | ||
id: string; | ||
/** label for the argument */ | ||
label: string; | ||
}[]; | ||
}) => IBrickBlock; | ||
showIndicators: boolean; | ||
|
||
label: string; | ||
args: string[]; | ||
colorBg: string; | ||
colorFg: string; | ||
outline: string; | ||
scale: number; | ||
}): JSX.Element { | ||
const { Component, prototype, label, args, colorBg, colorFg, outline, scale } = props; | ||
const { View, Model, showIndicators, label, args, colorBg, colorFg, outline, scale } = props; | ||
|
||
const instance = new Model({ | ||
uuid: '', | ||
name: '', | ||
|
||
const instance = new prototype({ | ||
label, | ||
args: Object.fromEntries( | ||
args.map<[string, { label: string; dataType: TBrickArgDataType; meta: unknown }]>((name) => [ | ||
name, | ||
{ label: name, dataType: 'any', meta: undefined }, | ||
]), | ||
), | ||
colorBg, | ||
colorFg, | ||
colorBgHighlight: '', | ||
colorFgHighlight: '', | ||
outline, | ||
scale, | ||
glyph: '', | ||
connectAbove: true, | ||
connectBelow: true, | ||
name: '', | ||
|
||
args: args.map((label, i) => ({ id: `label_${i}`, label })), | ||
}); | ||
|
||
instance.scale = scale; | ||
|
||
const VisualIndicators = () => ( | ||
<> | ||
{/* Overall Bounding Box of the Brick */} | ||
<rect | ||
x={instance.bBoxBrick.coords.x} | ||
y={instance.bBoxBrick.coords.y} | ||
height={instance.bBoxBrick.extent.height} | ||
width={instance.bBoxBrick.extent.width} | ||
x={0} | ||
y={0} | ||
height={instance.boundingBox.height} | ||
width={instance.boundingBox.width} | ||
fill="black" | ||
opacity={0.25} | ||
/> | ||
|
||
{/* Right args bounding box */} | ||
{Object.keys(instance.bBoxArgs).map((name, i) => { | ||
const arg = instance.bBoxArgs[name]; | ||
|
||
return ( | ||
<rect | ||
key={i} | ||
x={arg.coords.x} | ||
y={arg.coords.y} | ||
height={arg.extent.height} | ||
width={arg.extent.width} | ||
fill="green" | ||
opacity={0.8} | ||
/> | ||
); | ||
})} | ||
|
||
{/* Top instruction notch bounding box */} | ||
{/* Connection point of Top */} | ||
<rect | ||
x={instance.bBoxNotchInsTop.coords.x} | ||
y={instance.bBoxNotchInsTop.coords.y} | ||
height={instance.bBoxNotchInsTop.extent.height} | ||
width={instance.bBoxNotchInsTop.extent.width} | ||
x={instance.connPointsFixed.insTop.coords.y} | ||
y={instance.connPointsFixed.insTop.coords.y} | ||
height={instance.connPointsFixed.insTop.extent.height} | ||
width={instance.connPointsFixed.insTop.extent.width} | ||
fill="green" | ||
opacity={0.9} | ||
opacity={0.75} | ||
/> | ||
|
||
{/* Bottom instruction notch bounding box */} | ||
{/* Connection point of Bottom */} | ||
<rect | ||
x={instance.bBoxNotchInsBot.coords.x} | ||
y={instance.bBoxNotchInsBot.coords.y} | ||
height={instance.bBoxNotchInsBot.extent.height} | ||
width={instance.bBoxNotchInsBot.extent.width} | ||
x={instance.connPointsFixed.insBottom.coords.y} | ||
y={instance.connPointsFixed.insBottom.coords.y} | ||
height={instance.connPointsFixed.insBottom.extent.height} | ||
width={instance.connPointsFixed.insBottom.extent.width} | ||
fill="green" | ||
opacity={0.9} | ||
opacity={0.75} | ||
/> | ||
|
||
{/* Top instruction notch inside nesting bounding box */} | ||
{/* Connection point of Nesting */} | ||
<rect | ||
x={instance.bBoxNotchInsNestTop.coords.x} | ||
y={instance.bBoxNotchInsNestTop.coords.y} | ||
height={instance.bBoxNotchInsNestTop.extent.height} | ||
width={instance.bBoxNotchInsNestTop.extent.width} | ||
x={instance.connPointsFixed.insNest.coords.y} | ||
y={instance.connPointsFixed.insNest.coords.y} | ||
height={instance.connPointsFixed.insNest.extent.height} | ||
width={instance.connPointsFixed.insNest.extent.width} | ||
fill="green" | ||
opacity={0.9} | ||
opacity={0.75} | ||
/> | ||
|
||
{/* Connection points of Args */} | ||
{Object.values(instance.connPointsArg).map(({ extent, coords }) => ( | ||
<rect | ||
x={coords.y} | ||
y={coords.y} | ||
height={extent.height} | ||
width={extent.width} | ||
fill="purple" | ||
opacity={0.75} | ||
/> | ||
))} | ||
</> | ||
); | ||
|
||
return ( | ||
<BrickWrapper> | ||
<Component instance={instance} /> | ||
<VisualIndicators /> | ||
<View {...instance.renderProps} /> | ||
{showIndicators && <VisualIndicators />} | ||
</BrickWrapper> | ||
); | ||
} |