Skip to content

Commit

Permalink
feat(content-switcher): update story to Storybook v7 (#11315)
Browse files Browse the repository at this point in the history
* chore(content-switcher): update content-switcher to sb v7

* fix(content-switcher): add imports for content-switcher dependencies

* fix(content-switcher): fix css selector for icon only styles

* fix(content-switcher): restore the size options

* chore(content-switcher): include storybook layers components

---------

Co-authored-by: kennylam <[email protected]>
  • Loading branch information
m4olivei and kennylam authored Jan 10, 2024
1 parent 9705c48 commit 2e29308
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 156 deletions.
2 changes: 2 additions & 0 deletions packages/carbon-web-components/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const stories = glob.sync(
// add mdx/story files as they are being worked on
'../src/**/combo-box.stories.ts',
'../src/**/combo-box.mdx',
'../src/**/content-switcher.mdx',
'../src/**/content-switcher.stories.ts',
'../src/**/dropdown.stories.ts',
'../src/**/dropdown.mdx',
'../src/**/data-table-*.stories.ts',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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';

<Meta of={ContentSwitcherStories} />

# Content switcher

Expand Down Expand Up @@ -44,8 +47,8 @@ import '@carbon/web-components/es/components/content-switcher/index.js';

## `<cds-content-switcher>` attributes, properties and events

<Props of="cds-content-switcher" />
<ArgsTable of="cds-content-switcher" />

## `<cds-content-switcher-item>` attributes and properties

<Props of="cds-content-switcher-item" />
<ArgsTable of="cds-content-switcher-item" />
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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`
<cds-content-switcher value="all">
<cds-content-switcher-item value="all">
First section
</cds-content-switcher-item>
<cds-content-switcher-item value="cloudFoundry">
Second section
</cds-content-switcher-item>
<cds-content-switcher-item value="staging">
Third section
</cds-content-switcher-item>
</cds-content-switcher>
`,
};

export const IconOnly = {
render: () => html`
<cds-content-switcher value="all">
<cds-content-switcher-item icon value="all">
${TableOfContents16()}
<span slot="tooltip-content">Table of Contents</span>
</cds-content-switcher-item>
<cds-content-switcher-item icon value="cloudFoundry">
${Workspace16()}
<span slot="tooltip-content">Workspace Test</span>
</cds-content-switcher-item>
<cds-content-switcher-item icon value="staging">
${ViewMode2_16()}
<span slot="tooltip-content">View Mode</span>
</cds-content-switcher-item>
</cds-content-switcher>
`,
};

export const IconOnlyWithLayer = {
render: () => html`
<sb-template-layers>
<cds-content-switcher value="all">
<cds-content-switcher-item icon value="all">
${TableOfContents16()}
<span slot="tooltip-content">Table of Contents</span>
</cds-content-switcher-item>
<cds-content-switcher-item icon value="cloudFoundry">
${Workspace16()}
<span slot="tooltip-content">Workspace Test</span>
</cds-content-switcher-item>
<cds-content-switcher-item icon value="staging">
${ViewMode2_16()}
<span slot="tooltip-content">View Mode</span>
</cds-content-switcher-item>
</cds-content-switcher>
</sb-template-layers>
`,
};

export const WithLayer = {
render: () => html`
<sb-template-layers>
<cds-content-switcher value="all">
<cds-content-switcher-item value="all">
First section
</cds-content-switcher-item>
<cds-content-switcher-item value="cloudFoundry">
Second section
</cds-content-switcher-item>
<cds-content-switcher-item value="staging">
Third section
</cds-content-switcher-item>
</cds-content-switcher>
</sb-template-layers>
`,
};

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`
<cds-content-switcher
value="${ifDefined(value)}"
@cds-content-switcher-beingselected="${handleBeforeSelected}"
@cds-content-switcher-selected="${onSelect}"
size="${size}">
<cds-content-switcher-item value="all">
First section
</cds-content-switcher-item>
<cds-content-switcher-item value="cloudFoundry">
Second section
</cds-content-switcher-item>
<cds-content-switcher-item value="staging">
Third section
</cds-content-switcher-item>
</cds-content-switcher>
`;
},
};

const meta = {
title: 'Components/Content switcher',
parameters: {
docs: {
page: storyDocs,
},
},
};

export default meta;
Original file line number Diff line number Diff line change
@@ -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';

0 comments on commit 2e29308

Please sign in to comment.