diff --git a/cypress/component/Accessory.spec.tsx b/cypress/component/Accessory.spec.tsx new file mode 100644 index 0000000000..2c78e5a041 --- /dev/null +++ b/cypress/component/Accessory.spec.tsx @@ -0,0 +1,45 @@ +import {Basic} from '../../modules/labs-react/accessory/stories/examples/Basic'; +import {Calendar} from '../../modules/labs-react/accessory/stories/examples/Calendar'; +import {Custom} from '../../modules/labs-react/accessory/stories/examples/Custom'; +import {Favicon} from '../../modules/labs-react/accessory/stories/examples/Favicon'; +import {File} from '../../modules/labs-react/accessory/stories/examples/File'; +import {Icon} from '../../modules/labs-react/accessory/stories/examples/Icon'; +import {Media} from '../../modules/labs-react/accessory/stories/examples/Media'; +import {Sizes} from '../../modules/labs-react/accessory/stories/examples/Sizes'; +import {Variants} from '../../modules/labs-react/accessory/stories/examples/Variants'; + +describe('Accessory', () => { + beforeEach(() => { + // Stub the remote image so this spec does not depend on picsum.photos (blocked/slow in CI). + cy.intercept('GET', 'https://picsum.photos/**', { + fixture: 'avatar.png', + headers: {'content-type': 'image/png'}, + }); + cy.intercept('GET', 'https://www.google.com/s2/favicons*', { + fixture: 'avatar.png', + headers: {'content-type': 'image/png'}, + }); + }); + + [Basic, Icon, Media, Favicon, File, Calendar, Custom, Sizes, Variants].forEach(Example => { + context(`given the ${Example.name} story is rendered`, () => { + beforeEach(() => { + cy.mount(); + }); + + it('should not have any axe errors', () => { + cy.checkA11y(); + }); + }); + }); + + context('given the Media story is rendered', () => { + beforeEach(() => { + cy.mount(); + }); + + it('should render the image', () => { + cy.get('img[alt="Random photo"]').should('be.visible'); + }); + }); +}); diff --git a/modules/labs-react/accessory/LICENSE b/modules/labs-react/accessory/LICENSE new file mode 100644 index 0000000000..10966086f1 --- /dev/null +++ b/modules/labs-react/accessory/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/accessory/README.md b/modules/labs-react/accessory/README.md new file mode 100644 index 0000000000..d200b97285 --- /dev/null +++ b/modules/labs-react/accessory/README.md @@ -0,0 +1,12 @@ +# Canvas Kit Accessory + + + LABS: Alpha + This component is work in progress and currently in prerelease. + +A small rounded visual that sits beside text. Prefer `AccessoryIcon`, `AccessoryFile`, +`AccessoryMedia`, `AccessoryFavicon`, or `AccessoryCalendar`. Use `Accessory` for custom content. + +View the +[documentation for Accessory](https://workday.github.io/canvas-kit/?path=/docs/labs-accessory--docs) +on Storybook. diff --git a/modules/labs-react/accessory/index.ts b/modules/labs-react/accessory/index.ts new file mode 100644 index 0000000000..991aa8e479 --- /dev/null +++ b/modules/labs-react/accessory/index.ts @@ -0,0 +1,6 @@ +export * from './lib/Accessory'; +export * from './lib/AccessoryCalendar'; +export * from './lib/AccessoryFavicon'; +export * from './lib/AccessoryFile'; +export * from './lib/AccessoryIcon'; +export * from './lib/AccessoryMedia'; diff --git a/modules/labs-react/accessory/lib/Accessory.tsx b/modules/labs-react/accessory/lib/Accessory.tsx new file mode 100644 index 0000000000..0b58d5e6a7 --- /dev/null +++ b/modules/labs-react/accessory/lib/Accessory.tsx @@ -0,0 +1,156 @@ +import {cornerShapeStencil, createComponent} from '@workday/canvas-kit-react/common'; +import {systemIconStencil} from '@workday/canvas-kit-react/icon'; +import {CSProps, createStencil, cssVar, handleCsProp} from '@workday/canvas-kit-styling'; +import {base, component, system} from '@workday/canvas-tokens-web'; + +/** + * The size of an `Accessory` tile. + * + * * `extraSmall` — 16px tile, 16px icon + * * `small` — 20px tile, 18px icon + * * `medium` — 24px tile, 16px icon + * * `large` — 32px tile, 18px icon + * * `extraLarge` — 40px tile, 20px icon + */ +export type AccessorySize = 'extraSmall' | 'small' | 'medium' | 'large' | 'extraLarge'; + +export interface AccessoryProps extends CSProps { + /** + * The size of the tile. Icon glyph size follows the tile through the icon `data-part`: 16px, + * 18px, 16px, 18px, and 20px from `extraSmall` to `extraLarge`. + * + * * `extraSmall` — 16px + * * `small` — 20px + * * `medium` — 24px + * * `large` — 32px + * * `extraLarge` — 40px + * + * @default 'extraLarge' + */ + size?: AccessorySize; + /** + * The color of the icon. When set, this overrides the icon color from `variant` on + * `AccessoryIcon`. Inherited by the icon `data-part` via a CSS variable. + */ + color?: string; + /** + * The background color of the icon tile. When set, this overrides the fill from `variant` and is + * painted at every size, including `small` and `extraSmall`. Inherited by the icon `data-part` + * via a CSS variable. + */ + background?: string; +} + +/** + * Tile shell for accessory visuals. Owns size, corner radius, icon glyph size, and optional icon + * color / fill overrides through the icon `data-part`. Prefer `AccessoryIcon`, `AccessoryFile`, or + * `AccessoryMedia`, which render this shell. + */ +export const accessoryStencil = createStencil({ + extends: cornerShapeStencil, + vars: { + iconColor: '', + tileBackground: '', + }, + parts: { + icon: 'accessory-icon', + }, + base: ({iconColor, iconPart}) => ({ + display: 'inline-flex', + position: 'relative', + alignItems: 'center', + justifyContent: 'center', + flexShrink: 0, + verticalAlign: 'middle', + [iconPart]: { + position: 'absolute', + inset: 0, + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + borderRadius: cssVar(cornerShapeStencil.vars.shape), + cornerShape: 'superellipse(1.1)', + [systemIconStencil.vars.color]: cssVar(iconColor), + }, + }), + modifiers: { + size: { + extraSmall: ({iconPart, tileBackground}) => ({ + width: system.legacy.size.xxxs, + height: system.legacy.size.xxxs, + [cornerShapeStencil.vars.shape]: system.legacy.shape.sm, + [iconPart]: { + [systemIconStencil.vars.size]: base.legacy.size200, + backgroundColor: cssVar(tileBackground, 'transparent'), + borderWidth: 0, + }, + }), + small: ({iconPart, tileBackground}) => ({ + width: system.legacy.size.xxs, + height: system.legacy.size.xxs, + [cornerShapeStencil.vars.shape]: system.sana.shape.sm, + [iconPart]: { + [systemIconStencil.vars.size]: base.legacy.size225, + backgroundColor: cssVar(tileBackground, 'transparent'), + borderWidth: 0, + }, + }), + medium: ({iconPart}) => ({ + width: system.legacy.size.xs, + height: system.legacy.size.xs, + [cornerShapeStencil.vars.shape]: system.legacy.shape.md, + [iconPart]: { + [systemIconStencil.vars.size]: component.legacy.systemIcon.size.xs, + }, + }), + large: ({iconPart}) => ({ + width: system.legacy.size.sm, + height: system.legacy.size.sm, + [cornerShapeStencil.vars.shape]: base.legacy.size125, + [iconPart]: { + [systemIconStencil.vars.size]: component.legacy.systemIcon.size.sm, + }, + }), + extraLarge: ({iconPart}) => ({ + width: system.legacy.size.md, + height: system.legacy.size.md, + [cornerShapeStencil.vars.shape]: system.legacy.shape.lg, + [iconPart]: { + [systemIconStencil.vars.size]: component.legacy.systemIcon.size.md, + }, + }), + }, + }, +}); + +/** + * `Accessory` is the small rounded visual that sits beside text, most often the leading element in + * a list item or other row. It owns the tile size and corner radius so a system icon, file type, + * image, site favicon, calendar date, or custom content stays one consistent shape. + * `AccessoryIcon`, `AccessoryFile`, `AccessoryMedia`, `AccessoryFavicon`, and `AccessoryCalendar` + * render this shell. Accessories are + * decorative and always hidden from assistive technology. + * + * ```tsx + * + * ``` + */ +export const Accessory = createComponent('span')({ + displayName: 'Accessory', + Component: ( + {size = 'extraLarge', color, background, ...elemProps}: AccessoryProps, + ref, + Element + ) => { + return ( + + ); + }, +}); diff --git a/modules/labs-react/accessory/lib/AccessoryCalendar.tsx b/modules/labs-react/accessory/lib/AccessoryCalendar.tsx new file mode 100644 index 0000000000..d399c8305b --- /dev/null +++ b/modules/labs-react/accessory/lib/AccessoryCalendar.tsx @@ -0,0 +1,86 @@ +import {createComponent} from '@workday/canvas-kit-react/common'; +import {createStencil, cssVar, handleCsProp, px2rem} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +import {Accessory, AccessoryProps, accessoryStencil} from './Accessory'; + +export interface AccessoryCalendarProps extends AccessoryProps { + /** + * The month label, such as `Apr`. + */ + month: string; + /** + * The day of the month, such as `30`. + */ + date: number | string; +} + +/** + * Calendar treatment for `AccessoryCalendar`. The month uses a critical color. The day uses the + * default foreground color. `color` overrides the month. `background` overrides the tile fill. + */ +export const accessoryCalendarStencil = createStencil({ + parts: { + icon: 'accessory-icon', + month: 'accessory-calendar-month', + date: 'accessory-calendar-date', + }, + base: ({datePart, iconPart, monthPart}) => ({ + [iconPart]: { + flexDirection: 'column', + // 2px month margin plus 1px stack gap in the Sana accessory calendar. + gap: px2rem(3), + overflow: 'hidden', + backgroundColor: cssVar( + accessoryStencil.vars.tileBackground, + system.legacy.color.surface.default + ), + borderWidth: px2rem(1), + borderStyle: 'solid', + borderColor: system.legacy.color.border.default, + }, + [monthPart]: { + color: cssVar(accessoryStencil.vars.iconColor, system.legacy.color.fg.danger.default), + fontSize: system.legacy.fontSize.subtext.sm, + fontWeight: system.fontWeight.medium, + lineHeight: 1, + transform: `translateY(${px2rem(1)})`, + }, + [datePart]: { + color: system.color.fg.default, + fontSize: system.legacy.fontSize.body.sm, + fontWeight: system.fontWeight.normal, + lineHeight: 1, + transform: `translateY(${px2rem(1)})`, + }, + }), +}); + +/** + * `AccessoryCalendar` renders a month and day in an accessory tile. The month is critical and the + * day is the default foreground color. Always decorative. + */ +export const AccessoryCalendar = createComponent('span')({ + displayName: 'AccessoryCalendar', + Component: ( + {month, date, size = 'extraLarge', color, background, ...elemProps}: AccessoryCalendarProps, + ref, + Element + ) => { + return ( + + + {month} + {date} + + + ); + }, +}); diff --git a/modules/labs-react/accessory/lib/AccessoryFavicon.tsx b/modules/labs-react/accessory/lib/AccessoryFavicon.tsx new file mode 100644 index 0000000000..aaf129ac69 --- /dev/null +++ b/modules/labs-react/accessory/lib/AccessoryFavicon.tsx @@ -0,0 +1,157 @@ +import {createComponent} from '@workday/canvas-kit-react/common'; +import {createStencil, cssVar, handleCsProp, px2rem} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +import {Accessory, AccessoryProps, AccessorySize, accessoryStencil} from './Accessory'; + +/** Hostname from a site URL or a bare domain such as `gmail.com`. */ +function hostnameFromSiteUrl(siteUrl: string): string { + const trimmed = siteUrl.trim(); + if (!trimmed) { + return ''; + } + + try { + const withProtocol = /^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`; + return new URL(withProtocol).hostname || ''; + } catch { + return ''; + } +} + +/** + * Brand favicon URL for a site, resolved through the public Google favicon endpoint. Tiles larger + * than 32px request a 180px source. Smaller tiles request 64px. + */ +function faviconSrcFromSiteUrl(siteUrl: string, size: AccessorySize): string { + const host = hostnameFromSiteUrl(siteUrl); + if (!host) { + return ''; + } + + const sourceSize = size === 'extraLarge' ? 180 : 64; + return `https://www.google.com/s2/favicons?domain=${encodeURIComponent(host)}&sz=${sourceSize}`; +} + +export interface AccessoryFaviconProps extends AccessoryProps { + /** + * The site URL or bare domain, such as `https://mail.google.com` or `gmail.com`. The hostname is + * used to resolve the favicon. + */ + url: string; +} + +/** + * Favicon treatment for `AccessoryFavicon`. At `large` and `extraLarge` the mark is inset in an + * outlined tile. At `medium` and smaller the mark fills the tile and the frame is removed. + * `background` overrides the tile fill. + */ +export const accessoryFaviconStencil = createStencil({ + parts: { + icon: 'accessory-icon', + image: 'accessory-favicon-image', + }, + base: ({iconPart, imagePart}) => ({ + [iconPart]: { + overflow: 'hidden', + backgroundColor: cssVar( + accessoryStencil.vars.tileBackground, + system.legacy.color.surface.default + ), + borderWidth: px2rem(1), + borderStyle: 'solid', + borderColor: system.legacy.color.border.default, + }, + [imagePart]: { + width: `calc(100% - ${cssVar(system.space.x3)})`, + height: `calc(100% - ${cssVar(system.space.x3)})`, + objectFit: 'contain', + borderRadius: system.legacy.shape.md, + cornerShape: 'superellipse(1.1)', + }, + }), + modifiers: { + size: { + extraSmall: ({iconPart, imagePart}) => ({ + [iconPart]: { + backgroundColor: cssVar(accessoryStencil.vars.tileBackground, 'transparent'), + borderWidth: 0, + }, + [imagePart]: { + width: '100%', + height: '100%', + borderRadius: 0, + }, + }), + small: ({iconPart, imagePart}) => ({ + [iconPart]: { + backgroundColor: cssVar(accessoryStencil.vars.tileBackground, 'transparent'), + borderWidth: 0, + }, + [imagePart]: { + width: '100%', + height: '100%', + borderRadius: 0, + }, + }), + medium: ({iconPart, imagePart}) => ({ + [iconPart]: { + backgroundColor: cssVar(accessoryStencil.vars.tileBackground, 'transparent'), + borderWidth: 0, + }, + [imagePart]: { + width: '100%', + height: '100%', + borderRadius: 0, + }, + }), + large: {}, + extraLarge: {}, + }, + }, + defaultModifiers: { + size: 'extraLarge', + }, +}); + +/** + * `AccessoryFavicon` renders a site favicon in an accessory tile. Pass a site URL or domain as + * `url`. The mark is inset in an outlined frame at `large` and `extraLarge`, and fills the tile at + * smaller sizes. Always decorative. + * + * The image is requested from the user's browser at `https://www.google.com/s2/favicons`. Google + * receives the hostname and the user's IP address. `referrerPolicy="no-referrer"` keeps the app + * origin off that request. It does not proxy the request. + */ +export const AccessoryFavicon = createComponent('span')({ + displayName: 'AccessoryFavicon', + Component: ( + {url, size = 'extraLarge', background, ...elemProps}: AccessoryFaviconProps, + ref, + Element + ) => { + const src = faviconSrcFromSiteUrl(url, size); + + return ( + + {src ? ( + + + + ) : null} + + ); + }, +}); diff --git a/modules/labs-react/accessory/lib/AccessoryFile.tsx b/modules/labs-react/accessory/lib/AccessoryFile.tsx new file mode 100644 index 0000000000..97b4bf1420 --- /dev/null +++ b/modules/labs-react/accessory/lib/AccessoryFile.tsx @@ -0,0 +1,138 @@ +import {createComponent} from '@workday/canvas-kit-react/common'; +import {SystemIcon, SystemIconProps, systemIconStencil} from '@workday/canvas-kit-react/icon'; +import {createStencil, cssVar, handleCsProp, px2rem} from '@workday/canvas-kit-styling'; +import { + documentIcon, + pdfIcon, + playCircleIcon, + stackIcon, + tableExpandIcon, + txtIcon, +} from '@workday/canvas-system-icons-web'; +import {system} from '@workday/canvas-tokens-web'; + +import {Accessory, AccessoryProps, accessoryStencil} from './Accessory'; + +/** + * The kind of file `AccessoryFile` represents. + */ +export type AccessoryFileType = + | 'pdf' + | 'spreadsheet' + | 'document' + | 'presentation' + | 'video' + | 'file' + | 'txt'; + +export interface AccessoryFileProps extends AccessoryProps { + /** + * The file type. Chooses the glyph and sets the tile fill and icon color through a stencil + * modifier. Colored types keep their accent fill at every size. `file` and `txt` use + * `surface.alt` with a `border.default` stroke. `video` uses `surface.alt` and an inverse icon. + * `color` and `background` override the type colors. + * @default 'file' + */ + type?: AccessoryFileType; +} + +/** + * File-type treatment for `AccessoryFile`. Each `type` sets the tile fill and icon color. + * `outline` adds the default border used by `file` and `txt`. `color` and `background` on + * `Accessory` still override the type colors. + */ +export const accessoryFileStencil = createStencil({ + parts: { + icon: 'accessory-icon', + }, + base: ({iconPart}) => ({ + [iconPart]: { + backgroundColor: cssVar(accessoryStencil.vars.tileBackground), + [systemIconStencil.vars.color]: cssVar(accessoryStencil.vars.iconColor), + }, + }), + modifiers: { + type: { + pdf: { + [accessoryStencil.vars.iconColor]: system.color.fg.inverse, + [accessoryStencil.vars.tileBackground]: system.legacy.color.accent.danger, + }, + spreadsheet: { + [accessoryStencil.vars.iconColor]: system.color.fg.inverse, + [accessoryStencil.vars.tileBackground]: system.legacy.color.accent.success, + }, + document: { + [accessoryStencil.vars.iconColor]: system.color.fg.inverse, + [accessoryStencil.vars.tileBackground]: system.legacy.color.accent.info, + }, + presentation: { + [accessoryStencil.vars.iconColor]: system.color.fg.inverse, + [accessoryStencil.vars.tileBackground]: system.legacy.color.accent.warning, + }, + video: { + [accessoryStencil.vars.iconColor]: system.color.fg.default, + [accessoryStencil.vars.tileBackground]: system.legacy.color.surface.alt.default, + }, + file: { + [accessoryStencil.vars.iconColor]: system.color.fg.default, + [accessoryStencil.vars.tileBackground]: system.legacy.color.surface.alt.default, + }, + txt: { + [accessoryStencil.vars.iconColor]: system.color.fg.default, + [accessoryStencil.vars.tileBackground]: system.legacy.color.surface.alt.default, + }, + }, + outline: { + true: ({iconPart}) => ({ + [iconPart]: { + borderWidth: px2rem(1), + borderStyle: 'solid', + borderColor: system.legacy.color.border.default, + }, + }), + }, + }, + defaultModifiers: { + type: 'file', + }, +}); + +const fileIcons: Record = { + pdf: pdfIcon, + spreadsheet: tableExpandIcon, + document: documentIcon, + presentation: stackIcon, + video: playCircleIcon, + file: documentIcon, + txt: txtIcon, +}; + +/** + * `AccessoryFile` renders a file-type tile. `type` chooses the glyph and sets the fill and icon + * color. Colored types keep their fill at every size. Generic file and text use `surface.alt` and + * a `border.default` stroke. Always decorative. + */ +export const AccessoryFile = createComponent('span')({ + displayName: 'AccessoryFile', + Component: ( + {type = 'file', size = 'extraLarge', color, background, ...elemProps}: AccessoryFileProps, + ref, + Element + ) => { + return ( + + + + ); + }, +}); diff --git a/modules/labs-react/accessory/lib/AccessoryIcon.tsx b/modules/labs-react/accessory/lib/AccessoryIcon.tsx new file mode 100644 index 0000000000..34059d3f08 --- /dev/null +++ b/modules/labs-react/accessory/lib/AccessoryIcon.tsx @@ -0,0 +1,213 @@ +import {createComponent} from '@workday/canvas-kit-react/common'; +import {SystemIcon, SystemIconProps, systemIconStencil} from '@workday/canvas-kit-react/icon'; +import {createStencil, cssVar, handleCsProp, px2rem} from '@workday/canvas-kit-styling'; +import {base, system} from '@workday/canvas-tokens-web'; + +import {Accessory, AccessoryProps, accessoryStencil} from './Accessory'; + +/** + * The color treatment of `AccessoryIcon`. + */ +export type AccessoryIconVariant = + | 'grey' + | 'green' + | 'blue' + | 'purple' + | 'amber' + | 'magenta' + | 'red' + | 'orange' + | 'outline'; + +export interface AccessoryIconProps extends AccessoryProps { + /** + * The icon to display from `@workday/canvas-system-icons-web`. + */ + icon: SystemIconProps['icon']; + /** + * The color treatment of the icon and, at `medium` and above, the tile fill. `color` and + * `background` from `Accessory` override these. Variant fills stay hidden at `small` and + * `extraSmall` unless `background` is set. + * @default 'grey' + */ + variant?: AccessoryIconVariant; +} + +/** + * Color treatment for `AccessoryIcon`. `variant` paints the icon part. `extraSmall` and `small` + * clear that fill and border unless `background` sets the tile variable. `color` and `background` + * on `Accessory` still override the variant. + */ +export const accessoryIconStencil = createStencil({ + parts: { + icon: 'accessory-icon', + }, + base: {}, + modifiers: { + variant: { + grey: ({iconPart}) => ({ + [iconPart]: { + backgroundColor: cssVar( + accessoryStencil.vars.tileBackground, + system.legacy.color.surface.alt.strong + ), + [systemIconStencil.vars.color]: cssVar( + accessoryStencil.vars.iconColor, + base.legacy.slate800 + ), + }, + }), + green: ({iconPart}) => ({ + [iconPart]: { + backgroundColor: cssVar( + accessoryStencil.vars.tileBackground, + system.legacy.color.surface.success.strong + ), + [systemIconStencil.vars.color]: cssVar( + accessoryStencil.vars.iconColor, + base.legacy.green800 + ), + }, + }), + blue: ({iconPart}) => ({ + [iconPart]: { + backgroundColor: cssVar( + accessoryStencil.vars.tileBackground, + system.legacy.color.surface.info.strong + ), + [systemIconStencil.vars.color]: cssVar( + accessoryStencil.vars.iconColor, + system.legacy.color.fg.info.strong + ), + }, + }), + purple: ({iconPart}) => ({ + [iconPart]: { + backgroundColor: cssVar(accessoryStencil.vars.tileBackground, base.legacy.purpleA50), + [systemIconStencil.vars.color]: cssVar( + accessoryStencil.vars.iconColor, + base.legacy.purple700 + ), + }, + }), + amber: ({iconPart}) => ({ + [iconPart]: { + backgroundColor: cssVar( + accessoryStencil.vars.tileBackground, + system.legacy.color.surface.warning.strong + ), + [systemIconStencil.vars.color]: cssVar( + accessoryStencil.vars.iconColor, + system.legacy.color.fg.warning.strong + ), + }, + }), + magenta: ({iconPart}) => ({ + [iconPart]: { + backgroundColor: cssVar(accessoryStencil.vars.tileBackground, base.legacy.magentaA50), + [systemIconStencil.vars.color]: cssVar( + accessoryStencil.vars.iconColor, + base.legacy.magenta800 + ), + }, + }), + red: ({iconPart}) => ({ + [iconPart]: { + backgroundColor: cssVar( + accessoryStencil.vars.tileBackground, + system.legacy.color.surface.danger.strong + ), + [systemIconStencil.vars.color]: cssVar( + accessoryStencil.vars.iconColor, + system.legacy.color.fg.danger.strong + ), + }, + }), + orange: ({iconPart}) => ({ + [iconPart]: { + backgroundColor: cssVar(accessoryStencil.vars.tileBackground, base.legacy.orangeA50), + [systemIconStencil.vars.color]: cssVar( + accessoryStencil.vars.iconColor, + base.legacy.orange700 + ), + }, + }), + outline: ({iconPart}) => ({ + [iconPart]: { + backgroundColor: cssVar( + accessoryStencil.vars.tileBackground, + system.legacy.color.surface.transparent + ), + [systemIconStencil.vars.color]: cssVar( + accessoryStencil.vars.iconColor, + base.legacy.slate800 + ), + borderWidth: px2rem(1), + borderStyle: 'solid', + borderColor: system.legacy.color.border.default, + }, + }), + }, + size: { + extraSmall: {}, + small: {}, + medium: {}, + large: {}, + extraLarge: {}, + }, + }, + compound: [ + { + modifiers: {size: 'extraSmall'}, + styles: ({iconPart}) => ({ + [iconPart]: { + backgroundColor: cssVar(accessoryStencil.vars.tileBackground, 'transparent'), + borderWidth: 0, + }, + }), + }, + { + modifiers: {size: 'small'}, + styles: ({iconPart}) => ({ + [iconPart]: { + backgroundColor: cssVar(accessoryStencil.vars.tileBackground, 'transparent'), + borderWidth: 0, + }, + }), + }, + ], +}); + +/** + * `AccessoryIcon` renders a system icon in an accessory tile. `variant` sets the tile fill and + * icon color. `color` and `background` on the shared `Accessory` props override the variant. The + * glyph size comes from `size` on `Accessory` through the icon `data-part`. Always decorative. + */ +export const AccessoryIcon = createComponent('span')({ + displayName: 'AccessoryIcon', + Component: ( + { + icon, + size = 'extraLarge', + variant = 'grey', + color, + background, + ...elemProps + }: AccessoryIconProps, + ref, + Element + ) => { + return ( + + + + ); + }, +}); diff --git a/modules/labs-react/accessory/lib/AccessoryMedia.tsx b/modules/labs-react/accessory/lib/AccessoryMedia.tsx new file mode 100644 index 0000000000..a87a1a8cea --- /dev/null +++ b/modules/labs-react/accessory/lib/AccessoryMedia.tsx @@ -0,0 +1,149 @@ +import React from 'react'; + +import {cornerShapeStencil, createComponent} from '@workday/canvas-kit-react/common'; +import {SystemIcon, SystemIconProps} from '@workday/canvas-kit-react/icon'; +import {createStencil, cssVar, handleCsProp} from '@workday/canvas-kit-styling'; +import {base, system} from '@workday/canvas-tokens-web'; + +import {Accessory, AccessoryProps, accessoryStencil} from './Accessory'; + +export interface AccessoryMediaProps extends AccessoryProps { + /** + * The URL of the image. + */ + src: string; + /** + * The alternative text for the image. Accessories are decorative, so the image is always hidden + * from assistive technology. Prefer an empty string when adjacent text already names the media. + */ + alt: string; + /** + * How the image is resized to fit the tile. + * @default 'cover' + */ + objectFit?: 'contain' | 'cover'; + /** + * The icon to display from `@workday/canvas-system-icons-web`, centered over the image. When + * set, a scrim is painted under the icon for contrast. Uses `color` from `Accessory` for the + * glyph (`base.legacy.neutral0` by default). + */ + icon?: SystemIconProps['icon']; +} + +/** + * Image treatment for `AccessoryMedia`. The image part stays hidden until `imageLoaded`. The scrim + * part sits under an optional icon. `background` overrides the tile fill. + */ +export const accessoryMediaStencil = createStencil({ + vars: { + background: '', + }, + parts: { + image: 'accessory-media-image', + scrim: 'accessory-media-scrim', + }, + base: ({background, imagePart, scrimPart}) => ({ + backgroundColor: cssVar(background, system.legacy.color.surface.alt.default), + [imagePart]: { + position: 'absolute', + inset: 0, + width: '100%', + height: '100%', + objectFit: 'cover', + overflow: 'hidden', + borderRadius: cssVar(cornerShapeStencil.vars.shape), + cornerShape: 'superellipse(1.1)', + }, + [scrimPart]: { + position: 'absolute', + inset: 0, + backgroundColor: system.legacy.color.surface.overlay.scrim, + borderRadius: cssVar(cornerShapeStencil.vars.shape), + cornerShape: 'superellipse(1.1)', + pointerEvents: 'none', + }, + }), + modifiers: { + imageLoaded: { + false: ({imagePart}) => ({ + [imagePart]: { + display: 'none', + }, + }), + true: {}, + }, + objectFit: { + cover: ({imagePart}) => ({ + [imagePart]: { + objectFit: 'cover', + }, + }), + contain: ({imagePart}) => ({ + [imagePart]: { + objectFit: 'contain', + }, + }), + }, + }, +}); + +/** + * `AccessoryMedia` fills an accessory tile with an image. Pass `icon` to center a decorative icon + * on a contrast scrim. The image stays hidden until it loads; a failed load keeps the tile + * background. Always decorative. + */ +export const AccessoryMedia = createComponent('span')({ + displayName: 'AccessoryMedia', + Component: ( + { + src, + alt, + size = 'extraLarge', + objectFit = 'cover', + icon, + color = base.legacy.neutral0, + background, + ...elemProps + }: AccessoryMediaProps, + ref, + Element + ) => { + // Track the loaded URL so a `src` change hides the image again without a mount effect that + // can race a synchronous `onLoad` (cached images and data URLs). + const [loadedSrc, setLoadedSrc] = React.useState(null); + const imageRef = React.useRef(null); + const imageLoaded = loadedSrc === src; + + React.useEffect(() => { + const image = imageRef.current; + if (image?.complete && image.naturalWidth > 0) { + setLoadedSrc(src); + } + }, [src]); + + return ( + + {alt} setLoadedSrc(src)} + src={src} + aria-hidden={true} + {...accessoryMediaStencil.parts.image} + /> + {icon && ( + <> + + + + )} + + ); + }, +}); diff --git a/modules/labs-react/accessory/spec/Accessory.spec.tsx b/modules/labs-react/accessory/spec/Accessory.spec.tsx new file mode 100644 index 0000000000..96189e984d --- /dev/null +++ b/modules/labs-react/accessory/spec/Accessory.spec.tsx @@ -0,0 +1,111 @@ +import {fireEvent, render, screen} from '@testing-library/react'; +import * as React from 'react'; + +import {checkIcon, playCircleIcon} from '@workday/canvas-system-icons-web'; + +import {Accessory} from '../lib/Accessory'; +import {AccessoryCalendar} from '../lib/AccessoryCalendar'; +import {AccessoryFavicon} from '../lib/AccessoryFavicon'; +import {AccessoryFile} from '../lib/AccessoryFile'; +import {AccessoryIcon} from '../lib/AccessoryIcon'; +import {AccessoryMedia} from '../lib/AccessoryMedia'; + +const imageSrc = + 'data:image/svg+xml,' + encodeURIComponent(''); + +describe('Accessory', () => { + verifyComponent(Accessory, {}); + verifyComponent(AccessoryIcon, {props: {icon: checkIcon}}); + verifyComponent(AccessoryMedia, {props: {src: imageSrc, alt: 'Preview', icon: checkIcon}}); + verifyComponent(AccessoryFile, {}); + verifyComponent(AccessoryCalendar, {props: {month: 'Apr', date: 30}}); + verifyComponent(AccessoryFavicon, {props: {url: 'gmail.com'}}); + + describe('when a calendar date is rendered', () => { + it('should show the month and day', () => { + const {container} = render(); + + expect(container).toHaveTextContent('Apr'); + expect(container).toHaveTextContent('30'); + expect(container.querySelector('[aria-hidden="true"]')).toBeInTheDocument(); + }); + }); + + describe('when an icon is rendered', () => { + it('should hide the accessory from assistive technology', () => { + const {container} = render(); + + expect(screen.queryByRole('img')).not.toBeInTheDocument(); + expect(container.querySelector('[aria-hidden="true"]')).toBeInTheDocument(); + expect(container.querySelector('svg')).toBeInTheDocument(); + }); + }); + + describe('when media has loaded', () => { + it('should keep the image decorative and show the photo', () => { + const {container} = render(); + const img = container.querySelector('img')!; + + fireEvent.load(img); + + expect(screen.queryByRole('img')).not.toBeInTheDocument(); + expect(img).toHaveAttribute('aria-hidden', 'true'); + }); + }); + + describe('when media has an icon', () => { + it('should keep the image and icon decorative', () => { + const {container} = render( + + ); + + fireEvent.load(container.querySelector('img')!); + + expect(screen.queryByRole('img')).not.toBeInTheDocument(); + expect(container.querySelector('svg')).toBeInTheDocument(); + }); + }); + + describe('when a favicon is rendered', () => { + it('should resolve the site hostname and stay decorative', () => { + const {container} = render(); + const img = container.querySelector('img')!; + + expect(img).toHaveAttribute( + 'src', + 'https://www.google.com/s2/favicons?domain=mail.google.com&sz=180' + ); + expect(img).toHaveAttribute('alt', ''); + expect(img).toHaveAttribute('referrerPolicy', 'no-referrer'); + expect(screen.queryByRole('img')).not.toBeInTheDocument(); + }); + + it('should render nothing when the site URL has no hostname', () => { + const {container} = render(); + + expect(container.querySelector('img')).not.toBeInTheDocument(); + }); + }); + + describe('when a file type is rendered', () => { + it('should hide the accessory from assistive technology', () => { + const {container} = render(); + + expect(screen.queryByRole('img')).not.toBeInTheDocument(); + expect(container.querySelector('svg')).toBeInTheDocument(); + }); + }); + + describe('when media has a play icon', () => { + it('should keep the preview and play icon decorative', () => { + const {container} = render( + + ); + + fireEvent.load(container.querySelector('img')!); + + expect(screen.queryByRole('img')).not.toBeInTheDocument(); + expect(container.querySelector('svg')).toBeInTheDocument(); + }); + }); +}); diff --git a/modules/labs-react/accessory/spec/SSR.spec.tsx b/modules/labs-react/accessory/spec/SSR.spec.tsx new file mode 100644 index 0000000000..7a82790fad --- /dev/null +++ b/modules/labs-react/accessory/spec/SSR.spec.tsx @@ -0,0 +1,32 @@ +/** + * @jest-environment node + */ +import {renderToString} from 'react-dom/server'; + +import {checkIcon} from '@workday/canvas-system-icons-web'; + +import {AccessoryCalendar} from '../lib/AccessoryCalendar'; +import {AccessoryFavicon} from '../lib/AccessoryFavicon'; +import {AccessoryFile} from '../lib/AccessoryFile'; +import {AccessoryIcon} from '../lib/AccessoryIcon'; +import {AccessoryMedia} from '../lib/AccessoryMedia'; + +const imageSrc = + 'data:image/svg+xml,' + encodeURIComponent(''); + +describe('Accessory', () => { + it('should render on a server without crashing', () => { + const ssrRender = () => + renderToString( + <> + + + + + + + ); + + expect(ssrRender).not.toThrow(); + }); +}); diff --git a/modules/labs-react/accessory/spec/tsconfig.json b/modules/labs-react/accessory/spec/tsconfig.json new file mode 100644 index 0000000000..d079d9f251 --- /dev/null +++ b/modules/labs-react/accessory/spec/tsconfig.json @@ -0,0 +1,4 @@ + +{ + "extends": "../../../../tsconfig.spec.json" +} diff --git a/modules/labs-react/accessory/stories/Accessory.mdx b/modules/labs-react/accessory/stories/Accessory.mdx new file mode 100644 index 0000000000..6be29caf41 --- /dev/null +++ b/modules/labs-react/accessory/stories/Accessory.mdx @@ -0,0 +1,120 @@ +import {Meta} from '@storybook/blocks'; + +import {ExampleCodeBlock, Specifications, SymbolDoc} from '@workday/canvas-kit-docs'; + +import AccessoryStoriesMeta from './Accessory.stories'; +import {Basic} from './examples/Basic'; +import {Calendar} from './examples/Calendar'; +import {Custom} from './examples/Custom'; +import {Favicon} from './examples/Favicon'; +import {File} from './examples/File'; +import {Icon} from './examples/Icon'; +import {Media} from './examples/Media'; +import {Sizes} from './examples/Sizes'; +import {Variants} from './examples/Variants'; + + + +# Canvas Kit Accessory + +`Accessory` is the small rounded visual that sits beside text, most often the leading element in a +list item or other row. It keeps every thumbnail in one consistent shape and size, so a list of +mixed content still feels uniform. + +It can show a system icon, a file type, an image, a site favicon, a calendar date, or fully custom +content — whichever suits the row. Prefer `AccessoryIcon`, `AccessoryFile`, `AccessoryMedia`, +`AccessoryFavicon`, or `AccessoryCalendar`, which each extend the shared `Accessory` props (`size`, +`color`, `background`) +and render that shell. Use `Accessory` itself for custom content, such as a gradient icon. +Accessories are decorative and always hidden from +assistive technology. They do not handle clicks or focus. + +## Installation + +```sh +yarn add @workday/canvas-kit-labs-react +``` + +## Usage + +### Basic Example + +`Accessory` is only the tile — size and corner radius. It does not render a visual by itself. Use a +targeted accessory instead: `AccessoryIcon` for a system icon, `AccessoryFile` for a file type, +`AccessoryMedia` for an image (optionally with an icon on a scrim), `AccessoryFavicon` for a site +favicon, or `AccessoryCalendar` for a month and day. Put custom content inside +`Accessory` when none of those fit the row. + + + +### Icon + +`AccessoryIcon` renders a system icon in the tile. `variant` sets the fill and icon color. + + + +### Media + +`AccessoryMedia` fills the tile with an image. The image stays hidden until it loads. Pass `icon` +to center a glyph on a contrast scrim. + + + +### Favicon + +`AccessoryFavicon` resolves a brand mark from a site URL or domain. The browser requests that mark +from Google's favicon service, which receives the hostname and the user's IP. The image uses +`referrerPolicy="no-referrer"`, so the app origin is not sent. At `large` and `extraLarge` the mark +sits inset in an outlined tile. At `medium` and smaller it fills the tile. + + + +### File + +`AccessoryFile` renders a file type through the shared icon graphic. `type` chooses the glyph and +is a stencil modifier for the fill and icon color. Colored types keep their accent fill at every +size. `file` and `txt` use `surface.alt` and a default border. + + + +### Calendar + +`AccessoryCalendar` stacks a month label over the day. Pass `month` and `date`. The month uses a +critical color. The day uses the default foreground color. + + + +### Custom + +Use `Accessory` when the row needs content that is not a system icon, file type, image, or favicon. +Set +`accessoryStencil.vars.iconColor` and `accessoryStencil.vars.tileBackground` to recolor the tile. +The icon `data-part` keeps the tile's corner radius. + + + +### Sizes + +`size` is a shared `Accessory` prop on each component. `extraLarge` (40px) is the default. + + + +### Variants + +`variant` is set on `AccessoryIcon`. It pairs an icon color with a tile fill. The fill is painted +at `medium`, `large`, and `extraLarge`. `outline` adds a default border at those larger sizes. + + + +### Accessibility + +Accessory components are presentational and always `aria-hidden`. Name the item in adjacent text +instead of on the accessory. They are not buttons and do not take click or keyboard handlers. + +## Component API + + + +## Specifications + + diff --git a/modules/labs-react/accessory/stories/Accessory.stories.ts b/modules/labs-react/accessory/stories/Accessory.stories.ts new file mode 100644 index 0000000000..30beaf42bf --- /dev/null +++ b/modules/labs-react/accessory/stories/Accessory.stories.ts @@ -0,0 +1,63 @@ +import {Meta, StoryObj} from '@storybook/react'; + +import {Accessory} from '@workday/canvas-kit-labs-react/accessory'; + +import mdxDoc from './Accessory.mdx'; +import {Basic as BasicExample} from './examples/Basic'; +import {Calendar as CalendarExample} from './examples/Calendar'; +import {Custom as CustomExample} from './examples/Custom'; +import {Favicon as FaviconExample} from './examples/Favicon'; +import {File as FileExample} from './examples/File'; +import {Icon as IconExample} from './examples/Icon'; +import {Media as MediaExample} from './examples/Media'; +import {Sizes as SizesExample} from './examples/Sizes'; +import {Variants as VariantsExample} from './examples/Variants'; + +export default { + title: 'Labs/Accessory', + component: Accessory, + tags: ['autodocs'], + parameters: { + docs: { + page: mdxDoc, + }, + }, +} as Meta; + +type Story = StoryObj; + +export const Basic: Story = { + render: BasicExample, +}; + +export const Icon: Story = { + render: IconExample, +}; + +export const Media: Story = { + render: MediaExample, +}; + +export const Favicon: Story = { + render: FaviconExample, +}; + +export const File: Story = { + render: FileExample, +}; + +export const Calendar: Story = { + render: CalendarExample, +}; + +export const Custom: Story = { + render: CustomExample, +}; + +export const Sizes: Story = { + render: SizesExample, +}; + +export const Variants: Story = { + render: VariantsExample, +}; diff --git a/modules/labs-react/accessory/stories/examples/Basic.tsx b/modules/labs-react/accessory/stories/examples/Basic.tsx new file mode 100644 index 0000000000..5a50a8ed1b --- /dev/null +++ b/modules/labs-react/accessory/stories/examples/Basic.tsx @@ -0,0 +1,27 @@ +import { + AccessoryFile, + AccessoryIcon, + AccessoryMedia, +} from '@workday/canvas-kit-labs-react/accessory'; +import {createStyles} from '@workday/canvas-kit-styling'; +import {checkIcon, playCircleIcon} from '@workday/canvas-system-icons-web'; +import {system} from '@workday/canvas-tokens-web'; + +const rowStyles = createStyles({ + display: 'flex', + alignItems: 'center', + gap: system.gap.sm, + flexWrap: 'wrap', +}); + +export const Basic = () => ( +
+ + + +
+); diff --git a/modules/labs-react/accessory/stories/examples/Calendar.tsx b/modules/labs-react/accessory/stories/examples/Calendar.tsx new file mode 100644 index 0000000000..3ef6881d96 --- /dev/null +++ b/modules/labs-react/accessory/stories/examples/Calendar.tsx @@ -0,0 +1,17 @@ +import {AccessoryCalendar} from '@workday/canvas-kit-labs-react/accessory'; +import {createStyles} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +const rowStyles = createStyles({ + display: 'flex', + alignItems: 'center', + gap: system.gap.sm, +}); + +export const Calendar = () => ( +
+ + + +
+); diff --git a/modules/labs-react/accessory/stories/examples/Custom.tsx b/modules/labs-react/accessory/stories/examples/Custom.tsx new file mode 100644 index 0000000000..854b23b828 --- /dev/null +++ b/modules/labs-react/accessory/stories/examples/Custom.tsx @@ -0,0 +1,74 @@ +import { + AccessoryFile, + AccessoryMedia, + accessoryStencil, +} from '@workday/canvas-kit-labs-react/accessory'; +import {createStencil, createStyles} from '@workday/canvas-kit-styling'; +import {checkIcon} from '@workday/canvas-system-icons-web'; +import {system} from '@workday/canvas-tokens-web'; + +const columnStyles = createStyles({ + display: 'flex', + flexDirection: 'column', + gap: system.gap.md, +}); + +const rowStyles = createStyles({ + display: 'flex', + alignItems: 'center', + gap: system.gap.sm, +}); + +const labelStyles = createStyles({ + display: 'flex', + flexDirection: 'column', + alignItems: 'center', + gap: system.gap.xs, +}); + +const customFileStencil = createStencil({ + base: { + [accessoryStencil.vars.iconColor]: system.color.fg.inverse, + [accessoryStencil.vars.tileBackground]: system.color.accent.info, + }, +}); + +const photo = + 'data:image/svg+xml,' + + encodeURIComponent( + ` + + + + + ` + ); + +export const Custom = () => ( +
+
+ + +
+
+
+ +
+
+ +
+
+ +
+
+
+); diff --git a/modules/labs-react/accessory/stories/examples/Favicon.tsx b/modules/labs-react/accessory/stories/examples/Favicon.tsx new file mode 100644 index 0000000000..cd380b0090 --- /dev/null +++ b/modules/labs-react/accessory/stories/examples/Favicon.tsx @@ -0,0 +1,16 @@ +import {AccessoryFavicon} from '@workday/canvas-kit-labs-react/accessory'; +import {createStyles} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +const rowStyles = createStyles({ + display: 'flex', + alignItems: 'center', + gap: system.gap.sm, +}); + +export const Favicon = () => ( +
+ + +
+); diff --git a/modules/labs-react/accessory/stories/examples/File.tsx b/modules/labs-react/accessory/stories/examples/File.tsx new file mode 100644 index 0000000000..e1cf5670e4 --- /dev/null +++ b/modules/labs-react/accessory/stories/examples/File.tsx @@ -0,0 +1,29 @@ +import {AccessoryFile, AccessoryFileType} from '@workday/canvas-kit-labs-react/accessory'; +import {createStyles} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +const rowStyles = createStyles({ + display: 'flex', + alignItems: 'center', + gap: system.gap.sm, + flexWrap: 'wrap', +}); + +const types: AccessoryFileType[] = [ + 'pdf', + 'spreadsheet', + 'document', + 'presentation', + 'video', + 'file', + 'txt', +]; + +export const File = () => ( +
+ {types.map(type => ( + + ))} + +
+); diff --git a/modules/labs-react/accessory/stories/examples/Icon.tsx b/modules/labs-react/accessory/stories/examples/Icon.tsx new file mode 100644 index 0000000000..d860c31d56 --- /dev/null +++ b/modules/labs-react/accessory/stories/examples/Icon.tsx @@ -0,0 +1,17 @@ +import {AccessoryIcon} from '@workday/canvas-kit-labs-react/accessory'; +import {createStyles} from '@workday/canvas-kit-styling'; +import {checkIcon} from '@workday/canvas-system-icons-web'; +import {system} from '@workday/canvas-tokens-web'; + +const rowStyles = createStyles({ + display: 'flex', + alignItems: 'center', + gap: system.gap.sm, +}); + +export const Icon = () => ( +
+ + +
+); diff --git a/modules/labs-react/accessory/stories/examples/Media.tsx b/modules/labs-react/accessory/stories/examples/Media.tsx new file mode 100644 index 0000000000..5a06b8e744 --- /dev/null +++ b/modules/labs-react/accessory/stories/examples/Media.tsx @@ -0,0 +1,5 @@ +import {AccessoryMedia} from '@workday/canvas-kit-labs-react/accessory'; + +export const Media = () => ( + +); diff --git a/modules/labs-react/accessory/stories/examples/Sizes.tsx b/modules/labs-react/accessory/stories/examples/Sizes.tsx new file mode 100644 index 0000000000..8e1ea0aff7 --- /dev/null +++ b/modules/labs-react/accessory/stories/examples/Sizes.tsx @@ -0,0 +1,34 @@ +import {AccessoryIcon} from '@workday/canvas-kit-labs-react/accessory'; +import {Subtext} from '@workday/canvas-kit-react/text'; +import {createStyles, px2rem} from '@workday/canvas-kit-styling'; +import {checkIcon} from '@workday/canvas-system-icons-web'; +import {system} from '@workday/canvas-tokens-web'; + +const containerStyles = createStyles({ + display: 'flex', + flexDirection: 'column', + gap: system.gap.md, +}); + +const rowStyles = createStyles({ + display: 'flex', + alignItems: 'center', + gap: system.gap.md, + p: { + minWidth: px2rem(104), + margin: 0, + }, +}); + +const sizes = ['extraSmall', 'small', 'medium', 'large', 'extraLarge'] as const; + +export const Sizes = () => ( +
+ {sizes.map(size => ( +
+ {size} + +
+ ))} +
+); diff --git a/modules/labs-react/accessory/stories/examples/Variants.tsx b/modules/labs-react/accessory/stories/examples/Variants.tsx new file mode 100644 index 0000000000..e284e7bae5 --- /dev/null +++ b/modules/labs-react/accessory/stories/examples/Variants.tsx @@ -0,0 +1,31 @@ +import {AccessoryIcon, AccessoryIconVariant} from '@workday/canvas-kit-labs-react/accessory'; +import {createStyles} from '@workday/canvas-kit-styling'; +import {checkIcon} from '@workday/canvas-system-icons-web'; +import {system} from '@workday/canvas-tokens-web'; + +const rowStyles = createStyles({ + display: 'flex', + alignItems: 'center', + gap: system.gap.sm, + flexWrap: 'wrap', +}); + +const variants: AccessoryIconVariant[] = [ + 'grey', + 'green', + 'blue', + 'purple', + 'amber', + 'magenta', + 'red', + 'orange', + 'outline', +]; + +export const Variants = () => ( +
+ {variants.map(variant => ( + + ))} +
+); diff --git a/modules/labs-react/accessory/stories/testing.stories.tsx b/modules/labs-react/accessory/stories/testing.stories.tsx new file mode 100644 index 0000000000..7d39d2fac7 --- /dev/null +++ b/modules/labs-react/accessory/stories/testing.stories.tsx @@ -0,0 +1,133 @@ +import { + AccessoryCalendar, + AccessoryFavicon, + AccessoryFile, + AccessoryFileType, + AccessoryIcon, + AccessoryIconVariant, + AccessoryMedia, + AccessorySize, +} from '@workday/canvas-kit-labs-react/accessory'; +import { + ComponentStatesTable, + StaticStates, + permutateProps, +} from '@workday/canvas-kit-react/testing'; +import {checkIcon} from '@workday/canvas-system-icons-web'; + +export default { + title: 'Testing/Labs/Accessory', + parameters: { + chromatic: { + disable: false, + }, + }, +}; + +const sizes: AccessorySize[] = ['extraSmall', 'small', 'medium', 'large', 'extraLarge']; +const variants: AccessoryIconVariant[] = [ + 'grey', + 'green', + 'blue', + 'purple', + 'amber', + 'magenta', + 'red', + 'orange', + 'outline', +]; +const fileTypes: AccessoryFileType[] = [ + 'pdf', + 'spreadsheet', + 'document', + 'presentation', + 'video', + 'file', + 'txt', +]; + +const photo = + 'data:image/svg+xml,' + + encodeURIComponent( + ` + + + + + ` + ); + +export const AccessoryIconStates = () => ( + + ({value: variant, label: variant})), + })} + columnProps={permutateProps({ + size: sizes.map(size => ({value: size, label: size})), + })} + > + {props => } + + +); + +export const AccessoryMediaStates = () => ( + + ({value: size, label: size})), + })} + columnProps={permutateProps({ + className: [{label: 'Default', value: ''}], + })} + > + {props => } + + +); + +export const AccessoryFaviconStates = () => ( + + ({value: size, label: size})), + })} + columnProps={permutateProps({ + className: [{label: 'Gmail', value: ''}], + })} + > + {props => } + + +); + +export const AccessoryFileStates = () => ( + + ({value: type, label: type})), + })} + columnProps={permutateProps({ + size: sizes.map(size => ({value: size, label: size})), + })} + > + {props => } + + +); + +export const AccessoryCalendarStates = () => ( + + ({value: size, label: size})), + })} + columnProps={permutateProps({ + className: [{label: 'Apr 30', value: ''}], + })} + > + {props => } + + +); diff --git a/modules/labs-react/accessory/stories/tsconfig.json b/modules/labs-react/accessory/stories/tsconfig.json new file mode 100644 index 0000000000..721d5175e2 --- /dev/null +++ b/modules/labs-react/accessory/stories/tsconfig.json @@ -0,0 +1,4 @@ + +{ + "extends": "../../../../tsconfig.stories.json" +} diff --git a/modules/labs-react/index.ts b/modules/labs-react/index.ts index 18053d3f72..fe0ddf94f1 100644 --- a/modules/labs-react/index.ts +++ b/modules/labs-react/index.ts @@ -1,3 +1,4 @@ +export * from './accessory'; export * from './ai-ingress-button'; export * from './kbd'; export * from './selection-group';