diff --git a/.eslintrc.js b/.eslintrc.js index 17de4ad335..2160f3a9f8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -32,8 +32,18 @@ module.exports = { env: { browser: true, }, - plugins: ['@typescript-eslint', 'jest', 'react', 'prettier', 'react-hooks', 'emotion', 'jsdoc'], + plugins: [ + 'workday-custom-rules', + '@typescript-eslint', + 'jest', + 'react', + 'prettier', + 'react-hooks', + 'emotion', + 'jsdoc', + ], rules: { + 'workday-custom-rules/restricted-imports': 'error', '@typescript-eslint/class-name-casing': 'error', '@typescript-eslint/indent': 'off', '@typescript-eslint/interface-name-prefix': 'error', diff --git a/CHANGELOG.md b/CHANGELOG.md index 82149e3f75..ed65b135b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,20 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# 3.8.0 (2020-05-22) + +### Infrastructure +- docs: Remove rebase section for pull requests ([#647](https://github.com/Workday/canvas-kit/pull/647)) [@NicholasBoll](https://github.com/NicholasBoll) +- chore: Add invalid import rule ([#652](https://github.com/Workday/canvas-kit/pull/652)) [@alanbsmith](https://github.com/alanbsmith) +- fix: Fix incorrect dep listing ([#668](https://github.com/Workday/canvas-kit/pull/668)) [@lychyi](https://github.com/lychyi) +- chore: Add public config to create-component script ([#667](https://github.com/Workday/canvas-kit/pull/667)) [@alanbsmith](https://github.com/alanbsmith) + +### Components +- feat(badge): Add CountBadge component ([#566](https://github.com/Workday/canvas-kit/pull/566)) [@alanbsmith](https://github.com/alanbsmith) +- fix: Add public access to Badge publish config ([#653](https://github.com/Workday/canvas-kit/pull/653)) [@alanbsmith](https://github.com/alanbsmith) +- fix: Align hover ripple for checkbox and radio components in IE11 ([#651](https://github.com/Workday/canvas-kit/pull/651)) [@lychyi](https://github.com/lychyi) +- fix(switch): Fix click target for switch ([#671](https://github.com/Workday/canvas-kit/pull/671)) [@mannycarrera4](https://github.com/mannycarrera4) + # 4.0.0-beta.4 (2020-05-20) ### Infrastructure diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 266a06e339..5c50000f1f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -128,8 +128,6 @@ fix: Add missing static class variable to IconButton and Avatar experience. - Project maintainers are able to push commits to fork PRs, but other contributors will need to open PRs to the personal fork to collaborate with others on a feature. -- It is up to the contributor to make sure their PR is rebased onto upstream/master before - submitting. - When a pull request passes all checks and reviews, a core maintainer merges via Squash and Merge with a link back to the PR. - The branch will automatically be deleted on merge, but its commits and the branch reference are diff --git a/TESTING.md b/TESTING.md index fece24ac69..d653de60aa 100644 --- a/TESTING.md +++ b/TESTING.md @@ -265,12 +265,12 @@ Component helpers come in 3 flavors: ## Visual Tests -Canvas Kit uses [ChromaticQA](https://www.chromaticqa.com/) for visual tests which are run on stories -that are opted-in through a special parameter. All the visual states should be represented at least -one story. This way all of the visual states of a component can be visually regression tested without -requiring the test to interact with the UI. These states should include loading states, error states, -etc. Stories created for visual regression tests should avoid dynamic solutions like -[knobs](https://github.com/storybookjs/storybook/tree/next/addons/knobs). +Canvas Kit uses [ChromaticQA](https://www.chromaticqa.com/) for visual tests which are run on +stories that are opted-in through a special parameter. All the visual states should be represented +at least one story. This way all of the visual states of a component can be visually regression +tested without requiring the test to interact with the UI. These states should include loading +states, error states, etc. Stories created for visual regression tests should avoid dynamic +solutions like [knobs](https://github.com/storybookjs/storybook/tree/next/addons/knobs). To make a story runnable in Chromatic for visual testing, add the following to the story's parameter list: @@ -278,25 +278,28 @@ list: ```tsx // default Storybook API storiesOf('Some Category', module) - .add('My Visual Story', () => { /** story contents */ }) + .add('My Visual Story', () => { + /** story contents */ + }) .addParameter({ chromatic: { disable: false, }, }); +``` + +```tsx +// CSF - All stories in file +export default withSnapshotsEnabled({ + // CSF details (title, component, etc.) +}); -// CSF +// or CSF - Specific story export const MyVisualStory = () => { // story contents }; -MyVisualStory.story = { - parameters: { - chromatic: { - disabled: false, - }, - } -}; +withSnapshotsEnabled(MyVisualStory); ``` Not all visual states are application states (E.g. `focus`, `hover`, and `active` on a button diff --git a/cypress/integration/SelectLabs.spec.ts b/cypress/integration/SelectLabs.spec.ts index c63f4f433f..550cf0c3a0 100644 --- a/cypress/integration/SelectLabs.spec.ts +++ b/cypress/integration/SelectLabs.spec.ts @@ -185,9 +185,7 @@ describe('Select', () => { context('when the listbox is expanded again', () => { beforeEach(() => { - cy.findByLabelText('Label') - .pipe(h.selectLabs.getMenu) - .type('{downarrow}'); + cy.focused().type('{downarrow}'); }); context('the fourth option', () => { diff --git a/cypress/integration/storybook.spec.ts b/cypress/integration/storybook.spec.ts index aa14e49064..7bd389c00c 100644 --- a/cypress/integration/storybook.spec.ts +++ b/cypress/integration/storybook.spec.ts @@ -6,10 +6,7 @@ describe('Storybook', () => { it('should render the Getting Started page', () => { cy.visit('/'); cy.get('iframe#storybook-preview-iframe') - .pipe( - getIframeBody, - {timeout: 20000} - ) + .pipe(getIframeBody, {timeout: 20000}) .should('contain', 'Workday Canvas Kit'); }); }); diff --git a/lerna.json b/lerna.json index 4524543376..951d0c3fa1 100644 --- a/lerna.json +++ b/lerna.json @@ -1,7 +1,5 @@ { - "packages": [ - "modules/**" - ], + "packages": ["modules/**"], "version": "4.0.0-beta.4", "npmClient": "yarn", "useWorkspaces": true, diff --git a/modules/_canvas-kit-react/index.ts b/modules/_canvas-kit-react/index.ts index 9fa69c3d48..5dca12422d 100644 --- a/modules/_canvas-kit-react/index.ts +++ b/modules/_canvas-kit-react/index.ts @@ -1,6 +1,7 @@ export {default as canvas} from '@workday/canvas-kit-react-core'; export * from '@workday/canvas-kit-react-action-bar'; export * from '@workday/canvas-kit-react-avatar'; +export * from '@workday/canvas-kit-react-badge'; export * from '@workday/canvas-kit-react-banner'; export * from '@workday/canvas-kit-react-button'; export * from '@workday/canvas-kit-react-card'; diff --git a/modules/_canvas-kit-react/package.json b/modules/_canvas-kit-react/package.json index a36f9be277..358e1642ee 100644 --- a/modules/_canvas-kit-react/package.json +++ b/modules/_canvas-kit-react/package.json @@ -48,6 +48,7 @@ "dependencies": { "@workday/canvas-kit-react-action-bar": "4.0.0-beta.4", "@workday/canvas-kit-react-avatar": "4.0.0-beta.4", + "@workday/canvas-kit-react-badge": "4.0.0-beta.4", "@workday/canvas-kit-react-banner": "4.0.0-beta.4", "@workday/canvas-kit-react-button": "4.0.0-beta.4", "@workday/canvas-kit-react-card": "4.0.0-beta.4", diff --git a/modules/_labs/pagination/react/stories/stories.tsx b/modules/_labs/pagination/react/stories/stories.tsx index 8be14043b3..44343208fe 100644 --- a/modules/_labs/pagination/react/stories/stories.tsx +++ b/modules/_labs/pagination/react/stories/stories.tsx @@ -4,7 +4,6 @@ import {boolean, number, text} from '@storybook/addon-knobs'; import {storiesOf} from '@storybook/react'; import React, {useEffect, useState} from 'react'; import withReadme from 'storybook-readme/with-readme'; -import {ComponentStatesTable} from '../../../../../utils/storybook'; import {Pagination} from '@workday/canvas-kit-labs-react-pagination'; import README from '../README.md'; @@ -110,45 +109,3 @@ storiesOf('Labs|Pagination/React', module) ); }); - -storiesOf('Labs|Pagination/React/Visual Testing', module) - .addParameters({ - chromatic: { - disable: false, - }, - }) - .add('States', () => { - const defaults = { - total: 1000, - pageSize: 10, - showLabel: true, - showGoTo: true, - currentPage: 1, - onPageChange: (_: any) => { - /* don't do anything */ - }, - }; - return ( - - {props => } - - ); - }); diff --git a/modules/_labs/pagination/react/stories/stories_visualTesting.tsx b/modules/_labs/pagination/react/stories/stories_visualTesting.tsx new file mode 100644 index 0000000000..0ce3ff8335 --- /dev/null +++ b/modules/_labs/pagination/react/stories/stories_visualTesting.tsx @@ -0,0 +1,45 @@ +/// +import React from 'react'; +import {ComponentStatesTable, withSnapshotsEnabled} from '../../../../../utils/storybook'; +import {Pagination} from '@workday/canvas-kit-labs-react-pagination'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Labs/Pagination', + component: Pagination, +}); + +export const PaginationStates = () => { + const defaults = { + total: 1000, + pageSize: 10, + showLabel: true, + showGoTo: true, + currentPage: 1, + onPageChange: (_: any) => { + /* don't do anything */ + }, + }; + return ( + + {props => } + + ); +}; diff --git a/modules/_labs/select/react/lib/Select.tsx b/modules/_labs/select/react/lib/Select.tsx index 9a2c96d135..0651207f40 100644 --- a/modules/_labs/select/react/lib/Select.tsx +++ b/modules/_labs/select/react/lib/Select.tsx @@ -289,7 +289,6 @@ export default class Select extends React.Component { // of focus (i.e., so focus is immediately transferred to the menu when // opening the menu, rather than briefly being applied to the button // and creating a momentary flash of a focus ring around the button) - event.preventDefault(); }; diff --git a/modules/_labs/select/react/lib/SelectBase.tsx b/modules/_labs/select/react/lib/SelectBase.tsx index 7048e1e1c2..fb430f0c8b 100644 --- a/modules/_labs/select/react/lib/SelectBase.tsx +++ b/modules/_labs/select/react/lib/SelectBase.tsx @@ -152,7 +152,7 @@ const buttonBorderWidth = 1; const buttonPadding = spacingNumbers.xxs - buttonBorderWidth; const SelectButton = styled('button')< - Pick + Pick >( { ...type.body, @@ -186,7 +186,7 @@ const SelectButton = styled('button')< }, }, }, - ({error, isMenuHidden, theme}) => { + ({error, isMenuHidden, isMenuHiding, theme}) => { const themedFocusOutlineColor = theme.canvas.palette.common.focusOutline; const buttonFocusStyles = { borderColor: themedFocusOutlineColor, @@ -194,10 +194,10 @@ const SelectButton = styled('button')< }; if (error === undefined) { - // If there isn't an error, apply focus and hover styles if the - // menu is hidden (otherwise, if the menu is visible, style + // If there isn't an error, apply focus and hover styles if the menu is + // hidden or hiding (otherwise, the menu is completely visible: style // the button as if it had focus) - return isMenuHidden + return isMenuHidden || isMenuHiding ? { '&:focus:not([disabled])': { ...buttonFocusStyles, @@ -353,10 +353,7 @@ export default class SelectBase extends React.Component { value: option.value, ...(onOptionSelection ? { - // mouseDown provides a slightly better UX than click - // since visual feedback of selected option is more - // immediate - onMouseDown: (event: React.MouseEvent) => { + onClick: (event: React.MouseEvent) => { event.preventDefault(); onOptionSelection(index); }, @@ -421,6 +418,7 @@ export default class SelectBase extends React.Component { error={error} grow={grow} isMenuHidden={isMenuHidden} + isMenuHiding={isMenuHiding} onKeyDown={onKeyDown} // Prevent Firefox from triggering click handler on spacebar during // type-ahead when the menu is closed (and, thus, incorrectly displaying diff --git a/modules/_labs/select/react/lib/SelectOption.tsx b/modules/_labs/select/react/lib/SelectOption.tsx index 8277da3b66..0134a88893 100644 --- a/modules/_labs/select/react/lib/SelectOption.tsx +++ b/modules/_labs/select/react/lib/SelectOption.tsx @@ -53,6 +53,7 @@ const Option = styled('li')( listStyle: 'none', // In case the content of the option is empty/undefined for some reason minHeight: type.body.lineHeight, + textAlign: 'left', }, ({disabled, focused, interactive, theme}) => { if (disabled) { @@ -78,14 +79,14 @@ const Option = styled('li')( '&:hover': { backgroundColor: commonColors.hoverBackground, }, - '&:active': { + '&:active, &:active[aria-selected="true"]': { ...activeStyles(theme), }, } : {}; return { // Place selected styles after interactive styles to have selected styles - // override interactive styles + // override interactive styles (subject to CSS specificity rules) ...interactiveStyles, ...selectedStyles, }; diff --git a/modules/_labs/select/react/spec/Select.spec.tsx b/modules/_labs/select/react/spec/Select.spec.tsx index c20f753558..442286a93d 100644 --- a/modules/_labs/select/react/spec/Select.spec.tsx +++ b/modules/_labs/select/react/spec/Select.spec.tsx @@ -8,7 +8,10 @@ describe('Select', () => { const selectButtonRole = 'button'; const optionRole = 'option'; - const options = [{label: 'E-mail', value: 'email'}, {label: 'Phone', value: 'phone'}]; + const options = [ + {label: 'E-mail', value: 'email'}, + {label: 'Phone', value: 'phone'}, + ]; afterEach(() => { cb.mockReset(); @@ -29,11 +32,11 @@ describe('Select', () => { }); }); - describe('when the mouse button is pressed down on an option with a different value than the current value of the select', () => { + describe('when an option with a different value than the current value of the select is clicked', () => { it('should call the onChange callback', () => { const {getAllByRole, getByRole} = render()} )); - -const SelectStates = () => ( - - { - if (props.disabled && !['', 'hover'].includes(props.className)) { - return false; - } - return true; - } - )} - > - {props => ( - {}} // eslint-disable-line no-empty-function + options={options} + /> + )} + + +); + +export const SelectStatesMenuOn = () => ( + + + {props => ( +
+ {}} // eslint-disable-line no-empty-function + options={normalizedOptions} + focusedOptionIndex={1} + isMenuAnimated={false} + isMenuHidden={false} + /> +
+ )} +
+
+); + +export const SelectStatesOption = () => ( +
+ {[ + { + label: 'Disabled States', + columnProps: [ + {label: 'Default', props: {}}, + {label: 'Hover', props: {className: 'hover'}}, + ], + rowProps: [{label: 'Disabled', props: {disabled: true}}], + }, + { + label: 'Interaction States', + columnProps: [ + {label: 'Default', props: {}}, + {label: 'Hover', props: {className: 'hover'}}, + {label: 'Active', props: {className: 'active'}}, + {label: 'Active Hover', props: {className: 'active hover'}}, + ], + rowProps: [ + {label: 'Default', props: {}}, + {label: 'Assistive-Focus', props: {focused: true}}, + {label: 'Selected', props: {'aria-selected': true}}, + {label: 'Assistive-Focus Selected', props: {'aria-selected': true, focused: true}}, + ], + }, + ].map(statesTable => ( +
+

{statesTable.label}

+ + + {props => ( +
    + E-mail +
+ )} +
+
+
+ ))} +
+); diff --git a/modules/badge/css/LICENSE b/modules/badge/css/LICENSE new file mode 100644 index 0000000000..0edd43cffc --- /dev/null +++ b/modules/badge/css/LICENSE @@ -0,0 +1,51 @@ +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 + +©2019. 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/badge/css/README.md b/modules/badge/css/README.md new file mode 100644 index 0000000000..324b209a8d --- /dev/null +++ b/modules/badge/css/README.md @@ -0,0 +1,80 @@ +# Canvas Kit CSS Badge + +The count badge provides a quantity-based summary with dynamic values. + +## Installation + +```sh +yarn add @workday/canvas-kit-css +``` + +or + +```sh +yarn add @workday/canvas-kit-css-badge +``` + +Add your `node_modules` directory to your SASS `includePaths`. You will then be able to import +`index.scss`. + +```scss +@import '~@workday/canvas-kit-css-badge/index.scss'; +``` + +## Accessibility + +A common use case for the count badge is for displaying notifications, and there are several +accessibility concerns you'll want to keep in mind: + +- The button should have an aria-label that updates with the count +- The elements inside the button should have `aria-hidden` +- The live region should be outside the button +- The live region should be visually hidden and only contain text + +### Example + +```html + +
+ New notifications +
+``` + +> Note: To use the `wdc-accessible-hide` class, you'll need to import it from the core module. + +```scss +@import '~@workday/canvas-kit-css-core/lib/accessibility.scss'; +``` + +## Usage + +### Variants + +#### Default + +```html + + 1 + +``` + +#### Inverse + +```html + + 2 + +``` + +### Formatting + +Badges with more than 999 notifications should display '999+' + +```html + + 999+ + +``` diff --git a/modules/badge/css/index.scss b/modules/badge/css/index.scss new file mode 100644 index 0000000000..8cb12b2a82 --- /dev/null +++ b/modules/badge/css/index.scss @@ -0,0 +1,4 @@ +@import '@workday/canvas-kit-css-core/lib/variables/type.scss'; +@import '@workday/canvas-kit-css-core/lib/variables/colors.scss'; + +@import './lib/count-badge.scss'; diff --git a/modules/badge/css/lib/count-badge.scss b/modules/badge/css/lib/count-badge.scss new file mode 100644 index 0000000000..7d9fbe905d --- /dev/null +++ b/modules/badge/css/lib/count-badge.scss @@ -0,0 +1,54 @@ +@keyframes wdc-count-badge-grow { + from { + transform: scale(0.85); + } + + to { + transform: scale(1); + } +} + +@mixin wdc-count-badge { + // base styles + align-items: center; + animation: wdc-count-badge-grow 0.2s ease; + border-radius: 999px; + box-sizing: border-box; + display: inline-flex; + font-family: $wdc-font-family; + font-size: 12px; + font-weight: 700; + height: 20px; + justify-content: center; + min-width: 20px; + line-height: 20px; + padding: 0 6.5px; +} + +// default badge styles +.wdc-count-badge { + @include wdc-count-badge(); + background: $wdc-color-cinnamon-500; + color: $wdc-color-french-vanilla-100; + text-shadow: 0 0 1px rgba(0, 0, 0, 0.35); + + &:empty { + background: $wdc-color-french-vanilla-100; + border: solid 6px $wdc-color-cinnamon-500; + padding: 0; + } +} + +// inverse badge styles +.wdc-count-badge-inverse { + @include wdc-count-badge(); + background: $wdc-color-french-vanilla-100; + box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); + color: $wdc-color-blueberry-400; + + &:empty { + background: $wdc-color-blueberry-400; + border: solid 6px $wdc-color-french-vanilla-100; + padding: 0; + } +} diff --git a/modules/badge/css/package.json b/modules/badge/css/package.json new file mode 100644 index 0000000000..0de1dd4eea --- /dev/null +++ b/modules/badge/css/package.json @@ -0,0 +1,35 @@ +{ + "name": "@workday/canvas-kit-css-badge", + "version": "4.0.0-beta.4", + "description": "provides a summary indicator with dynamic values", + "author": "Workday, Inc. (https://www.workday.com)", + "license": "Apache-2.0", + "files": [ + "dist", + "lib", + "index.scss" + ], + "style": "dist/canvas-kit-css-badge.min.css", + "main": "dist/canvas-kit-css-badge.min.css", + "repository": { + "type": "git", + "url": "https://github.com/Workday/canvas-kit/tree/master/modules/badge/css" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "build": "node ../../../utils/css-build.js index.scss" + }, + "keywords": [ + "canvas", + "canvas-kit", + "css", + "scss", + "sass", + "components", + "workday", + "badge" + ], + "publishConfig": { + "access": "public" + } +} diff --git a/modules/badge/css/stories/stories.tsx b/modules/badge/css/stories/stories.tsx new file mode 100644 index 0000000000..1deadc624a --- /dev/null +++ b/modules/badge/css/stories/stories.tsx @@ -0,0 +1,24 @@ +import React from 'react'; +import withReadme from 'storybook-readme/with-readme'; +import README from '../README.md'; +import '../index.scss'; + +export default { + title: 'Components|Indicators/Badge/CountBadge/CSS/', + decorators: [withReadme(README)], +}; + +export const Default = () => ( + <> +
+ 1 + 100 + 999+ +
+
+ 1 + 100 + 999+ +
+ +); diff --git a/modules/badge/react/LICENSE b/modules/badge/react/LICENSE new file mode 100644 index 0000000000..0edd43cffc --- /dev/null +++ b/modules/badge/react/LICENSE @@ -0,0 +1,51 @@ +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 + +©2019. 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/badge/react/README.md b/modules/badge/react/README.md new file mode 100644 index 0000000000..c2facc5441 --- /dev/null +++ b/modules/badge/react/README.md @@ -0,0 +1,102 @@ +# Canvas Kit React Badge + +CountBadge provides a quantity-based summary with dynamic values. + +## Installation + +```sh +yarn add @workday/canvas-kit-react +``` + +or + +```sh +yarn add @workday/canvas-kit-react-badge +``` + +## Accessibility + +A common use case for the CountBadge is for displaying notifications, and there are several +accessibility concerns you'll want to keep in mind: + +- The button should have an aria-label that updates with the count +- The elements inside the button should have `aria-hidden` +- The live region should be outside the button +- The live region should be visually hidden and only contain text + +### Example + +```tsx +import styled from '@emotion/styled'; +import { accessibleHide } from "@workday/canvas-kit-react"; + +... + +const AccessibleHide = styled('div')({ + ...accessibleHide, +}); + +... + + + + + New notifications + +``` + +## Usage + +```tsx +import * as React from 'react'; +import {CountBadge} from '@workday/canvas-kit-react-badge'; + +// default CountBadge + + +// inverse CountBadge variant + + +``` + +## Static Properties + +> None + +## Component Props + +### Required + +> None + +### Optional + +#### `variant: 'default' | 'inverse'` + +> Styled variant for the badge + +| Variant | Description | +| --------- | --------------------------- | +| `default` | Red background, White text | +| `inverse` | White background, Blue text | + +Default: `default` + +--- + +#### `count: number` + +> Count displayed on the badge + +Default: `0` + +📝 **Note** + +Values greater than 999 are formatted to "999+" diff --git a/modules/badge/react/eslintrc.js b/modules/badge/react/eslintrc.js new file mode 100644 index 0000000000..afd69d12eb --- /dev/null +++ b/modules/badge/react/eslintrc.js @@ -0,0 +1 @@ +require('../../../eslintrc.js'); diff --git a/modules/badge/react/index.ts b/modules/badge/react/index.ts new file mode 100644 index 0000000000..7788f629b7 --- /dev/null +++ b/modules/badge/react/index.ts @@ -0,0 +1 @@ +export {default as CountBadge, CountBadgeProps} from './lib/CountBadge'; diff --git a/modules/badge/react/lib/CountBadge.tsx b/modules/badge/react/lib/CountBadge.tsx new file mode 100644 index 0000000000..ea88b5b1e8 --- /dev/null +++ b/modules/badge/react/lib/CountBadge.tsx @@ -0,0 +1,67 @@ +import * as React from 'react'; +import {keyframes} from '@emotion/core'; +import styled from '@emotion/styled'; +import {borderRadius, colors, fontFamily} from '@workday/canvas-kit-react-core'; + +export interface CountBadgeProps extends React.HTMLAttributes { + count?: number; + variant?: 'default' | 'inverse'; +} + +const variants = { + default: { + background: colors.cinnamon500, + color: colors.frenchVanilla100, + textShadow: '0 0 1px rgba(0,0,0, 0.35)', + }, + inverse: { + background: colors.frenchVanilla100, + boxShadow: '0 1px 2px rgba(0,0,0, 0.25)', + color: colors.blueberry400, + }, +}; + +const grow = keyframes` + from { + transform: scale(0.85); + } + + to { + transform: scale(1.0); + } +`; + +const Container = styled('span')( + { + alignItems: 'center', + animation: `${grow} 0.2s ease`, + borderRadius: borderRadius.circle, + boxSizing: 'border-box', + display: 'inline-flex', + fontFamily, + fontSize: '12px', + fontWeight: 700, + height: '20px', + justifyContent: 'center', + lineHeight: '20px', + minWidth: '20px', + padding: '0 6.5px', + }, + ({variant = 'default'}) => ({ + ...variants[variant], + }) +); + +const CountBadge = (props: CountBadgeProps) => { + const {variant = 'default', count = 0, ...elemProps} = props; + + const formattedCount = count < 1000 ? `${count}` : '999+'; + + return ( + + {formattedCount} + + ); +}; + +export default CountBadge; diff --git a/modules/badge/react/package.json b/modules/badge/react/package.json new file mode 100644 index 0000000000..4f6f7a7526 --- /dev/null +++ b/modules/badge/react/package.json @@ -0,0 +1,49 @@ +{ + "name": "@workday/canvas-kit-react-badge", + "version": "4.0.0-beta.4", + "description": "provides a summary indicator with dynamic values", + "author": "Workday, Inc. (https://www.workday.com)", + "license": "Apache-2.0", + "main": "dist/commonjs/index.js", + "module": "dist/es6/index.js", + "sideEffects": false, + "types": "dist/es6/index.d.ts", + "repository": { + "type": "git", + "url": "https://github.com/Workday/canvas-kit/tree/master/modules/badge/react" + }, + "files": [ + "dist/", + "lib/", + "index.ts", + "ts3.5/**/*" + ], + "scripts": { + "watch": "yarn build:es6 -w", + "clean": "rimraf dist && rimraf .build-info && mkdirp dist", + "build:cjs": "tsc -p tsconfig.cjs.json", + "build:es6": "tsc -p tsconfig.es6.json", + "build:rebuild": "npm-run-all clean build", + "build": "npm-run-all --parallel build:cjs build:es6", + "depcheck": "node ../../../utils/check-dependencies-exist.js" + }, + "keywords": [ + "canvas", + "canvas-kit", + "react", + "components", + "workday", + "badge" + ], + "publishConfig": { + "access": "public" + }, + "peerDependencies": { + "react": ">= 16.8 < 17" + }, + "dependencies": { + "@emotion/core": "^10.0.28", + "@emotion/styled": "^10.0.27", + "@workday/canvas-kit-react-core": "4.0.0-beta.4" + } +} diff --git a/modules/badge/react/spec/CountBadge.spec.tsx b/modules/badge/react/spec/CountBadge.spec.tsx new file mode 100644 index 0000000000..6ea1641de1 --- /dev/null +++ b/modules/badge/react/spec/CountBadge.spec.tsx @@ -0,0 +1,32 @@ +import React from 'react'; +import {render} from '@testing-library/react'; +import {CountBadge, CountBadgeProps} from '../index'; + +describe('CountBadge', () => { + const renderCountBadge = (props = {} as Partial) => { + return render(); + }; + + it('should default to 0 if no count is provided', () => { + const expected = '0'; + const {container} = renderCountBadge(); + + expect(container.textContent).toEqual(expected); + }); + + it('should render the count for numbers under 1000', () => { + const count = 999; + const expected = count.toString(); + const {container} = renderCountBadge({count}); + + expect(container.textContent).toEqual(expected); + }); + + it('should render 999+ for numbers 1000 and above', () => { + const count = 1000; + const expected = '999+'; + const {container} = renderCountBadge({count}); + + expect(container.textContent).toEqual(expected); + }); +}); diff --git a/modules/badge/react/stories/stories.tsx b/modules/badge/react/stories/stories.tsx new file mode 100644 index 0000000000..069e45c72a --- /dev/null +++ b/modules/badge/react/stories/stories.tsx @@ -0,0 +1,30 @@ +/// +import React from 'react'; +import {withKnobs, number, select} from '@storybook/addon-knobs'; +import withReadme from 'storybook-readme/with-readme'; + +import {CountBadge} from '../index'; +import README from '../README.md'; + +export default { + title: 'Components|Indicators/Badge/CountBadge/React', + decorators: [withKnobs, withReadme(README)], +}; + +export const Default = () => ( +
+ +
+); + +export const Inverse = () => ( +
+ +
+); diff --git a/modules/badge/react/stories/stories_visualTesting.tsx b/modules/badge/react/stories/stories_visualTesting.tsx new file mode 100644 index 0000000000..56cd3a7876 --- /dev/null +++ b/modules/badge/react/stories/stories_visualTesting.tsx @@ -0,0 +1,36 @@ +/// +import React from 'react'; +import withReadme from 'storybook-readme/with-readme'; + +import {ComponentStatesTable, withSnapshotsEnabled} from '../../../../utils/storybook'; + +import {CountBadge} from '../index'; +import README from '../README.md'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Indicators/Badge/CountBadge', + component: CountBadge, + decorators: [withReadme(README)], +}); + +export const CountBadgeStates = () => { + return ( + + {props => } + + ); +}; diff --git a/modules/badge/react/tsconfig.cjs.json b/modules/badge/react/tsconfig.cjs.json new file mode 100644 index 0000000000..261641fcc9 --- /dev/null +++ b/modules/badge/react/tsconfig.cjs.json @@ -0,0 +1,11 @@ + +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "declaration": true, + "module": "commonjs", + "outDir": "dist/commonjs", + "skipLibCheck": true, + "tsBuildInfoFile": "./.build-info/tsconfig.cjs.tsbuildinfo" + } +} diff --git a/modules/badge/react/tsconfig.es6.json b/modules/badge/react/tsconfig.es6.json new file mode 100644 index 0000000000..cdf8edae25 --- /dev/null +++ b/modules/badge/react/tsconfig.es6.json @@ -0,0 +1,9 @@ + +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "declaration": true, + "outDir": "dist/es6", + "tsBuildInfoFile": "./.build-info/tsconfig.es6.tsbuildinfo" + } +} diff --git a/modules/badge/react/tsconfig.json b/modules/badge/react/tsconfig.json new file mode 100644 index 0000000000..85b3d2335d --- /dev/null +++ b/modules/badge/react/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../../tsconfig.json", + "exclude": ["node_modules", "ts-tmp", "dist", "spec", "stories"] +} diff --git a/modules/button/react/stories/stories_visualTesting.tsx b/modules/button/react/stories/stories_visualTesting.tsx deleted file mode 100644 index 3537684f92..0000000000 --- a/modules/button/react/stories/stories_visualTesting.tsx +++ /dev/null @@ -1,392 +0,0 @@ -/// -/** @jsx jsx */ -import {jsx, CSSObject} from '@emotion/core'; -import * as React from 'react'; -import {storiesOf} from '@storybook/react'; -import {colors} from '@workday/canvas-kit-react-core'; -import {StaticStates, type} from '@workday/canvas-kit-labs-react-core'; -import {ComponentStatesTable, permutateProps, customColorTheme} from '../../../../utils/storybook'; -import {playCircleIcon, activityStreamIcon} from '@workday/canvas-system-icons-web'; -import { - Button, - DropdownButton, - TextButton, - DeleteButton, - HighlightButton, - OutlineButton, - Hyperlink, - IconButton, - ToolbarIconButton, - deprecated_Button as DeprecatedButton, -} from '../index'; - -const buttonLayout: CSSObject = { - display: 'flex', - alignItems: 'center', - justifyContent: 'center', -}; - -const blueBackground: CSSObject = { - ...buttonLayout, - backgroundColor: colors.blueberry400, - padding: '12px', - borderRadius: '4px', -}; - -const Container = (props: any) => ( -
{props.children}
-); - -const getButtonStates = (rowProps: any, renderFn: (props: any) => React.ReactNode) => ( - - { - if (props.disabled && !['', 'hover'].includes(props.className)) { - return false; - } - return true; - } - )} - > - {renderFn} - - -); - -const buttonStories = [ - { - name: 'Button', - component: Button, - states: getButtonStates( - { - variant: [ - {value: Button.Variant.Primary, label: 'Primary'}, - {value: Button.Variant.Secondary, label: 'Secondary'}, - ], - size: [ - {value: Button.Size.Small, label: 'Small'}, - {value: Button.Size.Medium, label: 'Medium'}, - {value: Button.Size.Large, label: 'Large'}, - ], - icon: [ - {value: undefined, label: ''}, - {value: playCircleIcon, label: 'w/ Icon'}, - ], - dataLabel: [ - {value: undefined, label: ''}, - {value: '1:23', label: 'w/ Data Label'}, - ], - }, - (props: any) => ( - - - - ) - ), - }, - { - name: 'Delete Button', - component: DeleteButton, - states: getButtonStates( - { - size: [ - {value: DeleteButton.Size.Small, label: 'Small'}, - {value: DeleteButton.Size.Medium, label: 'Medium'}, - {value: DeleteButton.Size.Large, label: 'Large'}, - ], - }, - (props: any) => ( - - Test - - ) - ), - }, - { - name: 'Deprecated Button', - component: DeprecatedButton, - states: getButtonStates( - { - variant: [ - {value: DeprecatedButton.Variant.Primary, label: 'Primary'}, - {value: DeprecatedButton.Variant.Secondary, label: 'Secondary'}, - {value: DeprecatedButton.Variant.Delete, label: 'Delete'}, - ], - size: [ - {value: Button.Size.Small, label: 'Small'}, - {value: Button.Size.Medium, label: 'Medium'}, - {value: Button.Size.Large, label: 'Large'}, - ], - }, - (props: any) => ( - - Test - - ) - ), - }, - { - name: 'Dropdown Button', - component: DropdownButton, - states: getButtonStates( - { - variant: [ - {value: DropdownButton.Variant.Primary, label: 'Primary'}, - {value: DropdownButton.Variant.Secondary, label: 'Secondary'}, - ], - size: [ - {value: DropdownButton.Size.Medium, label: 'Medium'}, - {value: DropdownButton.Size.Large, label: 'Large'}, - ], - icon: [ - {value: undefined, label: ''}, - {value: playCircleIcon, label: 'w/ Icon'}, - ], - dataLabel: [ - {value: undefined, label: ''}, - {value: '1:23', label: 'w/ Data Label'}, - ], - }, - (props: any) => ( - - Test - - ) - ), - }, - { - name: 'Highlight Button', - component: HighlightButton, - states: getButtonStates( - { - size: [ - {value: Button.Size.Small, label: 'Small'}, - {value: Button.Size.Medium, label: 'Medium'}, - {value: Button.Size.Large, label: 'Large'}, - ], - icon: [ - {value: undefined, label: ''}, - {value: playCircleIcon, label: 'w/ Icon'}, - ], - }, - (props: any) => ( - - Test - - ) - ), - }, - { - name: 'Outline Button', - component: OutlineButton, - states: getButtonStates( - { - variant: [ - {value: OutlineButton.Variant.Primary, label: 'Outline Primary'}, - {value: OutlineButton.Variant.Secondary, label: 'Outline Secondary'}, - {value: OutlineButton.Variant.Inverse, label: 'Outline Inverse'}, - ], - size: [ - {value: Button.Size.Small, label: 'Small'}, - {value: Button.Size.Medium, label: 'Medium'}, - {value: Button.Size.Large, label: 'Large'}, - ], - icon: [ - {value: undefined, label: ''}, - {value: playCircleIcon, label: 'w/ Icon'}, - ], - dataLabel: [ - {value: undefined, label: ''}, - {value: '1:23', label: 'w/ Data Label'}, - ], - }, - (props: any) => ( - - Test - - ) - ), - }, - { - name: 'Text Button', - component: TextButton, - states: getButtonStates( - { - variant: [ - {value: TextButton.Variant.Default, label: 'Default'}, - {value: TextButton.Variant.Inverse, label: 'Inverse'}, - ], - size: [ - {value: TextButton.Size.Small, label: 'Small'}, - {value: TextButton.Size.Medium, label: 'Medium'}, - ], - icon: [ - {value: undefined, label: ''}, - {value: playCircleIcon, label: 'w/ Icon'}, - ], - allCaps: [ - {value: undefined, label: ''}, - {value: true, label: 'All Caps'}, - ], - }, - (props: any) => ( - - Test - - ) - ), - }, - { - name: 'Hyperlink', - component: Hyperlink, - states: ( - - - {(props: any) => ( - -
- Here's a Link to something -
-
- )} -
-
- ), - }, - { - name: 'Icon Button', - component: IconButton, - states: ( - - {[false, true].map(toggled => ( -
-

Toggled {toggled ? 'On' : 'Off'}

- {getButtonStates( - { - variant: [ - {value: IconButton.Variant.Inverse, label: 'Inverse'}, - {value: IconButton.Variant.InverseFilled, label: 'Inverse Filled'}, - {value: IconButton.Variant.Plain, label: 'Plain'}, - {value: IconButton.Variant.Circle, label: 'Circle'}, - {value: IconButton.Variant.CircleFilled, label: 'Circle Filled'}, - {value: IconButton.Variant.Square, label: 'Square'}, - {value: IconButton.Variant.SquareFilled, label: 'Square Filled'}, - ], - size: [ - {value: IconButton.Size.Small, label: 'Small'}, - {value: IconButton.Size.Medium, label: 'Medium'}, - ], - }, - (props: any) => ( - - {}} // eslint-disable-line no-empty-function - /> - - ) - )} -
- ))} -
- ), - }, - { - name: 'Toolbar Icon Button', - component: ToolbarIconButton, - states: ( - - {[false, true].map(toggled => ( -
-

Toggled {toggled ? 'On' : 'Off'}

- {getButtonStates({}, (props: any) => ( - - {}} // eslint-disable-line no-empty-function - /> - - ))} -
- ))} -
- ), - }, -]; - -buttonStories.forEach(({name, component, states}) => { - storiesOf(`Components|Buttons/Button/React/Visual Testing/${name}`, module) - .addParameters({ - component: component, - chromatic: { - disable: false, - }, - }) - .add('States', () => states as React.ReactElement); - - if (component !== DeprecatedButton) { - storiesOf(`Components|Buttons/Button/React/Visual Testing/${name}`, module) - .addParameters({ - component: component, - chromatic: { - disable: false, - }, - canvasProviderDecorator: { - theme: customColorTheme, - }, - }) - .add('Theming', () => states as React.ReactElement); - } -}); diff --git a/modules/button/react/stories/visual-testing/stories_Button.tsx b/modules/button/react/stories/visual-testing/stories_Button.tsx new file mode 100644 index 0000000000..8bee8face1 --- /dev/null +++ b/modules/button/react/stories/visual-testing/stories_Button.tsx @@ -0,0 +1,50 @@ +/// +/** @jsx jsx */ +import {jsx} from '@emotion/core'; +import {StaticStates} from '@workday/canvas-kit-labs-react-core'; +import { + ComponentStatesTable, + permutateProps, + withSnapshotsEnabled, +} from '../../../../../utils/storybook'; +import {playCircleIcon} from '@workday/canvas-system-icons-web'; +import {Button} from '../../index'; +import {Container, stateTableColumnProps} from './utils'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Button', + component: Button, +}); + +export const ButtonStates = () => ( + + + {props => ( + + + + )} + + +); diff --git a/modules/button/react/stories/visual-testing/stories_DeleteButton.tsx b/modules/button/react/stories/visual-testing/stories_DeleteButton.tsx new file mode 100644 index 0000000000..e9da46b6f4 --- /dev/null +++ b/modules/button/react/stories/visual-testing/stories_DeleteButton.tsx @@ -0,0 +1,37 @@ +/// +/** @jsx jsx */ +import {jsx} from '@emotion/core'; +import {StaticStates} from '@workday/canvas-kit-labs-react-core'; +import { + ComponentStatesTable, + permutateProps, + withSnapshotsEnabled, +} from '../../../../../utils/storybook'; +import {DeleteButton} from '../../index'; +import {Container, stateTableColumnProps} from './utils'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Delete Button', + component: DeleteButton, +}); + +export const DeleteButtonStates = () => ( + + + {props => ( + + Test + + )} + + +); diff --git a/modules/button/react/stories/visual-testing/stories_DropdownButton.tsx b/modules/button/react/stories/visual-testing/stories_DropdownButton.tsx new file mode 100644 index 0000000000..a4543f4f16 --- /dev/null +++ b/modules/button/react/stories/visual-testing/stories_DropdownButton.tsx @@ -0,0 +1,40 @@ +/// +/** @jsx jsx */ +import {jsx} from '@emotion/core'; +import {StaticStates} from '@workday/canvas-kit-labs-react-core'; +import { + ComponentStatesTable, + permutateProps, + withSnapshotsEnabled, +} from '../../../../../utils/storybook'; +import {DropdownButton} from '../../index'; +import {Container, stateTableColumnProps} from './utils'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Dropdown Button', + component: DropdownButton, +}); + +export const DropdownButtonStates = () => ( + + + {props => ( + + Test + + )} + + +); diff --git a/modules/button/react/stories/visual-testing/stories_HighlightButton.tsx b/modules/button/react/stories/visual-testing/stories_HighlightButton.tsx new file mode 100644 index 0000000000..2712c8685e --- /dev/null +++ b/modules/button/react/stories/visual-testing/stories_HighlightButton.tsx @@ -0,0 +1,42 @@ +/// +/** @jsx jsx */ +import {jsx} from '@emotion/core'; +import {StaticStates} from '@workday/canvas-kit-labs-react-core'; +import { + ComponentStatesTable, + permutateProps, + withSnapshotsEnabled, +} from '../../../../../utils/storybook'; +import {playCircleIcon} from '@workday/canvas-system-icons-web'; +import {HighlightButton} from '../../index'; +import {Container, stateTableColumnProps} from './utils'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Highlight Button', + component: HighlightButton, +}); + +export const HighlightButtonStates = () => ( + + + {props => ( + + Test + + )} + + +); diff --git a/modules/button/react/stories/visual-testing/stories_Hyperlink.tsx b/modules/button/react/stories/visual-testing/stories_Hyperlink.tsx new file mode 100644 index 0000000000..41ed0ddecd --- /dev/null +++ b/modules/button/react/stories/visual-testing/stories_Hyperlink.tsx @@ -0,0 +1,55 @@ +/// +/** @jsx jsx */ +import {jsx} from '@emotion/core'; +import {colors} from '@workday/canvas-kit-react-core'; +import {StaticStates, type} from '@workday/canvas-kit-labs-react-core'; +import { + ComponentStatesTable, + permutateProps, + withSnapshotsEnabled, +} from '../../../../../utils/storybook'; +import {Hyperlink} from '../../index'; +import {Container} from './utils'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Hyperlink', + component: Hyperlink, +}); + +export const HyperlinkStates = () => ( + + + {(props: any) => ( + +
+ Here's a Link to something +
+
+ )} +
+
+); diff --git a/modules/button/react/stories/visual-testing/stories_IconButton.tsx b/modules/button/react/stories/visual-testing/stories_IconButton.tsx new file mode 100644 index 0000000000..dd2d0857b4 --- /dev/null +++ b/modules/button/react/stories/visual-testing/stories_IconButton.tsx @@ -0,0 +1,60 @@ +/// +/** @jsx jsx */ +import {jsx} from '@emotion/core'; +import * as React from 'react'; +import {StaticStates} from '@workday/canvas-kit-labs-react-core'; +import { + ComponentStatesTable, + permutateProps, + withSnapshotsEnabled, +} from '../../../../../utils/storybook'; +import {playCircleIcon} from '@workday/canvas-system-icons-web'; +import {IconButton} from '../../index'; +import {Container, stateTableColumnProps} from './utils'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Icon Button', + component: IconButton, +}); + +export const IconButtonStates = () => ( + + {[false, true].map(toggled => ( +
+

Toggled {toggled ? 'On' : 'Off'}

+ + + {props => ( + + {}} // eslint-disable-line no-empty-function + /> + + )} + + +
+ ))} +
+); diff --git a/modules/button/react/stories/visual-testing/stories_OutlineButton.tsx b/modules/button/react/stories/visual-testing/stories_OutlineButton.tsx new file mode 100644 index 0000000000..6c4f7e772c --- /dev/null +++ b/modules/button/react/stories/visual-testing/stories_OutlineButton.tsx @@ -0,0 +1,51 @@ +/// +/** @jsx jsx */ +import {jsx} from '@emotion/core'; +import {StaticStates} from '@workday/canvas-kit-labs-react-core'; +import { + ComponentStatesTable, + permutateProps, + withSnapshotsEnabled, +} from '../../../../../utils/storybook'; +import {playCircleIcon} from '@workday/canvas-system-icons-web'; +import {OutlineButton} from '../../index'; +import {Container, stateTableColumnProps} from './utils'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Outline Button', + component: OutlineButton, +}); + +export const OutlineButtonStates = () => ( + + + {props => ( + + Test + + )} + + +); diff --git a/modules/button/react/stories/visual-testing/stories_TextButton.tsx b/modules/button/react/stories/visual-testing/stories_TextButton.tsx new file mode 100644 index 0000000000..a12eecc801 --- /dev/null +++ b/modules/button/react/stories/visual-testing/stories_TextButton.tsx @@ -0,0 +1,54 @@ +/// +/** @jsx jsx */ +import {jsx} from '@emotion/core'; +import {StaticStates} from '@workday/canvas-kit-labs-react-core'; +import { + ComponentStatesTable, + permutateProps, + withSnapshotsEnabled, +} from '../../../../../utils/storybook'; +import {playCircleIcon} from '@workday/canvas-system-icons-web'; +import {TextButton} from '../../index'; +import {Container, stateTableColumnProps} from './utils'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Text Button', + component: TextButton, +}); + +export const TextButtonStates = () => ( + + { + return true; + } + )} + columnProps={stateTableColumnProps} + > + {props => ( + + Test + + )} + + +); diff --git a/modules/button/react/stories/visual-testing/stories_ToolbarIconButton.tsx b/modules/button/react/stories/visual-testing/stories_ToolbarIconButton.tsx new file mode 100644 index 0000000000..15c9fa7bca --- /dev/null +++ b/modules/button/react/stories/visual-testing/stories_ToolbarIconButton.tsx @@ -0,0 +1,37 @@ +/// +/** @jsx jsx */ +import {jsx} from '@emotion/core'; +import * as React from 'react'; +import {StaticStates} from '@workday/canvas-kit-labs-react-core'; +import {ComponentStatesTable, withSnapshotsEnabled} from '../../../../../utils/storybook'; +import {activityStreamIcon} from '@workday/canvas-system-icons-web'; +import {ToolbarIconButton} from '../../index'; +import {Container, stateTableColumnProps} from './utils'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Toolbar Icon Button', + component: ToolbarIconButton, +}); + +export const ToolbarIconButtonStates = () => ( + + + {(props: any) => ( + + {}} // eslint-disable-line no-empty-function + /> + + )} + + +); diff --git a/modules/button/react/stories/visual-testing/stories_deprecatedButton.tsx b/modules/button/react/stories/visual-testing/stories_deprecatedButton.tsx new file mode 100644 index 0000000000..62da0d8868 --- /dev/null +++ b/modules/button/react/stories/visual-testing/stories_deprecatedButton.tsx @@ -0,0 +1,42 @@ +/// +/** @jsx jsx */ +import {jsx} from '@emotion/core'; +import {StaticStates} from '@workday/canvas-kit-labs-react-core'; +import { + ComponentStatesTable, + permutateProps, + withSnapshotsEnabled, +} from '../../../../../utils/storybook'; +import {deprecated_Button as DeprecatedButton} from '../../index'; +import {Container, stateTableColumnProps} from './utils'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Deprecated Button', + component: DeprecatedButton, +}); + +export const DeprecatedButtonStates = () => ( + + + {props => ( + + Test + + )} + + +); diff --git a/modules/button/react/stories/visual-testing/theming/stories_Button.tsx b/modules/button/react/stories/visual-testing/theming/stories_Button.tsx new file mode 100644 index 0000000000..766fd76ef6 --- /dev/null +++ b/modules/button/react/stories/visual-testing/theming/stories_Button.tsx @@ -0,0 +1,15 @@ +/// +import {customColorTheme, withSnapshotsEnabled} from '../../../../../../utils/storybook'; +import {Button} from '../../../'; +import {ButtonStates} from '../stories_Button'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Button', + component: Button, + parameters: { + canvasProviderDecorator: { + theme: customColorTheme, + }, + }, +}); +export const ButtonThemedStates = ButtonStates; diff --git a/modules/button/react/stories/visual-testing/theming/stories_DeleteButton.tsx b/modules/button/react/stories/visual-testing/theming/stories_DeleteButton.tsx new file mode 100644 index 0000000000..8d7ed2716d --- /dev/null +++ b/modules/button/react/stories/visual-testing/theming/stories_DeleteButton.tsx @@ -0,0 +1,15 @@ +/// +import {customColorTheme, withSnapshotsEnabled} from '../../../../../../utils/storybook'; +import {DeleteButton} from '../../../'; +import {DeleteButtonStates} from '../stories_DeleteButton'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Delete Button', + component: DeleteButton, + parameters: { + canvasProviderDecorator: { + theme: customColorTheme, + }, + }, +}); +export const DeleteButtonThemedStates = DeleteButtonStates; diff --git a/modules/button/react/stories/visual-testing/theming/stories_DropdownButton.tsx b/modules/button/react/stories/visual-testing/theming/stories_DropdownButton.tsx new file mode 100644 index 0000000000..70302a5aa5 --- /dev/null +++ b/modules/button/react/stories/visual-testing/theming/stories_DropdownButton.tsx @@ -0,0 +1,15 @@ +/// +import {customColorTheme, withSnapshotsEnabled} from '../../../../../../utils/storybook'; +import {DropdownButton} from '../../../'; +import {DropdownButtonStates} from '../stories_DropdownButton'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Dropdown Button', + component: DropdownButton, + parameters: { + canvasProviderDecorator: { + theme: customColorTheme, + }, + }, +}); +export const DropdownButtonThemedStates = DropdownButtonStates; diff --git a/modules/button/react/stories/visual-testing/theming/stories_HighlightButton.tsx b/modules/button/react/stories/visual-testing/theming/stories_HighlightButton.tsx new file mode 100644 index 0000000000..454bdabec1 --- /dev/null +++ b/modules/button/react/stories/visual-testing/theming/stories_HighlightButton.tsx @@ -0,0 +1,15 @@ +/// +import {customColorTheme, withSnapshotsEnabled} from '../../../../../../utils/storybook'; +import {HighlightButton} from '../../../'; +import {HighlightButtonStates} from '../stories_HighlightButton'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Highlight Button', + component: HighlightButton, + parameters: { + canvasProviderDecorator: { + theme: customColorTheme, + }, + }, +}); +export const HighlightButtonThemedStates = HighlightButtonStates; diff --git a/modules/button/react/stories/visual-testing/theming/stories_IconButton.tsx b/modules/button/react/stories/visual-testing/theming/stories_IconButton.tsx new file mode 100644 index 0000000000..959b683ec6 --- /dev/null +++ b/modules/button/react/stories/visual-testing/theming/stories_IconButton.tsx @@ -0,0 +1,15 @@ +/// +import {customColorTheme, withSnapshotsEnabled} from '../../../../../../utils/storybook'; +import {IconButton} from '../../../'; +import {IconButtonStates} from '../stories_IconButton'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Icon Button', + component: IconButton, + parameters: { + canvasProviderDecorator: { + theme: customColorTheme, + }, + }, +}); +export const IconButtonThemedStates = IconButtonStates; diff --git a/modules/button/react/stories/visual-testing/theming/stories_OutlineButton.tsx b/modules/button/react/stories/visual-testing/theming/stories_OutlineButton.tsx new file mode 100644 index 0000000000..ad4583c2c3 --- /dev/null +++ b/modules/button/react/stories/visual-testing/theming/stories_OutlineButton.tsx @@ -0,0 +1,15 @@ +/// +import {customColorTheme, withSnapshotsEnabled} from '../../../../../../utils/storybook'; +import {OutlineButton} from '../../../'; +import {OutlineButtonStates} from '../stories_OutlineButton'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Outline Button', + component: OutlineButton, + parameters: { + canvasProviderDecorator: { + theme: customColorTheme, + }, + }, +}); +export const OutlineButtonThemedStates = OutlineButtonStates; diff --git a/modules/button/react/stories/visual-testing/theming/stories_TextButton.tsx b/modules/button/react/stories/visual-testing/theming/stories_TextButton.tsx new file mode 100644 index 0000000000..0dfead1c6e --- /dev/null +++ b/modules/button/react/stories/visual-testing/theming/stories_TextButton.tsx @@ -0,0 +1,15 @@ +/// +import {customColorTheme, withSnapshotsEnabled} from '../../../../../../utils/storybook'; +import {TextButton} from '../../../'; +import {TextButtonStates} from '../stories_TextButton'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Text Button', + component: TextButton, + parameters: { + canvasProviderDecorator: { + theme: customColorTheme, + }, + }, +}); +export const TextButtonThemedStates = TextButtonStates; diff --git a/modules/button/react/stories/visual-testing/theming/stories_ToolbarIconButton.tsx b/modules/button/react/stories/visual-testing/theming/stories_ToolbarIconButton.tsx new file mode 100644 index 0000000000..a40b58b166 --- /dev/null +++ b/modules/button/react/stories/visual-testing/theming/stories_ToolbarIconButton.tsx @@ -0,0 +1,15 @@ +/// +import {customColorTheme, withSnapshotsEnabled} from '../../../../../../utils/storybook'; +import {ToolbarIconButton} from '../../../'; +import {ToolbarIconButtonStates} from '../stories_ToolbarIconButton'; + +export default withSnapshotsEnabled({ + title: 'Testing|React/Buttons/Button/Toolbar Icon Button', + component: ToolbarIconButton, + parameters: { + canvasProviderDecorator: { + theme: customColorTheme, + }, + }, +}); +export const ToolbarIconButtonThemedStates = ToolbarIconButtonStates; diff --git a/modules/button/react/stories/visual-testing/utils.tsx b/modules/button/react/stories/visual-testing/utils.tsx new file mode 100644 index 0000000000..7928ebe789 --- /dev/null +++ b/modules/button/react/stories/visual-testing/utils.tsx @@ -0,0 +1,31 @@ +/** @jsx jsx */ +import {jsx, CSSObject} from '@emotion/core'; +import {permutateProps} from '../../../../../utils/storybook'; + +const buttonLayout: CSSObject = { + display: 'flex', + alignItems: 'center', + justifyContent: 'center', +}; + +const blueBackground: CSSObject = { + ...buttonLayout, + backgroundColor: '#0875e1', + padding: '12px', + borderRadius: '4px', +}; + +export const Container = (props: any) => ( +
{props.children}
+); + +export const stateTableColumnProps = [ + {label: 'Default ', props: {className: '', disabled: false}}, + {label: 'Default Disabled', props: {className: '', disabled: true}}, + {label: 'Hover ', props: {className: 'hover', disabled: false}}, + {label: 'Hover Disabled', props: {className: 'hover', disabled: true}}, + {label: 'Focus ', props: {className: 'focus', disabled: false}}, + {label: 'Focus Hover ', props: {className: 'focus hover', disabled: false}}, + {label: 'Active ', props: {className: 'active', disabled: false}}, + {label: 'Active Hover ', props: {className: 'active hover', disabled: false}}, +]; diff --git a/modules/checkbox/react/lib/Checkbox.tsx b/modules/checkbox/react/lib/Checkbox.tsx index 8d0626ecdf..af3edff6b2 100644 --- a/modules/checkbox/react/lib/Checkbox.tsx +++ b/modules/checkbox/react/lib/Checkbox.tsx @@ -89,6 +89,17 @@ const CheckboxInputWrapper = styled('div')>({ alignSelf: 'flex-start', }); +const CheckboxRipple = styled('span')>({ + borderRadius: borderRadius.circle, + boxShadow: `0 0 0 0 ${colors.soap200}`, + height: checkboxHeight, + transition: 'box-shadow 150ms ease-out', + width: checkboxWidth, + position: 'absolute', + pointerEvents: 'none', // This is a decorative element we don't want it to block clicks to input + zIndex: -1, +}); + /** * Note: `~ div:first-of-type` refers to `CheckboxBackground` * and was easier to use than a component selector in this case. @@ -168,23 +179,8 @@ const CheckboxInput = styled('input')( }, }), }), - - // Ripple - { - '& ~ div:first-of-type::after': { - borderRadius: borderRadius.circle, - boxShadow: `0 0 0 0 ${colors.soap200}`, - content: '""', - display: 'inline-block', - height: checkboxHeight, - transition: 'box-shadow 150ms ease-out', - width: checkboxWidth, - position: 'absolute', - zIndex: -1, - }, - }, ({disabled}) => ({ - '&:hover ~ div:first-of-type::after': { + '&:hover ~ span:first-of-type': { boxShadow: disabled ? undefined : `0 0 0 ${rippleRadius}px ${colors.soap200}`, }, }), @@ -315,6 +311,7 @@ export default class Checkbox extends React.Component { error={error} {...elemProps} /> + {indeterminate ? ( diff --git a/modules/form-field/react/stories/stories_Checkbox.tsx b/modules/form-field/react/stories/stories_Checkbox.tsx index 76845b45cc..db89bedbcc 100644 --- a/modules/form-field/react/stories/stories_Checkbox.tsx +++ b/modules/form-field/react/stories/stories_Checkbox.tsx @@ -2,13 +2,7 @@ import * as React from 'react'; import {storiesOf} from '@storybook/react'; import withReadme from 'storybook-readme/with-readme'; -import {StaticStates} from '@workday/canvas-kit-labs-react-core'; -import { - ControlledComponentWrapper, - ComponentStatesTable, - permutateProps, - customColorTheme, -} from '../../../../utils/storybook'; +import {ControlledComponentWrapper} from '../../../../utils/storybook'; import {Checkbox} from '../../../checkbox/react'; import FormField from '../index'; @@ -118,70 +112,3 @@ storiesOf('Components|Inputs/Checkbox/React/Left Label', module) {control()} )); - -const CheckboxStates = () => ( - - { - if (props.indeterminate && !props.checked) { - return false; - } - return true; - } - )} - columnProps={permutateProps( - { - className: [ - {label: 'Default', value: ''}, - {label: 'Hover', value: 'hover'}, - {label: 'Focus', value: 'focus'}, - {label: 'Focus Hover', value: 'focus hover'}, - {label: 'Active', value: 'active'}, - {label: 'Active Hover', value: 'active hover'}, - ], - disabled: [{label: '', value: false}, {label: 'Disabled', value: true}], - }, - props => { - if (props.disabled && !['', 'hover'].includes(props.className)) { - return false; - } - return true; - } - )} - > - {props => ( - {}} // eslint-disable-line no-empty-function - label="Checkbox" - /> - )} - - -); - -storiesOf('Components|Inputs/Checkbox/React/Visual Testing', module) - .addParameters({ - component: Checkbox, - chromatic: { - disable: false, - }, - }) - .addDecorator(withReadme(README)) - .add('States', () => ) - .addParameters({ - canvasProviderDecorator: { - theme: customColorTheme, - }, - }) - .add('Theming', () => ); diff --git a/modules/form-field/react/stories/stories_ColorInput.tsx b/modules/form-field/react/stories/stories_ColorInput.tsx index ce44f120b7..f632acd8bc 100644 --- a/modules/form-field/react/stories/stories_ColorInput.tsx +++ b/modules/form-field/react/stories/stories_ColorInput.tsx @@ -2,13 +2,7 @@ import * as React from 'react'; import {storiesOf} from '@storybook/react'; import withReadme from 'storybook-readme/with-readme'; -import {StaticStates} from '@workday/canvas-kit-labs-react-core'; -import { - controlComponent, - ComponentStatesTable, - permutateProps, - customColorTheme, -} from '../../../../utils/storybook'; +import {controlComponent} from '../../../../utils/storybook'; import {ColorInput} from '../../../color-picker/react'; import FormField from '../index'; @@ -140,68 +134,3 @@ storiesOf('Components|Inputs/Color Picker/Color Input/React/Left Label', module) {controlComponent()} )); - -const ColorInputStates = () => ( - - { - if (props.value !== '' && props.placeholder) { - return false; - } else if (props.value === '' && props.showCheck) { - return false; - } else { - return true; - } - } - )} - columnProps={permutateProps( - { - className: [ - {label: 'Default', value: ''}, - {label: 'Hover', value: 'hover'}, - {label: 'Focus', value: 'focus'}, - {label: 'Focus Hover', value: 'focus hover'}, - {label: 'Active', value: 'active'}, - {label: 'Active Hover', value: 'active hover'}, - ], - disabled: [{label: '', value: false}, {label: 'Disabled', value: true}], - }, - props => { - if (props.disabled && !['', 'hover'].includes(props.className)) { - return false; - } - return true; - } - )} - > - {props => } - - -); - -storiesOf('Components|Inputs/Color Picker/Color Input/React/Visual Testing', module) - .addParameters({ - component: ColorInput, - chromatic: { - disable: false, - }, - }) - .addDecorator(withReadme(README)) - .add('States', () => ) - .addParameters({ - canvasProviderDecorator: { - theme: customColorTheme, - }, - }) - .add('Theming', () => ); diff --git a/modules/form-field/react/stories/stories.tsx b/modules/form-field/react/stories/stories_FormField.tsx similarity index 53% rename from modules/form-field/react/stories/stories.tsx rename to modules/form-field/react/stories/stories_FormField.tsx index 3cdb973513..8e667d8960 100644 --- a/modules/form-field/react/stories/stories.tsx +++ b/modules/form-field/react/stories/stories_FormField.tsx @@ -3,37 +3,8 @@ import * as React from 'react'; import {storiesOf} from '@storybook/react'; import withReadme from 'storybook-readme/with-readme'; import FormField from '../lib/FormField'; -import {ComponentStatesTable, permutateProps} from '../../../../utils/storybook'; -import {StaticStates} from '@workday/canvas-kit-labs-react-core'; import {TextInput} from '../../../text-input/react'; import README from '../README.md'; -import {FormFieldLabelPosition} from '../lib/types'; - -const FormFieldStates = () => ( - - - {props => ( - - - - )} - - -); storiesOf('Components|Inputs/Form Field/React', module) .addParameters({component: FormField}) @@ -83,13 +54,3 @@ storiesOf('Components|Inputs/Form Field/React', module) )); - -storiesOf('Components|Inputs/Form Field/React/Visual Testing', module) - .addParameters({ - component: FormField, - chromatic: { - disable: false, - }, - }) - .addDecorator(withReadme(README)) - .add('States', () => ); diff --git a/modules/form-field/react/stories/stories_Radio.tsx b/modules/form-field/react/stories/stories_Radio.tsx index a3cc37a4be..b5c06af4e1 100644 --- a/modules/form-field/react/stories/stories_Radio.tsx +++ b/modules/form-field/react/stories/stories_Radio.tsx @@ -2,13 +2,7 @@ import * as React from 'react'; import {storiesOf} from '@storybook/react'; import withReadme from 'storybook-readme/with-readme'; -import {StaticStates} from '@workday/canvas-kit-labs-react-core/lib/StaticStates'; -import { - ControlledComponentWrapper, - ComponentStatesTable, - permutateProps, - customColorTheme, -} from '../../../../utils/storybook'; +import {ControlledComponentWrapper} from '../../../../utils/storybook'; import {Radio, RadioGroup} from '../../../radio/react'; import FormField from '../index'; @@ -159,89 +153,3 @@ storiesOf('Components|Inputs/Radio/React/Left Label/Radio', module) )); - -const RadioStates = () => ( -
-

Radio

- - { - if (props.disabled && !['', 'hover'].includes(props.className)) { - return false; - } - return true; - } - )} - > - {props => ( - {}} // eslint-disable-line no-empty-function - label="Radio" - /> - )} - - -

Radio Group

- - - {props => ( - - - - - - - - - )} - - -
-); - -storiesOf('Components|Inputs/Radio/React/Visual Testing', module) - .addParameters({ - component: Radio, - chromatic: { - disable: false, - }, - }) - .addDecorator(withReadme(README)) - .add('States', () => ) - .addParameters({ - canvasProviderDecorator: { - theme: customColorTheme, - }, - }) - .add('Theming', () => ); diff --git a/modules/form-field/react/stories/stories_Select.tsx b/modules/form-field/react/stories/stories_Select.tsx index 6d6f69fd74..4d6f4e1716 100644 --- a/modules/form-field/react/stories/stories_Select.tsx +++ b/modules/form-field/react/stories/stories_Select.tsx @@ -2,8 +2,7 @@ import * as React from 'react'; import {storiesOf} from '@storybook/react'; import withReadme from 'storybook-readme/with-readme'; -import {StaticStates} from '@workday/canvas-kit-labs-react-core'; -import {controlComponent, ComponentStatesTable, permutateProps} from '../../../../utils/storybook'; +import {controlComponent} from '../../../../utils/storybook'; import FormField from '..'; import README from '../../../select/react/README.md'; @@ -209,53 +208,3 @@ storiesOf('Components|Inputs/Select/React/Left Label', module) )} )); - -storiesOf('Components|Inputs/Select/React/Visual Testing', module) - .addParameters({ - component: Select, - chromatic: { - disable: false, - }, - }) - .addDecorator(withReadme(README)) - .add('States', () => ( - - { - if (props.disabled && !['', 'hover'].includes(props.className)) { - return false; - } - return true; - } - )} - > - {props => ( - - )} - - - )); diff --git a/modules/form-field/react/stories/stories_Switch.tsx b/modules/form-field/react/stories/stories_Switch.tsx index 384e65297c..d0b83c2c90 100644 --- a/modules/form-field/react/stories/stories_Switch.tsx +++ b/modules/form-field/react/stories/stories_Switch.tsx @@ -2,13 +2,7 @@ import * as React from 'react'; import {storiesOf} from '@storybook/react'; import withReadme from 'storybook-readme/with-readme'; -import { - ControlledComponentWrapper, - ComponentStatesTable, - permutateProps, - customColorTheme, -} from '../../../../utils/storybook'; -import {StaticStates} from '@workday/canvas-kit-labs-react-core/lib/StaticStates'; +import {ControlledComponentWrapper} from '../../../../utils/storybook'; import {Switch} from '../../../switch/react'; import FormField from '../index'; import README from '../../../switch/react/README.md'; @@ -95,68 +89,3 @@ storiesOf('Components|Inputs/Switch/React/Left Label', module) {control()} )); - -const SwitchStates = () => ( - - { - if (props.indeterminate && !props.checked) { - return false; - } - return true; - } - )} - columnProps={permutateProps( - { - className: [ - {label: 'Default', value: ''}, - {label: 'Hover', value: 'hover'}, - {label: 'Focus', value: 'focus'}, - {label: 'Focus Hover', value: 'focus hover'}, - {label: 'Active', value: 'active'}, - {label: 'Active Hover', value: 'active hover'}, - ], - disabled: [{label: '', value: false}, {label: 'Disabled', value: true}], - }, - props => { - if (props.disabled && !['', 'hover'].includes(props.className)) { - return false; - } - return true; - } - )} - > - {props => ( - {}} // eslint-disable-line no-empty-function - /> - )} - - -); - -storiesOf('Components|Inputs/Switch/React/Visual Testing', module) - .addParameters({ - component: Switch, - chromatic: { - disable: false, - }, - }) - .addDecorator(withReadme(README)) - .add('States', () => ) - .addParameters({ - canvasProviderDecorator: { - theme: customColorTheme, - }, - }) - .add('Theming', () => ); diff --git a/modules/form-field/react/stories/stories_TextArea.tsx b/modules/form-field/react/stories/stories_TextArea.tsx index 65c79eaca6..0ecdc024b6 100644 --- a/modules/form-field/react/stories/stories_TextArea.tsx +++ b/modules/form-field/react/stories/stories_TextArea.tsx @@ -2,13 +2,7 @@ import * as React from 'react'; import {storiesOf} from '@storybook/react'; import withReadme from 'storybook-readme/with-readme'; -import {StaticStates} from '@workday/canvas-kit-labs-react-core'; -import { - controlComponent, - ComponentStatesTable, - permutateProps, - customColorTheme, -} from '../../../../utils/storybook'; +import {controlComponent} from '../../../../utils/storybook'; import {TextArea} from '../../../text-area/react'; import FormField from '../index'; @@ -162,70 +156,3 @@ storiesOf('Components|Inputs/TextArea/React/Left Label', module) {controlComponent(