@tamagui/toggle-group 1.13.3 → 1.14.0

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.
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
4
  "sourcesContent": ["export * from './ToggleGroup'\n"],
5
- "mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,0BAAd;",
6
- "names": []
5
+ "mappings": "iaAAA,IAAAA,EAAA,kBAAAC,EAAAD,GAAAE,EAAAF,EAAc,yBAAd",
6
+ "names": ["src_exports", "__toCommonJS", "__reExport"]
7
7
  }
@@ -1,96 +1,2 @@
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
- };
1
+ import{jsx as n}from"react/jsx-runtime";import{ThemeableStack as u}from"@tamagui/stacks";import{useControllableState as p}from"@tamagui/use-controllable-state";import{Theme as b,composeEventHandlers as f,styled as m}from"@tamagui/web";import*as P from"react";const s="Toggle",r=m(u,{name:s,tag:"button",variants:{unstyled:{false:{pressTheme:!0,backgroundColor:"$background",alignItems:"center",justifyContent:"center",display:"flex",borderColor:"$borderColor",borderWidth:"1px",margin:"-1px",hoverStyle:{backgroundColor:"$backgroundHover"},pressStyle:{backgroundColor:"$backgroundPress"},focusStyle:{borderColor:"$borderColorPress",backgroundColor:"$backgroundPress"}}},active:{true:{zIndex:1,hoverStyle:{backgroundColor:"$background"},focusStyle:{borderColor:"$borderColorPress",backgroundColor:"$backgroundPress"}}},orientation:{horizontal:{flexDirection:"row",spaceDirection:"horizontal"},vertical:{flexDirection:"column",spaceDirection:"vertical"}}},defaultVariants:{unstyled:!1}}),t=r.extractable(P.forwardRef((e,a)=>{const{pressed:l,defaultPressed:d=!1,onPressedChange:i,...g}=e,[o=!1,c]=p({prop:l,onChange:i,defaultProp:d});return n(b,{forceClassName:!0,name:o?"active":null,children:n(r,{active:e.unstyled?void 0:o,"aria-pressed":o,"data-state":o?"on":"off","data-disabled":e.disabled?"":void 0,...g,ref:a,onPress:f(e.onPress??void 0,y=>{e.disabled||c(!o)})})})}));t.displayName=s;export{t as Toggle,r as ToggleFrame};
96
2
  //# sourceMappingURL=Toggle.js.map
@@ -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;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,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C,KAAMa,EAAU,SAAW,KAC/C,SAAAhB,EAACQ,EAAA,CACC,OAASE,EAAM,SAAqB,OAAVM,EAC1B,eAAcA,EACd,aAAYA,EAAU,KAAO,MAC7B,gBAAeN,EAAM,SAAW,GAAK,OACpC,GAAGK,EACJ,IAAKJ,EACL,QAASP,EAAqBM,EAAM,SAAW,OAAYQ,GAAU,CAC9DR,EAAM,UACTO,EAAW,CAACD,CAAO,CAEvB,CAAC,EAcH,EACF,CAEJ,CAAC,CACH,EACAP,EAAO,YAAcF",
6
+ "names": ["jsx", "ThemeableStack", "useControllableState", "Theme", "composeEventHandlers", "styled", "React", "NAME", "ToggleFrame", "Toggle", "props", "forwardedRef", "pressedProp", "defaultPressed", "onPressedChange", "buttonProps", "pressed", "setPressed", "event"]
7
7
  }
@@ -1,96 +1,2 @@
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
- };
1
+ import{jsx as n}from"react/jsx-runtime";import{ThemeableStack as u}from"@tamagui/stacks";import{useControllableState as p}from"@tamagui/use-controllable-state";import{Theme as b,composeEventHandlers as f,styled as m}from"@tamagui/web";import*as P from"react";const s="Toggle",r=m(u,{name:s,tag:"button",variants:{unstyled:{false:{pressTheme:!0,backgroundColor:"$background",alignItems:"center",justifyContent:"center",display:"flex",borderColor:"$borderColor",borderWidth:"1px",margin:"-1px",hoverStyle:{backgroundColor:"$backgroundHover"},pressStyle:{backgroundColor:"$backgroundPress"},focusStyle:{borderColor:"$borderColorPress",backgroundColor:"$backgroundPress"}}},active:{true:{zIndex:1,hoverStyle:{backgroundColor:"$background"},focusStyle:{borderColor:"$borderColorPress",backgroundColor:"$backgroundPress"}}},orientation:{horizontal:{flexDirection:"row",spaceDirection:"horizontal"},vertical:{flexDirection:"column",spaceDirection:"vertical"}}},defaultVariants:{unstyled:!1}}),t=r.extractable(P.forwardRef((e,a)=>{const{pressed:l,defaultPressed:d=!1,onPressedChange:i,...g}=e,[o=!1,c]=p({prop:l,onChange:i,defaultProp:d});return n(b,{forceClassName:!0,name:o?"active":null,children:n(r,{active:e.unstyled?void 0:o,"aria-pressed":o,"data-state":o?"on":"off","data-disabled":e.disabled?"":void 0,...g,ref:a,onPress:f(e.onPress??void 0,y=>{e.disabled||c(!o)})})})}));t.displayName=s;export{t as Toggle,r as ToggleFrame};
96
2
  //# sourceMappingURL=Toggle.mjs.map
@@ -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;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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zD,KAAMU,EACN,SAAUE,EACV,YAAaD,CACf,CAAC,EAED,OACEb,EAACG,EAAA,CAAM,eAAc,GAAC,KAAMa,EAAU,SAAW,KAC/C,SAAAhB,EAACQ,EAAA,CACC,OAASE,EAAM,SAAqB,OAAVM,EAC1B,eAAcA,EACd,aAAYA,EAAU,KAAO,MAC7B,gBAAeN,EAAM,SAAW,GAAK,OACpC,GAAGK,EACJ,IAAKJ,EACL,QAASP,EAAqBM,EAAM,SAAW,OAAYQ,GAAU,CAC9DR,EAAM,UACTO,EAAW,CAACD,CAAO,CAEvB,CAAC,EAcH,EACF,CAEJ,CAAC,CACH,EACAP,EAAO,YAAcF",
6
+ "names": ["jsx", "ThemeableStack", "useControllableState", "Theme", "composeEventHandlers", "styled", "React", "NAME", "ToggleFrame", "Toggle", "props", "forwardedRef", "pressedProp", "defaultPressed", "onPressedChange", "buttonProps", "pressed", "setPressed", "event"]
7
7
  }
@@ -1,313 +1,2 @@
1
- import { jsx } from "react/jsx-runtime";
2
- 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
- };
1
+ import{jsx as l}from"react/jsx-runtime";import{createContextScope as V}from"@tamagui/create-context";import{registerFocusable as O}from"@tamagui/focusable";import{getFontSize as N}from"@tamagui/font-size";import{stepTokenUpOrDown as L}from"@tamagui/get-size";import{Group as U,useGroupItem as $}from"@tamagui/group";import{useGetThemedIcon as j}from"@tamagui/helpers-tamagui";import{RovingFocusGroup as z,createRovingFocusGroupScope as _}from"@tamagui/roving-focus";import{useControllableState as F}from"@tamagui/use-controllable-state";import{useDirection as B}from"@tamagui/use-direction";import{getVariableValue as I,isWeb as H,styled as W,useTheme as q,withStaticProperties as J}from"@tamagui/web";import s from"react";import{Toggle as K,ToggleFrame as v}from"./Toggle";const m="ToggleGroup",[S,Q]=V(m,[_]),G="ToggleGroupItem",[ve,X]=V(G),[Y,ye]=S(m),be=X(),R=v.extractable(s.forwardRef((e,p)=>{const n=w(G,e.__scopeToggleGroup),t=te(G,e.__scopeToggleGroup),r=e.__scopeToggleGroup,u=D(e.__scopeToggleGroup),i=n.value.includes(e.value),o=t.disabled||e.disabled||!1,g=s.useRef(null),T=$({disabled:o}),a=e.size??t.size,c={width:void 0,height:void 0,padding:I(a)*.6};e.orientation==="horizontal"?c.height=I(a)*2.4:c.width=I(a)*2.4;const d=(typeof a=="number"?a*.7:N(a))*1.2,P=q(),f=j({size:d,color:P.color}),y=s.Children.toArray(e.children).map(b=>e.disablePassStyles||!s.isValidElement(b)?b:f(b)),x={...e,pressed:i,disabled:o,...c,children:y};return l(Y,{scope:r,children:t.rovingFocus?l(z.Item,{asChild:!0,...u,focusable:!o,active:i,children:l(v,{asChild:!0,focusable:!o,disabled:o,ref:g,...T,children:l(M,{...x,ref:p})})}):l(v,{asChild:!0,focusable:!o,disabled:o,ref:g,children:l(M,{...x,ref:p})})})}));R.displayName=G;const M=v.extractable(s.forwardRef((e,p)=>{const{__scopeToggleGroup:n,value:t,...r}=e,u=w(G,n),i={"aria-pressed":void 0},o=u.type==="single"?i:void 0;return l(K,{...o,...r,ref:p,onPressedChange:g=>{g?u.onItemActivate(t):u.onItemDeactivate(t)}})})),D=_(),h=J(s.forwardRef((e,p)=>{const{type:n,...t}=e;if(H||s.useEffect(()=>{if(e.id)return O(e.id,{focus:()=>{}})},[e.id]),n==="single")return l(Z,{...t,ref:p});if(n==="multiple")return l(ee,{...t,ref:p});throw new Error(`Missing prop \`type\` expected on \`${m}\``)}),{Item:R});h.displayName=m;const[k,w]=S(m),Z=s.forwardRef((e,p)=>{const{value:n,defaultValue:t,onValueChange:r=()=>{},disableDeactivation:u=!1,...i}=e,[o,g]=F({prop:n,defaultProp:t,onChange:r});return l(k,{scope:e.__scopeToggleGroup,type:"single",value:o?[o]:[],defaultValue:o,onItemActivate:g,onItemDeactivate:s.useCallback(()=>u?null:g(""),[g,u]),children:l(A,{...i,ref:p})})}),ee=s.forwardRef((e,p)=>{const{value:n,defaultValue:t,onValueChange:r=()=>{},...u}=e,[i=[],o]=F({prop:n,defaultProp:t,onChange:r}),g=s.useCallback(a=>o((c=[])=>[...c,a]),[o]),T=s.useCallback(a=>o((c=[])=>c.filter(d=>d!==a)),[o]);return l(k,{scope:e.__scopeToggleGroup,type:"multiple",value:i,defaultValue:i,onItemActivate:g,onItemDeactivate:T,children:l(A,{...u,ref:p})})});h.displayName=m;const[oe,te]=S(m),C=W(U,{name:m,variants:{unstyled:{false:{backgroundColor:"$background"}},orientation:{vertical:{flexDirection:"column",spaceDirection:"vertical"},horizontal:{flexDirection:"row",spaceDirection:"horizontal"}}},defaultVariants:{unstyled:!1}}),A=C.extractable(s.forwardRef((e,p)=>{const{__scopeToggleGroup:n,disabled:t=!1,orientation:r="horizontal",dir:u,rovingFocus:i=!0,loop:o=!0,unstyled:g=!1,size:T="$true",sizeAdjust:a=0,...c}=e,d=D(n),P=B(u),f={role:"togglegroup",dir:P,...c},E=I(L("size",e.size,a)),y=Math.round(E*.45);return l(oe,{scope:n,rovingFocus:i,disabled:t,size:y,children:i?l(z,{asChild:!0,...d,orientation:r,dir:P,loop:o,children:l(C,{"aria-orientation":r,orientation:r,axis:r,ref:p,"data-disabled":t?"":void 0,unstyled:g,...f})}):l(C,{"aria-orientation":r,ref:p,orientation:r,"data-disabled":t?"":void 0,unstyled:g,...f})})}));export{h as ToggleGroup,Q as createToggleGroupScope};
313
2
  //# sourceMappingURL=ToggleGroup.js.map