1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import refType from '@mui/utils/refType';
|
7 | import composeClasses from '@mui/utils/composeClasses';
|
8 | import capitalize from "../utils/capitalize.js";
|
9 | import nativeSelectClasses, { getNativeSelectUtilityClasses } from "./nativeSelectClasses.js";
|
10 | import { styled } from "../zero-styled/index.js";
|
11 | import rootShouldForwardProp from "../styles/rootShouldForwardProp.js";
|
12 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
13 | const useUtilityClasses = ownerState => {
|
14 | const {
|
15 | classes,
|
16 | variant,
|
17 | disabled,
|
18 | multiple,
|
19 | open,
|
20 | error
|
21 | } = ownerState;
|
22 | const slots = {
|
23 | select: ['select', variant, disabled && 'disabled', multiple && 'multiple', error && 'error'],
|
24 | icon: ['icon', `icon${capitalize(variant)}`, open && 'iconOpen', disabled && 'disabled']
|
25 | };
|
26 | return composeClasses(slots, getNativeSelectUtilityClasses, classes);
|
27 | };
|
28 | export const StyledSelectSelect = styled('select')(({
|
29 | theme
|
30 | }) => ({
|
31 |
|
32 | MozAppearance: 'none',
|
33 |
|
34 | WebkitAppearance: 'none',
|
35 |
|
36 |
|
37 | userSelect: 'none',
|
38 |
|
39 | borderRadius: 0,
|
40 | cursor: 'pointer',
|
41 | '&:focus': {
|
42 |
|
43 | borderRadius: 0
|
44 | },
|
45 | [`&.${nativeSelectClasses.disabled}`]: {
|
46 | cursor: 'default'
|
47 | },
|
48 | '&[multiple]': {
|
49 | height: 'auto'
|
50 | },
|
51 | '&:not([multiple]) option, &:not([multiple]) optgroup': {
|
52 | backgroundColor: (theme.vars || theme).palette.background.paper
|
53 | },
|
54 | variants: [{
|
55 | props: ({
|
56 | ownerState
|
57 | }) => ownerState.variant !== 'filled' && ownerState.variant !== 'outlined',
|
58 | style: {
|
59 |
|
60 | '&&&': {
|
61 | paddingRight: 24,
|
62 | minWidth: 16
|
63 | }
|
64 | }
|
65 | }, {
|
66 | props: {
|
67 | variant: 'filled'
|
68 | },
|
69 | style: {
|
70 | '&&&': {
|
71 | paddingRight: 32
|
72 | }
|
73 | }
|
74 | }, {
|
75 | props: {
|
76 | variant: 'outlined'
|
77 | },
|
78 | style: {
|
79 | borderRadius: (theme.vars || theme).shape.borderRadius,
|
80 | '&:focus': {
|
81 | borderRadius: (theme.vars || theme).shape.borderRadius
|
82 | },
|
83 | '&&&': {
|
84 | paddingRight: 32
|
85 | }
|
86 | }
|
87 | }]
|
88 | }));
|
89 | const NativeSelectSelect = styled(StyledSelectSelect, {
|
90 | name: 'MuiNativeSelect',
|
91 | slot: 'Select',
|
92 | shouldForwardProp: rootShouldForwardProp,
|
93 | overridesResolver: (props, styles) => {
|
94 | const {
|
95 | ownerState
|
96 | } = props;
|
97 | return [styles.select, styles[ownerState.variant], ownerState.error && styles.error, {
|
98 | [`&.${nativeSelectClasses.multiple}`]: styles.multiple
|
99 | }];
|
100 | }
|
101 | })({});
|
102 | export const StyledSelectIcon = styled('svg')(({
|
103 | theme
|
104 | }) => ({
|
105 |
|
106 |
|
107 | position: 'absolute',
|
108 | right: 0,
|
109 |
|
110 | top: 'calc(50% - .5em)',
|
111 |
|
112 | pointerEvents: 'none',
|
113 | color: (theme.vars || theme).palette.action.active,
|
114 | [`&.${nativeSelectClasses.disabled}`]: {
|
115 | color: (theme.vars || theme).palette.action.disabled
|
116 | },
|
117 | variants: [{
|
118 | props: ({
|
119 | ownerState
|
120 | }) => ownerState.open,
|
121 | style: {
|
122 | transform: 'rotate(180deg)'
|
123 | }
|
124 | }, {
|
125 | props: {
|
126 | variant: 'filled'
|
127 | },
|
128 | style: {
|
129 | right: 7
|
130 | }
|
131 | }, {
|
132 | props: {
|
133 | variant: 'outlined'
|
134 | },
|
135 | style: {
|
136 | right: 7
|
137 | }
|
138 | }]
|
139 | }));
|
140 | const NativeSelectIcon = styled(StyledSelectIcon, {
|
141 | name: 'MuiNativeSelect',
|
142 | slot: 'Icon',
|
143 | overridesResolver: (props, styles) => {
|
144 | const {
|
145 | ownerState
|
146 | } = props;
|
147 | return [styles.icon, ownerState.variant && styles[`icon${capitalize(ownerState.variant)}`], ownerState.open && styles.iconOpen];
|
148 | }
|
149 | })({});
|
150 |
|
151 |
|
152 |
|
153 |
|
154 | const NativeSelectInput = React.forwardRef(function NativeSelectInput(props, ref) {
|
155 | const {
|
156 | className,
|
157 | disabled,
|
158 | error,
|
159 | IconComponent,
|
160 | inputRef,
|
161 | variant = 'standard',
|
162 | ...other
|
163 | } = props;
|
164 | const ownerState = {
|
165 | ...props,
|
166 | disabled,
|
167 | variant,
|
168 | error
|
169 | };
|
170 | const classes = useUtilityClasses(ownerState);
|
171 | return _jsxs(React.Fragment, {
|
172 | children: [_jsx(NativeSelectSelect, {
|
173 | ownerState: ownerState,
|
174 | className: clsx(classes.select, className),
|
175 | disabled: disabled,
|
176 | ref: inputRef || ref,
|
177 | ...other
|
178 | }), props.multiple ? null : _jsx(NativeSelectIcon, {
|
179 | as: IconComponent,
|
180 | ownerState: ownerState,
|
181 | className: classes.icon
|
182 | })]
|
183 | });
|
184 | });
|
185 | process.env.NODE_ENV !== "production" ? NativeSelectInput.propTypes = {
|
186 | |
187 |
|
188 |
|
189 |
|
190 | children: PropTypes.node,
|
191 | |
192 |
|
193 |
|
194 | classes: PropTypes.object,
|
195 | |
196 |
|
197 |
|
198 | className: PropTypes.string,
|
199 | |
200 |
|
201 |
|
202 | disabled: PropTypes.bool,
|
203 | |
204 |
|
205 |
|
206 | error: PropTypes.bool,
|
207 | |
208 |
|
209 |
|
210 | IconComponent: PropTypes.elementType.isRequired,
|
211 | |
212 |
|
213 |
|
214 |
|
215 | inputRef: refType,
|
216 | |
217 |
|
218 |
|
219 | multiple: PropTypes.bool,
|
220 | |
221 |
|
222 |
|
223 | name: PropTypes.string,
|
224 | |
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 | onChange: PropTypes.func,
|
231 | |
232 |
|
233 |
|
234 | value: PropTypes.any,
|
235 | |
236 |
|
237 |
|
238 | variant: PropTypes.oneOf(['standard', 'outlined', 'filled'])
|
239 | } : void 0;
|
240 | export default NativeSelectInput; |
\ | No newline at end of file |