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 | const {
|
44 | slotProps = {},
|
45 | slots = {}
|
46 | } = props,
|
47 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
48 | const {
|
49 | getInputProps,
|
50 | checked,
|
51 | disabled,
|
52 | focusVisible,
|
53 | readOnly
|
54 | } = useSwitch(props);
|
55 | const ownerState = _extends({}, props, {
|
56 | checked,
|
57 | disabled,
|
58 | focusVisible,
|
59 | readOnly
|
60 | });
|
61 | const classes = useUtilityClasses(ownerState);
|
62 | const Root = slots.root ?? 'span';
|
63 | const rootProps = useSlotProps({
|
64 | elementType: Root,
|
65 | externalSlotProps: slotProps.root,
|
66 | externalForwardedProps: other,
|
67 | additionalProps: {
|
68 | ref: forwardedRef
|
69 | },
|
70 | ownerState,
|
71 | className: classes.root
|
72 | });
|
73 | const Thumb = slots.thumb ?? 'span';
|
74 | const thumbProps = useSlotProps({
|
75 | elementType: Thumb,
|
76 | externalSlotProps: slotProps.thumb,
|
77 | ownerState,
|
78 | className: classes.thumb
|
79 | });
|
80 | const Input = slots.input ?? 'input';
|
81 | const inputProps = useSlotProps({
|
82 | elementType: Input,
|
83 | getSlotProps: getInputProps,
|
84 | externalSlotProps: slotProps.input,
|
85 | ownerState,
|
86 | className: classes.input
|
87 | });
|
88 | const Track = slots.track === null ? () => null : slots.track ?? 'span';
|
89 | const trackProps = useSlotProps({
|
90 | elementType: Track,
|
91 | externalSlotProps: slotProps.track,
|
92 | ownerState,
|
93 | className: classes.track
|
94 | });
|
95 | return _jsxs(Root, _extends({}, rootProps, {
|
96 | children: [_jsx(Track, _extends({}, trackProps)), _jsx(Thumb, _extends({}, thumbProps)), _jsx(Input, _extends({}, inputProps))]
|
97 | }));
|
98 | });
|
99 | process.env.NODE_ENV !== "production" ? Switch.propTypes = {
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | |
105 |
|
106 |
|
107 | checked: PropTypes.bool,
|
108 | |
109 |
|
110 |
|
111 | className: PropTypes.string,
|
112 | |
113 |
|
114 |
|
115 | defaultChecked: PropTypes.bool,
|
116 | |
117 |
|
118 |
|
119 | disabled: PropTypes.bool,
|
120 | |
121 |
|
122 |
|
123 | onBlur: PropTypes.func,
|
124 | |
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 | onChange: PropTypes.func,
|
132 | |
133 |
|
134 |
|
135 | onFocus: PropTypes.func,
|
136 | |
137 |
|
138 |
|
139 | onFocusVisible: PropTypes.func,
|
140 | |
141 |
|
142 |
|
143 | readOnly: PropTypes.bool,
|
144 | |
145 |
|
146 |
|
147 | required: PropTypes.bool,
|
148 | |
149 |
|
150 |
|
151 |
|
152 | slotProps: PropTypes.shape({
|
153 | input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
154 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
155 | thumb: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
156 | track: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
157 | }),
|
158 | |
159 |
|
160 |
|
161 |
|
162 |
|
163 | slots: PropTypes .shape({
|
164 | input: PropTypes.elementType,
|
165 | root: PropTypes.elementType,
|
166 | thumb: PropTypes.elementType,
|
167 | track: PropTypes.oneOfType([PropTypes.elementType, PropTypes.oneOf([null])])
|
168 | })
|
169 | } : void 0;
|
170 | export { Switch }; |
\ | No newline at end of file |