UNPKG

7.35 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _NativeSelectInput = _interopRequireDefault(require("./NativeSelectInput"));
21
22var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
23
24var _formControlState = _interopRequireDefault(require("../FormControl/formControlState"));
25
26var _useFormControl = _interopRequireDefault(require("../FormControl/useFormControl"));
27
28var _ArrowDropDown = _interopRequireDefault(require("../internal/svg-icons/ArrowDropDown"));
29
30var _Input = _interopRequireDefault(require("../Input"));
31
32var styles = function styles(theme) {
33 return {
34 /* Styles applied to the select component `root` class. */
35 root: {},
36
37 /* Styles applied to the select component `select` class. */
38 select: {
39 '-moz-appearance': 'none',
40 // Reset
41 '-webkit-appearance': 'none',
42 // Reset
43 // When interacting quickly, the text can end up selected.
44 // Native select can't be selected either.
45 userSelect: 'none',
46 borderRadius: 0,
47 // Reset
48 minWidth: 16,
49 // So it doesn't collapse.
50 cursor: 'pointer',
51 '&:focus': {
52 // Show that it's not an text input
53 backgroundColor: theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.05)' : 'rgba(255, 255, 255, 0.05)',
54 borderRadius: 0 // Reset Chrome style
55
56 },
57 // Remove IE 11 arrow
58 '&::-ms-expand': {
59 display: 'none'
60 },
61 '&$disabled': {
62 cursor: 'default'
63 },
64 '&[multiple]': {
65 height: 'auto'
66 },
67 '&:not([multiple]) option, &:not([multiple]) optgroup': {
68 backgroundColor: theme.palette.background.paper
69 },
70 '&&': {
71 paddingRight: 24
72 }
73 },
74
75 /* Styles applied to the select component if `variant="filled"`. */
76 filled: {
77 '&&': {
78 paddingRight: 32
79 }
80 },
81
82 /* Styles applied to the select component if `variant="outlined"`. */
83 outlined: {
84 borderRadius: theme.shape.borderRadius,
85 '&&': {
86 paddingRight: 32
87 }
88 },
89
90 /* Styles applied to the select component `selectMenu` class. */
91 selectMenu: {
92 height: 'auto',
93 // Resets for multpile select with chips
94 minHeight: '1.1876em',
95 // Required for select\text-field height consistency
96 textOverflow: 'ellipsis',
97 whiteSpace: 'nowrap',
98 overflow: 'hidden'
99 },
100
101 /* Pseudo-class applied to the select component `disabled` class. */
102 disabled: {},
103
104 /* Styles applied to the icon component. */
105 icon: {
106 // We use a position absolute over a flexbox in order to forward the pointer events
107 // to the input and to support wrapping tags..
108 position: 'absolute',
109 right: 0,
110 top: 'calc(50% - 12px)',
111 // Center vertically
112 pointerEvents: 'none',
113 // Don't block pointer events on the select under the icon.
114 color: theme.palette.action.active,
115 '&$disabled': {
116 color: theme.palette.action.disabled
117 }
118 },
119
120 /* Styles applied to the icon component if the popup is open. */
121 iconOpen: {
122 transform: 'rotate(180deg)'
123 },
124
125 /* Styles applied to the icon component if `variant="filled"`. */
126 iconFilled: {
127 right: 7
128 },
129
130 /* Styles applied to the icon component if `variant="outlined"`. */
131 iconOutlined: {
132 right: 7
133 },
134
135 /* Styles applied to the underlying native input component. */
136 nativeInput: {
137 bottom: 0,
138 left: 0,
139 position: 'absolute',
140 opacity: 0,
141 pointerEvents: 'none',
142 width: '100%'
143 }
144 };
145};
146
147exports.styles = styles;
148var defaultInput = /*#__PURE__*/React.createElement(_Input.default, null);
149/**
150 * An alternative to `<Select native />` with a much smaller bundle size footprint.
151 */
152
153var NativeSelect = /*#__PURE__*/React.forwardRef(function NativeSelect(props, ref) {
154 var children = props.children,
155 classes = props.classes,
156 _props$IconComponent = props.IconComponent,
157 IconComponent = _props$IconComponent === void 0 ? _ArrowDropDown.default : _props$IconComponent,
158 _props$input = props.input,
159 input = _props$input === void 0 ? defaultInput : _props$input,
160 inputProps = props.inputProps,
161 variant = props.variant,
162 other = (0, _objectWithoutProperties2.default)(props, ["children", "classes", "IconComponent", "input", "inputProps", "variant"]);
163 var muiFormControl = (0, _useFormControl.default)();
164 var fcs = (0, _formControlState.default)({
165 props: props,
166 muiFormControl: muiFormControl,
167 states: ['variant']
168 });
169 return /*#__PURE__*/React.cloneElement(input, (0, _extends2.default)({
170 // Most of the logic is implemented in `NativeSelectInput`.
171 // The `Select` component is a simple API wrapper to expose something better to play with.
172 inputComponent: _NativeSelectInput.default,
173 inputProps: (0, _extends2.default)({
174 children: children,
175 classes: classes,
176 IconComponent: IconComponent,
177 variant: fcs.variant,
178 type: undefined
179 }, inputProps, input ? input.props.inputProps : {}),
180 ref: ref
181 }, other));
182});
183process.env.NODE_ENV !== "production" ? NativeSelect.propTypes = {
184 // ----------------------------- Warning --------------------------------
185 // | These PropTypes are generated from the TypeScript type definitions |
186 // | To update them edit the d.ts file and run "yarn proptypes" |
187 // ----------------------------------------------------------------------
188
189 /**
190 * The option elements to populate the select with.
191 * Can be some `<option>` elements.
192 */
193 children: _propTypes.default.node,
194
195 /**
196 * Override or extend the styles applied to the component.
197 * See [CSS API](#css) below for more details.
198 */
199 classes: _propTypes.default.object,
200
201 /**
202 * The icon that displays the arrow.
203 */
204 IconComponent: _propTypes.default.elementType,
205
206 /**
207 * An `Input` element; does not have to be a material-ui specific `Input`.
208 */
209 input: _propTypes.default.element,
210
211 /**
212 * Attributes applied to the `select` element.
213 */
214 inputProps: _propTypes.default.object,
215
216 /**
217 * Callback function fired when a menu item is selected.
218 *
219 * @param {object} event The event source of the callback.
220 * You can pull out the new value by accessing `event.target.value` (string).
221 */
222 onChange: _propTypes.default.func,
223
224 /**
225 * The input value. The DOM API casts this to a string.
226 */
227 value: _propTypes.default.any,
228
229 /**
230 * The variant to use.
231 */
232 variant: _propTypes.default.oneOf(['filled', 'outlined', 'standard'])
233} : void 0;
234NativeSelect.muiName = 'Select';
235
236var _default = (0, _withStyles.default)(styles, {
237 name: 'MuiNativeSelect'
238})(NativeSelect);
239
240exports.default = _default;
\No newline at end of file