-
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
TimeInput: Expose as subcomponent of TimePicker #63145
Changes from all commits
7ecf53b
7e872c4
1bb3f2f
d94947d
27df6fc
4e659e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ import TimePicker from '../time'; | |
const meta: Meta< typeof TimePicker > = { | ||
title: 'Components/TimePicker', | ||
component: TimePicker, | ||
// @ts-expect-error - See https://github.com/storybookjs/storybook/issues/23170 | ||
subcomponents: { 'TimePicker.TimeInput': TimePicker.TimeInput }, | ||
argTypes: { | ||
currentTime: { control: 'date' }, | ||
onChange: { action: 'onChange', control: { type: null } }, | ||
|
@@ -49,3 +51,18 @@ const Template: StoryFn< typeof TimePicker > = ( { | |
}; | ||
|
||
export const Default: StoryFn< typeof TimePicker > = Template.bind( {} ); | ||
|
||
const TimeInputTemplate: StoryFn< typeof TimePicker.TimeInput > = ( args ) => { | ||
return <TimePicker.TimeInput { ...args } />; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Felt a bit odd to me that the Screen.Recording.2024-07-05.at.13.32.06.movThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, I should've hidden the controls for that story (1bb3f2f). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch 😳 Fixed in d94947d |
||
}; | ||
|
||
/** | ||
* The time input can be used in isolation as `<TimePicker.TimeInput />`. In this case, the `value` will be passed | ||
* as an object in 24-hour format (`{ hours: number, minutes: number }`). | ||
*/ | ||
export const TimeInput = TimeInputTemplate.bind( {} ); | ||
TimeInput.args = { | ||
label: 'Time', | ||
}; | ||
// Hide TimePicker controls because they don't apply to TimeInput | ||
TimeInput.parameters = { controls: { include: [] } }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ import { | |
validateInputElementTarget, | ||
} from '../utils'; | ||
import { TIMEZONELESS_FORMAT } from '../constants'; | ||
import { TimeInput } from '../time-input'; | ||
import { TimeInput } from './time-input'; | ||
|
||
const VALID_DATE_ORDERS = [ 'dmy', 'mdy', 'ymd' ]; | ||
|
||
|
@@ -252,4 +252,29 @@ export function TimePicker( { | |
); | ||
} | ||
|
||
/** | ||
* A component to input a time. | ||
* | ||
* Values are passed as an object in 24-hour format (`{ hours: number, minutes: number }`). | ||
* | ||
* ```jsx | ||
* import { TimePicker } from '@wordpress/components'; | ||
* import { useState } from '@wordpress/element'; | ||
* | ||
* const MyTimeInput = () => { | ||
* const [ time, setTime ] = useState( { hours: 13, minutes: 30 } ); | ||
* | ||
* return ( | ||
* <TimePicker.TimeInput | ||
* value={ time } | ||
* onChange={ setTime } | ||
* label="Time" | ||
* /> | ||
* ); | ||
* }; | ||
* ``` | ||
*/ | ||
TimePicker.TimeInput = TimeInput; | ||
Object.assign( TimePicker.TimeInput, { displayName: 'TimePicker.TimeInput' } ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're now exposing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. I'll be adding a readme in the next PR. I guess there is a bit of inconsistency for subcomponent readmes, but I think TimeInput warrants a separate readme because the props are distinct.
It doesn't seem like an oversight, because the DateTimePicker readme does mention that DatePicker and TimePicker can be used individually. |
||
|
||
export default TimePicker; |
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.
👍