-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SelectControl: Finish typescript migration (#40737)
* SelectControl: Move types * Inherit types from underlying components * Add named export * Convert stories to TS and Controls * Convert tests * Add changelog * Simplify size prop types Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com> * Use `text` control for prefix/suffix props Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
- Loading branch information
Showing
9 changed files
with
204 additions
and
150 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
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
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
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
104 changes: 0 additions & 104 deletions
104
packages/components/src/select-control/stories/index.js
This file was deleted.
Oops, something went wrong.
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,90 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
import type { ComponentProps } from 'react'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import SelectControl from '..'; | ||
|
||
const meta: ComponentMeta< typeof SelectControl > = { | ||
title: 'Components/SelectControl', | ||
component: SelectControl, | ||
argTypes: { | ||
help: { control: { type: 'text' } }, | ||
label: { control: { type: 'text' } }, | ||
prefix: { control: { type: 'text' } }, | ||
suffix: { control: { type: 'text' } }, | ||
value: { control: { type: null } }, | ||
}, | ||
parameters: { | ||
controls: { expanded: true }, | ||
docs: { source: { state: 'open' } }, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
const SelectControlWithState: ComponentStory< typeof SelectControl > = ( | ||
args | ||
) => { | ||
const [ selection, setSelection ] = useState< | ||
ComponentProps< typeof SelectControl >[ 'value' ] | ||
>(); | ||
|
||
return ( | ||
<SelectControl | ||
{ ...args } | ||
value={ selection } | ||
onChange={ setSelection } | ||
/> | ||
); | ||
}; | ||
|
||
export const Default = SelectControlWithState.bind( {} ); | ||
Default.args = { | ||
options: [ | ||
{ value: '', label: 'Select an Option', disabled: true }, | ||
{ value: 'a', label: 'Option A' }, | ||
{ value: 'b', label: 'Option B' }, | ||
{ value: 'c', label: 'Option C' }, | ||
], | ||
}; | ||
|
||
export const WithLabelAndHelpText = SelectControlWithState.bind( {} ); | ||
WithLabelAndHelpText.args = { | ||
...Default.args, | ||
help: 'Help text to explain the select control.', | ||
label: 'Value', | ||
}; | ||
|
||
/** | ||
* As an alternative to the `options` prop, `optgroup`s and `options` can be | ||
* passed in as `children` for more customizability. | ||
*/ | ||
export const WithCustomChildren: ComponentStory< typeof SelectControl > = ( | ||
args | ||
) => { | ||
return ( | ||
<SelectControlWithState { ...args }> | ||
<option value="option-1">Option 1</option> | ||
<option value="option-2" disabled> | ||
Option 2 - Disabled | ||
</option> | ||
<optgroup label="Option Group 1"> | ||
<option value="option-group-1-option-1"> | ||
Option Group 1 - Option 1 | ||
</option> | ||
<option value="option-group-1-option-2" disabled> | ||
Option Group 1 - Option 2 - Disabled | ||
</option> | ||
</optgroup> | ||
</SelectControlWithState> | ||
); | ||
}; |
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
Oops, something went wrong.