@fluentui/react-timepicker-compat 0.1.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -3
- package/dist/index.d.ts +2 -2
- package/lib/components/TimePicker/TimePicker.types.js.map +1 -1
- package/lib/components/TimePicker/useTimePicker.js +20 -9
- package/lib/components/TimePicker/useTimePicker.js.map +1 -1
- package/lib/components/TimePicker/useTimePickerStyles.styles.js +4 -0
- package/lib/components/TimePicker/useTimePickerStyles.styles.js.map +1 -1
- package/lib-commonjs/components/TimePicker/useTimePicker.js +20 -9
- package/lib-commonjs/components/TimePicker/useTimePicker.js.map +1 -1
- package/lib-commonjs/components/TimePicker/useTimePickerStyles.styles.js +4 -0
- package/lib-commonjs/components/TimePicker/useTimePickerStyles.styles.js.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,17 +1,34 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-timepicker-compat
|
|
2
2
|
|
|
3
|
-
This log was last generated on Tue,
|
|
3
|
+
This log was last generated on Tue, 20 Feb 2024 14:15:30 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [0.2.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-timepicker-compat_v0.2.0)
|
|
8
|
+
|
|
9
|
+
Tue, 20 Feb 2024 14:15:30 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-timepicker-compat_v0.1.9..@fluentui/react-timepicker-compat_v0.2.0)
|
|
11
|
+
|
|
12
|
+
### Minor changes
|
|
13
|
+
|
|
14
|
+
- feat: add "clearable" prop ([PR #30512](https://github.com/microsoft/fluentui/pull/30512) by olfedias@microsoft.com)
|
|
15
|
+
- Bump @fluentui/react-combobox to v9.8.0 ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by beachball)
|
|
16
|
+
- Bump @fluentui/react-field to v9.1.54 ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by beachball)
|
|
17
|
+
- Bump @fluentui/react-jsx-runtime to v9.0.30 ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by beachball)
|
|
18
|
+
- Bump @fluentui/react-utilities to v9.18.1 ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by beachball)
|
|
19
|
+
|
|
20
|
+
### Patches
|
|
21
|
+
|
|
22
|
+
- refactor: update activedescendant management from combobox ([PR #30539](https://github.com/microsoft/fluentui/pull/30539) by lingfan.gao@microsoft.com)
|
|
23
|
+
|
|
7
24
|
## [0.1.9](https://github.com/microsoft/fluentui/tree/@fluentui/react-timepicker-compat_v0.1.9)
|
|
8
25
|
|
|
9
|
-
Tue, 06 Feb 2024 17:
|
|
26
|
+
Tue, 06 Feb 2024 17:55:21 GMT
|
|
10
27
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-timepicker-compat_v0.1.8..@fluentui/react-timepicker-compat_v0.1.9)
|
|
11
28
|
|
|
12
29
|
### Patches
|
|
13
30
|
|
|
14
|
-
- Bump @fluentui/react-combobox to v9.7.5 ([PR #
|
|
31
|
+
- Bump @fluentui/react-combobox to v9.7.5 ([PR #30392](https://github.com/microsoft/fluentui/pull/30392) by beachball)
|
|
15
32
|
|
|
16
33
|
## [0.1.8](https://github.com/microsoft/fluentui/tree/@fluentui/react-timepicker-compat_v0.1.8)
|
|
17
34
|
|
package/dist/index.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export declare type TimePickerErrorType = 'invalid-input' | 'out-of-bounds' | 'r
|
|
|
55
55
|
/**
|
|
56
56
|
* TimePicker Props
|
|
57
57
|
*/
|
|
58
|
-
export declare type TimePickerProps = Omit<ComponentProps<Partial<ComboboxSlots>, 'input'>, 'children' | 'size'> & Pick<ComboboxProps, 'appearance' | 'defaultOpen' | 'defaultValue' | 'inlinePopup' | 'onOpenChange' | 'open' | 'placeholder' | 'positioning' | 'size' | 'value' | 'mountNode' | 'freeform'> & TimeFormatOptions & {
|
|
58
|
+
export declare type TimePickerProps = Omit<ComponentProps<Partial<ComboboxSlots>, 'input'>, 'children' | 'size'> & Pick<ComboboxProps, 'appearance' | 'clearable' | 'defaultOpen' | 'defaultValue' | 'inlinePopup' | 'onOpenChange' | 'open' | 'placeholder' | 'positioning' | 'size' | 'value' | 'mountNode' | 'freeform'> & TimeFormatOptions & {
|
|
59
59
|
/**
|
|
60
60
|
* Start hour (inclusive) for the time range, 0-24.
|
|
61
61
|
*/
|
|
@@ -94,7 +94,7 @@ export declare type TimePickerProps = Omit<ComponentProps<Partial<ComboboxSlots>
|
|
|
94
94
|
parseTimeStringToDate?: (time: string | undefined) => TimeStringValidationResult;
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
-
export declare type TimePickerSlots =
|
|
97
|
+
export declare type TimePickerSlots = ComboboxSlots;
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
100
|
* State used in rendering TimePicker
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["TimePicker.types.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ComboboxSlots, ComboboxState, ComboboxProps, SelectionEvents } from '@fluentui/react-combobox';\nimport type { ComponentProps } from '@fluentui/react-utilities';\n\nexport type Hour =\n | 0\n | 1\n | 2\n | 3\n | 4\n | 5\n | 6\n | 7\n | 8\n | 9\n | 10\n | 11\n | 12\n | 13\n | 14\n | 15\n | 16\n | 17\n | 18\n | 19\n | 20\n | 21\n | 22\n | 23\n | 24;\n\n/**\n * Data structure for rendering options in the TimePicker.\n */\nexport type TimePickerOption = {\n /**\n * The Date object associated with the option.\n */\n date: Date;\n\n /**\n * A unique identifier for the option.\n */\n key: string;\n\n /**\n * The display text for the option within the Combobox dropdown.\n */\n text: string;\n};\n\n/**\n * Error types returned by the `onValidationResult` callback.\n */\nexport type TimePickerErrorType = 'invalid-input' | 'out-of-bounds' | 'required-input';\n\nexport type TimeStringValidationResult = {\n date: Date | null;\n errorType?: TimePickerErrorType;\n};\n\nexport type TimePickerSlots =
|
|
1
|
+
{"version":3,"sources":["TimePicker.types.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ComboboxSlots, ComboboxState, ComboboxProps, SelectionEvents } from '@fluentui/react-combobox';\nimport type { ComponentProps } from '@fluentui/react-utilities';\n\nexport type Hour =\n | 0\n | 1\n | 2\n | 3\n | 4\n | 5\n | 6\n | 7\n | 8\n | 9\n | 10\n | 11\n | 12\n | 13\n | 14\n | 15\n | 16\n | 17\n | 18\n | 19\n | 20\n | 21\n | 22\n | 23\n | 24;\n\n/**\n * Data structure for rendering options in the TimePicker.\n */\nexport type TimePickerOption = {\n /**\n * The Date object associated with the option.\n */\n date: Date;\n\n /**\n * A unique identifier for the option.\n */\n key: string;\n\n /**\n * The display text for the option within the Combobox dropdown.\n */\n text: string;\n};\n\n/**\n * Error types returned by the `onValidationResult` callback.\n */\nexport type TimePickerErrorType = 'invalid-input' | 'out-of-bounds' | 'required-input';\n\nexport type TimeStringValidationResult = {\n date: Date | null;\n errorType?: TimePickerErrorType;\n};\n\nexport type TimePickerSlots = ComboboxSlots;\n\nexport type TimeSelectionEvents = SelectionEvents | React.FocusEvent<HTMLElement>;\nexport type TimeSelectionData = {\n /**\n * The Date object associated with the selected option. For freeform TimePicker it can also be the Date object parsed from the user input.\n */\n selectedTime: Date | null;\n /**\n * The display text for the selected option. For freeform TimePicker it can also be the value in user input.\n */\n selectedTimeText: string | undefined;\n /**\n * The error type for the selected option.\n */\n errorType: TimePickerErrorType | undefined;\n};\n\nexport type TimeFormatOptions = {\n /**\n * A string value indicating whether the 12-hour format (\"h11\", \"h12\") or the 24-hour format (\"h23\", \"h24\") should be used.\n * - 'h11' and 'h23' start with hour 0 and go up to 11 and 23 respectively.\n * - 'h12' and 'h24' start with hour 1 and go up to 12 and 24 respectively.\n * @default undefined\n */\n hourCycle?: 'h11' | 'h12' | 'h23' | 'h24' | undefined;\n\n /**\n * If true, show seconds in the dropdown options and consider seconds for default validation purposes.\n */\n showSeconds?: boolean;\n};\n\n/**\n * TimePicker Props\n */\nexport type TimePickerProps = Omit<ComponentProps<Partial<ComboboxSlots>, 'input'>, 'children' | 'size'> &\n Pick<\n ComboboxProps,\n | 'appearance'\n | 'clearable'\n | 'defaultOpen'\n | 'defaultValue'\n | 'inlinePopup'\n | 'onOpenChange'\n | 'open'\n | 'placeholder'\n | 'positioning'\n | 'size'\n | 'value'\n | 'mountNode'\n | 'freeform'\n > &\n TimeFormatOptions & {\n /**\n * Start hour (inclusive) for the time range, 0-24.\n */\n startHour?: Hour;\n\n /**\n * End hour (exclusive) for the time range, 0-24.\n */\n endHour?: Hour;\n\n /**\n * Time increment, in minutes, of the options in the dropdown.\n */\n increment?: number;\n\n /**\n * The date in which all dropdown options are based off of.\n */\n dateAnchor?: Date;\n\n /**\n * Currently selected time in the TimePicker.\n */\n selectedTime?: Date | null;\n\n /**\n * Default selected time in the TimePicker, for uncontrolled scenarios.\n */\n defaultSelectedTime?: Date;\n\n /**\n * Callback for when a time selection is made.\n */\n // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback\n onTimeChange?: (event: TimeSelectionEvents, data: TimeSelectionData) => void;\n\n /**\n * Customizes the formatting of date strings displayed in dropdown options.\n */\n formatDateToTimeString?: (date: Date) => string;\n\n /**\n * In the freeform TimePicker, customizes the parsing from the input time string into a Date and provides custom validation.\n */\n parseTimeStringToDate?: (time: string | undefined) => TimeStringValidationResult;\n };\n\n/**\n * State used in rendering TimePicker\n */\nexport type TimePickerState = ComboboxState &\n Required<Pick<TimePickerProps, 'freeform' | 'parseTimeStringToDate'>> & {\n /**\n * Submitted text from the input field. It is used to determine if the input value has changed when user submit a new value on Enter or blur from input.\n */\n submittedText: string | undefined;\n };\n"],"names":["React"],"mappings":"AAAA,YAAYA,WAAW,QAAQ"}
|
|
@@ -124,23 +124,33 @@ import { dateToKey, keyToDate, formatDateToTimeString as defaultFormatDateToTime
|
|
|
124
124
|
* - Enter/Tab key is pressed on the input.
|
|
125
125
|
* - TimePicker loses focus, signifying a possible change.
|
|
126
126
|
*/ const useSelectTimeFromValue = (state, callback)=>{
|
|
127
|
-
const {
|
|
127
|
+
const { getOptionById, freeform, parseTimeStringToDate, submittedText, value, activeDescendantController } = state;
|
|
128
|
+
const getActiveOption = React.useCallback(()=>{
|
|
129
|
+
const activeOptionId = activeDescendantController.active();
|
|
130
|
+
return activeOptionId ? getOptionById(activeOptionId) : null;
|
|
131
|
+
}, [
|
|
132
|
+
activeDescendantController,
|
|
133
|
+
getOptionById
|
|
134
|
+
]);
|
|
128
135
|
// Base Combobox has activeOption default to first option in dropdown even if it doesn't match input value, and Enter key will select it.
|
|
129
136
|
// This effect ensures that the activeOption is cleared when the input doesn't match any option.
|
|
130
137
|
// This behavior is specific to a freeform TimePicker where the input value is treated as a valid time even if it's not in the dropdown.
|
|
131
138
|
React.useEffect(()=>{
|
|
132
139
|
if (freeform && value) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
140
|
+
const activeOption = getActiveOption();
|
|
141
|
+
if (!activeOption) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const valueMatchesActiveOption = activeOption.text.toLowerCase().indexOf(value.toLowerCase()) === 0;
|
|
145
|
+
if (!valueMatchesActiveOption) {
|
|
146
|
+
activeDescendantController.blur();
|
|
147
|
+
}
|
|
139
148
|
}
|
|
140
149
|
}, [
|
|
141
150
|
freeform,
|
|
142
|
-
|
|
143
|
-
|
|
151
|
+
value,
|
|
152
|
+
activeDescendantController,
|
|
153
|
+
getActiveOption
|
|
144
154
|
]);
|
|
145
155
|
const selectTimeFromValue = useEventCallback((e)=>{
|
|
146
156
|
if (!freeform) {
|
|
@@ -157,6 +167,7 @@ import { dateToKey, keyToDate, formatDateToTimeString as defaultFormatDateToTime
|
|
|
157
167
|
}
|
|
158
168
|
});
|
|
159
169
|
const handleKeyDown = useEventCallback((e)=>{
|
|
170
|
+
const activeOption = getActiveOption();
|
|
160
171
|
if (!activeOption && e.key === Enter) {
|
|
161
172
|
selectTimeFromValue(e);
|
|
162
173
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useTimePicker.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n elementContains,\n mergeCallbacks,\n useControllableState,\n useEventCallback,\n useId,\n useMergedRefs,\n} from '@fluentui/react-utilities';\nimport { Enter } from '@fluentui/keyboard-keys';\nimport type { Hour, TimePickerOption, TimePickerProps, TimePickerState, TimeSelectionData } from './TimePicker.types';\nimport { ComboboxProps, useCombobox_unstable, Option } from '@fluentui/react-combobox';\nimport { useFieldContext_unstable as useFieldContext } from '@fluentui/react-field';\nimport {\n dateToKey,\n keyToDate,\n formatDateToTimeString as defaultFormatDateToTimeString,\n getDateStartAnchor,\n getDateEndAnchor,\n getTimesBetween,\n getDateFromTimeString,\n} from './timeMath';\n\n/**\n * Create the state required to render TimePicker.\n *\n * The returned state can be modified with hooks such as useTimePickerStyles_unstable,\n * before being passed to renderTimePicker_unstable.\n *\n * @param props - props from this instance of TimePicker\n * @param ref - reference to root HTMLElement of TimePicker\n */\nexport const useTimePicker_unstable = (props: TimePickerProps, ref: React.Ref<HTMLInputElement>): TimePickerState => {\n const {\n dateAnchor: dateAnchorInProps,\n defaultSelectedTime: defaultSelectedTimeInProps,\n endHour = 24,\n formatDateToTimeString = defaultFormatDateToTimeString,\n hourCycle,\n increment = 30,\n onTimeChange,\n selectedTime: selectedTimeInProps,\n showSeconds = false,\n startHour = 0,\n parseTimeStringToDate: parseTimeStringToDateInProps,\n ...rest\n } = props;\n const { freeform = false } = rest;\n\n const { dateStartAnchor, dateEndAnchor } = useStableDateAnchor(\n dateAnchorInProps ?? selectedTimeInProps ?? defaultSelectedTimeInProps,\n startHour,\n endHour,\n );\n\n const options: TimePickerOption[] = React.useMemo(\n () =>\n getTimesBetween(dateStartAnchor, dateEndAnchor, increment).map(time => ({\n date: time,\n key: dateToKey(time),\n text: formatDateToTimeString(time, { showSeconds, hourCycle }),\n })),\n [dateEndAnchor, dateStartAnchor, formatDateToTimeString, hourCycle, increment, showSeconds],\n );\n\n const [selectedTime, setSelectedTime] = useControllableState<Date | null>({\n state: selectedTimeInProps,\n defaultState: defaultSelectedTimeInProps,\n initialState: null,\n });\n\n const [submittedText, setSubmittedText] = React.useState<string | undefined>(undefined);\n\n const selectTime: TimePickerProps['onTimeChange'] = useEventCallback((e, data) => {\n setSelectedTime(data.selectedTime);\n setSubmittedText(data.selectedTimeText);\n onTimeChange?.(e, data);\n });\n\n const selectedOptions = React.useMemo(() => {\n const selectedTimeKey = dateToKey(selectedTime);\n const selectedOption = options.find(date => date.key === selectedTimeKey);\n return selectedOption ? [selectedOption.key] : [];\n }, [options, selectedTime]);\n\n const handleOptionSelect: ComboboxProps['onOptionSelect'] = useEventCallback((e, data) => {\n if (freeform && data.optionValue === undefined) {\n // Combobox clears selection when input value not matching any option; but we allow this case in freeform TimePicker.\n return;\n }\n const timeSelectionData: TimeSelectionData = {\n selectedTime: keyToDate(data.optionValue ?? ''),\n selectedTimeText: data.optionText,\n errorType: undefined,\n };\n selectTime(e, timeSelectionData);\n });\n\n const baseState = useCombobox_unstable(\n {\n autoComplete: 'off',\n ...rest,\n selectedOptions,\n onOptionSelect: handleOptionSelect,\n children: options.map(date => (\n <Option key={date.key} value={date.key}>\n {date.text}\n </Option>\n )),\n },\n ref,\n );\n\n const defaultParseTimeStringToDate = React.useCallback(\n (time: string | undefined) =>\n getDateFromTimeString(time, dateStartAnchor, dateEndAnchor, { hourCycle, showSeconds }),\n [dateEndAnchor, dateStartAnchor, hourCycle, showSeconds],\n );\n\n const state: TimePickerState = {\n ...baseState,\n freeform,\n parseTimeStringToDate: parseTimeStringToDateInProps ?? defaultParseTimeStringToDate,\n submittedText,\n };\n\n useDefaultChevronIconLabel(state);\n useSelectTimeFromValue(state, selectTime);\n\n return state;\n};\n\n/**\n * Provides stable start and end date anchors based on the provided date and time parameters.\n * The hook ensures that the memoization remains consistent even if new Date objects representing the same date are provided.\n */\nconst useStableDateAnchor = (providedDate: Date | undefined, startHour: Hour, endHour: Hour) => {\n const [fallbackDateAnchor] = React.useState(() => new Date());\n\n const providedDateKey = dateToKey(providedDate ?? null);\n\n return React.useMemo(() => {\n const dateAnchor = providedDate ?? fallbackDateAnchor;\n\n const dateStartAnchor = getDateStartAnchor(dateAnchor, startHour);\n const dateEndAnchor = getDateEndAnchor(dateAnchor, startHour, endHour);\n\n return { dateStartAnchor, dateEndAnchor };\n // `providedDate`'s stable key representation is used as dependency instead of the Date object. This ensures that the memoization remains stable when a new Date object representing the same date is passed in.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [endHour, fallbackDateAnchor, providedDateKey, startHour]);\n};\n\n/**\n * Mimics the behavior of the browser's change event for a freeform TimePicker.\n * The provided callback is called when input changed and:\n * - Enter/Tab key is pressed on the input.\n * - TimePicker loses focus, signifying a possible change.\n */\nconst useSelectTimeFromValue = (state: TimePickerState, callback: TimePickerProps['onTimeChange']) => {\n const { activeOption, freeform, parseTimeStringToDate, submittedText, setActiveOption, value } = state;\n\n // Base Combobox has activeOption default to first option in dropdown even if it doesn't match input value, and Enter key will select it.\n // This effect ensures that the activeOption is cleared when the input doesn't match any option.\n // This behavior is specific to a freeform TimePicker where the input value is treated as a valid time even if it's not in the dropdown.\n React.useEffect(() => {\n if (freeform && value) {\n setActiveOption(prevActiveOption => {\n if (prevActiveOption?.text && prevActiveOption.text.toLowerCase().indexOf(value.toLowerCase()) === 0) {\n return prevActiveOption;\n }\n return undefined;\n });\n }\n }, [freeform, setActiveOption, value]);\n\n const selectTimeFromValue = useEventCallback(\n (e: React.KeyboardEvent<HTMLInputElement> | React.FocusEvent<HTMLInputElement>) => {\n if (!freeform) {\n return;\n }\n\n const { date: selectedTime, errorType } = parseTimeStringToDate(value);\n\n // Only triggers callback when the text in input has changed.\n if (submittedText !== value) {\n callback?.(e, { selectedTime, selectedTimeText: value, errorType });\n }\n },\n );\n\n const handleKeyDown: ComboboxProps['onKeyDown'] = useEventCallback(e => {\n if (!activeOption && e.key === Enter) {\n selectTimeFromValue(e);\n }\n });\n state.root.onKeyDown = mergeCallbacks(handleKeyDown, state.root.onKeyDown);\n\n const rootRef = React.useRef<HTMLDivElement>(null);\n state.root.ref = useMergedRefs(state.root.ref, rootRef);\n\n if (state.listbox) {\n state.listbox.tabIndex = -1; // allows it to be the relatedTarget of a blur event.\n }\n\n if (state.expandIcon) {\n state.expandIcon.tabIndex = -1; // allows it to be the relatedTarget of a blur event.\n }\n\n const handleInputBlur = useEventCallback((e: React.FocusEvent<HTMLInputElement>) => {\n const isOutside = e.relatedTarget ? !elementContains(rootRef.current, e.relatedTarget) : true;\n if (isOutside) {\n selectTimeFromValue(e);\n }\n });\n state.input.onBlur = mergeCallbacks(handleInputBlur, state.input.onBlur);\n};\n\n/**\n * Provides a default aria-labelledby for the chevron icon if the TimePicker is wrapped in a Field.\n */\nconst useDefaultChevronIconLabel = (state: TimePickerState) => {\n const fieldContext = useFieldContext();\n const chevronDefaultId = useId('timepicker-chevron-');\n const defaultLabelFromCombobox = 'Open';\n\n if (fieldContext?.labelId && state.expandIcon?.['aria-label'] === defaultLabelFromCombobox) {\n const chevronId = state.expandIcon.id ?? chevronDefaultId;\n state.expandIcon['aria-labelledby'] = `${chevronId} ${fieldContext.labelId}`;\n }\n};\n"],"names":["React","elementContains","mergeCallbacks","useControllableState","useEventCallback","useId","useMergedRefs","Enter","useCombobox_unstable","Option","useFieldContext_unstable","useFieldContext","dateToKey","keyToDate","formatDateToTimeString","defaultFormatDateToTimeString","getDateStartAnchor","getDateEndAnchor","getTimesBetween","getDateFromTimeString","useTimePicker_unstable","props","ref","dateAnchor","dateAnchorInProps","defaultSelectedTime","defaultSelectedTimeInProps","endHour","hourCycle","increment","onTimeChange","selectedTime","selectedTimeInProps","showSeconds","startHour","parseTimeStringToDate","parseTimeStringToDateInProps","rest","freeform","dateStartAnchor","dateEndAnchor","useStableDateAnchor","options","useMemo","map","time","date","key","text","setSelectedTime","state","defaultState","initialState","submittedText","setSubmittedText","useState","undefined","selectTime","e","data","selectedTimeText","selectedOptions","selectedTimeKey","selectedOption","find","handleOptionSelect","optionValue","timeSelectionData","optionText","errorType","baseState","autoComplete","onOptionSelect","children","value","defaultParseTimeStringToDate","useCallback","useDefaultChevronIconLabel","useSelectTimeFromValue","providedDate","fallbackDateAnchor","Date","providedDateKey","callback","activeOption","setActiveOption","useEffect","prevActiveOption","toLowerCase","indexOf","selectTimeFromValue","handleKeyDown","root","onKeyDown","rootRef","useRef","listbox","tabIndex","expandIcon","handleInputBlur","isOutside","relatedTarget","current","input","onBlur","fieldContext","chevronDefaultId","defaultLabelFromCombobox","labelId","chevronId","id"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SACEC,eAAe,EACfC,cAAc,EACdC,oBAAoB,EACpBC,gBAAgB,EAChBC,KAAK,EACLC,aAAa,QACR,4BAA4B;AACnC,SAASC,KAAK,QAAQ,0BAA0B;AAEhD,SAAwBC,oBAAoB,EAAEC,MAAM,QAAQ,2BAA2B;AACvF,SAASC,4BAA4BC,eAAe,QAAQ,wBAAwB;AACpF,SACEC,SAAS,EACTC,SAAS,EACTC,0BAA0BC,6BAA6B,EACvDC,kBAAkB,EAClBC,gBAAgB,EAChBC,eAAe,EACfC,qBAAqB,QAChB,aAAa;AAEpB;;;;;;;;CAQC,GACD,OAAO,MAAMC,yBAAyB,CAACC,OAAwBC;IAC7D,MAAM,EACJC,YAAYC,iBAAiB,EAC7BC,qBAAqBC,0BAA0B,EAC/CC,UAAU,EAAE,EACZb,yBAAyBC,6BAA6B,EACtDa,SAAS,EACTC,YAAY,EAAE,EACdC,YAAY,EACZC,cAAcC,mBAAmB,EACjCC,cAAc,KAAK,EACnBC,YAAY,CAAC,EACbC,uBAAuBC,4BAA4B,EACnD,GAAGC,MACJ,GAAGhB;IACJ,MAAM,EAAEiB,WAAW,KAAK,EAAE,GAAGD;QA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MAAMgD,UAAU,CAACD,QAAQ,GAAG,CAAC,GAAG,qDAAqD;IACvF;IAEA,MAAME,kBAAkB/F,iBAAiB,CAACsD;QACxC,MAAM0C,YAAY1C,EAAE2C,aAAa,GAAG,CAACpG,gBAAgB6F,QAAQQ,OAAO,EAAE5C,EAAE2C,aAAa,IAAI;QACzF,IAAID,WAAW;YACbV,oBAAoBhC;QACtB;IACF;IACAR,MAAMqD,KAAK,CAACC,MAAM,GAAGtG,eAAeiG,iBAAiBjD,MAAMqD,KAAK,CAACC,MAAM;AACzE;AAEA;;CAEC,GACD,MAAM3B,6BAA6B,CAAC3B;QAKLA;IAJ7B,MAAMuD,eAAe9F;IACrB,MAAM+F,mBAAmBrG,MAAM;IAC/B,MAAMsG,2BAA2B;IAEjC,IAAIF,CAAAA,yBAAAA,mCAAAA,aAAcG,OAAO,KAAI1D,EAAAA,oBAAAA,MAAMgD,UAAU,cAAhBhD,wCAAAA,iBAAkB,CAAC,aAAa,MAAKyD,0BAA0B;YACxEzD;QAAlB,MAAM2D,YAAY3D,CAAAA,uBAAAA,MAAMgD,UAAU,CAACY,EAAE,cAAnB5D,kCAAAA,uBAAuBwD;QACzCxD,MAAMgD,UAAU,CAAC,kBAAkB,GAAG,CAAC,EAAEW,UAAU,CAAC,EAAEJ,aAAaG,OAAO,CAAC,CAAC;IAC9E;AACF"}
|
|
1
|
+
{"version":3,"sources":["useTimePicker.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n elementContains,\n mergeCallbacks,\n useControllableState,\n useEventCallback,\n useId,\n useMergedRefs,\n} from '@fluentui/react-utilities';\nimport { Enter } from '@fluentui/keyboard-keys';\nimport type { Hour, TimePickerOption, TimePickerProps, TimePickerState, TimeSelectionData } from './TimePicker.types';\nimport { ComboboxProps, useCombobox_unstable, Option } from '@fluentui/react-combobox';\nimport { useFieldContext_unstable as useFieldContext } from '@fluentui/react-field';\nimport {\n dateToKey,\n keyToDate,\n formatDateToTimeString as defaultFormatDateToTimeString,\n getDateStartAnchor,\n getDateEndAnchor,\n getTimesBetween,\n getDateFromTimeString,\n} from './timeMath';\n\n/**\n * Create the state required to render TimePicker.\n *\n * The returned state can be modified with hooks such as useTimePickerStyles_unstable,\n * before being passed to renderTimePicker_unstable.\n *\n * @param props - props from this instance of TimePicker\n * @param ref - reference to root HTMLElement of TimePicker\n */\nexport const useTimePicker_unstable = (props: TimePickerProps, ref: React.Ref<HTMLInputElement>): TimePickerState => {\n const {\n dateAnchor: dateAnchorInProps,\n defaultSelectedTime: defaultSelectedTimeInProps,\n endHour = 24,\n formatDateToTimeString = defaultFormatDateToTimeString,\n hourCycle,\n increment = 30,\n onTimeChange,\n selectedTime: selectedTimeInProps,\n showSeconds = false,\n startHour = 0,\n parseTimeStringToDate: parseTimeStringToDateInProps,\n ...rest\n } = props;\n const { freeform = false } = rest;\n\n const { dateStartAnchor, dateEndAnchor } = useStableDateAnchor(\n dateAnchorInProps ?? selectedTimeInProps ?? defaultSelectedTimeInProps,\n startHour,\n endHour,\n );\n\n const options: TimePickerOption[] = React.useMemo(\n () =>\n getTimesBetween(dateStartAnchor, dateEndAnchor, increment).map(time => ({\n date: time,\n key: dateToKey(time),\n text: formatDateToTimeString(time, { showSeconds, hourCycle }),\n })),\n [dateEndAnchor, dateStartAnchor, formatDateToTimeString, hourCycle, increment, showSeconds],\n );\n\n const [selectedTime, setSelectedTime] = useControllableState<Date | null>({\n state: selectedTimeInProps,\n defaultState: defaultSelectedTimeInProps,\n initialState: null,\n });\n\n const [submittedText, setSubmittedText] = React.useState<string | undefined>(undefined);\n\n const selectTime: TimePickerProps['onTimeChange'] = useEventCallback((e, data) => {\n setSelectedTime(data.selectedTime);\n setSubmittedText(data.selectedTimeText);\n onTimeChange?.(e, data);\n });\n\n const selectedOptions = React.useMemo(() => {\n const selectedTimeKey = dateToKey(selectedTime);\n const selectedOption = options.find(date => date.key === selectedTimeKey);\n return selectedOption ? [selectedOption.key] : [];\n }, [options, selectedTime]);\n\n const handleOptionSelect: ComboboxProps['onOptionSelect'] = useEventCallback((e, data) => {\n if (freeform && data.optionValue === undefined) {\n // Combobox clears selection when input value not matching any option; but we allow this case in freeform TimePicker.\n return;\n }\n const timeSelectionData: TimeSelectionData = {\n selectedTime: keyToDate(data.optionValue ?? ''),\n selectedTimeText: data.optionText,\n errorType: undefined,\n };\n selectTime(e, timeSelectionData);\n });\n\n const baseState = useCombobox_unstable(\n {\n autoComplete: 'off',\n ...rest,\n selectedOptions,\n onOptionSelect: handleOptionSelect,\n children: options.map(date => (\n <Option key={date.key} value={date.key}>\n {date.text}\n </Option>\n )),\n },\n ref,\n );\n\n const defaultParseTimeStringToDate = React.useCallback(\n (time: string | undefined) =>\n getDateFromTimeString(time, dateStartAnchor, dateEndAnchor, { hourCycle, showSeconds }),\n [dateEndAnchor, dateStartAnchor, hourCycle, showSeconds],\n );\n\n const state: TimePickerState = {\n ...baseState,\n freeform,\n parseTimeStringToDate: parseTimeStringToDateInProps ?? defaultParseTimeStringToDate,\n submittedText,\n };\n\n useDefaultChevronIconLabel(state);\n useSelectTimeFromValue(state, selectTime);\n\n return state;\n};\n\n/**\n * Provides stable start and end date anchors based on the provided date and time parameters.\n * The hook ensures that the memoization remains consistent even if new Date objects representing the same date are provided.\n */\nconst useStableDateAnchor = (providedDate: Date | undefined, startHour: Hour, endHour: Hour) => {\n const [fallbackDateAnchor] = React.useState(() => new Date());\n\n const providedDateKey = dateToKey(providedDate ?? null);\n\n return React.useMemo(() => {\n const dateAnchor = providedDate ?? fallbackDateAnchor;\n\n const dateStartAnchor = getDateStartAnchor(dateAnchor, startHour);\n const dateEndAnchor = getDateEndAnchor(dateAnchor, startHour, endHour);\n\n return { dateStartAnchor, dateEndAnchor };\n // `providedDate`'s stable key representation is used as dependency instead of the Date object. This ensures that the memoization remains stable when a new Date object representing the same date is passed in.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [endHour, fallbackDateAnchor, providedDateKey, startHour]);\n};\n\n/**\n * Mimics the behavior of the browser's change event for a freeform TimePicker.\n * The provided callback is called when input changed and:\n * - Enter/Tab key is pressed on the input.\n * - TimePicker loses focus, signifying a possible change.\n */\nconst useSelectTimeFromValue = (state: TimePickerState, callback: TimePickerProps['onTimeChange']) => {\n const { getOptionById, freeform, parseTimeStringToDate, submittedText, value, activeDescendantController } = state;\n const getActiveOption = React.useCallback(() => {\n const activeOptionId = activeDescendantController.active();\n return activeOptionId ? getOptionById(activeOptionId) : null;\n }, [activeDescendantController, getOptionById]);\n\n // Base Combobox has activeOption default to first option in dropdown even if it doesn't match input value, and Enter key will select it.\n // This effect ensures that the activeOption is cleared when the input doesn't match any option.\n // This behavior is specific to a freeform TimePicker where the input value is treated as a valid time even if it's not in the dropdown.\n React.useEffect(() => {\n if (freeform && value) {\n const activeOption = getActiveOption();\n if (!activeOption) {\n return;\n }\n\n const valueMatchesActiveOption = activeOption.text.toLowerCase().indexOf(value.toLowerCase()) === 0;\n if (!valueMatchesActiveOption) {\n activeDescendantController.blur();\n }\n }\n }, [freeform, value, activeDescendantController, getActiveOption]);\n\n const selectTimeFromValue = useEventCallback(\n (e: React.KeyboardEvent<HTMLInputElement> | React.FocusEvent<HTMLInputElement>) => {\n if (!freeform) {\n return;\n }\n\n const { date: selectedTime, errorType } = parseTimeStringToDate(value);\n\n // Only triggers callback when the text in input has changed.\n if (submittedText !== value) {\n callback?.(e, { selectedTime, selectedTimeText: value, errorType });\n }\n },\n );\n\n const handleKeyDown: ComboboxProps['onKeyDown'] = useEventCallback(e => {\n const activeOption = getActiveOption();\n if (!activeOption && e.key === Enter) {\n selectTimeFromValue(e);\n }\n });\n state.root.onKeyDown = mergeCallbacks(handleKeyDown, state.root.onKeyDown);\n\n const rootRef = React.useRef<HTMLDivElement>(null);\n state.root.ref = useMergedRefs(state.root.ref, rootRef);\n\n if (state.listbox) {\n state.listbox.tabIndex = -1; // allows it to be the relatedTarget of a blur event.\n }\n\n if (state.expandIcon) {\n state.expandIcon.tabIndex = -1; // allows it to be the relatedTarget of a blur event.\n }\n\n const handleInputBlur = useEventCallback((e: React.FocusEvent<HTMLInputElement>) => {\n const isOutside = e.relatedTarget ? !elementContains(rootRef.current, e.relatedTarget) : true;\n if (isOutside) {\n selectTimeFromValue(e);\n }\n });\n state.input.onBlur = mergeCallbacks(handleInputBlur, state.input.onBlur);\n};\n\n/**\n * Provides a default aria-labelledby for the chevron icon if the TimePicker is wrapped in a Field.\n */\nconst useDefaultChevronIconLabel = (state: TimePickerState) => {\n const fieldContext = useFieldContext();\n const chevronDefaultId = useId('timepicker-chevron-');\n const defaultLabelFromCombobox = 'Open';\n\n if (fieldContext?.labelId && state.expandIcon?.['aria-label'] === defaultLabelFromCombobox) {\n const chevronId = state.expandIcon.id ?? chevronDefaultId;\n state.expandIcon['aria-labelledby'] = `${chevronId} ${fieldContext.labelId}`;\n }\n};\n"],"names":["React","elementContains","mergeCallbacks","useControllableState","useEventCallback","useId","useMergedRefs","Enter","useCombobox_unstable","Option","useFieldContext_unstable","useFieldContext","dateToKey","keyToDate","formatDateToTimeString","defaultFormatDateToTimeString","getDateStartAnchor","getDateEndAnchor","getTimesBetween","getDateFromTimeString","useTimePicker_unstable","props","ref","dateAnchor","dateAnchorInProps","defaultSelectedTime","defaultSelectedTimeInProps","endHour","hourCycle","increment","onTimeChange","selectedTime","selectedTimeInProps","showSeconds","startHour","parseTimeStringToDate","parseTimeStringToDateInProps","rest","freeform","dateStartAnchor","dateEndAnchor","useStableDateAnchor","options","useMemo","map","time","date","key","text","setSelectedTime","state","defaultState","initialState","submittedText","setSubmittedText","useState","undefined","selectTime","e","data","selectedTimeText","selectedOptions","selectedTimeKey","selectedOption","find","handleOptionSelect","optionValue","timeSelectionData","optionText","errorType","baseState","autoComplete","onOptionSelect","children","value","defaultParseTimeStringToDate","useCallback","useDefaultChevronIconLabel","useSelectTimeFromValue","providedDate","fallbackDateAnchor","Date","providedDateKey","callback","getOptionById","activeDescendantController","getActiveOption","activeOptionId","active","useEffect","activeOption","valueMatchesActiveOption","toLowerCase","indexOf","blur","selectTimeFromValue","handleKeyDown","root","onKeyDown","rootRef","useRef","listbox","tabIndex","expandIcon","handleInputBlur","isOutside","relatedTarget","current","input","onBlur","fieldContext","chevronDefaultId","defaultLabelFromCombobox","labelId","chevronId","id"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SACEC,eAAe,EACfC,cAAc,EACdC,oBAAoB,EACpBC,gBAAgB,EAChBC,KAAK,EACLC,aAAa,QACR,4BAA4B;AACnC,SAASC,KAAK,QAAQ,0BAA0B;AAEhD,SAAwBC,oBAAoB,EAAEC,MAAM,QAAQ,2BAA2B;AACvF,SAASC,4BAA4BC,eAAe,QAAQ,wBAAwB;AACpF,SACEC,SAAS,EACTC,SAAS,EACTC,0BAA0BC,6BAA6B,EACvDC,kBAAkB,EAClBC,gBAAgB,EAChBC,eAAe,EACfC,qBAAqB,QAChB,aAAa;AAEpB;;;;;;;;CAQC,GACD,OAAO,MAAMC,yBAAyB,CAACC,OAAwBC;IAC7D,MAAM,EACJC,YAAYC,iBAAiB,EAC7BC,qBAAqBC,0BAA0B,EAC/CC,UAAU,EAAE,EACZb,yBAAyBC,6BAA6B,EACtDa,SAAS,EACTC,YAAY,EAAE,EACdC,YAAY,EACZC,cAAcC,mBAAmB,EACjCC,cAAc,KAAK,EACnBC,YAAY,CAAC,EACbC,uBAAuBC,4BAA4B,EACnD,GAAGC,MACJ,GAAGhB;IACJ,MAAM,EAAEiB,WAAW,KAAK,EAAE,GAAGD;QAG3Bb;IADF,MAAM,EAAEe,eAAe,EAAEC,aAAa,EAAE,GAAGC,oBACzCjB,CAAAA,OAAAA,8BAAAA,+BAAAA,oBAAqBQ,iCAArBR,kBAAAA,OAA4CE,4BAC5CQ,WACAP;IAGF,MAAMe,UAA8B1C,MAAM2C,OAAO,CAC/C,IACEzB,gBAAgBqB,iBAAiBC,eAAeX,WAAWe,GAAG,CAACC,CAAAA,OAAS,CAAA;gBACtEC,MAAMD;gBACNE,KAAKnC,UAAUiC;gBACfG,M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/C,EAAEgD,aAAa,GAAG,CAACzG,gBAAgBkG,QAAQQ,OAAO,EAAEjD,EAAEgD,aAAa,IAAI;QACzF,IAAID,WAAW;YACbV,oBAAoBrC;QACtB;IACF;IACAR,MAAM0D,KAAK,CAACC,MAAM,GAAG3G,eAAesG,iBAAiBtD,MAAM0D,KAAK,CAACC,MAAM;AACzE;AAEA;;CAEC,GACD,MAAMhC,6BAA6B,CAAC3B;QAKLA;IAJ7B,MAAM4D,eAAenG;IACrB,MAAMoG,mBAAmB1G,MAAM;IAC/B,MAAM2G,2BAA2B;IAEjC,IAAIF,CAAAA,yBAAAA,mCAAAA,aAAcG,OAAO,KAAI/D,EAAAA,oBAAAA,MAAMqD,UAAU,cAAhBrD,wCAAAA,iBAAkB,CAAC,aAAa,MAAK8D,0BAA0B;YACxE9D;QAAlB,MAAMgE,YAAYhE,CAAAA,uBAAAA,MAAMqD,UAAU,CAACY,EAAE,cAAnBjE,kCAAAA,uBAAuB6D;QACzC7D,MAAMqD,UAAU,CAAC,kBAAkB,GAAG,CAAC,EAAEW,UAAU,CAAC,EAAEJ,aAAaG,OAAO,CAAC,CAAC;IAC9E;AACF"}
|
|
@@ -4,6 +4,7 @@ export const timePickerClassNames = {
|
|
|
4
4
|
root: 'fui-TimePicker',
|
|
5
5
|
input: 'fui-TimePicker__input',
|
|
6
6
|
expandIcon: 'fui-TimePicker__expandIcon',
|
|
7
|
+
clearIcon: 'fui-TimePicker__clearIcon',
|
|
7
8
|
listbox: 'fui-TimePicker__listbox'
|
|
8
9
|
};
|
|
9
10
|
const useStyles = /*#__PURE__*/__styles({
|
|
@@ -23,6 +24,9 @@ export const useTimePickerStyles_unstable = state => {
|
|
|
23
24
|
if (state.expandIcon) {
|
|
24
25
|
state.expandIcon.className = mergeClasses(timePickerClassNames.expandIcon, state.expandIcon.className);
|
|
25
26
|
}
|
|
27
|
+
if (state.clearIcon) {
|
|
28
|
+
state.clearIcon.className = mergeClasses(timePickerClassNames.clearIcon, state.clearIcon.className);
|
|
29
|
+
}
|
|
26
30
|
if (state.listbox) {
|
|
27
31
|
state.listbox.className = mergeClasses(timePickerClassNames.listbox, styles.listbox, state.listbox.className);
|
|
28
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__styles","mergeClasses","useComboboxStyles_unstable","timePickerClassNames","root","input","expandIcon","listbox","useStyles","Bxyxcbc","d","useTimePickerStyles_unstable","state","styles","className"],"sources":["useTimePickerStyles.styles.js"],"sourcesContent":["import { makeStyles, mergeClasses } from '@griffel/react';\nimport { useComboboxStyles_unstable } from '@fluentui/react-combobox';\nexport const timePickerClassNames = {\n root: 'fui-TimePicker',\n input: 'fui-TimePicker__input',\n expandIcon: 'fui-TimePicker__expandIcon',\n listbox: 'fui-TimePicker__listbox'\n};\nconst useStyles = makeStyles({\n listbox: {\n maxHeight: 'min(80vh, 416px)'\n }\n});\n/**\n * Apply styling to the TimePicker slots based on the state\n */ export const useTimePickerStyles_unstable = (state)=>{\n const styles = useStyles();\n state.root.className = mergeClasses(timePickerClassNames.root, state.root.className);\n state.input.className = mergeClasses(timePickerClassNames.input, state.input.className);\n if (state.expandIcon) {\n state.expandIcon.className = mergeClasses(timePickerClassNames.expandIcon, state.expandIcon.className);\n }\n if (state.listbox) {\n state.listbox.className = mergeClasses(timePickerClassNames.listbox, styles.listbox, state.listbox.className);\n }\n useComboboxStyles_unstable(state);\n return state;\n};\n"],"mappings":"AAAA,SAAAA,QAAA,EAAqBC,YAAY,QAAQ,gBAAgB;AACzD,SAASC,0BAA0B,QAAQ,0BAA0B;AACrE,OAAO,MAAMC,oBAAoB,GAAG;EAChCC,IAAI,EAAE,gBAAgB;EACtBC,KAAK,EAAE,uBAAuB;EAC9BC,UAAU,EAAE,4BAA4B;EACxCC,OAAO,EAAE;AACb,CAAC;AACD,MAAMC,SAAS,
|
|
1
|
+
{"version":3,"names":["__styles","mergeClasses","useComboboxStyles_unstable","timePickerClassNames","root","input","expandIcon","clearIcon","listbox","useStyles","Bxyxcbc","d","useTimePickerStyles_unstable","state","styles","className"],"sources":["useTimePickerStyles.styles.js"],"sourcesContent":["import { makeStyles, mergeClasses } from '@griffel/react';\nimport { useComboboxStyles_unstable } from '@fluentui/react-combobox';\nexport const timePickerClassNames = {\n root: 'fui-TimePicker',\n input: 'fui-TimePicker__input',\n expandIcon: 'fui-TimePicker__expandIcon',\n clearIcon: 'fui-TimePicker__clearIcon',\n listbox: 'fui-TimePicker__listbox'\n};\nconst useStyles = makeStyles({\n listbox: {\n maxHeight: 'min(80vh, 416px)'\n }\n});\n/**\n * Apply styling to the TimePicker slots based on the state\n */ export const useTimePickerStyles_unstable = (state)=>{\n const styles = useStyles();\n state.root.className = mergeClasses(timePickerClassNames.root, state.root.className);\n state.input.className = mergeClasses(timePickerClassNames.input, state.input.className);\n if (state.expandIcon) {\n state.expandIcon.className = mergeClasses(timePickerClassNames.expandIcon, state.expandIcon.className);\n }\n if (state.clearIcon) {\n state.clearIcon.className = mergeClasses(timePickerClassNames.clearIcon, state.clearIcon.className);\n }\n if (state.listbox) {\n state.listbox.className = mergeClasses(timePickerClassNames.listbox, styles.listbox, state.listbox.className);\n }\n useComboboxStyles_unstable(state);\n return state;\n};\n"],"mappings":"AAAA,SAAAA,QAAA,EAAqBC,YAAY,QAAQ,gBAAgB;AACzD,SAASC,0BAA0B,QAAQ,0BAA0B;AACrE,OAAO,MAAMC,oBAAoB,GAAG;EAChCC,IAAI,EAAE,gBAAgB;EACtBC,KAAK,EAAE,uBAAuB;EAC9BC,UAAU,EAAE,4BAA4B;EACxCC,SAAS,EAAE,2BAA2B;EACtCC,OAAO,EAAE;AACb,CAAC;AACD,MAAMC,SAAS,gBAAGT,QAAA;EAAAQ,OAAA;IAAAE,OAAA;EAAA;AAAA;EAAAC,CAAA;AAAA,CAIjB,CAAC;AACF;AACA;AACA;AAAI,OAAO,MAAMC,4BAA4B,GAAIC,KAAK,IAAG;EACrD,MAAMC,MAAM,GAAGL,SAAS,CAAC,CAAC;EAC1BI,KAAK,CAACT,IAAI,CAACW,SAAS,GAAGd,YAAY,CAACE,oBAAoB,CAACC,IAAI,EAAES,KAAK,CAACT,IAAI,CAACW,SAAS,CAAC;EACpFF,KAAK,CAACR,KAAK,CAACU,SAAS,GAAGd,YAAY,CAACE,oBAAoB,CAACE,KAAK,EAAEQ,KAAK,CAACR,KAAK,CAACU,SAAS,CAAC;EACvF,IAAIF,KAAK,CAACP,UAAU,EAAE;IAClBO,KAAK,CAACP,UAAU,CAACS,SAAS,GAAGd,YAAY,CAACE,oBAAoB,CAACG,UAAU,EAAEO,KAAK,CAACP,UAAU,CAACS,SAAS,CAAC;EAC1G;EACA,IAAIF,KAAK,CAACN,SAAS,EAAE;IACjBM,KAAK,CAACN,SAAS,CAACQ,SAAS,GAAGd,YAAY,CAACE,oBAAoB,CAACI,SAAS,EAAEM,KAAK,CAACN,SAAS,CAACQ,SAAS,CAAC;EACvG;EACA,IAAIF,KAAK,CAACL,OAAO,EAAE;IACfK,KAAK,CAACL,OAAO,CAACO,SAAS,GAAGd,YAAY,CAACE,oBAAoB,CAACK,OAAO,EAAEM,MAAM,CAACN,OAAO,EAAEK,KAAK,CAACL,OAAO,CAACO,SAAS,CAAC;EACjH;EACAb,0BAA0B,CAACW,KAAK,CAAC;EACjC,OAAOA,KAAK;AAChB,CAAC"}
|
|
@@ -127,23 +127,33 @@ const useTimePicker_unstable = (props, ref)=>{
|
|
|
127
127
|
* - Enter/Tab key is pressed on the input.
|
|
128
128
|
* - TimePicker loses focus, signifying a possible change.
|
|
129
129
|
*/ const useSelectTimeFromValue = (state, callback)=>{
|
|
130
|
-
const {
|
|
130
|
+
const { getOptionById, freeform, parseTimeStringToDate, submittedText, value, activeDescendantController } = state;
|
|
131
|
+
const getActiveOption = _react.useCallback(()=>{
|
|
132
|
+
const activeOptionId = activeDescendantController.active();
|
|
133
|
+
return activeOptionId ? getOptionById(activeOptionId) : null;
|
|
134
|
+
}, [
|
|
135
|
+
activeDescendantController,
|
|
136
|
+
getOptionById
|
|
137
|
+
]);
|
|
131
138
|
// Base Combobox has activeOption default to first option in dropdown even if it doesn't match input value, and Enter key will select it.
|
|
132
139
|
// This effect ensures that the activeOption is cleared when the input doesn't match any option.
|
|
133
140
|
// This behavior is specific to a freeform TimePicker where the input value is treated as a valid time even if it's not in the dropdown.
|
|
134
141
|
_react.useEffect(()=>{
|
|
135
142
|
if (freeform && value) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
143
|
+
const activeOption = getActiveOption();
|
|
144
|
+
if (!activeOption) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const valueMatchesActiveOption = activeOption.text.toLowerCase().indexOf(value.toLowerCase()) === 0;
|
|
148
|
+
if (!valueMatchesActiveOption) {
|
|
149
|
+
activeDescendantController.blur();
|
|
150
|
+
}
|
|
142
151
|
}
|
|
143
152
|
}, [
|
|
144
153
|
freeform,
|
|
145
|
-
|
|
146
|
-
|
|
154
|
+
value,
|
|
155
|
+
activeDescendantController,
|
|
156
|
+
getActiveOption
|
|
147
157
|
]);
|
|
148
158
|
const selectTimeFromValue = (0, _reactutilities.useEventCallback)((e)=>{
|
|
149
159
|
if (!freeform) {
|
|
@@ -160,6 +170,7 @@ const useTimePicker_unstable = (props, ref)=>{
|
|
|
160
170
|
}
|
|
161
171
|
});
|
|
162
172
|
const handleKeyDown = (0, _reactutilities.useEventCallback)((e)=>{
|
|
173
|
+
const activeOption = getActiveOption();
|
|
163
174
|
if (!activeOption && e.key === _keyboardkeys.Enter) {
|
|
164
175
|
selectTimeFromValue(e);
|
|
165
176
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useTimePicker.js"],"sourcesContent":["import * as React from 'react';\nimport { elementContains, mergeCallbacks, useControllableState, useEventCallback, useId, useMergedRefs } from '@fluentui/react-utilities';\nimport { Enter } from '@fluentui/keyboard-keys';\nimport { useCombobox_unstable, Option } from '@fluentui/react-combobox';\nimport { useFieldContext_unstable as useFieldContext } from '@fluentui/react-field';\nimport { dateToKey, keyToDate, formatDateToTimeString as defaultFormatDateToTimeString, getDateStartAnchor, getDateEndAnchor, getTimesBetween, getDateFromTimeString } from './timeMath';\n/**\n * Create the state required to render TimePicker.\n *\n * The returned state can be modified with hooks such as useTimePickerStyles_unstable,\n * before being passed to renderTimePicker_unstable.\n *\n * @param props - props from this instance of TimePicker\n * @param ref - reference to root HTMLElement of TimePicker\n */ export const useTimePicker_unstable = (props, ref)=>{\n const { dateAnchor: dateAnchorInProps, defaultSelectedTime: defaultSelectedTimeInProps, endHour = 24, formatDateToTimeString = defaultFormatDateToTimeString, hourCycle, increment = 30, onTimeChange, selectedTime: selectedTimeInProps, showSeconds = false, startHour = 0, parseTimeStringToDate: parseTimeStringToDateInProps, ...rest } = props;\n const { freeform = false } = rest;\n var _ref;\n const { dateStartAnchor, dateEndAnchor } = useStableDateAnchor((_ref = dateAnchorInProps !== null && dateAnchorInProps !== void 0 ? dateAnchorInProps : selectedTimeInProps) !== null && _ref !== void 0 ? _ref : defaultSelectedTimeInProps, startHour, endHour);\n const options = React.useMemo(()=>getTimesBetween(dateStartAnchor, dateEndAnchor, increment).map((time)=>({\n date: time,\n key: dateToKey(time),\n text: formatDateToTimeString(time, {\n showSeconds,\n hourCycle\n })\n })), [\n dateEndAnchor,\n dateStartAnchor,\n formatDateToTimeString,\n hourCycle,\n increment,\n showSeconds\n ]);\n const [selectedTime, setSelectedTime] = useControllableState({\n state: selectedTimeInProps,\n defaultState: defaultSelectedTimeInProps,\n initialState: null\n });\n const [submittedText, setSubmittedText] = React.useState(undefined);\n const selectTime = useEventCallback((e, data)=>{\n setSelectedTime(data.selectedTime);\n setSubmittedText(data.selectedTimeText);\n onTimeChange === null || onTimeChange === void 0 ? void 0 : onTimeChange(e, data);\n });\n const selectedOptions = React.useMemo(()=>{\n const selectedTimeKey = dateToKey(selectedTime);\n const selectedOption = options.find((date)=>date.key === selectedTimeKey);\n return selectedOption ? [\n selectedOption.key\n ] : [];\n }, [\n options,\n selectedTime\n ]);\n const handleOptionSelect = useEventCallback((e, data)=>{\n if (freeform && data.optionValue === undefined) {\n // Combobox clears selection when input value not matching any option; but we allow this case in freeform TimePicker.\n return;\n }\n var _data_optionValue;\n const timeSelectionData = {\n selectedTime: keyToDate((_data_optionValue = data.optionValue) !== null && _data_optionValue !== void 0 ? _data_optionValue : ''),\n selectedTimeText: data.optionText,\n errorType: undefined\n };\n selectTime(e, timeSelectionData);\n });\n const baseState = useCombobox_unstable({\n autoComplete: 'off',\n ...rest,\n selectedOptions,\n onOptionSelect: handleOptionSelect,\n children: options.map((date)=>/*#__PURE__*/ React.createElement(Option, {\n key: date.key,\n value: date.key\n }, date.text))\n }, ref);\n const defaultParseTimeStringToDate = React.useCallback((time)=>getDateFromTimeString(time, dateStartAnchor, dateEndAnchor, {\n hourCycle,\n showSeconds\n }), [\n dateEndAnchor,\n dateStartAnchor,\n hourCycle,\n showSeconds\n ]);\n const state = {\n ...baseState,\n freeform,\n parseTimeStringToDate: parseTimeStringToDateInProps !== null && parseTimeStringToDateInProps !== void 0 ? parseTimeStringToDateInProps : defaultParseTimeStringToDate,\n submittedText\n };\n useDefaultChevronIconLabel(state);\n useSelectTimeFromValue(state, selectTime);\n return state;\n};\n/**\n * Provides stable start and end date anchors based on the provided date and time parameters.\n * The hook ensures that the memoization remains consistent even if new Date objects representing the same date are provided.\n */ const useStableDateAnchor = (providedDate, startHour, endHour)=>{\n const [fallbackDateAnchor] = React.useState(()=>new Date());\n const providedDateKey = dateToKey(providedDate !== null && providedDate !== void 0 ? providedDate : null);\n return React.useMemo(()=>{\n const dateAnchor = providedDate !== null && providedDate !== void 0 ? providedDate : fallbackDateAnchor;\n const dateStartAnchor = getDateStartAnchor(dateAnchor, startHour);\n const dateEndAnchor = getDateEndAnchor(dateAnchor, startHour, endHour);\n return {\n dateStartAnchor,\n dateEndAnchor\n };\n // `providedDate`'s stable key representation is used as dependency instead of the Date object. This ensures that the memoization remains stable when a new Date object representing the same date is passed in.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n endHour,\n fallbackDateAnchor,\n providedDateKey,\n startHour\n ]);\n};\n/**\n * Mimics the behavior of the browser's change event for a freeform TimePicker.\n * The provided callback is called when input changed and:\n * - Enter/Tab key is pressed on the input.\n * - TimePicker loses focus, signifying a possible change.\n */ const useSelectTimeFromValue = (state, callback)=>{\n const { activeOption, freeform, parseTimeStringToDate, submittedText, setActiveOption, value } = state;\n // Base Combobox has activeOption default to first option in dropdown even if it doesn't match input value, and Enter key will select it.\n // This effect ensures that the activeOption is cleared when the input doesn't match any option.\n // This behavior is specific to a freeform TimePicker where the input value is treated as a valid time even if it's not in the dropdown.\n React.useEffect(()=>{\n if (freeform && value) {\n setActiveOption((prevActiveOption)=>{\n if ((prevActiveOption === null || prevActiveOption === void 0 ? void 0 : prevActiveOption.text) && prevActiveOption.text.toLowerCase().indexOf(value.toLowerCase()) === 0) {\n return prevActiveOption;\n }\n return undefined;\n });\n }\n }, [\n freeform,\n setActiveOption,\n value\n ]);\n const selectTimeFromValue = useEventCallback((e)=>{\n if (!freeform) {\n return;\n }\n const { date: selectedTime, errorType } = parseTimeStringToDate(value);\n // Only triggers callback when the text in input has changed.\n if (submittedText !== value) {\n callback === null || callback === void 0 ? void 0 : callback(e, {\n selectedTime,\n selectedTimeText: value,\n errorType\n });\n }\n });\n const handleKeyDown = useEventCallback((e)=>{\n if (!activeOption && e.key === Enter) {\n selectTimeFromValue(e);\n }\n });\n state.root.onKeyDown = mergeCallbacks(handleKeyDown, state.root.onKeyDown);\n const rootRef = React.useRef(null);\n state.root.ref = useMergedRefs(state.root.ref, rootRef);\n if (state.listbox) {\n state.listbox.tabIndex = -1; // allows it to be the relatedTarget of a blur event.\n }\n if (state.expandIcon) {\n state.expandIcon.tabIndex = -1; // allows it to be the relatedTarget of a blur event.\n }\n const handleInputBlur = useEventCallback((e)=>{\n const isOutside = e.relatedTarget ? !elementContains(rootRef.current, e.relatedTarget) : true;\n if (isOutside) {\n selectTimeFromValue(e);\n }\n });\n state.input.onBlur = mergeCallbacks(handleInputBlur, state.input.onBlur);\n};\n/**\n * Provides a default aria-labelledby for the chevron icon if the TimePicker is wrapped in a Field.\n */ const useDefaultChevronIconLabel = (state)=>{\n var _state_expandIcon;\n const fieldContext = useFieldContext();\n const chevronDefaultId = useId('timepicker-chevron-');\n const defaultLabelFromCombobox = 'Open';\n if ((fieldContext === null || fieldContext === void 0 ? void 0 : fieldContext.labelId) && ((_state_expandIcon = state.expandIcon) === null || _state_expandIcon === void 0 ? void 0 : _state_expandIcon['aria-label']) === defaultLabelFromCombobox) {\n var _state_expandIcon_id;\n const chevronId = (_state_expandIcon_id = state.expandIcon.id) !== null && _state_expandIcon_id !== void 0 ? _state_expandIcon_id : chevronDefaultId;\n state.expandIcon['aria-labelledby'] = `${chevronId} ${fieldContext.labelId}`;\n }\n};\n"],"names":["useTimePicker_unstable","props","ref","dateAnchor","dateAnchorInProps","defaultSelectedTime","defaultSelectedTimeInProps","endHour","formatDateToTimeString","defaultFormatDateToTimeString","hourCycle","increment","onTimeChange","selectedTime","selectedTimeInProps","showSeconds","startHour","parseTimeStringToDate","parseTimeStringToDateInProps","rest","freeform","_ref","dateStartAnchor","dateEndAnchor","useStableDateAnchor","options","React","useMemo","getTimesBetween","map","time","date","key","dateToKey","text","setSelectedTime","useControllableState","state","defaultState","initialState","submittedText","setSubmittedText","useState","undefined","selectTime","useEventCallback","e","data","selectedTimeText","selectedOptions","selectedTimeKey","selectedOption","find","handleOptionSelect","optionValue","_data_optionValue","timeSelectionData","keyToDate","optionText","errorType","baseState","useCombobox_unstable","autoComplete","onOptionSelect","children","createElement","Option","value","defaultParseTimeStringToDate","useCallback","getDateFromTimeString","useDefaultChevronIconLabel","useSelectTimeFromValue","providedDate","fallbackDateAnchor","Date","providedDateKey","getDateStartAnchor","getDateEndAnchor","callback","activeOption","setActiveOption","useEffect","prevActiveOption","toLowerCase","indexOf","selectTimeFromValue","handleKeyDown","Enter","root","onKeyDown","mergeCallbacks","rootRef","useRef","useMergedRefs","listbox","tabIndex","expandIcon","handleInputBlur","isOutside","relatedTarget","elementContains","current","input","onBlur","_state_expandIcon","fieldContext","useFieldContext","chevronDefaultId","useId","defaultLabelFromCombobox","labelId","_state_expandIcon_id","chevronId","id"],"mappings":";;;;+BAciBA;;;eAAAA;;;;iEAdM;gCACuF;8BACxF;+BACuB;4BACe;0BACgH;AASjK,MAAMA,yBAAyB,CAACC,OAAOC;IAC9C,MAAM,EAAEC,YAAYC,iBAAiB,EAAEC,qBAAqBC,0BAA0B,EAAEC,UAAU,EAAE,EAAEC,yBAAyBC,gCAA6B,EAAEC,SAAS,EAAEC,YAAY,EAAE,EAAEC,YAAY,EAAEC,cAAcC,mBAAmB,EAAEC,cAAc,KAAK,EAAEC,YAAY,CAAC,EAAEC,uBAAuBC,4BAA4B,EAAE,GAAGC,MAAM,GAAGlB;IAC/U,MAAM,EAAEmB,WAAW,KAAK,EAAE,GAAGD;IAC7B,IAAIE;IACJ,MAAM,EAAEC,eAAe,EAAEC,aAAa,EAAE,GAAGC,oBAAoB,AAACH,CAAAA,OAAOjB,sBAAsB,QAAQA,sBAAsB,KAAK,IAAIA,oBAAoBU,mBAAkB,MAAO,QAAQO,SAAS,KAAK,IAAIA,OAAOf,4BAA4BU,WAAWT;IACzP,MAAMkB,UAAUC,OAAMC,OAAO,CAAC,IAAIC,IAAAA,yBAAe,EAACN,iBAAiBC,eAAeZ,WAAWkB,GAAG,CAAC,CAACC,OAAQ,CAAA;gBAC9FC,MAAMD;gBACNE,KAAKC,IAAAA,mBAAS,EAACH;gBACfI,MAAM1B,uBAAuBsB,MAAM;oBAC/Bf;oBACAL;gBACJ;YACJ,CAAA,IAAK;QACTa;QACAD;QACAd;QACAE;QACAC;QACAI;KACH;IACD,MAAM,CAACF,cAAcsB,gBAAgB,GAAGC,IAAAA,oCAAoB,EAAC;QACzDC,OAAOvB;QACPwB,cAAchC;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QAAQU,OAAO,EAAExD,EAAEsD,aAAa,IAAI;QACzF,IAAID,WAAW;YACXb,oBAAoBxC;QACxB;IACJ;IACAT,MAAMkE,KAAK,CAACC,MAAM,GAAGb,IAAAA,8BAAc,EAACO,iBAAiB7D,MAAMkE,KAAK,CAACC,MAAM;AAC3E;AACA;;CAEC,GAAG,MAAMjC,6BAA6B,CAAClC;IACpC,IAAIoE;IACJ,MAAMC,eAAeC,IAAAA,oCAAe;IACpC,MAAMC,mBAAmBC,IAAAA,qBAAK,EAAC;IAC/B,MAAMC,2BAA2B;IACjC,IAAI,AAACJ,CAAAA,iBAAiB,QAAQA,iBAAiB,KAAK,IAAI,KAAK,IAAIA,aAAaK,OAAO,AAAD,KAAM,AAAC,CAAA,AAACN,CAAAA,oBAAoBpE,MAAM4D,UAAU,AAAD,MAAO,QAAQQ,sBAAsB,KAAK,IAAI,KAAK,IAAIA,iBAAiB,CAAC,aAAa,AAAD,MAAOK,0BAA0B;QACjP,IAAIE;QACJ,MAAMC,YAAY,AAACD,CAAAA,uBAAuB3E,MAAM4D,UAAU,CAACiB,EAAE,AAAD,MAAO,QAAQF,yBAAyB,KAAK,IAAIA,uBAAuBJ;QACpIvE,MAAM4D,UAAU,CAAC,kBAAkB,GAAG,CAAC,EAAEgB,UAAU,CAAC,EAAEP,aAAaK,OAAO,CAAC,CAAC;IAChF;AACJ"}
|
|
1
|
+
{"version":3,"sources":["useTimePicker.js"],"sourcesContent":["import * as React from 'react';\nimport { elementContains, mergeCallbacks, useControllableState, useEventCallback, useId, useMergedRefs } from '@fluentui/react-utilities';\nimport { Enter } from '@fluentui/keyboard-keys';\nimport { useCombobox_unstable, Option } from '@fluentui/react-combobox';\nimport { useFieldContext_unstable as useFieldContext } from '@fluentui/react-field';\nimport { dateToKey, keyToDate, formatDateToTimeString as defaultFormatDateToTimeString, getDateStartAnchor, getDateEndAnchor, getTimesBetween, getDateFromTimeString } from './timeMath';\n/**\n * Create the state required to render TimePicker.\n *\n * The returned state can be modified with hooks such as useTimePickerStyles_unstable,\n * before being passed to renderTimePicker_unstable.\n *\n * @param props - props from this instance of TimePicker\n * @param ref - reference to root HTMLElement of TimePicker\n */ export const useTimePicker_unstable = (props, ref)=>{\n const { dateAnchor: dateAnchorInProps, defaultSelectedTime: defaultSelectedTimeInProps, endHour = 24, formatDateToTimeString = defaultFormatDateToTimeString, hourCycle, increment = 30, onTimeChange, selectedTime: selectedTimeInProps, showSeconds = false, startHour = 0, parseTimeStringToDate: parseTimeStringToDateInProps, ...rest } = props;\n const { freeform = false } = rest;\n var _ref;\n const { dateStartAnchor, dateEndAnchor } = useStableDateAnchor((_ref = dateAnchorInProps !== null && dateAnchorInProps !== void 0 ? dateAnchorInProps : selectedTimeInProps) !== null && _ref !== void 0 ? _ref : defaultSelectedTimeInProps, startHour, endHour);\n const options = React.useMemo(()=>getTimesBetween(dateStartAnchor, dateEndAnchor, increment).map((time)=>({\n date: time,\n key: dateToKey(time),\n text: formatDateToTimeString(time, {\n showSeconds,\n hourCycle\n })\n })), [\n dateEndAnchor,\n dateStartAnchor,\n formatDateToTimeString,\n hourCycle,\n increment,\n showSeconds\n ]);\n const [selectedTime, setSelectedTime] = useControllableState({\n state: selectedTimeInProps,\n defaultState: defaultSelectedTimeInProps,\n initialState: null\n });\n const [submittedText, setSubmittedText] = React.useState(undefined);\n const selectTime = useEventCallback((e, data)=>{\n setSelectedTime(data.selectedTime);\n setSubmittedText(data.selectedTimeText);\n onTimeChange === null || onTimeChange === void 0 ? void 0 : onTimeChange(e, data);\n });\n const selectedOptions = React.useMemo(()=>{\n const selectedTimeKey = dateToKey(selectedTime);\n const selectedOption = options.find((date)=>date.key === selectedTimeKey);\n return selectedOption ? [\n selectedOption.key\n ] : [];\n }, [\n options,\n selectedTime\n ]);\n const handleOptionSelect = useEventCallback((e, data)=>{\n if (freeform && data.optionValue === undefined) {\n // Combobox clears selection when input value not matching any option; but we allow this case in freeform TimePicker.\n return;\n }\n var _data_optionValue;\n const timeSelectionData = {\n selectedTime: keyToDate((_data_optionValue = data.optionValue) !== null && _data_optionValue !== void 0 ? _data_optionValue : ''),\n selectedTimeText: data.optionText,\n errorType: undefined\n };\n selectTime(e, timeSelectionData);\n });\n const baseState = useCombobox_unstable({\n autoComplete: 'off',\n ...rest,\n selectedOptions,\n onOptionSelect: handleOptionSelect,\n children: options.map((date)=>/*#__PURE__*/ React.createElement(Option, {\n key: date.key,\n value: date.key\n }, date.text))\n }, ref);\n const defaultParseTimeStringToDate = React.useCallback((time)=>getDateFromTimeString(time, dateStartAnchor, dateEndAnchor, {\n hourCycle,\n showSeconds\n }), [\n dateEndAnchor,\n dateStartAnchor,\n hourCycle,\n showSeconds\n ]);\n const state = {\n ...baseState,\n freeform,\n parseTimeStringToDate: parseTimeStringToDateInProps !== null && parseTimeStringToDateInProps !== void 0 ? parseTimeStringToDateInProps : defaultParseTimeStringToDate,\n submittedText\n };\n useDefaultChevronIconLabel(state);\n useSelectTimeFromValue(state, selectTime);\n return state;\n};\n/**\n * Provides stable start and end date anchors based on the provided date and time parameters.\n * The hook ensures that the memoization remains consistent even if new Date objects representing the same date are provided.\n */ const useStableDateAnchor = (providedDate, startHour, endHour)=>{\n const [fallbackDateAnchor] = React.useState(()=>new Date());\n const providedDateKey = dateToKey(providedDate !== null && providedDate !== void 0 ? providedDate : null);\n return React.useMemo(()=>{\n const dateAnchor = providedDate !== null && providedDate !== void 0 ? providedDate : fallbackDateAnchor;\n const dateStartAnchor = getDateStartAnchor(dateAnchor, startHour);\n const dateEndAnchor = getDateEndAnchor(dateAnchor, startHour, endHour);\n return {\n dateStartAnchor,\n dateEndAnchor\n };\n // `providedDate`'s stable key representation is used as dependency instead of the Date object. This ensures that the memoization remains stable when a new Date object representing the same date is passed in.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n endHour,\n fallbackDateAnchor,\n providedDateKey,\n startHour\n ]);\n};\n/**\n * Mimics the behavior of the browser's change event for a freeform TimePicker.\n * The provided callback is called when input changed and:\n * - Enter/Tab key is pressed on the input.\n * - TimePicker loses focus, signifying a possible change.\n */ const useSelectTimeFromValue = (state, callback)=>{\n const { getOptionById, freeform, parseTimeStringToDate, submittedText, value, activeDescendantController } = state;\n const getActiveOption = React.useCallback(()=>{\n const activeOptionId = activeDescendantController.active();\n return activeOptionId ? getOptionById(activeOptionId) : null;\n }, [\n activeDescendantController,\n getOptionById\n ]);\n // Base Combobox has activeOption default to first option in dropdown even if it doesn't match input value, and Enter key will select it.\n // This effect ensures that the activeOption is cleared when the input doesn't match any option.\n // This behavior is specific to a freeform TimePicker where the input value is treated as a valid time even if it's not in the dropdown.\n React.useEffect(()=>{\n if (freeform && value) {\n const activeOption = getActiveOption();\n if (!activeOption) {\n return;\n }\n const valueMatchesActiveOption = activeOption.text.toLowerCase().indexOf(value.toLowerCase()) === 0;\n if (!valueMatchesActiveOption) {\n activeDescendantController.blur();\n }\n }\n }, [\n freeform,\n value,\n activeDescendantController,\n getActiveOption\n ]);\n const selectTimeFromValue = useEventCallback((e)=>{\n if (!freeform) {\n return;\n }\n const { date: selectedTime, errorType } = parseTimeStringToDate(value);\n // Only triggers callback when the text in input has changed.\n if (submittedText !== value) {\n callback === null || callback === void 0 ? void 0 : callback(e, {\n selectedTime,\n selectedTimeText: value,\n errorType\n });\n }\n });\n const handleKeyDown = useEventCallback((e)=>{\n const activeOption = getActiveOption();\n if (!activeOption && e.key === Enter) {\n selectTimeFromValue(e);\n }\n });\n state.root.onKeyDown = mergeCallbacks(handleKeyDown, state.root.onKeyDown);\n const rootRef = React.useRef(null);\n state.root.ref = useMergedRefs(state.root.ref, rootRef);\n if (state.listbox) {\n state.listbox.tabIndex = -1; // allows it to be the relatedTarget of a blur event.\n }\n if (state.expandIcon) {\n state.expandIcon.tabIndex = -1; // allows it to be the relatedTarget of a blur event.\n }\n const handleInputBlur = useEventCallback((e)=>{\n const isOutside = e.relatedTarget ? !elementContains(rootRef.current, e.relatedTarget) : true;\n if (isOutside) {\n selectTimeFromValue(e);\n }\n });\n state.input.onBlur = mergeCallbacks(handleInputBlur, state.input.onBlur);\n};\n/**\n * Provides a default aria-labelledby for the chevron icon if the TimePicker is wrapped in a Field.\n */ const useDefaultChevronIconLabel = (state)=>{\n var _state_expandIcon;\n const fieldContext = useFieldContext();\n const chevronDefaultId = useId('timepicker-chevron-');\n const defaultLabelFromCombobox = 'Open';\n if ((fieldContext === null || fieldContext === void 0 ? void 0 : fieldContext.labelId) && ((_state_expandIcon = state.expandIcon) === null || _state_expandIcon === void 0 ? void 0 : _state_expandIcon['aria-label']) === defaultLabelFromCombobox) {\n var _state_expandIcon_id;\n const chevronId = (_state_expandIcon_id = state.expandIcon.id) !== null && _state_expandIcon_id !== void 0 ? _state_expandIcon_id : chevronDefaultId;\n state.expandIcon['aria-labelledby'] = `${chevronId} ${fieldContext.labelId}`;\n }\n};\n"],"names":["useTimePicker_unstable","props","ref","dateAnchor","dateAnchorInProps","defaultSelectedTime","defaultSelectedTimeInProps","endHour","formatDateToTimeString","defaultFormatDateToTimeString","hourCycle","increment","onTimeChange","selectedTime","selectedTimeInProps","showSeconds","startHour","parseTimeStringToDate","parseTimeStringToDateInProps","rest","freeform","_ref","dateStartAnchor","dateEndAnchor","useStableDateAnchor","options","React","useMemo","getTimesBetween","map","time","date","key","dateToKey","text","setSelectedTime","useControllableState","state","defaultState","initialState","submittedText","setSubmittedText","useState","undefined","selectTime","useEventCallback","e","data","selectedTimeText","selectedOptions","selectedTimeKey","selectedOption","find","handleOptionSelect","optionValue","_data_optionValue","timeSelectionData","keyToDate","optionText","errorType","baseState","useCombobox_unstable","autoComplete","onOptionSelect","children","createElement","Option","value","defaultParseTimeStringToDate","useCallback","getDateFromTimeString","useDefaultChevronIconLabel","useSelectTimeFromValue","providedDate","fallbackDateAnchor","Date","providedDateKey","getDateStartAnchor","getDateEndAnchor","callback","getOptionById","activeDescendantController","getActiveOption","activeOptionId","active","useEffect","activeOption","valueMatchesActiveOption","toLowerCase","indexOf","blur","selectTimeFromValue","handleKeyDown","Enter","root","onKeyDown","mergeCallbacks","rootRef","useRef","useMergedRefs","listbox","tabIndex","expandIcon","handleInputBlur","isOutside","relatedTarget","elementContains","current","input","onBlur","_state_expandIcon","fieldContext","useFieldContext","chevronDefaultId","useId","defaultLabelFromCombobox","labelId","_state_expandIcon_id","chevronId","id"],"mappings":";;;;+BAciBA;;;eAAAA;;;;iEAdM;gCACuF;8BACxF;+BACuB;4BACe;0BACgH;AASjK,MAAMA,yBAAyB,CAACC,OAAOC;IAC9C,MAAM,EAAEC,YAAYC,iBAAiB,EAAEC,qBAAqBC,0BAA0B,EAAEC,UAAU,EAAE,EAAEC,yBAAyBC,gCAA6B,EAAEC,SAAS,EAAEC,YAAY,EAAE,EAAEC,YAAY,EAAEC,cAAcC,mBAAmB,EAAEC,cAAc,KAAK,EAAEC,YAAY,CAAC,EAAEC,uBAAuBC,4BAA4B,EAAE,GAAGC,MAAM,GAAGlB;IAC/U,MAAM,EAAEmB,WAAW,KAAK,EAAE,GAAGD;IAC7B,IAAIE;IACJ,MAAM,EAAEC,eAAe,EAAEC,aAAa,EAAE,GAAGC,oBAAoB,AAACH,CAAAA,OAAOjB,sBAAsB,QAAQA,sBAAsB,KAAK,IAAIA,oBAAoBU,mBAAkB,MAAO,QAAQO,SAAS,KAAK,IAAIA,OAAOf,4BAA4BU,WAAWT;IACzP,MAAMkB,UAAUC,OAAMC,OAAO,CAAC,IAAIC,IAAAA,yBAAe,EAACN,iBAAiBC,eAAeZ,WAAWkB,GAAG,CAAC,CAACC,OAAQ,CAAA;gBAC9FC,MAAMD;gBACNE,KAAKC,IAAAA,mBAAS,EAACH;gBACfI,MAAM1B,uBAAuBsB,MAAM;oBAC/Bf;oBACAL;gBACJ;YACJ,CAAA,IAAK;QACTa;QACAD;QACAd;QACAE;QACAC;QACAI;KACH;IACD,MAAM,CAACF,cAAcsB,gBAAgB,GAAGC,IAAAA,oCAAoB,EAAC;QACzDC,OAAOvB;QACPwB,cAAchC;QACdiC,cAAc;IAClB;IAC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IACzF;IACA,MAAME,kBAAkB1D,IAAAA,gCAAgB,EAAC,CAACC;QACtC,MAAM0D,YAAY1D,EAAE2D,aAAa,GAAG,CAACC,IAAAA,+BAAe,EAACT,QAAQU,OAAO,EAAE7D,EAAE2D,aAAa,IAAI;QACzF,IAAID,WAAW;YACXb,oBAAoB7C;QACxB;IACJ;IACAT,MAAMuE,KAAK,CAACC,MAAM,GAAGb,IAAAA,8BAAc,EAACO,iBAAiBlE,MAAMuE,KAAK,CAACC,MAAM;AAC3E;AACA;;CAEC,GAAG,MAAMtC,6BAA6B,CAAClC;IACpC,IAAIyE;IACJ,MAAMC,eAAeC,IAAAA,oCAAe;IACpC,MAAMC,mBAAmBC,IAAAA,qBAAK,EAAC;IAC/B,MAAMC,2BAA2B;IACjC,IAAI,AAACJ,CAAAA,iBAAiB,QAAQA,iBAAiB,KAAK,IAAI,KAAK,IAAIA,aAAaK,OAAO,AAAD,KAAM,AAAC,CAAA,AAACN,CAAAA,oBAAoBzE,MAAMiE,UAAU,AAAD,MAAO,QAAQQ,sBAAsB,KAAK,IAAI,KAAK,IAAIA,iBAAiB,CAAC,aAAa,AAAD,MAAOK,0BAA0B;QACjP,IAAIE;QACJ,MAAMC,YAAY,AAACD,CAAAA,uBAAuBhF,MAAMiE,UAAU,CAACiB,EAAE,AAAD,MAAO,QAAQF,yBAAyB,KAAK,IAAIA,uBAAuBJ;QACpI5E,MAAMiE,UAAU,CAAC,kBAAkB,GAAG,CAAC,EAAEgB,UAAU,CAAC,EAAEP,aAAaK,OAAO,CAAC,CAAC;IAChF;AACJ"}
|
|
@@ -22,6 +22,7 @@ const timePickerClassNames = {
|
|
|
22
22
|
root: 'fui-TimePicker',
|
|
23
23
|
input: 'fui-TimePicker__input',
|
|
24
24
|
expandIcon: 'fui-TimePicker__expandIcon',
|
|
25
|
+
clearIcon: 'fui-TimePicker__clearIcon',
|
|
25
26
|
listbox: 'fui-TimePicker__listbox'
|
|
26
27
|
};
|
|
27
28
|
const useStyles = /*#__PURE__*/ (0, _react.__styles)({
|
|
@@ -40,6 +41,9 @@ const useTimePickerStyles_unstable = (state)=>{
|
|
|
40
41
|
if (state.expandIcon) {
|
|
41
42
|
state.expandIcon.className = (0, _react.mergeClasses)(timePickerClassNames.expandIcon, state.expandIcon.className);
|
|
42
43
|
}
|
|
44
|
+
if (state.clearIcon) {
|
|
45
|
+
state.clearIcon.className = (0, _react.mergeClasses)(timePickerClassNames.clearIcon, state.clearIcon.className);
|
|
46
|
+
}
|
|
43
47
|
if (state.listbox) {
|
|
44
48
|
state.listbox.className = (0, _react.mergeClasses)(timePickerClassNames.listbox, styles.listbox, state.listbox.className);
|
|
45
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useTimePickerStyles.styles.js"],"sourcesContent":["import { __styles, mergeClasses } from '@griffel/react';\nimport { useComboboxStyles_unstable } from '@fluentui/react-combobox';\nexport const timePickerClassNames = {\n root: 'fui-TimePicker',\n input: 'fui-TimePicker__input',\n expandIcon: 'fui-TimePicker__expandIcon',\n listbox: 'fui-TimePicker__listbox'\n};\nconst useStyles = /*#__PURE__*/__styles({\n listbox: {\n Bxyxcbc: \"f1vfnyiv\"\n }\n}, {\n d: [\".f1vfnyiv{max-height:min(80vh, 416px);}\"]\n});\n/**\n * Apply styling to the TimePicker slots based on the state\n */\nexport const useTimePickerStyles_unstable = state => {\n const styles = useStyles();\n state.root.className = mergeClasses(timePickerClassNames.root, state.root.className);\n state.input.className = mergeClasses(timePickerClassNames.input, state.input.className);\n if (state.expandIcon) {\n state.expandIcon.className = mergeClasses(timePickerClassNames.expandIcon, state.expandIcon.className);\n }\n if (state.listbox) {\n state.listbox.className = mergeClasses(timePickerClassNames.listbox, styles.listbox, state.listbox.className);\n }\n useComboboxStyles_unstable(state);\n return state;\n};\n//# sourceMappingURL=useTimePickerStyles.styles.js.map"],"names":["timePickerClassNames","useTimePickerStyles_unstable","root","input","expandIcon","listbox","useStyles","__styles","Bxyxcbc","d","state","styles","className","mergeClasses","useComboboxStyles_unstable"],"mappings":";;;;;;;;;;;IAEaA,oBAAoB;eAApBA;;
|
|
1
|
+
{"version":3,"sources":["useTimePickerStyles.styles.js"],"sourcesContent":["import { __styles, mergeClasses } from '@griffel/react';\nimport { useComboboxStyles_unstable } from '@fluentui/react-combobox';\nexport const timePickerClassNames = {\n root: 'fui-TimePicker',\n input: 'fui-TimePicker__input',\n expandIcon: 'fui-TimePicker__expandIcon',\n clearIcon: 'fui-TimePicker__clearIcon',\n listbox: 'fui-TimePicker__listbox'\n};\nconst useStyles = /*#__PURE__*/__styles({\n listbox: {\n Bxyxcbc: \"f1vfnyiv\"\n }\n}, {\n d: [\".f1vfnyiv{max-height:min(80vh, 416px);}\"]\n});\n/**\n * Apply styling to the TimePicker slots based on the state\n */\nexport const useTimePickerStyles_unstable = state => {\n const styles = useStyles();\n state.root.className = mergeClasses(timePickerClassNames.root, state.root.className);\n state.input.className = mergeClasses(timePickerClassNames.input, state.input.className);\n if (state.expandIcon) {\n state.expandIcon.className = mergeClasses(timePickerClassNames.expandIcon, state.expandIcon.className);\n }\n if (state.clearIcon) {\n state.clearIcon.className = mergeClasses(timePickerClassNames.clearIcon, state.clearIcon.className);\n }\n if (state.listbox) {\n state.listbox.className = mergeClasses(timePickerClassNames.listbox, styles.listbox, state.listbox.className);\n }\n useComboboxStyles_unstable(state);\n return state;\n};\n//# sourceMappingURL=useTimePickerStyles.styles.js.map"],"names":["timePickerClassNames","useTimePickerStyles_unstable","root","input","expandIcon","clearIcon","listbox","useStyles","__styles","Bxyxcbc","d","state","styles","className","mergeClasses","useComboboxStyles_unstable"],"mappings":";;;;;;;;;;;IAEaA,oBAAoB;eAApBA;;IAiBAC,4BAA4B;eAA5BA;;;uBAnB0B;+BACI;AACpC,MAAMD,uBAAuB;IAClCE,MAAM;IACNC,OAAO;IACPC,YAAY;IACZC,WAAW;IACXC,SAAS;AACX;AACA,MAAMC,YAAY,WAAW,GAAEC,IAAAA,eAAQ,EAAC;IACtCF,SAAS;QACPG,SAAS;IACX;AACF,GAAG;IACDC,GAAG;QAAC;KAA0C;AAChD;AAIO,MAAMT,+BAA+BU,CAAAA;IAC1C,MAAMC,SAASL;IACfI,MAAMT,IAAI,CAACW,SAAS,GAAGC,IAAAA,mBAAY,EAACd,qBAAqBE,IAAI,EAAES,MAAMT,IAAI,CAACW,SAAS;IACnFF,MAAMR,KAAK,CAACU,SAAS,GAAGC,IAAAA,mBAAY,EAACd,qBAAqBG,KAAK,EAAEQ,MAAMR,KAAK,CAACU,SAAS;IACtF,IAAIF,MAAMP,UAAU,EAAE;QACpBO,MAAMP,UAAU,CAACS,SAAS,GAAGC,IAAAA,mBAAY,EAACd,qBAAqBI,UAAU,EAAEO,MAAMP,UAAU,CAACS,SAAS;IACvG;IACA,IAAIF,MAAMN,SAAS,EAAE;QACnBM,MAAMN,SAAS,CAACQ,SAAS,GAAGC,IAAAA,mBAAY,EAACd,qBAAqBK,SAAS,EAAEM,MAAMN,SAAS,CAACQ,SAAS;IACpG;IACA,IAAIF,MAAML,OAAO,EAAE;QACjBK,MAAML,OAAO,CAACO,SAAS,GAAGC,IAAAA,mBAAY,EAACd,qBAAqBM,OAAO,EAAEM,OAAON,OAAO,EAAEK,MAAML,OAAO,CAACO,SAAS;IAC9G;IACAE,IAAAA,yCAA0B,EAACJ;IAC3B,OAAOA;AACT,GACA,sDAAsD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui/react-timepicker-compat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Fluent UI TimePicker Compat Component",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@fluentui/keyboard-keys": "^9.0.7",
|
|
43
|
-
"@fluentui/react-combobox": "^9.
|
|
44
|
-
"@fluentui/react-field": "^9.1.
|
|
45
|
-
"@fluentui/react-jsx-runtime": "^9.0.
|
|
43
|
+
"@fluentui/react-combobox": "^9.8.0",
|
|
44
|
+
"@fluentui/react-field": "^9.1.54",
|
|
45
|
+
"@fluentui/react-jsx-runtime": "^9.0.30",
|
|
46
46
|
"@fluentui/react-shared-contexts": "^9.14.0",
|
|
47
47
|
"@fluentui/react-theme": "^9.1.16",
|
|
48
|
-
"@fluentui/react-utilities": "^9.18.
|
|
48
|
+
"@fluentui/react-utilities": "^9.18.1",
|
|
49
49
|
"@griffel/react": "^1.5.14",
|
|
50
50
|
"@swc/helpers": "^0.5.1"
|
|
51
51
|
},
|