Skip to content

Commit 4bd44d8

Browse files
authored
Merge pull request #183 from reusejs/LayoutTemplate
Layout template: Side-Drawer Added
2 parents 9d8f80a + 4d57d13 commit 4bd44d8

9 files changed

Lines changed: 1276 additions & 1327 deletions

File tree

.changeset/few-planes-report.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@reusejs/react": minor
3+
---
4+
5+
Added Layout Side-Drawer

apps/storybook/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"@heroicons/react": "v1",
2626
"@lexical/react": "^0.5.0",
2727
"@reusejs/react": "*",
28-
"@storybook/react": "^6.5.9",
28+
"@storybook/react": "^6.5.16",
2929
"chart.js": "^4.2.1",
3030
"clsx": "^1.2.1",
3131
"faker": "5.5.3",
@@ -48,7 +48,6 @@
4848
"@storybook/addon-postcss": "^2.0.0",
4949
"@storybook/builder-webpack5": "^6.5.9",
5050
"@storybook/manager-webpack5": "^6.5.9",
51-
"@storybook/react": "^6.5.9",
5251
"@storybook/testing-library": "^0.0.13",
5352
"@svgr/webpack": "^6.2.1",
5453
"@tailwindcss/forms": "^0.5.2",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
3+
function Menu() {
4+
return (
5+
<svg
6+
xmlns='http://www.w3.org/2000/svg'
7+
width='24'
8+
height='24'
9+
fill='none'
10+
viewBox='0 0 24 24'
11+
>
12+
<path
13+
fill='#2A05CC'
14+
d='M21 5.5H3c-.41 0-.75-.34-.75-.75S2.59 4 3 4h18c.41 0 .75.34.75.75s-.34.75-.75.75zM12.47 12.5H3c-.41 0-.75-.34-.75-.75S2.59 11 3 11h9.47a.749.749 0 110 1.5zM21 19.5H3c-.41 0-.75-.34-.75-.75S2.59 18 3 18h18c.41 0 .75.34.75.75s-.34.75-.75.75z'
15+
></path>
16+
</svg>
17+
);
18+
}
19+
20+
export default Menu;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const docs = `
2+
**Side Drawer Layout** provides users with predefined custom Side drawer structure which can open a side drawer on \`Hover\` or on \`Click\`.
3+
4+
Following is the props list for using SideDrawer component
5+
1. **\`ref\`** : To make use of *\`onClick\`* function, use \`ref\` object and \`handleClick\` function to open or close the drawer.
6+
2. **\`effectOn\`** : This is used to decide whether the \`Side Drawer\` will open on hover or click. Default value is \`hover\`. Only two values are accepted \`hover\` or \`click\`.
7+
3. **\`overlap\`** : This prop is used to select whether the side-drawer in its active state should overlap the main content or not. Default value for this prop is \`true\`. It can accept boolean values \`true\` and \`false\`.
8+
4. **\`callback\`** : This is a custom callback which can be used to perform a side-effect when the state of side drawer is changed.
9+
5. **\`sideDrawerContent\`** : This will accept the component which will be displayed in SideDrawer.
10+
6. **\`mainContent\`** : This will accept the component which will be displayed as Main Content.
11+
7. **\`Style Props\`** : One of the recurring feature of **\`ReuseJS/React\`** chas been the ability to style the provided components as you see fit. This component is no different. Following are the list of style props which will be used to style the layout:
12+
- **\`wrapper\`** : This style prop is used to wrap the whole component. Default value is *\`flex h-full w-full\`*.
13+
- **\`drawerLayout\`** : This style prop gives the normal layout for the side drawer. Default value is *\`bg-red-600 transition-all overflow-hidden h-full shrink-0\`*.
14+
- **\`drawerActiveWidth\`** : This style prop holds the value for the width of side drawer when active. **For hover style side-drawer pass width as \`hover:w-1/6\` while for click based side-drawer pass width as \`w-1/6\`**. Default value for this props is *\`hover:w-6/12 md:hover:w-3/12\`*
15+
- **\`drawerInActiveWidth\`** : This style from holds the value for inactive width of side drawer. Default value for the style is *\`w-[70px]\`*. User can pass the value as **\`w-0\`** to make the sidedrawer **hidden** *(This should only be paired with \`click\` style side-drawer)*.
16+
- **\`contentLeftMargin\`** : This style props is only used when overlap prop is true. When the side-drawer is given with overflow true it will have absolute positioning so some part of main content might be hidden permanently. To prevent this we will be giving the same margin as the width of side-bar in \`inactive\` state. Default value is *\`ml-[70px]\`*
17+
- **\`contentWrapper\`** : This prop is used to style the main content. Default value is *\`h-full w-full bg-blue-200\`*.
18+
`;
19+
20+
export default docs;
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
import { BaseSideDrawer } from '@reusejs/react';
2+
import { ComponentMeta, ComponentStory } from '@storybook/react';
3+
import React, { useRef, useState } from 'react';
4+
import SideDrawerDocs from '../docs/SideDrawer.docs';
5+
import Menu from '../assets/Menu';
6+
7+
export default {
8+
title: 'Layouts/SideDrawer',
9+
component: BaseSideDrawer,
10+
argTypes: {},
11+
parameters: {
12+
docs: {
13+
description: {
14+
component: SideDrawerDocs,
15+
},
16+
},
17+
},
18+
} as ComponentMeta<typeof BaseSideDrawer>;
19+
20+
const Template: ComponentStory<typeof BaseSideDrawer> = (args) => {
21+
const componentRef = useRef<any>();
22+
23+
const click = () => {
24+
if (
25+
componentRef &&
26+
componentRef.current &&
27+
componentRef.current.handleClick
28+
) {
29+
componentRef.current.handleClick();
30+
}
31+
};
32+
33+
const SideDrawerContent = () => {
34+
return (
35+
<div className='h-full w-full '>Hello this is side drawer content</div>
36+
);
37+
};
38+
39+
const MainContent = () => {
40+
return (
41+
<div className='flex h-full flex-col items-center justify-center bg-yellow-400 md:flex-row'>
42+
<label>This is main content</label>
43+
<button
44+
className='ml-10 h-fit w-fit bg-blue-700 py-2 px-3 md:ml-56 md:flex-row md:px-6 md:py-5'
45+
onClick={() => {
46+
click();
47+
}}
48+
>
49+
Click Here!!
50+
</button>
51+
</div>
52+
);
53+
};
54+
55+
return (
56+
<div className='h-[500px] w-full'>
57+
<BaseSideDrawer
58+
ref={componentRef}
59+
sideDrawerContent={<SideDrawerContent />}
60+
mainContent={<MainContent />}
61+
{...args}
62+
/>
63+
</div>
64+
);
65+
};
66+
67+
export const DefaultHoverWithOverlap = Template.bind({});
68+
DefaultHoverWithOverlap.args = {};
69+
70+
export const HoverWithNoOverlap = Template.bind({});
71+
HoverWithNoOverlap.args = {
72+
overlap: false,
73+
baseSideDrawerStyleClasses: {
74+
drawerInActiveWidth: 'w-[100px]',
75+
contentLeftMargin: 'ml-[100px]',
76+
},
77+
};
78+
79+
export const ClickWithOverlap = Template.bind({});
80+
ClickWithOverlap.args = {
81+
effectOn: 'click',
82+
baseSideDrawerStyleClasses: {
83+
drawerActiveWidth: 'w-5/12 md:w-3/12',
84+
drawerInActiveWidth: 'w-[70px]',
85+
contentLeftMargin: 'ml-[70px]',
86+
},
87+
};
88+
89+
export const ClickWithNoOverlap = Template.bind({});
90+
ClickWithNoOverlap.args = {
91+
effectOn: 'click',
92+
overlap: false,
93+
baseSideDrawerStyleClasses: {
94+
drawerActiveWidth: 'md:w-4/12 w-6/12',
95+
drawerInActiveWidth: 'w-[70px]',
96+
contentLeftMargin: 'ml-[70px]',
97+
},
98+
};
99+
export const HiddenSidedrawer = Template.bind({});
100+
HiddenSidedrawer.args = {
101+
effectOn: 'click',
102+
overlap: true,
103+
baseSideDrawerStyleClasses: {
104+
drawerActiveWidth: 'w-5/12 md:w-4/12',
105+
drawerInActiveWidth: 'w-0',
106+
contentLeftMargin: 'ml-0',
107+
},
108+
};
109+
110+
export const HiddenSidedrawerNoOverlap = Template.bind({});
111+
HiddenSidedrawerNoOverlap.args = {
112+
effectOn: 'click',
113+
overlap: false,
114+
baseSideDrawerStyleClasses: {
115+
drawerActiveWidth: 'w-5/12 md:w-4/12',
116+
drawerInActiveWidth: 'w-0',
117+
contentLeftMargin: 'ml-0',
118+
},
119+
};
120+
121+
const Template2: ComponentStory<typeof BaseSideDrawer> = (args) => {
122+
const componentRef = useRef<any>();
123+
const [state, setState] = useState<boolean>(false);
124+
125+
const logger = (e: boolean) => {
126+
setState(e);
127+
};
128+
129+
const click = () => {
130+
if (
131+
componentRef &&
132+
componentRef.current &&
133+
componentRef.current.handleClick
134+
) {
135+
componentRef.current.handleClick();
136+
}
137+
};
138+
139+
const SideDrawerContent = () => {
140+
return (
141+
<div className='h-full w-full'>
142+
<div className='flex items-center overflow-hidden whitespace-nowrap bg-blue-400 text-white'>
143+
<button
144+
className='h-12 w-[70px] px-3 py-2 '
145+
onClick={() => {
146+
click();
147+
}}
148+
>
149+
<Menu />
150+
</button>
151+
{state ? (
152+
<label className='ml-3 font-bold'>Side Drawer Open</label>
153+
) : null}
154+
</div>
155+
</div>
156+
);
157+
};
158+
159+
const MainContent = () => {
160+
return (
161+
<div className='flex h-full flex-col items-center justify-center bg-yellow-400 md:flex-row'>
162+
<label>This is main content</label>
163+
</div>
164+
);
165+
};
166+
167+
return (
168+
<div className='h-[500px] w-full'>
169+
<BaseSideDrawer
170+
ref={componentRef}
171+
sideDrawerContent={<SideDrawerContent />}
172+
mainContent={<MainContent />}
173+
callback={logger}
174+
{...args}
175+
/>
176+
</div>
177+
);
178+
};
179+
180+
export const OpenFromSideDrawer = Template2.bind({});
181+
OpenFromSideDrawer.args = {
182+
effectOn: 'click',
183+
overlap: false,
184+
baseSideDrawerStyleClasses: {
185+
drawerActiveWidth: 'w-5/12 md:w-4/12',
186+
drawerInActiveWidth: 'w-[70px]',
187+
contentLeftMargin: 'ml-[70px]',
188+
},
189+
};

packages/react/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ export { default as StoreButton } from "./templates/StoreButtonTemplates/storeBu
152152

153153
/* End Templates */
154154

155+
//Start Layouts
156+
157+
export { default as BaseSideDrawer } from "./layouts/BaseSideDrawer";
158+
159+
// End Layouts
160+
155161
export {
156162
default as ThemeProvider,
157163
useThemeContext,

0 commit comments

Comments
 (0)