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