Skip to content

Commit 567ca4f

Browse files
[pickers] Improve the JSDoc of the PickerContextValue properties (#16327)
1 parent bc7258c commit 567ca4f

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

packages/x-date-pickers/src/internals/components/PickerProvider.tsx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,28 +97,27 @@ export interface PickerContextValue<
9797
> extends UsePickerValueContextValue<TValue, TError>,
9898
UsePickerViewsContextValue<TView> {
9999
/**
100-
* `true` if the picker is disabled, `false` otherwise.
100+
* Whether the picker is disabled.
101101
*/
102102
disabled: boolean;
103103
/**
104-
* `true` if the picker is read-only, `false` otherwise.
104+
* Whether the picker is read-only.
105105
*/
106106
readOnly: boolean;
107107
/**
108108
* The responsive variant of the picker.
109-
* Is equal to "desktop" when using a desktop picker (like <DesktopDatePicker />).
110-
* Is equal to "mobile" when using a mobile picker (like <MobileDatePicker />).
111-
* Is equal to "mobile" or "desktop" when using a responsive picker (like <DatePicker />) depending on the `desktopModeMediaQuery` prop.
112-
* Is equal to "mobile" or "desktop" when using a static picker (like <StaticDatePicker />) depending on the `displayStaticWrapperAs` prop.
113-
* Is always equal to "desktop" if the component you are accessing the context from is not wrapped by a picker.
109+
* It is equal to "desktop" when using a desktop picker (like <DesktopDatePicker />).
110+
* It is equal to "mobile" when using a mobile picker (like <MobileDatePicker />).
111+
* It is equal to "mobile" or "desktop" when using a responsive picker (like <DatePicker />) depending on the `desktopModeMediaQuery` prop.
112+
* It is equal to "mobile" or "desktop" when using a static picker (like <StaticDatePicker />) depending on the `displayStaticWrapperAs` prop.
113+
* It is always equal to "desktop" if the component you are accessing the context from is not wrapped by a picker.
114114
*/
115115
variant: PickerVariant;
116116
/**
117117
* The orientation of the picker.
118-
* Is equal to "landscape" when the picker is in landscape orientation.
119-
* Is equal to "portrait" when the picker is in portrait orientation.
120-
* You can use the "orientation" on any picker component to force the orientation.
121-
* Is always equal to "portrait" if the component you are accessing the context from is not wrapped by a picker.
118+
* On Time Pickers and Date Time Pickers, it is always equal to "portrait".
119+
* On Date Pickers, it is equal to the picker `orientation` prop if defined, otherwise it is based on the current orientation of the user's screen.
120+
* It is always equal to "portrait" if the component you are accessing the context from is not wrapped by a picker.
122121
*/
123122
orientation: PickerOrientation;
124123
/**
@@ -127,8 +126,8 @@ export interface PickerContextValue<
127126
*/
128127
reduceAnimations?: boolean;
129128
/**
130-
* The ref that should be attached to the element that triggers the Picker opening.
131-
* When using a built-in field component, this property is automatically handled.
129+
* The ref to attach to the element that triggers the Picker opening.
130+
* When using a built-in field component, this property is automatically attached to the right element.
132131
*/
133132
triggerRef: React.RefObject<any>;
134133
/**
@@ -139,11 +138,11 @@ export interface PickerContextValue<
139138
*/
140139
triggerStatus: 'hidden' | 'disabled' | 'enabled';
141140
/**
142-
* Format that should be used to render the value in the field.
143-
* Is equal to `props.format` on the picker component if defined.
144-
* Is generated based on the available views if not defined.
145-
* Is equal to an empty string if the picker does not have a field (static pickers).
146-
* Is always equal to an empty string if the component you are accessing the context from is not wrapped by a picker.
141+
* The format to use when rendering the value in the field.
142+
* It is equal to the picker `format` prop if defined.
143+
* It is generated based on the available views if not defined.
144+
* It is always equal to an empty string if the picker does not have a field (static pickers).
145+
* It is always equal to an empty string if the component you are accessing the context from is not wrapped by a picker.
147146
*/
148147
fieldFormat: string;
149148
}

packages/x-date-pickers/src/internals/hooks/usePicker/usePickerValue.types.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,15 @@ export interface UsePickerValueContextValue<TValue extends PickerValidValue, TEr
272272
value: TValue;
273273
/**
274274
* The timezone to use when rendering the dates.
275+
* If a `timezone` prop is provided, it will be used.
276+
* If the `value` prop contains a valid date, its timezone will be used.
277+
* If no `value` prop is provided, but the `defaultValue` contains a valid date, its timezone will be used.
278+
* If no `value` or `defaultValue` is provided, but the `referenceDate` is provided, its timezone will be used.
279+
* Otherwise, the timezone will be the default one of your date library.
275280
*/
276281
timezone: PickersTimezone;
277282
/**
278-
* `true` if the picker is open, `false` otherwise.
283+
* Whether the picker is open.
279284
*/
280285
open: boolean;
281286
}
@@ -324,31 +329,31 @@ export interface UsePickerValueActionsContextValue<TValue extends PickerValidVal
324329

325330
export interface UsePickerValuePrivateContextValue {
326331
/**
327-
* Closes the picker and accepts the current value if it is not equal to the last accepted value.
332+
* Close the picker and accepts the current value if it is not equal to the last accepted value.
328333
*/
329334
dismissViews: () => void;
330335
}
331336

332337
export interface SetValueActionOptions<TError = string | null> {
333338
/**
334-
* Importance of the change when picking a value:
339+
* The importance of the change when picking a value:
335340
* - "accept": fires `onChange`, fires `onAccept` and closes the picker.
336341
* - "set": fires `onChange` but do not fire `onAccept` and does not close the picker.
337342
* @default "accept"
338343
*/
339344
changeImportance?: PickerChangeImportance;
340345
/**
341346
* The validation error associated to the current value.
342-
* If not defined, the validation will be re-applied by the picker.
347+
* If not defined, the validation will be computed by the picker.
343348
*/
344349
validationError?: TError;
345350
/**
346351
* The shortcut that triggered this change.
347-
* Should not be defined if the change does not come from a shortcut.
352+
* It should not be defined if the change does not come from a shortcut.
348353
*/
349354
shortcut?: PickersShortcutsItemContext;
350355
/**
351-
* Decide if the value should call `onChange` and `onAccept` when the value is not controlled and has never been modified.
356+
* Whether the value should call `onChange` and `onAccept` when the value is not controlled and has never been modified.
352357
* If `true`, the `onChange` and `onAccept` callback will only be fired if the value has been modified (and is not equal to the last published value).
353358
* If `false`, the `onChange` and `onAccept` callback will be fired when the value has never been modified (`onAccept` only if `changeImportance` is set to "accept").
354359
* @default false

packages/x-date-pickers/src/internals/hooks/usePicker/usePickerViews.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,18 @@ export interface UsePickerViewsActionsContextValue<TView extends DateOrTimeViewW
124124
export interface UsePickerViewsContextValue<TView extends DateOrTimeViewWithMeridiem>
125125
extends UsePickerViewsActionsContextValue<TView> {
126126
/**
127-
* Available views.
127+
* The views that the picker must render.
128+
* It is equal to the picker `views` prop if defined.
129+
* Otherwise, a default set of views is provided based on the component you are using:
130+
* - Date Pickers: ['year', 'day']
131+
* - Time Pickers: ['hours', 'minutes']
132+
* - Date Time Pickers: ['year', 'day', 'hours', 'minutes']
133+
* - Date Range Pickers: ['day']
134+
* - Date Time Range Pickers: ['day', 'hours', 'minutes']
128135
*/
129136
views: readonly TView[];
130137
/**
131-
* View currently rendered.
138+
* The view currently rendered.
132139
*/
133140
view: TView | null;
134141
}

0 commit comments

Comments
 (0)