diff --git a/.yarn/cache/@lit-labs-ssr-dom-shim-npm-1.1.2-327f5934ca-a930f7de57.zip b/.yarn/cache/@lit-labs-ssr-dom-shim-npm-1.1.2-327f5934ca-a930f7de57.zip new file mode 100644 index 00000000000..156763e490f Binary files /dev/null and b/.yarn/cache/@lit-labs-ssr-dom-shim-npm-1.1.2-327f5934ca-a930f7de57.zip differ diff --git a/.yarn/cache/@lit-reactive-element-npm-2.0.2-2e22bbf731-2b74234f04.zip b/.yarn/cache/@lit-reactive-element-npm-2.0.2-2e22bbf731-2b74234f04.zip new file mode 100644 index 00000000000..cbc7cbc1b31 Binary files /dev/null and b/.yarn/cache/@lit-reactive-element-npm-2.0.2-2e22bbf731-2b74234f04.zip differ diff --git a/.yarn/cache/@rollup-plugin-alias-npm-5.1.0-5f8a6a898f-2749f9563d.zip b/.yarn/cache/@rollup-plugin-alias-npm-5.1.0-5f8a6a898f-2749f9563d.zip new file mode 100644 index 00000000000..127c1744bff Binary files /dev/null and b/.yarn/cache/@rollup-plugin-alias-npm-5.1.0-5f8a6a898f-2749f9563d.zip differ diff --git a/.yarn/cache/lit-element-npm-4.0.2-578d1f0327-185e8b9165.zip b/.yarn/cache/lit-element-npm-4.0.2-578d1f0327-185e8b9165.zip new file mode 100644 index 00000000000..741781fc24a Binary files /dev/null and b/.yarn/cache/lit-element-npm-4.0.2-578d1f0327-185e8b9165.zip differ diff --git a/.yarn/cache/lit-html-npm-3.1.0-a95b69193f-2831f48e82.zip b/.yarn/cache/lit-html-npm-3.1.0-a95b69193f-2831f48e82.zip new file mode 100644 index 00000000000..0db9e99d930 Binary files /dev/null and b/.yarn/cache/lit-html-npm-3.1.0-a95b69193f-2831f48e82.zip differ diff --git a/.yarn/cache/lit-npm-3.1.0-8c8011b724-cf46959d90.zip b/.yarn/cache/lit-npm-3.1.0-8c8011b724-cf46959d90.zip new file mode 100644 index 00000000000..779dc605f55 Binary files /dev/null and b/.yarn/cache/lit-npm-3.1.0-8c8011b724-cf46959d90.zip differ diff --git a/.yarn/cache/slash-npm-4.0.0-ce4bbc4a80-da8e4af737.zip b/.yarn/cache/slash-npm-4.0.0-ce4bbc4a80-da8e4af737.zip new file mode 100644 index 00000000000..1382ade5d5b Binary files /dev/null and b/.yarn/cache/slash-npm-4.0.0-ce4bbc4a80-da8e4af737.zip differ diff --git a/packages/carbon-web-components/.storybook/main.ts b/packages/carbon-web-components/.storybook/main.ts index 85e5a057c20..cff22ff9906 100644 --- a/packages/carbon-web-components/.storybook/main.ts +++ b/packages/carbon-web-components/.storybook/main.ts @@ -1,3 +1,12 @@ +/** + * @license + * + * Copyright IBM Corp. 2023, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + import type { StorybookConfig } from '@storybook/web-components-vite'; import { mergeConfig } from 'vite'; import { litStyleLoader, litTemplateLoader } from '@mordech/vite-lit-loader'; @@ -11,12 +20,78 @@ const stories = glob.sync( // '../src/**/*.mdx', // '../src/**/*.stories.@(js|jsx|ts|tsx)', // add mdx/story files as they are being worked on + '../src/**/checkbox.stories.ts', + '../src/**/checkbox.mdx', + '../src/**/accordion.mdx', + '../src/**/accordion.stories.ts', + '../src/**/breadcrumb.mdx', + '../src/**/breadcrumb.stories.ts', + '../src/**/code-snippet.mdx', + '../src/**/code-snippet.stories.ts', + '../src/**/combo-box.stories.ts', + '../src/**/combo-box.mdx', + '../src/**/date-picker.mdx', + '../src/**/date-picker.stories.ts', + '../src/**/content-switcher.mdx', + '../src/**/content-switcher.stories.ts', + '../src/**/dropdown.stories.ts', + '../src/**/dropdown.mdx', + '../src/**/data-table-*.stories.ts', + '../src/**/data-table.mdx', + '../src/**/ordered-list.stories.ts', + '../src/**/unordered-list.stories.ts', + '../src/**/list.mdx', + '../src/**/icon-button.mdx', + '../src/**/icon-button.stories.ts', + '../src/**/inline-loading.mdx', + '../src/**/inline-loading.stories.ts', + '../src/**/loading.stories.ts', + '../src/**/loading.mdx', + '../src/**/button.mdx', + '../src/**/button.stories.ts', '../src/**/link.mdx', '../src/**/link.stories.ts', + '../src/**/layer.stories.ts', + '../src/**/layer.mdx', '../src/**/file-uploader.mdx', '../src/**/file-uploader.stories.ts', '../src/**/popover.mdx', '../src/**/popover.stories.ts', + '../src/**/form-group.mdx', + '../src/**/form-group.stories.ts', + '../src/**/modal.stories.ts', + '../src/**/modal.mdx', + '../src/**/file-uploader.stories.ts', + '../src/**/number-input.mdx', + '../src/**/number-input.stories.ts', + '../src/**/multi-select.mdx', + '../src/**/multi-select.stories.ts', + '../src/**/notification.mdx', + '../src/**/actionable-notification.stories.ts', + '../src/**/inline-notification.stories.ts', + '../src/**/toast-notification.stories.ts', + '../src/**/overflow-menu.mdx', + '../src/**/overflow-menu.stories.ts', + '../src/**/progress-bar.mdx', + '../src/**/progress-bar.stories.ts', + '../src/**/progress-indicator.mdx', + '../src/**/progress-indicator.stories.ts', + '../src/**/search.mdx', + '../src/**/search.stories.ts', + '../src/**/select.mdx', + '../src/**/select.stories.ts', + '../src/**/skeleton-placeholder.mdx', + '../src/**/skeleton-placeholder.stories.ts', + '../src/**/skeleton-text.mdx', + '../src/**/skeleton-text.stories.ts', + '../src/**/skip-to-content.mdx', + '../src/**/skip-to-content.stories.ts', + '../src/**/slider.mdx', + '../src/**/slider.stories.ts', + '../src/**/tag.mdx', + '../src/**/tag.stories.ts', + '../src/**/tooltip.mdx', + '../src/**/tooltip.stories.ts', ], { ignore: ['../src/**/docs/*.mdx'], diff --git a/packages/carbon-web-components/.storybook/preview.js b/packages/carbon-web-components/.storybook/preview.js index f2bca308240..71896f81aa2 100644 --- a/packages/carbon-web-components/.storybook/preview.js +++ b/packages/carbon-web-components/.storybook/preview.js @@ -4,6 +4,7 @@ import container from './container'; import { white, g10, g90, g100 } from '@carbon/themes'; import { breakpoints } from '@carbon/layout'; import theme from './theme'; +import './templates/with-layer'; setCustomElementsManifest(customElements); diff --git a/packages/carbon-web-components/package.json b/packages/carbon-web-components/package.json index a850784dd12..122a32f5515 100644 --- a/packages/carbon-web-components/package.json +++ b/packages/carbon-web-components/package.json @@ -74,7 +74,7 @@ "@babel/runtime": "^7.16.3", "@carbon/styles": "^1.45.0", "flatpickr": "4.6.1", - "lit": "^2.7.6", + "lit": "^3.1.0", "lodash-es": "^4.17.21" }, "devDependencies": { @@ -100,6 +100,7 @@ "@percy/cli": "^1.27.4", "@percy/cypress": "^3.1.2", "@percy/dom": "^1.27.5", + "@rollup/plugin-alias": "^5.1.0", "@rollup/plugin-babel": "^5.3.1", "@rollup/plugin-commonjs": "^21.0.3", "@rollup/plugin-node-resolve": "^8.4.0", diff --git a/packages/carbon-web-components/src/components/accordion/accordion-story.ts b/packages/carbon-web-components/src/components/accordion/accordion-story.ts deleted file mode 100644 index 285541bf1c2..00000000000 --- a/packages/carbon-web-components/src/components/accordion/accordion-story.ts +++ /dev/null @@ -1,196 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { action } from '@storybook/addon-actions'; -import { boolean, select } from '@storybook/addon-knobs'; -import { prefix } from '../../globals/settings'; -import { ACCORDION_SIZE } from './accordion'; -import './index'; -import './accordion-skeleton'; -import '../button/index'; -import storyDocs from './accordion-story.mdx'; - -const sizes = { - [`Small size (${ACCORDION_SIZE.SMALL})`]: ACCORDION_SIZE.SMALL, - [`Medium size (${ACCORDION_SIZE.MEDIUM})`]: ACCORDION_SIZE.MEDIUM, - [`Large size (${ACCORDION_SIZE.LARGE})`]: ACCORDION_SIZE.LARGE, -}; - -export const Default = () => { - return html` - - -

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do - eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad - minim veniam, quis nostrud exercitation ullamco laboris nisi ut - aliquip ex ea commodo consequat. -

-
- -

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do - eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad - minim veniam, quis nostrud exercitation ullamco laboris nisi ut - aliquip ex ea commodo consequat. -

-
- -

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do - eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad - minim veniam, quis nostrud exercitation ullamco laboris nisi ut - aliquip ex ea commodo consequat. -

-
- -

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do - eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad - minim veniam, quis nostrud exercitation ullamco laboris nisi ut - aliquip ex ea commodo consequat. -

-
-
- `; -}; - -Default.storyName = 'Default'; - -export const Skeleton = (args) => { - const { alignment, isFlush } = args?.[`${prefix}-accordion-skeleton`] ?? {}; - return html` - - - `; -}; - -Skeleton.decorators = [ - (story) => { - return html`
${story()}
`; - }, -]; - -Skeleton.parameters = { - percy: { - skip: true, - }, - knobs: { - [`${prefix}-accordion-skeleton`]: () => ({ - alignment: select( - 'Accordion alignment (alignment)', - ['start', 'end'], - 'end' - ), - isFlush: boolean('isFlush', false), - }), - }, -}; - -const noop = () => {}; - -export const Playground = (args) => { - const { - disabled, - disableToggle, - onBeforeToggle = noop, - onToggle = noop, - size, - alignment, - isFlush, - } = args?.[`${prefix}-accordion-playground`] ?? {}; - const handleBeforeToggle = (event: CustomEvent) => { - onBeforeToggle(event); - if (disableToggle) { - event.preventDefault(); - } - }; - - return html` - - -

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do - eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad - minim veniam, quis nostrud exercitation ullamco laboris nisi ut - aliquip ex ea commodo consequat. -

-
- -

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do - eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad - minim veniam, quis nostrud exercitation ullamco laboris nisi ut - aliquip ex ea commodo consequat. -

-
- - This is a button. - - - - Section 4 title (the title can be a node) - -

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do - eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad - minim veniam, quis nostrud exercitation ullamco laboris nisi ut - aliquip ex ea commodo consequat. -

-
-
- `; -}; - -Playground.parameters = { - percy: { - skip: true, - }, - knobs: { - [`${prefix}-accordion-playground`]: () => ({ - alignment: select( - 'Specify the alignment of the accordion heading title and chevron (alignment)', - ['start', 'end'], - 'end' - ), - disabled: boolean( - 'Specify whether an individual AccordionItem should be disabled (disabled)', - false - ), - isFlush: boolean( - 'Specify whether Accordion text should be flush, default is false, does not work with align="start" (isFlush)', - false - ), - size: select( - 'Specify the size of the Accordion (size)', - sizes, - ACCORDION_SIZE.MEDIUM - ), - disableToggle: boolean( - `Disable user-initiated toggle action (Call event.preventDefault() in ${prefix}-accordion-beingtoggled event)`, - false - ), - onBeforeToggle: action(`${prefix}-accordion-item-beingtoggled`), - onToggle: action(`${prefix}-accordion-item-toggled`), - }), - }, -}; - -export default { - title: 'Components/Accordion', - parameters: { - ...storyDocs.parameters, - }, -}; diff --git a/packages/carbon-web-components/src/components/accordion/accordion-story.mdx b/packages/carbon-web-components/src/components/accordion/accordion.mdx similarity index 94% rename from packages/carbon-web-components/src/components/accordion/accordion-story.mdx rename to packages/carbon-web-components/src/components/accordion/accordion.mdx index d1a50deca36..c9b03f60048 100644 --- a/packages/carbon-web-components/src/components/accordion/accordion-story.mdx +++ b/packages/carbon-web-components/src/components/accordion/accordion.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Description } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as AccordionStories from './accordion.stories'; + + # Accordion @@ -87,4 +90,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `open` attribute). - + diff --git a/packages/carbon-web-components/src/components/accordion/accordion.stories.ts b/packages/carbon-web-components/src/components/accordion/accordion.stories.ts new file mode 100644 index 00000000000..d879af15836 --- /dev/null +++ b/packages/carbon-web-components/src/components/accordion/accordion.stories.ts @@ -0,0 +1,209 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { prefix } from '../../globals/settings'; +import { ACCORDION_SIZE } from './accordion'; +import './index'; +import '../button/index'; + +const sizes = { + [`Small size (${ACCORDION_SIZE.SMALL})`]: ACCORDION_SIZE.SMALL, + [`Medium size (${ACCORDION_SIZE.MEDIUM})`]: ACCORDION_SIZE.MEDIUM, + [`Large size (${ACCORDION_SIZE.LARGE})`]: ACCORDION_SIZE.LARGE, +}; + +const args = { + alignment: 'end', + disabled: false, + isFlush: false, + size: ACCORDION_SIZE.MEDIUM, + disableToggle: false, +}; + +const argTypes = { + alignment: { + control: 'select', + description: + 'Specify the alignment of the accordion heading title and chevron.', + options: ['start', 'end'], + }, + disabled: { + control: 'boolean', + description: + 'Specify whether an individual AccordionItem should be disabled.', + }, + isFlush: { + control: 'boolean', + description: + 'Specify whether Accordion text should be flush, default is false, does not work with align="start".', + }, + size: { + control: 'select', + description: 'Specify the size of the Accordion.', + options: sizes, + }, + disableToggle: { + control: 'boolean', + description: `Disable user-initiated toggle action (Call event.preventDefault() in ${prefix}-accordion-beingtoggled event).`, + }, + onBeforeToggle: { + action: `${prefix}-accordion-item-beingtoggled`, + }, + onToggle: { + action: `${prefix}-accordion-item-toggled`, + }, +}; + +export const Default = { + // This story doesn't accept any args. + args: {}, + argTypes: {}, + render: () => { + return html` + + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do + eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim + ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut + aliquip ex ea commodo consequat. +

+
+ +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do + eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim + ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut + aliquip ex ea commodo consequat. +

+
+ +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do + eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim + ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut + aliquip ex ea commodo consequat. +

+
+ +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do + eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim + ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut + aliquip ex ea commodo consequat. +

+
+
+ `; + }, +}; + +export const Skeleton = { + args: { + alignment: args['alignment'], + isFlush: args['isFlush'], + }, + argTypes: { + alignment: argTypes['alignment'], + isFlush: argTypes['isFlush'], + }, + decorators: [ + (story) => { + return html`
${story()}
`; + }, + ], + parameters: { + percy: { + skip: true, + }, + }, + render: (args) => { + const { alignment, isFlush } = args ?? {}; + return html` + + + `; + }, +}; + +const noop = () => {}; + +export const Playground = { + args, + argTypes, + parameters: { + percy: { + skip: true, + }, + }, + render: (args) => { + const { + disabled, + disableToggle, + onBeforeToggle = noop, + onToggle = noop, + size, + alignment, + isFlush, + } = args ?? {}; + const handleBeforeToggle = (event: CustomEvent) => { + onBeforeToggle(event); + if (disableToggle) { + event.preventDefault(); + } + }; + + return html` + + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do + eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim + ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut + aliquip ex ea commodo consequat. +

+
+ +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do + eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim + ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut + aliquip ex ea commodo consequat. +

+
+ + This is a button. + + + + Section 4 title (the title can be a node) + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do + eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim + ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut + aliquip ex ea commodo consequat. +

+
+
+ `; + }, +}; + +const meta = { + title: 'Components/Accordion', +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/breadcrumb/breadcrumb-story.ts b/packages/carbon-web-components/src/components/breadcrumb/breadcrumb-story.ts deleted file mode 100644 index 7e80f515505..00000000000 --- a/packages/carbon-web-components/src/components/breadcrumb/breadcrumb-story.ts +++ /dev/null @@ -1,116 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import './breadcrumb'; -import './breadcrumb-item'; -import './breadcrumb-link'; -import './breadcrumb-overflow-menu'; -import '../overflow-menu/overflow-menu-body'; -import './breadcrumb-skeleton'; -import { prefix } from '../../globals/settings'; -import { boolean, text } from '@storybook/addon-knobs'; -import storyDocs from './breadcrumb-story.mdx'; - -export const Default = () => { - return html` - - - Breadcrumb 1 - - - Breadcrumb 2 - - - Breadcrumb 3 - - - Breadcrumb 4 - - - `; -}; - -Default.storyName = 'Default'; - -export default { - title: 'Components/Breadcrumb', - parameters: { - ...storyDocs.parameters, - }, -}; - -export const BreadcrumbWithOverflowMenu = () => html` - - - Breadcrumb 1 - - - Breadcrumb 2 - - - - - Breadcrumb 3 - Breadcrumb 4 - - - - - Breadcrumb 5 - - - Breadcrumb 6 - - -`; - -BreadcrumbWithOverflowMenu.storyName = 'Breadcrumb With Overflow Menu'; - -export const skeleton = () => { - return html` `; -}; - -export const Playground = (args) => { - const { ariaLabel, classes, noTrailingSlash } = - args?.[`${prefix}-breadcrumb-playground`] ?? {}; - return html` - - - Breadcrumb 1 - - - Breadcrumb 2 - - - Breadcrumb 3 - - - Breadcrumb 4 - - - `; -}; - -Playground.parameters = { - ...storyDocs.parameters, - knobs: { - [`${prefix}-breadcrumb-playground`]: () => ({ - ariaLabel: text('aria-label (aria-label)', ''), - classes: text('class (class)', ''), - noTrailingSlash: boolean( - 'Optional prop to omit the trailing slash for the breadcrumbs (noTrailingSlash)', - false - ), - }), - }, -}; diff --git a/packages/carbon-web-components/src/components/breadcrumb/breadcrumb-story.mdx b/packages/carbon-web-components/src/components/breadcrumb/breadcrumb.mdx similarity index 93% rename from packages/carbon-web-components/src/components/breadcrumb/breadcrumb-story.mdx rename to packages/carbon-web-components/src/components/breadcrumb/breadcrumb.mdx index e5eddd72750..c0e1b92fc89 100644 --- a/packages/carbon-web-components/src/components/breadcrumb/breadcrumb-story.mdx +++ b/packages/carbon-web-components/src/components/breadcrumb/breadcrumb.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Description } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as BreadcrumbStories from './breadcrumb.stories'; + + # Breadcrumb @@ -116,8 +119,8 @@ import '@carbon/web-components/es/components/breadcrumb/index.js'; ## `` attributes, properties and events - + ## `` attributes, properties and events - + diff --git a/packages/carbon-web-components/src/components/breadcrumb/breadcrumb.stories.ts b/packages/carbon-web-components/src/components/breadcrumb/breadcrumb.stories.ts new file mode 100644 index 00000000000..1d0453947ff --- /dev/null +++ b/packages/carbon-web-components/src/components/breadcrumb/breadcrumb.stories.ts @@ -0,0 +1,133 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import './breadcrumb'; +import './breadcrumb-item'; +import './breadcrumb-link'; +import './breadcrumb-overflow-menu'; +import '../overflow-menu/overflow-menu-body'; +import './breadcrumb-skeleton'; +import storyDocs from './breadcrumb.mdx'; + +const args = { + ariaLabel: '', + classes: '', + noTrailingSlash: false, +}; + +const argTypes = { + ariaLabel: { + control: 'text', + description: 'Specify the label for the breadcrumb container.', + name: 'aria-label', + }, + classes: { + control: 'text', + description: + 'Specify an optional className to be applied to the container node.', + }, + noTrailingSlash: { + control: 'boolean', + description: + 'Optional prop to omit the trailing slash for the breadcrumbs.', + }, +}; + +export const Default = { + render: () => { + return html` + + + Breadcrumb 1 + + + Breadcrumb 2 + + + Breadcrumb 3 + + + Breadcrumb 4 + + + `; + }, +}; + +export const BreadcrumbWithOverflowMenu = { + render: () => html` + + + Breadcrumb 1 + + + Breadcrumb 2 + + + + + Breadcrumb 3 + Breadcrumb 4 + + + + + Breadcrumb 5 + + + Breadcrumb 6 + + + `, +}; + +export const Skeleton = { + render: () => { + return html` `; + }, +}; + +export const Playground = { + args, + argTypes, + render: (args) => { + const { ariaLabel, classes, noTrailingSlash } = args ?? {}; + return html` + + + Breadcrumb 1 + + + Breadcrumb 2 + + + Breadcrumb 3 + + + Breadcrumb 4 + + + `; + }, +}; + +const meta = { + title: 'Components/Breadcrumb', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/button/button-story.ts b/packages/carbon-web-components/src/components/button/button-story.ts deleted file mode 100644 index 5d7e8657a68..00000000000 --- a/packages/carbon-web-components/src/components/button/button-story.ts +++ /dev/null @@ -1,403 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { action } from '@storybook/addon-actions'; -import { boolean, select, text } from '@storybook/addon-knobs'; -// Below path will be there when an application installs `carbon-web-components` package. -// In our dev env, we auto-generate the file and re-map below path to to point to the generated file. -// @ts-ignore -import Add16 from '@carbon/web-components/es/icons/add/16'; -import { prefix } from '../../globals/settings'; -import { - BUTTON_KIND, - BUTTON_TYPE, - BUTTON_SIZE, - BUTTON_TOOLTIP_ALIGNMENT, - BUTTON_TOOLTIP_POSITION, -} from './button'; -import './button-skeleton'; -import textNullable from '../../../.storybook/knob-text-nullable'; -import storyDocs from './button-story.mdx'; -import { ifDefined } from 'lit/directives/if-defined.js'; - -const kind = { - [`Primary button (${BUTTON_KIND.PRIMARY})`]: BUTTON_KIND.PRIMARY, - [`Secondary button (${BUTTON_KIND.SECONDARY})`]: BUTTON_KIND.SECONDARY, - [`Tertiary button (${BUTTON_KIND.TERTIARY})`]: BUTTON_KIND.TERTIARY, - [`Danger button (${BUTTON_KIND.DANGER})`]: BUTTON_KIND.DANGER, - [`Danger tertiary button (${BUTTON_KIND.DANGER_TERTIARY})`]: - BUTTON_KIND.DANGER_TERTIARY, - [`Danger ghost button (${BUTTON_KIND.DANGER_GHOST})`]: - BUTTON_KIND.DANGER_GHOST, - [`Ghost button (${BUTTON_KIND.GHOST})`]: BUTTON_KIND.GHOST, -}; - -const types = { - [`Button`]: BUTTON_TYPE.BUTTON, - [`Reset`]: BUTTON_TYPE.RESET, - [`Submit`]: BUTTON_TYPE.SUBMIT, -}; - -const alignmentOptions = { - ['Start']: BUTTON_TOOLTIP_ALIGNMENT.START, - ['Center']: BUTTON_TOOLTIP_ALIGNMENT.CENTER, - ['End']: BUTTON_TOOLTIP_ALIGNMENT.END, -}; - -const positionOptions = { - ['Top']: BUTTON_TOOLTIP_POSITION.TOP, - ['Right']: BUTTON_TOOLTIP_POSITION.RIGHT, - ['Bottom']: BUTTON_TOOLTIP_POSITION.BOTTOM, - ['Left']: BUTTON_TOOLTIP_POSITION.LEFT, -}; - -const sizes = { - [`Small size (${BUTTON_SIZE.SMALL})`]: BUTTON_SIZE.SMALL, - [`Medium size (${BUTTON_SIZE.MEDIUM})`]: BUTTON_SIZE.MEDIUM, - [`Large size (${BUTTON_SIZE.LARGE})`]: BUTTON_SIZE.LARGE, - [`XL size (${BUTTON_SIZE.EXTRA_LARGE})`]: BUTTON_SIZE.EXTRA_LARGE, - [`2XL size (${BUTTON_SIZE.EXTRA_EXTRA_LARGE})`]: - BUTTON_SIZE.EXTRA_EXTRA_LARGE, -}; - -export const Default = (args) => { - const { - disabled, - href, - size, - kind, - isExpressive, - tooltipAlignment, - tooltipPosition, - tooltipText, - type, - onClick, - } = args?.[`${prefix}-btn`] ?? {}; - - return html` - - Button - - `; -}; - -export const Danger = (args) => { - const { - disabled, - href, - size, - tooltipAlignment, - isExpressive, - tooltipPosition, - tooltipText, - type, - onClick, - } = args?.[`${prefix}-btn`] ?? {}; - return html` - - Button - - - Tertiary Danger Button - - - Ghost Danger Button - - `; -}; - -export const Ghost = (args) => { - const { - disabled, - href, - size, - isExpressive, - isSelected, - tooltipAlignment, - tooltipPosition, - tooltipText, - type, - onClick, - } = args?.[`${prefix}-btn`] ?? {}; - return html` - - Ghost - - `; -}; - -Ghost.parameters = { - ...storyDocs.parameters, - knobs: { - [`${prefix}-btn`]: () => ({ - kind: select('Button kind (kind)', kind, BUTTON_KIND.PRIMARY), - types: select('Button type (type)', types, BUTTON_TYPE.BUTTON), - tooltipAlignment: select( - 'Tooltip alignment', - alignmentOptions, - BUTTON_TOOLTIP_ALIGNMENT.CENTER - ), - tooltipPosition: select( - 'Tooltip position', - positionOptions, - BUTTON_TOOLTIP_POSITION.TOP - ), - tooltipText: text('Tooltip text', ''), - disabled: boolean('Disabled (disabled)', false), - isExpressive: boolean('Expressive (is-expressive)', false), - isSelected: boolean('Selected (is-selected)', false), - size: select('Button size (size)', sizes, null), - href: textNullable('Link href (href)', ''), - onClick: action('click'), - }), - }, -}; - -export const IconButton = (args) => { - const { - disabled, - href, - size, - kind, - isExpressive, - tooltipAlignment, - tooltipPosition, - tooltipText, - type, - onClick, - } = args?.[`${prefix}-btn`] ?? {}; - return html` - - ${Add16({ slot: 'icon' })} - - `; -}; - -IconButton.parameters = { - knobs: { - [`${prefix}-btn`]: () => ({ - kind: select('Button kind (kind)', kind, BUTTON_KIND.PRIMARY), - types: select('Button type (type)', types, BUTTON_TYPE.BUTTON), - isExpressive: boolean('Expressive (is-expressive)', false), - tooltipAlignment: select( - 'Tooltip alignment', - alignmentOptions, - BUTTON_TOOLTIP_ALIGNMENT.CENTER - ), - tooltipPosition: select( - 'Tooltip position', - positionOptions, - BUTTON_TOOLTIP_POSITION.TOP - ), - tooltipText: text('Tooltip text', 'Icon description'), - disabled: boolean('Disabled (disabled)', false), - size: select('Button size (size)', sizes, null), - href: textNullable('Link href (href)', ''), - onClick: action('click'), - }), - }, -}; - -export const Secondary = (args) => { - const { - disabled, - href, - size, - isExpressive, - tooltipAlignment, - tooltipPosition, - tooltipText, - type, - onClick, - } = args?.[`${prefix}-btn`] ?? {}; - return html` - - Button - - `; -}; - -export const SetOfButtons = (args) => { - const { - disabled, - href, - size, - isExpressive, - tooltipAlignment, - tooltipPosition, - tooltipText, - type, - onClick, - } = args?.[`${prefix}-btn`] ?? {}; - return html` - - - Secondary button - - - Primary button - - - `; -}; - -export const skeleton = () => { - return html` - - - `; -}; - -export const Tertiary = (args) => { - const { - disabled, - href, - size, - tooltipAlignment, - isExpressive, - tooltipPosition, - tooltipText, - type, - onClick, - } = args?.[`${prefix}-btn`] ?? {}; - return html` - - Button - - `; -}; - -export default { - title: 'Components/Button', - parameters: { - ...storyDocs.parameters, - knobs: { - [`${prefix}-btn`]: () => ({ - kind: select('Button kind (kind)', kind, BUTTON_KIND.PRIMARY), - types: select('Button type (type)', types, BUTTON_TYPE.BUTTON), - tooltipAlignment: select( - 'Tooltip alignment', - alignmentOptions, - BUTTON_TOOLTIP_ALIGNMENT.CENTER - ), - tooltipPosition: select( - 'Tooltip position', - positionOptions, - BUTTON_TOOLTIP_POSITION.TOP - ), - tooltipText: text('Tooltip text', ''), - disabled: boolean('Disabled (disabled)', false), - isExpressive: boolean('Expressive (is-expressive)', false), - size: select('Button size (size)', sizes, null), - href: textNullable('Link href (href)', ''), - onClick: action('click'), - }), - }, - }, -}; diff --git a/packages/carbon-web-components/src/components/button/button-story.mdx b/packages/carbon-web-components/src/components/button/button.mdx similarity index 100% rename from packages/carbon-web-components/src/components/button/button-story.mdx rename to packages/carbon-web-components/src/components/button/button.mdx diff --git a/packages/carbon-web-components/src/components/button/button.stories.ts b/packages/carbon-web-components/src/components/button/button.stories.ts new file mode 100644 index 00000000000..e8bfd58046f --- /dev/null +++ b/packages/carbon-web-components/src/components/button/button.stories.ts @@ -0,0 +1,429 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2023 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +// Below path will be there when an application installs `carbon-web-components` package. +// In our dev env, we auto-generate the file and re-map below path to to point to the generated file. +// @ts-ignore +import Add16 from '@carbon/web-components/es/icons/add/16'; +import { + BUTTON_KIND, + BUTTON_TYPE, + BUTTON_SIZE, + BUTTON_TOOLTIP_ALIGNMENT, + BUTTON_TOOLTIP_POSITION, +} from './button'; +import './index'; +import storyDocs from './button.mdx'; + +const kind = { + [`Primary button (${BUTTON_KIND.PRIMARY})`]: BUTTON_KIND.PRIMARY, + [`Secondary button (${BUTTON_KIND.SECONDARY})`]: BUTTON_KIND.SECONDARY, + [`Tertiary button (${BUTTON_KIND.TERTIARY})`]: BUTTON_KIND.TERTIARY, + [`Danger button (${BUTTON_KIND.DANGER})`]: BUTTON_KIND.DANGER, + [`Danger tertiary button (${BUTTON_KIND.DANGER_TERTIARY})`]: + BUTTON_KIND.DANGER_TERTIARY, + [`Danger ghost button (${BUTTON_KIND.DANGER_GHOST})`]: + BUTTON_KIND.DANGER_GHOST, + [`Ghost button (${BUTTON_KIND.GHOST})`]: BUTTON_KIND.GHOST, +}; + +const types = { + [`Button`]: BUTTON_TYPE.BUTTON, + [`Reset`]: BUTTON_TYPE.RESET, + [`Submit`]: BUTTON_TYPE.SUBMIT, +}; + +const alignmentOptions = { + ['Start']: BUTTON_TOOLTIP_ALIGNMENT.START, + ['Center']: BUTTON_TOOLTIP_ALIGNMENT.CENTER, + ['End']: BUTTON_TOOLTIP_ALIGNMENT.END, +}; + +const positionOptions = { + ['Top']: BUTTON_TOOLTIP_POSITION.TOP, + ['Right']: BUTTON_TOOLTIP_POSITION.RIGHT, + ['Bottom']: BUTTON_TOOLTIP_POSITION.BOTTOM, + ['Left']: BUTTON_TOOLTIP_POSITION.LEFT, +}; + +const sizes = { + [`Small size (${BUTTON_SIZE.SMALL})`]: BUTTON_SIZE.SMALL, + [`Medium size (${BUTTON_SIZE.MEDIUM})`]: BUTTON_SIZE.MEDIUM, + [`Large size (${BUTTON_SIZE.LARGE})`]: BUTTON_SIZE.LARGE, + [`XL size (${BUTTON_SIZE.EXTRA_LARGE})`]: BUTTON_SIZE.EXTRA_LARGE, + [`2XL size (${BUTTON_SIZE.EXTRA_EXTRA_LARGE})`]: + BUTTON_SIZE.EXTRA_EXTRA_LARGE, +}; + +const defaultArgs = { + kind: BUTTON_KIND.PRIMARY, + tooltipAlignment: BUTTON_TOOLTIP_ALIGNMENT.CENTER, + tooltipPosition: BUTTON_TOOLTIP_POSITION.TOP, +}; + +const controls = { + buttonClassName: { + control: 'text', + description: 'Specify an optional className to be added to your Button', + }, + dangerDescription: { + control: 'text', + description: + 'Specify the message read by screen readers for the danger button variant', + }, + disabled: { + control: 'boolean', + description: 'Specify whether the Button should be disabled, or not', + }, + href: { + control: 'string', + description: + 'Optionally specify an href for your Button to become an element', + }, + isExpressive: { + control: 'boolean', + description: 'Specify whether the Button is expressive, or not', + }, + isSelected: { + control: 'boolean', + description: + 'Specify whether the Button is currently selected. Only applies to the Ghost variant.', + }, + kind: { + control: 'select', + description: 'Specifiy the kind of Button you want to create', + options: kind, + }, + linkRole: { + control: 'text', + description: 'Optional prop to specify the role of the Button', + }, + size: { + control: 'select', + description: + 'Specify the size of the button, from the following list of sizes:', + options: sizes, + }, + tooltipAlignment: { + control: 'radio', + description: + 'Specify the alignment of the tooltip to the icon-only button. Can be one of: start, center, or end.', + options: alignmentOptions, + }, + tooltipPosition: { + control: 'radio', + description: + 'Specify the direction of the tooltip for icon-only buttons. Can be either top, right, bottom, or left.', + options: positionOptions, + }, + type: { + control: 'radio', + description: 'Optional prop to specify the type of the Button', + options: types, + }, + onClick: { + table: { + disable: true, + }, + }, +}; + +export const Default = { + argTypes: controls, + args: defaultArgs, + render: ({ + buttonClassName, + dangerDescription, + disabled, + href, + isExpressive, + isSelected, + kind, + linkRole, + size, + tooltipAlignment, + tooltipPosition, + type, + }) => html` + Button + `, +}; + +export const Danger = { + argTypes: controls, + args: defaultArgs, + render: ({ + buttonClassName, + dangerDescription, + disabled, + href, + isExpressive, + isSelected, + linkRole, + size, + tooltipAlignment, + tooltipPosition, + type, + }) => html` + Button + + + Tertiary Danger Button + + + Ghost Danger Button + `, +}; + +export const Ghost = { + argTypes: controls, + args: defaultArgs, + render: ({ + buttonClassName, + dangerDescription, + disabled, + href, + isExpressive, + isSelected, + linkRole, + size, + tooltipAlignment, + tooltipPosition, + type, + }) => html` + Button + `, +}; + +export const IconButton = { + argTypes: controls, + args: defaultArgs, + render: ({ + buttonClassName, + dangerDescription, + disabled, + href, + isExpressive, + isSelected, + kind, + linkRole, + size, + tooltipAlignment, + tooltipPosition, + type, + onClick, + }) => html` + ${Add16({ slot: 'icon' })} + `, +}; + +export const Secondary = { + argTypes: controls, + args: defaultArgs, + render: ({ + buttonClassName, + dangerDescription, + disabled, + href, + isExpressive, + isSelected, + linkRole, + size, + tooltipAlignment, + tooltipPosition, + type, + }) => html` + Button + `, +}; + +export const SetOfButtons = { + argTypes: controls, + args: defaultArgs, + render: ({ + buttonClassName, + dangerDescription, + disabled, + href, + isExpressive, + isSelected, + linkRole, + size, + tooltipAlignment, + tooltipPosition, + type, + }) => html` + + Secondary button + + + Primary button `, +}; + +export const Skeleton = { + render: () => html` + `, +}; + +export const Tertiary = { + argTypes: controls, + args: defaultArgs, + render: ({ + buttonClassName, + dangerDescription, + disabled, + href, + isExpressive, + isSelected, + linkRole, + size, + tooltipAlignment, + tooltipPosition, + type, + }) => html` + Button + `, +}; + +const meta = { + title: 'Components/Button', + parameters: { + actions: { argTypesRegex: '^on.*' }, + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/button/index.ts b/packages/carbon-web-components/src/components/button/index.ts index 5aab0679239..0b96983d47a 100644 --- a/packages/carbon-web-components/src/components/button/index.ts +++ b/packages/carbon-web-components/src/components/button/index.ts @@ -8,5 +8,5 @@ */ import './button'; -// import './button-set'; -// import './button-skeleton'; +import './button-set'; +import './button-skeleton'; diff --git a/packages/carbon-web-components/src/components/checkbox/checkbox-group.ts b/packages/carbon-web-components/src/components/checkbox/checkbox-group.ts index eb3cae39563..7887bd42d48 100644 --- a/packages/carbon-web-components/src/components/checkbox/checkbox-group.ts +++ b/packages/carbon-web-components/src/components/checkbox/checkbox-group.ts @@ -1,7 +1,7 @@ /** * @license * - * Copyright IBM Corp. 2019, 2023 + * Copyright IBM Corp. 2019, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. @@ -14,7 +14,7 @@ import { prefix } from '../../globals/settings'; import WarningFilled16 from '@carbon/icons/lib/warning--filled/16'; import WarningAltFilled16 from '@carbon/icons/lib/warning--alt--filled/16'; import CDSCheckbox from './checkbox'; -import styles from './checkbox.scss'; +import styles from './checkbox.scss?lit'; import { carbonElement as customElement } from '../../globals/decorators/carbon-element'; /** diff --git a/packages/carbon-web-components/src/components/checkbox/checkbox-story.ts b/packages/carbon-web-components/src/components/checkbox/checkbox-story.ts deleted file mode 100644 index 5a46c9fc5ff..00000000000 --- a/packages/carbon-web-components/src/components/checkbox/checkbox-story.ts +++ /dev/null @@ -1,119 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { action } from '@storybook/addon-actions'; -import { boolean } from '@storybook/addon-knobs'; -import { prefix } from '../../globals/settings'; -import textNullable from '../../../.storybook/knob-text-nullable'; -import './index'; -import storyDocs from './checkbox-story.mdx'; - -const checkboxLabel = 'Checkbox label'; - -export const Default = () => { - return html` - - ${checkboxLabel} - ${checkboxLabel} - - `; -}; - -Default.storyName = 'Default'; - -export const Skeleton = () => { - return html` -
- ${checkboxLabel} -
- `; -}; - -export const Single = () => { - return html` - ${checkboxLabel} -

- ${checkboxLabel} -

- ${checkboxLabel} -

- ${checkboxLabel} - `; -}; - -export const Playground = (args) => { - const { - disabled, - readonly, - onChange, - helperText, - invalid, - invalidText, - legendText, - warn, - warnText, - } = args?.[`${prefix}-checkbox`] ?? {}; - return html` - - Checkbox label - Checkbox label - Checkbox label - - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-checkbox`]: () => ({ - onChange: action(`${prefix}-checkbox-changed`), - disabled: boolean('Disabled (disabled)', false), - helperText: textNullable( - 'Helper text (helper-text)', - 'Helper text goes here' - ), - invalid: boolean('Invalid (invalid)', false), - invalidText: textNullable( - 'Invalid text (invalid-text)', - 'Invalid message goes here' - ), - legendText: textNullable('Legend text (legend-text)', 'Group label'), - readonly: boolean('Read only (readonly)', false), - warn: boolean('Warn (warn)', false), - warnText: textNullable('Warn text (warn-text)', 'Warn message goes here'), - }), - }, -}; - -export default { - title: 'Components/Checkbox', - parameters: { - ...storyDocs.parameters, - }, -}; diff --git a/packages/carbon-web-components/src/components/checkbox/checkbox-story.mdx b/packages/carbon-web-components/src/components/checkbox/checkbox.mdx similarity index 83% rename from packages/carbon-web-components/src/components/checkbox/checkbox-story.mdx rename to packages/carbon-web-components/src/components/checkbox/checkbox.mdx index 668f682383f..7003121de56 100644 --- a/packages/carbon-web-components/src/components/checkbox/checkbox-story.mdx +++ b/packages/carbon-web-components/src/components/checkbox/checkbox.mdx @@ -1,6 +1,10 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Markdown, Meta } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as CheckboxStories from './checkbox.stories'; + + + # Check box > đź’ˇ Check our @@ -22,8 +26,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/checkbox/index.js'; ``` - - +{`${cdnJs({ components: ['checkbox'] })}`} +{`${cdnCss()}`} ### HTML @@ -49,4 +53,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `checked` attribute). - + diff --git a/packages/carbon-web-components/src/components/checkbox/checkbox.stories.ts b/packages/carbon-web-components/src/components/checkbox/checkbox.stories.ts new file mode 100644 index 00000000000..86337e04973 --- /dev/null +++ b/packages/carbon-web-components/src/components/checkbox/checkbox.stories.ts @@ -0,0 +1,148 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2023 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { prefix } from '../../globals/settings'; +import storyDocs from './checkbox.mdx'; +import './index'; + +const checkboxLabel = 'Checkbox label'; + +const defaultArgs = { + disabled: false, + helperText: 'Helper text goes here', + invalid: false, + invalidText: 'Invalid message goes here', + legendText: 'Group label', + readonly: false, + warn: false, + warnText: 'Warn message goes here', +}; + +const controls = { + disabled: { + control: 'boolean', + description: 'Specify whether the checkbox should be disabled.', + }, + helperText: { + control: 'textNullable', + description: 'Provide text for the form group for additional help.', + }, + invalid: { + control: 'boolean', + description: 'Specify whether the form group is currently invalid.', + }, + invalidText: { + control: 'textNullable', + description: + 'Provide the text that is displayed when the form group is in an invalid state.', + }, + legendText: { + control: 'textNullable', + description: 'Provide the text to be rendered inside of the fieldset.', + }, + readonly: { + control: 'boolean', + description: 'Specify whether the checkbox group is read-only.', + }, + warn: { + control: 'boolean', + description: + 'Specify whether the form group is currently in warning state.', + }, + warnText: { + control: 'textNullable', + description: + 'Provide the text that is displayed when the form group is in warning state.', + }, +}; + +export const Default = { + render: () => html` + + ${checkboxLabel} + ${checkboxLabel} + + `, +}; + +export const Skeleton = { + render: () => html` +
+ ${checkboxLabel} +
+ `, +}; + +export const Single = { + render: () => html` + ${checkboxLabel} +

+ ${checkboxLabel} +

+ ${checkboxLabel} +

+ ${checkboxLabel} + `, +}; + +export const Playground = { + args: defaultArgs, + argTypes: controls, + render: ({ + disabled, + readonly, + onChange, + helperText, + invalid, + invalidText, + legendText, + warn, + warnText, + }) => + html` + + Checkbox label + Checkbox label + Checkbox label + + `, +}; + +const meta = { + title: 'Components/Checkbox', + parameters: { + actions: { argTypesRegex: '^on.*' }, + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/code-snippet/code-snippet-story.ts b/packages/carbon-web-components/src/components/code-snippet/code-snippet-story.ts deleted file mode 100644 index fa46f8d44b2..00000000000 --- a/packages/carbon-web-components/src/components/code-snippet/code-snippet-story.ts +++ /dev/null @@ -1,214 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { number, boolean } from '@storybook/addon-knobs'; -import { prefix } from '../../globals/settings'; -import textNullable from '../../../.storybook/knob-text-nullable'; -import storyDocs from './code-snippet-story.mdx'; -import './index'; - -export const inline = () => { - return html` - node -v - - `; -}; - -export const inlineWithLayer = () => { - return html` - - node -v - - - `; -}; - -export const multiline = () => { - const children = `"scripts": { - "build": "lerna run build --stream --prefix --npm-client yarn", - "ci-check": "carbon-cli ci-check", - "clean": "lerna run clean && lerna clean --yes && rimraf node_modules", - "doctoc": "doctoc --title '## Table of Contents'", - "format": "prettier --write '**/*.{js,md,scss,ts}' '!**/{build,es,lib,storybook,ts,umd}/**'", - "format:diff": "prettier --list-different '**/*.{js,md,scss,ts}' '!**/{build,es,lib,storybook,ts,umd}/**' '!packages/components/**'", - "lint": "eslint actions config codemods packages", - "lint:styles": "stylelint '**/*.{css,scss}' --report-needless-disables --report-invalid-scope-disables", - "sync": "carbon-cli sync", - "test": "cross-env BABEL_ENV=test jest", - "test:e2e": "cross-env BABEL_ENV=test jest --testPathPattern=e2e --testPathIgnorePatterns='examples,/packages/components/,/packages/react/'" - }, - "resolutions": { - "react": "~16.9.0", - "react-dom": "~16.9.0", - "react-is": "~16.9.0", - "react-test-renderer": "~16.9.0" - }, - "devDependencies": { - "@babel/core": "^7.10.0", - "@babel/plugin-proposal-class-properties": "^7.7.4", - "@babel/plugin-proposal-export-default-from": "^7.7.4", - "@babel/plugin-proposal-export-namespace-from": "^7.7.4", - "@babel/plugin-transform-runtime": "^7.10.0", - "@babel/preset-env": "^7.10.0", - "@babel/preset-react": "^7.10.0", - "@babel/runtime": "^7.10.0", - "@commitlint/cli": "^8.3.5", -`; - // prettier-ignore - return html` - ${children} - -`; -}; - -export const multilineWithLayer = () => { - const children = `"scripts": { - "build": "lerna run build --stream --prefix --npm-client yarn", - "ci-check": "carbon-cli ci-check", - "clean": "lerna run clean && lerna clean --yes && rimraf node_modules", - "doctoc": "doctoc --title '## Table of Contents'", - "format": "prettier --write '**/*.{js,md,scss,ts}' '!**/{build,es,lib,storybook,ts,umd}/**'", - "format:diff": "prettier --list-different '**/*.{js,md,scss,ts}' '!**/{build,es,lib,storybook,ts,umd}/**' '!packages/components/**'", - "lint": "eslint actions config codemods packages", - "lint:styles": "stylelint '**/*.{css,scss}' --report-needless-disables --report-invalid-scope-disables", - "sync": "carbon-cli sync", - "test": "cross-env BABEL_ENV=test jest", - "test:e2e": "cross-env BABEL_ENV=test jest --testPathPattern=e2e --testPathIgnorePatterns='examples,/packages/components/,/packages/react/'" - }, - "resolutions": { - "react": "~16.9.0", - "react-dom": "~16.9.0", - "react-is": "~16.9.0", - "react-test-renderer": "~16.9.0" - }, - "devDependencies": { - "@babel/core": "^7.10.0", - "@babel/plugin-proposal-class-properties": "^7.7.4", - "@babel/plugin-proposal-export-default-from": "^7.7.4", - "@babel/plugin-proposal-export-namespace-from": "^7.7.4", - "@babel/plugin-transform-runtime": "^7.10.0", - "@babel/preset-env": "^7.10.0", - "@babel/preset-react": "^7.10.0", - "@babel/runtime": "^7.10.0", - "@commitlint/cli": "^8.3.5", -`; - // prettier-ignore - return html` - - ${children} - - -`; -}; - -export const singleline = () => { - return html` - - yarn add carbon-components@latest carbon-components-react@latest - @carbon/icons-react@latest carbon-icons@latest - - `; -}; - -export const singlelineWithLayer = () => { - return html` - - yarn add carbon-components@latest carbon-components-react@latest - @carbon/icons-react@latest carbon-icons@latest > - - `; -}; - -export const skeleton = () => - html` - - - `; - -skeleton.parameters = { - percy: { - skip: true, - }, -}; - -export const Playground = (args) => { - const { - copyButtonDescription, - copyText, - disabled, - feedback, - feedbackTimeout, - hideCopyButton, - maxCollapsedNumberOfRows, - maxExpandedNumberOfRows, - minCollapsedNumberOfRows, - minExpandedNumberOfRows, - showLessText, - showMoreText, - wrapText, - } = args?.[`${prefix}-code-snippet`] ?? {}; - return html` - yarn add @carbon/react - - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-code-snippet`]: () => ({ - copyButtonDescription: textNullable( - 'Copy button description', - 'Copy to clipboard' - ), - copyText: textNullable('Copy text', ''), - disabled: boolean('Disabled', false), - feedback: textNullable('Feedback', ''), - feedbackTimeout: number('Feedback timeout', 0), - hideCopyButton: boolean('Hide copy button', false), - maxCollapsedNumberOfRows: number('Max collapsed number of rows', 15), - maxExpandeddNumberOfRows: number('Max expanded number of rows', 0), - minCollapsedNumberOfRows: number('Min collapsed number of rows', 3), - minExpandeddNumberOfRows: number('Min expanded number of rows', 16), - showLessText: textNullable('Show less text', 'Show less'), - showMoreText: textNullable('Show more text', 'Show more'), - wrapText: boolean('Wrap text', false), - }), - }, -}; - -export default { - title: 'Components/Code snippet', - parameters: { - ...storyDocs.parameters, - }, -}; diff --git a/packages/carbon-web-components/src/components/code-snippet/code-snippet-story.mdx b/packages/carbon-web-components/src/components/code-snippet/code-snippet.mdx similarity index 91% rename from packages/carbon-web-components/src/components/code-snippet/code-snippet-story.mdx rename to packages/carbon-web-components/src/components/code-snippet/code-snippet.mdx index d344bb199d1..c7811cff78e 100644 --- a/packages/carbon-web-components/src/components/code-snippet/code-snippet-story.mdx +++ b/packages/carbon-web-components/src/components/code-snippet/code-snippet.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Description } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as CodeSnippetStories from './code-snippet.stories'; + + # Code snippet @@ -80,4 +83,4 @@ For the skeleton variation, utilize ``. ## `` attributes and properties - + diff --git a/packages/carbon-web-components/src/components/code-snippet/code-snippet.stories.ts b/packages/carbon-web-components/src/components/code-snippet/code-snippet.stories.ts new file mode 100644 index 00000000000..8b1ce887824 --- /dev/null +++ b/packages/carbon-web-components/src/components/code-snippet/code-snippet.stories.ts @@ -0,0 +1,291 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import storyDocs from './code-snippet.mdx'; +import './index'; +import '../layer/index'; +import '../../../.storybook/templates/with-layer'; + +const args = { + copyButtonDescription: 'Copy to clipboard', + copyText: '', + disabled: false, + feedback: '', + feedbackTimeout: 0, + hideCopyButton: false, + maxCollapsedNumberOfRows: 15, + maxExpandeddNumberOfRows: 0, + minCollapsedNumberOfRows: 3, + minExpandeddNumberOfRows: 16, + showLessText: 'Show less', + showMoreText: 'Show more', + wrapText: false, +}; + +const argTypes = { + copyButtonDescription: { + control: 'text', + description: 'Specify the description for the Copy Button.', + }, + copyText: { + control: 'text', + description: + "Optional text to copy. If not specified, the children node's innerText will be used as the copy value.", + }, + disabled: { + control: 'boolean', + description: 'Specify whether or not the CodeSnippet should be disabled.', + }, + feedback: { + control: 'text', + description: 'Specify the string displayed when the snippet is copied.', + }, + feedbackTimeout: { + control: 'number', + description: + 'Specify the time it takes for the feedback message to timeout.', + }, + hideCopyButton: { + control: 'boolean', + description: + 'Specify whether or not a copy button should be used/rendered.', + }, + maxCollapsedNumberOfRows: { + control: 'number', + description: + 'Specify the maximum number of rows to be shown when in collapsed view.', + }, + maxExpandeddNumberOfRows: { + control: 'number', + description: + 'Specify the maximum number of rows to be shown when in expanded view.', + }, + minCollapsedNumberOfRows: { + control: 'number', + description: + 'Specify the minimum number of rows to be shown when in collapsed view.', + }, + minExpandeddNumberOfRows: { + control: 'number', + description: + 'Specify the minimum number of rows to be shown when in expanded view.', + }, + showLessText: { + control: 'text', + description: + 'Specify a string that is displayed when the Code Snippet has been interacted with to show more lines.', + }, + showMoreText: { + control: 'text', + description: + 'Specify a string that is displayed when the Code Snippet text is more than 15 lines.', + }, + wrapText: { + control: 'boolean', + description: 'Specify whether or not to wrap the text.', + }, +}; + +export const Inline = { + render: () => { + return html` + node -v + + `; + }, +}; + +export const InlineWithLayer = { + render: () => { + return html` + + node -v + + + `; + }, +}; + +export const Multiline = { + render: () => { + const children = `"scripts": { + "build": "lerna run build --stream --prefix --npm-client yarn", + "ci-check": "carbon-cli ci-check", + "clean": "lerna run clean && lerna clean --yes && rimraf node_modules", + "doctoc": "doctoc --title '## Table of Contents'", + "format": "prettier --write '**/*.{js,md,scss,ts}' '!**/{build,es,lib,storybook,ts,umd}/**'", + "format:diff": "prettier --list-different '**/*.{js,md,scss,ts}' '!**/{build,es,lib,storybook,ts,umd}/**' '!packages/components/**'", + "lint": "eslint actions config codemods packages", + "lint:styles": "stylelint '**/*.{css,scss}' --report-needless-disables --report-invalid-scope-disables", + "sync": "carbon-cli sync", + "test": "cross-env BABEL_ENV=test jest", + "test:e2e": "cross-env BABEL_ENV=test jest --testPathPattern=e2e --testPathIgnorePatterns='examples,/packages/components/,/packages/react/'" + }, + "resolutions": { + "react": "~16.9.0", + "react-dom": "~16.9.0", + "react-is": "~16.9.0", + "react-test-renderer": "~16.9.0" + }, + "devDependencies": { + "@babel/core": "^7.10.0", + "@babel/plugin-proposal-class-properties": "^7.7.4", + "@babel/plugin-proposal-export-default-from": "^7.7.4", + "@babel/plugin-proposal-export-namespace-from": "^7.7.4", + "@babel/plugin-transform-runtime": "^7.10.0", + "@babel/preset-env": "^7.10.0", + "@babel/preset-react": "^7.10.0", + "@babel/runtime": "^7.10.0", + "@commitlint/cli": "^8.3.5", +`; + // prettier-ignore + return html` + ${children} + +`; + }, +}; + +export const MultilineWithLayer = { + render: () => { + const children = `"scripts": { + "build": "lerna run build --stream --prefix --npm-client yarn", + "ci-check": "carbon-cli ci-check", + "clean": "lerna run clean && lerna clean --yes && rimraf node_modules", + "doctoc": "doctoc --title '## Table of Contents'", + "format": "prettier --write '**/*.{js,md,scss,ts}' '!**/{build,es,lib,storybook,ts,umd}/**'", + "format:diff": "prettier --list-different '**/*.{js,md,scss,ts}' '!**/{build,es,lib,storybook,ts,umd}/**' '!packages/components/**'", + "lint": "eslint actions config codemods packages", + "lint:styles": "stylelint '**/*.{css,scss}' --report-needless-disables --report-invalid-scope-disables", + "sync": "carbon-cli sync", + "test": "cross-env BABEL_ENV=test jest", + "test:e2e": "cross-env BABEL_ENV=test jest --testPathPattern=e2e --testPathIgnorePatterns='examples,/packages/components/,/packages/react/'" + }, + "resolutions": { + "react": "~16.9.0", + "react-dom": "~16.9.0", + "react-is": "~16.9.0", + "react-test-renderer": "~16.9.0" + }, + "devDependencies": { + "@babel/core": "^7.10.0", + "@babel/plugin-proposal-class-properties": "^7.7.4", + "@babel/plugin-proposal-export-default-from": "^7.7.4", + "@babel/plugin-proposal-export-namespace-from": "^7.7.4", + "@babel/plugin-transform-runtime": "^7.10.0", + "@babel/preset-env": "^7.10.0", + "@babel/preset-react": "^7.10.0", + "@babel/runtime": "^7.10.0", + "@commitlint/cli": "^8.3.5", +`; + // prettier-ignore + return html` + + ${children} + + +`; + }, +}; + +export const Singleline = { + render: () => { + return html` + + yarn add carbon-components@latest carbon-components-react@latest + @carbon/icons-react@latest carbon-icons@latest + + `; + }, +}; + +export const SinglelineWithLayer = { + render: () => { + return html` + + yarn add carbon-components@latest carbon-components-react@latest + @carbon/icons-react@latest carbon-icons@latest > + + `; + }, +}; + +export const Skeleton = { + parameters: { + percy: { + skip: true, + }, + }, + render: () => + html` + + + `, +}; + +export const Playground = { + args, + argTypes, + render: (args) => { + const { + copyButtonDescription, + copyText, + disabled, + feedback, + feedbackTimeout, + hideCopyButton, + maxCollapsedNumberOfRows, + maxExpandedNumberOfRows, + minCollapsedNumberOfRows, + minExpandedNumberOfRows, + showLessText, + showMoreText, + wrapText, + } = args ?? {}; + return html` + yarn add @carbon/react + + `; + }, +}; + +const meta = { + title: 'Components/Code snippet', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/combo-box/combo-box-story.mdx b/packages/carbon-web-components/src/components/combo-box/combo-box.mdx similarity index 92% rename from packages/carbon-web-components/src/components/combo-box/combo-box-story.mdx rename to packages/carbon-web-components/src/components/combo-box/combo-box.mdx index e6f034ab047..a1f783dcf50 100644 --- a/packages/carbon-web-components/src/components/combo-box/combo-box-story.mdx +++ b/packages/carbon-web-components/src/components/combo-box/combo-box.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Markdown, Meta } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as ComboBoxStories from './combo-box.stories'; + + # Combo box @@ -22,8 +25,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/combo-box/index.js'; ``` - - +{`${cdnJs({ components: ['combo-box'] })}`} +{`${cdnCss()}`} ### HTML @@ -94,7 +97,7 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `open` attribute). - + ## `` attributes and properties @@ -102,4 +105,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `disabled` attribute). - + diff --git a/packages/carbon-web-components/src/components/combo-box/combo-box-story.ts b/packages/carbon-web-components/src/components/combo-box/combo-box.stories.ts similarity index 58% rename from packages/carbon-web-components/src/components/combo-box/combo-box-story.ts rename to packages/carbon-web-components/src/components/combo-box/combo-box.stories.ts index 9560e430d1b..8862273943c 100644 --- a/packages/carbon-web-components/src/components/combo-box/combo-box-story.ts +++ b/packages/carbon-web-components/src/components/combo-box/combo-box.stories.ts @@ -9,12 +9,9 @@ import { html } from 'lit'; import { ifDefined } from 'lit/directives/if-defined.js'; -import { boolean, select } from '@storybook/addon-knobs'; import { DROPDOWN_DIRECTION, DROPDOWN_SIZE } from './combo-box'; import './combo-box-item'; -import storyDocs from './combo-box-story.mdx'; -import { prefix } from '../../globals/settings'; -import textNullable from '../../../.storybook/knob-text-nullable'; +import storyDocs from './combo-box.mdx'; const items = [ { @@ -55,8 +52,79 @@ const sizes = { [`Large size (${DROPDOWN_SIZE.LARGE})`]: DROPDOWN_SIZE.LARGE, }; -export const Default = () => { - return html` +const defaultArgs = { + direction: DROPDOWN_DIRECTION.BOTTOM, + disabled: false, + hideLabel: false, + helperText: 'This is some helper text', + invalid: false, + invalidText: 'invalid selection', + label: 'This is an example label', + readOnly: false, + size: null, + titleText: 'This is an example title', + value: '', + warn: false, + warnText: 'please notice the warning', +} + +const controls = { + disabled: { + control: 'boolean', + description: `Specify if the dropdown should be disabled, or not.`, + }, + direction: { + control: 'select', options: directionOptions, + description: `Dropdown direction` + }, + hideLabel: { + control: 'boolean', + description: `Specify if the title text should be hidden, or not.`, + }, + helperText: { + control: 'text', + description: `The helper text for the dropdown.`, + }, + invalid: { + control: 'boolean', + description: `Specify if the dropdown should display an invalid icon, or not.`, + }, + invalidText: { + control: 'text', + description: `Message which is displayed if the value is invalid.`, + }, + label: { + control: 'text', + description: `The default content of the trigger button.`, + }, + readOnly: { + control: 'boolean', + description: `Specify if the dropdown should be read only, or not.`, + }, + size: { + control: 'select', options: sizes, + description: `Dropdown size.` + }, + titleText: { + control: 'text', + description: `Text that will be read by a screen reader when visiting this control.`, + }, + value: { + control: 'text', + description: `The value of the selected item.`, + }, + warn: { + control: 'boolean', + description: `Specify whether the control is currently in warning state.`, + }, + warnText: { + control: 'text', + description: `Text that is displayed when the control is in warning state.`, + }, +}; + +export const Default = { + render: () => html` @@ -68,11 +136,11 @@ export const Default = () => { ` )} - `; + ` }; -export const WithLayer = () => { - return html` +export const WithLayer = { + render: () => html`
{
- `; + ` }; -export const Playground = (args) => { - const { +export const Playground = { + argTypes: controls, + args: defaultArgs, + render: ({ disabled, helperText, invalid, @@ -110,8 +180,7 @@ export const Playground = (args) => { type, invalidText, value, - } = args?.[`${prefix}-combo-box`] ?? {}; - return html` + }) => html` { ` )} - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-combo-box`]: () => ({ - direction: select( - 'Direction', - directionOptions, - DROPDOWN_DIRECTION.BOTTOM - ), - disabled: boolean('Disabled (disabled)', false), - helperText: textNullable( - 'Helper text (helper-text)', - 'Optional helper text' - ), - hideLabel: boolean('Hide label (hide-label)', false), - invalid: boolean('Invalid (invalid)', false), - invalidText: textNullable( - 'Invalid text (invalid-text)', - 'invalid selection' - ), - readOnly: boolean('Read only (read-only)', false), - titleText: textNullable('Title text (title-text)', 'ComboBox title'), - size: select('Size (size)', sizes, null), - value: textNullable('Selected value (value)', ''), - label: textNullable('Placeholder (label)', ''), - warn: boolean('Warn (warn)', false), - warnText: textNullable( - 'Warn text (warn-text)', - 'please notice the warning' - ), - }), - }, -}; + ` +} -export default { +const meta = { title: 'Components/Combo box', - parameters: { - ...storyDocs.parameters, - }, decorators: [ (story, { name }) => { const width = !name.toLowerCase().includes('layer') ? `width:300px` : ``; return html`
${story()}
`; }, ], + parameters: { + docs: { + page: storyDocs, + }, + }, }; + +export default meta; diff --git a/packages/carbon-web-components/src/components/content-switcher/content-switcher-story.ts b/packages/carbon-web-components/src/components/content-switcher/content-switcher-story.ts deleted file mode 100644 index 5bdff77ba51..00000000000 --- a/packages/carbon-web-components/src/components/content-switcher/content-switcher-story.ts +++ /dev/null @@ -1,150 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { action } from '@storybook/addon-actions'; -import { boolean, select } from '@storybook/addon-knobs'; -import textNullable from '../../../.storybook/knob-text-nullable'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import { CONTENT_SWITCHER_SIZE } from './content-switcher'; -import './content-switcher-item'; -import storyDocs from './content-switcher-story.mdx'; -import { prefix } from '../../globals/settings'; -import TableOfContents16 from '@carbon/web-components/es/icons/table-of-contents/16'; -import Workspace16 from '@carbon/web-components/es/icons/workspace/16'; -import ViewMode2_16 from '@carbon/web-components/es/icons/view--mode-2/16'; -import '../../../.storybook/templates/with-layer'; - -const noop = () => {}; - -const sizes = { - 'Medium (md - default)': null, - [`Small (${CONTENT_SWITCHER_SIZE.SMALL})`]: CONTENT_SWITCHER_SIZE.SMALL, - [`Large (${CONTENT_SWITCHER_SIZE.LARGE})`]: CONTENT_SWITCHER_SIZE.LARGE, -}; - -export const Default = () => html` - - - First section - - - Second section - - - Third section - - -`; - -export default { - title: 'Components/Content switcher', -}; - -export const IconOnly = () => html` - - - ${TableOfContents16()} - Table of Contents - - - ${Workspace16()} - Workspace Test - - - ${ViewMode2_16()} - View Mode - - -`; - -export const IconOnlyWithLayer = () => html` - - - - ${TableOfContents16()} - Table of Contents - - - ${Workspace16()} - Workspace Test - - - ${ViewMode2_16()} - View Mode - - - -`; - -export const WithLayer = () => html` - - - - First section - - - Second section - - - Third section - - - -`; - -export const Playground = (args) => { - const { - value, - disableSelection, - onBeforeSelect = noop, - onSelect = noop, - size, - } = args?.[`${prefix}-content-switcher`] ?? {}; - const handleBeforeSelected = (event: CustomEvent) => { - onBeforeSelect(event); - if (disableSelection) { - event.preventDefault(); - } - }; - - return html` - - - First section - - - Second section - - - Third section - - - `; -}; - -Playground.parameters = { - ...storyDocs.parameters, - knobs: { - [`${prefix}-content-switcher`]: () => ({ - value: textNullable('The value of the selected item (value)', ''), - size: select('Button size (size)', sizes, null), - disableSelection: boolean( - `Disable user-initiated selection change (Call event.preventDefault() in ${prefix}-content-switcher-beingselected event)`, - false - ), - onBeforeSelect: action(`${prefix}-content-switcher-beingselected`), - onSelect: action(`${prefix}-content-switcher-selected`), - }), - }, -}; diff --git a/packages/carbon-web-components/src/components/content-switcher/content-switcher-story.mdx b/packages/carbon-web-components/src/components/content-switcher/content-switcher.mdx similarity index 86% rename from packages/carbon-web-components/src/components/content-switcher/content-switcher-story.mdx rename to packages/carbon-web-components/src/components/content-switcher/content-switcher.mdx index 89f5daa93aa..057680a7f69 100644 --- a/packages/carbon-web-components/src/components/content-switcher/content-switcher-story.mdx +++ b/packages/carbon-web-components/src/components/content-switcher/content-switcher.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Description } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as ContentSwitcherStories from './content-switcher.stories'; + + # Content switcher @@ -44,8 +47,8 @@ import '@carbon/web-components/es/components/content-switcher/index.js'; ## `` attributes, properties and events - + ## `` attributes and properties - + diff --git a/packages/carbon-web-components/src/components/content-switcher/content-switcher.scss b/packages/carbon-web-components/src/components/content-switcher/content-switcher.scss index e530ed5776b..7259866c5bb 100644 --- a/packages/carbon-web-components/src/components/content-switcher/content-switcher.scss +++ b/packages/carbon-web-components/src/components/content-switcher/content-switcher.scss @@ -1,5 +1,5 @@ // -// Copyright IBM Corp. 2019, 2023 +// Copyright IBM Corp. 2019, 2024 // // This source code is licensed under the Apache-2.0 license found in the // LICENSE file in the root directory of this source tree. @@ -77,7 +77,7 @@ $css--plex: true !default; } } -:host(#{$prefix}-content-switcher-item)[icon] { +:host(#{$prefix}-content-switcher-item[icon]) { width: initial; .#{$prefix}--content-switcher-btn { diff --git a/packages/carbon-web-components/src/components/content-switcher/content-switcher.stories.ts b/packages/carbon-web-components/src/components/content-switcher/content-switcher.stories.ts new file mode 100644 index 00000000000..68c70414794 --- /dev/null +++ b/packages/carbon-web-components/src/components/content-switcher/content-switcher.stories.ts @@ -0,0 +1,179 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { ifDefined } from 'lit/directives/if-defined.js'; +import { CONTENT_SWITCHER_SIZE } from './content-switcher'; +import './index'; +import storyDocs from './content-switcher.mdx'; +import { prefix } from '../../globals/settings'; +import TableOfContents16 from '@carbon/web-components/es/icons/table-of-contents/16'; +import Workspace16 from '@carbon/web-components/es/icons/workspace/16'; +import ViewMode2_16 from '@carbon/web-components/es/icons/view--mode-2/16'; +import '../layer/index'; +import '../../../.storybook/templates/with-layer'; + +const noop = () => {}; + +const sizes = { + 'Medium (md - default)': null, + [`Small (${CONTENT_SWITCHER_SIZE.SMALL})`]: CONTENT_SWITCHER_SIZE.SMALL, + [`Large (${CONTENT_SWITCHER_SIZE.LARGE})`]: CONTENT_SWITCHER_SIZE.LARGE, +}; + +const args = { + value: '', + size: null, + disableSelection: false, +}; + +const argTypes = { + value: { + control: 'text', + description: 'The value of the selected item (value)', + }, + size: { + control: 'select', + options: sizes, + description: 'Button size (size)', + }, + disableSelection: { + control: 'boolean', + description: `Disable user-initiated selection change (Call event.preventDefault() in ${prefix}-content-switcher-beingselected event)`, + }, + onBeforeSelect: { + action: `${prefix}-content-switcher-beingselected`, + }, + onSelect: { + action: `${prefix}-content-switcher-selected`, + }, +}; + +export const Default = { + render: () => html` + + + First section + + + Second section + + + Third section + + + `, +}; + +export const IconOnly = { + render: () => html` + + + ${TableOfContents16()} + Table of Contents + + + ${Workspace16()} + Workspace Test + + + ${ViewMode2_16()} + View Mode + + + `, +}; + +export const IconOnlyWithLayer = { + render: () => html` + + + + ${TableOfContents16()} + Table of Contents + + + ${Workspace16()} + Workspace Test + + + ${ViewMode2_16()} + View Mode + + + + `, +}; + +export const WithLayer = { + render: () => html` + + + + First section + + + Second section + + + Third section + + + + `, +}; + +export const Playground = { + args, + argTypes, + render: (args) => { + const { + value, + disableSelection, + onBeforeSelect = noop, + onSelect = noop, + size, + } = args ?? {}; + const handleBeforeSelected = (event: CustomEvent) => { + onBeforeSelect(event); + if (disableSelection) { + event.preventDefault(); + } + }; + + return html` + + + First section + + + Second section + + + Third section + + + `; + }, +}; + +const meta = { + title: 'Components/Content switcher', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/content-switcher/index.ts b/packages/carbon-web-components/src/components/content-switcher/index.ts index 1112fccef39..0cc82cd4fa5 100644 --- a/packages/carbon-web-components/src/components/content-switcher/index.ts +++ b/packages/carbon-web-components/src/components/content-switcher/index.ts @@ -1,11 +1,13 @@ /** * @license * - * Copyright IBM Corp. 2021, 2022 + * Copyright IBM Corp. 2021, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ +import '../tooltip/tooltip'; +import '../tooltip/tooltip-content'; import './content-switcher'; import './content-switcher-item'; diff --git a/packages/carbon-web-components/src/components/copy-button/copy-button.stories.ts b/packages/carbon-web-components/src/components/copy-button/copy-button.stories.ts index 6b5958e0097..f0719e35219 100644 --- a/packages/carbon-web-components/src/components/copy-button/copy-button.stories.ts +++ b/packages/carbon-web-components/src/components/copy-button/copy-button.stories.ts @@ -1,7 +1,7 @@ /** * @license * - * Copyright IBM Corp. 2019, 2023 + * Copyright IBM Corp. 2019, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. @@ -53,7 +53,6 @@ const meta: Meta = { }; export const Default = { - name: 'Default', parameters: { controls: { exclude: /(.*?)/ }, }, @@ -63,4 +62,4 @@ export const Playground = { argTypes: controls, }; -export default meta; \ No newline at end of file +export default meta; diff --git a/packages/carbon-web-components/src/components/data-table/stories/data-table-basic-story.ts b/packages/carbon-web-components/src/components/data-table/stories/data-table-basic.stories.ts similarity index 88% rename from packages/carbon-web-components/src/components/data-table/stories/data-table-basic-story.ts rename to packages/carbon-web-components/src/components/data-table/stories/data-table-basic.stories.ts index 419539e9453..8ff372e69f8 100644 --- a/packages/carbon-web-components/src/components/data-table/stories/data-table-basic-story.ts +++ b/packages/carbon-web-components/src/components/data-table/stories/data-table-basic.stories.ts @@ -8,11 +8,9 @@ */ import { html } from 'lit'; -import { boolean, select, text } from '@storybook/addon-knobs'; -import { prefix } from '../../../globals/settings'; import { TABLE_SIZE } from '../table'; import '../index'; -import storyDocs from './data-table-story.mdx'; +import storyDocs from './data-table.mdx'; const sizes = { [`xs (${TABLE_SIZE.XS})`]: TABLE_SIZE.XS, @@ -22,8 +20,35 @@ const sizes = { [`xl (${TABLE_SIZE.XL})`]: TABLE_SIZE.XL, }; -export const Default = () => { - return html` +const defaultArgs = { + locale: 'en', + size: TABLE_SIZE.LG, + useStaticWidth: false, + useZebraStyles: false, +}; + +const controls = { + locale: { + control: 'text', + description: 'Provide a string for the current locale.', + }, + size: { + control: 'radio', + description: 'Change the row height of table.', + options: sizes, + }, + useStaticWidth: { + control: 'boolean', + description: 'Use static width.', + }, + useZebraStyles: { + control: 'boolean', + description: 'Use zebra styles.', + }, +}; + +export const Default = { + render: () => html` @@ -86,11 +111,11 @@ export const Default = () => { - `; + `, }; -export const XLWithTwoLines = () => { - return html` +export const XLWithTwoLines = { + render: () => html` @@ -113,8 +138,8 @@ export const XLWithTwoLines = () => { 22 - Load Balancer 2 + + Load Balancer 2 Austin, Tx DNS delegation @@ -123,8 +148,8 @@ export const XLWithTwoLines = () => { 22 - Load Balancer 3 + + Load Balancer 3 Austin, Tx Round robin @@ -133,8 +158,8 @@ export const XLWithTwoLines = () => { 22 - Load Balancer 4 + + Load Balancer 4 Austin, Tx Round robin @@ -143,8 +168,8 @@ export const XLWithTwoLines = () => { 22 - Load Balancer 5 + + Load Balancer 5 Austin, Tx Round robin @@ -153,8 +178,8 @@ export const XLWithTwoLines = () => { 22 - Load Balancer 6 + + Load Balancer 6 Austin, Tx Round robin @@ -163,8 +188,8 @@ export const XLWithTwoLines = () => { 22 - Load Balancer 7 + + Load Balancer 7 Austin, Tx Round robin @@ -174,13 +199,13 @@ export const XLWithTwoLines = () => { - `; + `, }; -export const Playground = (args) => { - const { locale, size, useStaticWidth, useZebraStyles } = - args?.[`${prefix}-table`] ?? {}; - return html` +export const Playground = { + args: defaultArgs, + argTypes: controls, + render: ({ locale, size, useStaticWidth, useZebraStyles }) => html` { - `; + `, }; -Playground.parameters = { - knobs: { - [`${prefix}-table`]: () => ({ - locale: text('Locale', 'en'), - size: select('Size', sizes, TABLE_SIZE.LG), - useStaticWidth: boolean('Use static width', false), - useZebraStyles: boolean('Use zebra styles', false), - }), - }, -}; - -export default { +const meta = { title: 'Components/DataTable/Basic', parameters: { - ...storyDocs.parameters, + docs: { + page: storyDocs, + }, }, }; + +export default meta; diff --git a/packages/carbon-web-components/src/components/data-table/stories/data-table-batch-actions-story.ts b/packages/carbon-web-components/src/components/data-table/stories/data-table-batch-actions.stories.ts similarity index 91% rename from packages/carbon-web-components/src/components/data-table/stories/data-table-batch-actions-story.ts rename to packages/carbon-web-components/src/components/data-table/stories/data-table-batch-actions.stories.ts index 0fdfa4bb30d..9dc9b4bb8dd 100644 --- a/packages/carbon-web-components/src/components/data-table/stories/data-table-batch-actions-story.ts +++ b/packages/carbon-web-components/src/components/data-table/stories/data-table-batch-actions.stories.ts @@ -8,7 +8,6 @@ */ import { html } from 'lit'; -import { boolean, select, text } from '@storybook/addon-knobs'; import { prefix } from '../../../globals/settings'; import { TABLE_SIZE } from '../table'; import Add from '@carbon/web-components/es/icons/add/16'; @@ -18,8 +17,9 @@ import TrashCan from '@carbon/web-components/es/icons/trash-can/16'; import Download16 from '@carbon/web-components/es/icons/download/16'; // @ts-ignore import Settings16 from '@carbon/web-components/es/icons/settings/16'; +import '../../overflow-menu'; import '../index'; -import storyDocs from './data-table-story.mdx'; +import storyDocs from './data-table.mdx'; const sizes = { [`xs (${TABLE_SIZE.XS})`]: TABLE_SIZE.XS, @@ -29,8 +29,45 @@ const sizes = { [`xl (${TABLE_SIZE.XL})`]: TABLE_SIZE.XL, }; -export const Default = () => { - return html` +const defaultArgs = { + isSortable: false, + locale: 'en', + radio: false, + size: TABLE_SIZE.LG, + useStaticWidth: false, + useZebraStyles: false, +}; + +const controls = { + isSortable: { + control: 'boolean', + description: 'Is sortable', + }, + locale: { + control: 'text', + description: 'Locale', + }, + radio: { + control: 'boolean', + description: 'Radio', + }, + size: { + control: 'radio', + description: 'Size', + options: sizes, + }, + useStaticWidth: { + control: 'boolean', + description: 'Use static width', + }, + useZebraStyles: { + control: 'boolean', + description: 'Use zebra styles', + }, +}; + +export const Default = { + render: () => html` DataTable { - `; + `, }; -export const Playground = (args) => { - const { isSortable, locale, radio, size, useStaticWidth, useZebraStyles } = - args?.[`${prefix}-table`] ?? {}; - return html` +export const Playground = { + args: defaultArgs, + argsType: controls, + render: ({ + isSortable, + locale, + radio, + size, + useStaticWidth, + useZebraStyles, + }) => html` { - `; + `, }; -Playground.parameters = { - knobs: { - [`${prefix}-table`]: () => ({ - isSortable: boolean('Is sortable', false), - locale: text('Locale', 'en'), - radio: boolean('Radio', false), - size: select('Size', sizes, TABLE_SIZE.LG), - useStaticWidth: boolean('Use static width', false), - useZebraStyles: boolean('Use zebra styles', false), - }), - }, -}; - -export default { +const meta = { title: 'Components/DataTable/Batch Actions', parameters: { - ...storyDocs.parameters, + docs: { + page: storyDocs, + }, }, }; + +export default meta; diff --git a/packages/carbon-web-components/src/components/data-table/stories/data-table-dynamic-story.ts b/packages/carbon-web-components/src/components/data-table/stories/data-table-dynamic.stories.ts similarity index 93% rename from packages/carbon-web-components/src/components/data-table/stories/data-table-dynamic-story.ts rename to packages/carbon-web-components/src/components/data-table/stories/data-table-dynamic.stories.ts index 0b0767c4e82..79a39c70586 100644 --- a/packages/carbon-web-components/src/components/data-table/stories/data-table-dynamic-story.ts +++ b/packages/carbon-web-components/src/components/data-table/stories/data-table-dynamic.stories.ts @@ -8,7 +8,6 @@ */ import { html } from 'lit'; -import { boolean, select, text } from '@storybook/addon-knobs'; import { prefix } from '../../../globals/settings'; import { TABLE_SIZE } from '../table'; import Add from '@carbon/web-components/es/icons/add/16'; @@ -19,7 +18,7 @@ import Download16 from '@carbon/web-components/es/icons/download/16'; // @ts-ignore import Settings16 from '@carbon/web-components/es/icons/settings/16'; import '../index'; -import storyDocs from './data-table-story.mdx'; +import storyDocs from './data-table.mdx'; const sizes = { [`xs (${TABLE_SIZE.XS})`]: TABLE_SIZE.XS, @@ -29,6 +28,43 @@ const sizes = { [`xl (${TABLE_SIZE.XL})`]: TABLE_SIZE.XL, }; +const defaultArgs = { + isSortable: false, + locale: 'en', + radio: false, + size: TABLE_SIZE.LG, + useStaticWidth: false, + useZebraStyles: false, +}; + +const controls = { + isSortable: { + control: 'boolean', + description: 'Is sortable', + }, + locale: { + control: 'text', + description: 'Locale', + }, + radio: { + control: 'boolean', + description: 'Radio', + }, + size: { + control: 'radio', + description: 'Size', + options: sizes, + }, + useStaticWidth: { + control: 'boolean', + description: 'Use static width', + }, + useZebraStyles: { + control: 'boolean', + description: 'Use zebra styles', + }, +}; + let headerCount = 6; let rowCount = 1; @@ -91,8 +127,8 @@ const addHeader = () => { headerCount++; }; -export const Default = () => { - return html` +export const Default = { + render: () => html` DataTable { - `; + `, }; -export const Playground = (args) => { - const { isSortable, locale, radio, size, useStaticWidth, useZebraStyles } = - args?.[`${prefix}-table`] ?? {}; - return html` +export const Playground = { + args: defaultArgs, + argTypes: controls, + render: ({ + isSortable, + locale, + radio, + size, + useStaticWidth, + useZebraStyles, + }) => html` { - `; + `, }; -Playground.parameters = { - knobs: { - [`${prefix}-table`]: () => ({ - isSortable: boolean('Is sortable', false), - locale: text('Locale', 'en'), - radio: boolean('Radio', false), - size: select('Size', sizes, TABLE_SIZE.LG), - useStaticWidth: boolean('Use static width', false), - useZebraStyles: boolean('Use zebra styles', false), - }), - }, -}; - -export default { +const meta = { title: 'Components/DataTable/Dynamic', parameters: { - ...storyDocs.parameters, + docs: { + page: storyDocs, + }, }, }; + +export default meta; diff --git a/packages/carbon-web-components/src/components/data-table/stories/data-table-expansion-story.ts b/packages/carbon-web-components/src/components/data-table/stories/data-table-expansion.stories.ts similarity index 93% rename from packages/carbon-web-components/src/components/data-table/stories/data-table-expansion-story.ts rename to packages/carbon-web-components/src/components/data-table/stories/data-table-expansion.stories.ts index 5fc4f8c0b4c..196afe42a66 100644 --- a/packages/carbon-web-components/src/components/data-table/stories/data-table-expansion-story.ts +++ b/packages/carbon-web-components/src/components/data-table/stories/data-table-expansion.stories.ts @@ -8,11 +8,9 @@ */ import { html } from 'lit'; -import { boolean, select, text } from '@storybook/addon-knobs'; -import { prefix } from '../../../globals/settings'; import { TABLE_SIZE } from '../table'; import '../index'; -import storyDocs from './data-table-story.mdx'; +import storyDocs from './data-table.mdx'; const sizes = { [`xs (${TABLE_SIZE.XS})`]: TABLE_SIZE.XS, @@ -22,8 +20,40 @@ const sizes = { [`xl (${TABLE_SIZE.XL})`]: TABLE_SIZE.XL, }; -export const Default = () => { - return html` +const defaultArgs = { + isSortable: false, + locale: 'en', + size: TABLE_SIZE.LG, + useStaticWidth: false, + useZebraStyles: false, +}; + +const controls = { + isSortable: { + control: 'boolean', + description: 'Is sortable', + }, + locale: { + control: 'text', + description: 'Locale', + }, + size: { + control: 'radio', + description: 'Size', + options: sizes, + }, + useStaticWidth: { + control: 'boolean', + description: 'Use static width', + }, + useZebraStyles: { + control: 'boolean', + description: 'Use zebra styles', + }, +}; + +export const Default = { + render: () => html` DataTable { - `; + `, }; -export const BatchExpansion = () => { - return html` +export const BatchExpansion = { + render: () => html` DataTable { - `; + `, }; -export const Playground = (args) => { - const { isSortable, locale, size, useStaticWidth, useZebraStyles } = - args?.[`${prefix}-table`] ?? {}; - return html` +export const Playground = { + args: defaultArgs, + argTypes: controls, + render: ({ + isSortable, + locale, + size, + useStaticWidth, + useZebraStyles, + }) => html` { - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-table`]: () => ({ - isSortable: boolean('Is sortable', false), - locale: text('Locale', 'en'), - size: select('Size', sizes, TABLE_SIZE.LG), - useStaticWidth: boolean('Use static width', false), - useZebraStyles: boolean('Use zebra styles', false), - }), - }, + `, }; -export default { +const meta = { title: 'Components/DataTable/Expansion', parameters: { - ...storyDocs.parameters, + docs: { + page: storyDocs, + }, }, }; + +export default meta; diff --git a/packages/carbon-web-components/src/components/data-table/stories/data-table-filtering-story.ts b/packages/carbon-web-components/src/components/data-table/stories/data-table-filtering.stories.ts similarity index 90% rename from packages/carbon-web-components/src/components/data-table/stories/data-table-filtering-story.ts rename to packages/carbon-web-components/src/components/data-table/stories/data-table-filtering.stories.ts index b25f2ff3ac6..e7071a11d49 100644 --- a/packages/carbon-web-components/src/components/data-table/stories/data-table-filtering-story.ts +++ b/packages/carbon-web-components/src/components/data-table/stories/data-table-filtering.stories.ts @@ -8,13 +8,12 @@ */ import { html } from 'lit'; -import { boolean, select, text } from '@storybook/addon-knobs'; import { prefix } from '../../../globals/settings'; import { TABLE_SIZE } from '../table'; // @ts-ignore import Settings16 from '@carbon/web-components/es/icons/settings/16'; import '../index'; -import storyDocs from './data-table-story.mdx'; +import storyDocs from './data-table.mdx'; const sizes = { [`xs (${TABLE_SIZE.XS})`]: TABLE_SIZE.XS, @@ -24,8 +23,40 @@ const sizes = { [`xl (${TABLE_SIZE.XL})`]: TABLE_SIZE.XL, }; -export const Default = () => { - return html` +const defaultArgs = { + isSortable: false, + locale: 'en', + size: TABLE_SIZE.LG, + useStaticWidth: false, + useZebraStyles: false, +}; + +const controls = { + isSortable: { + control: 'boolean', + description: 'Is sortable', + }, + locale: { + control: 'text', + description: 'Locale', + }, + size: { + control: 'radio', + description: 'Size', + options: sizes, + }, + useStaticWidth: { + control: 'boolean', + description: 'Use static width', + }, + useZebraStyles: { + control: 'boolean', + description: 'Use zebra styles', + }, +}; + +export const Default = { + render: () => html` DataTable { - `; + `, }; -export const Playground = (args) => { - const { isSortable, locale, radio, size, useStaticWidth, useZebraStyles } = - args?.[`${prefix}-table`] ?? {}; - return html` +export const Playground = { + args: defaultArgs, + argTypes: controls, + render: ({ + isSortable, + locale, + radio, + size, + useStaticWidth, + useZebraStyles, + }) => html` { - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-table`]: () => ({ - isSortable: boolean('Is sortable', false), - locale: text('Locale', 'en'), - size: select('Size', sizes, TABLE_SIZE.LG), - useStaticWidth: boolean('Use static width', false), - useZebraStyles: boolean('Use zebra styles', false), - }), - }, + `, }; -export default { +const meta = { title: 'Components/DataTable/Filtering', parameters: { - ...storyDocs.parameters, + docs: { + page: storyDocs, + }, }, }; + +export default meta; diff --git a/packages/carbon-web-components/src/components/data-table/stories/data-table-selection-story.ts b/packages/carbon-web-components/src/components/data-table/stories/data-table-selection.stories.ts similarity index 92% rename from packages/carbon-web-components/src/components/data-table/stories/data-table-selection-story.ts rename to packages/carbon-web-components/src/components/data-table/stories/data-table-selection.stories.ts index 36c02492773..4062c614732 100644 --- a/packages/carbon-web-components/src/components/data-table/stories/data-table-selection-story.ts +++ b/packages/carbon-web-components/src/components/data-table/stories/data-table-selection.stories.ts @@ -8,11 +8,9 @@ */ import { html } from 'lit'; -import { boolean, select, text } from '@storybook/addon-knobs'; -import { prefix } from '../../../globals/settings'; import { TABLE_SIZE } from '../table'; import '../index'; -import storyDocs from './data-table-story.mdx'; +import storyDocs from './data-table.mdx'; const sizes = { [`xs (${TABLE_SIZE.XS})`]: TABLE_SIZE.XS, @@ -22,8 +20,45 @@ const sizes = { [`xl (${TABLE_SIZE.XL})`]: TABLE_SIZE.XL, }; -export const Default = () => { - return html` +const defaultArgs = { + isSortable: false, + locale: 'en', + radio: false, + size: TABLE_SIZE.LG, + useStaticWidth: false, + useZebraStyles: false, +}; + +const controls = { + isSortable: { + control: 'boolean', + description: 'Is sortable', + }, + locale: { + control: 'text', + description: 'Locale', + }, + radio: { + control: 'boolean', + description: 'Radio', + }, + size: { + control: 'radio', + description: 'Size', + options: sizes, + }, + useStaticWidth: { + control: 'boolean', + description: 'Use static width', + }, + useZebraStyles: { + control: 'boolean', + description: 'Use zebra styles', + }, +}; + +export const Default = { + render: () => html` DataTable { - `; + `, }; -export const WithRadioSelection = () => { - return html` - +export const WithRadioSelection = { + render: () => html` + DataTable With selection { - `; + `, }; -export const WithSelectionAndSorting = () => { - return html` +export const WithSelectionAndSorting = { + render: () => html` DataTable { - `; + `, }; -export const Playground = (args) => { - const { isSortable, locale, radio, size, useStaticWidth, useZebraStyles } = - args?.[`${prefix}-table`] ?? {}; - return html` +export const Playground = { + args: defaultArgs, + argTypes: controls, + render: ({ + isSortable, + locale, + radio, + size, + useStaticWidth, + useZebraStyles, + }) => html` { - `; + `, }; -Playground.parameters = { - knobs: { - [`${prefix}-table`]: () => ({ - isSortable: boolean('Is sortable', false), - locale: text('Locale', 'en'), - radio: boolean('Radio', false), - size: select('Size', sizes, TABLE_SIZE.LG), - useStaticWidth: boolean('Use static width', false), - useZebraStyles: boolean('Use zebra styles', false), - }), - }, -}; - -export default { +const meta = { title: 'Components/DataTable/Selection', parameters: { - ...storyDocs.parameters, + docs: { + page: storyDocs, + }, }, }; + +export default meta; diff --git a/packages/carbon-web-components/src/components/data-table/stories/data-table-skeleton-story.ts b/packages/carbon-web-components/src/components/data-table/stories/data-table-skeleton-story.ts deleted file mode 100644 index 883e3770f66..00000000000 --- a/packages/carbon-web-components/src/components/data-table/stories/data-table-skeleton-story.ts +++ /dev/null @@ -1,63 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { boolean, number } from '@storybook/addon-knobs'; -import { prefix } from '../../../globals/settings'; -import storyDocs from './data-table-story.mdx'; -import '../index'; - -const headers = [ - 'Name', - 'Protocol', - 'Port', - 'Rule', - 'Attached groups', - 'Status', -]; - -export const Default = () => { - return html` `; -}; - -export const Playground = (args) => { - const { columnCount, rowCount, showHeader, showToolbar, zebra } = - args?.[`${prefix}-table`] ?? {}; - - return html` - - - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-table`]: () => ({ - compact: boolean('Compact', false), - columnCount: number('Column count', 5), - rowCount: number('Row count', 5), - showHeader: boolean('Show header', true), - showToolbar: boolean('Show toolbar', true), - zebra: boolean('Use zebra styles', false), - }), - }, -}; - -export default { - title: 'Components/DataTable/Skeleton', - parameters: { - ...storyDocs.parameters, - }, -}; diff --git a/packages/carbon-web-components/src/components/data-table/stories/data-table-skeleton.stories.ts b/packages/carbon-web-components/src/components/data-table/stories/data-table-skeleton.stories.ts new file mode 100644 index 00000000000..20a9bc1e80b --- /dev/null +++ b/packages/carbon-web-components/src/components/data-table/stories/data-table-skeleton.stories.ts @@ -0,0 +1,88 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2023 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import storyDocs from './data-table.mdx'; +import '../index'; + +const headers = [ + 'Name', + 'Protocol', + 'Port', + 'Rule', + 'Attached groups', + 'Status', +]; + +const defaultArgs = { + compact: false, + columnCount: 5, + rowCount: 5, + showHeader: true, + showToolbar: true, + zebra: false, +}; + +const controls = { + compact: { + control: 'boolean', + description: 'Compact', + }, + columnCount: { + control: 'number', + description: 'Column count', + }, + rowCount: { + control: 'number', + description: 'Row count', + }, + showHeader: { + control: 'boolean', + description: 'Show header', + }, + showToolbar: { + control: 'boolean', + description: 'Show toolbar', + }, + zebra: { + control: 'boolean', + description: 'Use zebra styles', + }, +}; + +export const Default = { + render: () => + html` `, +}; + +export const Playground = { + args: defaultArgs, + argTypes: controls, + render: ({ columnCount, rowCount, showHeader, showToolbar, zebra }) => html` + + + `, +}; + +const meta = { + title: 'Components/DataTable/Skeleton', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/data-table/stories/data-table-sorting-story.ts b/packages/carbon-web-components/src/components/data-table/stories/data-table-sorting.stories.ts similarity index 88% rename from packages/carbon-web-components/src/components/data-table/stories/data-table-sorting-story.ts rename to packages/carbon-web-components/src/components/data-table/stories/data-table-sorting.stories.ts index b3bd7172c12..2f7bb9d1cd4 100644 --- a/packages/carbon-web-components/src/components/data-table/stories/data-table-sorting-story.ts +++ b/packages/carbon-web-components/src/components/data-table/stories/data-table-sorting.stories.ts @@ -8,11 +8,9 @@ */ import { html } from 'lit'; -import { boolean, select, text } from '@storybook/addon-knobs'; -import { prefix } from '../../../globals/settings'; import { TABLE_SIZE } from '../table'; import '../index'; -import storyDocs from './data-table-story.mdx'; +import storyDocs from './data-table.mdx'; const sizes = { [`xs (${TABLE_SIZE.XS})`]: TABLE_SIZE.XS, @@ -22,8 +20,40 @@ const sizes = { [`xl (${TABLE_SIZE.XL})`]: TABLE_SIZE.XL, }; -export const Default = () => { - return html` +const defaultArgs = { + isSortable: true, + locale: 'en', + size: TABLE_SIZE.LG, + useStaticWidth: false, + useZebraStyles: false, +}; + +const controls = { + isSortable: { + control: 'boolean', + description: 'Is sortable', + }, + locale: { + control: 'text', + description: 'Locale', + }, + size: { + control: 'radio', + description: 'Size', + options: sizes, + }, + useStaticWidth: { + control: 'boolean', + description: 'Use static width', + }, + useZebraStyles: { + control: 'boolean', + description: 'Use zebra styles', + }, +}; + +export const Default = { + render: () => html` DataTable { - `; + `, }; -export const Playground = (args) => { - const { isSortable, locale, size, useStaticWidth, useZebraStyles } = - args?.[`${prefix}-table`] ?? {}; - return html` +export const Playground = { + args: defaultArgs, + argTypes: controls, + render: ({ + isSortable, + locale, + size, + useStaticWidth, + useZebraStyles, + }) => html` { - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-table`]: () => ({ - isSortable: boolean('Is sortable', true), - locale: text('Locale', 'en'), - size: select('Size', sizes, TABLE_SIZE.LG), - useStaticWidth: boolean('Use static width', false), - useZebraStyles: boolean('Use zebra styles', false), - }), - }, + `, }; -export default { +const meta = { title: 'Components/DataTable/Sorting', parameters: { - ...storyDocs.parameters, + docs: { + page: storyDocs, + }, }, }; + +export default meta; diff --git a/packages/carbon-web-components/src/components/data-table/stories/data-table-toolbar-story.ts b/packages/carbon-web-components/src/components/data-table/stories/data-table-toolbar.stories.ts similarity index 81% rename from packages/carbon-web-components/src/components/data-table/stories/data-table-toolbar-story.ts rename to packages/carbon-web-components/src/components/data-table/stories/data-table-toolbar.stories.ts index d5808e46f68..9992561f5dc 100644 --- a/packages/carbon-web-components/src/components/data-table/stories/data-table-toolbar-story.ts +++ b/packages/carbon-web-components/src/components/data-table/stories/data-table-toolbar.stories.ts @@ -8,13 +8,12 @@ */ import { html } from 'lit'; -import { boolean, select, text } from '@storybook/addon-knobs'; import { prefix } from '../../../globals/settings'; import { TABLE_SIZE } from '../table'; import Settings16 from '@carbon/web-components/es/icons/settings/16'; import OverflowMenuVertical16 from '@carbon/icons/lib/overflow-menu--vertical/16'; +import storyDocs from './data-table.mdx'; import '../index'; -import storyDocs from './data-table-story.mdx'; const sizes = { [`xs (${TABLE_SIZE.XS})`]: TABLE_SIZE.XS, @@ -24,109 +23,153 @@ const sizes = { [`xl (${TABLE_SIZE.XL})`]: TABLE_SIZE.XL, }; -export const Default = () => { - return html` - - DataTable - With toolbar +const defaultArgs = { + isSortable: false, + locale: 'en', + overflowMenuOnHover: false, + radio: false, + size: TABLE_SIZE.LG, + useStaticWidth: false, + useZebraStyles: false, +}; - - - - - ${Settings16({ - slot: 'icon', - class: `${prefix}--overflow-menu__icon`, - })} - - alert('Alert 1')}> - Action 1 - - alert('Alert 2')}> - Action 2 - - alert('Alert 3')}> - Action 3 - - - - Primary button - - +const controls = { + isSortable: { + control: 'boolean', + description: 'Is sortable', + }, + locale: { + control: 'text', + description: 'Locale', + }, + overflowMenuOnHover: { + control: 'boolean', + description: 'Overflow menu on hover', + }, + radio: { + control: 'boolean', + description: 'Radio', + }, + size: { + control: 'select', + description: 'Size', + options: sizes, + }, + useStaticWidth: { + control: 'boolean', + description: 'Use static width', + }, + useZebraStyles: { + control: 'boolean', + description: 'Use zebra styles', + }, +}; - - - Name - Protocol - Port - Rule - Attached groups - Status - - - - - Load Balancer 3 - HTTP - 3000 - Round robin - Kevin's VM Groups - Disabled - - - Load Balancer 1 - HTTP - 443 - Round robin - Maureen's VM Groups - Starting - - - Load Balancer 2 - HTTP - 80 - DNS delegation - Andrew's VM Groups - Active - - - Load Balancer 6 - HTTP - 3000 - Round robin - Marc's VM Groups - Disabled - - - Load Balancer 4 - HTTP - 443 - Round robin - Mel's VM Groups - Starting - - - Load Balancer 5 - HTTP - 80 - DNS delegation - Ronja's VM Groups - Active - - - - `; +export const Default = { + render: () => { + return html` + + DataTable + With toolbar + + + + + + ${Settings16({ + slot: 'icon', + class: `${prefix}--overflow-menu__icon`, + })} + + alert('Alert 1')}> + Action 1 + + alert('Alert 2')}> + Action 2 + + alert('Alert 3')}> + Action 3 + + + + Primary button + + + + + + Name + Protocol + Port + Rule + Attached groups + Status + + + + + Load Balancer 3 + HTTP + 3000 + Round robin + Kevin's VM Groups + Disabled + + + Load Balancer 1 + HTTP + 443 + Round robin + Maureen's VM Groups + Starting + + + Load Balancer 2 + HTTP + 80 + DNS delegation + Andrew's VM Groups + Active + + + Load Balancer 6 + HTTP + 3000 + Round robin + Marc's VM Groups + Disabled + + + Load Balancer 4 + HTTP + 443 + Round robin + Mel's VM Groups + Starting + + + Load Balancer 5 + HTTP + 80 + DNS delegation + Ronja's VM Groups + Active + + + + `; + }, }; -export const PersistentToolbar = () => { - return html` +export const PersistentToolbar = { + render: () => html` DataTable { - `; + `, }; -export const SmallPersistentToolbar = () => { - return html` +export const SmallPersistentToolbar = { + render: () => html` DataTable { - `; + `, }; -export const WithOverflowMenu = () => { - return html` +export const WithOverflowMenu = { + render: () => html` DataTable { - `; + `, }; -export const Playground = (args) => { - const { +export const Playground = { + args: defaultArgs, + argTypes: controls, + + render: ({ isSortable, locale, radio, @@ -506,8 +552,7 @@ export const Playground = (args) => { size, useStaticWidth, useZebraStyles, - } = args?.[`${prefix}-table`] ?? {}; - return html` + }) => html` { - `; + `, }; -Playground.parameters = { - knobs: { - [`${prefix}-table`]: () => ({ - isSortable: boolean('Is sortable', false), - locale: text('Locale', 'en'), - overflowMenuOnHover: boolean('Overflow menu on hover', false), - radio: boolean('Radio', false), - size: select('Size', sizes, TABLE_SIZE.LG), - useStaticWidth: boolean('Use static width', false), - useZebraStyles: boolean('Use zebra styles', false), - }), - }, -}; - -export default { +const meta = { title: 'Components/DataTable/Toolbar', parameters: { - ...storyDocs.parameters, + docs: { + page: storyDocs, + }, }, }; + +export default meta; diff --git a/packages/carbon-web-components/src/components/data-table/stories/data-table-story.mdx b/packages/carbon-web-components/src/components/data-table/stories/data-table.mdx similarity index 96% rename from packages/carbon-web-components/src/components/data-table/stories/data-table-story.mdx rename to packages/carbon-web-components/src/components/data-table/stories/data-table.mdx index 1081f4df8c5..72703f2b98c 100644 --- a/packages/carbon-web-components/src/components/data-table/stories/data-table-story.mdx +++ b/packages/carbon-web-components/src/components/data-table/stories/data-table.mdx @@ -1,4 +1,4 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Markdown } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../../globals/internal/storybook-cdn'; # Data table @@ -51,8 +51,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/data-table/index.js'; ``` - - +{`${cdnJs({ components: ['data-table'] })}`} +{`${cdnCss()}`} ### HTML @@ -562,48 +562,48 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ### `` - + ### `` - + ### `` - + ### `` - + ### `` - + ### `` - + ### ` + ### `` - + ### `` - + ### `` - + ### `` - + ### `cds-table-skeleton` - + diff --git a/packages/carbon-web-components/src/components/data-table/table-cell-content.ts b/packages/carbon-web-components/src/components/data-table/table-cell-content.ts index b1111e0ecf7..55facd1cdeb 100644 --- a/packages/carbon-web-components/src/components/data-table/table-cell-content.ts +++ b/packages/carbon-web-components/src/components/data-table/table-cell-content.ts @@ -1,14 +1,14 @@ /** * @license * - * Copyright IBM Corp. 2019, 2023 + * Copyright IBM Corp. 2019, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ import { LitElement, html } from 'lit'; -import { customElement } from 'lit/decorators.js'; +import { carbonElement as customElement } from '../../globals/decorators/carbon-element'; import { prefix } from '../../globals/settings'; import styles from './data-table.scss?lit'; diff --git a/packages/carbon-web-components/src/components/data-table/table-row.ts b/packages/carbon-web-components/src/components/data-table/table-row.ts index 38c8c676131..d30a2225542 100644 --- a/packages/carbon-web-components/src/components/data-table/table-row.ts +++ b/packages/carbon-web-components/src/components/data-table/table-row.ts @@ -19,6 +19,8 @@ import HostListener from '../../globals/decorators/host-listener'; import HostListenerMixin from '../../globals/mixins/host-listener'; import CDSTableExpandedRow from './table-expanded-row'; import CDSTableCell from './table-cell'; +import '../checkbox'; +import '../radio-button'; /** * Data table row. diff --git a/packages/carbon-web-components/src/components/date-picker/date-picker-story.ts b/packages/carbon-web-components/src/components/date-picker/date-picker-story.ts deleted file mode 100644 index 31c8458788a..00000000000 --- a/packages/carbon-web-components/src/components/date-picker/date-picker-story.ts +++ /dev/null @@ -1,283 +0,0 @@ -/** - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { action } from '@storybook/addon-actions'; -import { boolean, select } from '@storybook/addon-knobs'; -import { prefix } from '../../globals/settings'; -import textNullable from '../../../.storybook/knob-text-nullable'; -import { INPUT_SIZE } from '../text-input/text-input'; -import './date-picker'; -import storyDocs from './date-picker-story.mdx'; -import './date-picker-input-skeleton'; -import '../layer/index'; - -const sizes = { - [`Small (${INPUT_SIZE.SMALL})`]: INPUT_SIZE.SMALL, - [`Medium (${INPUT_SIZE.MEDIUM})`]: INPUT_SIZE.MEDIUM, - [`Large (${INPUT_SIZE.LARGE})`]: INPUT_SIZE.LARGE, -}; - -const knobs = { - [`${prefix}-date-picker`]: () => ({ - dateFormat: textNullable('Date format (date-format)', 'm/d/Y'), - disabled: boolean('Disabled (disabled)', false), - allowInput: boolean('Allow input (allow-input)', true), - closeOnSelect: boolean('Close on select (close-on-select)', true), - minDate: textNullable('Minimum date in ISO8601 date format (min-date)', ''), - maxDate: textNullable('Maximum date in ISO8601 date format (max-date)', ''), - onChange: action(`${prefix}-date-picker-changed`), - }), - [`${prefix}-date-picker-input`]: () => ({ - datePickerType: select( - 'Date picker type (date-picker-type)', - { Single: 'single', Simple: 'simple', Range: 'range' }, - 'single' - ), - readonly: boolean('ReadOnly (readonly)', false), - short: boolean('Short (short)', false), - helperText: textNullable('Helper text (helper-text)', ''), - warning: boolean('Warning (warning)', false), - warningText: textNullable('Warning text (warning-text)', ''), - invalid: boolean('Invalid (invalid)', false), - invalidText: textNullable('Invalid text (invalid-text)', ''), - placeholder: textNullable('Placeholder text (placeholder)', 'mm/dd/yyyy'), - size: select('Size (size)', sizes, INPUT_SIZE.MEDIUM), - onInput: action('input'), - }), -}; -export const Simple = () => { - return html` - - - - - `; -}; - -export const SimpleWithLayer = () => { - return html` - - - - - - `; -}; - -export const singleWithCalendar = () => { - return html` - - - - - `; -}; - -singleWithCalendar.storyName = 'Single with calendar'; - -export const singleWithCalendarWithLayer = () => { - return html` - - - - - - - `; -}; - -singleWithCalendarWithLayer.storyName = 'Single with calendar with layer'; - -export const rangeWithCalendar = () => { - return html` - - - - - - - `; -}; - -rangeWithCalendar.storyName = 'Range with calendar'; - -export const rangeWithCalendarWithLayer = () => { - return html` - - - - - - - - - - - - - - - - - - - - - - - - - `; -}; - -rangeWithCalendarWithLayer.storyName = 'Range with calendar with layer'; - -export const Skeleton = () => - html` - - - `; - -Skeleton.storyName = 'Skeleton'; - -Skeleton.decorators = [(story) => html`
${story()}
`]; - -Skeleton.parameters = { - percy: { - skip: true, - }, -}; - -export const Playground = (args) => { - const { disabled, dateFormat, onChange, minDate, maxDate } = - args?.['cds-date-picker'] || {}; - const { - size, - helperText, - placeholder, - invalid, - invalidText, - warning, - warningText, - short, - datePickerType, - readonly, - onInput, - } = args?.['cds-date-picker-input'] || {}; - - return html` - - ${datePickerType === 'range' - ? html` - - ${helperText - ? html`${helperText}` - : html``} - - - ${helperText - ? html`${helperText}` - : html``} - - ` - : html` - - ${helperText - ? html`${helperText}` - : html``} - - `} - - `; -}; - -Playground.storyName = 'Playground'; - -Playground.decorators = [(story) => html`
${story()}
`]; - -Playground.parameters = { - knobs, -}; - -export default { - title: 'Components/Date picker', - parameters: { - ...storyDocs.parameters, - }, -}; diff --git a/packages/carbon-web-components/src/components/date-picker/date-picker-story.mdx b/packages/carbon-web-components/src/components/date-picker/date-picker.mdx similarity index 92% rename from packages/carbon-web-components/src/components/date-picker/date-picker-story.mdx rename to packages/carbon-web-components/src/components/date-picker/date-picker.mdx index fd0054b3227..b3ff2cb3736 100644 --- a/packages/carbon-web-components/src/components/date-picker/date-picker-story.mdx +++ b/packages/carbon-web-components/src/components/date-picker/date-picker.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Description } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as DatePickerStories from './date-picker.stories'; + + # Date picker @@ -102,7 +105,7 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `open` attribute). - + ## `` attributes and properties @@ -110,4 +113,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `light` attribute). - + diff --git a/packages/carbon-web-components/src/components/date-picker/date-picker.stories.ts b/packages/carbon-web-components/src/components/date-picker/date-picker.stories.ts new file mode 100644 index 00000000000..bdcbcd46552 --- /dev/null +++ b/packages/carbon-web-components/src/components/date-picker/date-picker.stories.ts @@ -0,0 +1,352 @@ +/** + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { prefix } from '../../globals/settings'; +import { INPUT_SIZE } from '../text-input/text-input'; +import './date-picker'; +import './date-picker-input-skeleton'; +import '../layer/index'; +import '../../../.storybook/templates/with-layer'; + +const sizes = { + [`Small (${INPUT_SIZE.SMALL})`]: INPUT_SIZE.SMALL, + [`Medium (${INPUT_SIZE.MEDIUM})`]: INPUT_SIZE.MEDIUM, + [`Large (${INPUT_SIZE.LARGE})`]: INPUT_SIZE.LARGE, +}; + +const defaultArgs = { + dateFormat: 'm/d/Y', + disabled: false, + allowInput: true, + closeOnSelect: true, + minDate: '', + maxDate: '', + datePickerType: 'single', + readonly: false, + short: false, + helperText: '', + warning: false, + warningText: '', + invalid: false, + invalidText: '', + placeholder: 'mm/dd/yyyy', + size: INPUT_SIZE.MEDIUM, +}; + +const argTypes = { + allowInput: { + control: 'boolean', + description: + 'Flatpickr prop passthrough enables direct date input, and when set to false, we must clear dates manually by resetting the value prop to empty string making it a controlled input.', + }, + closeOnSelect: { + control: 'boolean', + description: + 'Flatpickr prop passthrough. Controls whether the calendar dropdown closes upon selection.', + }, + dateFormat: { + control: 'text', + description: 'The date format.', + }, + datePickerType: { + control: 'radio', + options: { Single: 'single', Simple: 'simple', Range: 'range' }, + description: `The type of the date picker: +
    +
  • simple +
    • Without calendar dropdown.
    +
  • +
  • single +
    • With calendar dropdown and single date.
    +
  • +
  • range +
    • With calendar dropdown and a date range.
    +
  • +
`, + }, + disabled: { control: 'boolean' }, + helperText: { control: 'text' }, + invalid: { + control: 'boolean', + description: 'Specify whether or not the control is invalid (Fluid only).', + }, + invalidText: { + control: 'text', + description: + 'Provide the text that is displayed when the control is in error state (Fluid Only).', + }, + maxDate: { + control: 'text', + description: 'The maximum date that a user can pick to.', + }, + minDate: { + control: 'text', + description: 'The minimum date that a user can start picking from.', + }, + placeholder: { control: 'text' }, + readonly: { + control: 'boolean', + description: + 'Whether the DatePicker is to be readOnly if boolean applies to all inputs if array applies to each input in order.', + }, + short: { + control: 'boolean', + description: 'true to use the short version.', + }, + size: { control: 'select', options: sizes }, + warning: { + control: 'boolean', + description: + 'Specify whether the control is currently in warning state (Fluid only).', + }, + warningText: { + control: 'text', + description: + 'Provide the text that is displayed when the control is in warning state (Fluid only).', + }, + onChange: { + action: `${prefix}-date-picker-changed`, + }, + onInput: { + action: 'input', + }, +}; + +export const Simple = { + render: () => { + return html` + + + + + `; + }, +}; + +export const SimpleWithLayer = { + render: () => { + return html` + + + + + + `; + }, +}; + +export const SingleWithCalendar = { + render: () => { + return html` + + + + + `; + }, +}; + +export const SingleWithCalendarWithLayer = { + render: () => { + return html` + + + + + + + `; + }, +}; + +export const RangeWithCalendar = { + render: () => { + return html` + + + + + + + `; + }, +}; + +export const RangeWithCalendarWithLayer = { + render: () => { + return html` + + + + + + + + + + + + + + + + + + + + + + + + + `; + }, +}; + +export const Skeleton = { + render: () => + html` + + + `, + decorators: [(story) => html`
${story()}
`], + parameters: { + percy: { + skip: true, + }, + }, +}; + +export const Playground = { + decorators: [(story) => html`
${story()}
`], + argTypes, + args: defaultArgs, + render: (args) => { + const { + disabled, + dateFormat, + onChange, + minDate, + maxDate, + size, + helperText, + placeholder, + invalid, + invalidText, + warning, + warningText, + short, + datePickerType, + readonly, + onInput, + } = args || {}; + + return html` + + ${datePickerType === 'range' + ? html` + + ${helperText + ? html`${helperText}` + : html``} + + + ${helperText + ? html`${helperText}` + : html``} + + ` + : html` + + ${helperText + ? html`${helperText}` + : html``} + + `} + + `; + }, +}; + +const meta = { + title: 'Components/Date picker', +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/dropdown/dropdown-story.mdx b/packages/carbon-web-components/src/components/dropdown/dropdown.mdx similarity index 88% rename from packages/carbon-web-components/src/components/dropdown/dropdown-story.mdx rename to packages/carbon-web-components/src/components/dropdown/dropdown.mdx index 850bf26eb79..21b362ca8e2 100644 --- a/packages/carbon-web-components/src/components/dropdown/dropdown-story.mdx +++ b/packages/carbon-web-components/src/components/dropdown/dropdown.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Markdown, Meta } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as DropdownStories from './dropdown.stories'; + + # Dropdown @@ -22,8 +25,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/dropdown/index.js'; ``` - - +{`${cdnJs({ components: ['dropdown'] })}`} +{`${cdnCss()}`} ### HTML @@ -75,7 +78,7 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `open` attribute). - + ## `` attributes and properties @@ -83,4 +86,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `disabled` attribute). - + diff --git a/packages/carbon-web-components/src/components/dropdown/dropdown-story.ts b/packages/carbon-web-components/src/components/dropdown/dropdown.stories.ts similarity index 61% rename from packages/carbon-web-components/src/components/dropdown/dropdown-story.ts rename to packages/carbon-web-components/src/components/dropdown/dropdown.stories.ts index b02a7dbb52d..049ce8e9d0b 100644 --- a/packages/carbon-web-components/src/components/dropdown/dropdown-story.ts +++ b/packages/carbon-web-components/src/components/dropdown/dropdown.stories.ts @@ -8,14 +8,11 @@ */ import { html } from 'lit'; -import { boolean, select } from '@storybook/addon-knobs'; -import { prefix } from '../../globals/settings'; -import textNullable from '../../../.storybook/knob-text-nullable'; import { ifDefined } from 'lit/directives/if-defined.js'; import { DROPDOWN_DIRECTION, DROPDOWN_SIZE, DROPDOWN_TYPE } from './dropdown'; import './dropdown-item'; import './dropdown-skeleton'; -import storyDocs from './dropdown-story.mdx'; +import storyDocs from './dropdown.mdx'; const directionOptions = { [`Top`]: DROPDOWN_DIRECTION.TOP, @@ -61,8 +58,89 @@ const items = [ }, ]; -export const Default = () => { - return html` +const defaultArgs = { + direction: DROPDOWN_DIRECTION.BOTTOM, + disabled: false, + hideLabel: false, + helperText: 'This is some helper text', + invalid: false, + invalidText: 'invalid selection', + label: 'This is an example label', + open: false, + readOnly: false, + size: null, + titleText: 'This is an example title', + type: null, + value: '', + warn: false, + warnText: 'please notice the warning', +} + +const controls = { + disabled: { + control: 'boolean', + description: `Specify if the dropdown should be disabled, or not.`, + }, + direction: { + control: 'select', options: directionOptions, + description: `Dropdown direction.` + }, + hideLabel: { + control: 'boolean', + description: `Specify if the title text should be hidden, or not.`, + }, + helperText: { + control: 'text', + description: `The helper text for the dropdown.`, + }, + invalid: { + control: 'boolean', + description: `Specify if the dropdown should display an invalid icon, or not.`, + }, + invalidText: { + control: 'text', + description: `Message which is displayed if the value is invalid.`, + }, + label: { + control: 'text', + description: `The default content of the trigger button.`, + }, + open: { + control: 'boolean', + description: `Specify if the dropdown should be open, or not.`, + }, + readOnly: { + control: 'boolean', + description: `Specify if the dropdown should be read only, or not.`, + }, + size: { + control: 'select', options: sizes, + description: `Dropdown size.` + }, + titleText: { + control: 'text', + description: `Text that will be read by a screen reader when visiting this control.`, + }, + type: { + control: 'select', options: types, + description: `Dropdown size.` + }, + value: { + control: 'text', + description: `The value of the selected item.`, + }, + warn: { + control: 'boolean', + description: `Specify whether the control is currently in warning state.`, + }, + warnText: { + control: 'text', + description: `Text that is displayed when the control is in warning state.`, + }, +}; + +export const Default = { + render: () => html` { ` )} - `; + ` }; -export const Inline = () => { - return html` +export const Inline = { + render: () => html` { ` )} - `; + ` }; -export const InlineWithLayer = () => { - return html` +export const InlineWithLayer = { + render: () => html`
{
- `; + ` }; -export const WithLayer = () => { - return html` +export const WithLayer = { + render: () => html`
{
- `; + ` }; -export const Playground = (args) => { - const { +export const Playground = { + argTypes: controls, + args: defaultArgs, + render: ({ open, direction, disabled, @@ -158,9 +238,8 @@ export const Playground = (args) => { label, warn, warnText, - } = args?.[`${prefix}-dropdown`] ?? {}; - - return html` + }) => + html` { ` )} - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-dropdown`]: () => ({ - open: boolean('Open (open)', false), - direction: select('Direction', directionOptions, null), - disabled: boolean('Disabled (disabled)', false), - helperText: textNullable( - 'Helper text (helper-text)', - 'This is some helper text' - ), - hideLabel: boolean('Hide label (hide-label)', false), - invalid: boolean('Invalid (invalid)', false), - invalidText: textNullable( - 'Invalid text (invalid-text)', - 'invalid selection' - ), - readOnly: boolean('Read only (read-only)', false), - label: textNullable( - 'The default content of the trigger button (label)', - 'This is an example label' - ), - titleText: textNullable( - 'Title text (title-text)', - 'This is an example title' - ), - size: select('Dropdown size (size)', sizes, null), - type: select('Dropdown type (type)', types, null), - value: textNullable('Selected value (value)', ''), - warn: boolean('Warn (warn)', false), - warnText: textNullable( - 'Warn text (warn-text)', - 'please notice the warning' - ), - }), - }, + ` }; -export const skeleton = () => - html` `; - -skeleton.parameters = { - percy: { - skip: true, +export const Skeleton = { + parameters: { + percy: { + skip: true, + }, }, -}; + render: () => html` ` +} -export default { +const meta = { title: 'Components/Dropdown', - parameters: { - ...storyDocs.parameters, - }, decorators: [ (story, { name }) => { const width = !name.toLowerCase().includes('layer') ? `width:400px` : ``; return html`
${story()}
`; }, ], + parameters: { + docs: { + page: storyDocs, + }, + }, }; + +export default meta; diff --git a/packages/carbon-web-components/src/components/file-uploader/file-uploader.mdx b/packages/carbon-web-components/src/components/file-uploader/file-uploader.mdx index ec698c2ca0e..6f5ec6f5266 100644 --- a/packages/carbon-web-components/src/components/file-uploader/file-uploader.mdx +++ b/packages/carbon-web-components/src/components/file-uploader/file-uploader.mdx @@ -1,4 +1,4 @@ -import { ArgsTable, Meta, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Markdown, Meta } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; import * as FileUploaderStories from './file-uploader.stories'; @@ -25,8 +25,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/file-uploader/index.js'; ``` - - +{`${cdnJs({ components: ['file-uploader'] })}`} +{`${cdnCss()}`} ### HTML diff --git a/packages/carbon-web-components/src/components/form-group/form-group-story.ts b/packages/carbon-web-components/src/components/form-group/form-group-story.ts deleted file mode 100644 index 755e78b98ea..00000000000 --- a/packages/carbon-web-components/src/components/form-group/form-group-story.ts +++ /dev/null @@ -1,104 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { boolean } from '@storybook/addon-knobs'; -import { prefix } from '../../globals/settings'; -import textNullable from '../../../.storybook/knob-text-nullable'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import './form-group'; -import '../text-input'; -import '../stack'; -import '../radio-button/index'; -import '../button'; -import storyDocs from './form-group-story.mdx'; - -export const Default = () => { - return html` - - - - - - - - - - Submit - - - `; -}; - -export const Playground = (args) => { - const { legendText, message, messageText } = args?.['cds-form-group'] ?? {}; - return html` - - - - - - - - - - Submit - - - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-form-group`]: () => ({ - legendText: textNullable('Legend Text (legend-text)', 'FormGroup Legend'), - message: boolean('message', false), - messageText: textNullable('Message Text (message-text)', ''), - }), - }, -}; - -export default { - title: 'Components/Form Group', - parameters: { - ...storyDocs.parameters, - }, - decorators: [ - (story) => { - return html`
${story()}
`; - }, - ], -}; diff --git a/packages/carbon-web-components/src/components/form-group/form-group-story.mdx b/packages/carbon-web-components/src/components/form-group/form-group.mdx similarity index 85% rename from packages/carbon-web-components/src/components/form-group/form-group-story.mdx rename to packages/carbon-web-components/src/components/form-group/form-group.mdx index ea4f49c9244..a8413e132d9 100644 --- a/packages/carbon-web-components/src/components/form-group/form-group-story.mdx +++ b/packages/carbon-web-components/src/components/form-group/form-group.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Markdown } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as FormGroupStories from './form-group.stories'; + + # Form Group @@ -19,8 +22,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/form-group/index.js'; ``` - - +{`${cdnJs({ components: ['form-group'] })}`} +{`${cdnCss()}`} ### HTML @@ -57,4 +60,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `message` attribute). - + diff --git a/packages/carbon-web-components/src/components/form-group/form-group.stories.ts b/packages/carbon-web-components/src/components/form-group/form-group.stories.ts new file mode 100644 index 00000000000..938c183ca8e --- /dev/null +++ b/packages/carbon-web-components/src/components/form-group/form-group.stories.ts @@ -0,0 +1,122 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { ifDefined } from 'lit/directives/if-defined.js'; +import './form-group'; +import '../text-input'; +import '../stack'; +import '../radio-button/index'; +import '../button'; +import storyDocs from './form-group.mdx'; + +const args = { + legendText: 'FormGroup Legend', + message: false, +}; + +const argTypes = { + legendText: { + control: 'text', + description: 'Provide the text to be rendered inside of the fieldset.', + }, + message: { + control: 'boolean', + description: + 'Specify whether the message should be displayed in the form group.', + }, + messageText: { + control: 'text', + description: 'Provide the text for the message in the form group.', + }, +}; + +export const Default = { + render: () => { + return html` + + + + + + + + + + Submit + + + `; + }, +}; + +export const Playground = { + args, + argTypes, + render: (args) => { + const { legendText, message, messageText } = args ?? {}; + return html` + + + + + + + + + + Submit + + + `; + }, +}; + +const meta = { + title: 'Components/Form Group', + parameters: { + docs: { + page: storyDocs, + }, + }, + decorators: [ + (story) => { + return html`
${story()}
`; + }, + ], +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/icon-button/icon-button-story.ts b/packages/carbon-web-components/src/components/icon-button/icon-button-story.ts deleted file mode 100644 index 5cca9e3cdec..00000000000 --- a/packages/carbon-web-components/src/components/icon-button/icon-button-story.ts +++ /dev/null @@ -1,84 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { boolean, select, text, number } from '@storybook/addon-knobs'; -import './index'; -import '../button/index'; -import storyDocs from './icon-button-story.mdx'; -import { ICON_BUTTON_TOOLTIP_ALIGNMENT } from './defs'; -import Edit16 from '@carbon/icons/lib/edit/16'; -import { ICON_BUTTON_SIZE } from './defs'; - -const tooltipAlignments = { - [`top`]: ICON_BUTTON_TOOLTIP_ALIGNMENT.TOP, - [`top-left`]: ICON_BUTTON_TOOLTIP_ALIGNMENT.TOP_LEFT, - [`top-right`]: ICON_BUTTON_TOOLTIP_ALIGNMENT.TOP_RIGHT, - [`bottom`]: ICON_BUTTON_TOOLTIP_ALIGNMENT.BOTTOM, - [`bottom-left`]: ICON_BUTTON_TOOLTIP_ALIGNMENT.BOTTOM_LEFT, - [`bottom-right`]: ICON_BUTTON_TOOLTIP_ALIGNMENT.BOTTOM_RIGHT, - [`left`]: ICON_BUTTON_TOOLTIP_ALIGNMENT.LEFT, - [`right`]: ICON_BUTTON_TOOLTIP_ALIGNMENT.RIGHT, -}; - -export const Default = () => { - return html` - ${Edit16({ slot: 'icon' })} - `; -}; - -export const Playground = (args) => { - const { - alignment, - defaultOpen, - disabled, - tooltipContent, - enterDelay, - leaveDelay, - size, - } = args?.['cds-icon-button']; - return html` - - ${Edit16({ slot: 'icon' })} - ${tooltipContent} - - `; -}; - -Playground.parameters = { - knobs: { - 'cds-icon-button': () => ({ - alignment: select( - 'Tooltip alignment to trigger button (alignment)', - tooltipAlignments, - ICON_BUTTON_TOOLTIP_ALIGNMENT.BOTTOM - ), - defaultOpen: boolean('Default open (defaultOpen)', false), - disabled: boolean('Disabled (disabled)', false), - enterDelay: number('Enter delay (in ms)', 100), - leaveDelay: number('leave delay (in ms)', 300), - tooltipContent: text('tooltip-content', 'Custom label'), - size: select('size', ICON_BUTTON_SIZE, ICON_BUTTON_SIZE.MEDIUM), - }), - }, -}; - -export default { - parameters: { - ...storyDocs.parameters, - }, - title: 'Components/Icon Button', - decorators: [(story) => html`
${story()}
`], -}; diff --git a/packages/carbon-web-components/src/components/icon-button/icon-button-story.mdx b/packages/carbon-web-components/src/components/icon-button/icon-button.mdx similarity index 82% rename from packages/carbon-web-components/src/components/icon-button/icon-button-story.mdx rename to packages/carbon-web-components/src/components/icon-button/icon-button.mdx index 3e38ee00541..041ffc4554b 100644 --- a/packages/carbon-web-components/src/components/icon-button/icon-button-story.mdx +++ b/packages/carbon-web-components/src/components/icon-button/icon-button.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Markdown } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as IconButtonStories from './icon-button.stories'; + + # Icon Button @@ -24,8 +27,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/icon-button/index.js'; ``` - - +{`${cdnJs({ components: ['icon-button'] })}`} +{`${cdnCss()}`} ```javascript import '@carbon/web-components/es/components/icon-button/index.js'; @@ -41,5 +44,4 @@ function App() { ## `` attributes and properties - -```` + diff --git a/packages/carbon-web-components/src/components/icon-button/icon-button.stories.ts b/packages/carbon-web-components/src/components/icon-button/icon-button.stories.ts new file mode 100644 index 00000000000..d34e008d3c3 --- /dev/null +++ b/packages/carbon-web-components/src/components/icon-button/icon-button.stories.ts @@ -0,0 +1,158 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import './index'; +import '../button/index'; +import storyDocs from './icon-button.mdx'; +import { ICON_BUTTON_TOOLTIP_ALIGNMENT } from './defs'; +import Edit16 from '@carbon/icons/lib/edit/16'; +import { ICON_BUTTON_SIZE } from './defs'; +import { BUTTON_KIND } from '../button/defs'; + +const kinds = { + [`Primary button (${BUTTON_KIND.PRIMARY})`]: BUTTON_KIND.PRIMARY, + [`Secondary button (${BUTTON_KIND.SECONDARY})`]: BUTTON_KIND.SECONDARY, + [`Tertiary button (${BUTTON_KIND.TERTIARY})`]: BUTTON_KIND.TERTIARY, + [`Danger button (${BUTTON_KIND.DANGER})`]: BUTTON_KIND.DANGER, + [`Danger tertiary button (${BUTTON_KIND.DANGER_TERTIARY})`]: + BUTTON_KIND.DANGER_TERTIARY, + [`Danger ghost button (${BUTTON_KIND.DANGER_GHOST})`]: + BUTTON_KIND.DANGER_GHOST, + [`Ghost button (${BUTTON_KIND.GHOST})`]: BUTTON_KIND.GHOST, +}; + +const tooltipAlignments = { + [`top`]: ICON_BUTTON_TOOLTIP_ALIGNMENT.TOP, + [`top-left`]: ICON_BUTTON_TOOLTIP_ALIGNMENT.TOP_LEFT, + [`top-right`]: ICON_BUTTON_TOOLTIP_ALIGNMENT.TOP_RIGHT, + [`bottom`]: ICON_BUTTON_TOOLTIP_ALIGNMENT.BOTTOM, + [`bottom-left`]: ICON_BUTTON_TOOLTIP_ALIGNMENT.BOTTOM_LEFT, + [`bottom-right`]: ICON_BUTTON_TOOLTIP_ALIGNMENT.BOTTOM_RIGHT, + [`left`]: ICON_BUTTON_TOOLTIP_ALIGNMENT.LEFT, + [`right`]: ICON_BUTTON_TOOLTIP_ALIGNMENT.RIGHT, +}; + +const args = { + align: ICON_BUTTON_TOOLTIP_ALIGNMENT.BOTTOM, + defaultOpen: true, + disabled: false, + isSelected: false, + kind: BUTTON_KIND.PRIMARY, + label: 'Custom label', + size: ICON_BUTTON_SIZE.MEDIUM, +}; + +const argTypes = { + align: { + control: 'select', + description: 'Specify how the trigger should align with the tooltip.', + options: tooltipAlignments, + }, + closeOnActivation: { + control: 'boolean', + description: + 'Determines whether the tooltip should close when inner content is activated (click, Enter or Space).', + }, + defaultOpen: { + control: 'boolean', + description: + 'Specify whether the tooltip should be open when it first renders.', + }, + disabled: { + control: 'boolean', + description: 'Specify whether the Button should be disabled, or not.', + }, + enterDelayMs: { + control: 'number', + description: + 'Specify the duration in milliseconds to delay before displaying the tooltip.', + }, + isSelected: { + control: 'boolean', + description: 'Specify whether the Icon Button is currently selected.', + }, + kind: { + control: 'select', + description: + 'Specify the type of button to be used as the base for the Icon Button.', + options: kinds, + }, + label: { + control: 'text', + description: + 'Provide the label to be rendered inside of the Tooltip. The label will use aria-labelledby and will fully describe the child node that is provided. This means that if you have text in the child node it will not be announced to the screen reader.', + }, + leaveDelayMs: { + control: 'number', + description: + 'Specify the duration in milliseconds to delay before hiding the tooltip.', + }, + size: { + control: 'select', + description: 'Specify the size of the Button. Defaults to md.', + options: ICON_BUTTON_SIZE, + }, +}; + +export const Default = { + render: () => { + return html` + + ${Edit16({ slot: 'icon' })} + label + + `; + }, +}; + +export const Playground = { + args, + argTypes, + render: ({ + align, + closeOnActivation, + defaultOpen, + disabled, + enterDelayMs, + isSelected, + kind, + label, + leaveDelayMs, + size, + }) => { + return html` + + ${Edit16({ slot: 'icon' })} + ${label} + + `; + }, +}; + +const meta = { + decorators: [(story) => html`
${story()}
`], + title: 'Components/Icon Button', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/icon/icon.stories.ts b/packages/carbon-web-components/src/components/icon/icon.stories.ts index 9271ae03450..663cc49f2cc 100644 --- a/packages/carbon-web-components/src/components/icon/icon.stories.ts +++ b/packages/carbon-web-components/src/components/icon/icon.stories.ts @@ -1,7 +1,7 @@ /** * @license * - * Copyright IBM Corp. 2019, 2023 + * Copyright IBM Corp. 2019, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. @@ -22,58 +22,56 @@ import Add32 from '@carbon/web-components/es/icons/add/32'; import storyDocs from './icon.mdx'; - export const Default = { - render: () => html` ${Add16()} ${Add20()} ${Add24()} ${Add32()} ` -} - + render: () => html` ${Add16()} ${Add20()} ${Add24()} ${Add32()} `, +}; export const withCustomClass = { name: 'With custom class', render: () => html` - - ${Add16({ class: 'test-class' })} ${Add20({ class: 'test-class' })} - ${Add24({ class: 'test-class' })} ${Add32({ class: 'test-class' })} -` -} + + ${Add16({ class: 'test-class' })} ${Add20({ class: 'test-class' })} + ${Add24({ class: 'test-class' })} ${Add32({ class: 'test-class' })} + `, +}; export const withAriaLabel = { name: 'With aria label', render: () => html` - ${Add16({ 'aria-label': 'add' })} ${Add20({ 'aria-label': 'add' })} - ${Add24({ 'aria-label': 'add' })} ${Add32({ 'aria-label': 'add' })} -` -} + ${Add16({ 'aria-label': 'add' })} ${Add20({ 'aria-label': 'add' })} + ${Add24({ 'aria-label': 'add' })} ${Add32({ 'aria-label': 'add' })} + `, +}; -export const withTitle = { +export const withTitle = { name: 'With title', render: () => html` - ${Add16({ - 'aria-describedby': 'id-title-1', - // @ts-ignore - children: svg`add`, - })} - ${Add20({ - 'aria-describedby': 'id-title-2', - // @ts-ignore - children: svg`add`, - })} - ${Add24({ - 'aria-describedby': 'id-title-3', - // @ts-ignore - children: svg`add`, - })} - ${Add32({ - 'aria-describedby': 'id-title-4', - // @ts-ignore - children: svg`add`, - })} -` -} + ${Add16({ + 'aria-describedby': 'id-title-1', + // @ts-ignore + children: svg`add`, + })} + ${Add20({ + 'aria-describedby': 'id-title-2', + // @ts-ignore + children: svg`add`, + })} + ${Add24({ + 'aria-describedby': 'id-title-3', + // @ts-ignore + children: svg`add`, + })} + ${Add32({ + 'aria-describedby': 'id-title-4', + // @ts-ignore + children: svg`add`, + })} + `, +}; const meta = { title: 'Components/Icon', @@ -84,4 +82,4 @@ const meta = { }, }; -export default meta; \ No newline at end of file +export default meta; diff --git a/packages/carbon-web-components/src/components/inline-loading/inline-loading-story.ts b/packages/carbon-web-components/src/components/inline-loading/inline-loading-story.ts deleted file mode 100644 index b1462d93b1f..00000000000 --- a/packages/carbon-web-components/src/components/inline-loading/inline-loading-story.ts +++ /dev/null @@ -1,66 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { select, text } from '@storybook/addon-knobs'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import { INLINE_LOADING_STATE } from './inline-loading'; -import storyDocs from './inline-loading-story.mdx'; -import { prefix } from '../../globals/settings'; - -const states = { - [`Inactive (${INLINE_LOADING_STATE.INACTIVE})`]: - INLINE_LOADING_STATE.INACTIVE, - [`Active (${INLINE_LOADING_STATE.ACTIVE})`]: INLINE_LOADING_STATE.ACTIVE, - [`Finished (${INLINE_LOADING_STATE.FINISHED})`]: - INLINE_LOADING_STATE.FINISHED, - [`Failed (${INLINE_LOADING_STATE.ERROR})`]: INLINE_LOADING_STATE.ERROR, -}; - -export const Default = () => - html`Loading data...`; - -export default { - title: 'Components/Inline loading', - parameters: { ...storyDocs.parameters }, -}; - -export const Playground = (args) => { - const { assistiveText, description, status } = - args?.[`${prefix}-inline-loading`] ?? {}; - return html` - - ${description} - - `; -}; - -Playground.parameters = { - ...storyDocs.parameters, - percy: { skip: true }, - knobs: { - [`${prefix}-inline-loading`]: () => ({ - description: text( - 'Description (description) - Specify the description for the inline loading text', - 'Loading data...' - ), - assistiveText: text( - 'Assistive text (assistive-text) - Specify a description that would be used to best describe the loading state', - 'Loading' - ), - status: select( - 'Loading status (status)', - states, - INLINE_LOADING_STATE.ACTIVE - ), - }), - }, -}; diff --git a/packages/carbon-web-components/src/components/inline-loading/inline-loading-story.mdx b/packages/carbon-web-components/src/components/inline-loading/inline-loading.mdx similarity index 82% rename from packages/carbon-web-components/src/components/inline-loading/inline-loading-story.mdx rename to packages/carbon-web-components/src/components/inline-loading/inline-loading.mdx index f8ba2922167..e15df102c9f 100644 --- a/packages/carbon-web-components/src/components/inline-loading/inline-loading-story.mdx +++ b/packages/carbon-web-components/src/components/inline-loading/inline-loading.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Markdown, Meta } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as InlineLoadingStories from './inline-loading.stories'; + + # Inline loading @@ -30,8 +33,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/inline-loading/index.js'; ``` - - +{`${cdnJs({ components: ['inline-loading'] })}`} +{`${cdnCss()}`} ### HTML @@ -41,4 +44,4 @@ import '@carbon/web-components/es/components/inline-loading/index.js'; ## `` attributes and properties - + diff --git a/packages/carbon-web-components/src/components/inline-loading/inline-loading.stories.ts b/packages/carbon-web-components/src/components/inline-loading/inline-loading.stories.ts new file mode 100644 index 00000000000..b2017dae706 --- /dev/null +++ b/packages/carbon-web-components/src/components/inline-loading/inline-loading.stories.ts @@ -0,0 +1,73 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2023 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { INLINE_LOADING_STATE } from './inline-loading'; +import storyDocs from './inline-loading.mdx'; + +const states = { + [`Inactive (${INLINE_LOADING_STATE.INACTIVE})`]: + INLINE_LOADING_STATE.INACTIVE, + [`Active (${INLINE_LOADING_STATE.ACTIVE})`]: INLINE_LOADING_STATE.ACTIVE, + [`Finished (${INLINE_LOADING_STATE.FINISHED})`]: + INLINE_LOADING_STATE.FINISHED, + [`Failed (${INLINE_LOADING_STATE.ERROR})`]: INLINE_LOADING_STATE.ERROR, +}; + +const defaultArgs = { + description: 'Loading data...', + assistiveText: 'Loading', + status: INLINE_LOADING_STATE.ACTIVE, +}; + +const controls = { + description: { + control: 'text', + description: 'Specify the description for the inline loading text.', + }, + assistiveText: { + control: 'text', + description: + 'Specify a description that would be used to best describe the loading state.', + }, + status: { + control: 'select', + description: 'Specify the loading status.', + options: states, + }, +}; + +export const Default = { + render: () => html`Loading data...`, +}; + +export const Playground = { + args: defaultArgs, + argTypes: controls, + parameters: { + percy: { skip: true }, + }, + render: ({ assistiveText, description, status }) => + html` + + ${description} + + `, +}; + +const meta = { + title: 'Components/Inline loading', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/layer/layer-story.mdx b/packages/carbon-web-components/src/components/layer/layer.mdx similarity index 92% rename from packages/carbon-web-components/src/components/layer/layer-story.mdx rename to packages/carbon-web-components/src/components/layer/layer.mdx index 0a70d3e16e6..1c4bd90815a 100644 --- a/packages/carbon-web-components/src/components/layer/layer-story.mdx +++ b/packages/carbon-web-components/src/components/layer/layer.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Markdown, Meta } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as LayerStories from './layer.stories'; + + # Layer @@ -28,8 +31,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/layer/index.js'; ``` - - +{`${cdnJs({ components: ['layer'] })}`} +{`${cdnCss()}`} ### HTML @@ -108,4 +111,4 @@ like the Layer component to be seen as a section you could write the following: ## `` attributes, properties and events - + diff --git a/packages/carbon-web-components/src/components/layer/layer-story.ts b/packages/carbon-web-components/src/components/layer/layer.stories.ts similarity index 59% rename from packages/carbon-web-components/src/components/layer/layer-story.ts rename to packages/carbon-web-components/src/components/layer/layer.stories.ts index 7bd115c39b1..79ff1580ff1 100644 --- a/packages/carbon-web-components/src/components/layer/layer-story.ts +++ b/packages/carbon-web-components/src/components/layer/layer.stories.ts @@ -8,11 +8,10 @@ */ import { html } from 'lit'; -import { radios } from '@storybook/addon-knobs'; import { prefix } from '../../globals/settings'; -import storyDocs from './layer-story.mdx'; import styles from './layer-story.scss?lit'; -import './index.ts'; +import storyDocs from './layer.mdx'; +import './index'; const levels = { 'First layer': '0', @@ -20,8 +19,19 @@ const levels = { 'Third layer': '2', }; -export const Default = () => { - return html` +const defaultArgs = { + level: '0' +} + +const controls = { + level: { + control: 'radio', options: levels, + description: `Specify the layer level.` + }, +} + +export const Default = { + render: () => html`
Test component
@@ -34,33 +44,32 @@ export const Default = () => { - `; + ` }; -Default.storyName = 'Default'; - -export const CustomLevel = () => { - return html` +export const CustomLevel = { + name: 'Custom level', + render: () => html`
Test component
- `; + ` }; -CustomLevel.storyName = 'Custom level'; +export const UseLayer = { + name: 'useLayer', + render: () => { + document.addEventListener(`${prefix}-use-layer`, (e) => { + const { layer, level } = (e as any).detail; + layer.querySelector( + '.example-layer-test-component.use-layer' + ).innerText = `The current layer level is: ${level + 1}`; + }); -export const UseLayer = () => { - document.addEventListener(`${prefix}-use-layer`, (e) => { - const { layer, level } = (e as any).detail; - layer.querySelector( - '.example-layer-test-component.use-layer' - ).innerText = `The current layer level is: ${level + 1}`; - }); - - return html` + return html`
@@ -70,37 +79,35 @@ export const UseLayer = () => { - `; + ` + } }; -UseLayer.storyName = 'useLayer'; - -export const Playground = (args) => { - const { level } = args?.[`${prefix}-layer-playground`] ?? {}; - return html` +export const Playground = { + args: defaultArgs, + argTypes: controls, + parameters: { + percy: { + skip: true, + }, + }, + render: ({level}) => html`
Test component
- `; -}; - -Playground.parameters = { - percy: { - skip: true, - }, - knobs: { - [`${prefix}-layer-playground`]: () => ({ - level: radios('Specify the layer level', levels, '0'), - }), - }, + `, }; -export default { +const meta = { title: 'Components/Layer', parameters: { - ...storyDocs.parameters, + docs: { + page: storyDocs, + }, }, }; + +export default meta; diff --git a/packages/carbon-web-components/src/components/link/link.mdx b/packages/carbon-web-components/src/components/link/link.mdx index 9fb784f106e..af00b41745a 100644 --- a/packages/carbon-web-components/src/components/link/link.mdx +++ b/packages/carbon-web-components/src/components/link/link.mdx @@ -1,4 +1,4 @@ -import { ArgsTable, Description, Meta } from '@storybook/blocks'; +import { ArgsTable, Markdown, Meta } from '@storybook/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; import * as LinkStories from './link.stories'; @@ -25,8 +25,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/list/index.js'; ``` - - +{`${cdnJs({ components: ['list'] })}`} +{`${cdnCss()}`} ### HTML diff --git a/packages/carbon-web-components/src/components/link/link.stories.ts b/packages/carbon-web-components/src/components/link/link.stories.ts index cb3ec31b4b2..32d5f4d069e 100644 --- a/packages/carbon-web-components/src/components/link/link.stories.ts +++ b/packages/carbon-web-components/src/components/link/link.stories.ts @@ -1,7 +1,7 @@ /** * @license * - * Copyright IBM Corp. 2019, 2023 + * Copyright IBM Corp. 2019, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. @@ -19,7 +19,7 @@ const defaultArgs = { inline: false, size: LINK_SIZE.MEDIUM, visited: false, -} +}; const controls = { disabled: { @@ -31,20 +31,20 @@ const controls = { description: `Provide the href attribute for the
node`, }, size: { - control: 'radio', options: [LINK_SIZE.SMALL, LINK_SIZE.MEDIUM, LINK_SIZE.LARGE], - description: `Specify the size of the Link. Currently supports either sm, 'md' (default) or 'lg' as an option.` + control: 'radio', + options: [LINK_SIZE.SMALL, LINK_SIZE.MEDIUM, LINK_SIZE.LARGE], + description: `Specify the size of the Link. Currently supports either sm, 'md' (default) or 'lg' as an option.`, }, visited: { control: 'boolean', description: `Specify whether you want the link to receive visited styles after the link has been clicked`, }, -} +}; export const Default = { - render: () => html` Link ` + render: () => html` Link `, }; - export const Inline = { render: () => html` - ` + `, }; export const PairedWithIcon = { @@ -72,12 +72,7 @@ export const PairedWithIcon = { parameters: { controls: { exclude: /(.*?)/ }, }, - render: ({ - disabled, - href, - size, - onClick - }) => html` + render: ({ disabled, href, size, onClick }) => html` html` + render: ({ disabled, href, inline, size, visited, onClick }) => html` - +{`${cdnJs({ components: ['list'] })}`} +{`${cdnCss()}`} ### HTML @@ -74,4 +74,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `nested` attribute). - + diff --git a/packages/carbon-web-components/src/components/list/ordered-list-story.ts b/packages/carbon-web-components/src/components/list/ordered-list-story.ts deleted file mode 100644 index e594074ec91..00000000000 --- a/packages/carbon-web-components/src/components/list/ordered-list-story.ts +++ /dev/null @@ -1,120 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import './ordered-list'; -import './list-item'; -import { boolean } from '@storybook/addon-knobs'; -import storyDocs from './list-story.mdx'; -import { prefix } from '../../globals/settings'; - -export const Default = () => html` - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 -`; - -export default { - title: 'Components/Ordered List', -}; - -export const NativeListStyles = () => html` - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - - Ordered List level 1 - - Ordered List level 2 - Ordered List level 2 - Ordered List level 2 - Ordered List level 2 - - - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 -`; - -export const Nested = () => html` - - Ordered List level 1 - - Ordered List level 2 - - Ordered List level 2 - - Ordered List level 3 - Ordered List level 3 - - - - - Ordered List level 1 - Ordered List level 1 -`; - -export const Playground = (args) => { - const { isExpressive, native } = args?.[`${prefix}-list`] ?? {}; - return html` - - - Ordered List level 1 - - Ordered List level 2 - - Ordered List level 2 - - Ordered List level 2 - Ordered List level 2 - - - - - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - Ordered List level 1 - - - `; -}; - -Playground.parameters = { - ...storyDocs.parameters, - knobs: { - [`${prefix}-list`]: () => ({ - isExpressive: boolean('Expressive (isExpressive)', false), - native: boolean('Native (native)', false), - }), - }, -}; diff --git a/packages/carbon-web-components/src/components/list/ordered-list.stories.ts b/packages/carbon-web-components/src/components/list/ordered-list.stories.ts new file mode 100644 index 00000000000..6771ae556a4 --- /dev/null +++ b/packages/carbon-web-components/src/components/list/ordered-list.stories.ts @@ -0,0 +1,138 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2023 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import storyDocs from './list.mdx'; +import './index'; + +const defaultArgs = { + isExpressive: false, + native: true, +}; + +const controls = { + isExpressive: { + control: 'boolean', + description: 'Specify whether this ordered list expressive or not.', + }, + native: { + control: 'boolean', + description: + 'Specify whether this ordered list should use native list styles instead of custom counter.', + }, +}; + +export const Default = { + render: () => html` + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + `, +}; + +export const NativeListStyles = { + render: () => html` + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + + Ordered List level 1 + + Ordered List level 2 + Ordered List level 2 + Ordered List level 2 + Ordered List level 2 + + + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + `, +}; + +export const Nested = { + render: () => html` + + Ordered List level 1 + + Ordered List level 2 + + Ordered List level 2 + + Ordered List level 3 + Ordered List level 3 + + + + + Ordered List level 1 + Ordered List level 1 + `, +}; + +export const Playground = { + args: defaultArgs, + argTypes: controls, + render: ({ isExpressive, native }) => html` + + + Ordered List level 1 + + Ordered List level 2 + + Ordered List level 2 + + Ordered List level 2 + Ordered List level 2 + + + + + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + Ordered List level 1 + + + `, +}; + +const meta = { + title: 'Components/Ordered list', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/list/unordered-list-story.ts b/packages/carbon-web-components/src/components/list/unordered-list-story.ts deleted file mode 100644 index d37874cf268..00000000000 --- a/packages/carbon-web-components/src/components/list/unordered-list-story.ts +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import './unordered-list'; -import './list-item'; -import { boolean } from '@storybook/addon-knobs'; -import storyDocs from './list-story.mdx'; -import { prefix } from '../../globals/settings'; - -export const Default = () => html` - Unordered List level 1 - Unordered List level 1 - Unordered List level 1 -`; - -export default { - title: 'Components/Unordered List', -}; - -export const Nested = () => html` - - Unordered List level 1 - - Unordered List level 2 - - Unordered List level 2 - - Unordered List level 3 - Unordered List level 3 - - - - - Unordered List level 1 - Unordered List level 1 -`; - -export const Playground = (args) => { - const { isExpressive } = args?.[`${prefix}-list`] ?? {}; - return html` - - - Unordered List level 1 - - Unordered List level 2 - - Unordered List level 2 - - Unordered List level 2 - Unordered List level 2 - - - - - Unordered List level 1 - Unordered List level 1 - - `; -}; - -Playground.parameters = { - ...storyDocs.parameters, - knobs: { - [`${prefix}-list`]: () => ({ - isExpressive: boolean('Expressive (isExpressive)', false), - }), - }, -}; diff --git a/packages/carbon-web-components/src/components/list/unordered-list.stories.ts b/packages/carbon-web-components/src/components/list/unordered-list.stories.ts new file mode 100644 index 00000000000..21d42b8ea36 --- /dev/null +++ b/packages/carbon-web-components/src/components/list/unordered-list.stories.ts @@ -0,0 +1,87 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2023 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import storyDocs from './list.mdx'; +import './index'; + +const defaultArgs = { + isExpressive: false, +}; + +const controls = { + isExpressive: { + control: 'boolean', + description: 'Specify whether this ordered list expressive or not.', + }, +}; + +export const Default = { + render: () => html` + Unordered List level 1 + Unordered List level 1 + Unordered List level 1 + `, +}; + +export const Nested = { + render: () => html` + + Unordered List level 1 + + Unordered List level 2 + + Unordered List level 2 + + Unordered List level 3 + Unordered List level 3 + + + + + Unordered List level 1 + Unordered List level 1 + `, +}; + +export const Playground = { + args: defaultArgs, + argTypes: controls, + + render: ({ isExpressive }) => html` + + + Unordered List level 1 + + Unordered List level 2 + + Unordered List level 2 + + Unordered List level 2 + Unordered List level 2 + + + + + Unordered List level 1 + Unordered List level 1 + + `, +}; + +const meta = { + title: 'Components/Unordered list', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/loading/loading-story.ts b/packages/carbon-web-components/src/components/loading/loading-story.ts deleted file mode 100644 index 30a6337f0f8..00000000000 --- a/packages/carbon-web-components/src/components/loading/loading-story.ts +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { boolean, select, text } from '@storybook/addon-knobs'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import { LOADING_TYPE } from './loading'; -import storyDocs from './loading-story.mdx'; -import { prefix } from '../../globals/settings'; - -const types = { - [`Regular (${LOADING_TYPE.REGULAR})`]: null, - [`Small (${LOADING_TYPE.SMALL})`]: LOADING_TYPE.SMALL, -}; - -export const Default = () => html` `; - -export default { - title: 'Components/Loading', - parameters: { ...storyDocs.parameters }, -}; - -export const Playground = (args) => { - const { inactive, assistiveText, type, withOverlay } = - args?.[`${prefix}-loading`] ?? {}; - return html` - - `; -}; - -Playground.parameters = { - ...storyDocs.parameters, - knobs: { - [`${prefix}-loading`]: () => ({ - inactive: boolean('Inactive (inactive)', false), - assistiveText: text( - 'Assistive text (assistive-text) - Specify a description that would be used to best describe the loading state', - 'Loading' - ), - type: select('The spinner type (type)', types, null), - withOverlay: boolean('With overlay (withOverlay)', false), - }), - }, -}; diff --git a/packages/carbon-web-components/src/components/loading/loading-story.mdx b/packages/carbon-web-components/src/components/loading/loading.mdx similarity index 83% rename from packages/carbon-web-components/src/components/loading/loading-story.mdx rename to packages/carbon-web-components/src/components/loading/loading.mdx index 6765f136dcd..31883edbfc8 100644 --- a/packages/carbon-web-components/src/components/loading/loading-story.mdx +++ b/packages/carbon-web-components/src/components/loading/loading.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Markdown, Meta } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as LoadingStories from './loading.stories'; + + # Loading @@ -25,8 +28,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/loading/index.js'; ``` - - +{`${cdnJs({ components: ['loading'] })}`} +{`${cdnCss()}`} ### HTML @@ -42,4 +45,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `inactive` attribute). - + diff --git a/packages/carbon-web-components/src/components/loading/loading.stories.ts b/packages/carbon-web-components/src/components/loading/loading.stories.ts new file mode 100644 index 00000000000..7ccfb14b2be --- /dev/null +++ b/packages/carbon-web-components/src/components/loading/loading.stories.ts @@ -0,0 +1,73 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2023 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { ifDefined } from 'lit/directives/if-defined.js'; +import { LOADING_TYPE } from './loading'; +import storyDocs from './loading.mdx'; + +const types = { + [`Regular (${LOADING_TYPE.REGULAR})`]: null, + [`Small (${LOADING_TYPE.SMALL})`]: LOADING_TYPE.SMALL, +}; + +const defaultArgs = { + inactive: false, + assistiveText: 'Loading', + type: null, + withOverlay: false, +}; + +const controls = { + inactive: { + control: 'boolean', + description: `Specify whether the component should be inactive, or not.`, + }, + assistiveText: { + control: 'text', + description: `Specify a description that would be used to best describe the loading state.`, + }, + type: { + control: 'radio', + options: types, + description: `Specify the spinner type.`, + }, + withOverlay: { + control: 'boolean', + description: `Specify whether the loading should be an overlay.`, + }, +}; + +export const Default = { + render: () => html` `, +}; + +export const Playground = { + args: defaultArgs, + argTypes: controls, + render: ({ inactive, assistiveText, type, withOverlay }) => + html` + + `, +}; + +const meta = { + title: 'Components/Loading', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/modal/modal-footer-button.ts b/packages/carbon-web-components/src/components/modal/modal-footer-button.ts index 73443a513a7..dcab26a29a3 100644 --- a/packages/carbon-web-components/src/components/modal/modal-footer-button.ts +++ b/packages/carbon-web-components/src/components/modal/modal-footer-button.ts @@ -1,7 +1,7 @@ /** * @license * - * Copyright IBM Corp. 2021, 2023 + * Copyright IBM Corp. 2021, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. @@ -9,7 +9,7 @@ import { prefix } from '../../globals/settings'; import CDSButton from '../button/button'; -import buttonStyles from '../button/button.scss'; +import buttonStyles from '../button/button.scss?lit'; import styles from './modal.scss?lit'; import { carbonElement as customElement } from '../../globals/decorators/carbon-element'; diff --git a/packages/carbon-web-components/src/components/modal/modal-story.ts b/packages/carbon-web-components/src/components/modal/modal-story.ts deleted file mode 100644 index 8c7dc0abd55..00000000000 --- a/packages/carbon-web-components/src/components/modal/modal-story.ts +++ /dev/null @@ -1,392 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { boolean, select, text } from '@storybook/addon-knobs'; -import '../button/button'; -import { MODAL_SIZE } from './modal'; -import './index'; -import storyDocs from './modal-story.mdx'; - -const toggleButton = () => { - document.querySelector('cds-modal')?.toggleAttribute('open'); -}; - -const sizes = { - [`Extra small size (${MODAL_SIZE.EXTRA_SMALL})`]: MODAL_SIZE.EXTRA_SMALL, - [`Small size (${MODAL_SIZE.SMALL})`]: MODAL_SIZE.SMALL, - [`Medium size (${MODAL_SIZE.MEDIUM})`]: MODAL_SIZE.MEDIUM, - [`Large size (${MODAL_SIZE.LARGE})`]: MODAL_SIZE.LARGE, -}; - -const buttons = { - 'One (1)': 1, - 'Two (2)': 2, - 'Three (3)': 3, -}; - -export const Default = () => { - return html` - - - - Account resources - Add a custom domain - - - - Custom domains direct requests for your apps in this Cloud Foundry - organization to a URL that you own. A custom domain can be a shared - domain, a shared subdomain, or a shared domain and host. - - - - - - - - - US South - US East - - - - - One - Two - - - - Option 1 - Option 2 - - - - Cancel - Add - - - `; -}; - -export const DangerModal = () => { - return html` - - - - Account resources - Are you sure you want to delete this custom - domain? - - - Cancel - Delete - - - `; -}; - -export const FullWidth = () => { - return html` - - - - An example of a modal with no padding - Full Width Modal - - - - - - Column A - Column B - Column C - - - - - Row 1 - Row 1 - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc - dui magna, finibus id tortor sed, aliquet bibendum augue. Aenean - posuere sem vel euismod dignissim. Nulla ut cursus dolor. - Pellentesque vulputate nisl a porttitor interdum. - - - - Row 2 - Row 2 - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc - dui magna, finibus id tortor sed, aliquet bibendum augue. Aenean - posuere sem vel euismod dignissim. Nulla ut cursus dolor. - Pellentesque vulputate nisl a porttitor interdum. - - - - Row 3 - Row 3 - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc - dui magna, finibus id tortor sed, aliquet bibendum augue. Aenean - posuere sem vel euismod dignissim. Nulla ut cursus dolor. - Pellentesque vulputate nisl a porttitor interdum. - - - - - - - Cancel - Add - - - `; -}; - -export const PassiveModal = () => { - return html` - - - - You have been successfully signed out - - - - `; -}; - -export const WithStateManager = () => { - return html` - - - - Account resources - Add a custom domain - - - - Custom domains direct requests for your apps in this Cloud Foundry - organization to a URL that you own. A custom domain can be a shared - domain, a shared subdomain, or a shared domain and host. - - - - - - - Option 1 - Option 2 - - - - Cancel - Add - - - Launch modal - `; -}; - -export const Playground = (args) => { - const { - alert, - ariaLabel, - danger, - open, - closeButtonLabel, - hasScrollingContent, - fullWidth, - modalHeading, - modalLabel, - numberOfButtons, - passiveModal, - preventCloseOnClickOutside, - primaryButtonDisabled, - size, - } = args?.['cds-modal'] ?? {}; - return html` - - - - ${modalLabel} - ${modalHeading} - - - - Custom domains direct requests for your apps in this Cloud Foundry - organization to a URL that you own. A custom domain can be a shared - domain, a shared subdomain, or a shared domain and host. - - - - - - - Option 1 - Option 2 - - - ${hasScrollingContent - ? html` - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean - id accumsan augue. Phasellus consequat augue vitae tellus - tincidunt posuere. Curabitur justo urna, consectetur vel elit - iaculis, ultrices condimentum risus. Nulla facilisi. Etiam - venenatis molestie tellus. Quisque consectetur non risus eu - rutrum. - - - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean - id accumsan augue. Phasellus consequat augue vitae tellus - tincidunt posuere. Curabitur justo urna, consectetur vel elit - iaculis, ultrices condimentum risus. Nulla facilisi. Etiam - venenatis molestie tellus. Quisque consectetur non risus eu - rutrum. - - - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean - id accumsan augue. Phasellus consequat augue vitae tellus - tincidunt posuere. Curabitur justo urna, consectetur vel elit - iaculis, ultrices condimentum risus. Nulla facilisi. Etiam - venenatis molestie tellus. Quisque consectetur non risus eu - rutrum. - -

Lorem ipsum

- - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean - id accumsan augue. Phasellus consequat augue vitae tellus - tincidunt posuere. Curabitur justo urna, consectetur vel elit - iaculis, ultrices condimentum risus. Nulla facilisi. Etiam - venenatis molestie tellus. Quisque consectetur non risus eu - rutrum. - - - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean - id accumsan augue. Phasellus consequat augue vitae tellus - tincidunt posuere. Curabitur justo urna, consectetur vel elit - iaculis, ultrices condimentum risus. Nulla facilisi. Etiam - venenatis molestie tellus. Quisque consectetur non risus eu - rutrum. - - - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean - id accumsan augue. Phasellus consequat augue vitae tellus - tincidunt posuere. Curabitur justo urna, consectetur vel elit - iaculis, ultrices condimentum risus. Nulla facilisi. Etiam - venenatis molestie tellus. Quisque consectetur non risus eu - rutrum. - - - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean - id accumsan augue. Phasellus consequat augue vitae tellus - tincidunt posuere. Curabitur justo urna, consectetur vel elit - iaculis, ultrices condimentum risus. Nulla facilisi. Etiam - venenatis molestie tellus. Quisque consectetur non risus eu - rutrum. - ` - : ``} -
- - ${passiveModal - ? `` - : html` - ${numberOfButtons > 2 - ? html` Keep both` - : ``} - ${numberOfButtons >= 2 - ? html` ${numberOfButtons === 2 - ? html`Cancel` - : 'Rename'}` - : ``} - - Add - `} -
- `; -}; - -Playground.parameters = { - ...storyDocs.parameters, - knobs: { - 'cds-modal': () => ({ - alert: boolean('Alert (alert)', false), - ariaLabel: text('Aria label (aria-label)', ''), - closeButtonLabel: text( - 'Close button label (close-button-label)', - 'Close' - ), - danger: boolean('Danger mode (danger)', false), - fullWidth: boolean('Full width (full-width)', false), - hasScrollingContent: boolean( - 'Has scrolling content (has-scrolling-content)', - false - ), - modalHeading: text('Modal heading', 'Add a custom domain'), - modalLabel: text('Modal label', ''), - numberOfButtons: select('Number of buttons', buttons, 2), - open: boolean('Open (open)', true), - passiveModal: boolean('Passive modal (passive-modal)', false), - preventCloseOnClickOutside: boolean( - 'Prevent close on click outside', - false - ), - primaryButtonDisabled: boolean('Primary button disabled', false), - size: select('Modal size (size)', sizes, null), - }), - }, -}; - -export default { - title: 'Components/Modal', - decorators: [(story) => html` ${story()} `], - parameters: { - ...storyDocs.parameters, - }, -}; diff --git a/packages/carbon-web-components/src/components/modal/modal-story.mdx b/packages/carbon-web-components/src/components/modal/modal.mdx similarity index 95% rename from packages/carbon-web-components/src/components/modal/modal-story.mdx rename to packages/carbon-web-components/src/components/modal/modal.mdx index d774aa5f510..a98b039a7f6 100644 --- a/packages/carbon-web-components/src/components/modal/modal-story.mdx +++ b/packages/carbon-web-components/src/components/modal/modal.mdx @@ -1,6 +1,10 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Markdown, Meta } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as ModalStories from './modal.stories'; + + + # Modal > đź’ˇ Check our @@ -36,8 +40,8 @@ import '@carbon/web-components/es/components/modal/index.js'; import '@carbon/web-components/es/components/button/index.js'; ``` - - +{`${cdnJs({ components: ['modal', 'button'] })}`} +{`${cdnCss()}`} ### HTML @@ -74,7 +78,7 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `open` attribute). - + ## `` attributes and properties @@ -82,7 +86,7 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `disabled` attribute). - + ## Opening/closing modal diff --git a/packages/carbon-web-components/src/components/modal/modal.stories.ts b/packages/carbon-web-components/src/components/modal/modal.stories.ts new file mode 100644 index 00000000000..28377ae89ad --- /dev/null +++ b/packages/carbon-web-components/src/components/modal/modal.stories.ts @@ -0,0 +1,445 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2023 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import '../structured-list'; +import { MODAL_SIZE } from './modal'; +import './index'; +import storyDocs from './modal.mdx'; + +const toggleButton = () => { + document.querySelector('cds-modal')?.toggleAttribute('open'); +}; + +const sizes = { + [`Extra small size (${MODAL_SIZE.EXTRA_SMALL})`]: MODAL_SIZE.EXTRA_SMALL, + [`Small size (${MODAL_SIZE.SMALL})`]: MODAL_SIZE.SMALL, + [`Medium size (${MODAL_SIZE.MEDIUM})`]: MODAL_SIZE.MEDIUM, + [`Large size (${MODAL_SIZE.LARGE})`]: MODAL_SIZE.LARGE, +}; + +const buttons = { + 'One (1)': 1, + 'Two (2)': 2, + 'Three (3)': 3, +}; + +const defaultArgs = { + alert: false, + ariaLabel: '', + closeButtonLabel: 'Close', + danger: false, + fullWidth: false, + hasScrollingContent: false, + modalHeading: 'Add a custom domain', + modalLabel: '', + numberOfButtons: 2, + open: true, + passiveModal: false, + preventCloseOnClickOutside: false, + primaryButtonDisabled: false, + size: null, +}; + +const controls = { + alert: { + control: 'boolean', + description: + 'Specify whether the Modal is displaying an alert, error or warning Should go hand in hand with the danger prop.', + }, + ariaLabel: { + control: 'text', + description: 'Required props for the accessibility label of the header.', + }, + closeButtonLabel: { + control: 'text', + description: 'Required props for the accessibility label of the header.', + }, + danger: { + control: 'boolean', + description: 'Specify whether the Modal is for dangerous actions.', + }, + fullWidth: { + control: 'boolean', + description: + 'Specify whether or not the Modal content should have any inner padding.', + }, + hasScrollingContent: { + control: 'boolean', + description: 'Specify whether the modal contains scrolling content.', + }, + modalHeading: { + control: 'text', + description: 'Specify the content of the modal header title.', + }, + modalLabel: { + control: 'text', + description: 'Specify the content of the modal header label.', + }, + numberOfButtons: { + control: 'radio', + description: 'Count of Footer Buttons', + options: buttons, + }, + open: { + control: 'boolean', + description: 'Specify whether the modal is currently open.', + }, + passiveModal: { + control: 'boolean', + description: 'Specify whether the Modal should be passive, or not.', + }, + preventCloseOnClickOutside: { + control: 'boolean', + description: 'Prevent close on click outside.', + }, + primaryButtonDisabled: { + control: 'boolean', + description: 'Primary button disabled.', + }, + size: { + control: 'select', + description: 'Modal size.', + options: sizes, + }, +}; + +export const Default = { + render: () => html` + + + + Account resources + Add a custom domain + + + + Custom domains direct requests for your apps in this Cloud Foundry + organization to a URL that you own. A custom domain can be a shared + domain, a shared subdomain, or a shared domain and host. + + + + + + + + + US South + US East + + + + + One + Two + + + + Option 1 + Option 2 + + + + Cancel + Add + + + `, +}; + +export const DangerModal = { + render: () => html` + + + + Account resources + Are you sure you want to delete this custom + domain? + + + Cancel + Delete + + + `, +}; + +export const FullWidth = { + render: () => html` + + + + An example of a modal with no padding + Full Width Modal + + + + + + Column A + Column B + Column C + + + + + Row 1 + Row 1 + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc + dui magna, finibus id tortor sed, aliquet bibendum augue. Aenean + posuere sem vel euismod dignissim. Nulla ut cursus dolor. + Pellentesque vulputate nisl a porttitor interdum. + + + + Row 2 + Row 2 + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc + dui magna, finibus id tortor sed, aliquet bibendum augue. Aenean + posuere sem vel euismod dignissim. Nulla ut cursus dolor. + Pellentesque vulputate nisl a porttitor interdum. + + + + Row 3 + Row 3 + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc + dui magna, finibus id tortor sed, aliquet bibendum augue. Aenean + posuere sem vel euismod dignissim. Nulla ut cursus dolor. + Pellentesque vulputate nisl a porttitor interdum. + + + + + + + Cancel + Add + + + `, +}; + +export const PassiveModal = { + render: () => html` + + + + You have been successfully signed out + + + + `, +}; + +export const WithStateManager = { + render: () => html` + + + + Account resources + Add a custom domain + + + + Custom domains direct requests for your apps in this Cloud Foundry + organization to a URL that you own. A custom domain can be a shared + domain, a shared subdomain, or a shared domain and host. + + + + + + + Option 1 + Option 2 + + + + Cancel + Add + + + Launch modal + `, +}; + +export const Playground = { + args: defaultArgs, + argTypes: controls, + render: ({ + alert, + ariaLabel, + danger, + open, + closeButtonLabel, + hasScrollingContent, + fullWidth, + modalHeading, + modalLabel, + numberOfButtons, + passiveModal, + preventCloseOnClickOutside, + primaryButtonDisabled, + size, + }) => + html` + + + + ${modalLabel} + ${modalHeading} + + + + Custom domains direct requests for your apps in this Cloud Foundry + organization to a URL that you own. A custom domain can be a shared + domain, a shared subdomain, or a shared domain and host. + + + + + + + Option 1 + Option 2 + + + ${hasScrollingContent + ? html` + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Aenean id accumsan augue. Phasellus consequat augue vitae + tellus tincidunt posuere. Curabitur justo urna, consectetur + vel elit iaculis, ultrices condimentum risus. Nulla facilisi. + Etiam venenatis molestie tellus. Quisque consectetur non risus + eu rutrum. + + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Aenean id accumsan augue. Phasellus consequat augue vitae + tellus tincidunt posuere. Curabitur justo urna, consectetur + vel elit iaculis, ultrices condimentum risus. Nulla facilisi. + Etiam venenatis molestie tellus. Quisque consectetur non risus + eu rutrum. + + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Aenean id accumsan augue. Phasellus consequat augue vitae + tellus tincidunt posuere. Curabitur justo urna, consectetur + vel elit iaculis, ultrices condimentum risus. Nulla facilisi. + Etiam venenatis molestie tellus. Quisque consectetur non risus + eu rutrum. + +

Lorem ipsum

+ + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Aenean id accumsan augue. Phasellus consequat augue vitae + tellus tincidunt posuere. Curabitur justo urna, consectetur + vel elit iaculis, ultrices condimentum risus. Nulla facilisi. + Etiam venenatis molestie tellus. Quisque consectetur non risus + eu rutrum. + + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Aenean id accumsan augue. Phasellus consequat augue vitae + tellus tincidunt posuere. Curabitur justo urna, consectetur + vel elit iaculis, ultrices condimentum risus. Nulla facilisi. + Etiam venenatis molestie tellus. Quisque consectetur non risus + eu rutrum. + + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Aenean id accumsan augue. Phasellus consequat augue vitae + tellus tincidunt posuere. Curabitur justo urna, consectetur + vel elit iaculis, ultrices condimentum risus. Nulla facilisi. + Etiam venenatis molestie tellus. Quisque consectetur non risus + eu rutrum. + + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Aenean id accumsan augue. Phasellus consequat augue vitae + tellus tincidunt posuere. Curabitur justo urna, consectetur + vel elit iaculis, ultrices condimentum risus. Nulla facilisi. + Etiam venenatis molestie tellus. Quisque consectetur non risus + eu rutrum. + ` + : ``} +
+ + ${passiveModal + ? `` + : html` + ${numberOfButtons > 2 + ? html` Keep both` + : ``} + ${numberOfButtons >= 2 + ? html` ${numberOfButtons === 2 + ? html`Cancel` + : 'Rename'}` + : ``} + + Add + `} +
+ `, +}; + +const meta = { + title: 'Components/Modal', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/multi-select/multi-select-story.ts b/packages/carbon-web-components/src/components/multi-select/multi-select-story.ts deleted file mode 100644 index aee2bf265bf..00000000000 --- a/packages/carbon-web-components/src/components/multi-select/multi-select-story.ts +++ /dev/null @@ -1,292 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { boolean, select } from '@storybook/addon-knobs'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import textNullable from '../../../.storybook/knob-text-nullable'; -import { prefix } from '../../globals/settings'; -import { - DROPDOWN_SIZE, - DROPDOWN_TYPE, - DROPDOWN_DIRECTION, - SELECTION_FEEDBACK_OPTION, -} from './multi-select'; -import './multi-select-item'; -import '../../../.storybook/templates/with-layer'; -import storyDocs from './multi-select-story.mdx'; - -const sizes = { - [`Small size (${DROPDOWN_SIZE.SMALL})`]: DROPDOWN_SIZE.SMALL, - [`Medium size (${DROPDOWN_SIZE.MEDIUM})`]: DROPDOWN_SIZE.MEDIUM, - [`Large size (${DROPDOWN_SIZE.LARGE})`]: DROPDOWN_SIZE.LARGE, -}; - -const directionOptions = { - [`Top`]: DROPDOWN_DIRECTION.TOP, - [`Bottom`]: DROPDOWN_DIRECTION.BOTTOM, -}; - -const types = { - Default: null, - [`Inline (${DROPDOWN_TYPE.INLINE})`]: DROPDOWN_TYPE.INLINE, -}; - -const selectionFeedbackOptions = { - [`Top (${SELECTION_FEEDBACK_OPTION.TOP})`]: SELECTION_FEEDBACK_OPTION.TOP, - [`Fixed (${SELECTION_FEEDBACK_OPTION.FIXED})`]: - SELECTION_FEEDBACK_OPTION.FIXED, - [`Top-after-reopen (${SELECTION_FEEDBACK_OPTION.TOP_AFTER_REOPEN})`]: - SELECTION_FEEDBACK_OPTION.TOP_AFTER_REOPEN, -}; - -export const Default = () => { - return html` - - An example option that is really long to show what should be done to - handle long text - Option 1 - Option 2 - Option 3 - a disabled item - Option 4 - Option 5 - - `; -}; - -Default.decorators = [ - (story) => html`
${story()}
`, -]; - -export const Filterable = () => { - return html` - - An example option that is really long to show what should be done to - handle long text - Option 1 - Option 2 - Option 3 - a disabled item - Option 4 - Option 5 - - `; -}; - -Filterable.decorators = [ - (story) => html`
${story()}
`, -]; - -export const FilterableWithLayer = () => { - return html` - -
- - An example option that is really long to show what should be done - to handle long text - Option 1 - Option 2 - Option 3 - a disabled item - Option 4 - Option 5 - -
-
- `; -}; - -export const WithInitialSelectedItems = () => { - return html` - - An example option that is really long to show what should be done to - handle long text - Option 1 - Option 2 - Option 3 - a disabled item - Option 4 - Option 5 - - `; -}; - -WithInitialSelectedItems.decorators = [ - (story) => html`
${story()}
`, -]; - -export const WithLayer = () => { - return html` - -
- - An example option that is really long to show what should be done - to handle long text - Option 1 - Option 2 - Option 3 - a disabled item - Option 4 - Option 5 - -
-
- `; -}; - -export const Playground = (args) => { - const { - clearSelectionLabel, - direction, - disabled, - helperText, - hideLabel, - locale, - invalid, - invalidText, - readOnly, - titleText, - selectionFeedback, - size, - label, - type, - value, - warn, - warnText, - } = args?.[`${prefix}-multi-select`] ?? {}; - return html` - - An example option that is really long to show what should be done to - handle long text - Option 1 - Option 2 - Option 3 - a disabled item - Option 4 - Option 5 - - `; -}; - -Playground.decorators = [ - (story) => html`
${story()}
`, -]; - -export default { - title: 'Components/Multi select', - parameters: { - ...storyDocs.parameters, - knobs: { - [`${prefix}-multi-select`]: () => ({ - clearSelectionDescription: textNullable( - 'Clear selection description for a11y (clear-selection-description)', - 'Total items selected: ' - ), - clearSelectionText: textNullable( - 'Clear selection text for a11y (clear-selection-text)', - 'To clear selection, press Delete or Backspace.' - ), - disabled: boolean('Disabled (disabled)', false), - direction: select( - 'Direction', - directionOptions, - DROPDOWN_DIRECTION.BOTTOM - ), - helperText: textNullable( - 'Helper text (helper-text)', - 'Optional helper text' - ), - hideLabel: boolean('Hide label (hide-label)', false), - locale: textNullable('Locale (locale)', 'en'), - invalid: boolean('Show invalid state (invalid)', false), - invalidText: textNullable('Invalid text (invalid-text)', 'whoopsie!'), - titleText: textNullable( - 'Title text (title-text)', - 'This is a MultiSelect Title' - ), - label: textNullable('Label of field (label)', 'This is a label'), - size: select('Size (size)', sizes, DROPDOWN_SIZE.MEDIUM), - selectionFeedback: select( - 'Selection feedback (selection-feedback)', - selectionFeedbackOptions, - SELECTION_FEEDBACK_OPTION.TOP_AFTER_REOPEN - ), - readOnly: boolean('Read only (read-only)', false), - type: select('Type (type)', types, null), - warn: boolean('Warn (warn)', false), - warnText: textNullable('Warn text (warn-text)', 'whoopsie!'), - }), - }, - }, -}; diff --git a/packages/carbon-web-components/src/components/multi-select/multi-select-story.mdx b/packages/carbon-web-components/src/components/multi-select/multi-select.mdx similarity index 94% rename from packages/carbon-web-components/src/components/multi-select/multi-select-story.mdx rename to packages/carbon-web-components/src/components/multi-select/multi-select.mdx index 610080c30ae..37702b3e828 100644 --- a/packages/carbon-web-components/src/components/multi-select/multi-select-story.mdx +++ b/packages/carbon-web-components/src/components/multi-select/multi-select.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Description } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as MultiSelectStories from './multi-select.stories'; + + # Multi select @@ -103,7 +106,7 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `open` attribute). - + ## `` attributes and properties @@ -111,4 +114,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `disabled` attribute). - + diff --git a/packages/carbon-web-components/src/components/multi-select/multi-select.stories.ts b/packages/carbon-web-components/src/components/multi-select/multi-select.stories.ts new file mode 100644 index 00000000000..0b627d4c1ca --- /dev/null +++ b/packages/carbon-web-components/src/components/multi-select/multi-select.stories.ts @@ -0,0 +1,364 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { ifDefined } from 'lit/directives/if-defined.js'; +import { + DROPDOWN_SIZE, + DROPDOWN_TYPE, + DROPDOWN_DIRECTION, + SELECTION_FEEDBACK_OPTION, +} from './multi-select'; +import './multi-select-item'; +import '../layer/index'; +import '../../../.storybook/templates/with-layer'; +import storyDocs from './multi-select.mdx'; + +const sizes = { + [`Small size (${DROPDOWN_SIZE.SMALL})`]: DROPDOWN_SIZE.SMALL, + [`Medium size (${DROPDOWN_SIZE.MEDIUM})`]: DROPDOWN_SIZE.MEDIUM, + [`Large size (${DROPDOWN_SIZE.LARGE})`]: DROPDOWN_SIZE.LARGE, +}; + +const directionOptions = { + [`Top`]: DROPDOWN_DIRECTION.TOP, + [`Bottom`]: DROPDOWN_DIRECTION.BOTTOM, +}; + +const types = { + Default: null, + [`Inline (${DROPDOWN_TYPE.INLINE})`]: DROPDOWN_TYPE.INLINE, +}; + +const selectionFeedbackOptions = { + [`Top (${SELECTION_FEEDBACK_OPTION.TOP})`]: SELECTION_FEEDBACK_OPTION.TOP, + [`Fixed (${SELECTION_FEEDBACK_OPTION.FIXED})`]: + SELECTION_FEEDBACK_OPTION.FIXED, + [`Top-after-reopen (${SELECTION_FEEDBACK_OPTION.TOP_AFTER_REOPEN})`]: + SELECTION_FEEDBACK_OPTION.TOP_AFTER_REOPEN, +}; + +const args = { + clearSelectionDescription: 'Total items selected: ', + clearSelectionText: 'To clear selection, press Delete or Backspace.', + disabled: false, + direction: DROPDOWN_DIRECTION.BOTTOM, + helperText: 'Optional helper text', + hideLabel: false, + locale: 'en', + invalid: false, + invalidText: 'whoopsie!', + titleText: 'This is a MultiSelect Title', + label: 'This is a label', + size: DROPDOWN_SIZE.MEDIUM, + selectionFeedback: SELECTION_FEEDBACK_OPTION.TOP_AFTER_REOPEN, + readOnly: false, + type: null, + warn: false, + warnText: 'whoopsie!', +}; + +const argTypes = { + clearSelectionDescription: { + control: 'text', + description: + 'Specify the text that should be read for screen readers that describes total items selected.', + }, + clearSelectionText: { + control: 'text', + description: + 'Specify the text that should be read for screen readers to clear selection.', + }, + disabled: { + control: 'boolean', + description: 'Disable the control.', + }, + direction: { + control: 'select', + description: + 'Specify the direction of the multiselect dropdown. Can be either top or bottom.', + options: directionOptions, + }, + helperText: { + control: 'text', + description: + 'Provide helper text that is used alongside the control label for additional help.', + }, + hideLabel: { + control: 'boolean', + description: 'Specify whether the title text should be hidden or not.', + }, + locale: { + control: 'text', + description: + 'Specify the locale of the control. Used for the default compareItems used for sorting the list of items in the control.', + }, + invalid: { + control: 'boolean', + description: 'Is the current selection invalid?', + }, + invalidText: { + control: 'text', + description: 'If invalid, what is the error?', + }, + titleText: { + control: 'text', + description: + 'Provide text to be used in a <label> element that is tied to the multiselect via ARIA attributes.', + }, + label: { + control: 'text', + description: + 'Generic label that will be used as the textual representation of what this field is for.', + }, + size: { + control: 'select', + description: + 'Specify the size of the ListBox. Currently supports either sm, md or lg as an option.', + options: sizes, + }, + selectionFeedback: { + control: 'select', + description: + "Specify feedback (mode) of the selection. top: selected item jumps to top fixed: selected item stays at it's position top-after-reopen: selected item jump to top after reopen dropdown.", + options: selectionFeedbackOptions, + }, + readOnly: { + control: 'boolean', + description: 'Whether or not the Dropdown is readonly.', + }, + type: { + control: 'select', + description: "Specify 'inline' to create an inline multi-select.", + options: types, + }, + warn: { + control: 'boolean', + description: 'Specify whether the control is currently in warning state.', + }, + warnText: { + control: 'text', + description: + 'Provide the text that is displayed when the control is in warning state.', + }, +}; + +export const Default = { + decorators: [(story) => html`
${story()}
`], + render: () => { + return html` + + An example option that is really long to show what should be done to + handle long text + Option 1 + Option 2 + Option 3 - a disabled item + Option 4 + Option 5 + + `; + }, +}; + +export const Filterable = { + decorators: [(story) => html`
${story()}
`], + render: () => { + return html` + + An example option that is really long to show what should be done to + handle long text + Option 1 + Option 2 + Option 3 - a disabled item + Option 4 + Option 5 + + `; + }, +}; + +export const FilterableWithLayer = { + render: () => { + return html` + +
+ + An example option that is really long to show what should be done + to handle long text + Option 1 + Option 2 + Option 3 - a disabled item + Option 4 + Option 5 + +
+
+ `; + }, +}; + +export const WithInitialSelectedItems = { + decorators: [(story) => html`
${story()}
`], + render: () => { + return html` + + An example option that is really long to show what should be done to + handle long text + Option 1 + Option 2 + Option 3 - a disabled item + Option 4 + Option 5 + + `; + }, +}; + +export const WithLayer = { + render: () => { + return html` + +
+ + An example option that is really long to show what should be done + to handle long text + Option 1 + Option 2 + Option 3 - a disabled item + Option 4 + Option 5 + +
+
+ `; + }, +}; + +export const Playground = { + args, + argTypes, + decorators: [(story) => html`
${story()}
`], + render: (args) => { + const { + clearSelectionLabel, + direction, + disabled, + helperText, + hideLabel, + locale, + invalid, + invalidText, + readOnly, + titleText, + selectionFeedback, + size, + label, + type, + value, + warn, + warnText, + } = args ?? {}; + return html` + + An example option that is really long to show what should be done to + handle long text + Option 1 + Option 2 + Option 3 - a disabled item + Option 4 + Option 5 + + `; + }, +}; + +const meta = { + title: 'Components/Multi Select', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/notification/actionable-notification-story.ts b/packages/carbon-web-components/src/components/notification/actionable-notification-story.ts deleted file mode 100644 index 57f51defee3..00000000000 --- a/packages/carbon-web-components/src/components/notification/actionable-notification-story.ts +++ /dev/null @@ -1,120 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import { action } from '@storybook/addon-actions'; -import { boolean, select } from '@storybook/addon-knobs'; -import textNullable from '../../../.storybook/knob-text-nullable'; -import { NOTIFICATION_KIND } from './inline-notification'; -import './actionable-notification'; -import './actionable-notification-button'; -import storyDocs from './notification-story.mdx'; -import { prefix } from '../../globals/settings'; -import kinds from './stories/helper'; -import '../button/button'; - -const noop = () => {}; - -export const Default = () => { - return html` - - Action - - `; -}; - -export const Playground = (args) => { - const { - actionButtonLabel, - closeOnEscape, - hasFocus, - kind, - title, - subtitle, - hideCloseButton, - lowContrast, - role, - inline, - statusIconDescription, - disableClose, - onBeforeClose = noop, - onClose = noop, - } = args?.[`${prefix}-actionable-notification`] ?? {}; - const handleBeforeClose = (event: CustomEvent) => { - onBeforeClose(event); - if (disableClose) { - event.preventDefault(); - } - }; - return html` - - ${actionButtonLabel} - - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-actionable-notification`]: () => ({ - actionButtonLabel: textNullable( - 'Action button label (action-button-label)', - 'Action' - ), - closeOnEscape: boolean('Close on escape (close-on-escape)', true), - hasFocus: boolean('Has focus (has-focus)', false), - hideCloseButton: boolean( - 'Hide the close button (hide-close-button)', - false - ), - inline: boolean('Inline (inline)', false), - kind: select( - 'The notification kind (kind)', - kinds, - NOTIFICATION_KIND.ERROR - ), - lowContrast: boolean('Use low contrast variant (low-contrast)', false), - role: textNullable('Role (role)', 'alertdialog'), - subtitle: textNullable('Subtitle (subtitle)', 'Subtitle text goes here'), - statusIconDescription: textNullable( - 'statusIconDescription (status-icon-description)', - 'notification' - ), - title: textNullable('Title (title)', 'Notification title'), - onBeforeClose: action(`${prefix}-notification-beingclosed`), - onClose: action(`${prefix}-notification-closed`), - }), - }, -}; - -export default { - title: 'Components/Notifications/Actionable', - parameters: { - ...storyDocs.parameters, - }, -}; diff --git a/packages/carbon-web-components/src/components/notification/actionable-notification.stories.ts b/packages/carbon-web-components/src/components/notification/actionable-notification.stories.ts new file mode 100644 index 00000000000..202bf2a8fd0 --- /dev/null +++ b/packages/carbon-web-components/src/components/notification/actionable-notification.stories.ts @@ -0,0 +1,167 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { ifDefined } from 'lit/directives/if-defined.js'; +import { NOTIFICATION_KIND } from './inline-notification'; +import './actionable-notification'; +import './actionable-notification-button'; +import storyDocs from './notification.mdx'; +import { prefix } from '../../globals/settings'; +import kinds from './stories/helper'; +import '../button/button'; + +const noop = () => {}; + +const args = { + actionButtonLabel: 'Action', + closeOnEscape: true, + hasFocus: false, + hideCloseButton: false, + inline: false, + kind: NOTIFICATION_KIND.ERROR, + lowContrast: false, + role: 'alertdialog', + subtitle: 'Subtitle text goes here', + statusIconDescription: 'notification', + title: 'Notification title', +}; + +const argTypes = { + actionButtonLabel: { + control: 'text', + description: + 'Pass in the action button label that will be rendered within the ActionableNotification.', + }, + closeOnEscape: { + control: 'boolean', + description: + 'Specify if pressing the escape key should close notifications.', + }, + hasFocus: { + control: 'boolean', + description: + 'Specify if focus should be moved to the component when the notification contains actions.', + }, + hideCloseButton: { + control: 'boolean', + description: 'Specify the close button should be disabled, or not.', + }, + inline: { + control: 'boolean', + }, + kind: { + control: 'select', + description: 'Specify what state the notification represents.', + options: kinds, + }, + lowContrast: { + control: 'boolean', + description: + 'Specify whether you are using the low contrast variant of the ActionableNotification.', + }, + role: { + control: 'text', + description: + 'By default, this value is "alertdialog". You can also provide an alternate role if it makes sense from from an accessibility perspective.', + }, + subtitle: { + control: 'text', + description: 'Specify the subtitle.', + }, + statusIconDescription: { + control: 'text', + description: + 'Provide a description for "status" icon that can be read by screen readers.', + }, + title: { + control: 'text', + description: 'Specify the title.', + }, + onBeforeClose: { + action: `${prefix}-notification-beingclosed`, + }, + onClose: { + action: `${prefix}-notification-closed`, + }, +}; + +export const Default = { + render: () => { + return html` + + Action + + `; + }, +}; + +export const Playground = { + args, + argTypes, + render: (args) => { + const { + actionButtonLabel, + closeOnEscape, + hasFocus, + kind, + title, + subtitle, + hideCloseButton, + lowContrast, + role, + inline, + statusIconDescription, + disableClose, + onBeforeClose = noop, + onClose = noop, + } = args ?? {}; + const handleBeforeClose = (event: CustomEvent) => { + onBeforeClose(event); + if (disableClose) { + event.preventDefault(); + } + }; + return html` + + ${actionButtonLabel} + + `; + }, +}; + +const meta = { + title: 'Components/Notifications/Actionable', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/notification/inline-notification-story.ts b/packages/carbon-web-components/src/components/notification/inline-notification-story.ts deleted file mode 100644 index 4113f290c22..00000000000 --- a/packages/carbon-web-components/src/components/notification/inline-notification-story.ts +++ /dev/null @@ -1,103 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { action } from '@storybook/addon-actions'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import { boolean, select } from '@storybook/addon-knobs'; -import storyDocs from './notification-story.mdx'; -import { NOTIFICATION_KIND } from './inline-notification'; -import { prefix } from '../../globals/settings'; -import textNullable from '../../../.storybook/knob-text-nullable'; -import kinds from './stories/helper'; - -const noop = () => {}; - -export const Default = () => { - return html` - - - `; -}; - -export const Playground = (args) => { - const { - kind, - title, - subtitle, - hideCloseButton, - lowContrast, - role, - statusIconDescription, - timeout, - disableClose, - onBeforeClose = noop, - onClose = noop, - } = args?.[`${prefix}-inline-notification`] ?? {}; - const handleBeforeClose = (event: CustomEvent) => { - onBeforeClose(event); - if (disableClose) { - event.preventDefault(); - } - }; - return html` - - - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-inline-notification`]: () => ({ - hideCloseButton: boolean( - 'Hide the close button (hide-close-button)', - false - ), - kind: select( - 'The notification kind (kind)', - kinds, - NOTIFICATION_KIND.INFO - ), - lowContrast: boolean('Use low contrast variant (low-contrast)', false), - role: select( - 'Role (role)', - { alert: 'alert', log: 'log', status: 'status' }, - 'status' - ), - statusIconDescription: textNullable( - 'statusIconDescription (status-icon-description)', - 'notification' - ), - subtitle: textNullable('Subtitle (subtitle)', 'Subtitle text goes here'), - title: textNullable('Title (title)', 'Notification title'), - onBeforeClose: action(`${prefix}-notification-beingclosed`), - onClose: action(`${prefix}-notification-closed`), - }), - }, -}; - -export default { - title: 'Components/Notifications/Inline', - parameters: { - ...storyDocs.parameters, - }, -}; diff --git a/packages/carbon-web-components/src/components/notification/inline-notification.stories.ts b/packages/carbon-web-components/src/components/notification/inline-notification.stories.ts new file mode 100644 index 00000000000..a1620eabd96 --- /dev/null +++ b/packages/carbon-web-components/src/components/notification/inline-notification.stories.ts @@ -0,0 +1,132 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { ifDefined } from 'lit/directives/if-defined.js'; +import storyDocs from './notification.mdx'; +import { NOTIFICATION_KIND } from './inline-notification'; +import { prefix } from '../../globals/settings'; +import kinds from './stories/helper'; + +const noop = () => {}; + +const args = { + hideCloseButton: false, + kind: NOTIFICATION_KIND.INFO, + lowContrast: false, + role: 'status', + statusIconDescription: 'notification', + subtitle: 'Subtitle text goes here', + title: 'Notification title', +}; + +const argTypes = { + hideCloseButton: { + control: 'boolean', + description: 'Specify the close button should be disabled, or not.', + }, + kind: { + control: 'select', + description: 'Specify what state the notification represents.', + options: kinds, + }, + lowContrast: { + control: 'boolean', + description: + 'Specify whether you are using the low contrast variant of the InlineNotification.', + }, + role: { + control: 'select', + description: + 'By default, this value is "status". You can also provide an alternate role if it makes sense from the accessibility-side.', + options: { alert: 'alert', log: 'log', status: 'status' }, + }, + statusIconDescription: { + control: 'text', + description: + 'Provide a description for "status" icon that can be read by screen readers.', + }, + subtitle: { + control: 'text', + description: 'Specify the subtitle.', + }, + title: { + control: 'text', + description: 'Specify the title.', + }, + onBeforeClose: { + action: `${prefix}-notification-beingclosed`, + }, + onClose: { + action: `${prefix}-notification-closed`, + }, +}; + +export const Default = { + render: () => { + return html` + + + `; + }, +}; + +export const Playground = { + args, + argTypes, + render: (args) => { + const { + kind, + title, + subtitle, + hideCloseButton, + lowContrast, + role, + statusIconDescription, + timeout, + disableClose, + onBeforeClose = noop, + onClose = noop, + } = args ?? {}; + const handleBeforeClose = (event: CustomEvent) => { + onBeforeClose(event); + if (disableClose) { + event.preventDefault(); + } + }; + return html` + + + `; + }, +}; + +const meta = { + title: 'Components/Notifications/Inline', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/notification/notification-story.mdx b/packages/carbon-web-components/src/components/notification/notification.mdx similarity index 91% rename from packages/carbon-web-components/src/components/notification/notification-story.mdx rename to packages/carbon-web-components/src/components/notification/notification.mdx index 2d9af6fe877..1e44aa7c14b 100644 --- a/packages/carbon-web-components/src/components/notification/notification-story.mdx +++ b/packages/carbon-web-components/src/components/notification/notification.mdx @@ -1,4 +1,7 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { + ArgsTable, + Markdown +} from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; # Notification @@ -27,8 +30,8 @@ import '@carbon/web-components/es/components/notification/index.js'; @use '@carbon/styles/scss/components/notification'; ``` - - +{`${cdnJs({ components: ['notification'] })}`} +{`${cdnCss()}`} ### HTML @@ -94,7 +97,7 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `open` attribute). - + ## `` attributes, properties and events @@ -102,7 +105,7 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `open` attribute). - + ## `` attributes, properties and events @@ -110,4 +113,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `open` attribute). - + diff --git a/packages/carbon-web-components/src/components/notification/toast-notification-story.ts b/packages/carbon-web-components/src/components/notification/toast-notification-story.ts deleted file mode 100644 index a09a1011f96..00000000000 --- a/packages/carbon-web-components/src/components/notification/toast-notification-story.ts +++ /dev/null @@ -1,111 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import { action } from '@storybook/addon-actions'; -import { boolean, select } from '@storybook/addon-knobs'; -import textNullable from '../../../.storybook/knob-text-nullable'; -import { NOTIFICATION_KIND } from './inline-notification'; -import './toast-notification'; -import storyDocs from './notification-story.mdx'; -import { prefix } from '../../globals/settings'; -import kinds from './stories/helper'; - -const noop = () => {}; - -export const Default = () => { - return html` - - - `; -}; - -export const Playground = (args) => { - const { - kind, - title, - subtitle, - caption, - hideCloseButton, - statusIconDescription, - lowContrast, - timeout, - role, - disableClose, - onBeforeClose = noop, - onClose = noop, - } = args?.[`${prefix}-toast-notification`] ?? {}; - const handleBeforeClose = (event: CustomEvent) => { - onBeforeClose(event); - if (disableClose) { - event.preventDefault(); - } - }; - return html` - - - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-toast-notification`]: () => ({ - caption: textNullable('Caption (caption)', '00:00:00 AM'), - hideCloseButton: boolean( - 'Hide the close button (hide-close-button)', - false - ), - kind: select( - 'The notification kind (kind)', - kinds, - NOTIFICATION_KIND.INFO - ), - lowContrast: boolean('Use low contrast variant (low-contrast)', false), - role: select( - 'Role (role)', - { alert: 'alert', log: 'log', status: 'status' }, - 'status' - ), - statusIconDescription: textNullable( - 'statusIconDescription (status-icon-description)', - 'notification' - ), - subtitle: textNullable('Subtitle (subtitle)', 'Subtitle text goes here'), - timeout: textNullable('Timeout in ms (timeout)', '0'), - title: textNullable('Title (title)', 'Notification title'), - onBeforeClose: action(`${prefix}-notification-beingclosed`), - onClose: action(`${prefix}-notification-closed`), - }), - }, -}; - -export default { - title: 'Components/Notifications/Toast', - parameters: { - ...storyDocs.parameters, - }, -}; diff --git a/packages/carbon-web-components/src/components/notification/toast-notification.stories.ts b/packages/carbon-web-components/src/components/notification/toast-notification.stories.ts new file mode 100644 index 00000000000..7af4034643b --- /dev/null +++ b/packages/carbon-web-components/src/components/notification/toast-notification.stories.ts @@ -0,0 +1,149 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { ifDefined } from 'lit/directives/if-defined.js'; +import { NOTIFICATION_KIND } from './inline-notification'; +import './toast-notification'; +import storyDocs from './notification.mdx'; +import { prefix } from '../../globals/settings'; +import kinds from './stories/helper'; + +const noop = () => {}; + +const args = { + caption: '00:00:00 AM', + hideCloseButton: false, + kind: NOTIFICATION_KIND.INFO, + lowContrast: false, + role: 'status', + statusIconDescription: 'notification', + subtitle: 'Subtitle text goes here', + timeout: '0', + title: 'Notification title', +}; + +const argTypes = { + caption: { + control: 'text', + description: 'Specify the caption.', + }, + hideCloseButton: { + control: 'boolean', + description: 'Specify the close button should be disabled, or not.', + }, + kind: { + control: 'select', + description: 'Specify what state the notification represents.', + options: kinds, + }, + lowContrast: { + control: 'boolean', + description: + 'Specify whether you are using the low contrast variant of the Toast Notification.', + }, + role: { + control: 'select', + description: + 'By default, this value is "status". You can also provide an alternate role if it makes sense from the accessibility-side.', + options: { alert: 'alert', log: 'log', status: 'status' }, + }, + statusIconDescription: { + control: 'text', + description: + 'Provide a description for "status" icon that can be read by screen readers.', + }, + subtitle: { + control: 'text', + description: 'Specify the subtitle.', + }, + timeout: { + control: 'text', + description: + 'Specify an optional duration the notification should be closed in.', + }, + title: { + control: 'text', + description: 'Specify the title.', + }, + onBeforeClose: { + action: `${prefix}-notification-beingclosed`, + }, + onClose: { + action: `${prefix}-notification-closed`, + }, +}; + +export const Default = { + render: () => { + return html` + + + `; + }, +}; + +export const Playground = { + args, + argTypes, + render: (args) => { + const { + kind, + title, + subtitle, + caption, + hideCloseButton, + statusIconDescription, + lowContrast, + timeout, + role, + disableClose, + onBeforeClose = noop, + onClose = noop, + } = args ?? {}; + const handleBeforeClose = (event: CustomEvent) => { + onBeforeClose(event); + if (disableClose) { + event.preventDefault(); + } + }; + return html` + + + `; + }, +}; + +const meta = { + title: 'Components/Notifications/Toast', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/number-input/number-input-story.ts b/packages/carbon-web-components/src/components/number-input/number-input-story.ts deleted file mode 100644 index d9511ad7d99..00000000000 --- a/packages/carbon-web-components/src/components/number-input/number-input-story.ts +++ /dev/null @@ -1,114 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import * as knobs from '@storybook/addon-knobs'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import { INPUT_SIZE } from '../text-input/text-input'; -import './number-input'; -import './number-input-skeleton'; -import '../form/form-item'; -import createProps from './stories/helpers'; -import storyDocs from './number-input-story.mdx'; -import { prefix } from '../../globals/settings'; - -export const Default = () => { - return html` - - - - - `; -}; - -Default.storyName = 'Default'; - -export const skeleton = () => - html` `; - -skeleton.parameters = { - percy: { - skip: true, - }, -}; - -export const Playground = (args) => { - const { - allowEmpty, - decrementButtonDescription, - incrementButtonDescription, - disabled, - helperText, - hideLabel, - hideSteppers, - invalid, - invalidText, - label, - readonly, - warn, - warnText, - value, - min, - max, - size, - step, - onInput, - } = args?.[`${prefix}-number-input`] ?? {}; - return html` - - - - - `; -}; - -Playground.storyName = 'Playground'; - -Playground.parameters = { - knobs: { - [`${prefix}-number-input`]: () => createProps({ ...knobs }), - }, -}; - -export default { - title: 'Components/Number Input', - parameters: { - ...storyDocs.parameters, - }, -}; diff --git a/packages/carbon-web-components/src/components/number-input/number-input-story.mdx b/packages/carbon-web-components/src/components/number-input/number-input.mdx similarity index 85% rename from packages/carbon-web-components/src/components/number-input/number-input-story.mdx rename to packages/carbon-web-components/src/components/number-input/number-input.mdx index c0f428ff0e9..e71ece78142 100644 --- a/packages/carbon-web-components/src/components/number-input/number-input-story.mdx +++ b/packages/carbon-web-components/src/components/number-input/number-input.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Markdown } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as NumberInputStories from './number-input.stories'; + + # Number input @@ -22,8 +25,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/number-input/index.js'; ``` - - +{`${cdnJs({ components: ['number-input'] })}`} +{`${cdnCss()}`} ### HTML @@ -72,4 +75,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `invalid` attribute). - + diff --git a/packages/carbon-web-components/src/components/number-input/number-input.stories.ts b/packages/carbon-web-components/src/components/number-input/number-input.stories.ts new file mode 100644 index 00000000000..c182e256f73 --- /dev/null +++ b/packages/carbon-web-components/src/components/number-input/number-input.stories.ts @@ -0,0 +1,220 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { ifDefined } from 'lit/directives/if-defined.js'; +import { INPUT_SIZE } from '../text-input/text-input'; +import './number-input'; +import './number-input-skeleton'; +import '../form/form-item'; +import storyDocs from './number-input.mdx'; + +const sizes = { + [`Small size (${INPUT_SIZE.SMALL})`]: INPUT_SIZE.SMALL, + [`Medium size (${INPUT_SIZE.MEDIUM})`]: INPUT_SIZE.MEDIUM, + [`Large size (${INPUT_SIZE.LARGE})`]: INPUT_SIZE.LARGE, +}; + +const args = { + allowEmpty: false, + decrementButtonDescription: 'decrease number input', + incrementButtonDescription: 'increase number input', + disabled: false, + helperText: 'Optional helper text', + hideLabel: false, + hideSteppers: false, + invalid: false, + invalidText: 'Number is not valid', + label: 'number-input label', + readOnly: false, + value: 50, + warn: false, + warnText: 'Warning text', + min: 0, + max: 100, + step: 1, + size: INPUT_SIZE.MEDIUM, +}; + +const argTypes = { + allowEmpty: { + control: 'boolean', + description: 'true to allow empty string.', + }, + decrementButtonDescription: { + control: 'text', + description: + 'Decrement button assistive description (decrement-button-assistive-text)', + }, + incrementButtonDescription: { + control: 'text', + description: + 'Increment button assistive description (increment-button-assistive-text)', + }, + disabled: { + control: 'boolean', + description: 'Specify if the control should be disabled, or not.', + }, + helperText: { + control: 'text', + description: + 'Provide text that is used alongside the control label for additional help.', + }, + hideLabel: { + control: 'boolean', + description: + 'Specify whether you want the underlying label to be visually hidden.', + }, + hideSteppers: { + control: 'boolean', + description: 'Specify whether you want the steppers to be hidden.', + }, + invalid: { + control: 'boolean', + description: 'Specify if the currently value is invalid.', + }, + invalidText: { + control: 'text', + description: 'Message which is displayed if the value is invalid.', + }, + label: { + control: 'text', + description: + 'Generic label that will be used as the textual representation of what this field is for.', + }, + readOnly: { + control: 'boolean', + description: 'Specify if the component should be read-only.', + }, + value: { + control: 'number', + description: 'Specify the value of the input.', + }, + warn: { + control: 'boolean', + description: 'Specify whether the control is currently in warning state.', + }, + warnText: { + control: 'text', + description: + 'Provide the text that is displayed when the control is in warning state.', + }, + min: { + control: 'number', + description: 'The minimum value.', + }, + max: { + control: 'number', + description: 'The maximum value.', + }, + step: { + control: 'number', + description: + 'Specify how much the values should increase/decrease upon clicking on up/down button.', + }, + size: { + control: 'select', + description: 'Specify the size of the Number Input.', + options: sizes, + }, + onInput: { + action: 'input', + }, +}; + +export const Default = { + render: () => { + return html` + + + + + `; + }, +}; + +export const Skeleton = { + parameters: { + percy: { + skip: true, + }, + }, + render: () => html` `, +}; + +export const Playground = { + args, + argTypes, + render: (args) => { + const { + allowEmpty, + decrementButtonDescription, + incrementButtonDescription, + disabled, + helperText, + hideLabel, + hideSteppers, + invalid, + invalidText, + label, + readOnly, + warn, + warnText, + value, + min, + max, + size, + step, + onInput, + } = args ?? {}; + return html` + + + + + `; + }, +}; + +export default { + title: 'Components/Number Input', + parameters: { + ...storyDocs.parameters, + }, +}; diff --git a/packages/carbon-web-components/src/components/number-input/stories/helpers.ts b/packages/carbon-web-components/src/components/number-input/stories/helpers.ts deleted file mode 100644 index 69e4d5ff194..00000000000 --- a/packages/carbon-web-components/src/components/number-input/stories/helpers.ts +++ /dev/null @@ -1,47 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { action } from '@storybook/addon-actions'; -import { INPUT_SIZE } from '../../text-input/text-input'; - -const sizes = { - [`Small size (${INPUT_SIZE.SMALL})`]: INPUT_SIZE.SMALL, - [`Medium size (${INPUT_SIZE.MEDIUM})`]: INPUT_SIZE.MEDIUM, - [`Large size (${INPUT_SIZE.LARGE})`]: INPUT_SIZE.LARGE, -}; - -const createProps = ({ boolean, number, select, text }) => ({ - allowEmpty: boolean('Allow empty (allow-empty)', false), - decrementButtonDescription: text( - 'Decrement button assistive description (decrement-button-assistive-text)', - 'decrease number input' - ), - incrementButtonDescription: text( - 'Increment button assistive description (increment-button-assistive-text)', - 'increase number input' - ), - disabled: boolean('Disabled (disabled)', false), - helperText: text('Helper text (helper-text)', 'Optional helper text'), - hideLabel: boolean('Hide label (hide-label)', false), - hideSteppers: boolean('Hide steppers (hide-steppers)', false), - invalid: boolean('Invalid (invalid)', false), - invalidText: text('Invalid text (invalid-text)', 'Number is not valid'), - label: text('Label (label)', 'number-input label'), - readonly: boolean('Read only (readonly)', false), - value: number('Value (value)', 50), - warn: boolean('Warn (warn)', false), - warnText: text('Warn text (warn-text)', 'Warning text'), - min: number('Minimum value (min)', 0), - max: number('Maximum value (max)', 100), - step: number('Value to step the input by (step)', 1), - size: select('Size (size)', sizes, INPUT_SIZE.MEDIUM), - onInput: action('input'), -}); - -export default createProps; diff --git a/packages/carbon-web-components/src/components/overflow-menu/overflow-menu-story.ts b/packages/carbon-web-components/src/components/overflow-menu/overflow-menu-story.ts deleted file mode 100644 index 03cd05e7fb0..00000000000 --- a/packages/carbon-web-components/src/components/overflow-menu/overflow-menu-story.ts +++ /dev/null @@ -1,119 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import { boolean, number, select } from '@storybook/addon-knobs'; -import textNullable from '../../../.storybook-backup/knob-text-nullable'; -import { OVERFLOW_MENU_SIZE } from './overflow-menu'; -import './overflow-menu-body'; -import './overflow-menu-item'; -import storyDocs from './overflow-menu-story.mdx'; -import { prefix } from '../../globals/settings'; -import OverflowMenuVertical16 from '@carbon/icons/lib/overflow-menu--vertical/16'; -import Filter16 from '@carbon/icons/lib/filter/16'; - -const sizes = { - [`Small size (${OVERFLOW_MENU_SIZE.SMALL})`]: OVERFLOW_MENU_SIZE.SMALL, - [`Medium size (default) (${OVERFLOW_MENU_SIZE.MEDIUM})`]: - OVERFLOW_MENU_SIZE.MEDIUM, - [`Lg size (${OVERFLOW_MENU_SIZE.LARGE})`]: OVERFLOW_MENU_SIZE.LARGE, -}; - -export const Default = () => { - return html` - - ${OverflowMenuVertical16({ - class: `${prefix}--overflow-menu__icon`, - slot: 'icon', - })} - Options - - Stop app - Restart app - Rename app - Clone and move app - Edit routes and access - Delete app - - - `; -}; - -export const renderCustomIcon = () => { - return html` - - ${Filter16({ - class: `${prefix}--overflow-menu__icon`, - slot: 'icon', - })} - Options - - Filter A - Filter B - - - `; -}; - -export const Playground = (args) => { - const { flipped, iconDescription, open, index, size } = - args?.[`${prefix}-overflow-menu`] ?? {}; - return html` - - ${OverflowMenuVertical16({ - class: `${prefix}--overflow-menu__icon`, - slot: 'icon', - })} - ${iconDescription} - - Stop app - Restart app - Rename app - Clone and move app - Edit routes and access - Delete app - - - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-overflow-menu`]: () => ({ - flipped: boolean('Flipped (flipped)', false), - iconDescription: textNullable( - 'Icon description (iconDescription)', - 'Options' - ), - open: boolean('Open (open)', false), - index: number('Index focus (index)', 1), - size: select( - 'Overflow menu size (size)', - sizes, - OVERFLOW_MENU_SIZE.MEDIUM - ), - }), - }, -}; - -export default { - title: 'Components/Overflow menu', - parameters: { - ...storyDocs.parameters, - }, -}; diff --git a/packages/carbon-web-components/src/components/overflow-menu/overflow-menu-story.mdx b/packages/carbon-web-components/src/components/overflow-menu/overflow-menu.mdx similarity index 84% rename from packages/carbon-web-components/src/components/overflow-menu/overflow-menu-story.mdx rename to packages/carbon-web-components/src/components/overflow-menu/overflow-menu.mdx index f573484e105..1ef3fad2bc6 100644 --- a/packages/carbon-web-components/src/components/overflow-menu/overflow-menu-story.mdx +++ b/packages/carbon-web-components/src/components/overflow-menu/overflow-menu.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Markdown } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as OverflowMenuStories from './overflow-menu.stories'; + + # Overflow menu @@ -24,8 +27,8 @@ import '@carbon/web-components/es/components/overflow-menu/index.js'; import OverflowMenuVertical16 from '@carbon/icons/lib/overflow-menu--vertical/16'; ``` - - +{`${cdnJs({ components: ['overflow-menu'] })}`} +{`${cdnCss()}`} ### HTML @@ -50,11 +53,11 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `open` attribute). - + ## `` attributes and properties - + ## `` attributes and properties @@ -62,4 +65,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `disabled` attribute). - + diff --git a/packages/carbon-web-components/src/components/overflow-menu/overflow-menu.stories.ts b/packages/carbon-web-components/src/components/overflow-menu/overflow-menu.stories.ts new file mode 100644 index 00000000000..dbf13824101 --- /dev/null +++ b/packages/carbon-web-components/src/components/overflow-menu/overflow-menu.stories.ts @@ -0,0 +1,146 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { ifDefined } from 'lit/directives/if-defined.js'; +import { OVERFLOW_MENU_SIZE } from './overflow-menu'; +import './overflow-menu-body'; +import './overflow-menu-item'; +import storyDocs from './overflow-menu.mdx'; +import { prefix } from '../../globals/settings'; +import OverflowMenuVertical16 from '@carbon/icons/lib/overflow-menu--vertical/16'; +import Filter16 from '@carbon/icons/lib/filter/16'; + +const sizes = { + [`Small size (${OVERFLOW_MENU_SIZE.SMALL})`]: OVERFLOW_MENU_SIZE.SMALL, + [`Medium size (default) (${OVERFLOW_MENU_SIZE.MEDIUM})`]: + OVERFLOW_MENU_SIZE.MEDIUM, + [`Lg size (${OVERFLOW_MENU_SIZE.LARGE})`]: OVERFLOW_MENU_SIZE.LARGE, +}; + +const args = { + flipped: false, + iconDescription: 'Options', + open: false, + index: 1, + size: OVERFLOW_MENU_SIZE.MEDIUM, +}; + +const argTypes = { + flipped: { + control: 'boolean', + description: 'true if the menu alignment should be flipped.', + }, + iconDescription: { + control: 'text', + description: 'The icon description.', + }, + open: { + control: 'boolean', + description: 'true if the menu should be open.\n', + }, + index: { + control: 'number', + description: 'The index for the item which should be focused in the menu.', + }, + size: { + control: 'select', + description: + 'Specify the size of the OverflowMenu. Currently supports either sm, md (default) or lg as an option.', + options: sizes, + }, +}; + +export const Default = { + render: () => { + return html` + + ${OverflowMenuVertical16({ + class: `${prefix}--overflow-menu__icon`, + slot: 'icon', + })} + Options + + Stop app + Restart app + Rename app + Clone and move app + Edit routes and access + Delete app + + + `; + }, +}; + +export const RenderCustomIcon = { + render: () => { + return html` + + ${Filter16({ + class: `${prefix}--overflow-menu__icon`, + slot: 'icon', + })} + Options + + Filter A + Filter B + + + `; + }, +}; + +export const Playground = { + args, + argTypes, + render: (args) => { + const { flipped, iconDescription, open, index, size } = args ?? {}; + return html` + + ${OverflowMenuVertical16({ + class: `${prefix}--overflow-menu__icon`, + slot: 'icon', + })} + ${iconDescription} + + Stop app + Restart app + Rename app + Clone and move app + Edit routes and access + Delete app + + + `; + }, +}; + +const meta = { + title: 'Components/Overflow Menu', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/progress-bar/progress-bar-story.ts b/packages/carbon-web-components/src/components/progress-bar/progress-bar-story.ts deleted file mode 100644 index b157d9420ff..00000000000 --- a/packages/carbon-web-components/src/components/progress-bar/progress-bar-story.ts +++ /dev/null @@ -1,146 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import { boolean, number, select } from '@storybook/addon-knobs'; -import textNullable from '../../../.storybook/knob-text-nullable'; -import { - PROGRESS_BAR_SIZE, - PROGRESS_BAR_STATUS, - PROGRESS_BAR_TYPE, -} from '../progress-bar/progress-bar'; -import './progress-bar'; -import '../../../.storybook/templates/with-layer'; -import storyDocs from './progress-bar-story.mdx'; -import { prefix } from '../../globals/settings'; - -const sizes = { - [`Small size (${PROGRESS_BAR_SIZE.SMALL})`]: PROGRESS_BAR_SIZE.SMALL, - [`Big size (${PROGRESS_BAR_SIZE.BIG})`]: PROGRESS_BAR_SIZE.BIG, -}; - -const status = { - [`Active (${PROGRESS_BAR_STATUS.ACTIVE})`]: PROGRESS_BAR_STATUS.ACTIVE, - [`Finished (${PROGRESS_BAR_STATUS.FINISHED})`]: PROGRESS_BAR_STATUS.FINISHED, - [`Error (${PROGRESS_BAR_STATUS.ERROR})`]: PROGRESS_BAR_STATUS.ERROR, -}; - -const types = { - [`Default (${PROGRESS_BAR_TYPE.DEFAULT})`]: PROGRESS_BAR_TYPE.DEFAULT, - [`Inline (${PROGRESS_BAR_TYPE.INLINE})`]: PROGRESS_BAR_TYPE.INLINE, - [`Indented (${PROGRESS_BAR_TYPE.INDENTED})`]: PROGRESS_BAR_TYPE.INDENTED, -}; - -export const Default = () => { - return html` - - - `; -}; - -export const Example = () => { - const size = 728; - let progress = 0; - - setTimeout(() => { - const bar = document.querySelector('cds-progress-bar'); - const interval = setInterval(() => { - const advancement = Math.random() * 8; - if (progress + advancement < size) { - progress = progress + advancement; - bar!.setAttribute('value', `${progress}`); - bar!.setAttribute( - 'helper-text', - `${progress.toFixed(1)}MB of ${size}MB` - ); - } else { - clearInterval(interval); - bar!.setAttribute('value', `${size}`); - bar!.setAttribute('status', `${PROGRESS_BAR_STATUS.FINISHED}`); - bar!.setAttribute('helper-text', 'Done'); - } - }, 50); - }, 3000); - - return html` - - - `; -}; - -export const Indeterminate = () => { - return html` - - - `; -}; - -export const WithLayer = () => { - return html` - - - - - `; -}; - -export const Playground = (args) => { - const { helperText, hideLabel, label, max, size, status, type, value } = - args?.[`${prefix}-progress-bar`] ?? {}; - return html` - - - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-progress-bar`]: () => ({ - helperText: textNullable( - 'Helper text (helper-text)', - 'Optional helper text' - ), - hideLabel: boolean('Hide label (hide-label)', false), - label: textNullable('Label (label)', 'Progress bar label'), - max: number('Max (max)', 100), - size: select('Size (size)', sizes, PROGRESS_BAR_SIZE.BIG), - status: select('Status (status)', status, PROGRESS_BAR_STATUS.ACTIVE), - type: select('Type (type)', types, PROGRESS_BAR_TYPE.DEFAULT), - value: number('Value (value)', 75), - }), - }, -}; - -export default { - title: 'Components/Progress bar', - parameters: { - ...storyDocs.parameters, - }, -}; diff --git a/packages/carbon-web-components/src/components/progress-bar/progress-bar-story.mdx b/packages/carbon-web-components/src/components/progress-bar/progress-bar.mdx similarity index 85% rename from packages/carbon-web-components/src/components/progress-bar/progress-bar-story.mdx rename to packages/carbon-web-components/src/components/progress-bar/progress-bar.mdx index 39d258ca9b6..d0bbc4db3b1 100644 --- a/packages/carbon-web-components/src/components/progress-bar/progress-bar-story.mdx +++ b/packages/carbon-web-components/src/components/progress-bar/progress-bar.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Markdown } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as ProgressBarStories from './progress-bar.stories'; + + # Progress bar @@ -24,8 +27,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/progress-bar/index.js'; ``` - - +{`${cdnJs({ components: ['progress-bar'] })}`} +{`${cdnCss()}`} ### HTML @@ -58,4 +61,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `hide-label` attribute). - + diff --git a/packages/carbon-web-components/src/components/progress-bar/progress-bar.stories.ts b/packages/carbon-web-components/src/components/progress-bar/progress-bar.stories.ts new file mode 100644 index 00000000000..8fae7089a36 --- /dev/null +++ b/packages/carbon-web-components/src/components/progress-bar/progress-bar.stories.ts @@ -0,0 +1,190 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { ifDefined } from 'lit/directives/if-defined.js'; +import { + PROGRESS_BAR_SIZE, + PROGRESS_BAR_STATUS, + PROGRESS_BAR_TYPE, +} from '../progress-bar/progress-bar'; +import './progress-bar'; +import '../../../.storybook/templates/with-layer'; +import storyDocs from './progress-bar.mdx'; + +const sizes = { + [`Small size (${PROGRESS_BAR_SIZE.SMALL})`]: PROGRESS_BAR_SIZE.SMALL, + [`Big size (${PROGRESS_BAR_SIZE.BIG})`]: PROGRESS_BAR_SIZE.BIG, +}; + +const status = { + [`Active (${PROGRESS_BAR_STATUS.ACTIVE})`]: PROGRESS_BAR_STATUS.ACTIVE, + [`Finished (${PROGRESS_BAR_STATUS.FINISHED})`]: PROGRESS_BAR_STATUS.FINISHED, + [`Error (${PROGRESS_BAR_STATUS.ERROR})`]: PROGRESS_BAR_STATUS.ERROR, +}; + +const types = { + [`Default (${PROGRESS_BAR_TYPE.DEFAULT})`]: PROGRESS_BAR_TYPE.DEFAULT, + [`Inline (${PROGRESS_BAR_TYPE.INLINE})`]: PROGRESS_BAR_TYPE.INLINE, + [`Indented (${PROGRESS_BAR_TYPE.INDENTED})`]: PROGRESS_BAR_TYPE.INDENTED, +}; + +const args = { + helperText: 'Optional helper text', + hideLabel: false, + label: 'Progress bar label', + max: 100, + size: PROGRESS_BAR_SIZE.BIG, + status: PROGRESS_BAR_STATUS.ACTIVE, + type: PROGRESS_BAR_TYPE.DEFAULT, + value: 75, +}; + +const argTypes = { + helperText: { + control: 'text', + description: 'The current progress as a textual representation.', + }, + hideLabel: { + control: 'boolean', + description: 'Whether the label should be visually hidden.', + }, + label: { + control: 'text', + description: 'A label describing the progress bar.', + }, + max: { + control: 'number', + description: 'The maximum value.', + }, + size: { + control: 'select', + description: 'Specify the size of the progress bar.', + options: sizes, + }, + status: { + control: 'select', + description: 'Specify the status.', + options: status, + }, + type: { + control: 'select', + description: 'Defines the alignment variant of the progress bar.', + options: types, + }, + value: { + control: 'number', + description: 'The current value.', + }, +}; + +export const Default = { + render: () => { + return html` + + + `; + }, +}; + +export const Example = { + render: () => { + const size = 728; + let progress = 0; + + setTimeout(() => { + const bar = document.querySelector('cds-progress-bar'); + const interval = setInterval(() => { + const advancement = Math.random() * 8; + if (progress + advancement < size) { + progress = progress + advancement; + bar!.setAttribute('value', `${progress}`); + bar!.setAttribute( + 'helper-text', + `${progress.toFixed(1)}MB of ${size}MB` + ); + } else { + clearInterval(interval); + bar!.setAttribute('value', `${size}`); + bar!.setAttribute('status', `${PROGRESS_BAR_STATUS.FINISHED}`); + bar!.setAttribute('helper-text', 'Done'); + } + }, 50); + }, 3000); + + return html` + + + `; + }, +}; + +export const Indeterminate = { + render: () => { + return html` + + + `; + }, +}; + +export const WithLayer = { + render: () => { + return html` + + + + + `; + }, +}; + +export const Playground = { + args, + argTypes, + render: (args) => { + const { helperText, hideLabel, label, max, size, status, type, value } = + args ?? {}; + return html` + + + `; + }, +}; + +const meta = { + title: 'Components/Progress Bar', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/progress-indicator/progress-indicator-story.ts b/packages/carbon-web-components/src/components/progress-indicator/progress-indicator-story.ts deleted file mode 100644 index 854aab154e0..00000000000 --- a/packages/carbon-web-components/src/components/progress-indicator/progress-indicator-story.ts +++ /dev/null @@ -1,140 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import { boolean } from '@storybook/addon-knobs'; -import textNullable from '../../../.storybook/knob-text-nullable'; -import './progress-indicator'; -import './progress-step'; -import './progress-indicator-skeleton'; -import './progress-step-skeleton'; -import storyDocs from './progress-indicator-story.mdx'; -import { prefix } from '../../globals/settings'; - -export const Default = () => html` - - - - - - - -`; - -export const Interactive = () => html` - - - - - -`; - -export const Playground = (args) => { - const { vertical, spaceEqually } = - args?.[`${prefix}-progress-indicator`] ?? {}; - const { iconLabel, secondaryLabelText } = - args?.[`${prefix}-progress-step`] ?? {}; - return html` - - - - - - - - `; -}; - -Playground.parameters = { - ...storyDocs.parameters, - knobs: { - [`${prefix}-progress-indicator`]: () => ({ - vertical: boolean('Vertical (vertical)', false), - spaceEqually: boolean('Space equally (space-equally)', false), - }), - [`${prefix}-progress-step`]: () => ({ - description: textNullable('Icon label (description)', ''), - secondaryLabelText: textNullable( - 'Secondary label text (secondary-label)', - 'Optional label' - ), - }), - }, -}; - -export const skeleton = (args) => { - const { vertical } = args?.[`${prefix}-progress-indicator-skeleton`]; - return html` - - - - - - - `; -}; - -skeleton.parameters = { - percy: { - skip: true, - }, - knobs: { - [`${prefix}-progress-indicator-skeleton`]: () => ({ - vertical: boolean('Vertical (vertical)', false), - }), - }, -}; - -export default { - title: 'Components/Progress indicator', -}; diff --git a/packages/carbon-web-components/src/components/progress-indicator/progress-indicator-story.mdx b/packages/carbon-web-components/src/components/progress-indicator/progress-indicator.mdx similarity index 87% rename from packages/carbon-web-components/src/components/progress-indicator/progress-indicator-story.mdx rename to packages/carbon-web-components/src/components/progress-indicator/progress-indicator.mdx index a816f37957d..cf90dc441c7 100644 --- a/packages/carbon-web-components/src/components/progress-indicator/progress-indicator-story.mdx +++ b/packages/carbon-web-components/src/components/progress-indicator/progress-indicator.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Description, Markdown } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as ProgressIndicatorStories from './progress-indicator.stories'; + + # Progress indicator @@ -27,8 +30,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/progress-indicator/index.js'; ``` - - +{`${cdnJs({ components: ['progress-indicator'] })}`} +{`${cdnCss()}`} ### HTML @@ -75,7 +78,7 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `vertical` attribute). - + ## `` attributes and properties @@ -83,4 +86,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `disabled` attribute). - + diff --git a/packages/carbon-web-components/src/components/progress-indicator/progress-indicator.stories.ts b/packages/carbon-web-components/src/components/progress-indicator/progress-indicator.stories.ts new file mode 100644 index 00000000000..236d0b9c1c4 --- /dev/null +++ b/packages/carbon-web-components/src/components/progress-indicator/progress-indicator.stories.ts @@ -0,0 +1,161 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { ifDefined } from 'lit/directives/if-defined.js'; +import './index'; +import storyDocs from './progress-indicator.mdx'; +import ifNonEmpty from '../../globals/directives/if-non-empty'; + +const args = { + vertical: false, + spaceEqually: false, + iconLabel: '', + secondaryLabelText: 'Optional label', +}; + +const argTypes = { + vertical: { + control: 'boolean', + description: + 'Determines whether or not the Progress Indicator should be rendered vertically.', + }, + spaceEqually: { + control: 'boolean', + description: + 'Specify whether the progress steps should be split equally in size in the div.', + }, + iconLabel: { + control: 'text', + description: 'Label used for the SVG icons in each step.', + }, + secondaryLabelText: { + control: 'text', + description: 'The secondary progress label.', + }, +}; + +export const Default = { + render: () => html` + + + + + + + + `, +}; + +export const Interactive = { + render: () => html` + + + + + + `, +}; + +export const Skeleton = { + args: { + vertical: args['vertical'], + }, + argTypes: { + vertical: args['vertical'], + }, + parameters: { + percy: { + skip: true, + }, + }, + render: (args) => { + const { vertical } = args ?? {}; + return html` + + + + + + + `; + }, +}; + +export const Playground = { + args, + argTypes, + render: (args) => { + const { iconLabel, secondaryLabelText, spaceEqually, vertical } = + args ?? {}; + return html` + + + + + + + + `; + }, +}; + +const meta = { + title: 'Components/Progress Indicator', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/search/search-story.ts b/packages/carbon-web-components/src/components/search/search-story.ts deleted file mode 100644 index ecaf42a43a4..00000000000 --- a/packages/carbon-web-components/src/components/search/search-story.ts +++ /dev/null @@ -1,152 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import { boolean, number, select } from '@storybook/addon-knobs'; -import textNullable from '../../../.storybook/knob-text-nullable'; -import { INPUT_SIZE } from '../text-input/text-input'; -import './search-skeleton'; -import storyDocs from './search-story.mdx'; -import { prefix } from '../../globals/settings'; -import '../layer'; -import '../../../.storybook/templates/with-layer'; - -const sizes = { - [`Small size (${INPUT_SIZE.SMALL})`]: INPUT_SIZE.SMALL, - [`Medium size (${INPUT_SIZE.MEDIUM})`]: INPUT_SIZE.MEDIUM, - [`Large size (${INPUT_SIZE.LARGE})`]: INPUT_SIZE.LARGE, -}; - -const widthSliderOptions = { - range: true, - min: 300, - max: 800, - step: 50, -}; - -export const Default = () => { - return html` - - `; -}; - -export const Disabled = () => { - return html` - - `; -}; - -export const Expandable = () => { - return html` - - `; -}; - -export const ExpandableWithLayer = () => { - return html` - - - - `; -}; - -export const WithLayer = () => { - return html` - - - - `; -}; - -export const Playground = (args) => { - const { - autoComplete, - closeButtonLabelText, - colorScheme, - disabled, - labelText, - placeholder, - playgroundWidth, - size, - role, - type, - value, - onInput, - } = args?.[`${prefix}-search`] ?? {}; - - const mainDiv = document.querySelector('#main-content'); - - if (mainDiv) { - (mainDiv as HTMLElement).style.width = `${playgroundWidth}px`; - } - - return html` - - - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-search`]: () => ({ - autoComplete: textNullable('Autocomplete (autocomplete)', 'off'), - closeButtonLabelText: textNullable( - 'The label text for the close button (close-button-label-text)', - 'Clear search input' - ), - disabled: boolean('Disabled (disabled)', false), - labelText: textNullable('Label text (label-text)', 'Search'), - placeholder: textNullable( - 'Placeholder text (placeholder)', - 'Placeholder text' - ), - playgroundWidth: number('Playground width', 300, widthSliderOptions), - role: textNullable('The role of the (role)', 'searchbox'), - size: select('Search size (size)', sizes, null), - type: textNullable('The type of the (type)', 'text'), - value: textNullable('Value (value)', 'Default value'), - }), - }, -}; - -export default { - title: 'Components/Search', - parameters: { - ...storyDocs.parameters, - }, -}; diff --git a/packages/carbon-web-components/src/components/search/search-story.mdx b/packages/carbon-web-components/src/components/search/search.mdx similarity index 83% rename from packages/carbon-web-components/src/components/search/search-story.mdx rename to packages/carbon-web-components/src/components/search/search.mdx index 7677aad5c2e..86f1aa8c1d4 100644 --- a/packages/carbon-web-components/src/components/search/search-story.mdx +++ b/packages/carbon-web-components/src/components/search/search.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Markdown } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as SearchStories from './search.stories'; + + # Search @@ -24,8 +27,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/search/index.js'; ``` - - +{`${cdnJs({ components: ['search'] })}`} +{`${cdnCss()}`} ### HTML @@ -47,4 +50,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `light` attribute). - + diff --git a/packages/carbon-web-components/src/components/search/search.stories.ts b/packages/carbon-web-components/src/components/search/search.stories.ts new file mode 100644 index 00000000000..446e5c9ef92 --- /dev/null +++ b/packages/carbon-web-components/src/components/search/search.stories.ts @@ -0,0 +1,201 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { ifDefined } from 'lit/directives/if-defined.js'; +import { INPUT_SIZE } from '../text-input/text-input'; +import './search-skeleton'; +import storyDocs from './search.mdx'; +import '../layer'; +import '../../../.storybook/templates/with-layer'; +import './index'; + +const sizes = { + [`Small size (${INPUT_SIZE.SMALL})`]: INPUT_SIZE.SMALL, + [`Medium size (${INPUT_SIZE.MEDIUM})`]: INPUT_SIZE.MEDIUM, + [`Large size (${INPUT_SIZE.LARGE})`]: INPUT_SIZE.LARGE, +}; + +const args = { + autoComplete: 'off', + closeButtonLabelText: 'Clear search input', + disabled: false, + labelText: 'Search', + placeholder: 'Placeholder text', + playgroundWidth: 300, + role: 'searchbox', + size: null, + type: 'text', + value: 'Default value', +}; + +const argTypes = { + autoComplete: { + control: 'text', + description: + 'Specify an optional value for the autocomplete property on the underlying <input>, defaults to "off".', + }, + closeButtonLabelText: { + control: 'text', + description: + 'Specify a label to be read by screen readers on the "close" button.', + }, + disabled: { + control: 'boolean', + description: + 'Specify whether the <input> should be disabled.', + }, + labelText: { + control: 'text', + description: 'Provide the label text for the Search icon.', + }, + placeholder: { + control: 'text', + description: + 'Provide an optional placeholder text for the Search. Note: if the label and placeholder differ, VoiceOver on Mac will read both.', + }, + playgroundWidth: { + control: { type: 'range', min: 300, max: 800, step: 50 }, + description: 'Playground width', + }, + role: { + control: 'text', + description: + 'Specify the role for the underlying <input>, defaults to searchbox.', + }, + size: { + control: 'select', + description: 'Specify the size of the Search.', + options: sizes, + }, + type: { + control: 'text', + description: + 'Optional prop to specify the type of the <input>.', + }, + value: { + control: 'text', + description: 'Specify the value of the <input>.', + }, +}; + +export const Default = { + render: () => { + return html` + + `; + }, +}; + +export const Disabled = { + render: () => { + return html` + + `; + }, +}; + +export const Expandable = { + render: () => { + return html` + + `; + }, +}; + +export const ExpandableWithLayer = { + render: () => { + return html` + + + + `; + }, +}; + +export const WithLayer = { + render: () => { + return html` + + + + `; + }, +}; + +export const Playground = { + args, + argTypes, + render: (args) => { + const { + autoComplete, + closeButtonLabelText, + colorScheme, + disabled, + labelText, + placeholder, + playgroundWidth, + size, + role, + type, + value, + onInput, + } = args ?? {}; + + const mainDiv = document.querySelector('#main-content'); + + if (mainDiv) { + (mainDiv as HTMLElement).style.width = `${playgroundWidth}px`; + } + + return html` + + + `; + }, +}; + +const meta = { + title: 'Components/Search', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/select/select-story.ts b/packages/carbon-web-components/src/components/select/select-story.ts deleted file mode 100644 index 8e55c291409..00000000000 --- a/packages/carbon-web-components/src/components/select/select-story.ts +++ /dev/null @@ -1,198 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2020, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import { action } from '@storybook/addon-actions'; -import { boolean, select } from '@storybook/addon-knobs'; -import textNullable from '../../../.storybook/knob-text-nullable'; -// Below path will be there when an application installs `carbon-web-components` package. -// In our dev env, we auto-generate the file and re-map below path to to point to the generated file. -// @ts-ignore -import { prefix } from '../../globals/settings'; -import { INPUT_SIZE } from '../text-input/text-input'; -import './select'; -import './select-item-group'; -import './select-item'; -import './select-skeleton'; -import '../form/form-item'; -import '../layer'; -import '../../../.storybook/templates/with-layer'; - -import storyDocs from './select-story.mdx'; - -const sizes = { - [`Small size (${INPUT_SIZE.SMALL})`]: INPUT_SIZE.SMALL, - [`Medium size (${INPUT_SIZE.MEDIUM})`]: INPUT_SIZE.MEDIUM, - [`Large size (${INPUT_SIZE.LARGE})`]: INPUT_SIZE.LARGE, -}; - -export const Default = () => { - return html` - - - - Option 1 - Option 2 - - - Option 3 - Option 4 - Option 5 - - - - `; -}; - -export const Inline = () => { - return html` - - - - Option 1 - Option 2 - - - Option 3 - Option 4 - Option 5 - - - - `; -}; - -export const skeleton = () => - html` `; - -skeleton.parameters = { - percy: { - skip: true, - }, -}; - -export const WithLayer = () => { - return html` - - - - Option 1 - Option 2 - - - Option 3 - Option 4 - Option 5 - - - - `; -}; - -export const Playground = (args) => { - const { - disabled, - helperText, - hideLabel, - inline, - invalid, - invalidText, - labelText, - name, - placeholder, - size, - readonly, - warn, - warnText, - value, - children = html` - - Option 1 - Option 2 - - - Option 3 - Option 4 - Option 5 - - `, - onInput, - } = args?.[`${prefix}-select`] ?? {}; - return html` - - - ${children} - - - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-select`]: () => ({ - disabled: boolean('Disabled (disabled)', false), - helperText: textNullable( - 'Helper text (helper-text)', - 'Optional helper text' - ), - hideLabel: boolean('Hide label (hide-label)', false), - inline: boolean('Inline (inline)', false), - invalid: boolean('Invalid (invalid)', false), - invalidText: textNullable('Invalid text (invalid-text)', 'Error message'), - labelText: textNullable('Label text (label-text)', 'Select an option'), - placeholder: textNullable( - 'Placeholder (placeholder)', - 'Choose an option' - ), - size: select('size (size)', sizes, INPUT_SIZE.MEDIUM), - readonly: boolean('Read only (readonly)', false), - warn: boolean('Warn (warn)', false), - warnText: textNullable('Warn text (warn-text)', 'Warning message'), - value: textNullable('The value of the selected item (value)', ''), - onInput: action(`${prefix}-select-selected`), - }), - }, -}; - -export default { - title: 'Components/Select', - parameters: { - ...storyDocs.parameters, - }, - decorators: [ - (story) => { - return html`
${story()}
`; - }, - ], -}; diff --git a/packages/carbon-web-components/src/components/select/select-story.mdx b/packages/carbon-web-components/src/components/select/select.mdx similarity index 86% rename from packages/carbon-web-components/src/components/select/select-story.mdx rename to packages/carbon-web-components/src/components/select/select.mdx index 6f0176d0686..cd2445809e2 100644 --- a/packages/carbon-web-components/src/components/select/select-story.mdx +++ b/packages/carbon-web-components/src/components/select/select.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Markdown } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as SelectStories from './select.stories'; + + # Select @@ -22,8 +25,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/select/index.js'; ``` - - +{`${cdnJs({ components: ['select'] })}`} +{`${cdnCss()}`} ### HTML @@ -50,7 +53,7 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `autofocus` attribute). - + ## `` attributes, properties and events @@ -58,7 +61,7 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `disabled` attribute). - + ## `` attributes, properties and events @@ -66,4 +69,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `disabled` attribute). - + diff --git a/packages/carbon-web-components/src/components/select/select.stories.ts b/packages/carbon-web-components/src/components/select/select.stories.ts new file mode 100644 index 00000000000..4f4ecf78730 --- /dev/null +++ b/packages/carbon-web-components/src/components/select/select.stories.ts @@ -0,0 +1,258 @@ +/** + * @license + * + * Copyright IBM Corp. 2020, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { ifDefined } from 'lit/directives/if-defined.js'; +// Below path will be there when an application installs `carbon-web-components` package. +// In our dev env, we auto-generate the file and re-map below path to to point to the generated file. +// @ts-ignore +import { prefix } from '../../globals/settings'; +import { INPUT_SIZE } from '../text-input/text-input'; +import './index'; +import '../form/form-item'; +import '../layer'; +import '../../../.storybook/templates/with-layer'; + +import storyDocs from './select.mdx'; + +const sizes = { + [`Small size (${INPUT_SIZE.SMALL})`]: INPUT_SIZE.SMALL, + [`Medium size (${INPUT_SIZE.MEDIUM})`]: INPUT_SIZE.MEDIUM, + [`Large size (${INPUT_SIZE.LARGE})`]: INPUT_SIZE.LARGE, +}; + +const args = { + disabled: false, + helperText: 'Optional helper text', + hideLabel: false, + inline: false, + invalid: false, + invalidText: 'Error message', + labelText: 'Select an option', + placeholder: 'Choose an option', + size: INPUT_SIZE.MEDIUM, + readOnly: false, + warn: false, + warnText: 'Warning message', + value: '', +}; + +const argTypes = { + disabled: { + control: 'boolean', + description: 'Specify whether the control is disabled.', + }, + helperText: { + control: 'text', + description: + 'Provide text that is used alongside the control label for additional help.', + }, + hideLabel: { + control: 'boolean', + description: 'Specify whether the label should be hidden, or not.', + }, + inline: { + control: 'boolean', + description: 'Specify whether you want the inline version of this control.', + }, + invalid: { + control: 'boolean', + description: 'Specify if the currently value is invalid.', + }, + invalidText: { + control: 'text', + description: 'Message which is displayed if the value is invalid.', + }, + labelText: { + control: 'text', + description: + 'Provide label text to be read by screen readers when interacting with the control.', + }, + placeholder: { + control: 'text', + description: + 'Placeholder text to be used with the <input>.', + }, + size: { + control: 'select', + description: 'Specify the size of the Select Input.', + options: sizes, + }, + readOnly: { + control: 'boolean', + description: 'Whether the select should be read-only.', + }, + warn: { + control: 'boolean', + description: 'Specify whether the control is currently in warning state.', + }, + warnText: { + control: 'text', + description: + 'Provide the text that is displayed when the control is in warning state.', + }, + value: { + control: 'text', + description: 'The value of the selected item.', + }, + onInput: { + action: `${prefix}-select-selected`, + }, +}; + +export const Default = { + render: () => { + return html` + + + + Option 1 + Option 2 + + + Option 3 + Option 4 + Option 5 + + + + `; + }, +}; + +export const Inline = { + render: () => { + return html` + + + + Option 1 + Option 2 + + + Option 3 + Option 4 + Option 5 + + + + `; + }, +}; + +export const Skeleton = { + parameters: { + percy: { + skip: true, + }, + }, + render: () => html` `, +}; + +export const WithLayer = { + render: () => { + return html` + + + + Option 1 + Option 2 + + + Option 3 + Option 4 + Option 5 + + + + `; + }, +}; + +export const Playground = { + args, + argTypes, + render: (args) => { + const { + disabled, + helperText, + hideLabel, + inline, + invalid, + invalidText, + labelText, + name, + placeholder, + size, + readOnly, + warn, + warnText, + value, + children = html` + + Option 1 + Option 2 + + + Option 3 + Option 4 + Option 5 + + `, + onInput, + } = args ?? {}; + return html` + + + ${children} + + + `; + }, +}; + +const meta = { + decorators: [ + (story) => { + return html`
${story()}
`; + }, + ], + title: 'Components/Select', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/select/select.ts b/packages/carbon-web-components/src/components/select/select.ts index 3bc40ee58cd..a21f1d03648 100644 --- a/packages/carbon-web-components/src/components/select/select.ts +++ b/packages/carbon-web-components/src/components/select/select.ts @@ -1,7 +1,7 @@ /** * @license * - * Copyright IBM Corp. 2020, 2023 + * Copyright IBM Corp. 2020, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. @@ -295,7 +295,7 @@ class CDSSelect extends FormMixin(LitElement) { */ @property({ type: Number }) get selectedIndex() { - return this._selectNode.selectedIndex; + return this._selectNode?.selectedIndex; } set selectedIndex(value) { diff --git a/packages/carbon-web-components/src/components/skeleton-placeholder/skeleton-placeholder-story.ts b/packages/carbon-web-components/src/components/skeleton-placeholder/skeleton-placeholder-story.ts deleted file mode 100644 index 9cb37821bdf..00000000000 --- a/packages/carbon-web-components/src/components/skeleton-placeholder/skeleton-placeholder-story.ts +++ /dev/null @@ -1,30 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import './skeleton-placeholder'; -import storyDocs from './skeleton-placeholder-story.mdx'; - -export const Default = () => - html``; - -Default.storyName = 'Default'; - -Default.parameters = { - percy: { - skip: true, - }, -}; - -export default { - title: 'Components/Skeleton/Skeleton placeholder', - parameters: { - ...storyDocs.parameters, - }, -}; diff --git a/packages/carbon-web-components/src/components/skeleton-placeholder/skeleton-placeholder-story.mdx b/packages/carbon-web-components/src/components/skeleton-placeholder/skeleton-placeholder.mdx similarity index 72% rename from packages/carbon-web-components/src/components/skeleton-placeholder/skeleton-placeholder-story.mdx rename to packages/carbon-web-components/src/components/skeleton-placeholder/skeleton-placeholder.mdx index fcb3bf9676e..ef10759a074 100644 --- a/packages/carbon-web-components/src/components/skeleton-placeholder/skeleton-placeholder-story.mdx +++ b/packages/carbon-web-components/src/components/skeleton-placeholder/skeleton-placeholder.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Markdown } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as SkeletonPlaceholderStories from './skeleton-placeholder.stories'; + + # Skeleton placeholder @@ -19,8 +22,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/skeleton-placeholder/index.js'; ``` - - +{`${cdnJs({ components: ['skeleton-placeholder'] })}`} +{`${cdnCss()}`} ### HTML @@ -30,4 +33,4 @@ import '@carbon/web-components/es/components/skeleton-placeholder/index.js'; ## `` attributes, properties and events - + diff --git a/packages/carbon-web-components/src/components/skeleton-placeholder/skeleton-placeholder.stories.ts b/packages/carbon-web-components/src/components/skeleton-placeholder/skeleton-placeholder.stories.ts new file mode 100644 index 00000000000..0d455f997b1 --- /dev/null +++ b/packages/carbon-web-components/src/components/skeleton-placeholder/skeleton-placeholder.stories.ts @@ -0,0 +1,32 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import './skeleton-placeholder'; +import storyDocs from './skeleton-placeholder.mdx'; + +export const Default = { + parameters: { + percy: { + skip: true, + }, + }, + render: () => html``, +}; + +const meta = { + title: 'Components/Skeleton/Skeleton Placeholder', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/skeleton-text/skeleton-text-story.ts b/packages/carbon-web-components/src/components/skeleton-text/skeleton-text-story.ts deleted file mode 100644 index 032c03c4dbc..00000000000 --- a/packages/carbon-web-components/src/components/skeleton-text/skeleton-text-story.ts +++ /dev/null @@ -1,67 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { boolean, number, select, text } from '@storybook/addon-knobs'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import { prefix } from '../../globals/settings'; -import { SKELETON_TEXT_TYPE } from './skeleton-text'; -import storyDocs from './skeleton-text-story.mdx'; - -const types = { - Regular: null, - [`Heading (${SKELETON_TEXT_TYPE.HEADING})`]: SKELETON_TEXT_TYPE.HEADING, -}; - -export const Default = () => html` `; - -Default.storyName = 'Default'; - -Default.parameters = { - percy: { - skip: true, - }, -}; - -export const Playground = (args) => { - const { type, paragraph, lineCount, width } = - args?.[`${prefix}-skeleton-text`] ?? {}; - return html` - - - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-skeleton-text`]: () => ({ - type: select('Skeleton text type (type)', types, null), - paragraph: boolean('Use multiple lines of text (paragraph)', true), - lineCount: number('The number of lines in a paragraph (lineCount)', 3), - width: text( - 'Width (in px or %) of single line of text or max-width of paragraph lines (width)', - '100%' - ), - }), - }, -}; - -export default { - title: 'Components/Skeleton/Skeleton text', - parameters: { - ...storyDocs.parameters, - percy: { - skip: true, - }, - }, -}; diff --git a/packages/carbon-web-components/src/components/skeleton-text/skeleton-text-story.mdx b/packages/carbon-web-components/src/components/skeleton-text/skeleton-text.mdx similarity index 78% rename from packages/carbon-web-components/src/components/skeleton-text/skeleton-text-story.mdx rename to packages/carbon-web-components/src/components/skeleton-text/skeleton-text.mdx index 860c3aee993..6a523900234 100644 --- a/packages/carbon-web-components/src/components/skeleton-text/skeleton-text-story.mdx +++ b/packages/carbon-web-components/src/components/skeleton-text/skeleton-text.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Markdown } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as SkeletonTextStories from './skeleton-text.stories'; + + # Skeleton text @@ -19,8 +22,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/skeleton-text/index.js'; ``` - - +{`${cdnJs({ components: ['skeleton-text'] })}`} +{`${cdnCss()}`} ### HTML @@ -41,4 +44,4 @@ multiple instances of ``. ## `` attributes and properties - + diff --git a/packages/carbon-web-components/src/components/skeleton-text/skeleton-text.stories.ts b/packages/carbon-web-components/src/components/skeleton-text/skeleton-text.stories.ts new file mode 100644 index 00000000000..107efa685ff --- /dev/null +++ b/packages/carbon-web-components/src/components/skeleton-text/skeleton-text.stories.ts @@ -0,0 +1,85 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { ifDefined } from 'lit/directives/if-defined.js'; +import { SKELETON_TEXT_TYPE } from './skeleton-text'; +import storyDocs from './skeleton-text.mdx'; + +const types = { + Regular: null, + [`Heading (${SKELETON_TEXT_TYPE.HEADING})`]: SKELETON_TEXT_TYPE.HEADING, +}; + +const args = { + type: null, + paragraph: true, + lineCount: 3, + width: '100%', +}; + +const argTypes = { + type: { + control: 'select', + description: 'Indicate the type of skeleton text, heading or regular.', + options: types, + }, + paragraph: { + control: 'boolean', + description: 'Set this to true to generate multiple lines of text.', + }, + lineCount: { + control: 'number', + description: 'The number of lines shown if paragraph is true.', + }, + width: { + control: 'text', + description: + 'Width (in px or %) of single line of text or max-width of paragraph lines.', + }, +}; + +export const Default = { + parameters: { + percy: { + skip: true, + }, + }, + render: () => html``, +}; + +export const Playground = { + args, + argTypes, + render: (args) => { + const { type, paragraph, lineCount, width } = args ?? {}; + return html` + + + `; + }, +}; + +const meta = { + title: 'Components/Skeleton/Skeleton Text', + parameters: { + docs: { + page: storyDocs, + }, + percy: { + skip: true, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/skip-to-content/skip-to-content-story.ts b/packages/carbon-web-components/src/components/skip-to-content/skip-to-content-story.ts deleted file mode 100644 index 58484d45702..00000000000 --- a/packages/carbon-web-components/src/components/skip-to-content/skip-to-content-story.ts +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2020, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import './skip-to-content'; -import styles from './skip-to-content-story.scss?lit'; -import storyDocs from './skip-to-content-story.mdx'; -import { prefix } from '../../globals/settings'; - -export const Default = () => html` - -
-
-
-

Purpose and function

-

- The shell is perhaps the most crucial piece of any UI built with - Carbon. It contains the shared navigation framework for the entire - design system and ties the products in IBM’s portfolio together in a - cohesive and elegant way. The shell is the home of the topmost - navigation, where users can quickly and dependably gain their bearings - and move between pages. -
-
- The shell was designed with maximum flexibility built in, to serve the - needs of a broad range of products and users. Adopting the shell - ensures compliance with IBM design standards, simplifies development - efforts, and provides great user experiences. All IBM products built - with Carbon are required to use the shell’s header. -
-
- To better understand the purpose and function of the UI shell, - consider the “shell” of MacOS, which contains the Apple menu, - top-level navigation, and universal, OS-level controls at the top of - the screen, as well as a universal dock along the bottom or side of - the screen. The Carbon UI shell is roughly analogous in function to - these parts of the Mac UI. For example, the app switcher portion of - the shell can be compared to the dock in MacOS. -

-

Header responsive behavior

-

- As a header scales down to fit smaller screen sizes, headers with - persistent side nav menus should have the side nav collapse into - “hamburger” menu. See the example to better understand responsive - behavior of the header. -

-

Secondary navigation

-

- The side-nav contains secondary navigation and fits below the header. - It can be configured to be either fixed-width or flexible, with only - one level of nested items allowed. Both links and category lists can - be used in the side-nav and may be mixed together. There are several - configurations of the side-nav, but only one configuration should be - used per product section. If tabs are needed on a page when using a - side-nav, then the tabs are secondary in hierarchy to the side-nav. -

-
-
-
-`; - -export default { - title: 'Components/Skip to content', - parameters: { - ...storyDocs.parameters, - }, -}; diff --git a/packages/carbon-web-components/src/components/skip-to-content/skip-to-content-story.mdx b/packages/carbon-web-components/src/components/skip-to-content/skip-to-content.mdx similarity index 70% rename from packages/carbon-web-components/src/components/skip-to-content/skip-to-content-story.mdx rename to packages/carbon-web-components/src/components/skip-to-content/skip-to-content.mdx index 93c22b66d17..6c53a070adf 100644 --- a/packages/carbon-web-components/src/components/skip-to-content/skip-to-content-story.mdx +++ b/packages/carbon-web-components/src/components/skip-to-content/skip-to-content.mdx @@ -1,4 +1,8 @@ -import { Props } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Markdown } from '@storybook/addon-docs/blocks'; +import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as SkipToContentStories from './skip-to-content.stories'; + + # Skip to content @@ -21,8 +25,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/skip-to-content/index.js'; ``` - - +{`${cdnJs({ components: ['skip-to-content'] })}`} +{`${cdnCss()}`} ### HTML @@ -32,4 +36,4 @@ import '@carbon/web-components/es/components/skip-to-content/index.js'; ## `` attributes and properties - + diff --git a/packages/carbon-web-components/src/components/skip-to-content/skip-to-content.stories.ts b/packages/carbon-web-components/src/components/skip-to-content/skip-to-content.stories.ts new file mode 100644 index 00000000000..1b653a4f272 --- /dev/null +++ b/packages/carbon-web-components/src/components/skip-to-content/skip-to-content.stories.ts @@ -0,0 +1,82 @@ +/** + * @license + * + * Copyright IBM Corp. 2020, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import './skip-to-content'; +import styles from './skip-to-content-story.scss?lit'; +import storyDocs from './skip-to-content.mdx'; +import { prefix } from '../../globals/settings'; + +export const Default = { + render: () => html` + +
+
+
+

Purpose and function

+

+ The shell is perhaps the most crucial piece of any UI built with + Carbon. It contains the shared navigation framework for the entire + design system and ties the products in IBM’s portfolio together in a + cohesive and elegant way. The shell is the home of the topmost + navigation, where users can quickly and dependably gain their + bearings and move between pages. +
+
+ The shell was designed with maximum flexibility built in, to serve + the needs of a broad range of products and users. Adopting the shell + ensures compliance with IBM design standards, simplifies development + efforts, and provides great user experiences. All IBM products built + with Carbon are required to use the shell’s header. +
+
+ To better understand the purpose and function of the UI shell, + consider the “shell” of MacOS, which contains the Apple menu, + top-level navigation, and universal, OS-level controls at the top of + the screen, as well as a universal dock along the bottom or side of + the screen. The Carbon UI shell is roughly analogous in function to + these parts of the Mac UI. For example, the app switcher portion of + the shell can be compared to the dock in MacOS. +

+

Header responsive behavior

+

+ As a header scales down to fit smaller screen sizes, headers with + persistent side nav menus should have the side nav collapse into + “hamburger” menu. See the example to better understand responsive + behavior of the header. +

+

Secondary navigation

+

+ The side-nav contains secondary navigation and fits below the + header. It can be configured to be either fixed-width or flexible, + with only one level of nested items allowed. Both links and category + lists can be used in the side-nav and may be mixed together. There + are several configurations of the side-nav, but only one + configuration should be used per product section. If tabs are needed + on a page when using a side-nav, then the tabs are secondary in + hierarchy to the side-nav. +

+
+
+
+ `, +}; + +const meta = { + title: 'Components/Skip To Content', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/slider/slider-story.ts b/packages/carbon-web-components/src/components/slider/slider-story.ts deleted file mode 100644 index 636955df9bb..00000000000 --- a/packages/carbon-web-components/src/components/slider/slider-story.ts +++ /dev/null @@ -1,223 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { action } from '@storybook/addon-actions'; -import { boolean, number, text } from '@storybook/addon-knobs'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import './slider'; -import './slider-input'; -import './slider-skeleton'; -import '../form/form-item'; -import '../layer'; -import storyDocs from './slider-story.mdx'; -import { prefix } from '../../globals/settings'; -import '../../../.storybook/templates/with-layer'; - -export const Default = () => { - return html` - - - - - - `; -}; - -export const ControlledSlider = () => { - let value = 87; - function onClick() { - value = Math.round(Math.random() * 100); - const sliders = document.getElementsByTagName('cds-slider'); - for (const slider of sliders) { - slider.setAttribute('value', `${value}`); - } - - const headers = document.getElementsByClassName('slider-headers'); - for (const header of headers) { - header.innerHTML = `${value}`; - } - } - return html` - - - - - - -

${value}

- `; -}; - -export const ControlledSliderWithLayer = () => { - let value = 87; - function onClick() { - value = Math.round(Math.random() * 100); - const sliders = document.getElementsByTagName('cds-slider'); - for (const slider of sliders) { - slider.setAttribute('value', `${value}`); - } - - const headers = document.getElementsByClassName('slider-headers'); - for (const header of headers) { - header.innerHTML = `${value}`; - } - } - - return html` - -
- - - - - - -

${value}

-
-
- `; -}; - -export const WithLayer = () => { - return html` - - - - - - - - `; -}; - -export const skeleton = () => - html` - - `; - -skeleton.parameters = { - percy: { - skip: true, - }, -}; - -export const Playground = (args) => { - const { - ariaLabelInput, - disabled, - hideTextInput, - invalid, - invalidText, - inputType, - labelText, - max, - min, - maxLabel, - minLabel, - name, - readonly, - required, - step, - stepMultiplier, - warn, - warnText, - value, - onChange, - } = args?.[`${prefix}-slider`] || {}; - return html` - - - ${!hideTextInput - ? html`` - : null} - - - `; -}; - -Playground.storyName = 'Playground'; - -Playground.parameters = { - knobs: { - [`${prefix}-slider`]: () => ({ - ariaLabelInput: text('Aria label for input (aria-label-input)', ''), - disabled: boolean('Disabled (disabled)', false), - hideTextInput: boolean('Hide text input (hide-text-input)', false), - labelText: text( - 'Label text (label-text)', - 'Slider (must be an increment of 5)' - ), - inputType: text('Input type (type)', 'number'), - invalid: boolean('Invalid (invalid)', false), - invalidText: text( - 'Invalid text (invalid-text)', - 'Invalid message goes here' - ), - name: text('Name (name)', ''), - max: number('Maximum value (max)', 100), - min: number('Minimum value (min)', 0), - maxLabel: text('Maximum value label (max-label)', ''), - minLabel: text('Minimum value label (min-label)', ''), - readonly: boolean('Readonly (readonly)', false), - required: boolean('Required (required)', false), - step: number('Step (step)', 5), - stepMultiplier: number('Step multiplier (step-multiplier)', 5), - warn: boolean('Warn (warn)', false), - warnText: text('Warn text (warn-text)', 'Warning message goes here'), - value: number('Value (value)', 50), - onAfterChange: action(`${prefix}-slider-changed`), - }), - }, -}; - -export default { - title: 'Components/Slider', - parameters: { - ...storyDocs.parameters, - }, -}; diff --git a/packages/carbon-web-components/src/components/slider/slider-story.mdx b/packages/carbon-web-components/src/components/slider/slider.mdx similarity index 85% rename from packages/carbon-web-components/src/components/slider/slider-story.mdx rename to packages/carbon-web-components/src/components/slider/slider.mdx index dbdad58c33b..b222f0b4641 100644 --- a/packages/carbon-web-components/src/components/slider/slider-story.mdx +++ b/packages/carbon-web-components/src/components/slider/slider.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Meta, Markdown } from '@storybook/addon-docs/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as SliderStories from './slider.stories'; + + # Slider @@ -22,8 +25,8 @@ Here's a quick example to get you started. import '@carbon/web-components/es/components/slider/index.js'; ``` - - +{`${cdnJs({ components: ['slider'] })}`} +{`${cdnCss()}`} ### HTML @@ -60,7 +63,7 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `disabled` attribute). - + ## `` attributes, properties and events @@ -68,4 +71,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `invalid` attribute). - + diff --git a/packages/carbon-web-components/src/components/slider/slider.stories.ts b/packages/carbon-web-components/src/components/slider/slider.stories.ts new file mode 100644 index 00000000000..cfd4d3a7ea9 --- /dev/null +++ b/packages/carbon-web-components/src/components/slider/slider.stories.ts @@ -0,0 +1,306 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { ifDefined } from 'lit/directives/if-defined.js'; +import './index'; +import '../form/form-item'; +import '../layer'; +import storyDocs from './slider.mdx'; +import { prefix } from '../../globals/settings'; +import '../../../.storybook/templates/with-layer'; + +const args = { + ariaLabelInput: 'Lower bound', + disabled: false, + hideTextInput: false, + labelText: 'Slider (must be an increment of 5)', + invalid: false, + invalidText: 'Invalid message goes here', + max: 100, + min: 0, + readOnly: false, + required: false, + step: 5, + stepMultiplier: 5, + warn: false, + warnText: 'Warning message goes here', + value: 50, +}; + +const argTypes = { + ariaLabelInput: { + control: 'text', + description: + 'The ariaLabel for the <input>.', + }, + disabled: { + control: 'boolean', + description: 'true to disable this slider.', + }, + hideTextInput: { + control: 'boolean', + description: 'true to hide the number input box.', + }, + labelText: { + control: 'text', + description: 'Provide the text for the slider label.', + }, + inputType: { + control: 'text', + description: 'The type attribute of the <input>.', + }, + invalid: { + control: 'boolean', + description: 'Specify whether the Slider is currently invalid.', + }, + invalidText: { + control: 'text', + description: + 'Provide the text that is displayed when the Slider is in an invalid state.', + }, + name: { + control: 'text', + description: 'The name attribute of the <input>.', + }, + max: { + control: 'number', + description: 'The maximum value.', + }, + min: { + control: 'number', + description: 'The minimum value.', + }, + maxLabel: { + control: 'text', + description: 'The label associated with the maximum value.', + }, + minLabel: { + control: 'text', + description: 'The label associated with the minimum value.', + }, + readOnly: { + control: 'boolean', + description: 'Whether the slider should be read-only.', + }, + required: { + control: 'boolean', + description: 'true to specify if the control is required.', + }, + step: { + control: 'number', + description: + 'A value determining how much the value should increase/decrease by moving the thumb by mouse. If a value other than 1 is provided and the input is not hidden, the new step requirement should be added to a visible label. Values outside the step increment will be considered invalid.', + }, + stepMultiplier: { + control: 'number', + description: + 'A value determining how much the value should increase/decrease by Shift+arrow keys, which will be (max - min) / stepMultiplier.', + }, + warn: { + control: 'boolean', + description: 'Specify whether the control is currently in warning state.', + }, + warnText: { + control: 'text', + description: + 'Provide the text that is displayed when the control is in warning state.', + }, + value: { + control: 'number', + description: + 'The value of the slider. When there are two handles, value is the lower bound.', + }, + onAfterChange: { + action: `${prefix}-slider-changed`, + table: { + disable: true, + }, + }, +}; + +export const Default = { + render: () => { + return html` + + + + + + `; + }, +}; + +export const ControlledSlider = { + render: () => { + let value = 87; + function onClick() { + value = Math.round(Math.random() * 100); + const sliders = document.getElementsByTagName('cds-slider'); + for (const slider of sliders) { + slider.setAttribute('value', `${value}`); + } + + const headers = document.getElementsByClassName('slider-headers'); + for (const header of headers) { + header.innerHTML = `${value}`; + } + } + return html` + + + + + + +

${value}

+ `; + }, +}; + +export const ControlledSliderWithLayer = { + render: () => { + let value = 87; + function onClick() { + value = Math.round(Math.random() * 100); + const sliders = document.getElementsByTagName('cds-slider'); + for (const slider of sliders) { + slider.setAttribute('value', `${value}`); + } + + const headers = document.getElementsByClassName('slider-headers'); + for (const header of headers) { + header.innerHTML = `${value}`; + } + } + + return html` + +
+ + + + + + +

${value}

+
+
+ `; + }, +}; + +export const WithLayer = { + render: () => { + return html` + + + + + + + + `; + }, +}; + +export const Skeleton = { + parameters: { + percy: { + skip: true, + }, + }, + render: () => + html` + + `, +}; + +export const Playground = { + args, + argTypes, + render: (args) => { + const { + ariaLabelInput, + disabled, + hideTextInput, + invalid, + invalidText, + inputType, + labelText, + max, + min, + maxLabel, + minLabel, + name, + readOnly, + required, + step, + stepMultiplier, + warn, + warnText, + value, + onChange, + } = args || {}; + return html` + + + ${!hideTextInput + ? html`` + : null} + + + `; + }, +}; + +export default { + title: 'Components/Slider', + parameters: { + ...storyDocs.parameters, + }, +}; diff --git a/packages/carbon-web-components/src/components/tag/tag-story.ts b/packages/carbon-web-components/src/components/tag/tag-story.ts deleted file mode 100644 index ce6887efdf9..00000000000 --- a/packages/carbon-web-components/src/components/tag/tag-story.ts +++ /dev/null @@ -1,94 +0,0 @@ -/** - * @license - * - * Copyright IBM Corp. 2019, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { html } from 'lit'; -import { action } from '@storybook/addon-actions'; -import { boolean, select } from '@storybook/addon-knobs'; -import textNullable from '../../../.storybook/knob-text-nullable'; -import { ifDefined } from 'lit/directives/if-defined.js'; -import { TAG_SIZE, TAG_TYPE } from './tag'; -import './index'; -import storyDocs from './tag-story.mdx'; -import { prefix } from '../../globals/settings'; - -const sizes = { - [`Medium size (${TAG_SIZE.MEDIUM})`]: TAG_SIZE.MEDIUM, - [`Small size (${TAG_SIZE.SMALL})`]: TAG_SIZE.SMALL, -}; - -const types = [ - 'red', - 'magenta', - 'purple', - 'blue', - 'cyan', - 'teal', - 'green', - 'gray', - 'cool-gray', - 'warm-gray', - 'high-contrast', - 'outline', -]; - -export const Default = () => { - return html` - ${types.map((e) => html`Tag content`)} - `; -}; - -export const Playground = (args) => { - const { open, filter, size, type, title, disabled } = - args?.[`${prefix}-tag`] ?? {}; - - return html` - - This is a tag - - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-tag`]: () => ({ - disabled: boolean('Disabled (disabled)', false), - title: textNullable('Title (title)', 'Clear Selection'), - size: select('Tag size (size)', sizes, TAG_SIZE.MEDIUM), - type: select( - 'Tag type (type)', - Object.values(TAG_TYPE).reduce( - (acc, type) => ({ - ...acc, - [`${type} (${type})`]: type, - }), - {} - ), - 'gray' - ), - open: boolean('Open', true), - filter: boolean('Filter', false), - onClick: action('click'), - onBeforeClose: action(`${prefix}-tag-beingclosed`), - onClose: action(`${prefix}-tag-closed`), - }), - }, -}; - -export default { - parameters: { - ...storyDocs.parameters, - }, - title: 'Components/Tag', -}; diff --git a/packages/carbon-web-components/src/components/tag/tag-story.mdx b/packages/carbon-web-components/src/components/tag/tag.mdx similarity index 85% rename from packages/carbon-web-components/src/components/tag/tag-story.mdx rename to packages/carbon-web-components/src/components/tag/tag.mdx index 1c38708a902..f6bd77de6fe 100644 --- a/packages/carbon-web-components/src/components/tag/tag-story.mdx +++ b/packages/carbon-web-components/src/components/tag/tag.mdx @@ -1,5 +1,8 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Description, Meta } from '@storybook/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; +import * as TagStories from './tag.stories'; + + # Tag @@ -69,7 +72,7 @@ function App() { html` This is a tag ${Download16({ slot: 'icon' })}` ); } - +``` ## `` attributes and properties @@ -77,13 +80,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `disabled` attribute). - - -## `` attributes and properties - -Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. -``) and `false` means not setting the attribute (e.g. -`` without `disabled` attribute). - - -``` + diff --git a/packages/carbon-web-components/src/components/tag/tag.stories.ts b/packages/carbon-web-components/src/components/tag/tag.stories.ts new file mode 100644 index 00000000000..d308be1e7c2 --- /dev/null +++ b/packages/carbon-web-components/src/components/tag/tag.stories.ts @@ -0,0 +1,97 @@ +/** + * @license + * + * Copyright IBM Corp. 2019, 2023 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { html } from 'lit'; +import { TAG_SIZE } from './tag'; +import './index'; +import storyDocs from './tag.mdx'; + +const sizes = { + [`Medium size (${TAG_SIZE.MEDIUM})`]: TAG_SIZE.MEDIUM, + [`Small size (${TAG_SIZE.SMALL})`]: TAG_SIZE.SMALL, +}; + +const types = [ + 'red', + 'magenta', + 'purple', + 'blue', + 'cyan', + 'teal', + 'green', + 'gray', + 'cool-gray', + 'warm-gray', + 'high-contrast', + 'outline', +]; + +const defaultArgs = { + disabled: false, + filter: false, + title: 'Clear filter', + size: TAG_SIZE.MEDIUM, +}; + +const controls = { + disabled: { + control: 'boolean', + description: 'Specify if the Tag is disabled', + }, + filter: { + control: 'boolean', + description: 'Determine if Tag is a filter/chip', + }, + size: { + control: 'select', + description: + 'Specify the size of the Tag. Currently supports either sm or "md" (default) sizes.', + options: sizes, + }, + title: { + control: 'text', + description: 'Text to show on clear filters', + }, + type: { + control: 'select', + description: 'Specify the type of the Tag.', + options: types, + }, +}; + +export const Default = { + render: () => + html`${types.map((e) => html`Tag content`)}`, +}; + +export const Playground = { + argTypes: controls, + args: defaultArgs, + render: ({ filter, size, type, title, disabled }) => html` + + Tag content + + `, +}; + +const meta = { + title: 'Components/Tag', + parameters: { + docs: { + page: storyDocs, + }, + }, +}; + +export default meta; diff --git a/packages/carbon-web-components/src/components/tooltip/tooltip-story.scss b/packages/carbon-web-components/src/components/tooltip/tooltip-story.scss index ff8ddb944fe..52aecf27011 100644 --- a/packages/carbon-web-components/src/components/tooltip/tooltip-story.scss +++ b/packages/carbon-web-components/src/components/tooltip/tooltip-story.scss @@ -29,7 +29,6 @@ justify-content: center; width: $spacing-07; height: $spacing-07; - border: 1px solid theme.$border-subtle; } .sb-tooltip-trigger svg { diff --git a/packages/carbon-web-components/src/components/tooltip/tooltip-story.mdx b/packages/carbon-web-components/src/components/tooltip/tooltip.mdx similarity index 96% rename from packages/carbon-web-components/src/components/tooltip/tooltip-story.mdx rename to packages/carbon-web-components/src/components/tooltip/tooltip.mdx index 22d60fbeead..b264609b485 100644 --- a/packages/carbon-web-components/src/components/tooltip/tooltip-story.mdx +++ b/packages/carbon-web-components/src/components/tooltip/tooltip.mdx @@ -1,4 +1,4 @@ -import { Props, Description } from '@storybook/addon-docs/blocks'; +import { ArgsTable, Description } from '@storybook/blocks'; import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn'; # Tooltip @@ -60,4 +60,4 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g. ``) and `false` means not setting the attribute (e.g. `` without `open` attribute). - + diff --git a/packages/carbon-web-components/src/components/tooltip/tooltip-story.ts b/packages/carbon-web-components/src/components/tooltip/tooltip.stories.ts similarity index 60% rename from packages/carbon-web-components/src/components/tooltip/tooltip-story.ts rename to packages/carbon-web-components/src/components/tooltip/tooltip.stories.ts index 58066262804..23df05ef638 100644 --- a/packages/carbon-web-components/src/components/tooltip/tooltip-story.ts +++ b/packages/carbon-web-components/src/components/tooltip/tooltip.stories.ts @@ -8,16 +8,13 @@ */ import { html } from 'lit'; -import { boolean, number, select, text } from '@storybook/addon-knobs'; // Below path will be there when an application installs `@carbon/web-components` package. // In our dev env, we auto-generate the file and re-map below path to to point to the generated file. // @ts-ignore -import './tooltip'; -import './tooltip-content'; +import './index'; import { POPOVER_ALIGNMENT } from '../popover/defs'; -import { prefix } from '../../globals/settings'; import styles from './tooltip-story.scss?lit'; -import storyDocs from './tooltip-story.mdx'; +import storyDocs from './tooltip.mdx'; import Information16 from '@carbon/icons/lib/information/16'; const tooltipAlignments = { @@ -35,11 +32,49 @@ const tooltipAlignments = { [`right-top`]: POPOVER_ALIGNMENT.RIGHT_TOP, }; -export const Default = () => { - return html` - +const defaultArgs = { + align: POPOVER_ALIGNMENT.BOTTOM, + closeOnActivation: false, + defaultOpen: true, + enterDelayMs: 100, + label: 'Custom label', + leaveDelayMs: 300, +}; + +const controls = { + align: { + control: 'select', + description: 'Specify how the trigger should align with the tooltip', + options: tooltipAlignments, + }, + closeOnActivation: { + control: 'boolean', + description: + 'Determines wether the tooltip should close when inner content is activated (click, Enter or Space)', + }, + defaultOpen: { + control: 'boolean', + description: + 'Specify whether the tooltip should be open when it first renders', + }, + enterDelayMs: { + control: 'number', + description: + 'Specify the duration in milliseconds to delay before displaying the tooltip', + }, + label: { + control: 'text', + description: 'Provide the label to be rendered inside of the Tooltip.', + }, + leaveDelayMs: { + control: 'number', + description: + 'Specify the duration in milliseconds to delay before hiding the tooltip', + }, +}; + +export const Default = { + render: () => html` Label one - `; + `, }; -export const Playground = (args) => { - const { - alignment, +export const Playground = { + argTypes: controls, + args: defaultArgs, + render: ({ + align, + closeOnActivation, defaultOpen, + enterDelayMs, label, - enterDelay, - leaveDelay, - closeOnActivation, - } = args?.['cds-tooltip'] ?? {}; - return html` - + leaveDelayMs, + }) => html` ${label} - `; -}; - -Playground.parameters = { - knobs: { - [`${prefix}-tooltip`]: () => ({ - defaultOpen: boolean('Default open (defaultOpen)', false), - alignment: select( - 'Tooltip alignment to trigger button (alignment)', - tooltipAlignments, - POPOVER_ALIGNMENT.TOP - ), - label: text('Label (label)', 'Custom label'), - enterDelay: number('Enter delay (in ms)', 100), - leaveDelay: number('Leave delay (in ms)', 300), - closeOnActivation: boolean( - 'Close on activation (closeOnActivation)', - false - ), - }), - }, + `, }; -Default.storyName = 'Default'; - -export default { +const meta = { title: 'Components/Tooltip', parameters: { - ...storyDocs.parameters, + docs: { + page: storyDocs, + }, }, - decorators: [(story) => html`
${story()}
`], + decorators: [ + (story) => html`
+ ${story()} +
`, + ], }; + +export default meta; diff --git a/packages/carbon-web-components/src/components/ui-shell/ui-shell-story.ts b/packages/carbon-web-components/src/components/ui-shell/ui-shell-story.ts index 09df097872a..91e6a40cca9 100644 --- a/packages/carbon-web-components/src/components/ui-shell/ui-shell-story.ts +++ b/packages/carbon-web-components/src/components/ui-shell/ui-shell-story.ts @@ -1,7 +1,7 @@ /** * @license * - * Copyright IBM Corp. 2019, 2023 + * Copyright IBM Corp. 2019, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. @@ -15,7 +15,7 @@ import Fade16 from '@carbon/web-components/es/icons/fade/16'; import Search20 from '@carbon/web-components/es/icons/search/20'; import Notification20 from '@carbon/web-components/es/icons/notification/20'; import SwitcherIcon20 from '@carbon/web-components/es/icons/switcher/20'; -import contentStyles from '@carbon/styles/scss/components/ui-shell/content/_content.scss'; +import contentStyles from '@carbon/styles/scss/components/ui-shell/content/_content.scss?lit'; import { SIDE_NAV_COLLAPSE_MODE, SIDE_NAV_USAGE_MODE } from './side-nav'; import { classMap } from 'lit/directives/class-map.js'; import './index'; diff --git a/packages/carbon-web-components/src/globals/decorators/carbon-element.ts b/packages/carbon-web-components/src/globals/decorators/carbon-element.ts index 127882f9e54..ea8a23b6345 100644 --- a/packages/carbon-web-components/src/globals/decorators/carbon-element.ts +++ b/packages/carbon-web-components/src/globals/decorators/carbon-element.ts @@ -1,7 +1,7 @@ /** * @license * - * Copyright IBM Corp. 2019, 2022 + * Copyright IBM Corp. 2019, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. @@ -13,48 +13,23 @@ * an @ExportDecoratedItems annotation must be defined as a regular function, * not an arrow function. */ -import { - Constructor, - ClassDescriptor, -} from '@lit/reactive-element/decorators/base.js'; + +import type { Constructor } from '@lit/reactive-element/decorators/base.js'; /** * Allow for custom element classes with private constructors */ type CustomElementClass = Omit; -const legacyCustomElement = (tagName: string, clazz: CustomElementClass) => { - try { - customElements.define(tagName, clazz as CustomElementConstructor); - } catch (error) { - console.warn(`Attempting to re-define ${tagName}`); - } - // Cast as any because TS doesn't recognize the return type as being a - // subtype of the decorated class when clazz is typed as - // `Constructor` for some reason. - // `Constructor` is helpful to make sure the decorator is - // applied to elements however. - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return clazz as any; -}; +export type CustomElementDecorator = { + // legacy + (cls: CustomElementClass): void; -const standardCustomElement = ( - tagName: string, - descriptor: ClassDescriptor -) => { - const { kind, elements } = descriptor; - return { - kind, - elements, - // This callback is called once the class is otherwise fully defined - finisher(clazz: Constructor) { - try { - customElements.define(tagName, clazz); - } catch (error) { - console.warn(`Attempting to re-define ${tagName}`); - } - }, - }; + // standard + ( + target: CustomElementClass, + context: ClassDecoratorContext> + ): void; }; /** @@ -68,13 +43,30 @@ const standardCustomElement = ( * } * } * ``` - * * @category Decorator * @param tagName The tag name of the custom element to define. */ export const carbonElement = - (tagName: string) => - (classOrDescriptor: CustomElementClass | ClassDescriptor) => - typeof classOrDescriptor === 'function' - ? legacyCustomElement(tagName, classOrDescriptor) - : standardCustomElement(tagName, classOrDescriptor as ClassDescriptor); + (tagName: string): CustomElementDecorator => + ( + classOrTarget: CustomElementClass | Constructor, + context?: ClassDecoratorContext> + ) => { + if (context !== undefined) { + context.addInitializer(() => { + customElements.define( + tagName, + classOrTarget as CustomElementConstructor + ); + }); + } else { + try { + customElements.define( + tagName, + classOrTarget as CustomElementConstructor + ); + } catch (error) { + console.warn(`Attempting to re-define ${tagName}`); + } + } + }; diff --git a/packages/carbon-web-components/src/globals/internal/storybook-cdn.ts b/packages/carbon-web-components/src/globals/internal/storybook-cdn.ts index 2de6cf591e8..bf88574e737 100644 --- a/packages/carbon-web-components/src/globals/internal/storybook-cdn.ts +++ b/packages/carbon-web-components/src/globals/internal/storybook-cdn.ts @@ -1,7 +1,7 @@ /** * @license * - * Copyright IBM Corp. 2021, 2023 + * Copyright IBM Corp. 2021, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. @@ -37,31 +37,31 @@ function _renderScript(components, tag, isRTL = false) { */ export const cdnJs = ({ components }) => { return ` - ### JS (via CDN) +### JS (via CDN) \`\`\`html - // SPECIFIC VERSION (available starting v1.6.0) - ${_renderScript(components, `version/v${packageJson.version}`)} +// SPECIFIC VERSION (available starting v1.6.0) +${_renderScript(components, `version/v${packageJson.version}`)} - // LATEST tag - ${_renderScript(components, 'tag/v2/latest')} - \`\`\` +// LATEST tag +${_renderScript(components, 'tag/v2/latest')} +\`\`\` - > NOTE: The latest tag is a moving version. While beneficial to - > always stay on the most recent version, it is recommended to choose a specific - > version and properly test your application when upgrading to a newer version. +> NOTE: The latest tag is a moving version. While beneficial to +> always stay on the most recent version, it is recommended to choose a specific +> version and properly test your application when upgrading to a newer version. - #### Right-to-left (RTL) versions +#### Right-to-left (RTL) versions - \`\`\`html - // SPECIFIC VERSION (available starting v1.6.0) - ${_renderScript(components, `version/v${packageJson.version}`, true)} +\`\`\`html +// SPECIFIC VERSION (available starting v1.6.0) +${_renderScript(components, `version/v${packageJson.version}`, true)} - // LATEST tag - ${_renderScript(components, 'tag/v2/latest', true)} - \`\`\` - `; +// LATEST tag +${_renderScript(components, 'tag/v2/latest', true)} +\`\`\` + `; }; /** diff --git a/packages/carbon-web-components/tests/spec/button_spec.ts b/packages/carbon-web-components/tests/spec/button_spec.ts index 4cc41fc325b..81237c4696b 100644 --- a/packages/carbon-web-components/tests/spec/button_spec.ts +++ b/packages/carbon-web-components/tests/spec/button_spec.ts @@ -9,7 +9,7 @@ import { render } from 'lit'; import { BUTTON_KIND } from '../../src/components/button/button'; -import { Default } from '../../src/components/button/button-story'; +import { Default } from '../../src/components/button/button.stories'; const template = (props?) => Default({ diff --git a/packages/carbon-web-components/tests/spec/checkbox_spec.ts b/packages/carbon-web-components/tests/spec/checkbox_spec.ts index 88808ad3040..d44aa61f6d6 100644 --- a/packages/carbon-web-components/tests/spec/checkbox_spec.ts +++ b/packages/carbon-web-components/tests/spec/checkbox_spec.ts @@ -8,7 +8,7 @@ */ import { html, render } from 'lit'; -import { Playground as Default } from '../../src/components/checkbox/checkbox-story'; +import { Playground as Default } from '../../src/components/checkbox/checkbox.stories'; /** * @param formData A `FormData` instance. diff --git a/packages/carbon-web-components/tests/spec/combo-box_spec.ts b/packages/carbon-web-components/tests/spec/combo-box_spec.ts index 553f9d5f9ba..cc460ecc2fd 100644 --- a/packages/carbon-web-components/tests/spec/combo-box_spec.ts +++ b/packages/carbon-web-components/tests/spec/combo-box_spec.ts @@ -13,7 +13,7 @@ import EventManager from '../utils/event-manager'; import CDSComboBox from '../../src/components/combo-box/combo-box'; import CDSComboBoxItem from '../../src/components/combo-box/combo-box-item'; -import { Playground } from '../../src/components/combo-box/combo-box-story'; +import { Playground } from '../../src/components/combo-box/combo-box.stories'; const template = (props?) => Playground({ diff --git a/packages/carbon-web-components/tests/spec/copy-button_spec.ts b/packages/carbon-web-components/tests/spec/copy-button_spec.ts index e21b3ce3bac..49de1caf7cb 100644 --- a/packages/carbon-web-components/tests/spec/copy-button_spec.ts +++ b/packages/carbon-web-components/tests/spec/copy-button_spec.ts @@ -1,14 +1,14 @@ /** * @license * - * Copyright IBM Corp. 2019, 2023 + * Copyright IBM Corp. 2019, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ import { render } from 'lit'; -import { Default } from '../../src/components/copy-button/copy-button-story'; +import { Default } from '../../src/components/copy-button/copy-button.stories'; const template = (props?) => Default({ diff --git a/packages/carbon-web-components/tests/spec/data-table_spec.ts b/packages/carbon-web-components/tests/spec/data-table_spec.ts index d78594227d4..56ceb5df7a6 100644 --- a/packages/carbon-web-components/tests/spec/data-table_spec.ts +++ b/packages/carbon-web-components/tests/spec/data-table_spec.ts @@ -18,7 +18,7 @@ import CDSTableHeaderCell, { import CDSTableRow from '../../src/components/data-table/table-row'; import CDSTableExpandedRow from '../../src/components/data-table/table-expanded-row'; import CDSTableToolbarSearch from '../../src/components/data-table/table-toolbar-search'; -import { Playground } from '../../src/components/data-table/stories/data-table-basic-story'; +import { Playground } from '../../src/components/data-table/stories/data-table-basic.stories'; const template = ({ ...rest } = {}) => Playground({ diff --git a/packages/carbon-web-components/tests/spec/dropdown_spec.ts b/packages/carbon-web-components/tests/spec/dropdown_spec.ts index 96f81421bf8..5279f252e7b 100644 --- a/packages/carbon-web-components/tests/spec/dropdown_spec.ts +++ b/packages/carbon-web-components/tests/spec/dropdown_spec.ts @@ -13,7 +13,7 @@ import EventManager from '../utils/event-manager'; import CDSDropdown from '../../src/components/dropdown/dropdown'; import CDSDropdownItem from '../../src/components/dropdown/dropdown-item'; -import { Playground } from '../../src/components/dropdown/dropdown-story'; +import { Playground } from '../../src/components/dropdown/dropdown.stories'; const template = (props?) => Playground({ diff --git a/packages/carbon-web-components/tests/spec/inline-loading_spec.ts b/packages/carbon-web-components/tests/spec/inline-loading_spec.ts index 5da912e7d42..e40fb006a8d 100644 --- a/packages/carbon-web-components/tests/spec/inline-loading_spec.ts +++ b/packages/carbon-web-components/tests/spec/inline-loading_spec.ts @@ -12,7 +12,7 @@ import { render } from 'lit'; import CDSInlineLoading, { INLINE_LOADING_STATE, } from '../../src/components/inline-loading/inline-loading'; -import { Playground } from '../../src/components/inline-loading/inline-loading-story'; +import { Playground } from '../../src/components/inline-loading/inline-loading.stories'; const template = (props?) => Playground({ diff --git a/packages/carbon-web-components/tests/spec/link_spec.ts b/packages/carbon-web-components/tests/spec/link_spec.ts index ca111458a12..83b6de7c619 100644 --- a/packages/carbon-web-components/tests/spec/link_spec.ts +++ b/packages/carbon-web-components/tests/spec/link_spec.ts @@ -1,7 +1,7 @@ /** * @license * - * Copyright IBM Corp. 2020, 2023 + * Copyright IBM Corp. 2020, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. @@ -9,10 +9,10 @@ import { render } from 'lit'; import '../../src/components/link/link'; -import { pairedWithIcon } from '../../src/components/link/link.stories'; +import { PairedWithIcon } from '../../src/components/link/link.stories'; const template = (props?) => - pairedWithIcon({ + (PairedWithIcon = { 'cds-link': props, }); diff --git a/packages/carbon-web-components/tests/spec/overflow-menu_spec.ts b/packages/carbon-web-components/tests/spec/overflow-menu_spec.ts index 1c584a2a408..0f20d42e726 100644 --- a/packages/carbon-web-components/tests/spec/overflow-menu_spec.ts +++ b/packages/carbon-web-components/tests/spec/overflow-menu_spec.ts @@ -1,7 +1,7 @@ /** * @license * - * Copyright IBM Corp. 2020, 2023 + * Copyright IBM Corp. 2020, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. @@ -10,7 +10,7 @@ import { render } from 'lit'; import CDSOverflowMenu from '../../src/components/overflow-menu/overflow-menu'; -import { Playground } from '../../src/components/overflow-menu/overflow-menu-story'; +import { Playground } from '../../src/components/overflow-menu/overflow-menu.stories'; const template = (props?) => Playground({ diff --git a/packages/carbon-web-components/tests/spec/tag_spec.ts b/packages/carbon-web-components/tests/spec/tag_spec.ts index 10107c81d2f..f594131167b 100644 --- a/packages/carbon-web-components/tests/spec/tag_spec.ts +++ b/packages/carbon-web-components/tests/spec/tag_spec.ts @@ -9,7 +9,7 @@ import { render } from 'lit'; import EventManager from '../utils/event-manager'; -import { Default, Playground } from '../../src/components/tag/tag-story'; +import { Default, Playground } from '../../src/components/tag/tag.stories'; const tagTemplate = () => Default(); diff --git a/packages/carbon-web-components/tests/spec/tooltip_spec.ts b/packages/carbon-web-components/tests/spec/tooltip_spec.ts index 9dacc49ec54..8069cfe8be1 100644 --- a/packages/carbon-web-components/tests/spec/tooltip_spec.ts +++ b/packages/carbon-web-components/tests/spec/tooltip_spec.ts @@ -12,7 +12,7 @@ import ResizeObserver from 'resize-observer-polyfill'; import CDSTooltip from '../../src/components/tooltip/tooltip'; import CDSTooltipContent from '../../src/components/tooltip/tooltip-content'; import { POPOVER_ALIGNMENT } from '../../src/components/popover/defs'; -import { Playground } from '../../src/components/tooltip/tooltip-story'; +import { Playground } from '../../src/components/tooltip/tooltip.stories'; const bodyTemplate = () => html` `; const contentTemplate = ({ diff --git a/packages/carbon-web-components/tools/babel-plugin-resource-js-paths.js b/packages/carbon-web-components/tools/babel-plugin-resource-js-paths.js index 5f21a6317b9..3718349930d 100644 --- a/packages/carbon-web-components/tools/babel-plugin-resource-js-paths.js +++ b/packages/carbon-web-components/tools/babel-plugin-resource-js-paths.js @@ -1,7 +1,7 @@ /** * @license * - * Copyright IBM Corp. 2019, 2022 + * Copyright IBM Corp. 2019, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. @@ -18,7 +18,7 @@ module.exports = function resourceJSPaths(babel) { ImportDeclaration(path, state) { const { node } = path; const { value: source } = node.source; - if (/^\..*\.scss$/i.test(source)) { + if (/^\..*\.scss\?lit$/i.test(source)) { const declaration = t.cloneNode(node); declaration.source.value = `./${replaceExtension(source, '.css.js')}`; path.replaceWith(declaration); diff --git a/packages/carbon-web-components/tools/get-rollup-config.js b/packages/carbon-web-components/tools/get-rollup-config.js index 583ccd2fd6d..5c1d6194bc8 100644 --- a/packages/carbon-web-components/tools/get-rollup-config.js +++ b/packages/carbon-web-components/tools/get-rollup-config.js @@ -1,7 +1,7 @@ /** * @license * - * Copyright IBM Corp. 2020, 2023 + * Copyright IBM Corp. 2020, 2024 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. @@ -20,7 +20,7 @@ const { nodeResolve } = require('@rollup/plugin-node-resolve'); const rtlcss = require('rtlcss'); const { promisify } = require('util'); const { terser } = require('rollup-plugin-terser'); - +const alias = require('@rollup/plugin-alias'); const carbonIcons = require('./rollup-plugin-icons'); const fixHostPseudo = require('./postcss-fix-host-pseudo'); const license = require('./rollup-plugin-license'); @@ -118,6 +118,9 @@ function getRollupConfig({ return { input: _generateInputs(mode, dir, folders), plugins: [ + alias({ + entries: [{ find: /^(.*)\.scss\?lit$/, replacement: '$1.scss' }], + }), multiInput(), nodeResolve({ browser: true, diff --git a/yarn.lock b/yarn.lock index 00a186d711b..e29ffe5151e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4262,6 +4262,7 @@ __metadata: "@percy/cli": "npm:^1.27.4" "@percy/cypress": "npm:^3.1.2" "@percy/dom": "npm:^1.27.5" + "@rollup/plugin-alias": "npm:^5.1.0" "@rollup/plugin-babel": "npm:^5.3.1" "@rollup/plugin-commonjs": "npm:^21.0.3" "@rollup/plugin-node-resolve": "npm:^8.4.0" @@ -4341,7 +4342,7 @@ __metadata: karma-sourcemap-loader: "npm:^0.4.0" karma-spec-reporter: "npm:0.0.36" karma-webpack: "npm:^4.0.2" - lit: "npm:^2.7.6" + lit: "npm:^3.1.0" lodash-es: "npm:^4.17.21" magic-string: "npm:^0.30.0" mini-css-extract-plugin: "npm:~2.7.0" @@ -6160,6 +6161,13 @@ __metadata: languageName: node linkType: hard +"@lit-labs/ssr-dom-shim@npm:^1.1.2": + version: 1.1.2 + resolution: "@lit-labs/ssr-dom-shim@npm:1.1.2" + checksum: a930f7de57b952dc21317a5754aa0411e000bb4991053cde771c111b7792c4a4cdc896922f0353c832215bed71400431c5ab5a6252c8f4f70bb9ce0b37fe4752 + languageName: node + linkType: hard + "@lit/reactive-element@npm:^1.3.0, @lit/reactive-element@npm:^1.6.0": version: 1.6.2 resolution: "@lit/reactive-element@npm:1.6.2" @@ -6169,6 +6177,15 @@ __metadata: languageName: node linkType: hard +"@lit/reactive-element@npm:^2.0.0": + version: 2.0.2 + resolution: "@lit/reactive-element@npm:2.0.2" + dependencies: + "@lit-labs/ssr-dom-shim": "npm:^1.1.2" + checksum: 2b74234f041740a8e0ab65980e2ac949533f067e43a6a512171a2b5f8ecd2116996f728776adc8ab94c1dddb679235cceb463a9c9ceb0f34a00fe95966646eff + languageName: node + linkType: hard + "@mdx-js/mdx@npm:^1.6.22": version: 1.6.22 resolution: "@mdx-js/mdx@npm:1.6.22" @@ -7681,6 +7698,20 @@ __metadata: languageName: node linkType: hard +"@rollup/plugin-alias@npm:^5.1.0": + version: 5.1.0 + resolution: "@rollup/plugin-alias@npm:5.1.0" + dependencies: + slash: "npm:^4.0.0" + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + checksum: 2749f9563dba9274e4324fcd14ffe761fa66ee3baab307ba583d0348adfa2c1d2a164f59eac8c26a9ce7c713a99a991a831c072101e83697157ccf082c362310 + languageName: node + linkType: hard + "@rollup/plugin-babel@npm:^5.3.1": version: 5.3.1 resolution: "@rollup/plugin-babel@npm:5.3.1" @@ -26869,6 +26900,17 @@ __metadata: languageName: node linkType: hard +"lit-element@npm:^4.0.0": + version: 4.0.2 + resolution: "lit-element@npm:4.0.2" + dependencies: + "@lit-labs/ssr-dom-shim": "npm:^1.1.2" + "@lit/reactive-element": "npm:^2.0.0" + lit-html: "npm:^3.1.0" + checksum: 185e8b916516c87d337d0491e572af412a3f7c60f751b5432d2f671ab1615f515683c49f2a28aeae81264072a8d6f80cfdcf39ca9521b2a6dd96d2f83e929bf6 + languageName: node + linkType: hard + "lit-html@npm:^2.7.0": version: 2.7.5 resolution: "lit-html@npm:2.7.5" @@ -26878,6 +26920,15 @@ __metadata: languageName: node linkType: hard +"lit-html@npm:^3.1.0": + version: 3.1.0 + resolution: "lit-html@npm:3.1.0" + dependencies: + "@types/trusted-types": "npm:^2.0.2" + checksum: 2831f48e82bc75a27e329a844faf0b0324f006c004e2bbc2c5cc8632429ec79a5401aae31866fba9befae7861bf40c7513a7a39227ceafe2dc7a069f617ef875 + languageName: node + linkType: hard + "lit@npm:^2.7.6": version: 2.7.6 resolution: "lit@npm:2.7.6" @@ -26889,6 +26940,17 @@ __metadata: languageName: node linkType: hard +"lit@npm:^3.1.0": + version: 3.1.0 + resolution: "lit@npm:3.1.0" + dependencies: + "@lit/reactive-element": "npm:^2.0.0" + lit-element: "npm:^4.0.0" + lit-html: "npm:^3.1.0" + checksum: cf46959d909a5dce2ac4bff3d9f8aa942be223c30ce1d4e86e66eda55d53f2886e4ae6092f9ab825c1a26d56d1a57c360981040cb579d53a73869d07ec04bad9 + languageName: node + linkType: hard + "load-json-file@npm:6.2.0": version: 6.2.0 resolution: "load-json-file@npm:6.2.0" @@ -35383,6 +35445,13 @@ __metadata: languageName: node linkType: hard +"slash@npm:^4.0.0": + version: 4.0.0 + resolution: "slash@npm:4.0.0" + checksum: da8e4af73712253acd21b7853b7e0dbba776b786e82b010a5bfc8b5051a1db38ed8aba8e1e8f400dd2c9f373be91eb1c42b66e91abb407ff42b10feece5e1d2d + languageName: node + linkType: hard + "slice-ansi@npm:^2.1.0": version: 2.1.0 resolution: "slice-ansi@npm:2.1.0"