|
| 1 | +import React from 'react'; |
| 2 | +import { Meta, StoryObj } from '@storybook/react'; |
| 3 | +import { radiusTokens, version } from '@rangle/radius-foundations'; |
| 4 | + |
| 5 | +import { BADGE } from '@geometricpanda/storybook-addon-badges'; |
| 6 | +import { RadiusAutoLayout } from './auto-layout'; |
| 7 | +import { flattenObject } from '@rangle/radius-shared'; |
| 8 | +import { AutoLayoutExtendedProps } from './auto-layout.types'; |
| 9 | + |
| 10 | +const [major, minor, patch] = version ? version.split('.') : ['0', '0', '0']; |
| 11 | + |
| 12 | +const meta: Meta<typeof RadiusAutoLayout> = { |
| 13 | + component: RadiusAutoLayout, |
| 14 | + title: 'Auto Layout / Wrap', |
| 15 | + parameters: { |
| 16 | + // Version is rendered by this plugin https://github.com/silversonicaxel/storybook-addon-versioning |
| 17 | + version: { |
| 18 | + major, |
| 19 | + minor, |
| 20 | + patch, |
| 21 | + }, |
| 22 | + badges: [BADGE.BETA], |
| 23 | + |
| 24 | + // More on Storybook parameters at: https://storybook.js.org/docs/react/writing-stories/parameters#component-parameters |
| 25 | + }, |
| 26 | + argTypes: { |
| 27 | + as: { |
| 28 | + control: 'text', |
| 29 | + description: 'The HTML element or component to render', |
| 30 | + table: { defaultValue: { summary: 'div' } }, |
| 31 | + }, |
| 32 | + width: { |
| 33 | + options: ['629px', '200px', '50%', 'fill-parent', 'hug-contents'], |
| 34 | + }, |
| 35 | + height: { |
| 36 | + options: ['150px', '50%', 'fill-parent', 'hug-contents'], |
| 37 | + }, |
| 38 | + space: { |
| 39 | + options: ['auto', ...flattenObject(radiusTokens.core.spacing)], |
| 40 | + table: { defaultValue: { summary: '10px' } }, |
| 41 | + }, |
| 42 | + padding: { |
| 43 | + options: ['', ...flattenObject(radiusTokens.core.spacing)], |
| 44 | + }, |
| 45 | + direction: { |
| 46 | + options: ['horizontal', 'vertical'], |
| 47 | + }, |
| 48 | + fill: { |
| 49 | + options: [ |
| 50 | + '', |
| 51 | + ...flattenObject(radiusTokens.core.color), |
| 52 | + ...flattenObject(radiusTokens.semantic.color), |
| 53 | + ...flattenObject(radiusTokens.semanticTheme.color), |
| 54 | + ...flattenObject(radiusTokens.component.color), |
| 55 | + ], |
| 56 | + }, |
| 57 | + stroke: { |
| 58 | + options: [ |
| 59 | + '', |
| 60 | + ...flattenObject(radiusTokens.core.color), |
| 61 | + ...flattenObject(radiusTokens.semantic.color), |
| 62 | + ...flattenObject(radiusTokens.semanticTheme.color), |
| 63 | + ...flattenObject(radiusTokens.component.color), |
| 64 | + ], |
| 65 | + }, |
| 66 | + strokeWidth: { |
| 67 | + options: ['', ...flattenObject(radiusTokens.core.borderWidth)], |
| 68 | + }, |
| 69 | + opacity: { |
| 70 | + options: ['', ...flattenObject(radiusTokens.core.opacity)], |
| 71 | + }, |
| 72 | + x: { |
| 73 | + control: 'text', |
| 74 | + }, |
| 75 | + y: { |
| 76 | + control: 'text', |
| 77 | + }, |
| 78 | + cornerRadius: { |
| 79 | + options: ['', ...flattenObject(radiusTokens.core.borderRadius)], |
| 80 | + }, |
| 81 | + dropShadow: { |
| 82 | + options: ['', ...flattenObject(radiusTokens.core.shadow)], |
| 83 | + }, |
| 84 | + innerShadow: { |
| 85 | + options: ['', ...flattenObject(radiusTokens.core.shadow)], |
| 86 | + }, |
| 87 | + layerBlur: { |
| 88 | + options: [0, 1, 2, 3], |
| 89 | + }, |
| 90 | + backgroundBlur: { |
| 91 | + options: [0, 1, 2, 3], |
| 92 | + }, |
| 93 | + // TODO: add grid tokens when ready |
| 94 | + ref: { table: { disable: true } }, |
| 95 | + }, |
| 96 | + decorators: [ |
| 97 | + (Story) => ( |
| 98 | + <div |
| 99 | + style={{ |
| 100 | + display: 'flex', |
| 101 | + }} |
| 102 | + > |
| 103 | + <Story /> |
| 104 | + </div> |
| 105 | + ), |
| 106 | + ], |
| 107 | +}; |
| 108 | + |
| 109 | +export default meta; |
| 110 | +type Story = StoryObj<typeof RadiusAutoLayout>; |
| 111 | + |
| 112 | +export const AutoLayoutWrap: Story = { |
| 113 | + parameters: { |
| 114 | + controls: { |
| 115 | + // exclude grid controls until we've aligned on the direction we want to go with it |
| 116 | + exclude: [ |
| 117 | + 'grid', |
| 118 | + 'gridColSpan', |
| 119 | + 'gridColStart', |
| 120 | + 'gridColEnd', |
| 121 | + 'gridRowSpan', |
| 122 | + 'gridRowStart', |
| 123 | + 'gridRowEnd', |
| 124 | + ], |
| 125 | + }, |
| 126 | + }, |
| 127 | + // @ts-expect-error - bug with `args` type inference due to polymorphism |
| 128 | + render: (args: AutoLayoutExtendedProps) => ( |
| 129 | + <RadiusAutoLayout |
| 130 | + height={args.direction === 'vertical' ? 388 : undefined} |
| 131 | + width="fill-parent" |
| 132 | + > |
| 133 | + <RadiusAutoLayout alignment="center" isParent {...args}> |
| 134 | + <RadiusAutoLayout |
| 135 | + width={args.direction === 'horizontal' ? 40 : 'fill-parent'} |
| 136 | + height={args.direction === 'horizontal' ? 242 : 40} |
| 137 | + fill={{ css: '#F7856E' }} |
| 138 | + style={{ zIndex: 1 }} |
| 139 | + /> |
| 140 | + <RadiusAutoLayout |
| 141 | + width={args.direction === 'horizontal' ? 40 : 'fill-parent'} |
| 142 | + height={args.direction === 'horizontal' ? 242 : 40} |
| 143 | + fill={{ css: '#F7856E' }} |
| 144 | + style={{ zIndex: 1 }} |
| 145 | + /> |
| 146 | + <RadiusAutoLayout |
| 147 | + width={args.direction === 'horizontal' ? 40 : 'fill-parent'} |
| 148 | + height={args.direction === 'horizontal' ? 242 : 40} |
| 149 | + fill={{ css: '#F7856E' }} |
| 150 | + style={{ zIndex: 1 }} |
| 151 | + /> |
| 152 | + </RadiusAutoLayout> |
| 153 | + </RadiusAutoLayout> |
| 154 | + ), |
| 155 | + args: { |
| 156 | + as: 'div', |
| 157 | + width: '629px', |
| 158 | + height: 'fill-parent', |
| 159 | + space: 'auto', |
| 160 | + padding: radiusTokens.core.spacing[24], |
| 161 | + direction: 'horizontal', |
| 162 | + fill: radiusTokens.core.color.neutral[50], |
| 163 | + stroke: radiusTokens.core.color.neutral[600], |
| 164 | + strokeWidth: radiusTokens.core.borderWidth[1], |
| 165 | + strokeAlign: 'inside', |
| 166 | + cornerRadius: radiusTokens.core.borderRadius.none, |
| 167 | + clippedContent: false, |
| 168 | + alignment: 'top', |
| 169 | + isParent: false, |
| 170 | + absolutePosition: false, |
| 171 | + horizontalConstraint: 'left', |
| 172 | + verticalConstraint: 'top', |
| 173 | + }, |
| 174 | +}; |
| 175 | + |
| 176 | +/** |
| 177 | + * The `padding` property controls the padding of the Auto Layout component. |
| 178 | + * `padding` can be a single value or a list of values. If a list of values is |
| 179 | + * provided, the values are applied in the following order: top, right, bottom, |
| 180 | + * left. |
| 181 | + * |
| 182 | + * [How Figma Padding works](https://help.figma.com/hc/en-us/articles/360040451373-Explore-auto-layout-properties#padding) |
| 183 | + */ |
| 184 | +export const NoWrap: Story = { |
| 185 | + parameters: { |
| 186 | + controls: { |
| 187 | + // only show controls relevant to this story |
| 188 | + include: ['padding'], |
| 189 | + }, |
| 190 | + }, |
| 191 | + argTypes: { |
| 192 | + padding: { |
| 193 | + options: { |
| 194 | + '0px': '0px', |
| 195 | + '10px': { css: '10px' }, |
| 196 | + '48px 24px': { css: '48px 24px' }, |
| 197 | + '10px 20px 30px 40px': { css: '10px 20px 30px 40px' }, |
| 198 | + }, |
| 199 | + }, |
| 200 | + }, |
| 201 | + render: (args) => ( |
| 202 | + <RadiusAutoLayout |
| 203 | + stroke={{ css: '#006C95' }} |
| 204 | + strokeWidth={{ css: `2px` }} |
| 205 | + padding={{ css: '48px 24px' }} |
| 206 | + style={{ |
| 207 | + borderStyle: 'dashed', |
| 208 | + }} |
| 209 | + {...args} |
| 210 | + > |
| 211 | + <RadiusAutoLayout |
| 212 | + width={585} |
| 213 | + space="auto" |
| 214 | + stroke={{ css: '#006C95' }} |
| 215 | + strokeWidth={{ css: `2px` }} |
| 216 | + style={{ |
| 217 | + borderStyle: 'dashed', |
| 218 | + }} |
| 219 | + > |
| 220 | + <RadiusAutoLayout width={40} height={242} fill={{ css: '#F7856E' }} /> |
| 221 | + <RadiusAutoLayout width={40} height={242} fill={{ css: '#F7856E' }} /> |
| 222 | + <RadiusAutoLayout width={40} height={242} fill={{ css: '#F7856E' }} /> |
| 223 | + </RadiusAutoLayout> |
| 224 | + </RadiusAutoLayout> |
| 225 | + ), |
| 226 | +}; |
| 227 | + |
0 commit comments