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/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'}); +}; 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..34495bce13 --- /dev/null +++ b/modules/docs/mdx/10.0-UPGRADE_GUIDE.mdx @@ -0,0 +1,161 @@ +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) +- [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 + +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. + +## 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 + +**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. + +## 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/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/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 16814088d7..e382b028e6 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 7cfbe28f81..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/WAI/ARIA/apg/patterns/menu-button/examples/menu-button-actions-active-descendant/) - * 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/WAI/ARIA/apg/patterns/menu-button/examples/menu-button-actions-active-descendant/ - 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 &&