Skip to content

Commit be56b21

Browse files
author
Kubit
committed
Improve layout stories
1 parent d781dd6 commit be56b21

File tree

1 file changed

+87
-5
lines changed

1 file changed

+87
-5
lines changed

src/components/layout/stories/layout.stories.tsx

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,55 @@ const meta = {
1919
},
2020
tags: ['autodocs'],
2121
argTypes: argtypes(variantsObject, themeSelected),
22+
render: ({ ...args }) => <StoryWithHooks {...args} />,
2223
} satisfies Meta<typeof Story>;
2324

2425
export default meta;
2526

2627
type Story = StoryObj<typeof meta> & { args: { themeArgs?: object } };
2728

29+
const StoryWithHooks = args => {
30+
const [height, setHeight] = React.useState(0);
31+
const refFirstContent = React.useRef<HTMLElement | null>(null);
32+
// Check if mainContent is an empty fragment
33+
const isEmptyFragment =
34+
args.mainContent?.type === React.Fragment && !args.mainContent.props.children;
35+
36+
// catch the reference when the component appears
37+
const callbackRef = React.useCallback(node => {
38+
if (node) {
39+
refFirstContent.current = node;
40+
const element = refFirstContent.current as HTMLElement;
41+
setHeight(element.clientHeight || 0);
42+
}
43+
}, []);
44+
45+
const mainContent = isEmptyFragment ? (
46+
<>
47+
<ReplaceContent ref={callbackRef} height={'50%'}>
48+
Main content
49+
</ReplaceContent>
50+
<ReplaceContent height={'50%'}>Main content</ReplaceContent>
51+
</>
52+
) : (
53+
args.mainContent
54+
);
55+
56+
const asideContent = args.asideContent ? (
57+
args.asideContent
58+
) : (
59+
<ReplaceContent height={'50%'} margin={`${height}px 0 0 0 `}>
60+
Aside content
61+
</ReplaceContent>
62+
);
63+
64+
return <Story {...args} asideContent={asideContent} mainContent={mainContent} />;
65+
};
66+
2867
export const Layout: Story = {
2968
args: {
3069
variant: Object.values(variantsObject[themeSelected].LayoutVariantType || {})[0] as string,
31-
mainContent: (
32-
<>
33-
<ReplaceContent height={'100%'}>Main content</ReplaceContent>
34-
</>
35-
),
70+
mainContent: <ReplaceContent height={'100%'}>Main content</ReplaceContent>,
3671
headerContent: <ReplaceContent>Header content</ReplaceContent>,
3772
asideContent: <ReplaceContent height={'100%'}>Aside content</ReplaceContent>,
3873
footerContent: <ReplaceContent>Footer content</ReplaceContent>,
@@ -64,10 +99,57 @@ export const Layout: Story = {
6499
[DeviceBreakpointsType.MOBILE]: 4,
65100
},
66101
},
102+
67103
themeArgs: themesObject[themeSelected][STYLES_NAME.LAYOUT],
68104
},
69105
};
70106

107+
export const LayoutAlignAside: Story = {
108+
args: {
109+
variant: Object.values(variantsObject[themeSelected].LayoutVariantType || {})[0] as string,
110+
mainContent: <></>,
111+
headerContent: <ReplaceContent>Header content</ReplaceContent>,
112+
footerContent: <ReplaceContent>Footer content</ReplaceContent>,
113+
backgroundColor: '#f5f5f5',
114+
columnsConfig: {
115+
header: {
116+
[DeviceBreakpointsType.LARGE_DESKTOP]: 12,
117+
[DeviceBreakpointsType.DESKTOP]: 12,
118+
[DeviceBreakpointsType.TABLET]: 8,
119+
[DeviceBreakpointsType.MOBILE]: 4,
120+
},
121+
footer: {
122+
[DeviceBreakpointsType.LARGE_DESKTOP]: 12,
123+
[DeviceBreakpointsType.DESKTOP]: 12,
124+
[DeviceBreakpointsType.TABLET]: 8,
125+
[DeviceBreakpointsType.MOBILE]: 4,
126+
},
127+
main: {
128+
[DeviceBreakpointsType.LARGE_DESKTOP]: 9,
129+
[DeviceBreakpointsType.DESKTOP]: 9,
130+
DESKTOP_FULL: 12,
131+
[DeviceBreakpointsType.TABLET]: 8,
132+
[DeviceBreakpointsType.MOBILE]: 4,
133+
},
134+
aside: {
135+
[DeviceBreakpointsType.LARGE_DESKTOP]: 3,
136+
[DeviceBreakpointsType.DESKTOP]: 3,
137+
[DeviceBreakpointsType.TABLET]: 8,
138+
[DeviceBreakpointsType.MOBILE]: 4,
139+
},
140+
},
141+
ctv: {
142+
gridConfig: {
143+
DESKTOP: {
144+
// mainStyles: {
145+
// height: 'fit-content',
146+
// },
147+
},
148+
},
149+
},
150+
},
151+
};
152+
71153
export const LayoutWithCtv: Story = {
72154
args: {
73155
variant: Object.values(variantsObject[themeSelected].LayoutVariantType || {})[0] as string,

0 commit comments

Comments
 (0)