-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add toggle control component to storybook (#18388)
- Loading branch information
1 parent
0868611
commit 37301b8
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
/> | ||
); | ||
}; |