@tamagui/toggle-group 1.14.1 → 1.14.3
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/Toggle.js +130 -1
- package/dist/cjs/Toggle.js.map +2 -2
- package/dist/cjs/ToggleGroup.js +341 -1
- package/dist/cjs/ToggleGroup.js.map +2 -2
- package/dist/cjs/index.js +18 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/Toggle.js +95 -1
- package/dist/esm/Toggle.js.map +2 -2
- package/dist/esm/Toggle.mjs +95 -1
- package/dist/esm/Toggle.mjs.map +2 -2
- package/dist/esm/ToggleGroup.js +312 -1
- package/dist/esm/ToggleGroup.js.map +2 -2
- package/dist/esm/ToggleGroup.mjs +312 -1
- package/dist/esm/ToggleGroup.mjs.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/jsx/Toggle.js +91 -1
- package/dist/jsx/Toggle.js.map +2 -2
- package/dist/jsx/Toggle.mjs +91 -1
- package/dist/jsx/Toggle.mjs.map +2 -2
- package/dist/jsx/ToggleGroup.js +278 -1
- package/dist/jsx/ToggleGroup.js.map +2 -2
- package/dist/jsx/ToggleGroup.mjs +278 -1
- package/dist/jsx/ToggleGroup.mjs.map +2 -2
- package/dist/jsx/index.js +1 -1
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +1 -1
- package/dist/jsx/index.mjs.map +1 -1
- package/package.json +13 -13
package/dist/cjs/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["export * from './ToggleGroup'\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,0BAAd;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
package/dist/esm/Toggle.js
CHANGED
|
@@ -1,2 +1,96 @@
|
|
|
1
|
-
import{jsx
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ThemeableStack } from "@tamagui/stacks";
|
|
3
|
+
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
4
|
+
import { Theme, composeEventHandlers, styled } from "@tamagui/web";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
const NAME = "Toggle";
|
|
7
|
+
const ToggleFrame = styled(ThemeableStack, {
|
|
8
|
+
name: NAME,
|
|
9
|
+
tag: "button",
|
|
10
|
+
variants: {
|
|
11
|
+
unstyled: {
|
|
12
|
+
false: {
|
|
13
|
+
pressTheme: true,
|
|
14
|
+
backgroundColor: "$background",
|
|
15
|
+
alignItems: "center",
|
|
16
|
+
justifyContent: "center",
|
|
17
|
+
display: "flex",
|
|
18
|
+
borderColor: "$borderColor",
|
|
19
|
+
borderWidth: "1px",
|
|
20
|
+
margin: "-1px",
|
|
21
|
+
hoverStyle: {
|
|
22
|
+
backgroundColor: "$backgroundHover"
|
|
23
|
+
},
|
|
24
|
+
pressStyle: {
|
|
25
|
+
backgroundColor: "$backgroundPress"
|
|
26
|
+
},
|
|
27
|
+
focusStyle: {
|
|
28
|
+
borderColor: "$borderColorPress",
|
|
29
|
+
backgroundColor: "$backgroundPress"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
active: {
|
|
34
|
+
true: {
|
|
35
|
+
zIndex: 1,
|
|
36
|
+
hoverStyle: {
|
|
37
|
+
backgroundColor: "$background"
|
|
38
|
+
},
|
|
39
|
+
focusStyle: {
|
|
40
|
+
borderColor: "$borderColorPress",
|
|
41
|
+
backgroundColor: "$backgroundPress"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
orientation: {
|
|
46
|
+
horizontal: {
|
|
47
|
+
flexDirection: "row",
|
|
48
|
+
spaceDirection: "horizontal"
|
|
49
|
+
},
|
|
50
|
+
vertical: {
|
|
51
|
+
flexDirection: "column",
|
|
52
|
+
spaceDirection: "vertical"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
defaultVariants: {
|
|
57
|
+
unstyled: false
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const Toggle = ToggleFrame.extractable(
|
|
61
|
+
React.forwardRef((props, forwardedRef) => {
|
|
62
|
+
const {
|
|
63
|
+
pressed: pressedProp,
|
|
64
|
+
defaultPressed = false,
|
|
65
|
+
onPressedChange,
|
|
66
|
+
...buttonProps
|
|
67
|
+
} = props;
|
|
68
|
+
const [pressed = false, setPressed] = useControllableState({
|
|
69
|
+
prop: pressedProp,
|
|
70
|
+
onChange: onPressedChange,
|
|
71
|
+
defaultProp: defaultPressed
|
|
72
|
+
});
|
|
73
|
+
return /* @__PURE__ */ jsx(Theme, { forceClassName: true, name: pressed ? "active" : null, children: /* @__PURE__ */ jsx(
|
|
74
|
+
ToggleFrame,
|
|
75
|
+
{
|
|
76
|
+
active: !props.unstyled ? pressed : void 0,
|
|
77
|
+
"aria-pressed": pressed,
|
|
78
|
+
"data-state": pressed ? "on" : "off",
|
|
79
|
+
"data-disabled": props.disabled ? "" : void 0,
|
|
80
|
+
...buttonProps,
|
|
81
|
+
ref: forwardedRef,
|
|
82
|
+
onPress: composeEventHandlers(props.onPress ?? void 0, (event) => {
|
|
83
|
+
if (!props.disabled) {
|
|
84
|
+
setPressed(!pressed);
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
) });
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
Toggle.displayName = NAME;
|
|
92
|
+
export {
|
|
93
|
+
Toggle,
|
|
94
|
+
ToggleFrame
|
|
95
|
+
};
|
|
2
96
|
//# sourceMappingURL=Toggle.js.map
|
package/dist/esm/Toggle.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Toggle.tsx"],
|
|
4
4
|
"sourcesContent": ["import { ThemeableStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport { GetProps, Theme, composeEventHandlers, isWeb, styled } from '@tamagui/web'\nimport * as React from 'react'\n\n/* -------------------------------------------------------------------------------------------------\n * Toggle\n * -----------------------------------------------------------------------------------------------*/\n\nconst NAME = 'Toggle'\n\ntype TamaguiButtonElement = HTMLButtonElement\n\ntype ToggleElement = TamaguiButtonElement\n\nconst ToggleFrame = styled(ThemeableStack, {\n name: NAME,\n tag: 'button',\n\n variants: {\n unstyled: {\n false: {\n pressTheme: true,\n backgroundColor: '$background',\n alignItems: 'center',\n justifyContent: 'center',\n display: 'flex',\n borderColor: '$borderColor',\n borderWidth: '1px',\n margin: '-1px',\n hoverStyle: {\n backgroundColor: '$backgroundHover',\n },\n pressStyle: {\n backgroundColor: '$backgroundPress',\n },\n focusStyle: {\n borderColor: '$borderColorPress',\n backgroundColor: '$backgroundPress',\n },\n },\n },\n active: {\n true: {\n zIndex: 1,\n hoverStyle: {\n backgroundColor: '$background',\n },\n focusStyle: {\n borderColor: '$borderColorPress',\n backgroundColor: '$backgroundPress',\n },\n },\n },\n orientation: {\n horizontal: {\n flexDirection: 'row',\n spaceDirection: 'horizontal',\n },\n vertical: {\n flexDirection: 'column',\n spaceDirection: 'vertical',\n },\n },\n } as const,\n defaultVariants: {\n unstyled: false,\n },\n})\n\ntype ToggleFrameProps = GetProps<typeof ToggleFrame>\n\ntype ToggleProps = ToggleFrameProps & {\n defaultValue?: string\n disabled?: boolean\n pressed?: boolean\n defaultPressed?: boolean\n onPressedChange?(pressed: boolean): void\n}\n\nconst Toggle = ToggleFrame.extractable(\n React.forwardRef<ToggleElement, ToggleProps>((props, forwardedRef) => {\n const {\n pressed: pressedProp,\n defaultPressed = false,\n onPressedChange,\n ...buttonProps\n } = props\n\n const [pressed = false, setPressed] = useControllableState({\n prop: pressedProp,\n onChange: onPressedChange,\n defaultProp: defaultPressed,\n })\n\n return (\n <Theme forceClassName name={pressed ? 'active' : null}>\n <ToggleFrame\n active={!props.unstyled ? pressed : undefined}\n aria-pressed={pressed}\n data-state={pressed ? 'on' : 'off'}\n data-disabled={props.disabled ? '' : undefined}\n {...buttonProps}\n ref={forwardedRef}\n onPress={composeEventHandlers(props.onPress ?? undefined, (event) => {\n if (!props.disabled) {\n setPressed(!pressed)\n }\n })}\n // caught by onPress - no need for this\n // {...(isWeb && {\n // onKeyDown: composeEventHandlers(\n // (props as React.HTMLProps<HTMLButtonElement>).onKeyDown,\n // (event) => {\n // if ([' ', 'Enter'].includes(event.key)) {\n // if (!props.disabled) {\n // setPressed(!pressed)\n // }\n // }\n // }\n // ),\n // })}\n />\n </Theme>\n )\n })\n)\nToggle.displayName = NAME\n\n/* ---------------------------------------------------------------------------------------------- */\n\nexport { Toggle, ToggleFrame }\nexport type { ToggleProps }\n"],
|
|
5
|
-
"mappings": "AAiGQ,
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": "AAiGQ;AAjGR,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B;AACrC,SAAmB,OAAO,sBAA6B,cAAc;AACrE,YAAY,WAAW;AAMvB,MAAM,OAAO;AAMb,MAAM,cAAc,OAAO,gBAAgB;AAAA,EACzC,MAAM;AAAA,EACN,KAAK;AAAA,EAEL,UAAU;AAAA,IACR,UAAU;AAAA,MACR,OAAO;AAAA,QACL,YAAY;AAAA,QACZ,iBAAiB;AAAA,QACjB,YAAY;AAAA,QACZ,gBAAgB;AAAA,QAChB,SAAS;AAAA,QACT,aAAa;AAAA,QACb,aAAa;AAAA,QACb,QAAQ;AAAA,QACR,YAAY;AAAA,UACV,iBAAiB;AAAA,QACnB;AAAA,QACA,YAAY;AAAA,UACV,iBAAiB;AAAA,QACnB;AAAA,QACA,YAAY;AAAA,UACV,aAAa;AAAA,UACb,iBAAiB;AAAA,QACnB;AAAA,MACF;AAAA,IACF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 @@
|
|
|
1
|
-
import{jsx
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ThemeableStack } from "@tamagui/stacks";
|
|
3
|
+
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
4
|
+
import { Theme, composeEventHandlers, styled } from "@tamagui/web";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
const NAME = "Toggle";
|
|
7
|
+
const ToggleFrame = styled(ThemeableStack, {
|
|
8
|
+
name: NAME,
|
|
9
|
+
tag: "button",
|
|
10
|
+
variants: {
|
|
11
|
+
unstyled: {
|
|
12
|
+
false: {
|
|
13
|
+
pressTheme: true,
|
|
14
|
+
backgroundColor: "$background",
|
|
15
|
+
alignItems: "center",
|
|
16
|
+
justifyContent: "center",
|
|
17
|
+
display: "flex",
|
|
18
|
+
borderColor: "$borderColor",
|
|
19
|
+
borderWidth: "1px",
|
|
20
|
+
margin: "-1px",
|
|
21
|
+
hoverStyle: {
|
|
22
|
+
backgroundColor: "$backgroundHover"
|
|
23
|
+
},
|
|
24
|
+
pressStyle: {
|
|
25
|
+
backgroundColor: "$backgroundPress"
|
|
26
|
+
},
|
|
27
|
+
focusStyle: {
|
|
28
|
+
borderColor: "$borderColorPress",
|
|
29
|
+
backgroundColor: "$backgroundPress"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
active: {
|
|
34
|
+
true: {
|
|
35
|
+
zIndex: 1,
|
|
36
|
+
hoverStyle: {
|
|
37
|
+
backgroundColor: "$background"
|
|
38
|
+
},
|
|
39
|
+
focusStyle: {
|
|
40
|
+
borderColor: "$borderColorPress",
|
|
41
|
+
backgroundColor: "$backgroundPress"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
orientation: {
|
|
46
|
+
horizontal: {
|
|
47
|
+
flexDirection: "row",
|
|
48
|
+
spaceDirection: "horizontal"
|
|
49
|
+
},
|
|
50
|
+
vertical: {
|
|
51
|
+
flexDirection: "column",
|
|
52
|
+
spaceDirection: "vertical"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
defaultVariants: {
|
|
57
|
+
unstyled: false
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const Toggle = ToggleFrame.extractable(
|
|
61
|
+
React.forwardRef((props, forwardedRef) => {
|
|
62
|
+
const {
|
|
63
|
+
pressed: pressedProp,
|
|
64
|
+
defaultPressed = false,
|
|
65
|
+
onPressedChange,
|
|
66
|
+
...buttonProps
|
|
67
|
+
} = props;
|
|
68
|
+
const [pressed = false, setPressed] = useControllableState({
|
|
69
|
+
prop: pressedProp,
|
|
70
|
+
onChange: onPressedChange,
|
|
71
|
+
defaultProp: defaultPressed
|
|
72
|
+
});
|
|
73
|
+
return /* @__PURE__ */ jsx(Theme, { forceClassName: true, name: pressed ? "active" : null, children: /* @__PURE__ */ jsx(
|
|
74
|
+
ToggleFrame,
|
|
75
|
+
{
|
|
76
|
+
active: !props.unstyled ? pressed : void 0,
|
|
77
|
+
"aria-pressed": pressed,
|
|
78
|
+
"data-state": pressed ? "on" : "off",
|
|
79
|
+
"data-disabled": props.disabled ? "" : void 0,
|
|
80
|
+
...buttonProps,
|
|
81
|
+
ref: forwardedRef,
|
|
82
|
+
onPress: composeEventHandlers(props.onPress ?? void 0, (event) => {
|
|
83
|
+
if (!props.disabled) {
|
|
84
|
+
setPressed(!pressed);
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
) });
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
Toggle.displayName = NAME;
|
|
92
|
+
export {
|
|
93
|
+
Toggle,
|
|
94
|
+
ToggleFrame
|
|
95
|
+
};
|
|
2
96
|
//# sourceMappingURL=Toggle.mjs.map
|
package/dist/esm/Toggle.mjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Toggle.tsx"],
|
|
4
4
|
"sourcesContent": ["import { ThemeableStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport { GetProps, Theme, composeEventHandlers, isWeb, styled } from '@tamagui/web'\nimport * as React from 'react'\n\n/* -------------------------------------------------------------------------------------------------\n * Toggle\n * -----------------------------------------------------------------------------------------------*/\n\nconst NAME = 'Toggle'\n\ntype TamaguiButtonElement = HTMLButtonElement\n\ntype ToggleElement = TamaguiButtonElement\n\nconst ToggleFrame = styled(ThemeableStack, {\n name: NAME,\n tag: 'button',\n\n variants: {\n unstyled: {\n false: {\n pressTheme: true,\n backgroundColor: '$background',\n alignItems: 'center',\n justifyContent: 'center',\n display: 'flex',\n borderColor: '$borderColor',\n borderWidth: '1px',\n margin: '-1px',\n hoverStyle: {\n backgroundColor: '$backgroundHover',\n },\n pressStyle: {\n backgroundColor: '$backgroundPress',\n },\n focusStyle: {\n borderColor: '$borderColorPress',\n backgroundColor: '$backgroundPress',\n },\n },\n },\n active: {\n true: {\n zIndex: 1,\n hoverStyle: {\n backgroundColor: '$background',\n },\n focusStyle: {\n borderColor: '$borderColorPress',\n backgroundColor: '$backgroundPress',\n },\n },\n },\n orientation: {\n horizontal: {\n flexDirection: 'row',\n spaceDirection: 'horizontal',\n },\n vertical: {\n flexDirection: 'column',\n spaceDirection: 'vertical',\n },\n },\n } as const,\n defaultVariants: {\n unstyled: false,\n },\n})\n\ntype ToggleFrameProps = GetProps<typeof ToggleFrame>\n\ntype ToggleProps = ToggleFrameProps & {\n defaultValue?: string\n disabled?: boolean\n pressed?: boolean\n defaultPressed?: boolean\n onPressedChange?(pressed: boolean): void\n}\n\nconst Toggle = ToggleFrame.extractable(\n React.forwardRef<ToggleElement, ToggleProps>((props, forwardedRef) => {\n const {\n pressed: pressedProp,\n defaultPressed = false,\n onPressedChange,\n ...buttonProps\n } = props\n\n const [pressed = false, setPressed] = useControllableState({\n prop: pressedProp,\n onChange: onPressedChange,\n defaultProp: defaultPressed,\n })\n\n return (\n <Theme forceClassName name={pressed ? 'active' : null}>\n <ToggleFrame\n active={!props.unstyled ? pressed : undefined}\n aria-pressed={pressed}\n data-state={pressed ? 'on' : 'off'}\n data-disabled={props.disabled ? '' : undefined}\n {...buttonProps}\n ref={forwardedRef}\n onPress={composeEventHandlers(props.onPress ?? undefined, (event) => {\n if (!props.disabled) {\n setPressed(!pressed)\n }\n })}\n // caught by onPress - no need for this\n // {...(isWeb && {\n // onKeyDown: composeEventHandlers(\n // (props as React.HTMLProps<HTMLButtonElement>).onKeyDown,\n // (event) => {\n // if ([' ', 'Enter'].includes(event.key)) {\n // if (!props.disabled) {\n // setPressed(!pressed)\n // }\n // }\n // }\n // ),\n // })}\n />\n </Theme>\n )\n })\n)\nToggle.displayName = NAME\n\n/* ---------------------------------------------------------------------------------------------- */\n\nexport { Toggle, ToggleFrame }\nexport type { ToggleProps }\n"],
|
|
5
|
-
"mappings": "AAiGQ,
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": "AAiGQ;AAjGR,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B;AACrC,SAAmB,OAAO,sBAA6B,cAAc;AACrE,YAAY,WAAW;AAMvB,MAAM,OAAO;AAMb,MAAM,cAAc,OAAO,gBAAgB;AAAA,EACzC,MAAM;AAAA,EACN,KAAK;AAAA,EAEL,UAAU;AAAA,IACR,UAAU;AAAA,MACR,OAAO;AAAA,QACL,YAAY;AAAA,QACZ,iBAAiB;AAAA,QACjB,YAAY;AAAA,QACZ,gBAAgB;AAAA,QAChB,SAAS;AAAA,QACT,aAAa;AAAA,QACb,aAAa;AAAA,QACb,QAAQ;AAAA,QACR,YAAY;AAAA,UACV,iBAAiB;AAAA,QACnB;AAAA,QACA,YAAY;AAAA,UACV,iBAAiB;AAAA,QACnB;AAAA,QACA,YAAY;AAAA,UACV,aAAa;AAAA,UACb,iBAAiB;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AAAA,IACA,QAAQ;AAAA,MACN,MAAM;AAAA,QACJ,QAAQ;AAAA,QACR,YAAY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
+
import { createContextScope } from "@tamagui/create-context";
|
|
3
|
+
import { registerFocusable } from "@tamagui/focusable";
|
|
4
|
+
import { getFontSize } from "@tamagui/font-size";
|
|
5
|
+
import { stepTokenUpOrDown } from "@tamagui/get-size";
|
|
6
|
+
import { Group, useGroupItem } from "@tamagui/group";
|
|
7
|
+
import { useGetThemedIcon } from "@tamagui/helpers-tamagui";
|
|
8
|
+
import { RovingFocusGroup, createRovingFocusGroupScope } from "@tamagui/roving-focus";
|
|
9
|
+
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
10
|
+
import { useDirection } from "@tamagui/use-direction";
|
|
11
|
+
import {
|
|
12
|
+
getVariableValue,
|
|
13
|
+
isWeb,
|
|
14
|
+
styled,
|
|
15
|
+
useTheme,
|
|
16
|
+
withStaticProperties
|
|
17
|
+
} from "@tamagui/web";
|
|
18
|
+
import React from "react";
|
|
19
|
+
import { Toggle, ToggleFrame } from "./Toggle";
|
|
20
|
+
const TOGGLE_GROUP_NAME = "ToggleGroup";
|
|
21
|
+
const [createToggleGroupContext, createToggleGroupScope] = createContextScope(
|
|
22
|
+
TOGGLE_GROUP_NAME,
|
|
23
|
+
[createRovingFocusGroupScope]
|
|
24
|
+
);
|
|
25
|
+
const TOGGLE_GROUP_ITEM_NAME = "ToggleGroupItem";
|
|
26
|
+
const [createToggleGroupItemContext, createToggleGroupItemScope] = createContextScope(TOGGLE_GROUP_ITEM_NAME);
|
|
27
|
+
const [ToggleGroupItemProvider, useToggleGroupItemContext] = createToggleGroupContext(TOGGLE_GROUP_NAME);
|
|
28
|
+
const useToggleGroupItemScope = createToggleGroupItemScope();
|
|
29
|
+
const ToggleGroupItem = ToggleFrame.extractable(
|
|
30
|
+
React.forwardRef(
|
|
31
|
+
(props, forwardedRef) => {
|
|
32
|
+
const valueContext = useToggleGroupValueContext(
|
|
33
|
+
TOGGLE_GROUP_ITEM_NAME,
|
|
34
|
+
props.__scopeToggleGroup
|
|
35
|
+
);
|
|
36
|
+
const context = useToggleGroupContext(
|
|
37
|
+
TOGGLE_GROUP_ITEM_NAME,
|
|
38
|
+
props.__scopeToggleGroup
|
|
39
|
+
);
|
|
40
|
+
const __scopeToggleGroup = props.__scopeToggleGroup;
|
|
41
|
+
const rovingFocusGroupScope = useRovingFocusGroupScope(props.__scopeToggleGroup);
|
|
42
|
+
const pressed = valueContext.value.includes(props.value);
|
|
43
|
+
const disabled = context.disabled || props.disabled || false;
|
|
44
|
+
const ref = React.useRef(null);
|
|
45
|
+
const groupItemProps = useGroupItem({ disabled });
|
|
46
|
+
const size = props.size ?? context.size;
|
|
47
|
+
const sizeProps = {
|
|
48
|
+
width: void 0,
|
|
49
|
+
height: void 0,
|
|
50
|
+
padding: getVariableValue(size) * 0.6
|
|
51
|
+
};
|
|
52
|
+
if (props.orientation === "horizontal")
|
|
53
|
+
sizeProps.height = getVariableValue(size) * 2.4;
|
|
54
|
+
else
|
|
55
|
+
sizeProps.width = getVariableValue(size) * 2.4;
|
|
56
|
+
const iconSize = (typeof size === "number" ? size * 0.7 : getFontSize(size)) * 1.2;
|
|
57
|
+
const theme = useTheme();
|
|
58
|
+
const getThemedIcon = useGetThemedIcon({ size: iconSize, color: theme.color });
|
|
59
|
+
const childrens = React.Children.toArray(props.children);
|
|
60
|
+
const children = childrens.map((child) => {
|
|
61
|
+
if (props.disablePassStyles || !React.isValidElement(child)) {
|
|
62
|
+
return child;
|
|
63
|
+
}
|
|
64
|
+
return getThemedIcon(child);
|
|
65
|
+
});
|
|
66
|
+
const commonProps = { ...props, pressed, disabled, ...sizeProps, children };
|
|
67
|
+
return /* @__PURE__ */ jsx(ToggleGroupItemProvider, { scope: __scopeToggleGroup, children: context.rovingFocus ? /* @__PURE__ */ jsx(
|
|
68
|
+
RovingFocusGroup.Item,
|
|
69
|
+
{
|
|
70
|
+
asChild: true,
|
|
71
|
+
...rovingFocusGroupScope,
|
|
72
|
+
focusable: !disabled,
|
|
73
|
+
active: pressed,
|
|
74
|
+
children: /* @__PURE__ */ jsx(
|
|
75
|
+
ToggleFrame,
|
|
76
|
+
{
|
|
77
|
+
asChild: true,
|
|
78
|
+
focusable: !disabled,
|
|
79
|
+
disabled,
|
|
80
|
+
ref,
|
|
81
|
+
...groupItemProps,
|
|
82
|
+
children: /* @__PURE__ */ jsx(ToggleGroupItemImpl, { ...commonProps, ref: forwardedRef })
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
) : /* @__PURE__ */ jsx(ToggleFrame, { asChild: true, focusable: !disabled, disabled, ref, children: /* @__PURE__ */ jsx(ToggleGroupItemImpl, { ...commonProps, ref: forwardedRef }) }) });
|
|
87
|
+
}
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
ToggleGroupItem.displayName = TOGGLE_GROUP_ITEM_NAME;
|
|
91
|
+
const ToggleGroupItemImpl = ToggleFrame.extractable(
|
|
92
|
+
React.forwardRef(
|
|
93
|
+
(props, forwardedRef) => {
|
|
94
|
+
const { __scopeToggleGroup, value, ...itemProps } = props;
|
|
95
|
+
const valueContext = useToggleGroupValueContext(
|
|
96
|
+
TOGGLE_GROUP_ITEM_NAME,
|
|
97
|
+
__scopeToggleGroup
|
|
98
|
+
);
|
|
99
|
+
const singleProps = {
|
|
100
|
+
"aria-pressed": void 0
|
|
101
|
+
};
|
|
102
|
+
const typeProps = valueContext.type === "single" ? singleProps : void 0;
|
|
103
|
+
return /* @__PURE__ */ jsx(
|
|
104
|
+
Toggle,
|
|
105
|
+
{
|
|
106
|
+
...typeProps,
|
|
107
|
+
...itemProps,
|
|
108
|
+
ref: forwardedRef,
|
|
109
|
+
onPressedChange: (pressed) => {
|
|
110
|
+
if (pressed) {
|
|
111
|
+
valueContext.onItemActivate(value);
|
|
112
|
+
} else {
|
|
113
|
+
valueContext.onItemDeactivate(value);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
)
|
|
120
|
+
);
|
|
121
|
+
const useRovingFocusGroupScope = createRovingFocusGroupScope();
|
|
122
|
+
const ToggleGroup = withStaticProperties(
|
|
123
|
+
React.forwardRef((props, forwardedRef) => {
|
|
124
|
+
const { type, ...toggleGroupProps } = props;
|
|
125
|
+
if (!isWeb) {
|
|
126
|
+
React.useEffect(() => {
|
|
127
|
+
if (!props.id)
|
|
128
|
+
return;
|
|
129
|
+
return registerFocusable(props.id, {
|
|
130
|
+
// TODO: would be nice to focus on the first child later - could be done with reforest
|
|
131
|
+
// for now leaving it empty
|
|
132
|
+
focus: () => {
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}, [props.id]);
|
|
136
|
+
}
|
|
137
|
+
if (type === "single") {
|
|
138
|
+
const singleProps = toggleGroupProps;
|
|
139
|
+
return /* @__PURE__ */ jsx(ToggleGroupImplSingle, { ...singleProps, ref: forwardedRef });
|
|
140
|
+
}
|
|
141
|
+
if (type === "multiple") {
|
|
142
|
+
const multipleProps = toggleGroupProps;
|
|
143
|
+
return /* @__PURE__ */ jsx(ToggleGroupImplMultiple, { ...multipleProps, ref: forwardedRef });
|
|
144
|
+
}
|
|
145
|
+
throw new Error(`Missing prop \`type\` expected on \`${TOGGLE_GROUP_NAME}\``);
|
|
146
|
+
}),
|
|
147
|
+
{
|
|
148
|
+
Item: ToggleGroupItem
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
ToggleGroup.displayName = TOGGLE_GROUP_NAME;
|
|
152
|
+
const [ToggleGroupValueProvider, useToggleGroupValueContext] = createToggleGroupContext(TOGGLE_GROUP_NAME);
|
|
153
|
+
const ToggleGroupImplSingle = React.forwardRef((props, forwardedRef) => {
|
|
154
|
+
const {
|
|
155
|
+
value: valueProp,
|
|
156
|
+
defaultValue,
|
|
157
|
+
onValueChange = () => {
|
|
158
|
+
},
|
|
159
|
+
disableDeactivation = false,
|
|
160
|
+
...toggleGroupSingleProps
|
|
161
|
+
} = props;
|
|
162
|
+
const [value, setValue] = useControllableState({
|
|
163
|
+
prop: valueProp,
|
|
164
|
+
defaultProp: defaultValue,
|
|
165
|
+
onChange: onValueChange
|
|
166
|
+
});
|
|
167
|
+
return /* @__PURE__ */ jsx(
|
|
168
|
+
ToggleGroupValueProvider,
|
|
169
|
+
{
|
|
170
|
+
scope: props.__scopeToggleGroup,
|
|
171
|
+
type: "single",
|
|
172
|
+
value: value ? [value] : [],
|
|
173
|
+
defaultValue: value,
|
|
174
|
+
onItemActivate: setValue,
|
|
175
|
+
onItemDeactivate: React.useCallback(() => disableDeactivation ? null : setValue(""), [setValue, disableDeactivation]),
|
|
176
|
+
children: /* @__PURE__ */ jsx(ToggleGroupImpl, { ...toggleGroupSingleProps, ref: forwardedRef })
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
});
|
|
180
|
+
const ToggleGroupImplMultiple = React.forwardRef((props, forwardedRef) => {
|
|
181
|
+
const {
|
|
182
|
+
value: valueProp,
|
|
183
|
+
defaultValue,
|
|
184
|
+
onValueChange = () => {
|
|
185
|
+
},
|
|
186
|
+
...toggleGroupMultipleProps
|
|
187
|
+
} = props;
|
|
188
|
+
const [value = [], setValue] = useControllableState({
|
|
189
|
+
prop: valueProp,
|
|
190
|
+
defaultProp: defaultValue,
|
|
191
|
+
onChange: onValueChange
|
|
192
|
+
});
|
|
193
|
+
const handleButtonActivate = React.useCallback(
|
|
194
|
+
(itemValue) => setValue((prevValue = []) => [...prevValue, itemValue]),
|
|
195
|
+
[setValue]
|
|
196
|
+
);
|
|
197
|
+
const handleButtonDeactivate = React.useCallback(
|
|
198
|
+
(itemValue) => setValue((prevValue = []) => prevValue.filter((value2) => value2 !== itemValue)),
|
|
199
|
+
[setValue]
|
|
200
|
+
);
|
|
201
|
+
return /* @__PURE__ */ jsx(
|
|
202
|
+
ToggleGroupValueProvider,
|
|
203
|
+
{
|
|
204
|
+
scope: props.__scopeToggleGroup,
|
|
205
|
+
type: "multiple",
|
|
206
|
+
value,
|
|
207
|
+
defaultValue: value,
|
|
208
|
+
onItemActivate: handleButtonActivate,
|
|
209
|
+
onItemDeactivate: handleButtonDeactivate,
|
|
210
|
+
children: /* @__PURE__ */ jsx(ToggleGroupImpl, { ...toggleGroupMultipleProps, ref: forwardedRef })
|
|
211
|
+
}
|
|
212
|
+
);
|
|
213
|
+
});
|
|
214
|
+
ToggleGroup.displayName = TOGGLE_GROUP_NAME;
|
|
215
|
+
const [ToggleGroupContext, useToggleGroupContext] = createToggleGroupContext(TOGGLE_GROUP_NAME);
|
|
216
|
+
const ToggleGroupImplElementFrame = styled(Group, {
|
|
217
|
+
name: TOGGLE_GROUP_NAME,
|
|
218
|
+
variants: {
|
|
219
|
+
unstyled: {
|
|
220
|
+
false: {
|
|
221
|
+
backgroundColor: "$background"
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
orientation: {
|
|
225
|
+
vertical: {
|
|
226
|
+
flexDirection: "column",
|
|
227
|
+
spaceDirection: "vertical"
|
|
228
|
+
},
|
|
229
|
+
horizontal: {
|
|
230
|
+
flexDirection: "row",
|
|
231
|
+
spaceDirection: "horizontal"
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
defaultVariants: {
|
|
236
|
+
unstyled: false
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
const ToggleGroupImpl = ToggleGroupImplElementFrame.extractable(
|
|
240
|
+
React.forwardRef(
|
|
241
|
+
(props, forwardedRef) => {
|
|
242
|
+
const {
|
|
243
|
+
__scopeToggleGroup,
|
|
244
|
+
disabled = false,
|
|
245
|
+
orientation = "horizontal",
|
|
246
|
+
dir,
|
|
247
|
+
rovingFocus = true,
|
|
248
|
+
loop = true,
|
|
249
|
+
unstyled = false,
|
|
250
|
+
size: sizeProp = "$true",
|
|
251
|
+
sizeAdjust = 0,
|
|
252
|
+
...toggleGroupProps
|
|
253
|
+
} = props;
|
|
254
|
+
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeToggleGroup);
|
|
255
|
+
const direction = useDirection(dir);
|
|
256
|
+
const commonProps = {
|
|
257
|
+
role: "togglegroup",
|
|
258
|
+
dir: direction,
|
|
259
|
+
...toggleGroupProps
|
|
260
|
+
};
|
|
261
|
+
const adjustedSize = getVariableValue(
|
|
262
|
+
stepTokenUpOrDown("size", props.size, sizeAdjust)
|
|
263
|
+
);
|
|
264
|
+
const size = Math.round(adjustedSize * 0.45);
|
|
265
|
+
return /* @__PURE__ */ jsx(
|
|
266
|
+
ToggleGroupContext,
|
|
267
|
+
{
|
|
268
|
+
scope: __scopeToggleGroup,
|
|
269
|
+
rovingFocus,
|
|
270
|
+
disabled,
|
|
271
|
+
size,
|
|
272
|
+
children: rovingFocus ? /* @__PURE__ */ jsx(
|
|
273
|
+
RovingFocusGroup,
|
|
274
|
+
{
|
|
275
|
+
asChild: true,
|
|
276
|
+
...rovingFocusGroupScope,
|
|
277
|
+
orientation,
|
|
278
|
+
dir: direction,
|
|
279
|
+
loop,
|
|
280
|
+
children: /* @__PURE__ */ jsx(
|
|
281
|
+
ToggleGroupImplElementFrame,
|
|
282
|
+
{
|
|
283
|
+
"aria-orientation": orientation,
|
|
284
|
+
orientation,
|
|
285
|
+
axis: orientation,
|
|
286
|
+
ref: forwardedRef,
|
|
287
|
+
"data-disabled": disabled ? "" : void 0,
|
|
288
|
+
unstyled,
|
|
289
|
+
...commonProps
|
|
290
|
+
}
|
|
291
|
+
)
|
|
292
|
+
}
|
|
293
|
+
) : /* @__PURE__ */ jsx(
|
|
294
|
+
ToggleGroupImplElementFrame,
|
|
295
|
+
{
|
|
296
|
+
"aria-orientation": orientation,
|
|
297
|
+
ref: forwardedRef,
|
|
298
|
+
orientation,
|
|
299
|
+
"data-disabled": disabled ? "" : void 0,
|
|
300
|
+
unstyled,
|
|
301
|
+
...commonProps
|
|
302
|
+
}
|
|
303
|
+
)
|
|
304
|
+
}
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
)
|
|
308
|
+
);
|
|
309
|
+
export {
|
|
310
|
+
ToggleGroup,
|
|
311
|
+
createToggleGroupScope
|
|
312
|
+
};
|
|
2
313
|
//# sourceMappingURL=ToggleGroup.js.map
|