Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Migrate some stories to use @storybook/addon-controls
Browse files Browse the repository at this point in the history
Add a comment for @storybook/addon-knobs
  • Loading branch information
chihsuan committed Mar 17, 2022
1 parent 8db1f58 commit 2528aed
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 48 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
"@storybook/addon-a11y": "^6.4.19",
"@storybook/addon-actions": "^6.4.19",
"@storybook/addon-console": "^1.2.3",
"@storybook/addon-controls": "^6.4.19",
"@storybook/addon-docs": "^6.4.19",
"@storybook/addon-knobs": "^6.4.0",
"@storybook/addon-links": "^6.4.19",
Expand Down
3 changes: 2 additions & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"types": "build-types",
"dependencies": {
"@automattic/interpolate-components": "^1.2.0",
"@storybook/addon-knobs": "^6.4.0",
"@woocommerce/csv-export": "workspace:*",
"@woocommerce/currency": "workspace:*",
"@woocommerce/data": "workspace:*",
Expand Down Expand Up @@ -80,7 +79,9 @@
"@babel/core": "^7.17.5",
"@storybook/addon-actions": "^6.4.0",
"@storybook/addon-console": "^1.2.3",
"@storybook/addon-controls": "^6.4.19",
"@storybook/addon-docs": "^6.4.19",
"@storybook/addon-knobs": "^6.4.0",
"@storybook/addon-links": "^6.4.19",
"@storybook/addons": "^6.4.0",
"@storybook/api": "^6.4.0",
Expand Down
25 changes: 11 additions & 14 deletions packages/components/src/chart/stories/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { select } from '@storybook/addon-knobs';

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -186,15 +181,17 @@ const data = [
export default {
title: 'WooCommerce Admin/components/Chart',
component: Chart,
args: {
legendPosition: undefined,
},
argTypes: {
legendPosition: {
control: { type: 'select' },
options: [ undefined, 'bottom', 'side', 'top', 'hidden' ],
},
},
};

export const Default = () => (
<Chart
data={ data }
legendPosition={ select(
'Legend Position',
[ undefined, 'bottom', 'side', 'top', 'hidden' ],
undefined
) }
/>
export const Default = ( { legendPosition } ) => (
<Chart data={ data } legendPosition={ legendPosition } />
);
15 changes: 9 additions & 6 deletions packages/components/src/pagination/stories/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { number, boolean } from '@storybook/addon-knobs';

import { createElement, useState } from '@wordpress/element';

/**
Expand All @@ -12,22 +12,25 @@ import Pagination from '../';
export default {
title: 'WooCommerce Admin/components/Pagination',
component: Pagination,
args: {
total: 500,
showPagePicker: true,
showPerPagePicker: true,
showPageArrowsLabel: true,
},
};

export const Default = () => {
export const Default = ( args ) => {
const [ statePage, setPage ] = useState( 2 );
const [ statePerPage, setPerPage ] = useState( 50 );

return (
<Pagination
page={ statePage }
perPage={ statePerPage }
total={ number( 'Total', 500 ) }
showPagePicker={ boolean( 'Page Picker', true ) }
showPerPagePicker={ boolean( 'Per Page Picker', true ) }
showPageArrowsLabel={ boolean( 'Page Arrows Label', true ) }
onPageChange={ ( newPage ) => setPage( newPage ) }
onPerPageChange={ ( newPerPage ) => setPerPage( newPerPage ) }
{ ...args }
/>
);
};
18 changes: 6 additions & 12 deletions packages/components/src/rating/stories/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { number } from '@storybook/addon-knobs';

/**
* Internal dependencies
*/
Expand All @@ -11,12 +6,11 @@ import Rating from '../';
export default {
title: 'WooCommerce Admin/components/Rating',
component: Rating,
args: {
rating: 4.5,
totalStars: Rating.defaultProps.totalStars,
size: Rating.defaultProps.size,
},
};

export const Default = () => (
<Rating
rating={ number( 'Rating', 4.5 ) }
totalStars={ number( 'Total Stars', Rating.defaultProps.totalStars ) }
size={ number( 'Size', Rating.defaultProps.size ) }
/>
);
export const Default = ( args ) => <Rating { ...args } />;
32 changes: 24 additions & 8 deletions packages/components/src/search-list-control/stories/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
/**
* External dependencies
*/
import { boolean } from '@storybook/addon-knobs';
import { SearchListControl } from '@woocommerce/components';
import { useState } from '@wordpress/element';

const SearchListControlExample = () => {
const SearchListControlExample = ( { showCount, isCompact, isSingle } ) => {
const [ selected, setSelected ] = useState( [] );
const [ loading, setLoading ] = useState( false );

const showCount = boolean( 'Show count', false );
const isCompact = boolean( 'Compact', false );
const isSingle = boolean( 'Single', false );

let list = [
{ id: 1, name: 'Apricots' },
{ id: 2, name: 'Clementine' },
Expand Down Expand Up @@ -44,9 +38,31 @@ const SearchListControlExample = () => {
);
};

export const Basic = () => <SearchListControlExample />;
export const Basic = ( args ) => <SearchListControlExample { ...args } />;

export default {
title: 'WooCommerce Admin/components/SearchListControl',
component: SearchListControl,
args: {
showCount: false,
isCompact: false,
isSingle: false,
},
argTypes: {
showCount: {
control: {
type: 'boolean',
},
},
isCompact: {
control: {
type: 'boolean',
},
},
isSingle: {
control: {
type: 'boolean',
},
},
},
};
Loading

0 comments on commit 2528aed

Please sign in to comment.