diff --git a/.storybook/preview.js b/.storybook/preview.js index cf8f64c4d0..74526fc3b0 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -20,7 +20,7 @@ export const globalTypes = { theme: { name: 'Theme', description: 'Token theme', - defaultValue: 'canvas', + defaultValue: 'sana', toolbar: { icon: 'paintbrush', items: [ diff --git a/modules/docs/lib/ExampleCodeBlock.tsx b/modules/docs/lib/ExampleCodeBlock.tsx index 9457840202..7346a26eb8 100644 --- a/modules/docs/lib/ExampleCodeBlock.tsx +++ b/modules/docs/lib/ExampleCodeBlock.tsx @@ -137,7 +137,7 @@ export const ExampleCodeBlock = ({code}: any) => { {/* This allows for the div to scroll on smaller viewports while not allowing the components to overflow over the container */} - + {React.createElement(code)} {code && (
diff --git a/modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx b/modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx index e571a21066..3e1e1db2aa 100644 --- a/modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx +++ b/modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx @@ -17,6 +17,7 @@ Soon to be... - [Codemod](#codemod) - [Instructions](#instructions) - [New Components](#new-components) + - [KBD](#kbd) - [Component Updates](#component-updates) - [New Utilities](#new-utilities) - [cornerShapeStencil](#cornershapestencil) @@ -88,7 +89,35 @@ yarn remove @workday/canvas-kit-codemod ## New Components -[Content will be added] +### KBD + +**PR:** [#4001](https://github.com/Workday/canvas-kit/pull/4001) + +The new `KBD` component allows you to display keyboard inputs in your UI using accessible, visually +consistent keyboard key representations. This is useful for documenting keyboard shortcuts, +instructional prompts, or any UI patterns that reference specific keys. + +**Highlights:** + +- Provides a semantic (`kbd` element) way to visually present keyboard keys and shortcuts to users. +- Supports various variants (`default` for prominence, `plain` for use on colored surfaces), as well + as size options (`small`, `medium`, `large`). +- Easy to use nested `KBD.Item` components for sequences or combinations. +- RTL support. + +**Example:** + +```tsx +import {KBD} from '@workday/canvas-kit-labs-react'; + + + + C +; +``` + +For more details and advanced usage, including accessibility guidance for symbolic keys and +functional shortcuts, refer to the storybook documentation and our example stories. ## Component Updates diff --git a/modules/labs-react/index.ts b/modules/labs-react/index.ts index ed625199bf..936652a59f 100644 --- a/modules/labs-react/index.ts +++ b/modules/labs-react/index.ts @@ -1,2 +1,3 @@ export * from './ai-ingress-button'; +export * from './kbd'; export * from './version'; diff --git a/modules/labs-react/kbd/LICENSE b/modules/labs-react/kbd/LICENSE new file mode 100644 index 0000000000..10966086f1 --- /dev/null +++ b/modules/labs-react/kbd/LICENSE @@ -0,0 +1,52 @@ +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 + +©2021 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/labs-react/kbd/README.md b/modules/labs-react/kbd/README.md new file mode 100644 index 0000000000..b46974a751 --- /dev/null +++ b/modules/labs-react/kbd/README.md @@ -0,0 +1,11 @@ +# Canvas Kit KBD + + + LABS: Alpha + This component is work in progress and currently in prerelease. + +A compound component used to visually represent keyboard input, such as keys or keyboard shortcuts. + +View the +[documentation for KBD](https://workday.github.io/canvas-kit/?path=/docs/labs-kbd--docs) +on Storybook. diff --git a/modules/labs-react/kbd/index.ts b/modules/labs-react/kbd/index.ts new file mode 100644 index 0000000000..d1427c0fa0 --- /dev/null +++ b/modules/labs-react/kbd/index.ts @@ -0,0 +1,3 @@ +export * from './lib/KBD'; +export * from './lib/KBDItem'; +export * from './lib/useKBDModel'; diff --git a/modules/labs-react/kbd/lib/KBD.tsx b/modules/labs-react/kbd/lib/KBD.tsx new file mode 100644 index 0000000000..2398f9f13b --- /dev/null +++ b/modules/labs-react/kbd/lib/KBD.tsx @@ -0,0 +1,101 @@ +import React from 'react'; + +import {useListRenderItems} from '@workday/canvas-kit-react/collection'; +import {createContainer} from '@workday/canvas-kit-react/common'; +import {CSProps, createStencil, handleCsProp} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +import {KBDItem} from './KBDItem'; +import {useKBDModel} from './useKBDModel'; + +export interface KBDProps extends CSProps { + /** + * The children of the `KBD` container. This should contain one or more `KBD.Item` components that + * each represent a single keyboard key. If `items` are provided to the model, this should be a + * render prop that returns a `KBD.Item` for each item. + * + * @example + * // static + * + * + * C + * + * + * @example + * // dynamic + * + * {item => {item}} + * + */ + children?: React.ReactNode | ((item: string) => React.ReactNode); +} + +export const kbdStencil = createStencil({ + base: { + display: 'inline-flex', + alignItems: 'center', + gap: system.legacy.gap.xs, + }, + modifiers: { + variant: { + plain: { + color: system.color.fg.muted.default, + }, + default: { + color: system.color.fg.muted.strong, + }, + }, + size: { + large: { + span: { + ...system.type.subtext.lg, + }, + }, + medium: { + span: { + ...system.type.subtext.md, + }, + }, + small: { + span: { + ...system.type.subtext.sm, + }, + }, + }, + }, +}); + +/** + * `KBD` is a container component used to visually represent keyboard input, such as keys or + * keyboard shortcuts. It renders as a semantic `kbd` element and wraps one or more `KBD.Item` + * components. It is responsible for creating a {@link useKBDModel} and sharing the `size` and + * `variant` with its `KBD.Item` subcomponents. + * + * ```tsx + * + * + * C + * + * ``` + */ +export const KBD = createContainer('kbd')({ + displayName: 'KBD', + modelHook: useKBDModel, + subComponents: { + /** + * `KBD.Item` renders a single keyboard key as a semantic `kbd` element. + */ + Item: KBDItem, + }, +})(({children, ...elemProps}, Element, model) => { + return ( + + {useListRenderItems(model, children)} + + ); +}); diff --git a/modules/labs-react/kbd/lib/KBDItem.tsx b/modules/labs-react/kbd/lib/KBDItem.tsx new file mode 100644 index 0000000000..b2f874898e --- /dev/null +++ b/modules/labs-react/kbd/lib/KBDItem.tsx @@ -0,0 +1,92 @@ +import React from 'react'; + +import {useListItemRegister} from '@workday/canvas-kit-react/collection'; +import {cornerShapeStencil, createSubcomponent} from '@workday/canvas-kit-react/common'; +import {CSProps, createStencil, handleCsProp, px2rem} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +import {useKBDModel} from './useKBDModel'; + +export interface KBDItemProps extends CSProps { + /** + * The content of the key. This should be the label of a single keyboard key (e.g. `Ctrl`, `⌘`, + * `Enter`). + */ + children?: React.ReactNode; +} + +export const kbdItemStencil = createStencil({ + extends: cornerShapeStencil, + base: { + [cornerShapeStencil.vars.shape]: system.legacy.shape.sm, + textAlign: 'center', + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + }, + modifiers: { + variant: { + plain: { + backgroundColor: system.legacy.color.surface.transparent, + borderRadius: 0, + cornerShape: 'unset', + }, + default: { + backgroundColor: system.sana.color.surface.alt.default, + }, + }, + }, + compound: [ + { + modifiers: { + size: 'large', + variant: 'default', + }, + styles: { + minWidth: system.legacy.size.xs, + padding: `${px2rem(2)} ${system.legacy.padding.xxs}`, + }, + }, + { + modifiers: { + size: 'medium', + variant: 'default', + }, + styles: { + minWidth: system.legacy.size.xxs, + padding: `${px2rem(2)} ${system.legacy.padding.xxs}`, + }, + }, + { + modifiers: { + size: 'small', + variant: 'default', + }, + styles: { + minWidth: system.legacy.size.xxxs, + paddingInline: px2rem(2), + }, + }, + ], +}); + +/** + * `KBD.Item` renders a single keyboard key as a semantic `kbd` element. It reads the `size` and + * `variant` from the {@link useKBDModel} provided by the parent `KBD` container. + */ +export const KBDItem = createSubcomponent('kbd')({ + displayName: 'KBD.Item', + modelHook: useKBDModel, + elemPropsHook: useListItemRegister, +})(({children, ...elemProps}, Element, model) => { + return ( + + {children} + + ); +}); diff --git a/modules/labs-react/kbd/lib/useKBDModel.tsx b/modules/labs-react/kbd/lib/useKBDModel.tsx new file mode 100644 index 0000000000..60956ce442 --- /dev/null +++ b/modules/labs-react/kbd/lib/useKBDModel.tsx @@ -0,0 +1,56 @@ +import {useListModel} from '@workday/canvas-kit-react/collection'; +import {createModelHook} from '@workday/canvas-kit-react/common'; + +/** + * The `KBD` model extends the [Collection System](/get-started/for-developers/guides/collection-api/). + * It tracks the keyboard keys (`items`) and shares the `size` and `variant` of the keys with the + * `KBD.Item` subcomponents. + * + * ```tsx + * const model = useKBDModel({ + * size: 'large', + * variant: 'plain', + * items: ['⌘', 'C'], + * }); + * + * {item => {item}} + * ``` + */ +export const useKBDModel = createModelHook({ + defaultConfig: { + ...useListModel.defaultConfig, + /** + * The keyboard keys to render. Each string represents the label of a single key (e.g. `Ctrl`, + * `⌘`, `Enter`). When provided, use a render prop for the `KBD` children. + */ + items: [] as string[], + /** + * The size of the `KBD` keys. Shared with each `KBD.Item`. + * @default 'medium' + */ + size: 'medium' as 'small' | 'medium' | 'large', + /** + * The variant of the `KBD` keys. Shared with each `KBD.Item`. + * @default 'default' + */ + variant: 'default' as 'plain' | 'default', + }, + requiredConfig: useListModel.requiredConfig, + contextOverride: useListModel.Context, +})(config => { + const list = useListModel( + useListModel.mergeConfig(config, { + // `KBD` renders inline and has no scroll container, so virtualization would render no items + shouldVirtualize: false, + }) + ); + + return { + ...list, + state: { + ...list.state, + size: config.size, + variant: config.variant, + }, + }; +}); diff --git a/modules/labs-react/kbd/spec/SSR.spec.tsx b/modules/labs-react/kbd/spec/SSR.spec.tsx new file mode 100644 index 0000000000..3101a19b7b --- /dev/null +++ b/modules/labs-react/kbd/spec/SSR.spec.tsx @@ -0,0 +1,19 @@ +/** + * @jest-environment node + */ +import {renderToString} from 'react-dom/server'; + +import {KBD} from '../lib/KBD'; + +describe('KBD', () => { + it('should render on a server without crashing', () => { + const ssrRender = () => + renderToString( + + Ctrl + C + + ); + expect(ssrRender).not.toThrow(); + }); +}); diff --git a/modules/labs-react/kbd/spec/tsconfig.json b/modules/labs-react/kbd/spec/tsconfig.json new file mode 100644 index 0000000000..d079d9f251 --- /dev/null +++ b/modules/labs-react/kbd/spec/tsconfig.json @@ -0,0 +1,4 @@ + +{ + "extends": "../../../../tsconfig.spec.json" +} diff --git a/modules/labs-react/kbd/stories/KBD.mdx b/modules/labs-react/kbd/stories/KBD.mdx new file mode 100644 index 0000000000..9d2bd9552c --- /dev/null +++ b/modules/labs-react/kbd/stories/KBD.mdx @@ -0,0 +1,135 @@ +import {Meta} from '@storybook/blocks'; + +import {ExampleCodeBlock, SymbolDoc} from '@workday/canvas-kit-docs'; + +import {KBD} from '@workday/canvas-kit-labs-react/kbd'; + +import KBDStoriesMeta from './KBD.stories'; +import {Basic} from './examples/Basic'; +import {Items} from './examples/Items'; +import {RTL} from './examples/RTL'; +import {Size} from './examples/Size'; +import {Variant} from './examples/Variant'; + + + +# KBD + +`KBD` is a compound component used to visually represent keyboard input, such as keys or keyboard +shortcuts. + +## Installation + +```sh +yarn add @workday/canvas-kit-labs-react +``` + +## Usage + +### Basic Example + +`KBD` is a container that wraps one or more `KBD.Item` components. Each `KBD.Item` represents a +single keyboard key. + +> **Important:** When displaying a group of keyboard keys (such as Ctrl + C), +> **do not** place that combination as a text into a single `KBD.Item` (for example, +> `Ctrl + C`). Doing so will cause issues with RTL (right-to-left) positioning +> and keyboard shortcut display. Instead, wrap each key in its own `KBD.Item` and group them inside +> a `KBD` container. This ensures correct rendering and layout in both LTR and RTL environments. + + + +### Dynamic Items + +`KBD` is built on the [Collection API](/get-started/for-developers/guides/collection-api/). Instead +of rendering `KBD.Item` components statically, you can pass an array of strings to the `items` prop +and provide a render prop as the children. Each string represents the label of a single keyboard +key. + + + +### RTL Example + +You can also use the `KBD` component in right-to-left (RTL) layouts. This is helpful for languages +that are read from right to left. + + + +### Size + +The `KBD` component supports different sizes. You can adjust the size using the `size` prop with +options like `small`, `medium`, and `large` to suit various UI needs. The `size` is shared with each +`KBD.Item` through the model. + + + +### Variant + +The `KBD` component supports different variants through the `variant` prop. Use `default` for the +standard style or `plain` for a more minimal appearance. The `variant` is shared with each +`KBD.Item` through the model. + + + +## Accessibility + +`KBD` is **presentational and semantic text**. It renders a `kbd` element so assistive technology +can recognize the content as keyboard input, but it does **not** make a keyboard shortcut work or +expose it to the browser. It is the visual/semantic representation of a key, not the accessibility +contract for a functioning shortcut. + +### Provide spoken labels for symbolic or abbreviated keys + +Glyphs and abbreviations such as , , , and arrow keys are **not +announced reliably** across screen reader, browser, and OS combinations. When a `KBD.Item` contains +a symbol or abbreviation, add an `aria-label` with the spoken name of the key so it is announced +consistently: + +```tsx + + + C + +``` + +Plain alphanumeric keys (such as `C` above) read correctly on their own and don't need an +`aria-label`. + +### Expose the actual shortcut on the control it triggers + +`KBD` only documents a shortcut visually. If the shortcut is functional, also expose it on the +relevant interactive control using +[`aria-keyshortcuts`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-keyshortcuts) +so assistive technology can communicate it to users: + +```tsx + +``` + +## Component API + + + +## Model + +`KBD` uses a `useKBDModel` to track the keyboard keys (`items`) and to share the `size` and +`variant` with each `KBD.Item`. If you need direct access to the model's state, you can create it +yourself with `useKBDModel` and pass it to `KBD` via the `model` prop. + +```tsx +const model = useKBDModel({ + size: 'large', + variant: 'plain', + items: ['⌘', 'C'], +}); + +{item => {item}}; +``` + + diff --git a/modules/labs-react/kbd/stories/KBD.stories.tsx b/modules/labs-react/kbd/stories/KBD.stories.tsx new file mode 100644 index 0000000000..fb825e5b53 --- /dev/null +++ b/modules/labs-react/kbd/stories/KBD.stories.tsx @@ -0,0 +1,38 @@ +import {Meta} from '@storybook/react'; + +import mdxDoc from './KBD.mdx'; +import {Basic as BasicExample} from './examples/Basic'; +import {Items as ItemsExample} from './examples/Items'; +import {RTL as RTLExample} from './examples/RTL'; +import {Size as SizeExample} from './examples/Size'; +import {Variant as VariantExample} from './examples/Variant'; + +export default { + title: 'Labs/KBD', + tags: ['autodocs'], + parameters: { + docs: { + page: mdxDoc, + }, + }, +} as Meta; + +export const Basic = { + render: BasicExample, +}; + +export const RTL = { + render: RTLExample, +}; + +export const Size = { + render: SizeExample, +}; + +export const Variant = { + render: VariantExample, +}; + +export const Items = { + render: ItemsExample, +}; diff --git a/modules/labs-react/kbd/stories/examples/Basic.tsx b/modules/labs-react/kbd/stories/examples/Basic.tsx new file mode 100644 index 0000000000..4b854243d9 --- /dev/null +++ b/modules/labs-react/kbd/stories/examples/Basic.tsx @@ -0,0 +1,42 @@ +import {KBD} from '@workday/canvas-kit-labs-react/kbd'; +import {BodyText} from '@workday/canvas-kit-react/text'; +import {createStyles} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +const containerStyles = createStyles({ + gap: system.gap.md, + display: 'flex', + flexDirection: 'column', +}); + +export const Basic = () => { + return ( +
+ + Press + + F + + to pay respects. + + + + C + + + Shift + + + P + + + + + Shift + + + P + + + +
+ ); +}; diff --git a/modules/labs-react/kbd/stories/examples/Items.tsx b/modules/labs-react/kbd/stories/examples/Items.tsx new file mode 100644 index 0000000000..c8bc009df2 --- /dev/null +++ b/modules/labs-react/kbd/stories/examples/Items.tsx @@ -0,0 +1,19 @@ +import {KBD} from '@workday/canvas-kit-labs-react/kbd'; +import {createStyles} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +const containerStyles = createStyles({ + gap: system.gap.md, + display: 'flex', + flexDirection: 'column', +}); + +const items = ['⌘', 'Shift', 'P']; + +export const Items = () => { + return ( +
+ {item => {item}} +
+ ); +}; diff --git a/modules/labs-react/kbd/stories/examples/RTL.tsx b/modules/labs-react/kbd/stories/examples/RTL.tsx new file mode 100644 index 0000000000..46bf517a2c --- /dev/null +++ b/modules/labs-react/kbd/stories/examples/RTL.tsx @@ -0,0 +1,37 @@ +import {KBD} from '@workday/canvas-kit-labs-react/kbd'; +import {createStyles} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +const containerStyles = createStyles({ + gap: system.gap.md, + display: 'flex', + flexDirection: 'column', +}); + +export const RTL = () => { + return ( +
+ + F + + + + C + + + Shift + + + P + + + + + Shift + + + P + + + +
+ ); +}; diff --git a/modules/labs-react/kbd/stories/examples/Size.tsx b/modules/labs-react/kbd/stories/examples/Size.tsx new file mode 100644 index 0000000000..2b8f8661e0 --- /dev/null +++ b/modules/labs-react/kbd/stories/examples/Size.tsx @@ -0,0 +1,49 @@ +import {KBD} from '@workday/canvas-kit-labs-react/kbd'; +import {Subtext} from '@workday/canvas-kit-react/text'; +import {createStyles, px2rem} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +const containerStyles = createStyles({ + gap: system.gap.md, + display: 'flex', + flexDirection: 'column', +}); + +const rowStyles = createStyles({ + display: 'flex', + alignItems: 'center', + gap: system.gap.md, + p: { + minWidth: px2rem(104), + margin: 0, + }, +}); + +export const Size = () => { + return ( +
+
+ Large Size + + + C + +
+
+ Medium Size + + Shift + + + A + +
+
+ Small Size + + Ctrl + V + +
+
+ ); +}; diff --git a/modules/labs-react/kbd/stories/examples/Variant.tsx b/modules/labs-react/kbd/stories/examples/Variant.tsx new file mode 100644 index 0000000000..9d8ba5ce61 --- /dev/null +++ b/modules/labs-react/kbd/stories/examples/Variant.tsx @@ -0,0 +1,42 @@ +import {KBD} from '@workday/canvas-kit-labs-react/kbd'; +import {Subtext} from '@workday/canvas-kit-react/text'; +import {createStyles, px2rem} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +const containerStyles = createStyles({ + gap: system.gap.md, + display: 'flex', + flexDirection: 'column', + p: { + minWidth: px2rem(104), + margin: 0, + }, +}); + +const rowStyles = createStyles({ + display: 'flex', + alignItems: 'center', + gap: system.gap.md, +}); + +export const Variant = () => { + return ( +
+
+ Default Variant + + + C + +
+
+ Plain Variant + + Shift + + + A + +
+
+ ); +}; diff --git a/modules/labs-react/kbd/stories/tsconfig.json b/modules/labs-react/kbd/stories/tsconfig.json new file mode 100644 index 0000000000..721d5175e2 --- /dev/null +++ b/modules/labs-react/kbd/stories/tsconfig.json @@ -0,0 +1,4 @@ + +{ + "extends": "../../../../tsconfig.stories.json" +} diff --git a/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx b/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx new file mode 100644 index 0000000000..9e5d4444c6 --- /dev/null +++ b/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx @@ -0,0 +1,47 @@ +import {KBD} from '@workday/canvas-kit-labs-react/kbd'; +import { + ComponentStatesTable, + StaticStates, + permutateProps, +} from '@workday/canvas-kit-react/testing'; +import {createStencil, createStyles} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +export default { + title: 'Testing/Labs/KBD', + component: KBD, + parameters: { + chromatic: { + disable: false, + }, + }, +}; + +export const KBDStates = () => ( + + + {props => ( +
+ + + C + +
+ )} +
+
+); diff --git a/modules/react/testing/lib/StaticStates.tsx b/modules/react/testing/lib/StaticStates.tsx index fb68664d56..c0d4bad604 100644 --- a/modules/react/testing/lib/StaticStates.tsx +++ b/modules/react/testing/lib/StaticStates.tsx @@ -43,7 +43,12 @@ export const StaticStates: React.FC< localTheme._styleRewriteFn = convertToStaticStates; return ( - + {children} );