|
1 |
| -import React from 'react'; |
2 |
| -import type { Meta, StoryFn } from '@storybook/react'; |
3 |
| -import CompoundBrickView, { CompoundBrickViewProps } from '../components/compound'; |
4 |
| -import type { TColor, TExtent, TVisualState } from '../../@types/brick'; |
| 1 | +// src/masonry/view/CompoundBrickView.stories.tsx |
5 | 2 |
|
6 |
| -const VISUAL_STATES = [ |
7 |
| - 'default', |
8 |
| - 'hovered', |
9 |
| - 'selected', |
10 |
| - 'executing', |
11 |
| - 'unconnected', |
12 |
| - 'dragged', |
13 |
| -] as TVisualState[]; |
| 3 | +import React from 'react'; |
| 4 | +import type { Meta, StoryObj, Decorator } from '@storybook/react'; |
| 5 | +import { CompoundBrickView } from '../components/compound'; |
| 6 | +import type { TBrickRenderPropsCompound } from '../../@types/brick'; |
14 | 7 |
|
15 |
| -const centerDecorator = (Story: any) => ( |
| 8 | +const centerDecorator: Decorator<TBrickRenderPropsCompound> = (Story) => ( |
16 | 9 | <div style={{ display: 'flex', justifyContent: 'center', padding: '2rem' }}>
|
17 | 10 | <Story />
|
18 | 11 | </div>
|
19 | 12 | );
|
20 | 13 |
|
21 |
| -export default { |
| 14 | +const meta: Meta<TBrickRenderPropsCompound> = { |
22 | 15 | title: 'Bricks/CompoundBrick',
|
23 | 16 | component: CompoundBrickView,
|
24 | 17 | decorators: [centerDecorator],
|
25 |
| - |
26 | 18 | argTypes: {
|
27 |
| - // plumbing |
28 |
| - uuid: { table: { disable: true } }, |
29 |
| - name: { table: { disable: true } }, |
30 |
| - x: { table: { disable: true } }, |
31 |
| - y: { table: { disable: true } }, |
32 |
| - onClick: { table: { disable: true } }, |
33 |
| - |
34 |
| - // shared props |
35 | 19 | label: { control: 'text' },
|
36 |
| - labelType: { control: 'select', options: ['text', 'glyph', 'icon', 'thumbnail'] }, |
37 | 20 | colorBg: { control: 'color' },
|
38 | 21 | colorFg: { control: 'color' },
|
39 | 22 | strokeColor: { control: 'color' },
|
40 |
| - shadow: { control: 'boolean' }, |
41 |
| - isHighlighted: { name: 'Highlighted', control: 'boolean' }, |
| 23 | + strokeWidth: { control: { type: 'number', min: 0, max: 10, step: 1 } }, |
42 | 24 | scale: { control: { type: 'number', min: 0.1, max: 3, step: 0.1 } },
|
| 25 | + shadow: { control: 'boolean' }, |
43 | 26 | tooltip: { control: 'text' },
|
| 27 | + topNotch: { control: 'boolean' }, |
| 28 | + bottomNotch: { control: 'boolean' }, |
| 29 | + isFolded: { control: 'boolean' }, |
| 30 | + bboxArgs: { control: 'object' }, |
| 31 | + bboxNest: { control: 'object' }, |
44 | 32 |
|
45 |
| - // connectors |
46 |
| - topNotch: { name: 'Top Notch', control: 'boolean' }, |
47 |
| - bottomNotch: { name: 'Bottom Notch', control: 'boolean' }, |
48 |
| - |
49 |
| - // argument-slot boxes |
50 |
| - bboxArgs: { |
51 |
| - name: 'Arg Bounding Boxes', |
52 |
| - description: 'Array of { w, h } for each argument slot', |
53 |
| - control: 'object', |
54 |
| - }, |
55 |
| - |
56 |
| - // nesting-area boxes |
57 |
| - bboxNest: { |
58 |
| - name: 'Nest Bounding Boxes', |
59 |
| - description: 'Array of { w, h } for nested content area', |
60 |
| - control: 'object', |
61 |
| - }, |
62 |
| - |
63 |
| - // visual flags |
64 |
| - visualState: { |
65 |
| - name: 'Visual State', |
66 |
| - control: { type: 'select', options: VISUAL_STATES }, |
67 |
| - }, |
68 |
| - isActionMenuOpen: { |
69 |
| - name: 'Action Menu Open', |
70 |
| - control: 'boolean', |
71 |
| - }, |
72 |
| - isFolded: { |
73 |
| - name: 'Folded', |
74 |
| - control: 'boolean', |
75 |
| - }, |
76 |
| - isVisible: { |
77 |
| - name: 'Visible', |
78 |
| - control: 'boolean', |
79 |
| - }, |
| 33 | + // plumbing |
| 34 | + labelType: { table: { disable: true } }, |
| 35 | + isActionMenuOpen: { table: { disable: true } }, |
| 36 | + isVisible: { table: { disable: true } }, |
80 | 37 | },
|
81 |
| -} as Meta<CompoundBrickViewProps>; |
82 |
| - |
83 |
| -const baseArgs: CompoundBrickViewProps = { |
84 |
| - uuid: 'compound-1', |
85 |
| - name: 'compound-1', |
86 |
| - label: 'Compound Brick', |
87 |
| - labelType: 'text', |
88 |
| - colorBg: '#FFEB3B' as TColor, |
89 |
| - colorFg: '#000' as TColor, |
90 |
| - strokeColor: '#333' as TColor, |
91 |
| - shadow: false, |
92 |
| - isHighlighted: false, |
93 |
| - tooltip: 'This is a compound brick', |
94 |
| - scale: 1, |
95 |
| - |
96 |
| - topNotch: false, |
97 |
| - bottomNotch: false, |
98 |
| - bboxArgs: [] as TExtent[], |
99 |
| - bboxNest: [] as TExtent[], |
100 |
| - |
101 |
| - visualState: 'default', |
102 |
| - isActionMenuOpen: false, |
103 |
| - isFolded: false, |
104 |
| - isVisible: true, |
105 |
| - |
106 |
| - x: 0, |
107 |
| - y: 0, |
108 | 38 | };
|
109 | 39 |
|
110 |
| -const Template: StoryFn<CompoundBrickViewProps> = (args) => <CompoundBrickView {...args} />; |
111 |
| - |
112 |
| -// ── Playground ──────────────────────────────────────────── |
113 |
| -export const Playground = Template.bind({}); |
114 |
| -Playground.storyName = 'Playground'; |
115 |
| -Playground.args = { ...baseArgs }; |
116 |
| - |
117 |
| -// ── Visual States ───────────────────────────────────────── |
118 |
| -export const VisualStates = Template.bind({}); |
119 |
| -VisualStates.storyName = 'Visual States'; |
120 |
| -VisualStates.args = { ...baseArgs }; |
121 |
| -VisualStates.parameters = { |
122 |
| - controls: { include: ['visualState'] }, |
123 |
| -}; |
124 |
| - |
125 |
| -// ── Notch Variants ──────────────────────────────────────── |
126 |
| -export const NotchVariants = Template.bind({}); |
127 |
| -NotchVariants.storyName = 'Notch Variants'; |
128 |
| -NotchVariants.args = { ...baseArgs }; |
129 |
| -NotchVariants.parameters = { |
130 |
| - controls: { include: ['topNotch', 'bottomNotch'] }, |
131 |
| -}; |
132 |
| - |
133 |
| -// ── Arg Bounding Boxes ──────────────────────────────────── |
134 |
| -export const ArgBoundingBoxes = Template.bind({}); |
135 |
| -ArgBoundingBoxes.storyName = 'Arg Bounding Boxes'; |
136 |
| -ArgBoundingBoxes.args = { |
137 |
| - ...baseArgs, |
138 |
| - bboxArgs: [ |
139 |
| - { w: 30, h: 40 }, |
140 |
| - { w: 60, h: 80 }, |
141 |
| - ], |
142 |
| -}; |
143 |
| -ArgBoundingBoxes.parameters = { |
144 |
| - controls: { include: ['bboxArgs'] }, |
145 |
| -}; |
146 |
| - |
147 |
| -// ── Nest Bounding Boxes ─────────────────────────────────── |
148 |
| -export const NestBoundingBoxes = Template.bind({}); |
149 |
| -NestBoundingBoxes.storyName = 'Nest Bounding Boxes'; |
150 |
| -NestBoundingBoxes.args = { |
151 |
| - ...baseArgs, |
152 |
| - bboxNest: [ |
153 |
| - { w: 120, h: 60 }, |
154 |
| - { w: 100, h: 40 }, |
155 |
| - ], |
156 |
| -}; |
157 |
| -NestBoundingBoxes.parameters = { |
158 |
| - controls: { include: ['bboxNest'] }, |
159 |
| -}; |
160 |
| - |
161 |
| -// ── Folded ──────────────────────────────────────────────── |
162 |
| -export const Folded = Template.bind({}); |
163 |
| -Folded.storyName = 'Folded'; |
164 |
| -Folded.args = { |
165 |
| - ...baseArgs, |
166 |
| - isFolded: true, |
167 |
| - // give it some nesting space to see the fold effect: |
168 |
| - bboxNest: [{ w: 100, h: 50 }], |
169 |
| -}; |
170 |
| -Folded.parameters = { |
171 |
| - controls: { include: ['isFolded'] }, |
172 |
| -}; |
173 |
| - |
174 |
| -// ── Action Menu ─────────────────────────────────────────── |
175 |
| -export const ActionMenu = Template.bind({}); |
176 |
| -ActionMenu.storyName = 'Action Menu'; |
177 |
| -ActionMenu.args = { ...baseArgs }; |
178 |
| -ActionMenu.parameters = { |
179 |
| - controls: { include: ['isActionMenuOpen'] }, |
180 |
| -}; |
181 |
| - |
182 |
| -// ── Visibility ──────────────────────────────────────────── |
183 |
| -export const Visibility = Template.bind({}); |
184 |
| -Visibility.storyName = 'Visibility'; |
185 |
| -Visibility.args = { ...baseArgs }; |
186 |
| -Visibility.parameters = { |
187 |
| - controls: { include: ['isVisible'] }, |
| 40 | +export default meta; |
| 41 | +type Story = StoryObj<TBrickRenderPropsCompound>; |
| 42 | + |
| 43 | +/** The default compound-statement brick */ |
| 44 | +export const Default: Story = { |
| 45 | + args: { |
| 46 | + label: 'doSomething', |
| 47 | + labelType: 'text', |
| 48 | + colorBg: '#aad3df', |
| 49 | + colorFg: '#000000', |
| 50 | + strokeColor: '#000000', |
| 51 | + strokeWidth: 1, |
| 52 | + scale: 1, |
| 53 | + shadow: true, |
| 54 | + tooltip: 'A compound-statement brick', |
| 55 | + bboxArgs: [], |
| 56 | + bboxNest: [], |
| 57 | + topNotch: true, |
| 58 | + bottomNotch: true, |
| 59 | + isFolded: false, |
| 60 | + isActionMenuOpen: false, |
| 61 | + isVisible: true, |
| 62 | + }, |
188 | 63 | };
|
0 commit comments