From aab5fd6d61d519adbcc7276860cf5675434cf57e Mon Sep 17 00:00:00 2001 From: ariellalgilmore Date: Wed, 10 Jan 2024 08:29:17 -0800 Subject: [PATCH] feat(tag/tooltip): cwc storybook controls --- .../carbon-web-components/.storybook/main.ts | 4 + .../src/components/tag/tag-story.ts | 94 ------------ .../components/tag/{tag-story.mdx => tag.mdx} | 18 +-- .../src/components/tag/tag.stories.ts | 97 ++++++++++++ .../src/components/tooltip/tooltip-story.scss | 1 - .../{tooltip-story.mdx => tooltip.mdx} | 4 +- .../{tooltip-story.ts => tooltip.stories.ts} | 141 ++++++++++-------- .../tests/spec/tag_spec.ts | 2 +- .../tests/spec/tooltip_spec.ts | 2 +- 9 files changed, 189 insertions(+), 174 deletions(-) delete mode 100644 packages/carbon-web-components/src/components/tag/tag-story.ts rename packages/carbon-web-components/src/components/tag/{tag-story.mdx => tag.mdx} (85%) create mode 100644 packages/carbon-web-components/src/components/tag/tag.stories.ts rename packages/carbon-web-components/src/components/tooltip/{tooltip-story.mdx => tooltip.mdx} (96%) rename packages/carbon-web-components/src/components/tooltip/{tooltip-story.ts => tooltip.stories.ts} (60%) diff --git a/packages/carbon-web-components/.storybook/main.ts b/packages/carbon-web-components/.storybook/main.ts index dcd6c9c6491..c86e8985d61 100644 --- a/packages/carbon-web-components/.storybook/main.ts +++ b/packages/carbon-web-components/.storybook/main.ts @@ -26,6 +26,10 @@ const stories = glob.sync( '../src/**/file-uploader.stories.ts', '../src/**/overflow-menu.mdx', '../src/**/overflow-menu.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/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/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 = ({