-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create TimePicker component (#29252)
- Loading branch information
1 parent
01d9fdb
commit 5d04798
Showing
14 changed files
with
198 additions
and
1 deletion.
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
1 change: 1 addition & 0 deletions
1
packages/react-components/react-timepicker-compat-preview/src/TimePicker.ts
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 @@ | ||
export * from './components/TimePicker/index'; |
9 changes: 9 additions & 0 deletions
9
...-components/react-timepicker-compat-preview/src/components/TimePicker/TimePicker.test.tsx
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,9 @@ | ||
import { isConformant } from '../../testing/isConformant'; | ||
import { TimePicker } from './TimePicker'; | ||
|
||
describe('TimePicker', () => { | ||
isConformant({ | ||
Component: TimePicker, | ||
displayName: 'TimePicker', | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
...react-components/react-timepicker-compat-preview/src/components/TimePicker/TimePicker.tsx
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,18 @@ | ||
import * as React from 'react'; | ||
import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
import { useTimePicker_unstable } from './useTimePicker'; | ||
import { renderTimePicker_unstable } from './renderTimePicker'; | ||
import { useTimePickerStyles_unstable } from './useTimePickerStyles.styles'; | ||
import type { TimePickerProps } from './TimePicker.types'; | ||
|
||
/** | ||
* TimePicker component - TODO: add more docs | ||
*/ | ||
export const TimePicker: ForwardRefComponent<TimePickerProps> = React.forwardRef((props, ref) => { | ||
const state = useTimePicker_unstable(props, ref); | ||
|
||
useTimePickerStyles_unstable(state); | ||
return renderTimePicker_unstable(state); | ||
}); | ||
|
||
TimePicker.displayName = 'TimePicker'; |
17 changes: 17 additions & 0 deletions
17
...-components/react-timepicker-compat-preview/src/components/TimePicker/TimePicker.types.ts
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,17 @@ | ||
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
|
||
export type TimePickerSlots = { | ||
root: Slot<'div'>; | ||
}; | ||
|
||
/** | ||
* TimePicker Props | ||
*/ | ||
export type TimePickerProps = ComponentProps<TimePickerSlots> & {}; | ||
|
||
/** | ||
* State used in rendering TimePicker | ||
*/ | ||
export type TimePickerState = ComponentState<TimePickerSlots>; | ||
// TODO: Remove semicolon from previous line, uncomment next line, and provide union of props to pick from TimePickerProps. | ||
// & Required<Pick<TimePickerProps, 'propName'>> |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-timepicker-compat-preview/src/components/TimePicker/index.ts
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,5 @@ | ||
export * from './TimePicker'; | ||
export * from './TimePicker.types'; | ||
export * from './renderTimePicker'; | ||
export * from './useTimePicker'; | ||
export * from './useTimePickerStyles.styles'; |
16 changes: 16 additions & 0 deletions
16
...components/react-timepicker-compat-preview/src/components/TimePicker/renderTimePicker.tsx
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,16 @@ | ||
/** @jsxRuntime classic */ | ||
/** @jsx createElement */ | ||
|
||
import { createElement } from '@fluentui/react-jsx-runtime'; | ||
import { assertSlots } from '@fluentui/react-utilities'; | ||
import type { TimePickerState, TimePickerSlots } from './TimePicker.types'; | ||
|
||
/** | ||
* Render the final JSX of TimePicker | ||
*/ | ||
export const renderTimePicker_unstable = (state: TimePickerState) => { | ||
assertSlots<TimePickerSlots>(state); | ||
|
||
// TODO Add additional slots in the appropriate place | ||
return <state.root />; | ||
}; |
31 changes: 31 additions & 0 deletions
31
...act-components/react-timepicker-compat-preview/src/components/TimePicker/useTimePicker.ts
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,31 @@ | ||
import * as React from 'react'; | ||
import { getNativeElementProps, slot } from '@fluentui/react-utilities'; | ||
import type { TimePickerProps, TimePickerState } from './TimePicker.types'; | ||
|
||
/** | ||
* Create the state required to render TimePicker. | ||
* | ||
* The returned state can be modified with hooks such as useTimePickerStyles_unstable, | ||
* before being passed to renderTimePicker_unstable. | ||
* | ||
* @param props - props from this instance of TimePicker | ||
* @param ref - reference to root HTMLElement of TimePicker | ||
*/ | ||
export const useTimePicker_unstable = (props: TimePickerProps, ref: React.Ref<HTMLElement>): TimePickerState => { | ||
return { | ||
// TODO add appropriate props/defaults | ||
components: { | ||
// TODO add each slot's element type or component | ||
root: 'div', | ||
}, | ||
// TODO add appropriate slots, for example: | ||
// mySlot: resolveShorthand(props.mySlot), | ||
root: slot.always( | ||
getNativeElementProps('div', { | ||
ref, | ||
...props, | ||
}), | ||
{ elementType: 'div' }, | ||
), | ||
}; | ||
}; |
33 changes: 33 additions & 0 deletions
33
...s/react-timepicker-compat-preview/src/components/TimePicker/useTimePickerStyles.styles.ts
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,33 @@ | ||
import { makeStyles, mergeClasses } from '@griffel/react'; | ||
import type { SlotClassNames } from '@fluentui/react-utilities'; | ||
import type { TimePickerSlots, TimePickerState } from './TimePicker.types'; | ||
|
||
export const timePickerClassNames: SlotClassNames<TimePickerSlots> = { | ||
root: 'fui-TimePicker', | ||
// TODO: add class names for all slots on TimePickerSlots. | ||
// Should be of the form `<slotName>: 'fui-TimePicker__<slotName>` | ||
}; | ||
|
||
/** | ||
* Styles for the root slot | ||
*/ | ||
const useStyles = makeStyles({ | ||
root: { | ||
// TODO Add default styles for the root element | ||
}, | ||
|
||
// TODO add additional classes for different states and/or slots | ||
}); | ||
|
||
/** | ||
* Apply styling to the TimePicker slots based on the state | ||
*/ | ||
export const useTimePickerStyles_unstable = (state: TimePickerState): TimePickerState => { | ||
const styles = useStyles(); | ||
state.root.className = mergeClasses(timePickerClassNames.root, styles.root, state.root.className); | ||
|
||
// TODO Add class names to slots, for example: | ||
// state.mySlot.className = mergeClasses(styles.mySlot, state.mySlot.className); | ||
|
||
return state; | ||
}; |
9 changes: 8 additions & 1 deletion
9
packages/react-components/react-timepicker-compat-preview/src/index.ts
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 +1,8 @@ | ||
export {}; | ||
export { | ||
TimePicker, | ||
renderTimePicker_unstable, | ||
timePickerClassNames, | ||
useTimePickerStyles_unstable, | ||
useTimePicker_unstable, | ||
} from './TimePicker'; | ||
export type { TimePickerProps, TimePickerSlots, TimePickerState } from './TimePicker'; |
5 changes: 5 additions & 0 deletions
5
...s/react-timepicker-compat-preview/stories/TimePicker/TimePickerBestPractices.md
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,5 @@ | ||
## Best practices | ||
|
||
### Do | ||
|
||
### Don't |
4 changes: 4 additions & 0 deletions
4
...mponents/react-timepicker-compat-preview/stories/TimePicker/TimePickerDefault.stories.tsx
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,4 @@ | ||
import * as React from 'react'; | ||
import { TimePicker, TimePickerProps } from '@fluentui/react-timepicker-compat-preview'; | ||
|
||
export const Default = (props: Partial<TimePickerProps>) => <TimePicker {...props} />; |
Empty file.
18 changes: 18 additions & 0 deletions
18
...ges/react-components/react-timepicker-compat-preview/stories/TimePicker/index.stories.tsx
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,18 @@ | ||
import { TimePicker } from '@fluentui/react-timepicker-compat-preview'; | ||
|
||
import descriptionMd from './TimePickerDescription.md'; | ||
import bestPracticesMd from './TimePickerBestPractices.md'; | ||
|
||
export { Default } from './TimePickerDefault.stories'; | ||
|
||
export default { | ||
title: 'Preview Components/TimePicker', | ||
component: TimePicker, | ||
parameters: { | ||
docs: { | ||
description: { | ||
component: [descriptionMd, bestPracticesMd].join('\n'), | ||
}, | ||
}, | ||
}, | ||
}; |