@tamagui/switch 1.5.8 → 1.5.10
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 +31 -13
- package/dist/cjs/Switch.js.map +2 -2
- package/dist/esm/Switch.js +31 -13
- package/dist/esm/Switch.js.map +2 -2
- package/dist/esm/Switch.mjs +31 -13
- package/dist/esm/Switch.mjs.map +2 -2
- package/dist/jsx/Switch.js +31 -13
- package/dist/jsx/Switch.js.map +2 -2
- package/dist/jsx/Switch.mjs +31 -13
- package/dist/jsx/Switch.mjs.map +2 -2
- package/package.json +10 -10
- package/src/Switch.tsx +35 -14
- package/types/Switch.d.ts +32 -15
- package/types/Switch.d.ts.map +1 -1
package/dist/cjs/Switch.js
CHANGED
|
@@ -56,9 +56,14 @@ const [SwitchProvider, useSwitchContext] = createSwitchContext(SWITCH_NAME);
|
|
|
56
56
|
const THUMB_NAME = "SwitchThumb";
|
|
57
57
|
const SwitchThumbFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
58
58
|
name: "SwitchThumb",
|
|
59
|
-
backgroundColor: "$background",
|
|
60
|
-
borderRadius: 1e3,
|
|
61
59
|
variants: {
|
|
60
|
+
unstyled: {
|
|
61
|
+
false: {
|
|
62
|
+
size: "$true",
|
|
63
|
+
backgroundColor: "$background",
|
|
64
|
+
borderRadius: 1e3
|
|
65
|
+
}
|
|
66
|
+
},
|
|
62
67
|
size: {
|
|
63
68
|
"...size": (val) => {
|
|
64
69
|
const size = getSwitchHeight(val);
|
|
@@ -70,18 +75,23 @@ const SwitchThumbFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
|
70
75
|
}
|
|
71
76
|
},
|
|
72
77
|
defaultVariants: {
|
|
73
|
-
|
|
78
|
+
unstyled: false
|
|
74
79
|
}
|
|
75
80
|
});
|
|
76
81
|
const SwitchThumb = SwitchThumbFrame.extractable(
|
|
77
82
|
React.forwardRef(
|
|
78
83
|
(props, forwardedRef) => {
|
|
79
84
|
const { __scopeSwitch, ...thumbProps } = props;
|
|
80
|
-
const { size, disabled, checked } = useSwitchContext(
|
|
85
|
+
const { size, disabled, checked, unstyled } = useSwitchContext(
|
|
86
|
+
THUMB_NAME,
|
|
87
|
+
__scopeSwitch
|
|
88
|
+
);
|
|
81
89
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
82
90
|
SwitchThumbFrame,
|
|
83
91
|
{
|
|
92
|
+
unstyled,
|
|
84
93
|
size,
|
|
94
|
+
theme: checked ? "active" : null,
|
|
85
95
|
"data-state": getState(checked),
|
|
86
96
|
"data-disabled": disabled ? "" : void 0,
|
|
87
97
|
...thumbProps,
|
|
@@ -94,16 +104,21 @@ const SwitchThumb = SwitchThumbFrame.extractable(
|
|
|
94
104
|
);
|
|
95
105
|
SwitchThumb.displayName = THUMB_NAME;
|
|
96
106
|
const SwitchFrame = (0, import_core.styled)(import_stacks.XStack, {
|
|
97
|
-
name:
|
|
107
|
+
name: SWITCH_NAME,
|
|
98
108
|
tag: "button",
|
|
99
|
-
borderRadius: 1e3,
|
|
100
|
-
borderWidth: 2,
|
|
101
|
-
borderColor: "transparent",
|
|
102
|
-
backgroundColor: "$background",
|
|
103
|
-
focusStyle: {
|
|
104
|
-
borderColor: "$borderColorFocus"
|
|
105
|
-
},
|
|
106
109
|
variants: {
|
|
110
|
+
unstyled: {
|
|
111
|
+
false: {
|
|
112
|
+
size: "$true",
|
|
113
|
+
borderRadius: 1e3,
|
|
114
|
+
borderWidth: 2,
|
|
115
|
+
borderColor: "transparent",
|
|
116
|
+
backgroundColor: "$background",
|
|
117
|
+
focusStyle: {
|
|
118
|
+
borderColor: "$borderColorFocus"
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
},
|
|
107
122
|
size: {
|
|
108
123
|
"...size": (val) => {
|
|
109
124
|
const height = getSwitchHeight(val) + 4;
|
|
@@ -117,7 +132,7 @@ const SwitchFrame = (0, import_core.styled)(import_stacks.XStack, {
|
|
|
117
132
|
}
|
|
118
133
|
},
|
|
119
134
|
defaultVariants: {
|
|
120
|
-
|
|
135
|
+
unstyled: false
|
|
121
136
|
}
|
|
122
137
|
});
|
|
123
138
|
const Switch = (0, import_core.withStaticProperties)(
|
|
@@ -135,6 +150,7 @@ const Switch = (0, import_core.withStaticProperties)(
|
|
|
135
150
|
value = "on",
|
|
136
151
|
onCheckedChange,
|
|
137
152
|
size = "$true",
|
|
153
|
+
unstyled = false,
|
|
138
154
|
...switchProps
|
|
139
155
|
} = props;
|
|
140
156
|
const [button, setButton] = React.useState(null);
|
|
@@ -170,10 +186,12 @@ const Switch = (0, import_core.withStaticProperties)(
|
|
|
170
186
|
checked,
|
|
171
187
|
disabled,
|
|
172
188
|
size,
|
|
189
|
+
unstyled,
|
|
173
190
|
children: [
|
|
174
191
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
175
192
|
SwitchFrame,
|
|
176
193
|
{
|
|
194
|
+
unstyled,
|
|
177
195
|
size,
|
|
178
196
|
role: "switch",
|
|
179
197
|
"aria-checked": checked,
|
package/dist/cjs/Switch.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Switch.tsx"],
|
|
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 getVariableValue,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { registerFocusable } from '@tamagui/focusable'\nimport { getSize } from '@tamagui/get-size'\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) =>\n 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 const size = getSwitchHeight(val)\n return {\n height: size,\n width: size,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$true',\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)) -\n 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 = getSwitchHeight(val) + 4\n const width = getSwitchWidth(val) + 4\n return {\n height,\n minHeight: height,\n width,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$true',\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 = '$true',\n ...switchProps\n } = props\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) =>\n setButton(node as any)\n )\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\n ? button\n ? Boolean(button.closest('form'))\n : true\n : false\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true,\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\n scope={__scopeSwitch}\n checked={checked}\n disabled={disabled}\n size={size}\n >\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(\n inputProto,\n 'checked'\n ) 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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
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 getVariableValue,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { registerFocusable } from '@tamagui/focusable'\nimport { getSize } from '@tamagui/get-size'\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) =>\n 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 unstyled?: boolean\n}>(SWITCH_NAME)\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb'\n\nexport const SwitchThumbFrame = styled(ThemeableStack, {\n name: 'SwitchThumb',\n\n variants: {\n unstyled: {\n false: {\n size: '$true',\n backgroundColor: '$background',\n borderRadius: 1000,\n },\n },\n\n size: {\n '...size': (val) => {\n const size = getSwitchHeight(val)\n return {\n height: size,\n width: size,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\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, unstyled } = useSwitchContext(\n THUMB_NAME,\n __scopeSwitch\n )\n return (\n <SwitchThumbFrame\n unstyled={unstyled}\n size={size}\n theme={checked ? 'active' : null}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n {...thumbProps}\n x={\n checked\n ? getVariableValue(getSwitchWidth(size)) -\n 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_NAME,\n tag: 'button',\n\n variants: {\n unstyled: {\n false: {\n size: '$true',\n borderRadius: 1000,\n borderWidth: 2,\n borderColor: 'transparent',\n backgroundColor: '$background',\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n },\n },\n\n size: {\n '...size': (val) => {\n const height = getSwitchHeight(val) + 4\n const width = getSwitchWidth(val) + 4\n return {\n height,\n minHeight: height,\n width,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\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 = '$true',\n unstyled = false,\n ...switchProps\n } = props\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) =>\n setButton(node as any)\n )\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\n ? button\n ? Boolean(button.closest('form'))\n : true\n : false\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true,\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\n scope={__scopeSwitch}\n checked={checked}\n disabled={disabled}\n size={size}\n unstyled={unstyled}\n >\n <SwitchFrame\n unstyled={unstyled}\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(\n inputProto,\n 'checked'\n ) 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": ";;;;;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,SAAS,SAAS,SAAkB;AAClC,SAAO,UAAU,YAAY;AAC/B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/Switch.js
CHANGED
|
@@ -24,9 +24,14 @@ const [SwitchProvider, useSwitchContext] = createSwitchContext(SWITCH_NAME);
|
|
|
24
24
|
const THUMB_NAME = "SwitchThumb";
|
|
25
25
|
const SwitchThumbFrame = styled(ThemeableStack, {
|
|
26
26
|
name: "SwitchThumb",
|
|
27
|
-
backgroundColor: "$background",
|
|
28
|
-
borderRadius: 1e3,
|
|
29
27
|
variants: {
|
|
28
|
+
unstyled: {
|
|
29
|
+
false: {
|
|
30
|
+
size: "$true",
|
|
31
|
+
backgroundColor: "$background",
|
|
32
|
+
borderRadius: 1e3
|
|
33
|
+
}
|
|
34
|
+
},
|
|
30
35
|
size: {
|
|
31
36
|
"...size": (val) => {
|
|
32
37
|
const size = getSwitchHeight(val);
|
|
@@ -38,18 +43,23 @@ const SwitchThumbFrame = styled(ThemeableStack, {
|
|
|
38
43
|
}
|
|
39
44
|
},
|
|
40
45
|
defaultVariants: {
|
|
41
|
-
|
|
46
|
+
unstyled: false
|
|
42
47
|
}
|
|
43
48
|
});
|
|
44
49
|
const SwitchThumb = SwitchThumbFrame.extractable(
|
|
45
50
|
React.forwardRef(
|
|
46
51
|
(props, forwardedRef) => {
|
|
47
52
|
const { __scopeSwitch, ...thumbProps } = props;
|
|
48
|
-
const { size, disabled, checked } = useSwitchContext(
|
|
53
|
+
const { size, disabled, checked, unstyled } = useSwitchContext(
|
|
54
|
+
THUMB_NAME,
|
|
55
|
+
__scopeSwitch
|
|
56
|
+
);
|
|
49
57
|
return /* @__PURE__ */ jsx(
|
|
50
58
|
SwitchThumbFrame,
|
|
51
59
|
{
|
|
60
|
+
unstyled,
|
|
52
61
|
size,
|
|
62
|
+
theme: checked ? "active" : null,
|
|
53
63
|
"data-state": getState(checked),
|
|
54
64
|
"data-disabled": disabled ? "" : void 0,
|
|
55
65
|
...thumbProps,
|
|
@@ -62,16 +72,21 @@ const SwitchThumb = SwitchThumbFrame.extractable(
|
|
|
62
72
|
);
|
|
63
73
|
SwitchThumb.displayName = THUMB_NAME;
|
|
64
74
|
const SwitchFrame = styled(XStack, {
|
|
65
|
-
name:
|
|
75
|
+
name: SWITCH_NAME,
|
|
66
76
|
tag: "button",
|
|
67
|
-
borderRadius: 1e3,
|
|
68
|
-
borderWidth: 2,
|
|
69
|
-
borderColor: "transparent",
|
|
70
|
-
backgroundColor: "$background",
|
|
71
|
-
focusStyle: {
|
|
72
|
-
borderColor: "$borderColorFocus"
|
|
73
|
-
},
|
|
74
77
|
variants: {
|
|
78
|
+
unstyled: {
|
|
79
|
+
false: {
|
|
80
|
+
size: "$true",
|
|
81
|
+
borderRadius: 1e3,
|
|
82
|
+
borderWidth: 2,
|
|
83
|
+
borderColor: "transparent",
|
|
84
|
+
backgroundColor: "$background",
|
|
85
|
+
focusStyle: {
|
|
86
|
+
borderColor: "$borderColorFocus"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
75
90
|
size: {
|
|
76
91
|
"...size": (val) => {
|
|
77
92
|
const height = getSwitchHeight(val) + 4;
|
|
@@ -85,7 +100,7 @@ const SwitchFrame = styled(XStack, {
|
|
|
85
100
|
}
|
|
86
101
|
},
|
|
87
102
|
defaultVariants: {
|
|
88
|
-
|
|
103
|
+
unstyled: false
|
|
89
104
|
}
|
|
90
105
|
});
|
|
91
106
|
const Switch = withStaticProperties(
|
|
@@ -103,6 +118,7 @@ const Switch = withStaticProperties(
|
|
|
103
118
|
value = "on",
|
|
104
119
|
onCheckedChange,
|
|
105
120
|
size = "$true",
|
|
121
|
+
unstyled = false,
|
|
106
122
|
...switchProps
|
|
107
123
|
} = props;
|
|
108
124
|
const [button, setButton] = React.useState(null);
|
|
@@ -138,10 +154,12 @@ const Switch = withStaticProperties(
|
|
|
138
154
|
checked,
|
|
139
155
|
disabled,
|
|
140
156
|
size,
|
|
157
|
+
unstyled,
|
|
141
158
|
children: [
|
|
142
159
|
/* @__PURE__ */ jsx(
|
|
143
160
|
SwitchFrame,
|
|
144
161
|
{
|
|
162
|
+
unstyled,
|
|
145
163
|
size,
|
|
146
164
|
role: "switch",
|
|
147
165
|
"aria-checked": checked,
|
package/dist/esm/Switch.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Switch.tsx"],
|
|
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 getVariableValue,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { registerFocusable } from '@tamagui/focusable'\nimport { getSize } from '@tamagui/get-size'\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) =>\n 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 const size = getSwitchHeight(val)\n return {\n height: size,\n width: size,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$true',\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)) -\n 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 = getSwitchHeight(val) + 4\n const width = getSwitchWidth(val) + 4\n return {\n height,\n minHeight: height,\n width,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$true',\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 = '$true',\n ...switchProps\n } = props\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) =>\n setButton(node as any)\n )\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\n ? button\n ? Boolean(button.closest('form'))\n : true\n : false\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true,\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\n scope={__scopeSwitch}\n checked={checked}\n disabled={disabled}\n size={size}\n >\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(\n inputProto,\n 'checked'\n ) 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": "
|
|
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 getVariableValue,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { registerFocusable } from '@tamagui/focusable'\nimport { getSize } from '@tamagui/get-size'\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) =>\n 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 unstyled?: boolean\n}>(SWITCH_NAME)\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb'\n\nexport const SwitchThumbFrame = styled(ThemeableStack, {\n name: 'SwitchThumb',\n\n variants: {\n unstyled: {\n false: {\n size: '$true',\n backgroundColor: '$background',\n borderRadius: 1000,\n },\n },\n\n size: {\n '...size': (val) => {\n const size = getSwitchHeight(val)\n return {\n height: size,\n width: size,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\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, unstyled } = useSwitchContext(\n THUMB_NAME,\n __scopeSwitch\n )\n return (\n <SwitchThumbFrame\n unstyled={unstyled}\n size={size}\n theme={checked ? 'active' : null}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n {...thumbProps}\n x={\n checked\n ? getVariableValue(getSwitchWidth(size)) -\n 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_NAME,\n tag: 'button',\n\n variants: {\n unstyled: {\n false: {\n size: '$true',\n borderRadius: 1000,\n borderWidth: 2,\n borderColor: 'transparent',\n backgroundColor: '$background',\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n },\n },\n\n size: {\n '...size': (val) => {\n const height = getSwitchHeight(val) + 4\n const width = getSwitchWidth(val) + 4\n return {\n height,\n minHeight: height,\n width,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\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 = '$true',\n unstyled = false,\n ...switchProps\n } = props\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) =>\n setButton(node as any)\n )\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\n ? button\n ? Boolean(button.closest('form'))\n : true\n : false\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true,\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\n scope={__scopeSwitch}\n checked={checked}\n disabled={disabled}\n size={size}\n unstyled={unstyled}\n >\n <SwitchFrame\n unstyled={unstyled}\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(\n inputProto,\n 'checked'\n ) 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": "AAqFQ,cA8HE,YA9HF;AAlFR,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAsB,0BAA0B;AAChD,SAAS,yBAAyB;AAClC,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,cAAc;AACvC,SAAS,4BAA4B;AACrC,YAAY,WAAW;AAGvB,MAAM,cAAc;AAGpB,MAAM,kBAAkB,CAAC,QACvB,KAAK,MAAM,iBAAiB,QAAQ,GAAG,CAAC,IAAI,IAAI;AAClD,MAAM,iBAAiB,CAAC,QAAoB,gBAAgB,GAAG,IAAI;AAEnE,MAAM,gBAAgB,mBAAmB,WAAW;AACpD,MAAM,CAAC,mBAAmB,IAAI;AACvB,MAAM,oBAAoB,cAAc,CAAC;AAEhD,MAAM,CAAC,gBAAgB,gBAAgB,IAAI,oBAKxC,WAAW;AAMd,MAAM,a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AAIvC,QAAM,UAAU,MAAM;AACpB,UAAM,QAAQ,IAAI;AAClB,UAAM,aAAa,OAAO,iBAAiB;AAC3C,UAAM,aAAa,OAAO;AAAA,MACxB;AAAA,MACA;AAAA,IACF;AACA,UAAM,aAAa,WAAW;AAC9B,QAAI,gBAAgB,WAAW,YAAY;AACzC,YAAM,QAAQ,IAAI,MAAM,SAAS,EAAE,QAAQ,CAAC;AAC5C,iBAAW,KAAK,OAAO,OAAO;AAC9B,YAAM,cAAc,KAAK;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,aAAa,SAAS,OAAO,CAAC;AAElC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL,eAAW;AAAA,MACX,gBAAgB;AAAA,MACf,GAAG;AAAA,MACJ,UAAU;AAAA,MACV;AAAA,MACA,OAAO;AAAA,QACL,GAAG,MAAM;AAAA;AAAA,QAET,UAAU;AAAA,QACV,eAAe;AAAA,QACf,SAAS;AAAA,QACT,QAAQ;AAAA,MACV;AAAA;AAAA,EACF;AAEJ;AAEA,SAAS,SAAS,SAAkB;AAClC,SAAO,UAAU,YAAY;AAC/B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/Switch.mjs
CHANGED
|
@@ -24,9 +24,14 @@ const [SwitchProvider, useSwitchContext] = createSwitchContext(SWITCH_NAME);
|
|
|
24
24
|
const THUMB_NAME = "SwitchThumb";
|
|
25
25
|
const SwitchThumbFrame = styled(ThemeableStack, {
|
|
26
26
|
name: "SwitchThumb",
|
|
27
|
-
backgroundColor: "$background",
|
|
28
|
-
borderRadius: 1e3,
|
|
29
27
|
variants: {
|
|
28
|
+
unstyled: {
|
|
29
|
+
false: {
|
|
30
|
+
size: "$true",
|
|
31
|
+
backgroundColor: "$background",
|
|
32
|
+
borderRadius: 1e3
|
|
33
|
+
}
|
|
34
|
+
},
|
|
30
35
|
size: {
|
|
31
36
|
"...size": (val) => {
|
|
32
37
|
const size = getSwitchHeight(val);
|
|
@@ -38,18 +43,23 @@ const SwitchThumbFrame = styled(ThemeableStack, {
|
|
|
38
43
|
}
|
|
39
44
|
},
|
|
40
45
|
defaultVariants: {
|
|
41
|
-
|
|
46
|
+
unstyled: false
|
|
42
47
|
}
|
|
43
48
|
});
|
|
44
49
|
const SwitchThumb = SwitchThumbFrame.extractable(
|
|
45
50
|
React.forwardRef(
|
|
46
51
|
(props, forwardedRef) => {
|
|
47
52
|
const { __scopeSwitch, ...thumbProps } = props;
|
|
48
|
-
const { size, disabled, checked } = useSwitchContext(
|
|
53
|
+
const { size, disabled, checked, unstyled } = useSwitchContext(
|
|
54
|
+
THUMB_NAME,
|
|
55
|
+
__scopeSwitch
|
|
56
|
+
);
|
|
49
57
|
return /* @__PURE__ */ jsx(
|
|
50
58
|
SwitchThumbFrame,
|
|
51
59
|
{
|
|
60
|
+
unstyled,
|
|
52
61
|
size,
|
|
62
|
+
theme: checked ? "active" : null,
|
|
53
63
|
"data-state": getState(checked),
|
|
54
64
|
"data-disabled": disabled ? "" : void 0,
|
|
55
65
|
...thumbProps,
|
|
@@ -62,16 +72,21 @@ const SwitchThumb = SwitchThumbFrame.extractable(
|
|
|
62
72
|
);
|
|
63
73
|
SwitchThumb.displayName = THUMB_NAME;
|
|
64
74
|
const SwitchFrame = styled(XStack, {
|
|
65
|
-
name:
|
|
75
|
+
name: SWITCH_NAME,
|
|
66
76
|
tag: "button",
|
|
67
|
-
borderRadius: 1e3,
|
|
68
|
-
borderWidth: 2,
|
|
69
|
-
borderColor: "transparent",
|
|
70
|
-
backgroundColor: "$background",
|
|
71
|
-
focusStyle: {
|
|
72
|
-
borderColor: "$borderColorFocus"
|
|
73
|
-
},
|
|
74
77
|
variants: {
|
|
78
|
+
unstyled: {
|
|
79
|
+
false: {
|
|
80
|
+
size: "$true",
|
|
81
|
+
borderRadius: 1e3,
|
|
82
|
+
borderWidth: 2,
|
|
83
|
+
borderColor: "transparent",
|
|
84
|
+
backgroundColor: "$background",
|
|
85
|
+
focusStyle: {
|
|
86
|
+
borderColor: "$borderColorFocus"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
75
90
|
size: {
|
|
76
91
|
"...size": (val) => {
|
|
77
92
|
const height = getSwitchHeight(val) + 4;
|
|
@@ -85,7 +100,7 @@ const SwitchFrame = styled(XStack, {
|
|
|
85
100
|
}
|
|
86
101
|
},
|
|
87
102
|
defaultVariants: {
|
|
88
|
-
|
|
103
|
+
unstyled: false
|
|
89
104
|
}
|
|
90
105
|
});
|
|
91
106
|
const Switch = withStaticProperties(
|
|
@@ -103,6 +118,7 @@ const Switch = withStaticProperties(
|
|
|
103
118
|
value = "on",
|
|
104
119
|
onCheckedChange,
|
|
105
120
|
size = "$true",
|
|
121
|
+
unstyled = false,
|
|
106
122
|
...switchProps
|
|
107
123
|
} = props;
|
|
108
124
|
const [button, setButton] = React.useState(null);
|
|
@@ -138,10 +154,12 @@ const Switch = withStaticProperties(
|
|
|
138
154
|
checked,
|
|
139
155
|
disabled,
|
|
140
156
|
size,
|
|
157
|
+
unstyled,
|
|
141
158
|
children: [
|
|
142
159
|
/* @__PURE__ */ jsx(
|
|
143
160
|
SwitchFrame,
|
|
144
161
|
{
|
|
162
|
+
unstyled,
|
|
145
163
|
size,
|
|
146
164
|
role: "switch",
|
|
147
165
|
"aria-checked": checked,
|
package/dist/esm/Switch.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Switch.tsx"],
|
|
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 getVariableValue,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { registerFocusable } from '@tamagui/focusable'\nimport { getSize } from '@tamagui/get-size'\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) =>\n 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 const size = getSwitchHeight(val)\n return {\n height: size,\n width: size,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$true',\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)) -\n 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 = getSwitchHeight(val) + 4\n const width = getSwitchWidth(val) + 4\n return {\n height,\n minHeight: height,\n width,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$true',\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 = '$true',\n ...switchProps\n } = props\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) =>\n setButton(node as any)\n )\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\n ? button\n ? Boolean(button.closest('form'))\n : true\n : false\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true,\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\n scope={__scopeSwitch}\n checked={checked}\n disabled={disabled}\n size={size}\n >\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(\n inputProto,\n 'checked'\n ) 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": "
|
|
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 getVariableValue,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { registerFocusable } from '@tamagui/focusable'\nimport { getSize } from '@tamagui/get-size'\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) =>\n 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 unstyled?: boolean\n}>(SWITCH_NAME)\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb'\n\nexport const SwitchThumbFrame = styled(ThemeableStack, {\n name: 'SwitchThumb',\n\n variants: {\n unstyled: {\n false: {\n size: '$true',\n backgroundColor: '$background',\n borderRadius: 1000,\n },\n },\n\n size: {\n '...size': (val) => {\n const size = getSwitchHeight(val)\n return {\n height: size,\n width: size,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\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, unstyled } = useSwitchContext(\n THUMB_NAME,\n __scopeSwitch\n )\n return (\n <SwitchThumbFrame\n unstyled={unstyled}\n size={size}\n theme={checked ? 'active' : null}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n {...thumbProps}\n x={\n checked\n ? getVariableValue(getSwitchWidth(size)) -\n 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_NAME,\n tag: 'button',\n\n variants: {\n unstyled: {\n false: {\n size: '$true',\n borderRadius: 1000,\n borderWidth: 2,\n borderColor: 'transparent',\n backgroundColor: '$background',\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n },\n },\n\n size: {\n '...size': (val) => {\n const height = getSwitchHeight(val) + 4\n const width = getSwitchWidth(val) + 4\n return {\n height,\n minHeight: height,\n width,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\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 = '$true',\n unstyled = false,\n ...switchProps\n } = props\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) =>\n setButton(node as any)\n )\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\n ? button\n ? Boolean(button.closest('form'))\n : true\n : false\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true,\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\n scope={__scopeSwitch}\n checked={checked}\n disabled={disabled}\n size={size}\n unstyled={unstyled}\n >\n <SwitchFrame\n unstyled={unstyled}\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(\n inputProto,\n 'checked'\n ) 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: bo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,eAAe;AAAA,QACf,SAAS;AAAA,QACT,QAAQ;AAAA,MACV;AAAA;AAAA,EACF;AAEJ;AAEA,SAAS,SAAS,SAAkB;AAClC,SAAO,UAAU,YAAY;AAC/B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/jsx/Switch.js
CHANGED
|
@@ -23,9 +23,14 @@ const [SwitchProvider, useSwitchContext] = createSwitchContext(SWITCH_NAME);
|
|
|
23
23
|
const THUMB_NAME = "SwitchThumb";
|
|
24
24
|
const SwitchThumbFrame = styled(ThemeableStack, {
|
|
25
25
|
name: "SwitchThumb",
|
|
26
|
-
backgroundColor: "$background",
|
|
27
|
-
borderRadius: 1e3,
|
|
28
26
|
variants: {
|
|
27
|
+
unstyled: {
|
|
28
|
+
false: {
|
|
29
|
+
size: "$true",
|
|
30
|
+
backgroundColor: "$background",
|
|
31
|
+
borderRadius: 1e3
|
|
32
|
+
}
|
|
33
|
+
},
|
|
29
34
|
size: {
|
|
30
35
|
"...size": (val) => {
|
|
31
36
|
const size = getSwitchHeight(val);
|
|
@@ -37,16 +42,21 @@ const SwitchThumbFrame = styled(ThemeableStack, {
|
|
|
37
42
|
}
|
|
38
43
|
},
|
|
39
44
|
defaultVariants: {
|
|
40
|
-
|
|
45
|
+
unstyled: false
|
|
41
46
|
}
|
|
42
47
|
});
|
|
43
48
|
const SwitchThumb = SwitchThumbFrame.extractable(
|
|
44
49
|
React.forwardRef(
|
|
45
50
|
(props, forwardedRef) => {
|
|
46
51
|
const { __scopeSwitch, ...thumbProps } = props;
|
|
47
|
-
const { size, disabled, checked } = useSwitchContext(
|
|
52
|
+
const { size, disabled, checked, unstyled } = useSwitchContext(
|
|
53
|
+
THUMB_NAME,
|
|
54
|
+
__scopeSwitch
|
|
55
|
+
);
|
|
48
56
|
return <SwitchThumbFrame
|
|
57
|
+
unstyled={unstyled}
|
|
49
58
|
size={size}
|
|
59
|
+
theme={checked ? "active" : null}
|
|
50
60
|
data-state={getState(checked)}
|
|
51
61
|
data-disabled={disabled ? "" : void 0}
|
|
52
62
|
{...thumbProps}
|
|
@@ -58,16 +68,21 @@ const SwitchThumb = SwitchThumbFrame.extractable(
|
|
|
58
68
|
);
|
|
59
69
|
SwitchThumb.displayName = THUMB_NAME;
|
|
60
70
|
const SwitchFrame = styled(XStack, {
|
|
61
|
-
name:
|
|
71
|
+
name: SWITCH_NAME,
|
|
62
72
|
tag: "button",
|
|
63
|
-
borderRadius: 1e3,
|
|
64
|
-
borderWidth: 2,
|
|
65
|
-
borderColor: "transparent",
|
|
66
|
-
backgroundColor: "$background",
|
|
67
|
-
focusStyle: {
|
|
68
|
-
borderColor: "$borderColorFocus"
|
|
69
|
-
},
|
|
70
73
|
variants: {
|
|
74
|
+
unstyled: {
|
|
75
|
+
false: {
|
|
76
|
+
size: "$true",
|
|
77
|
+
borderRadius: 1e3,
|
|
78
|
+
borderWidth: 2,
|
|
79
|
+
borderColor: "transparent",
|
|
80
|
+
backgroundColor: "$background",
|
|
81
|
+
focusStyle: {
|
|
82
|
+
borderColor: "$borderColorFocus"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
71
86
|
size: {
|
|
72
87
|
"...size": (val) => {
|
|
73
88
|
const height = getSwitchHeight(val) + 4;
|
|
@@ -81,7 +96,7 @@ const SwitchFrame = styled(XStack, {
|
|
|
81
96
|
}
|
|
82
97
|
},
|
|
83
98
|
defaultVariants: {
|
|
84
|
-
|
|
99
|
+
unstyled: false
|
|
85
100
|
}
|
|
86
101
|
});
|
|
87
102
|
const Switch = withStaticProperties(
|
|
@@ -99,6 +114,7 @@ const Switch = withStaticProperties(
|
|
|
99
114
|
value = "on",
|
|
100
115
|
onCheckedChange,
|
|
101
116
|
size = "$true",
|
|
117
|
+
unstyled = false,
|
|
102
118
|
...switchProps
|
|
103
119
|
} = props;
|
|
104
120
|
const [button, setButton] = React.useState(null);
|
|
@@ -132,8 +148,10 @@ const Switch = withStaticProperties(
|
|
|
132
148
|
checked={checked}
|
|
133
149
|
disabled={disabled}
|
|
134
150
|
size={size}
|
|
151
|
+
unstyled={unstyled}
|
|
135
152
|
>
|
|
136
153
|
<SwitchFrame
|
|
154
|
+
unstyled={unstyled}
|
|
137
155
|
size={size}
|
|
138
156
|
role="switch"
|
|
139
157
|
aria-checked={checked}
|
package/dist/jsx/Switch.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Switch.tsx"],
|
|
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 getVariableValue,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { registerFocusable } from '@tamagui/focusable'\nimport { getSize } from '@tamagui/get-size'\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) =>\n 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 const size = getSwitchHeight(val)\n return {\n height: size,\n width: size,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$true',\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)) -\n 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 = getSwitchHeight(val) + 4\n const width = getSwitchWidth(val) + 4\n return {\n height,\n minHeight: height,\n width,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$true',\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 = '$true',\n ...switchProps\n } = props\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) =>\n setButton(node as any)\n )\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\n ? button\n ? Boolean(button.closest('form'))\n : true\n : false\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true,\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\n scope={__scopeSwitch}\n checked={checked}\n disabled={disabled}\n size={size}\n >\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(\n inputProto,\n 'checked'\n ) 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,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAsB,0BAA0B;AAChD,SAAS,yBAAyB;AAClC,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,cAAc;AACvC,SAAS,4BAA4B;AACrC,YAAY,WAAW;AAGvB,MAAM,cAAc;AAGpB,MAAM,kBAAkB,CAAC,QACvB,KAAK,MAAM,iBAAiB,QAAQ,GAAG,CAAC,IAAI,IAAI;AAClD,MAAM,iBAAiB,CAAC,QAAoB,gBAAgB,GAAG,IAAI;AAEnE,MAAM,gBAAgB,mBAAmB,WAAW;AACpD,MAAM,CAAC,mBAAmB,IAAI;AACvB,MAAM,oBAAoB,cAAc,CAAC;AAEhD,MAAM,CAAC,gBAAgB,gBAAgB,IAAI,
|
|
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 getVariableValue,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { registerFocusable } from '@tamagui/focusable'\nimport { getSize } from '@tamagui/get-size'\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) =>\n 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 unstyled?: boolean\n}>(SWITCH_NAME)\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb'\n\nexport const SwitchThumbFrame = styled(ThemeableStack, {\n name: 'SwitchThumb',\n\n variants: {\n unstyled: {\n false: {\n size: '$true',\n backgroundColor: '$background',\n borderRadius: 1000,\n },\n },\n\n size: {\n '...size': (val) => {\n const size = getSwitchHeight(val)\n return {\n height: size,\n width: size,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\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, unstyled } = useSwitchContext(\n THUMB_NAME,\n __scopeSwitch\n )\n return (\n <SwitchThumbFrame\n unstyled={unstyled}\n size={size}\n theme={checked ? 'active' : null}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n {...thumbProps}\n x={\n checked\n ? getVariableValue(getSwitchWidth(size)) -\n 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_NAME,\n tag: 'button',\n\n variants: {\n unstyled: {\n false: {\n size: '$true',\n borderRadius: 1000,\n borderWidth: 2,\n borderColor: 'transparent',\n backgroundColor: '$background',\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n },\n },\n\n size: {\n '...size': (val) => {\n const height = getSwitchHeight(val) + 4\n const width = getSwitchWidth(val) + 4\n return {\n height,\n minHeight: height,\n width,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\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 = '$true',\n unstyled = false,\n ...switchProps\n } = props\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) =>\n setButton(node as any)\n )\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\n ? button\n ? Boolean(button.closest('form'))\n : true\n : false\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true,\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\n scope={__scopeSwitch}\n checked={checked}\n disabled={disabled}\n size={size}\n unstyled={unstyled}\n >\n <SwitchFrame\n unstyled={unstyled}\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(\n inputProto,\n 'checked'\n ) 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,SAAS,mBAAmB;AAC5B,SA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mjs
CHANGED
|
@@ -23,9 +23,14 @@ const [SwitchProvider, useSwitchContext] = createSwitchContext(SWITCH_NAME);
|
|
|
23
23
|
const THUMB_NAME = "SwitchThumb";
|
|
24
24
|
const SwitchThumbFrame = styled(ThemeableStack, {
|
|
25
25
|
name: "SwitchThumb",
|
|
26
|
-
backgroundColor: "$background",
|
|
27
|
-
borderRadius: 1e3,
|
|
28
26
|
variants: {
|
|
27
|
+
unstyled: {
|
|
28
|
+
false: {
|
|
29
|
+
size: "$true",
|
|
30
|
+
backgroundColor: "$background",
|
|
31
|
+
borderRadius: 1e3
|
|
32
|
+
}
|
|
33
|
+
},
|
|
29
34
|
size: {
|
|
30
35
|
"...size": (val) => {
|
|
31
36
|
const size = getSwitchHeight(val);
|
|
@@ -37,16 +42,21 @@ const SwitchThumbFrame = styled(ThemeableStack, {
|
|
|
37
42
|
}
|
|
38
43
|
},
|
|
39
44
|
defaultVariants: {
|
|
40
|
-
|
|
45
|
+
unstyled: false
|
|
41
46
|
}
|
|
42
47
|
});
|
|
43
48
|
const SwitchThumb = SwitchThumbFrame.extractable(
|
|
44
49
|
React.forwardRef(
|
|
45
50
|
(props, forwardedRef) => {
|
|
46
51
|
const { __scopeSwitch, ...thumbProps } = props;
|
|
47
|
-
const { size, disabled, checked } = useSwitchContext(
|
|
52
|
+
const { size, disabled, checked, unstyled } = useSwitchContext(
|
|
53
|
+
THUMB_NAME,
|
|
54
|
+
__scopeSwitch
|
|
55
|
+
);
|
|
48
56
|
return <SwitchThumbFrame
|
|
57
|
+
unstyled={unstyled}
|
|
49
58
|
size={size}
|
|
59
|
+
theme={checked ? "active" : null}
|
|
50
60
|
data-state={getState(checked)}
|
|
51
61
|
data-disabled={disabled ? "" : void 0}
|
|
52
62
|
{...thumbProps}
|
|
@@ -58,16 +68,21 @@ const SwitchThumb = SwitchThumbFrame.extractable(
|
|
|
58
68
|
);
|
|
59
69
|
SwitchThumb.displayName = THUMB_NAME;
|
|
60
70
|
const SwitchFrame = styled(XStack, {
|
|
61
|
-
name:
|
|
71
|
+
name: SWITCH_NAME,
|
|
62
72
|
tag: "button",
|
|
63
|
-
borderRadius: 1e3,
|
|
64
|
-
borderWidth: 2,
|
|
65
|
-
borderColor: "transparent",
|
|
66
|
-
backgroundColor: "$background",
|
|
67
|
-
focusStyle: {
|
|
68
|
-
borderColor: "$borderColorFocus"
|
|
69
|
-
},
|
|
70
73
|
variants: {
|
|
74
|
+
unstyled: {
|
|
75
|
+
false: {
|
|
76
|
+
size: "$true",
|
|
77
|
+
borderRadius: 1e3,
|
|
78
|
+
borderWidth: 2,
|
|
79
|
+
borderColor: "transparent",
|
|
80
|
+
backgroundColor: "$background",
|
|
81
|
+
focusStyle: {
|
|
82
|
+
borderColor: "$borderColorFocus"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
71
86
|
size: {
|
|
72
87
|
"...size": (val) => {
|
|
73
88
|
const height = getSwitchHeight(val) + 4;
|
|
@@ -81,7 +96,7 @@ const SwitchFrame = styled(XStack, {
|
|
|
81
96
|
}
|
|
82
97
|
},
|
|
83
98
|
defaultVariants: {
|
|
84
|
-
|
|
99
|
+
unstyled: false
|
|
85
100
|
}
|
|
86
101
|
});
|
|
87
102
|
const Switch = withStaticProperties(
|
|
@@ -99,6 +114,7 @@ const Switch = withStaticProperties(
|
|
|
99
114
|
value = "on",
|
|
100
115
|
onCheckedChange,
|
|
101
116
|
size = "$true",
|
|
117
|
+
unstyled = false,
|
|
102
118
|
...switchProps
|
|
103
119
|
} = props;
|
|
104
120
|
const [button, setButton] = React.useState(null);
|
|
@@ -132,8 +148,10 @@ const Switch = withStaticProperties(
|
|
|
132
148
|
checked={checked}
|
|
133
149
|
disabled={disabled}
|
|
134
150
|
size={size}
|
|
151
|
+
unstyled={unstyled}
|
|
135
152
|
>
|
|
136
153
|
<SwitchFrame
|
|
154
|
+
unstyled={unstyled}
|
|
137
155
|
size={size}
|
|
138
156
|
role="switch"
|
|
139
157
|
aria-checked={checked}
|
package/dist/jsx/Switch.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Switch.tsx"],
|
|
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 getVariableValue,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { registerFocusable } from '@tamagui/focusable'\nimport { getSize } from '@tamagui/get-size'\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) =>\n 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 const size = getSwitchHeight(val)\n return {\n height: size,\n width: size,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$true',\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)) -\n 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 = getSwitchHeight(val) + 4\n const width = getSwitchWidth(val) + 4\n return {\n height,\n minHeight: height,\n width,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n size: '$true',\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 = '$true',\n ...switchProps\n } = props\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) =>\n setButton(node as any)\n )\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\n ? button\n ? Boolean(button.closest('form'))\n : true\n : false\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true,\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\n scope={__scopeSwitch}\n checked={checked}\n disabled={disabled}\n size={size}\n >\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(\n inputProto,\n 'checked'\n ) 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,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAsB,0BAA0B;AAChD,SAAS,yBAAyB;AAClC,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,cAAc;AACvC,SAAS,4BAA4B;AACrC,YAAY,WAAW;AAGvB,MAAM,cAAc;AAGpB,MAAM,kBAAkB,CAAC,QACvB,KAAK,MAAM,iBAAiB,QAAQ,GAAG,CAAC,IAAI,IAAI;AAClD,MAAM,iBAAiB,CAAC,QAAoB,gBAAgB,GAAG,IAAI;AAEnE,MAAM,gBAAgB,mBAAmB,WAAW;AACpD,MAAM,CAAC,mBAAmB,IAAI;AACvB,MAAM,oBAAoB,cAAc,CAAC;AAEhD,MAAM,CAAC,gBAAgB,gBAAgB,IAAI,
|
|
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 getVariableValue,\n isWeb,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { registerFocusable } from '@tamagui/focusable'\nimport { getSize } from '@tamagui/get-size'\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) =>\n 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 unstyled?: boolean\n}>(SWITCH_NAME)\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb'\n\nexport const SwitchThumbFrame = styled(ThemeableStack, {\n name: 'SwitchThumb',\n\n variants: {\n unstyled: {\n false: {\n size: '$true',\n backgroundColor: '$background',\n borderRadius: 1000,\n },\n },\n\n size: {\n '...size': (val) => {\n const size = getSwitchHeight(val)\n return {\n height: size,\n width: size,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\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, unstyled } = useSwitchContext(\n THUMB_NAME,\n __scopeSwitch\n )\n return (\n <SwitchThumbFrame\n unstyled={unstyled}\n size={size}\n theme={checked ? 'active' : null}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n {...thumbProps}\n x={\n checked\n ? getVariableValue(getSwitchWidth(size)) -\n 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_NAME,\n tag: 'button',\n\n variants: {\n unstyled: {\n false: {\n size: '$true',\n borderRadius: 1000,\n borderWidth: 2,\n borderColor: 'transparent',\n backgroundColor: '$background',\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n },\n },\n\n size: {\n '...size': (val) => {\n const height = getSwitchHeight(val) + 4\n const width = getSwitchWidth(val) + 4\n return {\n height,\n minHeight: height,\n width,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\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 = '$true',\n unstyled = false,\n ...switchProps\n } = props\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) =>\n setButton(node as any)\n )\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\n ? button\n ? Boolean(button.closest('form'))\n : true\n : false\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n transition: true,\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\n scope={__scopeSwitch}\n checked={checked}\n disabled={disabled}\n size={size}\n unstyled={unstyled}\n >\n <SwitchFrame\n unstyled={unstyled}\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(\n inputProto,\n 'checked'\n ) 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,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAsB,0BAA0B;AAChD,SAAS,yBAAyB;AAClC,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,cAAc;AAC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,14 +24,14 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@radix-ui/react-use-previous": "^0.1.1",
|
|
27
|
-
"@tamagui/compose-refs": "^1.5.
|
|
28
|
-
"@tamagui/core": "^1.5.
|
|
29
|
-
"@tamagui/create-context": "^1.5.
|
|
30
|
-
"@tamagui/focusable": "^1.5.
|
|
31
|
-
"@tamagui/get-size": "^1.5.
|
|
32
|
-
"@tamagui/label": "^1.5.
|
|
33
|
-
"@tamagui/stacks": "^1.5.
|
|
34
|
-
"@tamagui/use-controllable-state": "^1.5.
|
|
27
|
+
"@tamagui/compose-refs": "^1.5.10",
|
|
28
|
+
"@tamagui/core": "^1.5.10",
|
|
29
|
+
"@tamagui/create-context": "^1.5.10",
|
|
30
|
+
"@tamagui/focusable": "^1.5.10",
|
|
31
|
+
"@tamagui/get-size": "^1.5.10",
|
|
32
|
+
"@tamagui/label": "^1.5.10",
|
|
33
|
+
"@tamagui/stacks": "^1.5.10",
|
|
34
|
+
"@tamagui/use-controllable-state": "^1.5.10"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"react": "*",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"react-native": "*"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@tamagui/build": "^1.5.
|
|
42
|
+
"@tamagui/build": "^1.5.10",
|
|
43
43
|
"react": "^18.2.0",
|
|
44
44
|
"react-dom": "^18.2.0",
|
|
45
45
|
"react-native": "*"
|
package/src/Switch.tsx
CHANGED
|
@@ -35,6 +35,7 @@ const [SwitchProvider, useSwitchContext] = createSwitchContext<{
|
|
|
35
35
|
checked: boolean
|
|
36
36
|
disabled?: boolean
|
|
37
37
|
size: SizeTokens
|
|
38
|
+
unstyled?: boolean
|
|
38
39
|
}>(SWITCH_NAME)
|
|
39
40
|
|
|
40
41
|
/* -------------------------------------------------------------------------------------------------
|
|
@@ -45,10 +46,16 @@ const THUMB_NAME = 'SwitchThumb'
|
|
|
45
46
|
|
|
46
47
|
export const SwitchThumbFrame = styled(ThemeableStack, {
|
|
47
48
|
name: 'SwitchThumb',
|
|
48
|
-
backgroundColor: '$background',
|
|
49
|
-
borderRadius: 1000,
|
|
50
49
|
|
|
51
50
|
variants: {
|
|
51
|
+
unstyled: {
|
|
52
|
+
false: {
|
|
53
|
+
size: '$true',
|
|
54
|
+
backgroundColor: '$background',
|
|
55
|
+
borderRadius: 1000,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
|
|
52
59
|
size: {
|
|
53
60
|
'...size': (val) => {
|
|
54
61
|
const size = getSwitchHeight(val)
|
|
@@ -61,7 +68,7 @@ export const SwitchThumbFrame = styled(ThemeableStack, {
|
|
|
61
68
|
} as const,
|
|
62
69
|
|
|
63
70
|
defaultVariants: {
|
|
64
|
-
|
|
71
|
+
unstyled: false,
|
|
65
72
|
},
|
|
66
73
|
})
|
|
67
74
|
|
|
@@ -71,10 +78,15 @@ export const SwitchThumb = SwitchThumbFrame.extractable(
|
|
|
71
78
|
React.forwardRef<React.ElementRef<'span'>, SwitchThumbProps>(
|
|
72
79
|
(props: ScopedProps<SwitchThumbProps, 'Switch'>, forwardedRef) => {
|
|
73
80
|
const { __scopeSwitch, ...thumbProps } = props
|
|
74
|
-
const { size, disabled, checked } = useSwitchContext(
|
|
81
|
+
const { size, disabled, checked, unstyled } = useSwitchContext(
|
|
82
|
+
THUMB_NAME,
|
|
83
|
+
__scopeSwitch
|
|
84
|
+
)
|
|
75
85
|
return (
|
|
76
86
|
<SwitchThumbFrame
|
|
87
|
+
unstyled={unstyled}
|
|
77
88
|
size={size}
|
|
89
|
+
theme={checked ? 'active' : null}
|
|
78
90
|
data-state={getState(checked)}
|
|
79
91
|
data-disabled={disabled ? '' : undefined}
|
|
80
92
|
{...thumbProps}
|
|
@@ -98,18 +110,24 @@ SwitchThumb.displayName = THUMB_NAME
|
|
|
98
110
|
* -----------------------------------------------------------------------------------------------*/
|
|
99
111
|
|
|
100
112
|
export const SwitchFrame = styled(XStack, {
|
|
101
|
-
name:
|
|
113
|
+
name: SWITCH_NAME,
|
|
102
114
|
tag: 'button',
|
|
103
|
-
borderRadius: 1000,
|
|
104
|
-
borderWidth: 2,
|
|
105
|
-
borderColor: 'transparent',
|
|
106
|
-
backgroundColor: '$background',
|
|
107
|
-
|
|
108
|
-
focusStyle: {
|
|
109
|
-
borderColor: '$borderColorFocus',
|
|
110
|
-
},
|
|
111
115
|
|
|
112
116
|
variants: {
|
|
117
|
+
unstyled: {
|
|
118
|
+
false: {
|
|
119
|
+
size: '$true',
|
|
120
|
+
borderRadius: 1000,
|
|
121
|
+
borderWidth: 2,
|
|
122
|
+
borderColor: 'transparent',
|
|
123
|
+
backgroundColor: '$background',
|
|
124
|
+
|
|
125
|
+
focusStyle: {
|
|
126
|
+
borderColor: '$borderColorFocus',
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
|
|
113
131
|
size: {
|
|
114
132
|
'...size': (val) => {
|
|
115
133
|
const height = getSwitchHeight(val) + 4
|
|
@@ -124,7 +142,7 @@ export const SwitchFrame = styled(XStack, {
|
|
|
124
142
|
} as const,
|
|
125
143
|
|
|
126
144
|
defaultVariants: {
|
|
127
|
-
|
|
145
|
+
unstyled: false,
|
|
128
146
|
},
|
|
129
147
|
})
|
|
130
148
|
|
|
@@ -155,6 +173,7 @@ export const Switch = withStaticProperties(
|
|
|
155
173
|
value = 'on',
|
|
156
174
|
onCheckedChange,
|
|
157
175
|
size = '$true',
|
|
176
|
+
unstyled = false,
|
|
158
177
|
...switchProps
|
|
159
178
|
} = props
|
|
160
179
|
const [button, setButton] = React.useState<HTMLButtonElement | null>(null)
|
|
@@ -195,8 +214,10 @@ export const Switch = withStaticProperties(
|
|
|
195
214
|
checked={checked}
|
|
196
215
|
disabled={disabled}
|
|
197
216
|
size={size}
|
|
217
|
+
unstyled={unstyled}
|
|
198
218
|
>
|
|
199
219
|
<SwitchFrame
|
|
220
|
+
unstyled={unstyled}
|
|
200
221
|
size={size}
|
|
201
222
|
// @ts-ignore
|
|
202
223
|
role="switch"
|
package/types/Switch.d.ts
CHANGED
|
@@ -17,7 +17,8 @@ export declare const SwitchThumbFrame: import("@tamagui/core").TamaguiComponent<
|
|
|
17
17
|
readonly bordered?: number | boolean | undefined;
|
|
18
18
|
readonly transparent?: boolean | undefined;
|
|
19
19
|
readonly chromeless?: boolean | "all" | undefined;
|
|
20
|
-
}, "size"> & {
|
|
20
|
+
}, "size" | "unstyled"> & {
|
|
21
|
+
readonly unstyled?: boolean | undefined;
|
|
21
22
|
readonly size?: SizeTokens | undefined;
|
|
22
23
|
} & import("@tamagui/core").MediaProps<Partial<Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps & Omit<{
|
|
23
24
|
readonly fullscreen?: boolean | undefined;
|
|
@@ -34,7 +35,8 @@ export declare const SwitchThumbFrame: import("@tamagui/core").TamaguiComponent<
|
|
|
34
35
|
readonly bordered?: number | boolean | undefined;
|
|
35
36
|
readonly transparent?: boolean | undefined;
|
|
36
37
|
readonly chromeless?: boolean | "all" | undefined;
|
|
37
|
-
}, "size"> & {
|
|
38
|
+
}, "size" | "unstyled"> & {
|
|
39
|
+
readonly unstyled?: boolean | undefined;
|
|
38
40
|
readonly size?: SizeTokens | undefined;
|
|
39
41
|
}>> & import("@tamagui/core").PseudoProps<Partial<Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps & Omit<{
|
|
40
42
|
readonly fullscreen?: boolean | undefined;
|
|
@@ -51,7 +53,8 @@ export declare const SwitchThumbFrame: import("@tamagui/core").TamaguiComponent<
|
|
|
51
53
|
readonly bordered?: number | boolean | undefined;
|
|
52
54
|
readonly transparent?: boolean | undefined;
|
|
53
55
|
readonly chromeless?: boolean | "all" | undefined;
|
|
54
|
-
}, "size"> & {
|
|
56
|
+
}, "size" | "unstyled"> & {
|
|
57
|
+
readonly unstyled?: boolean | undefined;
|
|
55
58
|
readonly size?: SizeTokens | undefined;
|
|
56
59
|
}>>, import("@tamagui/core").TamaguiElement, Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps, {
|
|
57
60
|
readonly fullscreen?: boolean | undefined;
|
|
@@ -69,6 +72,7 @@ export declare const SwitchThumbFrame: import("@tamagui/core").TamaguiComponent<
|
|
|
69
72
|
readonly transparent?: boolean | undefined;
|
|
70
73
|
readonly chromeless?: boolean | "all" | undefined;
|
|
71
74
|
} & {
|
|
75
|
+
readonly unstyled?: boolean | undefined;
|
|
72
76
|
readonly size?: SizeTokens | undefined;
|
|
73
77
|
}>;
|
|
74
78
|
export type SwitchThumbProps = GetProps<typeof SwitchThumbFrame>;
|
|
@@ -87,7 +91,8 @@ export declare const SwitchThumb: React.ForwardRefExoticComponent<Omit<import("r
|
|
|
87
91
|
readonly bordered?: number | boolean | undefined;
|
|
88
92
|
readonly transparent?: boolean | undefined;
|
|
89
93
|
readonly chromeless?: boolean | "all" | undefined;
|
|
90
|
-
}, "size"> & {
|
|
94
|
+
}, "size" | "unstyled"> & {
|
|
95
|
+
readonly unstyled?: boolean | undefined;
|
|
91
96
|
readonly size?: SizeTokens | undefined;
|
|
92
97
|
} & import("@tamagui/core").MediaProps<Partial<Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps & Omit<{
|
|
93
98
|
readonly fullscreen?: boolean | undefined;
|
|
@@ -104,7 +109,8 @@ export declare const SwitchThumb: React.ForwardRefExoticComponent<Omit<import("r
|
|
|
104
109
|
readonly bordered?: number | boolean | undefined;
|
|
105
110
|
readonly transparent?: boolean | undefined;
|
|
106
111
|
readonly chromeless?: boolean | "all" | undefined;
|
|
107
|
-
}, "size"> & {
|
|
112
|
+
}, "size" | "unstyled"> & {
|
|
113
|
+
readonly unstyled?: boolean | undefined;
|
|
108
114
|
readonly size?: SizeTokens | undefined;
|
|
109
115
|
}>> & import("@tamagui/core").PseudoProps<Partial<Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps & Omit<{
|
|
110
116
|
readonly fullscreen?: boolean | undefined;
|
|
@@ -121,28 +127,33 @@ export declare const SwitchThumb: React.ForwardRefExoticComponent<Omit<import("r
|
|
|
121
127
|
readonly bordered?: number | boolean | undefined;
|
|
122
128
|
readonly transparent?: boolean | undefined;
|
|
123
129
|
readonly chromeless?: boolean | "all" | undefined;
|
|
124
|
-
}, "size"> & {
|
|
130
|
+
}, "size" | "unstyled"> & {
|
|
131
|
+
readonly unstyled?: boolean | undefined;
|
|
125
132
|
readonly size?: SizeTokens | undefined;
|
|
126
133
|
}>> & React.RefAttributes<HTMLSpanElement>>;
|
|
127
134
|
export declare const SwitchFrame: import("@tamagui/core").TamaguiComponent<Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps & Omit<{
|
|
128
135
|
readonly fullscreen?: boolean | undefined;
|
|
129
136
|
readonly elevation?: SizeTokens | undefined;
|
|
130
|
-
}, "size"> & {
|
|
137
|
+
}, "size" | "unstyled"> & {
|
|
138
|
+
readonly unstyled?: boolean | undefined;
|
|
131
139
|
readonly size?: SizeTokens | undefined;
|
|
132
140
|
} & import("@tamagui/core").MediaProps<Partial<Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps & Omit<{
|
|
133
141
|
readonly fullscreen?: boolean | undefined;
|
|
134
142
|
readonly elevation?: SizeTokens | undefined;
|
|
135
|
-
}, "size"> & {
|
|
143
|
+
}, "size" | "unstyled"> & {
|
|
144
|
+
readonly unstyled?: boolean | undefined;
|
|
136
145
|
readonly size?: SizeTokens | undefined;
|
|
137
146
|
}>> & import("@tamagui/core").PseudoProps<Partial<Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps & Omit<{
|
|
138
147
|
readonly fullscreen?: boolean | undefined;
|
|
139
148
|
readonly elevation?: SizeTokens | undefined;
|
|
140
|
-
}, "size"> & {
|
|
149
|
+
}, "size" | "unstyled"> & {
|
|
150
|
+
readonly unstyled?: boolean | undefined;
|
|
141
151
|
readonly size?: SizeTokens | undefined;
|
|
142
152
|
}>>, import("@tamagui/core").TamaguiElement, Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps, {
|
|
143
153
|
readonly fullscreen?: boolean | undefined;
|
|
144
154
|
readonly elevation?: SizeTokens | undefined;
|
|
145
155
|
} & {
|
|
156
|
+
readonly unstyled?: boolean | undefined;
|
|
146
157
|
readonly size?: SizeTokens | undefined;
|
|
147
158
|
}>;
|
|
148
159
|
type SwitchButtonProps = GetProps<typeof SwitchFrame>;
|
|
@@ -158,17 +169,20 @@ export type SwitchProps = SwitchButtonProps & {
|
|
|
158
169
|
export declare const Switch: React.ForwardRefExoticComponent<Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps & Omit<{
|
|
159
170
|
readonly fullscreen?: boolean | undefined;
|
|
160
171
|
readonly elevation?: SizeTokens | undefined;
|
|
161
|
-
}, "size"> & {
|
|
172
|
+
}, "size" | "unstyled"> & {
|
|
173
|
+
readonly unstyled?: boolean | undefined;
|
|
162
174
|
readonly size?: SizeTokens | undefined;
|
|
163
175
|
} & import("@tamagui/core").MediaProps<Partial<Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps & Omit<{
|
|
164
176
|
readonly fullscreen?: boolean | undefined;
|
|
165
177
|
readonly elevation?: SizeTokens | undefined;
|
|
166
|
-
}, "size"> & {
|
|
178
|
+
}, "size" | "unstyled"> & {
|
|
179
|
+
readonly unstyled?: boolean | undefined;
|
|
167
180
|
readonly size?: SizeTokens | undefined;
|
|
168
181
|
}>> & import("@tamagui/core").PseudoProps<Partial<Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps & Omit<{
|
|
169
182
|
readonly fullscreen?: boolean | undefined;
|
|
170
183
|
readonly elevation?: SizeTokens | undefined;
|
|
171
|
-
}, "size"> & {
|
|
184
|
+
}, "size" | "unstyled"> & {
|
|
185
|
+
readonly unstyled?: boolean | undefined;
|
|
172
186
|
readonly size?: SizeTokens | undefined;
|
|
173
187
|
}>> & {
|
|
174
188
|
labeledBy?: string | undefined;
|
|
@@ -194,7 +208,8 @@ export declare const Switch: React.ForwardRefExoticComponent<Omit<import("react-
|
|
|
194
208
|
readonly bordered?: number | boolean | undefined;
|
|
195
209
|
readonly transparent?: boolean | undefined;
|
|
196
210
|
readonly chromeless?: boolean | "all" | undefined;
|
|
197
|
-
}, "size"> & {
|
|
211
|
+
}, "size" | "unstyled"> & {
|
|
212
|
+
readonly unstyled?: boolean | undefined;
|
|
198
213
|
readonly size?: SizeTokens | undefined;
|
|
199
214
|
} & import("@tamagui/core").MediaProps<Partial<Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps & Omit<{
|
|
200
215
|
readonly fullscreen?: boolean | undefined;
|
|
@@ -211,7 +226,8 @@ export declare const Switch: React.ForwardRefExoticComponent<Omit<import("react-
|
|
|
211
226
|
readonly bordered?: number | boolean | undefined;
|
|
212
227
|
readonly transparent?: boolean | undefined;
|
|
213
228
|
readonly chromeless?: boolean | "all" | undefined;
|
|
214
|
-
}, "size"> & {
|
|
229
|
+
}, "size" | "unstyled"> & {
|
|
230
|
+
readonly unstyled?: boolean | undefined;
|
|
215
231
|
readonly size?: SizeTokens | undefined;
|
|
216
232
|
}>> & import("@tamagui/core").PseudoProps<Partial<Omit<import("react-native").ViewProps, "display" | "children" | "onLayout" | keyof import("react-native").GestureResponderHandlers> & import("@tamagui/core").ExtendBaseStackProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStylePropsBase>> & import("@tamagui/core/types/reactNativeTypes").RNViewProps & Omit<{
|
|
217
233
|
readonly fullscreen?: boolean | undefined;
|
|
@@ -228,7 +244,8 @@ export declare const Switch: React.ForwardRefExoticComponent<Omit<import("react-
|
|
|
228
244
|
readonly bordered?: number | boolean | undefined;
|
|
229
245
|
readonly transparent?: boolean | undefined;
|
|
230
246
|
readonly chromeless?: boolean | "all" | undefined;
|
|
231
|
-
}, "size"> & {
|
|
247
|
+
}, "size" | "unstyled"> & {
|
|
248
|
+
readonly unstyled?: boolean | undefined;
|
|
232
249
|
readonly size?: SizeTokens | undefined;
|
|
233
250
|
}>> & React.RefAttributes<HTMLSpanElement>>;
|
|
234
251
|
};
|
package/types/Switch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../src/Switch.tsx"],"names":[],"mappings":"AAKA,OAAO,EACL,QAAQ,EACR,UAAU,EAKX,MAAM,eAAe,CAAA;AAOtB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAWnC,eAAO,MAAM,iBAAiB,+CAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../src/Switch.tsx"],"names":[],"mappings":"AAKA,OAAO,EACL,QAAQ,EACR,UAAU,EAKX,MAAM,eAAe,CAAA;AAOtB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAWnC,eAAO,MAAM,iBAAiB,+CAAmB,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