forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPickersLayout.tsx
192 lines (181 loc) · 6.04 KB
/
PickersLayout.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { styled, useThemeProps } from '@mui/material/styles';
import composeClasses from '@mui/utils/composeClasses';
import { PickerLayoutOwnerState, PickersLayoutProps } from './PickersLayout.types';
import {
pickersLayoutClasses,
getPickersLayoutUtilityClass,
PickersLayoutClasses,
} from './pickersLayoutClasses';
import usePickerLayout from './usePickerLayout';
import { DateOrTimeViewWithMeridiem, PickerValidValue } from '../internals/models';
import { usePickerContext } from '../hooks/usePickerContext';
const useUtilityClasses = (
classes: Partial<PickersLayoutClasses> | undefined,
ownerState: PickerLayoutOwnerState,
) => {
const { pickerOrientation } = ownerState;
const slots = {
root: ['root', pickerOrientation === 'landscape' && 'landscape'],
contentWrapper: ['contentWrapper'],
};
return composeClasses(slots, getPickersLayoutUtilityClass, classes);
};
export const PickersLayoutRoot = styled('div', {
name: 'MuiPickersLayout',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})<{ ownerState: PickerLayoutOwnerState }>({
display: 'grid',
gridAutoColumns: 'max-content auto max-content',
gridAutoRows: 'max-content auto max-content',
[`& .${pickersLayoutClasses.actionBar}`]: { gridColumn: '1 / 4', gridRow: 3 },
variants: [
{
props: { pickerOrientation: 'landscape' },
style: {
[`& .${pickersLayoutClasses.toolbar}`]: {
gridColumn: 1,
gridRow: '2 / 3',
},
[`.${pickersLayoutClasses.shortcuts}`]: { gridColumn: '2 / 4', gridRow: 1 },
},
},
{
props: { pickerOrientation: 'landscape', layoutDirection: 'rtl' },
style: {
[`& .${pickersLayoutClasses.toolbar}`]: {
gridColumn: 3,
},
},
},
{
props: { pickerOrientation: 'portrait' },
style: {
[`& .${pickersLayoutClasses.toolbar}`]: { gridColumn: '2 / 4', gridRow: 1 },
[`& .${pickersLayoutClasses.shortcuts}`]: {
gridColumn: 1,
gridRow: '2 / 3',
},
},
},
{
props: { pickerOrientation: 'portrait', layoutDirection: 'rtl' },
style: {
[`& .${pickersLayoutClasses.shortcuts}`]: {
gridColumn: 3,
},
},
},
],
});
export const PickersLayoutContentWrapper = styled('div', {
name: 'MuiPickersLayout',
slot: 'ContentWrapper',
overridesResolver: (props, styles) => styles.contentWrapper,
})<{ ownerState: PickerLayoutOwnerState }>({
gridColumn: 2,
gridRow: 2,
display: 'flex',
flexDirection: 'column',
});
type PickersLayoutComponent = (<
TValue extends PickerValidValue,
TView extends DateOrTimeViewWithMeridiem,
>(
props: PickersLayoutProps<TValue, TView> & React.RefAttributes<HTMLDivElement>,
) => React.JSX.Element) & { propTypes?: any };
/**
* Demos:
*
* - [Custom layout](https://mui.com/x/react-date-pickers/custom-layout/)
*
* API:
*
* - [PickersLayout API](https://mui.com/x/api/date-pickers/pickers-layout/)
*/
const PickersLayout = React.forwardRef(function PickersLayout<
TValue extends PickerValidValue,
TView extends DateOrTimeViewWithMeridiem,
>(inProps: PickersLayoutProps<TValue, TView>, ref: React.Ref<HTMLDivElement>) {
const props = useThemeProps({ props: inProps, name: 'MuiPickersLayout' });
const { toolbar, content, tabs, actionBar, shortcuts, ownerState } = usePickerLayout(props);
const { orientation, variant } = usePickerContext();
const { sx, className, classes: classesProp } = props;
const classes = useUtilityClasses(classesProp, ownerState);
return (
<PickersLayoutRoot
ref={ref}
sx={sx}
className={clsx(classes.root, className)}
ownerState={ownerState}
>
{orientation === 'landscape' ? shortcuts : toolbar}
{orientation === 'landscape' ? toolbar : shortcuts}
<PickersLayoutContentWrapper className={classes.contentWrapper} ownerState={ownerState}>
{variant === 'desktop' ? (
<React.Fragment>
{content}
{tabs}
</React.Fragment>
) : (
<React.Fragment>
{tabs}
{content}
</React.Fragment>
)}
</PickersLayoutContentWrapper>
{actionBar}
</PickersLayoutRoot>
);
}) as PickersLayoutComponent;
PickersLayout.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
children: PropTypes.node,
/**
* Override or extend the styles applied to the component.
*/
classes: PropTypes.object,
className: PropTypes.string,
isValid: PropTypes.func.isRequired,
onAccept: PropTypes.func.isRequired,
onCancel: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
onClear: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
onDismiss: PropTypes.func.isRequired,
onOpen: PropTypes.func.isRequired,
onSelectShortcut: PropTypes.func.isRequired,
onSetToday: PropTypes.func.isRequired,
onViewChange: PropTypes.func.isRequired,
/**
* The props used for each component slot.
* @default {}
*/
slotProps: PropTypes.object,
/**
* Overridable component slots.
* @default {}
*/
slots: PropTypes.object,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])),
PropTypes.func,
PropTypes.object,
]),
value: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object]),
view: PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']),
views: PropTypes.arrayOf(
PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']).isRequired,
).isRequired,
} as any;
export { PickersLayout };