Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[internal][pickers] Inline some BasePickerProps usages #25971

Merged
merged 1 commit into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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