|
| 1 | +import React from 'react' |
| 2 | +import clsx from 'clsx' |
| 3 | + |
| 4 | +export default { |
| 5 | + title: 'Components/Layout/Alpha', |
| 6 | + excludeStories: ['LayoutAlphaTemplate'], |
| 7 | + argTypes: { |
| 8 | + container: { |
| 9 | + control: { type: 'select' }, |
| 10 | + options: ['fluid', 'md', 'lg', 'xl'], |
| 11 | + control: { |
| 12 | + type: 'inline-radio' |
| 13 | + }, |
| 14 | + description: 'Wrapper around the entire component to define an optional maximum width.', |
| 15 | + table: { |
| 16 | + category: 'CSS' |
| 17 | + } |
| 18 | + }, |
| 19 | + hasDivider: { |
| 20 | + control: { type: 'boolean' }, |
| 21 | + description: 'Whether to show a pane line divider.', |
| 22 | + table: { |
| 23 | + category: 'CSS' |
| 24 | + } |
| 25 | + }, |
| 26 | + gutter: { |
| 27 | + options: ['default', 'none', 'condensed', 'spacious'], |
| 28 | + control: { |
| 29 | + type: 'inline-radio' |
| 30 | + }, |
| 31 | + description: 'Sets the gap between columns.', |
| 32 | + table: { |
| 33 | + category: 'CSS' |
| 34 | + } |
| 35 | + }, |
| 36 | + sidebarPosition: { |
| 37 | + options: ['start', 'end'], |
| 38 | + control: { |
| 39 | + type: 'inline-radio' |
| 40 | + }, |
| 41 | + description: 'Sets the position of the sidebar.', |
| 42 | + table: { |
| 43 | + category: 'CSS' |
| 44 | + } |
| 45 | + }, |
| 46 | + sidebarWidth: { |
| 47 | + options: ['default', 'narrow', 'wide'], |
| 48 | + control: { |
| 49 | + type: 'inline-radio' |
| 50 | + }, |
| 51 | + description: 'Sets the width of the sidebar.', |
| 52 | + table: { |
| 53 | + category: 'CSS' |
| 54 | + } |
| 55 | + }, |
| 56 | + mainWidth: { |
| 57 | + options: ['fluid', 'md', 'lg', 'xl'], |
| 58 | + control: { |
| 59 | + type: 'inline-radio' |
| 60 | + }, |
| 61 | + description: 'Sets the width of the main content area.', |
| 62 | + table: { |
| 63 | + category: 'CSS' |
| 64 | + } |
| 65 | + }, |
| 66 | + flowRowUntil: { |
| 67 | + options: ['sm', 'md', 'lg'], |
| 68 | + control: { |
| 69 | + type: 'inline-radio', |
| 70 | + }, |
| 71 | + description: 'Sets the maximum breakpoint at which the layout will flow as row.', |
| 72 | + table: { |
| 73 | + category: 'CSS' |
| 74 | + } |
| 75 | + }, |
| 76 | + mainChildren: { |
| 77 | + description: 'creates a slot for main children', |
| 78 | + table: { |
| 79 | + category: 'HTML' |
| 80 | + } |
| 81 | + }, |
| 82 | + sidebarChildren: { |
| 83 | + description: 'creates a slot for sidebar children', |
| 84 | + table: { |
| 85 | + category: 'HTML' |
| 86 | + } |
| 87 | + }, |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +// build every component case here in the template (private api) |
| 92 | +export const LayoutAlphaTemplate = ({ |
| 93 | + container, |
| 94 | + hasDivider, |
| 95 | + gutter, |
| 96 | + sidebarPosition, |
| 97 | + sidebarWidth, |
| 98 | + mainWidth, |
| 99 | + flowRowUntil, |
| 100 | + mainChildren, |
| 101 | + sidebarChildren |
| 102 | +}) => { |
| 103 | + |
| 104 | + // Default values |
| 105 | + container = container ?? 'xl'; |
| 106 | + hasDivider = hasDivider ?? false; |
| 107 | + gutter = gutter ?? 'default'; |
| 108 | + sidebarPosition = sidebarPosition ?? 'end'; |
| 109 | + sidebarWidth = sidebarWidth ?? 'default'; |
| 110 | + mainWidth = mainWidth ?? 'full'; |
| 111 | + flowRowUntil = flowRowUntil ?? 'md'; |
| 112 | + |
| 113 | + // Leave `null` values for states that don't require a modifier class |
| 114 | + container = (container === 'full') ? null : container; |
| 115 | + hasDivider = (hasDivider === false) ? null : hasDivider; |
| 116 | + gutter = (gutter === 'default') ? null : gutter; |
| 117 | + sidebarWidth = (sidebarWidth === 'default') ? null : sidebarWidth; |
| 118 | + mainWidth = (mainWidth === 'full') ? null : mainWidth; |
| 119 | + flowRowUntil = (flowRowUntil === 'sm') ? null : flowRowUntil; |
| 120 | + |
| 121 | + return ( |
| 122 | + <div |
| 123 | + // use clsx for multiple classnames |
| 124 | + className={clsx( |
| 125 | + 'Layout', |
| 126 | + container && 'container-' + `${container}`, |
| 127 | + gutter && 'Layout--gutter-' + `${gutter}`, |
| 128 | + sidebarPosition && 'Layout--sidebarPosition-' + `${sidebarPosition}`, |
| 129 | + sidebarWidth && 'Layout--sidebar-' + `${sidebarWidth}`, |
| 130 | + hasDivider && 'Layout--divided', |
| 131 | + flowRowUntil && '' + 'Layout--flowRow-until-' + `${flowRowUntil}` |
| 132 | + )} |
| 133 | + // use undefined for values that shouldn't be set if false |
| 134 | + aria-hidden={hasDivider ? 'true' : undefined} |
| 135 | + > |
| 136 | + {/* use {children} for wrapper component templates */} |
| 137 | + <> |
| 138 | + <div className="Layout-main"> |
| 139 | + {mainWidth ? ( |
| 140 | + <> |
| 141 | + <div className={'Layout-main-centered-' + mainWidth}> |
| 142 | + <div className={clsx( mainWidth && 'container-' + mainWidth)}> |
| 143 | + {mainChildren} |
| 144 | + </div> |
| 145 | + </div> |
| 146 | + </> |
| 147 | + ) : ( |
| 148 | + <> |
| 149 | + {mainChildren} |
| 150 | + </> |
| 151 | + )} |
| 152 | + </div> |
| 153 | + <div className="Layout-divider"></div> |
| 154 | + <div className="Layout-sidebar">{sidebarChildren}</div> |
| 155 | + </> |
| 156 | + </div> |
| 157 | + ); |
| 158 | +}; |
| 159 | + |
| 160 | +const sidebarPlaceholder = |
| 161 | + <> |
| 162 | + <div style={ |
| 163 | + { |
| 164 | + width: '100%', |
| 165 | + height: '100%', |
| 166 | + backgroundColor: '#DDF4FF', |
| 167 | + border: '1px solid #80CCFF', |
| 168 | + padding: '16px', |
| 169 | + borderRadius: '6px' |
| 170 | + } |
| 171 | + }> |
| 172 | + sidebar |
| 173 | + </div> |
| 174 | + </>; |
| 175 | + |
| 176 | +const mainPlaceholder = |
| 177 | + <> |
| 178 | + <div style={ |
| 179 | + { |
| 180 | + width: '100%', |
| 181 | + height: '100%', |
| 182 | + backgroundColor: '#FFEFF7', |
| 183 | + border: '1px solid #FFADDA', |
| 184 | + padding: '16px', |
| 185 | + borderRadius: '6px' |
| 186 | + } |
| 187 | + }> |
| 188 | + main |
| 189 | + </div> |
| 190 | + </>; |
| 191 | + |
| 192 | +// create a "playground" demo page that may set some defaults and allow story to access component controls |
| 193 | +export const Playground = LayoutAlphaTemplate.bind({}) |
| 194 | +Playground.args = { |
| 195 | + container: 'full', |
| 196 | + hasDivider: false, |
| 197 | + gutter: 'default', |
| 198 | + sidebarPosition: 'end', |
| 199 | + sidebarWidth: 'default', |
| 200 | + mainWidth: 'full', |
| 201 | + flowRowUntil: 'md', |
| 202 | + mainChildren: mainPlaceholder, |
| 203 | + sidebarChildren: sidebarPlaceholder |
| 204 | +} |
0 commit comments