-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
BaseControl: Refactor stories to use Controls #38741
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,38 +1,81 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { boolean, text } from '@storybook/addon-knobs'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BaseControl from '../'; | ||
import Button from '../../button'; | ||
import { Spacer } from '../../spacer'; | ||
import TextareaControl from '../../textarea-control'; | ||
|
||
export default { | ||
title: 'Components/BaseControl', | ||
component: BaseControl, | ||
parameters: { | ||
knobs: { disable: false }, | ||
}, | ||
subcomponents: { BaseControl: BaseControl.VisualLabel }, | ||
}; | ||
|
||
export const _default = () => { | ||
const id = text( 'Id', 'textarea-1' ); | ||
const label = text( 'Label', 'Label text' ); | ||
const hideLabelFromVision = boolean( 'Hide label from vision', false ); | ||
const help = text( 'Help', 'Help text' ); | ||
const className = text( 'ClassName', '' ); | ||
|
||
const BaseControlWithTextarea = ( { id, ...props } ) => { | ||
return ( | ||
<BaseControl | ||
id={ id } | ||
label={ label } | ||
help={ help } | ||
hideLabelFromVision={ hideLabelFromVision } | ||
className={ className } | ||
> | ||
<BaseControl id={ id } { ...props }> | ||
<TextareaControl id={ id } /> | ||
</BaseControl> | ||
); | ||
}; | ||
|
||
export const Default = BaseControlWithTextarea.bind( {} ); | ||
Default.args = { | ||
id: 'textarea-1', | ||
label: '', | ||
hideLabelFromVision: false, | ||
help: '', | ||
}; | ||
|
||
export const WithLabel = BaseControlWithTextarea.bind( {} ); | ||
WithLabel.args = { | ||
...Default.args, | ||
label: 'Label text', | ||
}; | ||
|
||
export const WithHelpText = BaseControlWithTextarea.bind( {} ); | ||
WithHelpText.args = { | ||
...WithLabel.args, | ||
help: 'Help text adds more explanation.', | ||
}; | ||
|
||
export const WithVisualLabel = ( { visualLabelChildren, ...props } ) => { | ||
return ( | ||
<> | ||
<BaseControl { ...props }> | ||
<div> | ||
<BaseControl.VisualLabel> | ||
{ visualLabelChildren } | ||
</BaseControl.VisualLabel> | ||
</div> | ||
<Button variant="secondary">Select an author</Button> | ||
</BaseControl> | ||
<Spacer marginTop={ 12 }> | ||
<p> | ||
<code>BaseControl.VisualLabel</code> is used to render a | ||
purely visual label inside a <code>BaseControl</code>{ ' ' } | ||
component. | ||
</p> | ||
<p> | ||
It should <strong>only</strong> be used in cases where the | ||
children being rendered inside BaseControl are already | ||
accessibly labeled, e.g., a button, but we want an | ||
additional visual label for that section equivalent to the | ||
labels BaseControl would otherwise use if the{ ' ' } | ||
<code>label</code> prop was passed. | ||
</p> | ||
</Spacer> | ||
</> | ||
); | ||
}; | ||
WithVisualLabel.args = { | ||
...Default.args, | ||
help: 'This button is already accessibly labeled.', | ||
visualLabelChildren: 'Author', | ||
}; | ||
WithVisualLabel.argTypes = { | ||
visualLabelChildren: { | ||
name: 'VisualLabel children', | ||
}, | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about the
subcomponents
flag — it's probably something that we should use in all stories related to a component "family" — e.g.Card
,ItemGroup
,ToolsPanel
...