From 985ae6a5e39fa792f24a8b8409646b7d08e71de0 Mon Sep 17 00:00:00 2001 From: Raisa Primerova <48605821+RayRedGoose@users.noreply.github.com> Date: Tue, 30 May 2023 11:03:45 -0600 Subject: [PATCH 1/4] feat: Set initial v10 codemod (#2239) Resolves: #2238 I've added initial settings for v10 codemod, example codemod has been created to prevent typescript failure in index. [category:Codemods] --- modules/codemod/index.js | 7 +++++++ modules/codemod/lib/v10/example.ts | 10 ++++++++++ modules/codemod/lib/v10/index.ts | 14 ++++++++++++++ modules/codemod/lib/v10/spec/example.spec.ts | 18 ++++++++++++++++++ .../lib/v10/spec/expectTransformFactory.ts | 9 +++++++++ 5 files changed, 58 insertions(+) create mode 100644 modules/codemod/lib/v10/example.ts create mode 100644 modules/codemod/lib/v10/index.ts create mode 100644 modules/codemod/lib/v10/spec/example.spec.ts create mode 100644 modules/codemod/lib/v10/spec/expectTransformFactory.ts diff --git a/modules/codemod/index.js b/modules/codemod/index.js index 25bb957c32..059743cf8b 100755 --- a/modules/codemod/index.js +++ b/modules/codemod/index.js @@ -61,6 +61,13 @@ const {_: commands, path, ignoreConfig, ignorePattern, verbose} = require('yargs describe: chalk.gray('The path to execute the transform in (recursively).'), }); }) + .command('v10 [path]', chalk.gray('Canvas Kit v9 > v10 upgrade transform'), yargs => { + yargs.positional('path', { + type: 'string', + default: '.', + describe: chalk.gray('The path to execute the transform in (recursively).'), + }); + }) .demandCommand(1, chalk.red.bold('You must provide a transform to apply.')) .strictCommands() .fail((msg, err, yargs) => { diff --git a/modules/codemod/lib/v10/example.ts b/modules/codemod/lib/v10/example.ts new file mode 100644 index 0000000000..8bbcec96d9 --- /dev/null +++ b/modules/codemod/lib/v10/example.ts @@ -0,0 +1,10 @@ +import {API, FileInfo, Options} from 'jscodeshift'; + +export default function transformer(file: FileInfo, api: API, options: Options) { + const j = api.jscodeshift; + const root = j(file.source); + + // codemode goes here ... + + return root.toSource(); +} diff --git a/modules/codemod/lib/v10/index.ts b/modules/codemod/lib/v10/index.ts new file mode 100644 index 0000000000..bcb0d604e5 --- /dev/null +++ b/modules/codemod/lib/v10/index.ts @@ -0,0 +1,14 @@ +import {Transform} from 'jscodeshift'; +import example from './example'; + +const transform: Transform = (file, api, options) => { + // These will run in order. If your transform depends on others, place yours after dependent transforms + const fixes = [ + // add codemods here + example, + ]; + + return fixes.reduce((source, fix) => fix({...file, source}, api, options) as string, file.source); +}; + +export default transform; diff --git a/modules/codemod/lib/v10/spec/example.spec.ts b/modules/codemod/lib/v10/spec/example.spec.ts new file mode 100644 index 0000000000..adc87af960 --- /dev/null +++ b/modules/codemod/lib/v10/spec/example.spec.ts @@ -0,0 +1,18 @@ +import {expectTransformFactory} from './expectTransformFactory'; +import transform from '../example'; +import {stripIndent} from 'common-tags'; + +const expectTransform = expectTransformFactory(transform); + +describe('Example', () => { + it('should ignore non-canvas-kit imports', () => { + const input = stripIndent` + import Example from '@workday/some-other-library' + `; + const expected = stripIndent` + import Example from '@workday/some-other-library' + `; + + expectTransform(input, expected); + }); +}); diff --git a/modules/codemod/lib/v10/spec/expectTransformFactory.ts b/modules/codemod/lib/v10/spec/expectTransformFactory.ts new file mode 100644 index 0000000000..c67cb32768 --- /dev/null +++ b/modules/codemod/lib/v10/spec/expectTransformFactory.ts @@ -0,0 +1,9 @@ +import {runInlineTest} from 'jscodeshift/dist/testUtils'; + +export const expectTransformFactory = (fn: Function) => ( + input: string, + expected: string, + options?: Record +) => { + return runInlineTest(fn, options, {source: input}, expected, {parser: 'tsx'}); +}; From 53027e496d2d3c957d1711976b6cbb7fbb1622af Mon Sep 17 00:00:00 2001 From: Jaclyn Date: Tue, 30 May 2023 11:35:07 -0600 Subject: [PATCH 2/4] chore: Adding v10 upgrade guide (#2237) Adding the v10 upgrade guide [category:Documentation] --- modules/docs/mdx/10.0-UPGRADE_GUIDE.mdx | 42 +++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 modules/docs/mdx/10.0-UPGRADE_GUIDE.mdx diff --git a/modules/docs/mdx/10.0-UPGRADE_GUIDE.mdx b/modules/docs/mdx/10.0-UPGRADE_GUIDE.mdx new file mode 100644 index 0000000000..ac50c0fb25 --- /dev/null +++ b/modules/docs/mdx/10.0-UPGRADE_GUIDE.mdx @@ -0,0 +1,42 @@ +import {Meta} from '@storybook/addon-docs'; + + + +# Canvas Kit 10.0 Upgrade Guide + +This guide contains an overview of the changes in Canvas Kit v10. Please +[reach out](https://github.com/Workday/canvas-kit/issues/new?labels=bug&template=bug.md) if you have +any questions. + +- [Codemod](#codemod) + +## Codemod + +Please use our [codemod package](https://github.com/Workday/canvas-kit/tree/master/modules/codemod) +to automatically update your code to work with most of the breaking changes in v10. + +```sh +> npx @workday/canvas-kit-codemod v10 [path] +``` + +Alternatively, if you're unable to run the codemod successfully using `npx`, you can install the +codemod package as a dev dependency, run it with `yarn`, and then remove the package after you're +finished. + +```sh +> yarn add @workday/canvas-kit-codemod --dev +> yarn canvas-kit-codemod v10 [path] +> yarn remove @workday/canvas-kit-codemod +``` + +> The codemod only works on `.js`, `.jsx`, `.ts`, and `.tsx` files. You'll need to manually edit +> other file types (`.json`, `.mdx`, `.md`, etc.). You may need to run your linter after executing +> the codemod, as its resulting formatting (spacing, quotes, etc.) may not match your project +> conventions. + +The codemod will handle _most_ but _not all_ of the breaking changes in 10. **Breaking changes +handled by the codemod are marked with 🤖 in the Upgrade Guide.** + +**Please verify all changes made by the codemod.** As a safety precaution, we recommend committing +the changes from the codemod as a single isolated commit (separate from other changes) so you can +roll back more easily if necessary. From 7fc0c577c5f944eabe967840a78fc77f781833ce Mon Sep 17 00:00:00 2001 From: Josh <44883293+josh-bagwell@users.noreply.github.com> Date: Wed, 7 Jun 2023 09:02:39 -0600 Subject: [PATCH 3/4] feat!: Update space and depth tokens to rem (#2229) Updating `depth` and `space` tokens to use `rem` rather than `px`. This includes updating components as well since values have been updated to reflect `rem` and not `px` (i.e. `spaceNumbers.s` = `16` and now is `spaceNumbers.s` = `1`. This reflects the new `rem` value.) Fixes: #1227 [category:Components] Release Note: Updated `depth` and `space` token values to use `rem` instead of `px`. ### BREAKING CHANGES There is the possibility of breaking changes if users are changing the default browser font size from `16px` to another value. You can convert a `px` value to a `rem` value by dividing your `px` value by `16`(if your default browser font size hasn't been updated, the value will be `16`). For example: | Equation | rem Value | | ----------- | --------- | | `16px/16px` | `1rem` | | `32px/16px` | `2rem` | | `8px/16px` | `0.5rem` | Co-authored-by: @alanbsmith Co-authored-by: @bstanton678 <40372497+bstanton678@users.noreply.github.com> Co-authored-by: @mannycarrera4 --- modules/docs/mdx/10.0-UPGRADE_GUIDE.mdx | 48 +++++++ .../labs-react/search-form/lib/SearchForm.tsx | 10 +- .../preview-react/select/lib/SelectBase.tsx | 14 +- .../preview-react/select/lib/SelectMenu.tsx | 3 +- .../text-area/lib/TextAreaField.tsx | 4 +- .../visual-testing/stories_action-bar.tsx | 6 +- modules/react/button/lib/BaseButton.tsx | 8 +- modules/react/checkbox/lib/Checkbox.tsx | 30 ++-- modules/react/layout/spec/depth.spec.ts | 2 +- modules/react/layout/spec/flex.spec.ts | 6 +- modules/react/layout/spec/grid.spec.ts | 6 +- modules/react/layout/spec/space.spec.ts | 60 ++++---- modules/react/radio/lib/Radio.tsx | 34 +++-- modules/react/select/lib/Select.tsx | 11 +- modules/react/table/lib/TableRow.tsx | 2 +- modules/react/text-area/lib/TextArea.tsx | 14 +- modules/react/text-input/lib/TextInput.tsx | 2 +- modules/react/tokens/README.md | 38 ++--- modules/react/tokens/index.ts | 3 +- modules/react/tokens/lib/depth.ts | 28 ++-- modules/react/tokens/lib/space.ts | 130 +++++++++++------- .../react/tooltip/lib/TooltipContainer.tsx | 16 +-- 22 files changed, 286 insertions(+), 189 deletions(-) diff --git a/modules/docs/mdx/10.0-UPGRADE_GUIDE.mdx b/modules/docs/mdx/10.0-UPGRADE_GUIDE.mdx index ac50c0fb25..47c8420193 100644 --- a/modules/docs/mdx/10.0-UPGRADE_GUIDE.mdx +++ b/modules/docs/mdx/10.0-UPGRADE_GUIDE.mdx @@ -9,6 +9,8 @@ This guide contains an overview of the changes in Canvas Kit v10. Please any questions. - [Codemod](#codemod) +- [Token Updates](#token-updates) + - [Space and Depth](#space-and-depth) ## Codemod @@ -40,3 +42,49 @@ handled by the codemod are marked with 🤖 in the Upgrade Guide.** **Please verify all changes made by the codemod.** As a safety precaution, we recommend committing the changes from the codemod as a single isolated commit (separate from other changes) so you can roll back more easily if necessary. + +## Token Updates + +### Space and Depth + +**PR:** [#2229](https://github.com/Workday/canvas-kit/pull/2229) + +In v10, we have updated our `space` and `depth` token values from `px` to `rem`. This is based on +the default browser font size which is `16px`. + +These updates just mean that we have moved the values from `px` to `rem`. The values have been +updated on a 1:1 basis. None of the base value have changed, just the unit. + +Below is a table to show what each token value is, what is corresponds too and what the new `rem` +value is in `px`: + +| px Value | rem Value | space Token | +| -------- | --------- | ----------- | +| 0 | 0 | zero | +| 4px | 0.25rem | xxxs | +| 8px | 0.5rem | xxs | +| 12px | 0.75rem | xs | +| 16px | 1rem | s | +| 24px | 1.5rem | m | +| 32px | 2rem | l | +| 40px | 2.5rem | xl | +| 64px | 4rem | xxl | +| 80px | 5rem | xxxl | + +You can convert a `px` value to a `rem` value by dividing your `px` value by `16`(if your default +browser font size hasn't been updated, the value will be `16`). + +For example: + +| Equation | rem Value | +| ----------- | --------- | +| `16px/16px` | `1rem` | +| `32px/16px` | `2rem` | +| `8px/16px` | `0.5rem` | + +#### Why Did We Make This Change? + +We wanted to move away from absolute units in tokens to relative units for better accessibility and +adaptability to different viewport/screen sizes. If a user changes their default browser font size, +these sizes should change along with it. Since `px` are a fixed unit and do not scale, utilizing +`rem` will allow these tokens to scale with a new default font size. diff --git a/modules/labs-react/search-form/lib/SearchForm.tsx b/modules/labs-react/search-form/lib/SearchForm.tsx index 6028f9c5c7..73251e20c5 100644 --- a/modules/labs-react/search-form/lib/SearchForm.tsx +++ b/modules/labs-react/search-form/lib/SearchForm.tsx @@ -139,8 +139,8 @@ const StyledSearchForm = styled('form')< position: showForm ? 'absolute' : 'relative', backgroundColor: showForm ? formCollapsedBackground : 'rgba(0, 0, 0, 0)', transition: 'background-color 120ms', - maxWidth: showForm ? 'none' : spaceNumbers.xl + spaceNumbers.xxs, - minWidth: spaceNumbers.xl + spaceNumbers.xs, + maxWidth: showForm ? 'none' : `${spaceNumbers.xl + spaceNumbers.xxs}rem`, + minWidth: `${spaceNumbers.xl + spaceNumbers.xs}rem`, overflow: showForm ? 'visible' : 'hidden', zIndex: 1, } @@ -233,8 +233,8 @@ const SearchInput = styled(TextInput)< const collapseStyles: CSSObject = isCollapsed ? { fontSize: '20px', - paddingLeft: spaceNumbers.xl + spaceNumbers.s, - paddingRight: spaceNumbers.xl + spaceNumbers.s, + paddingLeft: `${spaceNumbers.xl + spaceNumbers.s}rem`, + paddingRight: `${spaceNumbers.xl + spaceNumbers.s}rem`, maxWidth: 'none', minWidth: 0, backgroundColor: `rgba(0, 0, 0, 0)`, @@ -243,7 +243,7 @@ const SearchInput = styled(TextInput)< : { maxWidth: grow ? '100%' : maxWidth, minWidth: minWidth, - paddingLeft: spaceNumbers.xl + spaceNumbers.xxs, + paddingLeft: `${spaceNumbers.xl + spaceNumbers.xxs}rem`, paddingRight: space.xl, backgroundColor: inputColors.background, height: height, diff --git a/modules/preview-react/select/lib/SelectBase.tsx b/modules/preview-react/select/lib/SelectBase.tsx index 30d5f35b2f..9cd0f26723 100644 --- a/modules/preview-react/select/lib/SelectBase.tsx +++ b/modules/preview-react/select/lib/SelectBase.tsx @@ -177,10 +177,10 @@ export interface SelectBaseProps extends CoreSelectBaseProps, StyledType { shouldMenuAutoFocus?: boolean; } -export const buttonBorderWidth = 1; -export const buttonDefaultWidth = 280; +export const buttonBorderWidth = 0.0625; +export const buttonDefaultWidth = `${(spaceNumbers.xxxl * 7) / 2}rem`; -const menuIconSize = 24; +const menuIconSize = spaceNumbers.m; const buttonPadding = spaceNumbers.xxs - buttonBorderWidth; const SelectButton = styled('button')< @@ -188,7 +188,7 @@ const SelectButton = styled('button')< >( { ...type.levels.subtext.large, - border: `${buttonBorderWidth}px solid ${inputColors.border}`, + border: `${buttonBorderWidth}rem solid ${inputColors.border}`, cursor: 'default', display: 'block', backgroundColor: inputColors.background, @@ -197,8 +197,8 @@ const SelectButton = styled('button')< height: space.xl, outline: 'none', overflow: 'hidden', - padding: buttonPadding, - paddingRight: spaceNumbers.xxs + menuIconSize + buttonPadding, + padding: `${buttonPadding}rem`, + paddingRight: `${spaceNumbers.xxs + menuIconSize + buttonPadding}rem`, textAlign: 'left', textOverflow: 'ellipsis', transition: '0.2s box-shadow, 0.2s border-color', @@ -470,7 +470,7 @@ export const SelectBase = ({ icon={caretDownSmallIcon} color={disabled ? colors.licorice100 : colors.licorice200} colorHover={disabled ? colors.licorice100 : colors.licorice500} - size={menuIconSize} + size={`${menuIconSize}rem`} /> ); diff --git a/modules/preview-react/select/lib/SelectMenu.tsx b/modules/preview-react/select/lib/SelectMenu.tsx index e8b6ed54ff..20a185ebf7 100644 --- a/modules/preview-react/select/lib/SelectMenu.tsx +++ b/modules/preview-react/select/lib/SelectMenu.tsx @@ -14,7 +14,6 @@ import { import {colors, borderRadius, inputColors} from '@workday/canvas-kit-react/tokens'; import {SelectProps} from './Select'; -import {buttonBorderWidth} from './SelectBase'; import {MenuPlacement, MenuVisibility} from './types'; interface SelectMenuProps @@ -251,7 +250,7 @@ export const SelectMenu = ({ const handleWidthChange = useCallback(() => { if (buttonRef && buttonRef.current && visibility !== 'closed') { - const newMenuWidth = buttonRef.current.clientWidth + 2 * buttonBorderWidth; + const newMenuWidth = buttonRef.current.clientWidth + 2; setWidth(newMenuWidth); } }, [buttonRef, visibility]); diff --git a/modules/preview-react/text-area/lib/TextAreaField.tsx b/modules/preview-react/text-area/lib/TextAreaField.tsx index f4b18c5859..04e1609c23 100644 --- a/modules/preview-react/text-area/lib/TextAreaField.tsx +++ b/modules/preview-react/text-area/lib/TextAreaField.tsx @@ -6,7 +6,7 @@ import { borderRadius, CSSProperties, inputColors, - spaceNumbers, + space, type, } from '@workday/canvas-kit-react/tokens'; import { @@ -71,7 +71,7 @@ export const TextAreaField = createSubcomponent('textarea')({ borderRadius={borderRadius.m} minHeight={64} minWidth={280} - padding={spaceNumbers.xxs} // Compensate for border + padding={space.xxs} // Compensate for border margin={0} // Fix Safari /> ); diff --git a/modules/react/action-bar/stories/visual-testing/stories_action-bar.tsx b/modules/react/action-bar/stories/visual-testing/stories_action-bar.tsx index acbaa99065..28eb0241c7 100644 --- a/modules/react/action-bar/stories/visual-testing/stories_action-bar.tsx +++ b/modules/react/action-bar/stories/visual-testing/stories_action-bar.tsx @@ -30,7 +30,7 @@ export const ActionBarStates = () => ( style={{ background: colors.soap100, position: 'relative', - height: `${spaceNumbers.xl * 2.5}px`, + height: `${spaceNumbers.xxl + 2.25}rem`, marginBottom: space.xs, }} > @@ -87,9 +87,7 @@ export const ActionBarWithOverflowMenuStates = () => { props: {maximumVisible: items.length, containerWidth: 280}, }, ]} - columnProps={[ - {label: 'Example', props: {}}, - ]} + columnProps={[{label: 'Example', props: {}}]} > {({containerWidth, maximumVisible}) => ( diff --git a/modules/react/button/lib/BaseButton.tsx b/modules/react/button/lib/BaseButton.tsx index 0b1418da05..2d1576f6c4 100644 --- a/modules/react/button/lib/BaseButton.tsx +++ b/modules/react/button/lib/BaseButton.tsx @@ -120,7 +120,7 @@ const ButtonContainer = styled('button')( fontWeight: type.properties.fontWeights.bold, height: '48px', '& > * ': { - margin: `0 ${spaceNumbers.xxs / 2}px`, + margin: `0 ${space.xxxs}`, }, }; case 'medium': @@ -128,14 +128,14 @@ const ButtonContainer = styled('button')( return { height: space.xl, '& > * ': { - margin: `0 ${spaceNumbers.xxs / 2}px`, + margin: `0 ${space.xxxs}`, }, }; case 'small': return { height: space.l, '& > * ': { - margin: `0 ${spaceNumbers.xxxs / 2}px`, + margin: `0 ${spaceNumbers.xxxs / 2}rem`, }, }; case 'extraSmall': @@ -144,7 +144,7 @@ const ButtonContainer = styled('button')( fontWeight: type.properties.fontWeights.bold, height: space.m, '& > * ': { - margin: `0 ${spaceNumbers.xxxs / 2}px`, + margin: `0 ${spaceNumbers.xxxs / 2}rem`, }, }; } diff --git a/modules/react/checkbox/lib/Checkbox.tsx b/modules/react/checkbox/lib/Checkbox.tsx index 501a756051..44b8d974a3 100644 --- a/modules/react/checkbox/lib/Checkbox.tsx +++ b/modules/react/checkbox/lib/Checkbox.tsx @@ -11,7 +11,13 @@ import { useTheme, Themeable, } from '@workday/canvas-kit-react/common'; -import {borderRadius, colors, inputColors, spaceNumbers} from '@workday/canvas-kit-react/tokens'; +import { + borderRadius, + colors, + inputColors, + space, + spaceNumbers, +} from '@workday/canvas-kit-react/tokens'; import {SystemIcon} from '@workday/canvas-kit-react/icon'; import {checkSmallIcon} from '@workday/canvas-system-icons-web'; import {LabelText} from '@workday/canvas-kit-react/text'; @@ -60,11 +66,11 @@ export interface CheckboxProps extends Themeable { variant?: 'inverse' | undefined; } -const checkboxHeight = 18; -const checkboxTapArea = spaceNumbers.m; +const checkboxHeight = (spaceNumbers.xl - spaceNumbers.xxxs) / 2; +const checkboxTapArea = space.m; const checkboxContainerHeight = checkboxTapArea; -const checkboxLabelDistance = spaceNumbers.xs; -const checkboxWidth = 18; +const checkboxLabelDistance = `${spaceNumbers.xs}rem`; +const checkboxWidth = checkboxHeight; const rippleRadius = (spaceNumbers.l - checkboxWidth) / 2; const CheckboxContainer = styled('div')({ @@ -81,8 +87,8 @@ const CheckboxContainer = styled('div')({ */ const CheckboxInputWrapper = styled('div')>({ display: 'flex', - height: checkboxHeight, - minWidth: checkboxWidth, + height: `${checkboxHeight}rem`, + minWidth: `${checkboxWidth}rem`, marginTop: '3px', alignSelf: 'flex-start', }); @@ -91,9 +97,9 @@ const CheckboxRipple = styled('span')( }), ({disabled}) => ({ '&:hover ~ span:first-of-type': { - boxShadow: disabled ? undefined : `0 0 0 ${rippleRadius}px ${colors.soap200}`, + boxShadow: disabled ? undefined : `0 0 0 ${rippleRadius}rem ${colors.soap200}`, }, }), ({theme, error, variant}) => { @@ -253,13 +259,13 @@ const CheckboxBackground = styled('div')( borderRadius: borderRadius.s, boxSizing: 'border-box', display: 'flex', - height: checkboxHeight, + height: `${checkboxHeight}rem`, justifyContent: 'center', padding: '0px 2px', pointerEvents: 'none', position: 'absolute', transition: 'border 200ms ease, background 200ms', - width: checkboxWidth, + width: `${checkboxWidth}rem`, }, ({variant}) => ({ border: `1px solid ${variant === 'inverse' ? colors.soap300 : inputColors.border}`, diff --git a/modules/react/layout/spec/depth.spec.ts b/modules/react/layout/spec/depth.spec.ts index 4be6aeb1fc..d620a468fe 100644 --- a/modules/react/layout/spec/depth.spec.ts +++ b/modules/react/layout/spec/depth.spec.ts @@ -18,7 +18,7 @@ describe('Depth Style Props Function', () => { depth: 4, } as DepthStyleProps; const expected = { - boxShadow: '0px 4px 16px rgba(31, 38, 46, 0.12), 0px 8px 32px rgba(31, 38, 46, 0.08)', + boxShadow: '0 0.25rem 1rem rgba(31, 38, 46, 0.12), 0 0.5rem 2rem rgba(31, 38, 46, 0.08)', }; const depthStyles = depth(props); diff --git a/modules/react/layout/spec/flex.spec.ts b/modules/react/layout/spec/flex.spec.ts index 3d6e0d5237..3575da2de7 100644 --- a/modules/react/layout/spec/flex.spec.ts +++ b/modules/react/layout/spec/flex.spec.ts @@ -37,9 +37,9 @@ describe('Flex Style Props Function', () => { } as FlexStyleProps; const expected = { ...props, - gap: '16px', - rowGap: '24px', - columnGap: '32px', + gap: '1rem', + rowGap: '1.5rem', + columnGap: '2rem', }; const flexStyles = flex(props); diff --git a/modules/react/layout/spec/grid.spec.ts b/modules/react/layout/spec/grid.spec.ts index 3370219830..0924ebea9e 100644 --- a/modules/react/layout/spec/grid.spec.ts +++ b/modules/react/layout/spec/grid.spec.ts @@ -36,9 +36,9 @@ describe('Grid Style Props Function', () => { } as GridStyleProps; const expected = { ...props, - gridGap: '16px', - gridRowGap: '24px', - gridColumnGap: '32px', + gridGap: '1rem', + gridRowGap: '1.5rem', + gridColumnGap: '2rem', }; const gridStyles = grid(props); diff --git a/modules/react/layout/spec/space.spec.ts b/modules/react/layout/spec/space.spec.ts index dc21755f72..c96f219904 100644 --- a/modules/react/layout/spec/space.spec.ts +++ b/modules/react/layout/spec/space.spec.ts @@ -7,9 +7,9 @@ describe('Space Style Props Function', () => { const props = { position: 'absolute', children: null, - margin: '12px', + margin: '0.75rem', }; - const expected = {margin: '12px'}; + const expected = {margin: '0.75rem'}; const colorStyles = space(props); expect(colorStyles).toEqual(expected); @@ -18,16 +18,16 @@ describe('Space Style Props Function', () => { context('given standard space props', () => { it('should handle generic props (string and number)', () => { const props = { - margin: 24, - marginTop: '12px', - marginRight: 12, - marginBottom: '12px', - marginLeft: 12, - padding: '32px', - paddingTop: 16, - paddingRight: '16px', - paddingBottom: 16, - paddingLeft: '16px', + margin: 1.5, + marginTop: '0.75rem', + marginRight: 0.75, + marginBottom: '0.75rem', + marginLeft: 0.75, + padding: '2rem', + paddingTop: 1, + paddingRight: '1rem', + paddingBottom: 1, + paddingLeft: '1rem', }; const expected = props; const spaceStyles = space(props); @@ -49,16 +49,16 @@ describe('Space Style Props Function', () => { paddingLeft: 'xxxl', }; const expected = { - margin: '0px', - marginTop: '4px', - marginRight: '8px', - marginBottom: '12px', - marginLeft: '16px', - padding: '24px', - paddingTop: '32px', - paddingRight: '40px', - paddingBottom: '64px', - paddingLeft: '80px', + margin: '0', + marginTop: '0.25rem', + marginRight: '0.5rem', + marginBottom: '0.75rem', + marginLeft: '1rem', + padding: '1.5rem', + paddingTop: '2rem', + paddingRight: '2.5rem', + paddingBottom: '4rem', + paddingLeft: '5rem', }; const spaceStyles = space(props); @@ -71,10 +71,10 @@ describe('Space Style Props Function', () => { paddingY: 'm', }; const expected = { - paddingTop: '24px', - paddingRight: '16px', - paddingBottom: '24px', - paddingLeft: '16px', + paddingTop: '1.5rem', + paddingRight: '1rem', + paddingBottom: '1.5rem', + paddingLeft: '1rem', }; const spaceStyles = space(props); @@ -87,10 +87,10 @@ describe('Space Style Props Function', () => { marginY: 'xl', }; const expected = { - marginTop: '40px', - marginRight: '32px', - marginBottom: '40px', - marginLeft: '32px', + marginTop: '2.5rem', + marginRight: '2rem', + marginBottom: '2.5rem', + marginLeft: '2rem', }; const spaceStyles = space(props); diff --git a/modules/react/radio/lib/Radio.tsx b/modules/react/radio/lib/Radio.tsx index 5208705b37..5d4d76fbab 100644 --- a/modules/react/radio/lib/Radio.tsx +++ b/modules/react/radio/lib/Radio.tsx @@ -8,7 +8,13 @@ import { Themeable, useUniqueId, } from '@workday/canvas-kit-react/common'; -import {borderRadius, colors, inputColors, spaceNumbers} from '@workday/canvas-kit-react/tokens'; +import { + borderRadius, + colors, + inputColors, + space, + spaceNumbers, +} from '@workday/canvas-kit-react/tokens'; import {LabelText} from '@workday/canvas-kit-react/text'; export interface RadioProps extends Themeable { @@ -47,13 +53,13 @@ export interface RadioProps extends Themeable { variant?: 'inverse' | undefined; } -const radioBorderRadius = 9; -const radioDot = 8; -const radioHeight = 18; -const radioTapArea = spaceNumbers.m; +const radioBorderRadius = `${spaceNumbers.xxs + 0.0625}rem`; +const radioDot = space.xxs; +const radioHeight = (spaceNumbers.xl - spaceNumbers.xxxs) / 2; +const radioTapArea = space.m; const radioContainerHeight = radioTapArea; -const radioLabelDistance = spaceNumbers.xs; -const radioWidth = 18; +const radioLabelDistance = space.xs; +const radioWidth = radioHeight; const rippleRadius = (spaceNumbers.l - radioWidth) / 2; const RadioContainer = styled('div')({ @@ -70,17 +76,17 @@ const RadioContainer = styled('div')({ */ const RadioInputWrapper = styled('div')>({ display: 'flex', - height: radioHeight, - width: radioWidth, + height: `${radioHeight}rem`, + width: `${radioWidth}rem`, }); const RadioRipple = styled('span')>( { borderRadius: borderRadius.circle, boxShadow: `0 0 0 0 ${colors.soap200}`, - height: radioHeight, + height: `${radioHeight}rem`, transition: 'box-shadow 150ms ease-out', - width: radioWidth, + width: `${radioWidth}rem`, position: 'absolute', pointerEvents: 'none', // This is a decorative element we don't want it to block clicks to input }, @@ -129,7 +135,7 @@ const RadioInput = styled('input')( // `span:first-of-type` refers to `RadioRipple`, the light grey // element that animates around the component on hover '&:hover ~ span:first-of-type': { - boxShadow: disabled ? undefined : `0 0 0 ${rippleRadius}px ${colors.soap200}`, + boxShadow: disabled ? undefined : `0 0 0 ${rippleRadius}rem ${colors.soap200}`, }, // `div:first-of-type` refers to the `RadioBackground`, the visual facade of the @@ -212,13 +218,13 @@ const RadioBackground = styled('div')( borderWidth: '1px', boxSizing: 'border-box', display: 'flex', - height: radioHeight, + height: `${radioHeight}rem`, justifyContent: 'center', padding: '0px 2px', pointerEvents: 'none', position: 'absolute', transition: 'border 200ms ease, background 200ms', - width: radioWidth, + width: `${radioWidth}rem`, }, ({ checked, diff --git a/modules/react/select/lib/Select.tsx b/modules/react/select/lib/Select.tsx index c65714ee1e..1e424c6d37 100644 --- a/modules/react/select/lib/Select.tsx +++ b/modules/react/select/lib/Select.tsx @@ -8,14 +8,7 @@ import { styled, Themeable, } from '@workday/canvas-kit-react/common'; -import { - colors, - borderRadius, - inputColors, - spaceNumbers, - type, - space, -} from '@workday/canvas-kit-react/tokens'; +import {colors, borderRadius, inputColors, type, space} from '@workday/canvas-kit-react/tokens'; import {caretDownSmallIcon} from '@workday/canvas-system-icons-web'; import {SystemIcon} from '@workday/canvas-kit-react/icon'; import {SelectOption} from './SelectOption'; @@ -55,7 +48,7 @@ const StyledSelect = styled('select')( height: space.xl, minWidth: 280, transition: '0.2s box-shadow, 0.2s border-color', - padding: spaceNumbers.xxs, + padding: space.xxs, margin: 0, // Fix Safari MozAppearance: 'none', // FF bugfix: hide arrow so it doesn't show under ours WebkitAppearance: 'none', diff --git a/modules/react/table/lib/TableRow.tsx b/modules/react/table/lib/TableRow.tsx index 85ae5c7f7a..dfa8c85325 100644 --- a/modules/react/table/lib/TableRow.tsx +++ b/modules/react/table/lib/TableRow.tsx @@ -100,7 +100,7 @@ const StyledTableRow = styled('tr')( fontSize: 13, borderRight: cellBorder, borderBottom: cellBorder, - height: spaceNumbers.xl + spaceNumbers.xxs, + height: `${spaceNumbers.xl + spaceNumbers.xxs}rem`, boxSizing: 'border-box', transition: 'background-color 0.2s', }, diff --git a/modules/react/text-area/lib/TextArea.tsx b/modules/react/text-area/lib/TextArea.tsx index 52c00d66b6..277c3d1610 100644 --- a/modules/react/text-area/lib/TextArea.tsx +++ b/modules/react/text-area/lib/TextArea.tsx @@ -8,7 +8,13 @@ import { styled, Themeable, } from '@workday/canvas-kit-react/common'; -import {borderRadius, inputColors, spaceNumbers, type} from '@workday/canvas-kit-react/tokens'; +import { + borderRadius, + inputColors, + space, + spaceNumbers, + type, +} from '@workday/canvas-kit-react/tokens'; export interface TextAreaProps extends Themeable, GrowthBehavior { /** @@ -59,10 +65,10 @@ const StyledTextArea = styled('textarea')( backgroundColor: inputColors.background, borderRadius: borderRadius.m, boxSizing: 'border-box', - minHeight: 64, - minWidth: 280, + minHeight: space.xxl, + minWidth: `${spaceNumbers.xxxl * 3 + spaceNumbers.xl}rem`, transition: '0.2s box-shadow, 0.2s border-color', - padding: spaceNumbers.xxs, // Compensate for border + padding: space.xxs, // Compensate for border margin: 0, // Fix Safari '&::webkit-resizer': { display: 'none', diff --git a/modules/react/text-input/lib/TextInput.tsx b/modules/react/text-input/lib/TextInput.tsx index e7d46449b2..cec1f3bd23 100644 --- a/modules/react/text-input/lib/TextInput.tsx +++ b/modules/react/text-input/lib/TextInput.tsx @@ -33,7 +33,7 @@ const StyledTextInput = styled('input')< boxSizing: 'border-box', height: 40, transition: '0.2s box-shadow, 0.2s border-color', - padding: spaceNumbers.xxs, // Compensate for border + padding: `${spaceNumbers.xxs}rem`, // Compensate for border margin: 0, // Fix Safari '&::placeholder': { color: inputColors.placeholder, diff --git a/modules/react/tokens/README.md b/modules/react/tokens/README.md index 21493e2230..9a257f0f8a 100644 --- a/modules/react/tokens/README.md +++ b/modules/react/tokens/README.md @@ -133,42 +133,42 @@ Border Radius variables are in a "t-shirt size" format. Border Radius values are Space variables are in a "t-shirt size" format. Space values are in `px` format (`space`) or number format (`spaceNumbers`). -| Variable | Size (px) | Size (number) | -| -------- | --------- | ------------- | -| `xxxs` | `'4px'` | `4` | -| `xxs` | `'8px'` | `8` | -| `xs` | `'12px'` | `12` | -| `s` | `'16px'` | `16` | -| `m` | `'24px'` | `24` | -| `l` | `'32px'` | `32` | -| `xl` | `'40px'` | `40` | -| `xxl` | `'64px'` | `64` | -| `xxxl` | `'80px'` | `80` | +| Variable | Size (rem) | Size (number) | +| -------- | ----------- | ------------- | +| `xxxs` | `'0.25rem'` | `0.25` | +| `xxs` | `'0.5rem'` | `0.5` | +| `xs` | `'0.75rem'` | `0.75` | +| `s` | `'1rem'` | `1` | +| `m` | `'1.5rem'` | `1.5` | +| `l` | `'2rem'` | `2` | +| `xl` | `'2.5rem'` | `2.5` | +| `xxl` | `'4rem'` | `4` | +| `xxxl` | `'5rem'` | `5` | The following space types are also provided: `CanvasSpace`, `CanvasSpaceValues`, `CanvasSpaceNumbers`, `CanvasSpaceNumberValues` Below are descriptions of these types: -| Name | Description | -| ------------------------- | -------------------------------------------- | -| `CanvasSpace` | `space` object with string px values | -| `CanvasSpaceValues` | string px values for CanvasSpace | -| `CanvasSpaceNumbers` | `spaceNumbers` object with numeric px values | -| `CanvasSpaceNumberValues` | numeric px values for CanvasSpaceNumbers | +| Name | Description | +| ------------------------- | --------------------------------------------- | +| `CanvasSpace` | `space` object with string rem values | +| `CanvasSpaceValues` | string rem values for CanvasSpace | +| `CanvasSpaceNumbers` | `spaceNumbers` object with numeric rem values | +| `CanvasSpaceNumberValues` | numeric rem values for CanvasSpaceNumbers | ### Usage ```tsx import {space, spaceNumbers} from '@workday/canvas-kit-react/tokens'; -const iconSize = 20; +const iconSize = 1.25; const buttonSyles = { paddingTop: space.xs, paddingRight: space.s, paddingBottom: space.xs, - paddingLeft: spaceNumbers.s + iconSize, + paddingLeft: `${spaceNumbers.s + iconSize}rem`, }; ``` diff --git a/modules/react/tokens/index.ts b/modules/react/tokens/index.ts index 0b6fb18ead..f6e147f043 100644 --- a/modules/react/tokens/index.ts +++ b/modules/react/tokens/index.ts @@ -21,8 +21,7 @@ import { CanvasSpaceValues, CanvasSpaceNumberValues, CanvasSpaceNumbers, - spaceNumbers, -} from './lib/space'; + spaceNumbers} from './lib/space'; import {type, fontFamily, monoFontFamily, diff --git a/modules/react/tokens/lib/depth.ts b/modules/react/tokens/lib/depth.ts index 6014083dc0..c7cd8a470d 100644 --- a/modules/react/tokens/lib/depth.ts +++ b/modules/react/tokens/lib/depth.ts @@ -29,7 +29,7 @@ export type CanvasDepth = { * ``` */ 1: { - boxShadow: '0px 1px 4px rgba(31, 38, 46, 0.12), 0px 2px 8px rgba(31, 38, 46, 0.08)'; + boxShadow: '0 0.0625rem 0.25rem rgba(31, 38, 46, 0.12), 0 0.125rem 0.5rem rgba(31, 38, 46, 0.08)'; }; /** * ### Depth 2 @@ -45,7 +45,7 @@ export type CanvasDepth = { * ``` */ 2: { - boxShadow: '0px 2px 8px rgba(31, 38, 46, 0.12), 0px 4px 16px rgba(31, 38, 46, 0.08)'; + boxShadow: '0 0.125rem 0.5rem rgba(31, 38, 46, 0.12), 0 0.25rem 1rem rgba(31, 38, 46, 0.08)'; }; /** * ### Depth 3 @@ -61,7 +61,7 @@ export type CanvasDepth = { * ``` */ 3: { - boxShadow: '0px 3px 12px rgba(31, 38, 46, 0.12), 0px 6px 24px rgba(31, 38, 46, 0.08)'; + boxShadow: '0 0.1875rem 0.75rem rgba(31, 38, 46, 0.12), 0 0.375rem 1.5rem rgba(31, 38, 46, 0.08)'; }; /** * ### Depth 4 @@ -76,7 +76,7 @@ export type CanvasDepth = { * ``` */ 4: { - boxShadow: '0px 4px 16px rgba(31, 38, 46, 0.12), 0px 8px 32px rgba(31, 38, 46, 0.08)'; + boxShadow: '0 0.25rem 1rem rgba(31, 38, 46, 0.12), 0 0.5rem 2rem rgba(31, 38, 46, 0.08)'; }; /** * ### Depth 5 @@ -92,7 +92,7 @@ export type CanvasDepth = { * ``` */ 5: { - boxShadow: '0px 5px 20px rgba(31, 38, 46, 0.12), 0px 10px 40px rgba(31, 38, 46, 0.08)'; + boxShadow: '0 0.3125rem 1.25rem rgba(31, 38, 46, 0.12), 0 0.625rem 2.5rem rgba(31, 38, 46, 0.08)'; }; /** * ### Depth 6 @@ -108,7 +108,7 @@ export type CanvasDepth = { * ``` */ 6: { - boxShadow: '0px 6px 24px rgba(31, 38, 46, 0.12), 0px 12px 48px rgba(31, 38, 46, 0.08)'; + boxShadow: '0 0.375rem 1.5rem rgba(31, 38, 46, 0.12), 0 0.75rem 3rem rgba(31, 38, 46, 0.08)'; }; }; @@ -137,26 +137,30 @@ export type CanvasDepthValues = ValueOf; * ``` * */ + export const depth: CanvasDepth = { none: { boxShadow: 'none', }, 1: { - boxShadow: '0px 1px 4px rgba(31, 38, 46, 0.12), 0px 2px 8px rgba(31, 38, 46, 0.08)', + boxShadow: + '0 0.0625rem 0.25rem rgba(31, 38, 46, 0.12), 0 0.125rem 0.5rem rgba(31, 38, 46, 0.08)', }, 2: { - boxShadow: '0px 2px 8px rgba(31, 38, 46, 0.12), 0px 4px 16px rgba(31, 38, 46, 0.08)', + boxShadow: '0 0.125rem 0.5rem rgba(31, 38, 46, 0.12), 0 0.25rem 1rem rgba(31, 38, 46, 0.08)', }, 3: { - boxShadow: '0px 3px 12px rgba(31, 38, 46, 0.12), 0px 6px 24px rgba(31, 38, 46, 0.08)', + boxShadow: + '0 0.1875rem 0.75rem rgba(31, 38, 46, 0.12), 0 0.375rem 1.5rem rgba(31, 38, 46, 0.08)', }, 4: { - boxShadow: '0px 4px 16px rgba(31, 38, 46, 0.12), 0px 8px 32px rgba(31, 38, 46, 0.08)', + boxShadow: '0 0.25rem 1rem rgba(31, 38, 46, 0.12), 0 0.5rem 2rem rgba(31, 38, 46, 0.08)', }, 5: { - boxShadow: '0px 5px 20px rgba(31, 38, 46, 0.12), 0px 10px 40px rgba(31, 38, 46, 0.08)', + boxShadow: + '0 0.3125rem 1.25rem rgba(31, 38, 46, 0.12), 0 0.625rem 2.5rem rgba(31, 38, 46, 0.08)', }, 6: { - boxShadow: '0px 6px 24px rgba(31, 38, 46, 0.12), 0px 12px 48px rgba(31, 38, 46, 0.08)', + boxShadow: '0 0.375rem 1.5rem rgba(31, 38, 46, 0.12), 0 0.75rem 3rem rgba(31, 38, 46, 0.08)', }, }; diff --git a/modules/react/tokens/lib/space.ts b/modules/react/tokens/lib/space.ts index 72fa6923f2..f31da8b7e8 100644 --- a/modules/react/tokens/lib/space.ts +++ b/modules/react/tokens/lib/space.ts @@ -5,73 +5,111 @@ type ValueOf = T[keyof T]; // but writing it this way removes the `readonly` in the hint, // which adds a lot of visual noise and can be confusing for folks. -/** Type for the `space` object with keys and px values (strings) */ +/** Type for the `space` object with keys and rem values (strings) */ export type CanvasSpace = { - zero: '0px'; - xxxs: '4px'; - xxs: '8px'; - xs: '12px'; - s: '16px'; - m: '24px'; - l: '32px'; - xl: '40px'; - xxl: '64px'; - xxxl: '80px'; + zero: '0'; + xxxs: '0.25rem'; + xxs: '0.5rem'; + xs: '0.75rem'; + s: '1rem'; + m: '1.5rem'; + l: '2rem'; + xl: '2.5rem'; + xxl: '4rem'; + xxxl: '5rem'; }; /** Type for `CanvasSpace` keys */ export type CanvasSpaceKeys = keyof CanvasSpace; -/** The px values for CanvasSpace (strings) */ +/** The rem values for CanvasSpace (strings) */ export type CanvasSpaceValues = ValueOf; -/** An object of space keys and px values (strings) */ +/** + * An object of space keys and rem values (strings) + * + * Below is a table to show the equivalent values from `px` to `rem`. + * This is based on the default browser font size which is `16px`. + * + * | px Value | rem Value | space token | + * | --------- | --------- | ----------- | + * | 0 | 0 | zero | + * | 4px | 0.25rem | xxxs | + * | 8px | 0.5rem | xxs | + * | 12px | 0.75rem | xs | + * | 16px | 1rem | s | + * | 24px | 1.5rem | m | + * | 32px | 2rem | l | + * | 40px | 2.5rem | xl | + * | 64px | 4rem | xxl | + * | 80px | 5rem | xxxl | + * + * */ export const space: CanvasSpace = { - zero: '0px', - xxxs: '4px', - xxs: '8px', - xs: '12px', - s: '16px', - m: '24px', - l: '32px', - xl: '40px', - xxl: '64px', - xxxl: '80px', + zero: '0', + xxxs: '0.25rem', + xxs: '0.5rem', + xs: '0.75rem', + s: '1rem', + m: '1.5rem', + l: '2rem', + xl: '2.5rem', + xxl: '4rem', + xxxl: '5rem', }; -/** Type for the `spaceNumbers` object with keys and numeric px values (numbers) */ +/** Type for the `spaceNumbers` object with keys and numeric rem values (numbers) */ export type CanvasSpaceNumbers = { zero: 0; - xxxs: 4; - xxs: 8; - xs: 12; - s: 16; - m: 24; - l: 32; - xl: 40; - xxl: 64; - xxxl: 80; + xxxs: 0.25; + xxs: 0.5; + xs: 0.75; + s: 1; + m: 1.5; + l: 2; + xl: 2.5; + xxl: 4; + xxxl: 5; }; -/** The numeric px values for CanvasSpaceNumbers (numbers) */ +/** The numeric rem values for CanvasSpaceNumbers (numbers) */ export type CanvasSpaceNumberValues = ValueOf; /** - * An object of space keys and their numeric px values (numbers) - * - These are helpful when you need a raw numeric px value. + * An object of space keys and their numeric rem values (numbers) + * - These are helpful when you need a raw numeric rem value. * - Here's an example usage to perform calculations: * @example - * const buttonPaddingLeft = spaceNumbers.s + iconSize; + * ```tsx + * const buttonPaddingLeft = `${spaceNumbers.s + iconSize}rem`; + * ``` + * + * Below is a table to show the equivalent values from `px` to `rem`. + * This is based on the default browser font size which is `16px`. + * + * | px Value | rem Value | space token | + * | --------- | --------- | ----------- | + * | 0 | 0 | zero | + * | 4px | 0.25rem | xxxs | + * | 8px | 0.5rem | xxs | + * | 12px | 0.75rem | xs | + * | 16px | 1rem | s | + * | 24px | 1.5rem | m | + * | 32px | 2rem | l | + * | 40px | 2.5rem | xl | + * | 64px | 4rem | xxl | + * | 80px | 5rem | xxxl | + * */ export const spaceNumbers: CanvasSpaceNumbers = { zero: 0, - xxxs: 4, - xxs: 8, - xs: 12, - s: 16, - m: 24, - l: 32, - xl: 40, - xxl: 64, - xxxl: 80, + xxxs: 0.25, + xxs: 0.5, + xs: 0.75, + s: 1, + m: 1.5, + l: 2, + xl: 2.5, + xxl: 4, + xxxl: 5, }; diff --git a/modules/react/tooltip/lib/TooltipContainer.tsx b/modules/react/tooltip/lib/TooltipContainer.tsx index e7f40739a9..532dd01c48 100644 --- a/modules/react/tooltip/lib/TooltipContainer.tsx +++ b/modules/react/tooltip/lib/TooltipContainer.tsx @@ -50,7 +50,7 @@ export const TooltipContainer = styled('div')( ...type.levels.subtext.medium, display: 'inline-flex', position: 'relative', - padding: spaceNumbers.xxs + spaceNumbers.xxxs, + padding: space.xs, color: colors.frenchVanilla100, a: { color: colors.frenchVanilla100, @@ -61,7 +61,7 @@ export const TooltipContainer = styled('div')( content: '""', borderRadius: borderRadius.m, zIndex: -1, - margin: spaceNumbers.xxxs, + margin: space.xxxs, backgroundColor: 'rgba(0,0,0,.85)', position: 'absolute', top: 0, @@ -72,9 +72,9 @@ export const TooltipContainer = styled('div')( // offset tooltips by 2 pixels when a keyboard focus ring is detected '[data-whatinput=keyboard] &': { - padding: spaceNumbers.xxs + spaceNumbers.xxxs + 2, + padding: `${spaceNumbers.s - 0.125}rem`, ':before': { - margin: spaceNumbers.xxxs + 2, + margin: `${spaceNumbers.xxxs + 0.125}rem`, }, }, @@ -86,16 +86,16 @@ export const TooltipContainer = styled('div')( // Fix offsets based on placement '[data-popper-placement="top-start"] &, [data-popper-placement="bottom-start"] &': { - left: -spaceNumbers.xxxs, + left: `-${space.xxxs}`, }, '[data-popper-placement="top-end"] &, [data-popper-placement="bottom-end"] &': { - right: -spaceNumbers.xxxs, + right: `-${space.xxxs}`, }, '[data-popper-placement="left-start"] &, [data-popper-placement="right-start"] &': { - top: -spaceNumbers.xxxs, + top: `-${space.xxxs}`, }, '[data-popper-placement="left-end"] &, [data-popper-placement="right-end"] &': { - bottom: -spaceNumbers.xxxs, + bottom: `-${space.xxxs}`, }, }, ({transformOrigin = defaultTransformOrigin}) => { From 7da08179fd7195c7ce332a4e55c8c6d3cc133a75 Mon Sep 17 00:00:00 2001 From: Josh <44883293+josh-bagwell@users.noreply.github.com> Date: Fri, 16 Jun 2023 12:00:52 -0600 Subject: [PATCH 4/4] feat!: Remove Menu Preview (#2247) Removal of the `DeprecatedMenu` and `DeprecatedMenuItem` component in Preview. Fixes: #1993 A compound component version is already in Main. [category:Components] Release Note: This will not involve a codemod since the API has too many differences between the component being removed in Preview and the component in Main. ### BREAKING CHANGES To move from the Menu component in Preview to the Menu compound component in Main, please read [this discussion](https://github.com/Workday/canvas-kit/discussions/2063). Also, see [this](https://codesandbox.io/s/deprecatedmenu-and-menu-migration-gwi1ov) codesandbox that shows the differences between DeprecatedMenu and the Menu compound component. --- cypress/integration/MenuPreview.spec.ts | 55 --- modules/docs/mdx/10.0-UPGRADE_GUIDE.mdx | 71 +++ .../combobox/spec/Combobox.spec.tsx | 22 +- modules/labs-react/combobox/spec/SSR.spec.tsx | 4 +- .../labs-react/combobox/stories/stories.tsx | 14 +- .../search-form/stories/examples/Basic.tsx | 6 +- .../stories/examples/CustomTheme.tsx | 6 +- .../search-form/stories/examples/Grow.tsx | 6 +- .../search-form/stories/examples/RTL.tsx | 6 +- .../search-form/stories/examples/Theming.tsx | 6 +- modules/preview-react/index.ts | 1 - modules/preview-react/menu/LICENSE | 51 -- modules/preview-react/menu/README.md | 7 - modules/preview-react/menu/index.ts | 2 - modules/preview-react/menu/lib/Menu.tsx | 387 --------------- modules/preview-react/menu/lib/MenuItem.tsx | 358 -------------- modules/preview-react/menu/spec/Menu.spec.tsx | 442 ------------------ modules/preview-react/menu/spec/tsconfig.json | 3 - .../menu/stories/Menu.stories.mdx | 103 ---- .../menu/stories/examples/Basic.tsx | 74 --- .../menu/stories/examples/ContextMenu.tsx | 67 --- .../menu/stories/examples/CustomMenuItem.tsx | 15 - .../menu/stories/examples/Headers.tsx | 32 -- .../menu/stories/examples/Icons.tsx | 26 -- .../menu/stories/examples/ManyItems.tsx | 15 - .../menu/stories/stories_visualTesting.tsx | 111 ----- .../preview-react/menu/stories/tsconfig.json | 3 - modules/react/menu/index.ts | 2 +- modules/react/menu/lib/MenuItem.tsx | 10 +- .../stories/stories_Popper_VisualTesting.tsx | 14 +- 30 files changed, 120 insertions(+), 1799 deletions(-) delete mode 100644 cypress/integration/MenuPreview.spec.ts delete mode 100644 modules/preview-react/menu/LICENSE delete mode 100644 modules/preview-react/menu/README.md delete mode 100644 modules/preview-react/menu/index.ts delete mode 100644 modules/preview-react/menu/lib/Menu.tsx delete mode 100644 modules/preview-react/menu/lib/MenuItem.tsx delete mode 100644 modules/preview-react/menu/spec/Menu.spec.tsx delete mode 100644 modules/preview-react/menu/spec/tsconfig.json delete mode 100644 modules/preview-react/menu/stories/Menu.stories.mdx delete mode 100644 modules/preview-react/menu/stories/examples/Basic.tsx delete mode 100644 modules/preview-react/menu/stories/examples/ContextMenu.tsx delete mode 100644 modules/preview-react/menu/stories/examples/CustomMenuItem.tsx delete mode 100644 modules/preview-react/menu/stories/examples/Headers.tsx delete mode 100644 modules/preview-react/menu/stories/examples/Icons.tsx delete mode 100644 modules/preview-react/menu/stories/examples/ManyItems.tsx delete mode 100644 modules/preview-react/menu/stories/stories_visualTesting.tsx delete mode 100644 modules/preview-react/menu/stories/tsconfig.json diff --git a/cypress/integration/MenuPreview.spec.ts b/cypress/integration/MenuPreview.spec.ts deleted file mode 100644 index 3ac047e13f..0000000000 --- a/cypress/integration/MenuPreview.spec.ts +++ /dev/null @@ -1,55 +0,0 @@ -import * as h from '../helpers'; - -function getAssistiveFocus($menu: JQuery): JQuery { - const activeId = $menu.attr('aria-activedescendant'); - return $menu.find(`[id="${activeId}"]`); -} - -function assertOptionInView($option: JQuery) { - const option = $option[0]; - const menu = option.parentElement!; - - const optionBox = option.getBoundingClientRect(); - const menuBox = menu.getBoundingClientRect(); - - expect(optionBox) - .property('top') - .to.be.gte(menuBox.top); - expect(optionBox) - .property('bottom') - .to.be.lte(menuBox.bottom); -} - -describe('Menu', () => { - before(() => { - h.stories.visit(); - }); - - context('given the [Preview/Menu, Basic] example is rendered', () => { - beforeEach(() => { - h.stories.load('Preview/Menu', 'Basic'); - }); - - it('should not have any axe errors', () => { - cy.checkA11y(); - }); - - context('when the menu is opened', () => { - beforeEach(() => { - cy.findByText('Open Menu').click(); - }); - - context('when the up arrow is pressed', () => { - beforeEach(() => { - cy.focused().type('{uparrow}'); - }); - - it('should scroll the menu to show the active menu item', () => { - cy.findByRole('menu') - .pipe(getAssistiveFocus) - .should(assertOptionInView); - }); - }); - }); - }); -}); diff --git a/modules/docs/mdx/10.0-UPGRADE_GUIDE.mdx b/modules/docs/mdx/10.0-UPGRADE_GUIDE.mdx index 47c8420193..34495bce13 100644 --- a/modules/docs/mdx/10.0-UPGRADE_GUIDE.mdx +++ b/modules/docs/mdx/10.0-UPGRADE_GUIDE.mdx @@ -9,8 +9,16 @@ This guide contains an overview of the changes in Canvas Kit v10. Please any questions. - [Codemod](#codemod) +- [Removals](#removals) + - [Menu (Preview)](#menu-preview) +- [Deprecations](#deprecations) - [Token Updates](#token-updates) - [Space and Depth](#space-and-depth) +- [Component Updates](#component-updates) +- [Glossary](#glossary) + - [Main](#main) + - [Preview](#preview) + - [Labs](#labs) ## Codemod @@ -43,6 +51,25 @@ handled by the codemod are marked with 🤖 in the Upgrade Guide.** the changes from the codemod as a single isolated commit (separate from other changes) so you can roll back more easily if necessary. +## Removals + +Removals are deletions from our codebase and you can no longer consume this component. We've either +promoted or replaced a component or utility. + +### Menu (Preview) + +We've removed the `Menu` component in Preview. We recommend using the +[Menu](/components/popups/menu/) in the Main package instead; it is a +[compound component](/getting-started/for-developers/resources/compound-components/) and offers a +more flexible API. Please refer to this +[discussion](https://github.com/Workday/canvas-kit/discussions/2063) for instructions on how to +migrate from the `Menu` in Preview to the `Menu` in Main. + +This change is **not** handled by the codemod due to the differences in API between the `Menu` in +Preview and the `Menu` in Main. + +## Deprecations + ## Token Updates ### Space and Depth @@ -88,3 +115,47 @@ We wanted to move away from absolute units in tokens to relative units for bette adaptability to different viewport/screen sizes. If a user changes their default browser font size, these sizes should change along with it. Since `px` are a fixed unit and do not scale, utilizing `rem` will allow these tokens to scale with a new default font size. + +## Component Updates + +## Glossary + +### Main + +Our Main package of Canvas Kit tokens, components, and utilities at `@workday/canvas-kit-react` has +undergone a full design and a11y review and is approved for use in product. + +Breaking changes to code in Main will only occur during major version updates and will always be +communicated in advance and accompanied by migration strategies. + +--- + +### Preview + +Our Preview package of Canvas Kit tokens, components, and utilities at +`@workday/canvas-kit-preview-react` has undergone a full design and a11y review and is approved for +use in product, but may not be up to the high code standards upheld in the [Main](#main) package. +Preview is analagous to code in beta. + +Breaking changes are unlikely, but possible, and can be deployed to Preview at any time without +triggering a major version update, though such changes will be communicated in advance and +accompanied by migration strategies. + +Generally speaking, our goal is to eventually promote code from Preview to [Main](#main). +Occasionally, a component with the same name will exist in both [Main](#main) and Preview (for +example, see Segmented Control in [Preview](/components/buttons/segmented-control/) and +[Main](https://d2krrudi3mmzzw.cloudfront.net/v8/?path=/docs/components-buttons-segmented-control--basic)). +In these cases, Preview serves as a staging ground for an improved version of the component with a +different API. The component in [Main](#main) will eventually be replaced with the one in Preview. + +--- + +### Labs + +Our Labs package of Canvas Kit tokens, components, and utilities at `@workday/canvas-kit-labs-react` +has **not** undergone a full design and a11y review. Labs serves as an incubator space for new and +experimental code and is analagous to code in alpha. + +Breaking changes can be deployed to Labs at any time without triggering a major version update and +may not be subject to the same rigor in communcation and migration strategies reserved for breaking +changes in [Preview](#preview) and [Main](#main). diff --git a/modules/labs-react/combobox/spec/Combobox.spec.tsx b/modules/labs-react/combobox/spec/Combobox.spec.tsx index 4c483bd176..ead4153b88 100644 --- a/modules/labs-react/combobox/spec/Combobox.spec.tsx +++ b/modules/labs-react/combobox/spec/Combobox.spec.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import {Combobox, ComboboxProps} from '../lib/Combobox'; -import {DeprecatedMenuItem} from '@workday/canvas-kit-preview-react/menu'; +import {StyledMenuItem} from '@workday/canvas-kit-react/menu'; import {TextInput} from '@workday/canvas-kit-react/text-input'; import {render, fireEvent} from '@testing-library/react'; @@ -13,7 +13,7 @@ describe('Combobox', () => { beforeEach(() => { defaultProps = { - autocompleteItems: [, ], + autocompleteItems: [, ], children: , }; }); @@ -88,7 +88,7 @@ describe('Combobox', () => { it('should render correct status text', () => { const screen = renderCombobox({ ...defaultProps, - autocompleteItems: [, ], + autocompleteItems: [, ], getStatusText(listCount: number) { return `Item count: ${listCount}`; }, @@ -113,7 +113,7 @@ describe('Combobox', () => { test('Call callback function when enter is pressed', async () => { const menuText = 'menuText'; - const autocompleteItems = [{menuText}]; + const autocompleteItems = [{menuText}]; const {findByRole} = renderCombobox({ ...defaultProps, autocompleteItems, @@ -132,9 +132,9 @@ describe('Combobox', () => { test('Call callback function when list item is clicked', async () => { const menuText = 'menuText'; const autocompleteItems = [ - + {menuText} - , + , ]; const {findByRole, findByText} = renderCombobox({ ...defaultProps, @@ -152,9 +152,9 @@ describe('Combobox', () => { const menuText = 'menuText'; const id = 'my-id'; const autocompleteItems = [ - + {menuText} - , + , ]; const {findByRole} = renderCombobox({ ...defaultProps, @@ -176,7 +176,7 @@ describe('Combobox', () => { test('Do not call callback function when meta key is pressed', async () => { const menuText = 'menuText'; const id = 'my-id'; - const autocompleteItems = [{menuText}]; + const autocompleteItems = [{menuText}]; const {findByRole} = renderCombobox({ ...defaultProps, autocompleteItems, @@ -233,9 +233,9 @@ describe('Combobox', () => { test('Do not call blur function when clicking on disabled menu item', async () => { const menuText = 'menuText'; const autocompleteItems = [ - + {menuText} - , + , ]; const {findByRole, findByText} = renderCombobox({ ...defaultProps, diff --git a/modules/labs-react/combobox/spec/SSR.spec.tsx b/modules/labs-react/combobox/spec/SSR.spec.tsx index 245b65bfa6..e4050e34ae 100644 --- a/modules/labs-react/combobox/spec/SSR.spec.tsx +++ b/modules/labs-react/combobox/spec/SSR.spec.tsx @@ -4,12 +4,12 @@ import React from 'react'; import {renderToString} from 'react-dom/server'; import {Combobox} from '../lib/Combobox'; -import {DeprecatedMenuItem} from '@workday/canvas-kit-preview-react/menu'; +import {StyledMenuItem} from '@workday/canvas-kit-react/menu'; import {TextInput} from '@workday/canvas-kit-react/text-input'; describe('InputProvider', () => { it('should render on a server without crashing', () => { - const autocompleteItems = [test]; + const autocompleteItems = [test]; const ssrRender = () => renderToString( diff --git a/modules/labs-react/combobox/stories/stories.tsx b/modules/labs-react/combobox/stories/stories.tsx index 5ba2488c9f..9ab7f83dd0 100644 --- a/modules/labs-react/combobox/stories/stories.tsx +++ b/modules/labs-react/combobox/stories/stories.tsx @@ -7,21 +7,21 @@ import { ComboBoxMenuItemGroup, } from '@workday/canvas-kit-labs-react/combobox'; import {FormField} from '@workday/canvas-kit-react/form-field'; -import {DeprecatedMenuItem, DeprecatedMenuItemProps} from '@workday/canvas-kit-preview-react/menu'; +import {StyledMenuItem, MenuItemProps} from '@workday/canvas-kit-react/menu'; import {TextInput} from '@workday/canvas-kit-react/text-input'; import {CanvasProvider, ContentDirection} from '@workday/canvas-kit-react/common'; const autocompleteResult = ( textModifier: number, - isDisabled: boolean -): ReactElement => ( - + disabled: boolean +): ReactElement => ( + Result{' '} number {' '} {textModifier} - + ); const simpleAutoComplete = (count: number, showDisabledItems, total = 5) => @@ -35,9 +35,9 @@ const groupOfResults = ( groupHeading: ReactNode = 'Group' ): ComboBoxMenuItemGroup => ({ header: ( - + {groupHeading} - + ), items: simpleAutoComplete(count, showDisabledItems, 10), }); diff --git a/modules/labs-react/search-form/stories/examples/Basic.tsx b/modules/labs-react/search-form/stories/examples/Basic.tsx index 206b6672c8..dd0ae90387 100644 --- a/modules/labs-react/search-form/stories/examples/Basic.tsx +++ b/modules/labs-react/search-form/stories/examples/Basic.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import {DeprecatedMenuItem} from '@workday/canvas-kit-preview-react/menu'; +import {StyledMenuItem} from '@workday/canvas-kit-react/menu'; import {SearchForm} from '@workday/canvas-kit-labs-react/search-form'; import {Flex} from '@workday/canvas-kit-react/layout'; @@ -29,9 +29,7 @@ export const Basic = () => { const [wineList, setWineList] = React.useState(initialWineList); // Tracking the input value for onSubmit const [searchInput, setSearchInput] = React.useState(''); - const menuItems = wineList.map(wine => ( - {wine} - )); + const menuItems = wineList.map(wine => {wine}); const filterMenuItems = e => { setSearchInput(e.target.value); diff --git a/modules/labs-react/search-form/stories/examples/CustomTheme.tsx b/modules/labs-react/search-form/stories/examples/CustomTheme.tsx index f9e18c3e34..6009959168 100644 --- a/modules/labs-react/search-form/stories/examples/CustomTheme.tsx +++ b/modules/labs-react/search-form/stories/examples/CustomTheme.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import {DeprecatedMenuItem} from '@workday/canvas-kit-preview-react/menu'; +import {StyledMenuItem} from '@workday/canvas-kit-react/menu'; import {SearchForm, SearchThemeAttributes} from '@workday/canvas-kit-labs-react/search-form'; import {Flex} from '@workday/canvas-kit-react/layout'; import {colors} from '@workday/canvas-kit-react/tokens'; @@ -30,9 +30,7 @@ export const CustomTheme = () => { const [wineList, setWineList] = React.useState(initialWineList); // Tracking the input value for onSubmit const [searchInput, setSearchInput] = React.useState(''); - const menuItems = wineList.map(wine => ( - {wine} - )); + const menuItems = wineList.map(wine => {wine}); const filterMenuItems = e => { setSearchInput(e.target.value); diff --git a/modules/labs-react/search-form/stories/examples/Grow.tsx b/modules/labs-react/search-form/stories/examples/Grow.tsx index 43f10c2c48..68a8fefc17 100644 --- a/modules/labs-react/search-form/stories/examples/Grow.tsx +++ b/modules/labs-react/search-form/stories/examples/Grow.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import {DeprecatedMenuItem} from '@workday/canvas-kit-preview-react/menu'; +import {StyledMenuItem} from '@workday/canvas-kit-react/menu'; import {SearchForm} from '@workday/canvas-kit-labs-react/search-form'; import {Flex} from '@workday/canvas-kit-react/layout'; @@ -29,9 +29,7 @@ export const Grow = () => { const [wineList, setWineList] = React.useState(initialWineList); // Tracking the input value for onSubmit const [searchInput, setSearchInput] = React.useState(''); - const menuItems = wineList.map(wine => ( - {wine} - )); + const menuItems = wineList.map(wine => {wine}); const filterMenuItems = e => { setSearchInput(e.target.value); diff --git a/modules/labs-react/search-form/stories/examples/RTL.tsx b/modules/labs-react/search-form/stories/examples/RTL.tsx index f78d6a88ed..5ab2adf6f5 100644 --- a/modules/labs-react/search-form/stories/examples/RTL.tsx +++ b/modules/labs-react/search-form/stories/examples/RTL.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import {DeprecatedMenuItem} from '@workday/canvas-kit-preview-react/menu'; +import {StyledMenuItem} from '@workday/canvas-kit-react/menu'; import {SearchForm} from '@workday/canvas-kit-labs-react/search-form'; import {Flex} from '@workday/canvas-kit-react/layout'; import {CanvasProvider, ContentDirection} from '@workday/canvas-kit-react/common'; @@ -30,9 +30,7 @@ export const RTL = () => { const [wineList, setWineList] = React.useState(initialWineList); // Tracking the input value for onSubmit const [searchInput, setSearchInput] = React.useState(''); - const menuItems = wineList.map(wine => ( - {wine} - )); + const menuItems = wineList.map(wine => {wine}); const filterMenuItems = e => { setSearchInput(e.target.value); diff --git a/modules/labs-react/search-form/stories/examples/Theming.tsx b/modules/labs-react/search-form/stories/examples/Theming.tsx index 93d2a56027..374171f1c1 100644 --- a/modules/labs-react/search-form/stories/examples/Theming.tsx +++ b/modules/labs-react/search-form/stories/examples/Theming.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import {DeprecatedMenuItem} from '@workday/canvas-kit-preview-react/menu'; +import {StyledMenuItem} from '@workday/canvas-kit-react/menu'; import {SearchForm, SearchTheme} from '@workday/canvas-kit-labs-react/search-form'; import {Flex} from '@workday/canvas-kit-react/layout'; @@ -29,9 +29,7 @@ export const Theming = () => { const [wineList, setWineList] = React.useState(initialWineList); // Tracking the input value for onSubmit const [searchInput, setSearchInput] = React.useState(''); - const menuItems = wineList.map(wine => ( - {wine} - )); + const menuItems = wineList.map(wine => {wine}); const filterMenuItems = e => { setSearchInput(e.target.value); diff --git a/modules/preview-react/index.ts b/modules/preview-react/index.ts index d9469b0844..3ba6403704 100644 --- a/modules/preview-react/index.ts +++ b/modules/preview-react/index.ts @@ -1,6 +1,5 @@ export * from './color-picker'; export * from './form-field'; -export * from './menu'; export * from './pill'; export * from './segmented-control'; export * from './select'; diff --git a/modules/preview-react/menu/LICENSE b/modules/preview-react/menu/LICENSE deleted file mode 100644 index 5bcbbab3b9..0000000000 --- a/modules/preview-react/menu/LICENSE +++ /dev/null @@ -1,51 +0,0 @@ -Apache License, Version 2.0 Apache License Version 2.0, January 2004 - -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. -"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. -"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. -"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. -"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. -"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. -"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. -"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). -"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. -"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. - -2. Grant of Copyright License. -Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. -Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. -You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: -You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. - -5. Submission of Contributions. -Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. - -6. Trademarks. -This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. -Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. -In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. -While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -©2020. Workday, Inc. All rights reserved. Workday and the Workday logo are registered trademarks of Workday, Inc. All other brand and product names are trademarks or registered trademarks of their respective holders. - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/modules/preview-react/menu/README.md b/modules/preview-react/menu/README.md deleted file mode 100644 index 791535fd52..0000000000 --- a/modules/preview-react/menu/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Canvas Kit Menu - -View the -[documentation for Menu](https://workday.github.io/canvas-kit/?path=/docs/preview-menu-react--default) -on Storybook. - -[> Workday Design Reference](https://design.workday.com/components/popups/menus) diff --git a/modules/preview-react/menu/index.ts b/modules/preview-react/menu/index.ts deleted file mode 100644 index 7f47c43277..0000000000 --- a/modules/preview-react/menu/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './lib/Menu'; -export * from './lib/MenuItem'; diff --git a/modules/preview-react/menu/lib/Menu.tsx b/modules/preview-react/menu/lib/Menu.tsx deleted file mode 100644 index 95015b533f..0000000000 --- a/modules/preview-react/menu/lib/Menu.tsx +++ /dev/null @@ -1,387 +0,0 @@ -import * as React from 'react'; -import styled from '@emotion/styled'; - -import {DeprecatedMenuItemProps} from './MenuItem'; -import {Card} from '@workday/canvas-kit-react/card'; -import {commonColors, space, borderRadius} from '@workday/canvas-kit-react/tokens'; -import {hideMouseFocus, GrowthBehavior, generateUniqueId} from '@workday/canvas-kit-react/common'; - -/** - * ### Deprecated Menu - * - * As of Canvas Kit v8, Menu is being deprecated. - * It will be removed in v10. Please see the - * [upgrade guide](https://workday.github.io/canvas-kit/?path=/story/welcome-upgrade-guides-v8-0--page) - * for more information. - */ -export interface DeprecatedMenuProps - extends GrowthBehavior, - React.HTMLAttributes { - /** - * The DeprecatedMenuItem children of the DeprecatedMenu (must be at least one). Also accepts other components which share the same interface as `DeprecatedMenuItem`. - */ - children?: - | React.ReactElement - | React.ReactElement[]; - /** - * If true, set the DeprecatedMenu to the open state. Useful for showing and hiding the DeprecatedMenu from a parent component such as a menu button. - * @default true - */ - isOpen?: boolean; - /** - * The width of the DeprecatedMenu. If no value is provided, the DeprecatedMenu will collapse around its content. - */ - width?: number | string; - /** - * The function called when a menu item is selected. - */ - onSelect?: () => void; - /** - * The function called when the DeprecatedMenu should close. This is called after a menu item is selected or if the escape shortcut key is used. This will not fire if the menu item sets `shouldClose` to false. - */ - onClose?: () => void; - /** - * The zero-based index of the menu item which should initially receive focus. - */ - initialSelectedItem?: number; - /** - * The unique id of the DeprecatedMenu used for ARIA and HTML `id` attributes. - */ - id?: string; - /** - * The HTML `id` of the element that labels the DeprecatedMenu. Often used with menu buttons. - */ - 'aria-labelledby'?: string; -} - -/** - * ### Deprecated Menu State - * - * As of Canvas Kit v8, Menu is being deprecated. - * It will be removed in v10. Please see the - * [upgrade guide](https://workday.github.io/canvas-kit/?path=/story/welcome-upgrade-guides-v8-0--page) - * for more information. - */ -export interface DeprecatedMenuState { - selectedItemIndex: number; -} - -const List = styled('ul')({ - background: commonColors.background, - borderRadius: borderRadius.m, - padding: 0, - margin: `${space.xxs} 0`, - '&:focus': { - outline: 'none', - }, - ...hideMouseFocus, -}); - -/** - * As of Canvas Kit v8, Menu is being deprecated. - * It will be removed in v10. Please see the [upgrade - * guide](https://workday.github.io/canvas-kit/?path=/story/welcome-upgrade-guides-v8-0--page) for - * more information. - * - * `DeprecatedMenu` renders a styled `
    ` element within a {@link Card} and follows - * the [Active Menu - * pattern](https://www.w3.org/TR/wai-aria-practices/examples/menu-button/menu-button-actions-active-descendant.html) - * using `aria-activedescendant`. - * - * Undocumented props are spread to the underlying `
      ` element. - * - * @deprecated - */ -export class DeprecatedMenu extends React.Component { - private id = generateUniqueId(); - private animateId!: number; - - private menuRef: React.RefObject; - private firstCharacters!: string[]; - - constructor(props: DeprecatedMenuProps) { - super(props); - this.menuRef = React.createRef(); - - const selected = this.getInitialSelectedItem(); - - // We track the active menu item by index so we can avoid setting a bunch of refs - // for doing things like selecting an item by first character (or really calling .focus() at all) - // It allows us to use the activedescendant design pattern - // https://www.w3.org/TR/wai-aria-practices/examples/menu-button/menu-button-actions-active-descendant.html - this.state = { - selectedItemIndex: selected, - }; - } - - componentDidUpdate(prevProps: DeprecatedMenuProps) { - if (this.props.children !== prevProps.children) { - this.setFirstCharacters(); - this.setInitialSelectedItem(); - } - if (this.props.isOpen && !prevProps.isOpen) { - this.setInitialSelectedItem(); - } - this.animateId = requestAnimationFrame(() => { - if (this.props.isOpen && this.menuRef.current) { - this.menuRef.current.focus(); - } - }); - } - - componentDidMount() { - console.warn( - `This component is being deprecated and will be removed in Canvas Kit V9.\n - For more information, please see the V8 upgrade guide:\n - https://workday.github.io/canvas-kit/?path=/story/welcome-upgrade-guides-v8-0--page - ` - ); - - this.setFirstCharacters(); - this.setInitialSelectedItem(); - } - - componentWillUnmount() { - cancelAnimationFrame(this.animateId); - } - - public render() { - // TODO: Standardize on prop spread location (see #150) - const { - id = this.id, - isOpen = true, - children, - 'aria-labelledby': ariaLabelledby, - grow, - width, - onSelect, - onClose, - initialSelectedItem, - ...elemProps - } = this.props; - const {selectedItemIndex} = this.state; - const cardWidth = grow ? '100%' : width; - let interactiveItemIndex: number | null = null; - - return ( - - - - {React.Children.map(children, menuItem => { - if (!React.isValidElement(menuItem)) { - return; - } - let itemId; - if (!menuItem.props.isHeader) { - interactiveItemIndex = (interactiveItemIndex ?? -1) + 1; - itemId = `${id}-${interactiveItemIndex}`; - } - return ( - - {React.cloneElement(menuItem, { - onClick: (event: React.MouseEvent) => this.handleClick(event, menuItem.props), - id: itemId, - isFocused: - selectedItemIndex === interactiveItemIndex && !menuItem.props.isHeader, - })} - - ); - })} - - - - ); - } - - public getNormalizedItemIndex = (index: number | undefined): number => { - const itemCount = React.Children.count(this.props.children); - const firstItem = 0; - const lastItem = itemCount - 1; - if (!index) { - return firstItem; - } - return index < 0 ? firstItem : index >= itemCount ? lastItem : index; - }; - - public setNormalizedItemIndex = (index: number | undefined): void => { - this.setState({selectedItemIndex: this.getNormalizedItemIndex(index)}); - }; - - private handleKeyboardShortcuts = (event: React.KeyboardEvent): void => { - if (event.ctrlKey || event.altKey || event.metaKey) { - return; - } - const children = React.Children.toArray(this.props.children); - let nextSelectedIndex = 0; - let isShortcut = false; - const interactiveItems = children.filter(child => { - return !(child as React.ReactElement)?.props?.isHeader; - }); - const interactiveItemCount = interactiveItems.length; - const firstIndex = 0; - const lastIndex = interactiveItemCount - 1; - - if (event.key.length === 1 && event.key.match(/\S/)) { - let start = this.state.selectedItemIndex + 1; - let searchIndex; - if (start === children.length) { - start = 0; - } - searchIndex = this.getIndexFirstChars(start, event.key.toLowerCase()); - if (searchIndex === -1) { - searchIndex = this.getIndexFirstChars(0, event.key.toLowerCase(), start); - } - if (searchIndex > -1) { - isShortcut = true; - nextSelectedIndex = searchIndex; - } - } else { - switch (event.key) { - case 'ArrowUp': - case 'ArrowDown': - const direction = event.key === 'ArrowUp' ? -1 : 1; - isShortcut = true; - const nextIndex = this.state.selectedItemIndex + direction; - nextSelectedIndex = - nextIndex < 0 ? lastIndex : nextIndex >= interactiveItemCount ? firstIndex : nextIndex; - break; - - case 'Home': - case 'End': - const skipTo = event.key === 'Home' ? firstIndex : lastIndex; - isShortcut = true; - nextSelectedIndex = skipTo; - break; - - case 'Tab': - if (this.props.onClose) { - this.props.onClose(); - } - break; - - case 'Escape': - case 'Esc': // IE/Edge specific value - isShortcut = true; - if (this.props.onClose) { - this.props.onClose(); - } - break; - - case 'Spacebar': - case ' ': - case 'Enter': - nextSelectedIndex = this.state.selectedItemIndex; - const child = interactiveItems[this.state.selectedItemIndex] as React.ReactElement< - DeprecatedMenuItemProps - >; - this.handleClick(event, child.props); - isShortcut = true; - break; - - default: - } - } - if (isShortcut) { - this.setNormalizedItemIndex(nextSelectedIndex); - event.stopPropagation(); - event.preventDefault(); - } - }; - - private handleClick = ( - event: React.MouseEvent | React.KeyboardEvent, - menuItemProps: DeprecatedMenuItemProps - ): void => { - /* istanbul ignore next line for coverage */ - if (menuItemProps.isDisabled) { - // You should only hit this point if you are using a custom DeprecatedMenuItem implementation. - return; - } - if (menuItemProps.onClick) { - menuItemProps.onClick(event as React.MouseEvent); - } - if (this.props.onSelect) { - this.props.onSelect(); - } - if (this.props.onClose) { - if (menuItemProps.shouldClose) { - this.props.onClose(); - } - } - }; - - private getIndexFirstChars = ( - startIndex: number, - character: string, - lastIndex: number = this.firstCharacters.length - ) => { - for (let i = startIndex; i < lastIndex; i++) { - if (character === this.firstCharacters[i]) { - return i; - } - } - return -1; - }; - - private setFirstCharacters = (): void => { - const getFirstCharacter = (child: React.ReactNode): string => { - let character = ''; - if (!child || typeof child === 'boolean') { - character = ''; - } else if (typeof child === 'string' || typeof child === 'number') { - character = child - .toString() - .trim() - .substring(0, 1) - .toLowerCase(); - } else if (Array.isArray(child) && child[0]) { - // TODO test React.ReactNodeArray - character = getFirstCharacter(child[0]); - } else if ('props' in child) { - const {children} = child.props; - - if (Array.isArray(children)) { - character = getFirstCharacter(children[0]); - } else { - character = getFirstCharacter(children); - } - } - return character; - }; - - const firstCharacters = React.Children.map(this.props.children, child => { - if ((child as React.ReactElement)?.props?.isHeader) { - return; - } - return getFirstCharacter(child); - }); - - this.firstCharacters = firstCharacters as string[]; - }; - - private getInitialSelectedItem = (): number => { - let selected = this.props.initialSelectedItem || 0; - selected = selected < 0 ? React.Children.count(this.props.children) + selected : selected; - if (selected < 0) { - selected = 0; - } else if (selected > React.Children.count(this.props.children) - 1) { - selected = React.Children.count(this.props.children) - 1; - } - - return selected; - }; - - private setInitialSelectedItem = () => { - const selected = this.getInitialSelectedItem(); - this.setState({selectedItemIndex: selected}); - }; -} diff --git a/modules/preview-react/menu/lib/MenuItem.tsx b/modules/preview-react/menu/lib/MenuItem.tsx deleted file mode 100644 index 053f27f013..0000000000 --- a/modules/preview-react/menu/lib/MenuItem.tsx +++ /dev/null @@ -1,358 +0,0 @@ -import * as React from 'react'; -import styled from '@emotion/styled'; -import { - colors, - commonColors, - iconColors, - typeColors, - space, - type, -} from '@workday/canvas-kit-react/tokens'; -import {CanvasSystemIcon} from '@workday/design-assets-types'; -import {SystemIcon, SystemIconProps} from '@workday/canvas-kit-react/icon'; - -/** - * ### Deprecated Menu Item Props - * - * As of Canvas Kit v8, Menu is being deprecated. - * It will be removed in v10. Please see the - * [upgrade guide](https://workday.github.io/canvas-kit/?path=/story/welcome-upgrade-guides-v8-0--page) - * for more information. - */ -export interface DeprecatedMenuItemProps extends React.LiHTMLAttributes { - /** - * The function called when the DeprecatedMenuItem is clicked. If the item is a child of the DeprecatedMenu component, this callback will be decorated with the onSelect and onClose DeprecatedMenu callbacks. This callback will not fire if the item is disabled (see below). - */ - onClick?: (event: React.MouseEvent) => void; - /** - * The unique id for the DeprecatedMenuItem used for ARIA attributes. If the item is a child of the `DeprecatedMenu` component, this property will be generated and overridden. - */ - id?: string; - /** - * The icon of the DeprecatedMenuItem. This icon is displayed before what you supplied for the children. - */ - icon?: CanvasSystemIcon; - /** - * The secondary icon of the DeprecatedMenuItem. This icon is displayed after what you supplied for the children. - */ - secondaryIcon?: CanvasSystemIcon; - /** - * If true, render a top border on the DeprecatedMenuItem. - * @default false - */ - hasDivider?: boolean; - /** - * If true, render a header to group data, this menu item will not be intractable. - * @default false - */ - isHeader?: boolean; - /** - * If true, set the DeprecatedMenuItem to the disabled state so it is not clickable. - * @default false - */ - isDisabled?: boolean; - /** - * If true, set the DeprecatedMenuItem to be the currently selected item. If the item is a child of the DeprecatedMenu component, this property will be generated and overridden. - * @default false - */ - isFocused?: boolean; - /** - * The role of the DeprecatedMenuItem. Use this to override the role of the item (e.g. you can use this element as an option in a Combobox). - * @default menuItem - */ - role?: string; - /** - * If true, allow the onClose DeprecatedMenu callback to be fired after the DeprecatedMenuItem has been clicked. - * @default true - */ - shouldClose?: boolean; -} - -const Item = styled('li')>( - { - ...type.levels.subtext.large, - padding: `${space.xxs} ${space.s}`, - height: space.xl, - boxSizing: 'border-box', - cursor: 'pointer', - color: colors.blackPepper300, - display: 'flex', - flexDirection: 'row', - alignItems: 'center', - transition: 'background-color 80ms, color 80ms', - '&:focus': { - outline: 'none', - }, - }, - ({isHeader}) => { - return {pointerEvents: isHeader ? 'none' : 'all'}; - }, - ({isFocused, isDisabled}) => { - if (!isFocused && !isDisabled) { - return { - backgroundColor: 'inherit', - '&:hover': { - backgroundColor: commonColors.hoverBackground, - color: colors.blackPepper300, - '.wd-icon-fill, .wd-icon-accent, .wd-icon-accent2': { - fill: iconColors.hover, - }, - }, - }; - } else if (isDisabled && !isFocused) { - return { - color: colors.licorice100, - cursor: 'default', - }; - } else { - // Is focused or focused and disabled - return { - backgroundColor: isDisabled ? colors.blueberry200 : commonColors.focusBackground, - color: typeColors.inverse, - 'span .wd-icon-background ~ .wd-icon-accent, .wd-icon-background ~ .wd-icon-accent2': { - fill: isDisabled ? iconColors.disabled : iconColors.active, - }, - '&:hover': { - 'span .wd-icon-fill, span .wd-icon-accent, span .wd-icon-accent2': { - fill: iconColors.inverse, - }, - 'span .wd-icon-background ~ .wd-icon-accent, span .wd-icon-background ~ .wd-icon-accent2': { - fill: isDisabled ? iconColors.disabled : iconColors.active, - }, - 'span .wd-icon-background': { - fill: iconColors.inverse, - }, - }, - [`[data-whatinput='mouse'] &, - [data-whatinput='touch'] &, - [data-whatinput='pointer'] &`]: { - backgroundColor: 'inherit', - color: colors.blackPepper300, - 'span .wd-icon-background ~ .wd-icon-accent, span .wd-icon-background ~ .wd-icon-accent2': { - fill: iconColors.standard, - }, - '&:hover': { - backgroundColor: commonColors.hoverBackground, - 'span .wd-icon-fill, span .wd-icon-accent, span .wd-icon-accent2': { - fill: iconColors.hover, - }, - }, - '.wd-icon-fill, .wd-icon-accent, .wd-icon-accent2': { - fill: iconColors.standard, - }, - }, - }; - } - } -); - -const LabelContainer = styled('span')({ - flex: '1 1 auto', - overflow: 'hidden', - whiteSpace: 'nowrap', - textOverflow: 'ellipsis', -}); - -const Divider = styled('hr')({ - display: 'block', - height: 1, - border: 0, - borderTop: `1px solid ${colors.soap400}`, - margin: `${space.xxs} 0`, -}); - -const iconSize = 24; -const iconPadding = 16; -const StyledSystemIcon = styled(SystemIcon)({ - minWidth: iconSize + iconPadding, // gives padding between LabelContainer, no matter the direction -}); - -const SecondaryStyledSystemIcon = styled(SystemIcon)({ - display: `flex`, - minWidth: iconSize + iconPadding, // gives padding between LabelContainer, no matter the direction - justifyContent: `flex-end`, -}); - -let iconProps: SystemIconProps | null = null; -let secondaryIconProps: SystemIconProps | null = null; -const setIconProps = ( - icon?: CanvasSystemIcon, - isDisabled?: boolean, - isFocused?: boolean -): SystemIconProps | null => { - if (!icon) { - return null; - } - let props: SystemIconProps = { - icon: icon, - size: iconSize, - }; - if (isDisabled) { - props = { - ...props, - fill: iconColors.disabled, - fillHover: iconColors.disabled, - accent: iconColors.disabled, - accentHover: iconColors.disabled, - }; - } - if (isFocused) { - props = { - ...props, - fill: iconColors.inverse, - fillHover: iconColors.inverse, - accent: iconColors.inverse, - accentHover: iconColors.inverse, - background: iconColors.inverse, - }; - } - return props; -}; - -const scrollIntoViewIfNeeded = (elem: HTMLElement, centerIfNeeded = true): void => { - const parent: HTMLElement | null = elem.parentElement; - - if (elem && parent) { - const parentComputedStyle = window.getComputedStyle(parent, null), - parentBorderTopWidth = parseInt(parentComputedStyle.getPropertyValue('border-top-width'), 10), - parentBorderLeftWidth = parseInt( - parentComputedStyle.getPropertyValue('border-left-width'), - 10 - ), - overTop = elem.offsetTop - parent.offsetTop < parent.scrollTop, - overBottom = - elem.offsetTop - parent.offsetTop + elem.clientHeight - parentBorderTopWidth > - parent.scrollTop + parent.clientHeight, - overLeft = elem.offsetLeft - parent.offsetLeft < parent.scrollLeft, - overRight = - elem.offsetLeft - parent.offsetLeft + elem.clientWidth - parentBorderLeftWidth > - parent.scrollLeft + parent.clientWidth, - alignWithTop = overTop && !overBottom; - - if ((overTop || overBottom) && centerIfNeeded) { - parent.scrollTop = - elem.offsetTop - - parent.offsetTop - - parent.clientHeight / 2 - - parentBorderTopWidth + - elem.clientHeight / 2; - } - - if ((overLeft || overRight) && centerIfNeeded) { - parent.scrollLeft = - elem.offsetLeft - - parent.offsetLeft - - parent.clientWidth / 2 - - parentBorderLeftWidth + - elem.clientWidth / 2; - } - - if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) { - elem.scrollIntoView(alignWithTop); - } - } -}; - -/** - * `DeprecatedMenuItem` renders an `
    • ` element with the correct attributes to ensure it is - * accessible. If you choose to implement your own custom menu items, be sure to use semantic `
    • ` - * elements with the following attributes: - * - * - `role="menuitem"` - * - `tabindex={-1}` - * - `id`s following this pattern: `${MenuId}-${index}` - * - * As of Canvas Kit v8, Menu is being deprecated. - * It will be removed in v10. Please see the [upgrade - * guide](https://workday.github.io/canvas-kit/?path=/story/welcome-upgrade-guides-v8-0--page) for - * more information. - * - * Undocumented props are spread to the underlying `
    • ` element. - * - * @deprecated - */ -export class DeprecatedMenuItem extends React.Component { - ref = React.createRef(); - - componentDidMount() { - console.warn( - `This component is being deprecated and will be removed in Canvas Kit V9.\n - For more information, please see the V8 upgrade guide:\n - https://workday.github.io/canvas-kit/?path=/story/welcome-upgrade-guides-v8-0--page - ` - ); - } - - componentDidUpdate = (prevProps: DeprecatedMenuItemProps) => { - if (!prevProps.isFocused && this.props.isFocused) { - if (this.ref.current) { - scrollIntoViewIfNeeded(this.ref.current); - } - } - }; - - render() { - const { - onClick, - children, - id, - icon, - secondaryIcon, - hasDivider, - isDisabled, - isFocused, - isHeader, - role, - ...elemProps - } = this.props; - - iconProps = setIconProps(icon, isDisabled, isFocused); - secondaryIconProps = setIconProps(secondaryIcon, isDisabled, isFocused); - - return ( - <> - {hasDivider &&