-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pickers] Prepare new picker ownerState object
- Loading branch information
1 parent
b4b1794
commit baa73e9
Showing
5 changed files
with
58 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/x-date-pickers/src/internals/hooks/usePicker/usePickerOwnerState.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,40 @@ | ||
import { FieldSection } from '../../../models'; | ||
import type { UsePickerProps } from './usePicker.types'; | ||
import { UsePickerValueResponse } from './usePickerValue.types'; | ||
|
||
export interface PickerOwnerState<TValue> { | ||
/** | ||
* The value currently displayed in the field and in the view. | ||
*/ | ||
value: TValue; | ||
/** | ||
* `true` if the picker is open, `false` otherwise. | ||
*/ | ||
open: boolean; | ||
/** | ||
* `true` if the picker is disabled, `false` otherwise. | ||
*/ | ||
disabled: boolean; | ||
/** | ||
* `true` if the picker is read-only, `false` otherwise. | ||
*/ | ||
readOnly: boolean; | ||
} | ||
|
||
interface UsePickerOwnerStateParameters<TValue> { | ||
props: UsePickerProps<TValue, any, any, any, any, any>; | ||
pickerValueResponse: UsePickerValueResponse<TValue, FieldSection, any>; | ||
} | ||
|
||
export function usePickerOwnerState<TValue>( | ||
parameters: UsePickerOwnerStateParameters<TValue>, | ||
): PickerOwnerState<TValue> { | ||
const { props, pickerValueResponse } = parameters; | ||
|
||
return { | ||
value: pickerValueResponse.viewProps.value, | ||
open: pickerValueResponse.open, | ||
disabled: props.disabled ?? false, | ||
readOnly: props.readOnly ?? false, | ||
}; | ||
} |