@tamagui/switch 1.0.1-beta.151 → 1.0.1-beta.152
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Switch.js +110 -91
- package/dist/cjs/Switch.js.map +1 -1
- package/dist/esm/Switch.js +106 -90
- package/dist/esm/Switch.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/jsx/Switch.js +65 -54
- package/dist/jsx/Switch.js.map +1 -1
- package/dist/jsx/index.js.map +1 -1
- package/package.json +9 -9
package/dist/cjs/Switch.js
CHANGED
|
@@ -17,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
21
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
25
|
var Switch_exports = {};
|
|
23
26
|
__export(Switch_exports, {
|
|
@@ -28,6 +31,7 @@ __export(Switch_exports, {
|
|
|
28
31
|
createSwitchScope: () => createSwitchScope
|
|
29
32
|
});
|
|
30
33
|
module.exports = __toCommonJS(Switch_exports);
|
|
34
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
35
|
var import_react_use_previous = require("@radix-ui/react-use-previous");
|
|
32
36
|
var import_compose_refs = require("@tamagui/compose-refs");
|
|
33
37
|
var import_core = require("@tamagui/core");
|
|
@@ -61,18 +65,22 @@ const SwitchThumbFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
|
61
65
|
size: "$4"
|
|
62
66
|
}
|
|
63
67
|
});
|
|
64
|
-
const SwitchThumb = SwitchThumbFrame.extractable(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
const SwitchThumb = SwitchThumbFrame.extractable(
|
|
69
|
+
React.forwardRef(
|
|
70
|
+
(props, forwardedRef) => {
|
|
71
|
+
const { __scopeSwitch, ...thumbProps } = props;
|
|
72
|
+
const { size, disabled, checked } = useSwitchContext(THUMB_NAME, __scopeSwitch);
|
|
73
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SwitchThumbFrame, {
|
|
74
|
+
size,
|
|
75
|
+
"data-state": getState(checked),
|
|
76
|
+
"data-disabled": disabled ? "" : void 0,
|
|
77
|
+
...thumbProps,
|
|
78
|
+
x: checked ? (0, import_core.getVariableValue)(getSwitchWidth(size)) - (0, import_core.getVariableValue)(getSwitchHeight(size)) : 0,
|
|
79
|
+
ref: forwardedRef
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
);
|
|
76
84
|
SwitchThumb.displayName = THUMB_NAME;
|
|
77
85
|
const SwitchFrame = (0, import_core.styled)(import_stacks.XStack, {
|
|
78
86
|
name: "Switch",
|
|
@@ -101,85 +109,96 @@ const SwitchFrame = (0, import_core.styled)(import_stacks.XStack, {
|
|
|
101
109
|
size: "$4"
|
|
102
110
|
}
|
|
103
111
|
});
|
|
104
|
-
const Switch = (0, import_core.withStaticProperties)(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
112
|
+
const Switch = (0, import_core.withStaticProperties)(
|
|
113
|
+
SwitchFrame.extractable(
|
|
114
|
+
React.forwardRef(
|
|
115
|
+
(props, forwardedRef) => {
|
|
116
|
+
const {
|
|
117
|
+
__scopeSwitch,
|
|
118
|
+
labeledBy: ariaLabelledby,
|
|
119
|
+
name,
|
|
120
|
+
checked: checkedProp,
|
|
121
|
+
defaultChecked,
|
|
122
|
+
required,
|
|
123
|
+
disabled,
|
|
124
|
+
value = "on",
|
|
125
|
+
onCheckedChange,
|
|
126
|
+
size = "$4",
|
|
127
|
+
...switchProps
|
|
128
|
+
} = props;
|
|
129
|
+
const [button, setButton] = React.useState(null);
|
|
130
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, (node) => setButton(node));
|
|
131
|
+
const labelId = (0, import_label.useLabelContext)(button);
|
|
132
|
+
const labelledBy = ariaLabelledby || labelId;
|
|
133
|
+
const hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
134
|
+
const isFormControl = import_core.isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
135
|
+
const [checked = false, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
136
|
+
prop: checkedProp,
|
|
137
|
+
defaultProp: defaultChecked || false,
|
|
138
|
+
onChange: onCheckedChange
|
|
139
|
+
});
|
|
140
|
+
if (!import_core.isWeb) {
|
|
141
|
+
React.useEffect(() => {
|
|
142
|
+
if (!props.id)
|
|
143
|
+
return;
|
|
144
|
+
return (0, import_focusable.registerFocusable)(props.id, {
|
|
145
|
+
focus: () => {
|
|
146
|
+
setChecked((x) => !x);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}, [props.id, setChecked]);
|
|
136
150
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
151
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(SwitchProvider, {
|
|
152
|
+
scope: __scopeSwitch,
|
|
153
|
+
checked,
|
|
154
|
+
disabled,
|
|
155
|
+
size,
|
|
156
|
+
children: [
|
|
157
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SwitchFrame, {
|
|
158
|
+
size,
|
|
159
|
+
role: "switch",
|
|
160
|
+
"aria-checked": checked,
|
|
161
|
+
"aria-labelledby": labelledBy,
|
|
162
|
+
"aria-required": required,
|
|
163
|
+
"data-state": getState(checked),
|
|
164
|
+
"data-disabled": disabled ? "" : void 0,
|
|
165
|
+
disabled,
|
|
166
|
+
theme: checked ? "active" : null,
|
|
167
|
+
themeShallow: true,
|
|
168
|
+
tabIndex: disabled ? void 0 : 0,
|
|
169
|
+
value,
|
|
170
|
+
...switchProps,
|
|
171
|
+
ref: composedRefs,
|
|
172
|
+
onPress: (event) => {
|
|
173
|
+
var _a;
|
|
174
|
+
(_a = props.onPress) == null ? void 0 : _a.call(props, event);
|
|
175
|
+
setChecked((prevChecked) => !prevChecked);
|
|
176
|
+
if (import_core.isWeb && isFormControl) {
|
|
177
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
178
|
+
if (!hasConsumerStoppedPropagationRef.current)
|
|
179
|
+
event.stopPropagation();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}),
|
|
183
|
+
import_core.isWeb && isFormControl && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BubbleInput, {
|
|
184
|
+
control: button,
|
|
185
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
186
|
+
name,
|
|
187
|
+
value,
|
|
188
|
+
checked,
|
|
189
|
+
required,
|
|
190
|
+
disabled,
|
|
191
|
+
style: { transform: "translateX(-100%)" }
|
|
192
|
+
})
|
|
193
|
+
]
|
|
194
|
+
});
|
|
168
195
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
checked,
|
|
176
|
-
required,
|
|
177
|
-
disabled,
|
|
178
|
-
style: { transform: "translateX(-100%)" }
|
|
179
|
-
}));
|
|
180
|
-
})), {
|
|
181
|
-
Thumb: SwitchThumb
|
|
182
|
-
});
|
|
196
|
+
)
|
|
197
|
+
),
|
|
198
|
+
{
|
|
199
|
+
Thumb: SwitchThumb
|
|
200
|
+
}
|
|
201
|
+
);
|
|
183
202
|
const BubbleInput = (props) => {
|
|
184
203
|
const { control, checked, bubbles = true, ...inputProps } = props;
|
|
185
204
|
const ref = React.useRef(null);
|
|
@@ -195,7 +214,7 @@ const BubbleInput = (props) => {
|
|
|
195
214
|
input.dispatchEvent(event);
|
|
196
215
|
}
|
|
197
216
|
}, [prevChecked, checked, bubbles]);
|
|
198
|
-
return /* @__PURE__ */
|
|
217
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
199
218
|
type: "checkbox",
|
|
200
219
|
"aria-hidden": true,
|
|
201
220
|
defaultChecked: checked,
|
package/dist/cjs/Switch.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Switch.tsx"],
|
|
4
4
|
"sourcesContent": ["// via radix\n// https://github.com/radix-ui/primitives/blob/main/packages/react/switch/src/Switch.tsx\n\nimport { usePrevious } from '@radix-ui/react-use-previous'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n SizeTokens,\n calc,\n getSize,\n getVariableValue,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { registerFocusable } from '@tamagui/focusable'\nimport { useLabelContext } from '@tamagui/label'\nimport { ThemeableStack, XStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst SWITCH_NAME = 'Switch'\n\n// TODO make customizable\nconst getSwitchHeight = (val: SizeTokens) => Math.round(getVariableValue(getSize(val)) * 0.65)\nconst getSwitchWidth = (val: SizeTokens) => getSwitchHeight(val) * 2\n\nconst scopeContexts = createContextScope(SWITCH_NAME)\nconst [createSwitchContext] = scopeContexts\nexport const createSwitchScope = scopeContexts[1]\n\nconst [SwitchProvider, useSwitchContext] = createSwitchContext<{\n checked: boolean\n disabled?: boolean\n size: SizeTokens\n}>(SWITCH_NAME)\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb'\n\nexport const SwitchThumbFrame = styled(ThemeableStack, {\n name: 'SwitchThumb',\n backgroundColor: '$background',\n borderRadius: 1000,\n\n variants: {\n size: {\n '...size': (val) => ({\n height: getSwitchHeight(val),\n width: getSwitchHeight(val),\n }),\n },\n },\n\n defaultVariants: {\n size: '$4',\n },\n})\n\nexport type SwitchThumbProps = GetProps<typeof SwitchThumbFrame>\n\nexport const SwitchThumb = SwitchThumbFrame.extractable(\n React.forwardRef<React.ElementRef<'span'>, SwitchThumbProps>(\n (props: ScopedProps<SwitchThumbProps, 'Switch'>, forwardedRef) => {\n const { __scopeSwitch, ...thumbProps } = props\n const { size, disabled, checked } = useSwitchContext(THUMB_NAME, __scopeSwitch)\n return (\n <SwitchThumbFrame\n size={size}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n {...thumbProps}\n x={\n checked\n ? getVariableValue(getSwitchWidth(size)) - getVariableValue(getSwitchHeight(size))\n : 0\n }\n ref={forwardedRef}\n />\n )\n }\n )\n)\n\nSwitchThumb.displayName = THUMB_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Switch\n * -----------------------------------------------------------------------------------------------*/\n\nexport const SwitchFrame = styled(XStack, {\n name: 'Switch',\n tag: 'button',\n borderRadius: 1000,\n borderWidth: 2,\n borderColor: 'transparent',\n backgroundColor: '$background',\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n\n variants: {\n size: {\n '...size': (val) => {\n const height = calc(getSwitchHeight(val), '+', 4)\n const width = calc(getSwitchWidth(val), '+', 4)\n return {\n height,\n minHeight: height,\n width,\n }\n },\n },\n },\n\n defaultVariants: {\n size: '$4',\n },\n})\n\ntype SwitchButtonProps = GetProps<typeof SwitchFrame>\n\nexport type SwitchProps = SwitchButtonProps & {\n labeledBy?: string\n name?: string\n value?: string\n checked?: boolean\n defaultChecked?: boolean\n required?: boolean\n onCheckedChange?(checked: boolean): void\n}\n\nexport const Switch = withStaticProperties(\n SwitchFrame.extractable(\n React.forwardRef<HTMLButtonElement | View, SwitchProps>(\n (props: ScopedProps<SwitchProps, 'Switch'>, forwardedRef) => {\n const {\n __scopeSwitch,\n labeledBy: ariaLabelledby,\n name,\n checked: checkedProp,\n defaultChecked,\n required,\n disabled,\n value = 'on',\n onCheckedChange,\n size = '$4',\n ...switchProps\n } = props\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node as any))\n const labelId = useLabelContext(button)\n const labelledBy = ariaLabelledby || labelId\n const hasConsumerStoppedPropagationRef = React.useRef(false)\n // We set this to true by default so that events bubble to forms without JS (SSR)\n const isFormControl = isWeb ? (button ? Boolean(button.closest('form')) : true) : false\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n })\n\n if (!isWeb) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (!props.id) return\n return registerFocusable(props.id, {\n focus: () => {\n setChecked((x) => !x)\n },\n })\n }, [props.id, setChecked])\n }\n\n return (\n <SwitchProvider scope={__scopeSwitch} checked={checked} disabled={disabled} size={size}>\n <SwitchFrame\n size={size}\n // @ts-ignore\n role=\"switch\"\n aria-checked={checked}\n aria-labelledby={labelledBy}\n aria-required={required}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n disabled={disabled}\n theme={checked ? 'active' : null}\n themeShallow\n // @ts-ignore\n tabIndex={disabled ? undefined : 0}\n // @ts-ignore\n value={value}\n {...switchProps}\n ref={composedRefs}\n onPress={(event) => {\n props.onPress?.(event)\n setChecked((prevChecked) => !prevChecked)\n if (isWeb && isFormControl) {\n hasConsumerStoppedPropagationRef.current = event.isPropagationStopped()\n // if switch is in a form, stop propagation from the button so that we only propagate\n // one click event (from the input). We propagate changes from an input so that native\n // form validation works and form events reflect switch updates.\n if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation()\n }\n }}\n />\n {isWeb && isFormControl && (\n <BubbleInput\n control={button}\n bubbles={!hasConsumerStoppedPropagationRef.current}\n name={name}\n value={value}\n checked={checked}\n required={required}\n disabled={disabled}\n // We transform because the input is absolutely positioned but we have\n // rendered it **after** the button. This pulls it back to sit on top\n // of the button.\n style={{ transform: 'translateX(-100%)' }}\n />\n )}\n </SwitchProvider>\n )\n }\n )\n ),\n {\n Thumb: SwitchThumb,\n }\n)\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype InputProps = any //Radix.ComponentPropsWithoutRef<'input'>\ninterface BubbleInputProps extends Omit<InputProps, 'checked'> {\n checked: boolean\n control: HTMLElement | null\n bubbles: boolean\n}\n\n// TODO make this native friendly\nconst BubbleInput = (props: BubbleInputProps) => {\n const { control, checked, bubbles = true, ...inputProps } = props\n const ref = React.useRef<HTMLInputElement>(null)\n const prevChecked = usePrevious(checked)\n // const controlSize = useSize(control)\n\n // Bubble checked change to parents (e.g form change event)\n React.useEffect(() => {\n const input = ref.current!\n const inputProto = window.HTMLInputElement.prototype\n const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked') as PropertyDescriptor\n const setChecked = descriptor.set\n if (prevChecked !== checked && setChecked) {\n const event = new Event('click', { bubbles })\n setChecked.call(input, checked)\n input.dispatchEvent(event)\n }\n }, [prevChecked, checked, bubbles])\n\n return (\n <input\n type=\"checkbox\"\n aria-hidden\n defaultChecked={checked}\n {...inputProps}\n tabIndex={-1}\n ref={ref}\n style={{\n ...props.style,\n // ...controlSize,\n position: 'absolute',\n pointerEvents: 'none',\n opacity: 0,\n margin: 0,\n }}\n />\n )\n}\n\nfunction getState(checked: boolean) {\n return checked ? 'checked' : 'unchecked'\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwEQ;AArER,gCAA4B;AAC5B,0BAAgC;AAChC,kBASO;AACP,4BAAgD;AAChD,uBAAkC;AAClC,mBAAgC;AAChC,oBAAuC;AACvC,oCAAqC;AACrC,YAAuB;AAGvB,MAAM,cAAc;AAGpB,MAAM,kBAAkB,CAAC,QAAoB,KAAK,UAAM,kCAAiB,qBAAQ,GAAG,CAAC,IAAI,IAAI;AAC7F,MAAM,iBAAiB,CAAC,QAAoB,gBAAgB,GAAG,IAAI;AAEnE,MAAM,oBAAgB,0CAAmB,WAAW;AACpD,MAAM,CAAC,mBAAmB,IAAI;AACvB,MAAM,oBAAoB,cAAc;AAE/C,MAAM,CAAC,gBAAgB,gBAAgB,IAAI,oBAIxC,WAAW;AAMd,MAAM,aAAa;AAEZ,MAAM,uBAAmB,oBAAO,8BAAgB;AAAA,EACrD,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,cAAc;AAAA,EAEd,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,WAAW,CAAC,SAAS;AAAA,QAC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A,MAET,UAAU;AAAA,MACV,eAAe;AAAA,MACf,SAAS;AAAA,MACT,QAAQ;AAAA,IACV;AAAA,GACF;AAEJ;AAEA,SAAS,SAAS,SAAkB;AAClC,SAAO,UAAU,YAAY;AAC/B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/Switch.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
1
2
|
import { usePrevious } from "@radix-ui/react-use-previous";
|
|
2
3
|
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
3
4
|
import {
|
|
@@ -38,18 +39,22 @@ const SwitchThumbFrame = styled(ThemeableStack, {
|
|
|
38
39
|
size: "$4"
|
|
39
40
|
}
|
|
40
41
|
});
|
|
41
|
-
const SwitchThumb = SwitchThumbFrame.extractable(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
const SwitchThumb = SwitchThumbFrame.extractable(
|
|
43
|
+
React.forwardRef(
|
|
44
|
+
(props, forwardedRef) => {
|
|
45
|
+
const { __scopeSwitch, ...thumbProps } = props;
|
|
46
|
+
const { size, disabled, checked } = useSwitchContext(THUMB_NAME, __scopeSwitch);
|
|
47
|
+
return /* @__PURE__ */ jsx(SwitchThumbFrame, {
|
|
48
|
+
size,
|
|
49
|
+
"data-state": getState(checked),
|
|
50
|
+
"data-disabled": disabled ? "" : void 0,
|
|
51
|
+
...thumbProps,
|
|
52
|
+
x: checked ? getVariableValue(getSwitchWidth(size)) - getVariableValue(getSwitchHeight(size)) : 0,
|
|
53
|
+
ref: forwardedRef
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
);
|
|
53
58
|
SwitchThumb.displayName = THUMB_NAME;
|
|
54
59
|
const SwitchFrame = styled(XStack, {
|
|
55
60
|
name: "Switch",
|
|
@@ -78,85 +83,96 @@ const SwitchFrame = styled(XStack, {
|
|
|
78
83
|
size: "$4"
|
|
79
84
|
}
|
|
80
85
|
});
|
|
81
|
-
const Switch = withStaticProperties(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
86
|
+
const Switch = withStaticProperties(
|
|
87
|
+
SwitchFrame.extractable(
|
|
88
|
+
React.forwardRef(
|
|
89
|
+
(props, forwardedRef) => {
|
|
90
|
+
const {
|
|
91
|
+
__scopeSwitch,
|
|
92
|
+
labeledBy: ariaLabelledby,
|
|
93
|
+
name,
|
|
94
|
+
checked: checkedProp,
|
|
95
|
+
defaultChecked,
|
|
96
|
+
required,
|
|
97
|
+
disabled,
|
|
98
|
+
value = "on",
|
|
99
|
+
onCheckedChange,
|
|
100
|
+
size = "$4",
|
|
101
|
+
...switchProps
|
|
102
|
+
} = props;
|
|
103
|
+
const [button, setButton] = React.useState(null);
|
|
104
|
+
const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node));
|
|
105
|
+
const labelId = useLabelContext(button);
|
|
106
|
+
const labelledBy = ariaLabelledby || labelId;
|
|
107
|
+
const hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
108
|
+
const isFormControl = isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
109
|
+
const [checked = false, setChecked] = useControllableState({
|
|
110
|
+
prop: checkedProp,
|
|
111
|
+
defaultProp: defaultChecked || false,
|
|
112
|
+
onChange: onCheckedChange
|
|
113
|
+
});
|
|
114
|
+
if (!isWeb) {
|
|
115
|
+
React.useEffect(() => {
|
|
116
|
+
if (!props.id)
|
|
117
|
+
return;
|
|
118
|
+
return registerFocusable(props.id, {
|
|
119
|
+
focus: () => {
|
|
120
|
+
setChecked((x) => !x);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}, [props.id, setChecked]);
|
|
113
124
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
125
|
+
return /* @__PURE__ */ jsxs(SwitchProvider, {
|
|
126
|
+
scope: __scopeSwitch,
|
|
127
|
+
checked,
|
|
128
|
+
disabled,
|
|
129
|
+
size,
|
|
130
|
+
children: [
|
|
131
|
+
/* @__PURE__ */ jsx(SwitchFrame, {
|
|
132
|
+
size,
|
|
133
|
+
role: "switch",
|
|
134
|
+
"aria-checked": checked,
|
|
135
|
+
"aria-labelledby": labelledBy,
|
|
136
|
+
"aria-required": required,
|
|
137
|
+
"data-state": getState(checked),
|
|
138
|
+
"data-disabled": disabled ? "" : void 0,
|
|
139
|
+
disabled,
|
|
140
|
+
theme: checked ? "active" : null,
|
|
141
|
+
themeShallow: true,
|
|
142
|
+
tabIndex: disabled ? void 0 : 0,
|
|
143
|
+
value,
|
|
144
|
+
...switchProps,
|
|
145
|
+
ref: composedRefs,
|
|
146
|
+
onPress: (event) => {
|
|
147
|
+
var _a;
|
|
148
|
+
(_a = props.onPress) == null ? void 0 : _a.call(props, event);
|
|
149
|
+
setChecked((prevChecked) => !prevChecked);
|
|
150
|
+
if (isWeb && isFormControl) {
|
|
151
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
152
|
+
if (!hasConsumerStoppedPropagationRef.current)
|
|
153
|
+
event.stopPropagation();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}),
|
|
157
|
+
isWeb && isFormControl && /* @__PURE__ */ jsx(BubbleInput, {
|
|
158
|
+
control: button,
|
|
159
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
160
|
+
name,
|
|
161
|
+
value,
|
|
162
|
+
checked,
|
|
163
|
+
required,
|
|
164
|
+
disabled,
|
|
165
|
+
style: { transform: "translateX(-100%)" }
|
|
166
|
+
})
|
|
167
|
+
]
|
|
168
|
+
});
|
|
145
169
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
checked,
|
|
153
|
-
required,
|
|
154
|
-
disabled,
|
|
155
|
-
style: { transform: "translateX(-100%)" }
|
|
156
|
-
}));
|
|
157
|
-
})), {
|
|
158
|
-
Thumb: SwitchThumb
|
|
159
|
-
});
|
|
170
|
+
)
|
|
171
|
+
),
|
|
172
|
+
{
|
|
173
|
+
Thumb: SwitchThumb
|
|
174
|
+
}
|
|
175
|
+
);
|
|
160
176
|
const BubbleInput = (props) => {
|
|
161
177
|
const { control, checked, bubbles = true, ...inputProps } = props;
|
|
162
178
|
const ref = React.useRef(null);
|
|
@@ -172,7 +188,7 @@ const BubbleInput = (props) => {
|
|
|
172
188
|
input.dispatchEvent(event);
|
|
173
189
|
}
|
|
174
190
|
}, [prevChecked, checked, bubbles]);
|
|
175
|
-
return /* @__PURE__ */
|
|
191
|
+
return /* @__PURE__ */ jsx("input", {
|
|
176
192
|
type: "checkbox",
|
|
177
193
|
"aria-hidden": true,
|
|
178
194
|
defaultChecked: checked,
|
package/dist/esm/Switch.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Switch.tsx"],
|
|
4
4
|
"sourcesContent": ["// via radix\n// https://github.com/radix-ui/primitives/blob/main/packages/react/switch/src/Switch.tsx\n\nimport { usePrevious } from '@radix-ui/react-use-previous'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n SizeTokens,\n calc,\n getSize,\n getVariableValue,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { registerFocusable } from '@tamagui/focusable'\nimport { useLabelContext } from '@tamagui/label'\nimport { ThemeableStack, XStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst SWITCH_NAME = 'Switch'\n\n// TODO make customizable\nconst getSwitchHeight = (val: SizeTokens) => Math.round(getVariableValue(getSize(val)) * 0.65)\nconst getSwitchWidth = (val: SizeTokens) => getSwitchHeight(val) * 2\n\nconst scopeContexts = createContextScope(SWITCH_NAME)\nconst [createSwitchContext] = scopeContexts\nexport const createSwitchScope = scopeContexts[1]\n\nconst [SwitchProvider, useSwitchContext] = createSwitchContext<{\n checked: boolean\n disabled?: boolean\n size: SizeTokens\n}>(SWITCH_NAME)\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb'\n\nexport const SwitchThumbFrame = styled(ThemeableStack, {\n name: 'SwitchThumb',\n backgroundColor: '$background',\n borderRadius: 1000,\n\n variants: {\n size: {\n '...size': (val) => ({\n height: getSwitchHeight(val),\n width: getSwitchHeight(val),\n }),\n },\n },\n\n defaultVariants: {\n size: '$4',\n },\n})\n\nexport type SwitchThumbProps = GetProps<typeof SwitchThumbFrame>\n\nexport const SwitchThumb = SwitchThumbFrame.extractable(\n React.forwardRef<React.ElementRef<'span'>, SwitchThumbProps>(\n (props: ScopedProps<SwitchThumbProps, 'Switch'>, forwardedRef) => {\n const { __scopeSwitch, ...thumbProps } = props\n const { size, disabled, checked } = useSwitchContext(THUMB_NAME, __scopeSwitch)\n return (\n <SwitchThumbFrame\n size={size}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n {...thumbProps}\n x={\n checked\n ? getVariableValue(getSwitchWidth(size)) - getVariableValue(getSwitchHeight(size))\n : 0\n }\n ref={forwardedRef}\n />\n )\n }\n )\n)\n\nSwitchThumb.displayName = THUMB_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Switch\n * -----------------------------------------------------------------------------------------------*/\n\nexport const SwitchFrame = styled(XStack, {\n name: 'Switch',\n tag: 'button',\n borderRadius: 1000,\n borderWidth: 2,\n borderColor: 'transparent',\n backgroundColor: '$background',\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n\n variants: {\n size: {\n '...size': (val) => {\n const height = calc(getSwitchHeight(val), '+', 4)\n const width = calc(getSwitchWidth(val), '+', 4)\n return {\n height,\n minHeight: height,\n width,\n }\n },\n },\n },\n\n defaultVariants: {\n size: '$4',\n },\n})\n\ntype SwitchButtonProps = GetProps<typeof SwitchFrame>\n\nexport type SwitchProps = SwitchButtonProps & {\n labeledBy?: string\n name?: string\n value?: string\n checked?: boolean\n defaultChecked?: boolean\n required?: boolean\n onCheckedChange?(checked: boolean): void\n}\n\nexport const Switch = withStaticProperties(\n SwitchFrame.extractable(\n React.forwardRef<HTMLButtonElement | View, SwitchProps>(\n (props: ScopedProps<SwitchProps, 'Switch'>, forwardedRef) => {\n const {\n __scopeSwitch,\n labeledBy: ariaLabelledby,\n name,\n checked: checkedProp,\n defaultChecked,\n required,\n disabled,\n value = 'on',\n onCheckedChange,\n size = '$4',\n ...switchProps\n } = props\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node as any))\n const labelId = useLabelContext(button)\n const labelledBy = ariaLabelledby || labelId\n const hasConsumerStoppedPropagationRef = React.useRef(false)\n // We set this to true by default so that events bubble to forms without JS (SSR)\n const isFormControl = isWeb ? (button ? Boolean(button.closest('form')) : true) : false\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n })\n\n if (!isWeb) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (!props.id) return\n return registerFocusable(props.id, {\n focus: () => {\n setChecked((x) => !x)\n },\n })\n }, [props.id, setChecked])\n }\n\n return (\n <SwitchProvider scope={__scopeSwitch} checked={checked} disabled={disabled} size={size}>\n <SwitchFrame\n size={size}\n // @ts-ignore\n role=\"switch\"\n aria-checked={checked}\n aria-labelledby={labelledBy}\n aria-required={required}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n disabled={disabled}\n theme={checked ? 'active' : null}\n themeShallow\n // @ts-ignore\n tabIndex={disabled ? undefined : 0}\n // @ts-ignore\n value={value}\n {...switchProps}\n ref={composedRefs}\n onPress={(event) => {\n props.onPress?.(event)\n setChecked((prevChecked) => !prevChecked)\n if (isWeb && isFormControl) {\n hasConsumerStoppedPropagationRef.current = event.isPropagationStopped()\n // if switch is in a form, stop propagation from the button so that we only propagate\n // one click event (from the input). We propagate changes from an input so that native\n // form validation works and form events reflect switch updates.\n if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation()\n }\n }}\n />\n {isWeb && isFormControl && (\n <BubbleInput\n control={button}\n bubbles={!hasConsumerStoppedPropagationRef.current}\n name={name}\n value={value}\n checked={checked}\n required={required}\n disabled={disabled}\n // We transform because the input is absolutely positioned but we have\n // rendered it **after** the button. This pulls it back to sit on top\n // of the button.\n style={{ transform: 'translateX(-100%)' }}\n />\n )}\n </SwitchProvider>\n )\n }\n )\n ),\n {\n Thumb: SwitchThumb,\n }\n)\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype InputProps = any //Radix.ComponentPropsWithoutRef<'input'>\ninterface BubbleInputProps extends Omit<InputProps, 'checked'> {\n checked: boolean\n control: HTMLElement | null\n bubbles: boolean\n}\n\n// TODO make this native friendly\nconst BubbleInput = (props: BubbleInputProps) => {\n const { control, checked, bubbles = true, ...inputProps } = props\n const ref = React.useRef<HTMLInputElement>(null)\n const prevChecked = usePrevious(checked)\n // const controlSize = useSize(control)\n\n // Bubble checked change to parents (e.g form change event)\n React.useEffect(() => {\n const input = ref.current!\n const inputProto = window.HTMLInputElement.prototype\n const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked') as PropertyDescriptor\n const setChecked = descriptor.set\n if (prevChecked !== checked && setChecked) {\n const event = new Event('click', { bubbles })\n setChecked.call(input, checked)\n input.dispatchEvent(event)\n }\n }, [prevChecked, checked, bubbles])\n\n return (\n <input\n type=\"checkbox\"\n aria-hidden\n defaultChecked={checked}\n {...inputProps}\n tabIndex={-1}\n ref={ref}\n style={{\n ...props.style,\n // ...controlSize,\n position: 'absolute',\n pointerEvents: 'none',\n opacity: 0,\n margin: 0,\n }}\n />\n )\n}\n\nfunction getState(checked: boolean) {\n return checked ? 'checked' : 'unchecked'\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": "AAwEQ,cA6GE,YA7GF;AArER,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAsB,0BAA0B;AAChD,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,cAAc;AACvC,SAAS,4BAA4B;AACrC,YAAY,WAAW;AAGvB,MAAM,cAAc;AAGpB,MAAM,kBAAkB,CAAC,QAAoB,KAAK,MAAM,iBAAiB,QAAQ,GAAG,CAAC,IAAI,IAAI;AAC7F,MAAM,iBAAiB,CAAC,QAAoB,gBAAgB,GAAG,IAAI;AAEnE,MAAM,gBAAgB,mBAAmB,WAAW;A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AAC;AAC5C,iBAAW,KAAK,OAAO,OAAO;AAC9B,YAAM,cAAc,KAAK;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,aAAa,SAAS,OAAO,CAAC;AAElC,SACE,oBAAC;AAAA,IACC,MAAK;AAAA,IACL,eAAW;AAAA,IACX,gBAAgB;AAAA,IACf,GAAG;AAAA,IACJ,UAAU;AAAA,IACV;AAAA,IACA,OAAO;AAAA,MACL,GAAG,MAAM;AAAA,MAET,UAAU;AAAA,MACV,eAAe;AAAA,MACf,SAAS;AAAA,MACT,QAAQ;AAAA,IACV;AAAA,GACF;AAEJ;AAEA,SAAS,SAAS,SAAkB;AAClC,SAAO,UAAU,YAAY;AAC/B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/index.js.map
CHANGED
package/dist/jsx/Switch.js
CHANGED
|
@@ -38,11 +38,15 @@ const SwitchThumbFrame = styled(ThemeableStack, {
|
|
|
38
38
|
size: "$4"
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
|
-
const SwitchThumb = SwitchThumbFrame.extractable(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
})
|
|
41
|
+
const SwitchThumb = SwitchThumbFrame.extractable(
|
|
42
|
+
React.forwardRef(
|
|
43
|
+
(props, forwardedRef) => {
|
|
44
|
+
const { __scopeSwitch, ...thumbProps } = props;
|
|
45
|
+
const { size, disabled, checked } = useSwitchContext(THUMB_NAME, __scopeSwitch);
|
|
46
|
+
return <SwitchThumbFrame size={size} data-state={getState(checked)} data-disabled={disabled ? "" : void 0} {...thumbProps} x={checked ? getVariableValue(getSwitchWidth(size)) - getVariableValue(getSwitchHeight(size)) : 0} ref={forwardedRef} />;
|
|
47
|
+
}
|
|
48
|
+
)
|
|
49
|
+
);
|
|
46
50
|
SwitchThumb.displayName = THUMB_NAME;
|
|
47
51
|
const SwitchFrame = styled(XStack, {
|
|
48
52
|
name: "Switch",
|
|
@@ -71,57 +75,64 @@ const SwitchFrame = styled(XStack, {
|
|
|
71
75
|
size: "$4"
|
|
72
76
|
}
|
|
73
77
|
});
|
|
74
|
-
const Switch = withStaticProperties(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
78
|
+
const Switch = withStaticProperties(
|
|
79
|
+
SwitchFrame.extractable(
|
|
80
|
+
React.forwardRef(
|
|
81
|
+
(props, forwardedRef) => {
|
|
82
|
+
const {
|
|
83
|
+
__scopeSwitch,
|
|
84
|
+
labeledBy: ariaLabelledby,
|
|
85
|
+
name,
|
|
86
|
+
checked: checkedProp,
|
|
87
|
+
defaultChecked,
|
|
88
|
+
required,
|
|
89
|
+
disabled,
|
|
90
|
+
value = "on",
|
|
91
|
+
onCheckedChange,
|
|
92
|
+
size = "$4",
|
|
93
|
+
...switchProps
|
|
94
|
+
} = props;
|
|
95
|
+
const [button, setButton] = React.useState(null);
|
|
96
|
+
const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node));
|
|
97
|
+
const labelId = useLabelContext(button);
|
|
98
|
+
const labelledBy = ariaLabelledby || labelId;
|
|
99
|
+
const hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
100
|
+
const isFormControl = isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
101
|
+
const [checked = false, setChecked] = useControllableState({
|
|
102
|
+
prop: checkedProp,
|
|
103
|
+
defaultProp: defaultChecked || false,
|
|
104
|
+
onChange: onCheckedChange
|
|
105
|
+
});
|
|
106
|
+
if (!isWeb) {
|
|
107
|
+
React.useEffect(() => {
|
|
108
|
+
if (!props.id)
|
|
109
|
+
return;
|
|
110
|
+
return registerFocusable(props.id, {
|
|
111
|
+
focus: () => {
|
|
112
|
+
setChecked((x) => !x);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}, [props.id, setChecked]);
|
|
106
116
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
return <SwitchProvider scope={__scopeSwitch} checked={checked} disabled={disabled} size={size}>
|
|
118
|
+
<SwitchFrame size={size} role="switch" aria-checked={checked} aria-labelledby={labelledBy} aria-required={required} data-state={getState(checked)} data-disabled={disabled ? "" : void 0} disabled={disabled} theme={checked ? "active" : null} themeShallow tabIndex={disabled ? void 0 : 0} value={value} {...switchProps} ref={composedRefs} onPress={(event) => {
|
|
119
|
+
props.onPress?.(event);
|
|
120
|
+
setChecked((prevChecked) => !prevChecked);
|
|
121
|
+
if (isWeb && isFormControl) {
|
|
122
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
123
|
+
if (!hasConsumerStoppedPropagationRef.current)
|
|
124
|
+
event.stopPropagation();
|
|
125
|
+
}
|
|
126
|
+
}} />
|
|
127
|
+
{isWeb && isFormControl && <BubbleInput control={button} bubbles={!hasConsumerStoppedPropagationRef.current} name={name} value={value} checked={checked} required={required} disabled={disabled} style={{ transform: "translateX(-100%)" }} />}
|
|
128
|
+
</SwitchProvider>;
|
|
118
129
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
130
|
+
)
|
|
131
|
+
),
|
|
132
|
+
{
|
|
133
|
+
Thumb: SwitchThumb
|
|
134
|
+
}
|
|
135
|
+
);
|
|
125
136
|
const BubbleInput = (props) => {
|
|
126
137
|
const { control, checked, bubbles = true, ...inputProps } = props;
|
|
127
138
|
const ref = React.useRef(null);
|
package/dist/jsx/Switch.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Switch.tsx"],
|
|
4
4
|
"sourcesContent": ["// via radix\n// https://github.com/radix-ui/primitives/blob/main/packages/react/switch/src/Switch.tsx\n\nimport { usePrevious } from '@radix-ui/react-use-previous'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n SizeTokens,\n calc,\n getSize,\n getVariableValue,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { registerFocusable } from '@tamagui/focusable'\nimport { useLabelContext } from '@tamagui/label'\nimport { ThemeableStack, XStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst SWITCH_NAME = 'Switch'\n\n// TODO make customizable\nconst getSwitchHeight = (val: SizeTokens) => Math.round(getVariableValue(getSize(val)) * 0.65)\nconst getSwitchWidth = (val: SizeTokens) => getSwitchHeight(val) * 2\n\nconst scopeContexts = createContextScope(SWITCH_NAME)\nconst [createSwitchContext] = scopeContexts\nexport const createSwitchScope = scopeContexts[1]\n\nconst [SwitchProvider, useSwitchContext] = createSwitchContext<{\n checked: boolean\n disabled?: boolean\n size: SizeTokens\n}>(SWITCH_NAME)\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb'\n\nexport const SwitchThumbFrame = styled(ThemeableStack, {\n name: 'SwitchThumb',\n backgroundColor: '$background',\n borderRadius: 1000,\n\n variants: {\n size: {\n '...size': (val) => ({\n height: getSwitchHeight(val),\n width: getSwitchHeight(val),\n }),\n },\n },\n\n defaultVariants: {\n size: '$4',\n },\n})\n\nexport type SwitchThumbProps = GetProps<typeof SwitchThumbFrame>\n\nexport const SwitchThumb = SwitchThumbFrame.extractable(\n React.forwardRef<React.ElementRef<'span'>, SwitchThumbProps>(\n (props: ScopedProps<SwitchThumbProps, 'Switch'>, forwardedRef) => {\n const { __scopeSwitch, ...thumbProps } = props\n const { size, disabled, checked } = useSwitchContext(THUMB_NAME, __scopeSwitch)\n return (\n <SwitchThumbFrame\n size={size}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n {...thumbProps}\n x={\n checked\n ? getVariableValue(getSwitchWidth(size)) - getVariableValue(getSwitchHeight(size))\n : 0\n }\n ref={forwardedRef}\n />\n )\n }\n )\n)\n\nSwitchThumb.displayName = THUMB_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Switch\n * -----------------------------------------------------------------------------------------------*/\n\nexport const SwitchFrame = styled(XStack, {\n name: 'Switch',\n tag: 'button',\n borderRadius: 1000,\n borderWidth: 2,\n borderColor: 'transparent',\n backgroundColor: '$background',\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n\n variants: {\n size: {\n '...size': (val) => {\n const height = calc(getSwitchHeight(val), '+', 4)\n const width = calc(getSwitchWidth(val), '+', 4)\n return {\n height,\n minHeight: height,\n width,\n }\n },\n },\n },\n\n defaultVariants: {\n size: '$4',\n },\n})\n\ntype SwitchButtonProps = GetProps<typeof SwitchFrame>\n\nexport type SwitchProps = SwitchButtonProps & {\n labeledBy?: string\n name?: string\n value?: string\n checked?: boolean\n defaultChecked?: boolean\n required?: boolean\n onCheckedChange?(checked: boolean): void\n}\n\nexport const Switch = withStaticProperties(\n SwitchFrame.extractable(\n React.forwardRef<HTMLButtonElement | View, SwitchProps>(\n (props: ScopedProps<SwitchProps, 'Switch'>, forwardedRef) => {\n const {\n __scopeSwitch,\n labeledBy: ariaLabelledby,\n name,\n checked: checkedProp,\n defaultChecked,\n required,\n disabled,\n value = 'on',\n onCheckedChange,\n size = '$4',\n ...switchProps\n } = props\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node as any))\n const labelId = useLabelContext(button)\n const labelledBy = ariaLabelledby || labelId\n const hasConsumerStoppedPropagationRef = React.useRef(false)\n // We set this to true by default so that events bubble to forms without JS (SSR)\n const isFormControl = isWeb ? (button ? Boolean(button.closest('form')) : true) : false\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n })\n\n if (!isWeb) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (!props.id) return\n return registerFocusable(props.id, {\n focus: () => {\n setChecked((x) => !x)\n },\n })\n }, [props.id, setChecked])\n }\n\n return (\n <SwitchProvider scope={__scopeSwitch} checked={checked} disabled={disabled} size={size}>\n <SwitchFrame\n size={size}\n // @ts-ignore\n role=\"switch\"\n aria-checked={checked}\n aria-labelledby={labelledBy}\n aria-required={required}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n disabled={disabled}\n theme={checked ? 'active' : null}\n themeShallow\n // @ts-ignore\n tabIndex={disabled ? undefined : 0}\n // @ts-ignore\n value={value}\n {...switchProps}\n ref={composedRefs}\n onPress={(event) => {\n props.onPress?.(event)\n setChecked((prevChecked) => !prevChecked)\n if (isWeb && isFormControl) {\n hasConsumerStoppedPropagationRef.current = event.isPropagationStopped()\n // if switch is in a form, stop propagation from the button so that we only propagate\n // one click event (from the input). We propagate changes from an input so that native\n // form validation works and form events reflect switch updates.\n if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation()\n }\n }}\n />\n {isWeb && isFormControl && (\n <BubbleInput\n control={button}\n bubbles={!hasConsumerStoppedPropagationRef.current}\n name={name}\n value={value}\n checked={checked}\n required={required}\n disabled={disabled}\n // We transform because the input is absolutely positioned but we have\n // rendered it **after** the button. This pulls it back to sit on top\n // of the button.\n style={{ transform: 'translateX(-100%)' }}\n />\n )}\n </SwitchProvider>\n )\n }\n )\n ),\n {\n Thumb: SwitchThumb,\n }\n)\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype InputProps = any //Radix.ComponentPropsWithoutRef<'input'>\ninterface BubbleInputProps extends Omit<InputProps, 'checked'> {\n checked: boolean\n control: HTMLElement | null\n bubbles: boolean\n}\n\n// TODO make this native friendly\nconst BubbleInput = (props: BubbleInputProps) => {\n const { control, checked, bubbles = true, ...inputProps } = props\n const ref = React.useRef<HTMLInputElement>(null)\n const prevChecked = usePrevious(checked)\n // const controlSize = useSize(control)\n\n // Bubble checked change to parents (e.g form change event)\n React.useEffect(() => {\n const input = ref.current!\n const inputProto = window.HTMLInputElement.prototype\n const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked') as PropertyDescriptor\n const setChecked = descriptor.set\n if (prevChecked !== checked && setChecked) {\n const event = new Event('click', { bubbles })\n setChecked.call(input, checked)\n input.dispatchEvent(event)\n }\n }, [prevChecked, checked, bubbles])\n\n return (\n <input\n type=\"checkbox\"\n aria-hidden\n defaultChecked={checked}\n {...inputProps}\n tabIndex={-1}\n ref={ref}\n style={{\n ...props.style,\n // ...controlSize,\n position: 'absolute',\n pointerEvents: 'none',\n opacity: 0,\n margin: 0,\n }}\n />\n )\n}\n\nfunction getState(checked: boolean) {\n return checked ? 'checked' : 'unchecked'\n}\n"],
|
|
5
|
-
"mappings": "AAGA;
|
|
5
|
+
"mappings": "AAGA,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAsB,0BAA0B;AAChD,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,cAAc;AACvC,SAAS,4BAA4B;AACrC,YAAY,WAAW;AAGvB,MAAM,cAAc;AAGpB,MAAM,kBAAkB,CAAC,QAAoB,KAAK,MAAM,iBAAiB,QAAQ,GAAG,CAAC,IAAI,IAAI;AAC7F,MAAM,iBAAiB,CAAC,QAAoB,gBAAgB,GAAG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WACL,YACA,gBAAgB,aACZ,YACJ,UAAU,IACV,KAAK,KACL,OAAO;AAAA,IACL,GAAG,MAAM;AAAA,IAET,UAAU;AAAA,IACV,eAAe;AAAA,IACf,SAAS;AAAA,IACT,QAAQ;AAAA,EACV,GACF;AAEJ;AAEA,SAAS,SAAS,SAAkB;AAClC,SAAO,UAAU,YAAY;AAC/B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/jsx/index.js.map
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/switch",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.152",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@radix-ui/react-use-previous": "^0.1.1",
|
|
27
|
-
"@tamagui/compose-refs": "^1.0.1-beta.
|
|
28
|
-
"@tamagui/core": "^1.0.1-beta.
|
|
29
|
-
"@tamagui/create-context": "^1.0.1-beta.
|
|
30
|
-
"@tamagui/focusable": "^1.0.1-beta.
|
|
31
|
-
"@tamagui/label": "^1.0.1-beta.
|
|
32
|
-
"@tamagui/stacks": "^1.0.1-beta.
|
|
33
|
-
"@tamagui/use-controllable-state": "^1.0.1-beta.
|
|
27
|
+
"@tamagui/compose-refs": "^1.0.1-beta.152",
|
|
28
|
+
"@tamagui/core": "^1.0.1-beta.152",
|
|
29
|
+
"@tamagui/create-context": "^1.0.1-beta.152",
|
|
30
|
+
"@tamagui/focusable": "^1.0.1-beta.152",
|
|
31
|
+
"@tamagui/label": "^1.0.1-beta.152",
|
|
32
|
+
"@tamagui/stacks": "^1.0.1-beta.152",
|
|
33
|
+
"@tamagui/use-controllable-state": "^1.0.1-beta.152"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": "*",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"react-native": "*"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
41
|
+
"@tamagui/build": "^1.0.1-beta.152",
|
|
42
42
|
"@types/react-native": "^0.69.2",
|
|
43
43
|
"react": "*",
|
|
44
44
|
"react-dom": "*",
|