1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import NativeSelectInput from './NativeSelectInput';
|
6 | import withStyles from '../styles/withStyles';
|
7 | import formControlState from '../FormControl/formControlState';
|
8 | import useFormControl from '../FormControl/useFormControl';
|
9 | import ArrowDropDownIcon from '../internal/svg-icons/ArrowDropDown';
|
10 | import Input from '../Input';
|
11 | export var styles = function styles(theme) {
|
12 | return {
|
13 |
|
14 | root: {},
|
15 |
|
16 |
|
17 | select: {
|
18 | '-moz-appearance': 'none',
|
19 |
|
20 | '-webkit-appearance': 'none',
|
21 |
|
22 |
|
23 |
|
24 | userSelect: 'none',
|
25 | borderRadius: 0,
|
26 |
|
27 | minWidth: 16,
|
28 |
|
29 | cursor: 'pointer',
|
30 | '&:focus': {
|
31 |
|
32 | backgroundColor: theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.05)' : 'rgba(255, 255, 255, 0.05)',
|
33 | borderRadius: 0
|
34 |
|
35 | },
|
36 |
|
37 | '&::-ms-expand': {
|
38 | display: 'none'
|
39 | },
|
40 | '&$disabled': {
|
41 | cursor: 'default'
|
42 | },
|
43 | '&[multiple]': {
|
44 | height: 'auto'
|
45 | },
|
46 | '&:not([multiple]) option, &:not([multiple]) optgroup': {
|
47 | backgroundColor: theme.palette.background.paper
|
48 | },
|
49 | '&&': {
|
50 | paddingRight: 24
|
51 | }
|
52 | },
|
53 |
|
54 |
|
55 | filled: {
|
56 | '&&': {
|
57 | paddingRight: 32
|
58 | }
|
59 | },
|
60 |
|
61 |
|
62 | outlined: {
|
63 | borderRadius: theme.shape.borderRadius,
|
64 | '&&': {
|
65 | paddingRight: 32
|
66 | }
|
67 | },
|
68 |
|
69 |
|
70 | selectMenu: {
|
71 | height: 'auto',
|
72 |
|
73 | minHeight: '1.1876em',
|
74 |
|
75 | textOverflow: 'ellipsis',
|
76 | whiteSpace: 'nowrap',
|
77 | overflow: 'hidden'
|
78 | },
|
79 |
|
80 |
|
81 | disabled: {},
|
82 |
|
83 |
|
84 | icon: {
|
85 |
|
86 |
|
87 | position: 'absolute',
|
88 | right: 0,
|
89 | top: 'calc(50% - 12px)',
|
90 |
|
91 | pointerEvents: 'none',
|
92 |
|
93 | color: theme.palette.action.active,
|
94 | '&$disabled': {
|
95 | color: theme.palette.action.disabled
|
96 | }
|
97 | },
|
98 |
|
99 |
|
100 | iconOpen: {
|
101 | transform: 'rotate(180deg)'
|
102 | },
|
103 |
|
104 |
|
105 | iconFilled: {
|
106 | right: 7
|
107 | },
|
108 |
|
109 |
|
110 | iconOutlined: {
|
111 | right: 7
|
112 | },
|
113 |
|
114 |
|
115 | nativeInput: {
|
116 | bottom: 0,
|
117 | left: 0,
|
118 | position: 'absolute',
|
119 | opacity: 0,
|
120 | pointerEvents: 'none',
|
121 | width: '100%'
|
122 | }
|
123 | };
|
124 | };
|
125 | var defaultInput = React.createElement(Input, null);
|
126 |
|
127 |
|
128 |
|
129 |
|
130 | var NativeSelect = React.forwardRef(function NativeSelect(props, ref) {
|
131 | var children = props.children,
|
132 | classes = props.classes,
|
133 | _props$IconComponent = props.IconComponent,
|
134 | IconComponent = _props$IconComponent === void 0 ? ArrowDropDownIcon : _props$IconComponent,
|
135 | _props$input = props.input,
|
136 | input = _props$input === void 0 ? defaultInput : _props$input,
|
137 | inputProps = props.inputProps,
|
138 | variant = props.variant,
|
139 | other = _objectWithoutProperties(props, ["children", "classes", "IconComponent", "input", "inputProps", "variant"]);
|
140 |
|
141 | var muiFormControl = useFormControl();
|
142 | var fcs = formControlState({
|
143 | props: props,
|
144 | muiFormControl: muiFormControl,
|
145 | states: ['variant']
|
146 | });
|
147 | return React.cloneElement(input, _extends({
|
148 |
|
149 |
|
150 | inputComponent: NativeSelectInput,
|
151 | inputProps: _extends({
|
152 | children: children,
|
153 | classes: classes,
|
154 | IconComponent: IconComponent,
|
155 | variant: fcs.variant,
|
156 | type: undefined
|
157 | }, inputProps, input ? input.props.inputProps : {}),
|
158 | ref: ref
|
159 | }, other));
|
160 | });
|
161 | process.env.NODE_ENV !== "production" ? NativeSelect.propTypes = {
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 | |
168 |
|
169 |
|
170 |
|
171 | children: PropTypes.node,
|
172 |
|
173 | |
174 |
|
175 |
|
176 |
|
177 | classes: PropTypes.object,
|
178 |
|
179 | |
180 |
|
181 |
|
182 | IconComponent: PropTypes.elementType,
|
183 |
|
184 | |
185 |
|
186 |
|
187 | input: PropTypes.element,
|
188 |
|
189 | |
190 |
|
191 |
|
192 | inputProps: PropTypes.object,
|
193 |
|
194 | |
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | onChange: PropTypes.func,
|
201 |
|
202 | |
203 |
|
204 |
|
205 | value: PropTypes.any,
|
206 |
|
207 | |
208 |
|
209 |
|
210 | variant: PropTypes.oneOf(['filled', 'outlined', 'standard'])
|
211 | } : void 0;
|
212 | NativeSelect.muiName = 'Select';
|
213 | export default withStyles(styles, {
|
214 | name: 'MuiNativeSelect'
|
215 | })(NativeSelect); |
\ | No newline at end of file |