|
| 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 | +}; |
0 commit comments