Skip to content

Commit

Permalink
[internal][pickers] Inline some BasePickerProps usages (#25971)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored Apr 26, 2021
1 parent 7556475 commit f3e4ac4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from 'react';
import { unstable_useEnhancedEffect as useEnhancedEffect } from '@material-ui/utils';
import { arrayIncludes } from '../utils';
import { BasePickerProps } from '../typings/BasePicker';
import { AllAvailableViews } from '../typings/Views';

// tslint:disable deprecation
const getOrientation = () => {
type Orientation = 'portrait' | 'landscape';

function getOrientation(): Orientation {
if (typeof window === 'undefined') {
return 'portrait';
}
Expand All @@ -14,21 +14,19 @@ const getOrientation = () => {
return Math.abs(window.screen.orientation.angle) === 90 ? 'landscape' : 'portrait';
}

// Support IOS safar
// Support IOS safari
if (window.orientation) {
return Math.abs(Number(window.orientation)) === 90 ? 'landscape' : 'portrait';
}

return 'portrait';
};
}

export function useIsLandscape(
views: readonly AllAvailableViews[],
customOrientation?: BasePickerProps['orientation'],
customOrientation: Orientation | undefined,
): boolean {
const [orientation, setOrientation] = React.useState<BasePickerProps['orientation']>(
getOrientation(),
);
const [orientation, setOrientation] = React.useState(getOrientation);

useEnhancedEffect(() => {
const eventHandler = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import * as React from 'react';
import { BasePickerProps } from '../typings/BasePicker';

export function useOpenState({ open, onOpen, onClose }: BasePickerProps<any, any>) {
export interface OpenStateProps {
open?: boolean;
onOpen?: () => void;
onClose?: () => void;
}

export function useOpenState({ open, onOpen, onClose }: OpenStateProps) {
const isControllingOpenProp = React.useRef(typeof open === 'boolean').current;
const [openState, setIsOpenState] = React.useState(false);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import { useOpenState } from './useOpenState';
import { WrapperVariant } from '../wrappers/WrapperVariantContext';
import { BasePickerProps } from '../typings/BasePicker';
import { useUtils, MuiPickersAdapter } from './useUtils';

export interface PickerStateValueManager<TInputValue, TDateValue> {
Expand All @@ -26,8 +25,21 @@ interface DraftAction<DraftValue> {
payload: DraftValue;
}

export interface PickerStateProps<TInput, TDateValue> {
disableCloseOnSelect?: boolean;
disabled?: boolean;
inputFormat?: string;
open?: boolean;
onAccept?: (date: TDateValue) => void;
onChange: (date: TDateValue, keyboardInputValue?: string) => void;
onClose?: () => void;
onOpen?: () => void;
readOnly?: boolean;
value: TInput;
}

export function usePickerState<TInput, TDateValue>(
props: BasePickerProps<TInput, TDateValue>,
props: PickerStateProps<TInput, TDateValue>,
valueManager: PickerStateValueManager<TInput, TDateValue>,
) {
const {
Expand Down

0 comments on commit f3e4ac4

Please sign in to comment.