Skip to content

Commit

Permalink
docs: redesign with-layer stories (#13331)
Browse files Browse the repository at this point in the history
* docs: add with-layer storybook template component

* docs(improved-contrast-tile): use with-layer storybook template

* docs(contained-list): use with-layer storybook template

* docs(progress-bar): use with-layer storybook template

* docs(slider): use with-layer storybook template

* docs(dropdown): use with-layer storybook template

* docs(content-switcher): use with-layer storybook template

* style(storybook): update with-layer story template design

* style(storybook): rename layer labels

* docs(combobox): use with-layer storybook template

* docs(multiselect): use with-layer storybook template

* docs(code-snippet): use with-layer storybook template

* docs(date-picker): use with-layer storybook template

* docs(search): use with-layer storybook template

* docs(select): use with-layer storybook template

* docs(text-area): use with-layer storybook template

* docs(text-input): use with-layer storybook template

* docs(theme): use with-layer storybook template

* docs(tile): use with-layer storybook template

* docs(time-picker): use with-layer storybook template

* docs(fluid-text-area): use with-layer storybook template

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
janhassel and kodiakhq[bot] authored Apr 4, 2023
1 parent 66f3ae5 commit 4c4f2f4
Show file tree
Hide file tree
Showing 22 changed files with 442 additions and 967 deletions.
31 changes: 31 additions & 0 deletions packages/react/.storybook/templates/WithLayer/WithLayer.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@use '@carbon/styles/scss/colors';
@use '@carbon/styles/scss/theme';
@use '@carbon/styles/scss/spacing';
@use '@carbon/styles/scss/type';
@use '@carbon/styles/scss/components/tag';

@use '../prefix' as *;

.#{$prefix}--with-layer__layer {
position: relative;
border: 1px dashed colors.$purple-50;
}

.#{$prefix}--with-layer__layer .#{$prefix}--with-layer__layer {
background-color: theme.$layer;
margin-block-start: spacing.$spacing-07;
}

.#{$prefix}--with-layer__label {
@include type.type-style('code-01');

display: inline-flex;
padding: spacing.$spacing-02;
background-color: tag.$tag-background-purple;
color: tag.$tag-color-purple;
column-gap: spacing.$spacing-02;
}

.#{$prefix}--with-layer__content {
padding: spacing.$spacing-05;
}
68 changes: 68 additions & 0 deletions packages/react/.storybook/templates/WithLayer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright IBM Corp. 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 PropTypes from 'prop-types';
import React from 'react';
import './WithLayer.scss';

import { Layers as Icon } from '@carbon/react/icons';
import { Layer } from '../../../src';

import { prefix } from '../_prefix';

function WithLayer({ children }) {
function renderChild(layer) {
return typeof children === 'function' ? children(layer) : children;
}

return (
<div className={`${prefix}--with-layer`}>
<div className={`${prefix}--with-layer__layer`}>
<div className={`${prefix}--with-layer__label`}>
<Icon />
Layer 1
</div>
<div className={`${prefix}--with-layer__content`}>
{renderChild(0)}

<div className={`${prefix}--with-layer__layer`}>
<div className={`${prefix}--with-layer__label`}>
<Icon />
Layer 2
</div>
<div className={`${prefix}--with-layer__content`}>
<Layer>
{renderChild(1)}

<div className={`${prefix}--with-layer__layer`}>
<div className={`${prefix}--with-layer__label`}>
<Icon />
Layer 3
</div>
<div className={`${prefix}--with-layer__content`}>
<Layer>{renderChild(2)}</Layer>
</div>
</div>
</Layer>
</div>
</div>
</div>
</div>
</div>
);
}

WithLayer.propTypes = {
/**
* The component demo to be rendered on all layers.
* Can be either a node or a function that receives the layer
* index as a parameter and returns the child for that layer.
*/
children: PropTypes.oneOf([PropTypes.node, PropTypes.func]),
};

export { WithLayer };
1 change: 1 addition & 0 deletions packages/react/.storybook/templates/_prefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const prefix = 'carbon-storybook-template';
1 change: 1 addition & 0 deletions packages/react/.storybook/templates/_prefix.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$prefix: 'carbon-storybook-template';
198 changes: 53 additions & 145 deletions packages/react/src/components/CodeSnippet/CodeSnippet.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
*/

import React from 'react';

import { WithLayer } from '../../../.storybook/templates/WithLayer';

import { default as CodeSnippet, CodeSnippetSkeleton } from '.';
import { Layer } from '../Layer';
import mdx from './CodeSnippet.mdx';

export default {
Expand Down Expand Up @@ -74,152 +76,58 @@ export const Singleline = () => (
</CodeSnippet>
);

export const InlineWithLayer = () => {
return (
<>
<CodeSnippet type="inline" feedback="Copied to clipboard">
{'node -v'}
</CodeSnippet>
<Layer>
<CodeSnippet type="inline" feedback="Copied to clipboard">
{'node -v'}
</CodeSnippet>
<Layer>
<CodeSnippet type="inline" feedback="Copied to clipboard">
{'node -v'}
</CodeSnippet>
</Layer>
</Layer>
</>
);
};
export const InlineWithLayer = () => (
<WithLayer>
<CodeSnippet type="inline" feedback="Copied to clipboard">
{'node -v'}
</CodeSnippet>
</WithLayer>
);

export const MultilineWithLayer = () => {
return (
<>
<CodeSnippet type="multi" feedback="Copied to clipboard">
{` "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",`}
</CodeSnippet>
<Layer>
<CodeSnippet type="multi" feedback="Copied to clipboard">
{` "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",`}
</CodeSnippet>
<Layer>
<CodeSnippet type="multi" feedback="Copied to clipboard">
{` "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",`}
</CodeSnippet>
</Layer>
</Layer>
</>
);
};
export const MultilineWithLayer = () => (
<WithLayer>
<CodeSnippet type="multi" feedback="Copied to clipboard">
{` "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",`}
</CodeSnippet>
</WithLayer>
);

export const SinglelineWithLayer = () => {
return (
<>
<CodeSnippet type="single" feedback="Copied to clipboard">
yarn add carbon-components@latest carbon-components-react@latest
@carbon/icons-react@latest carbon-icons@latest
</CodeSnippet>
<Layer>
<CodeSnippet type="single" feedback="Copied to clipboard">
yarn add carbon-components@latest carbon-components-react@latest
@carbon/icons-react@latest carbon-icons@latest
</CodeSnippet>
<Layer>
<CodeSnippet type="single" feedback="Copied to clipboard">
yarn add carbon-components@latest carbon-components-react@latest
@carbon/icons-react@latest carbon-icons@latest
</CodeSnippet>
</Layer>
</Layer>
</>
);
};
export const SinglelineWithLayer = () => (
<WithLayer>
<CodeSnippet type="single" feedback="Copied to clipboard">
yarn add carbon-components@latest carbon-components-react@latest
@carbon/icons-react@latest carbon-icons@latest
</CodeSnippet>
</WithLayer>
);

export const Skeleton = () => (
<div>
Expand Down
40 changes: 12 additions & 28 deletions packages/react/src/components/ComboBox/ComboBox.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
*/

import React from 'react';

import { WithLayer } from '../../../.storybook/templates/WithLayer';

import ComboBox from '../ComboBox';
import { Layer } from '../Layer';
import mdx from './ComboBox.mdx';

const items = [
Expand Down Expand Up @@ -78,40 +80,22 @@ export const Default = () => (
</div>
);

export const WithLayer = () => (
<div style={{ width: 300 }}>
<ComboBox
onChange={() => {}}
id="carbon-combobox"
items={items}
itemToString={(item) => (item ? item.text : '')}
placeholder="Filter..."
titleText="First Layer"
helperText="Combobox helper text"
/>
<Layer>
<ComboBox
onChange={() => {}}
id="carbon-combobox"
items={items}
itemToString={(item) => (item ? item.text : '')}
placeholder="Filter..."
titleText="Second Layer"
helperText="Combobox helper text"
/>
<Layer>
export const _WithLayer = () => (
<WithLayer>
{(layer) => (
<div style={{ width: 300 }}>
<ComboBox
onChange={() => {}}
id="carbon-combobox"
id={`carbon-combobox-${layer}`}
items={items}
itemToString={(item) => (item ? item.text : '')}
placeholder="Filter..."
titleText="Third Layer"
titleText="ComboBox title"
helperText="Combobox helper text"
/>
</Layer>
</Layer>
</div>
</div>
)}
</WithLayer>
);

export const Playground = (args) => (
Expand Down
Loading

0 comments on commit 4c4f2f4

Please sign in to comment.