Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toggle control component to Storybook #18388

Merged
merged 1 commit into from
Nov 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions packages/components/src/toggle-control/stories/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* External dependencies
*/
import { text } from '@storybook/addon-knobs';

/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import ToggleControl from '../';

export default { title: 'ToggleControl', component: ToggleControl };

const ToggleControlWithState = ( { helpTextChecked, helpTextUnchecked, ...props } ) => {
const [ hasFixedBackground, setHasFixedBackground ] = useState( true );
return (
<ToggleControl
{ ...props }
help={ hasFixedBackground ? helpTextChecked : helpTextUnchecked }
checked={ hasFixedBackground }
onChange={ setHasFixedBackground }
/>
);
};

export const _default = () => {
const label = text( 'Label', 'Does this have a fixed background?' );

return (
<ToggleControlWithState
label={ label }
/>
);
};

export const withHelpText = () => {
const label = text( 'Label', 'Does this have a fixed background?' );
const helpTextChecked = text( 'Help When Checked', 'Has fixed background.' );
const helpTextUnchecked = text( 'Help When Unchecked', 'No fixed background.' );

return (
<ToggleControlWithState
label={ label }
helpTextChecked={ helpTextChecked }
helpTextUnchecked={ helpTextUnchecked }
/>
);
};