1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | const _excluded = ["checked", "defaultChecked", "disabled", "onBlur", "onChange", "onFocus", "onFocusVisible", "readOnly", "required", "slotProps", "slots"];
|
4 | import * as React from 'react';
|
5 | import PropTypes from 'prop-types';
|
6 | import composeClasses from '../composeClasses';
|
7 | import useSwitch from '../useSwitch';
|
8 | import { useSlotProps } from '../utils';
|
9 | import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
10 | import { getSwitchUtilityClass } from './switchClasses';
|
11 | import { jsx as _jsx } from "react/jsx-runtime";
|
12 | import { jsxs as _jsxs } from "react/jsx-runtime";
|
13 | const useUtilityClasses = ownerState => {
|
14 | const {
|
15 | checked,
|
16 | disabled,
|
17 | focusVisible,
|
18 | readOnly
|
19 | } = ownerState;
|
20 | const slots = {
|
21 | root: ['root', checked && 'checked', disabled && 'disabled', focusVisible && 'focusVisible', readOnly && 'readOnly'],
|
22 | thumb: ['thumb'],
|
23 | input: ['input'],
|
24 | track: ['track']
|
25 | };
|
26 | return composeClasses(slots, useClassNamesOverride(getSwitchUtilityClass));
|
27 | };
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | const Switch = React.forwardRef(function Switch(props, forwardedRef) {
|
41 | var _slots$root, _slots$thumb, _slots$input, _slots$track;
|
42 | const {
|
43 | checked: checkedProp,
|
44 | defaultChecked,
|
45 | disabled: disabledProp,
|
46 | onBlur,
|
47 | onChange,
|
48 | onFocus,
|
49 | onFocusVisible,
|
50 | readOnly: readOnlyProp,
|
51 | slotProps = {},
|
52 | slots = {}
|
53 | } = props,
|
54 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
55 | const useSwitchProps = {
|
56 | checked: checkedProp,
|
57 | defaultChecked,
|
58 | disabled: disabledProp,
|
59 | onBlur,
|
60 | onChange,
|
61 | onFocus,
|
62 | onFocusVisible,
|
63 | readOnly: readOnlyProp
|
64 | };
|
65 | const {
|
66 | getInputProps,
|
67 | checked,
|
68 | disabled,
|
69 | focusVisible,
|
70 | readOnly
|
71 | } = useSwitch(useSwitchProps);
|
72 | const ownerState = _extends({}, props, {
|
73 | checked,
|
74 | disabled,
|
75 | focusVisible,
|
76 | readOnly
|
77 | });
|
78 | const classes = useUtilityClasses(ownerState);
|
79 | const Root = (_slots$root = slots.root) != null ? _slots$root : 'span';
|
80 | const rootProps = useSlotProps({
|
81 | elementType: Root,
|
82 | externalSlotProps: slotProps.root,
|
83 | externalForwardedProps: other,
|
84 | additionalProps: {
|
85 | ref: forwardedRef
|
86 | },
|
87 | ownerState,
|
88 | className: classes.root
|
89 | });
|
90 | const Thumb = (_slots$thumb = slots.thumb) != null ? _slots$thumb : 'span';
|
91 | const thumbProps = useSlotProps({
|
92 | elementType: Thumb,
|
93 | externalSlotProps: slotProps.thumb,
|
94 | ownerState,
|
95 | className: classes.thumb
|
96 | });
|
97 | const Input = (_slots$input = slots.input) != null ? _slots$input : 'input';
|
98 | const inputProps = useSlotProps({
|
99 | elementType: Input,
|
100 | getSlotProps: getInputProps,
|
101 | externalSlotProps: slotProps.input,
|
102 | ownerState,
|
103 | className: classes.input
|
104 | });
|
105 | const Track = slots.track === null ? () => null : (_slots$track = slots.track) != null ? _slots$track : 'span';
|
106 | const trackProps = useSlotProps({
|
107 | elementType: Track,
|
108 | externalSlotProps: slotProps.track,
|
109 | ownerState,
|
110 | className: classes.track
|
111 | });
|
112 | return _jsxs(Root, _extends({}, rootProps, {
|
113 | children: [_jsx(Track, _extends({}, trackProps)), _jsx(Thumb, _extends({}, thumbProps)), _jsx(Input, _extends({}, inputProps))]
|
114 | }));
|
115 | });
|
116 | process.env.NODE_ENV !== "production" ? Switch.propTypes = {
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | |
122 |
|
123 |
|
124 | checked: PropTypes.bool,
|
125 | |
126 |
|
127 |
|
128 | defaultChecked: PropTypes.bool,
|
129 | |
130 |
|
131 |
|
132 | disabled: PropTypes.bool,
|
133 | |
134 |
|
135 |
|
136 | onBlur: PropTypes.func,
|
137 | |
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 | onChange: PropTypes.func,
|
145 | |
146 |
|
147 |
|
148 | onFocus: PropTypes.func,
|
149 | |
150 |
|
151 |
|
152 | onFocusVisible: PropTypes.func,
|
153 | |
154 |
|
155 |
|
156 | readOnly: PropTypes.bool,
|
157 | |
158 |
|
159 |
|
160 | required: PropTypes.bool,
|
161 | |
162 |
|
163 |
|
164 |
|
165 | slotProps: PropTypes.shape({
|
166 | input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
167 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
168 | thumb: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
169 | track: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
170 | }),
|
171 | |
172 |
|
173 |
|
174 |
|
175 |
|
176 | slots: PropTypes .shape({
|
177 | input: PropTypes.elementType,
|
178 | root: PropTypes.elementType,
|
179 | thumb: PropTypes.elementType,
|
180 | track: PropTypes.oneOfType([PropTypes.elementType, PropTypes.oneOf([null])])
|
181 | })
|
182 | } : void 0;
|
183 | export default Switch; |
\ | No newline at end of file |