@tamagui/radio-group 1.0.1
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/LICENSE +21 -0
- package/dist/cjs/RadioGroup.cjs +132 -0
- package/dist/cjs/RadioGroup.js +120 -0
- package/dist/cjs/RadioGroup.js.map +6 -0
- package/dist/cjs/RadioGroup.native.js +137 -0
- package/dist/cjs/RadioGroup.native.js.map +1 -0
- package/dist/cjs/RadioGroupStyledContext.cjs +30 -0
- package/dist/cjs/RadioGroupStyledContext.js +28 -0
- package/dist/cjs/RadioGroupStyledContext.js.map +6 -0
- package/dist/cjs/RadioGroupStyledContext.native.js +33 -0
- package/dist/cjs/RadioGroupStyledContext.native.js.map +1 -0
- package/dist/cjs/createRadioGroup.cjs +165 -0
- package/dist/cjs/createRadioGroup.js +106 -0
- package/dist/cjs/createRadioGroup.js.map +6 -0
- package/dist/cjs/createRadioGroup.native.js +168 -0
- package/dist/cjs/createRadioGroup.native.js.map +1 -0
- package/dist/cjs/index.cjs +36 -0
- package/dist/cjs/index.js +29 -0
- package/dist/cjs/index.js.map +6 -0
- package/dist/cjs/index.native.js +39 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/esm/RadioGroup.js +106 -0
- package/dist/esm/RadioGroup.js.map +6 -0
- package/dist/esm/RadioGroup.mjs +107 -0
- package/dist/esm/RadioGroup.mjs.map +1 -0
- package/dist/esm/RadioGroup.native.js +109 -0
- package/dist/esm/RadioGroup.native.js.map +1 -0
- package/dist/esm/RadioGroupStyledContext.js +12 -0
- package/dist/esm/RadioGroupStyledContext.js.map +6 -0
- package/dist/esm/RadioGroupStyledContext.mjs +7 -0
- package/dist/esm/RadioGroupStyledContext.mjs.map +1 -0
- package/dist/esm/RadioGroupStyledContext.native.js +7 -0
- package/dist/esm/RadioGroupStyledContext.native.js.map +1 -0
- package/dist/esm/createRadioGroup.js +95 -0
- package/dist/esm/createRadioGroup.js.map +6 -0
- package/dist/esm/createRadioGroup.mjs +131 -0
- package/dist/esm/createRadioGroup.mjs.map +1 -0
- package/dist/esm/createRadioGroup.native.js +131 -0
- package/dist/esm/createRadioGroup.native.js.map +1 -0
- package/dist/esm/index.js +18 -0
- package/dist/esm/index.js.map +6 -0
- package/dist/esm/index.mjs +12 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +12 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/jsx/RadioGroup.js +106 -0
- package/dist/jsx/RadioGroup.js.map +6 -0
- package/dist/jsx/RadioGroup.mjs +107 -0
- package/dist/jsx/RadioGroup.mjs.map +1 -0
- package/dist/jsx/RadioGroup.native.js +137 -0
- package/dist/jsx/RadioGroup.native.js.map +1 -0
- package/dist/jsx/RadioGroupStyledContext.js +12 -0
- package/dist/jsx/RadioGroupStyledContext.js.map +6 -0
- package/dist/jsx/RadioGroupStyledContext.mjs +7 -0
- package/dist/jsx/RadioGroupStyledContext.mjs.map +1 -0
- package/dist/jsx/RadioGroupStyledContext.native.js +33 -0
- package/dist/jsx/RadioGroupStyledContext.native.js.map +1 -0
- package/dist/jsx/createRadioGroup.js +95 -0
- package/dist/jsx/createRadioGroup.js.map +6 -0
- package/dist/jsx/createRadioGroup.mjs +131 -0
- package/dist/jsx/createRadioGroup.mjs.map +1 -0
- package/dist/jsx/createRadioGroup.native.js +168 -0
- package/dist/jsx/createRadioGroup.native.js.map +1 -0
- package/dist/jsx/index.js +18 -0
- package/dist/jsx/index.js.map +6 -0
- package/dist/jsx/index.mjs +12 -0
- package/dist/jsx/index.mjs.map +1 -0
- package/dist/jsx/index.native.js +39 -0
- package/dist/jsx/index.native.js.map +1 -0
- package/package.json +62 -0
- package/src/RadioGroup.tsx +125 -0
- package/src/RadioGroupStyledContext.tsx +10 -0
- package/src/createRadioGroup.tsx +191 -0
- package/src/index.ts +16 -0
- package/types/RadioGroup.d.ts +18 -0
- package/types/RadioGroup.d.ts.map +1 -0
- package/types/RadioGroupStyledContext.d.ts +6 -0
- package/types/RadioGroupStyledContext.d.ts.map +1 -0
- package/types/createRadioGroup.d.ts +282 -0
- package/types/createRadioGroup.d.ts.map +1 -0
- package/types/index.d.ts +253 -0
- package/types/index.d.ts.map +1 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { getVariableValue, styled } from '@tamagui/core'
|
|
2
|
+
import { getSize } from '@tamagui/get-token'
|
|
3
|
+
import { YStack } from '@tamagui/stacks'
|
|
4
|
+
|
|
5
|
+
const RADIO_GROUP_ITEM_NAME = 'RadioGroupItem'
|
|
6
|
+
|
|
7
|
+
export const RadioGroupItemFrame = styled(YStack, {
|
|
8
|
+
name: RADIO_GROUP_ITEM_NAME,
|
|
9
|
+
render: 'button',
|
|
10
|
+
|
|
11
|
+
variants: {
|
|
12
|
+
unstyled: {
|
|
13
|
+
false: {
|
|
14
|
+
size: '$true',
|
|
15
|
+
borderRadius: 1000,
|
|
16
|
+
backgroundColor: '$background',
|
|
17
|
+
alignItems: 'center',
|
|
18
|
+
justifyContent: 'center',
|
|
19
|
+
borderWidth: 1,
|
|
20
|
+
borderColor: '$borderColor',
|
|
21
|
+
padding: 0,
|
|
22
|
+
|
|
23
|
+
hoverStyle: {
|
|
24
|
+
borderColor: '$borderColorHover',
|
|
25
|
+
backgroundColor: '$backgroundHover',
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
focusStyle: {
|
|
29
|
+
borderColor: '$borderColorHover',
|
|
30
|
+
backgroundColor: '$backgroundHover',
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
focusVisibleStyle: {
|
|
34
|
+
outlineStyle: 'solid',
|
|
35
|
+
outlineWidth: 2,
|
|
36
|
+
outlineColor: '$outlineColor',
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
pressStyle: {
|
|
40
|
+
borderColor: '$borderColorFocus',
|
|
41
|
+
backgroundColor: '$backgroundFocus',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
disabled: {
|
|
47
|
+
true: {
|
|
48
|
+
pointerEvents: 'none',
|
|
49
|
+
userSelect: 'none',
|
|
50
|
+
cursor: 'not-allowed',
|
|
51
|
+
|
|
52
|
+
hoverStyle: {
|
|
53
|
+
borderColor: '$borderColor',
|
|
54
|
+
backgroundColor: '$background',
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
pressStyle: {
|
|
58
|
+
borderColor: '$borderColor',
|
|
59
|
+
backgroundColor: '$background',
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
focusVisibleStyle: {
|
|
63
|
+
outlineWidth: 0,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
size: {
|
|
69
|
+
'...size': (value, { props }) => {
|
|
70
|
+
const size = Math.floor(
|
|
71
|
+
getVariableValue(getSize(value)) * (props['scaleSize'] ?? 0.5)
|
|
72
|
+
)
|
|
73
|
+
return {
|
|
74
|
+
width: size,
|
|
75
|
+
height: size,
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
} as const,
|
|
80
|
+
|
|
81
|
+
defaultVariants: {
|
|
82
|
+
unstyled: process.env.TAMAGUI_HEADLESS === '1',
|
|
83
|
+
},
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
const RADIO_GROUP_INDICATOR_NAME = 'RadioGroupIndicator'
|
|
87
|
+
|
|
88
|
+
export const RadioGroupIndicatorFrame = styled(YStack, {
|
|
89
|
+
name: RADIO_GROUP_INDICATOR_NAME,
|
|
90
|
+
|
|
91
|
+
variants: {
|
|
92
|
+
unstyled: {
|
|
93
|
+
false: {
|
|
94
|
+
width: '33%',
|
|
95
|
+
height: '33%',
|
|
96
|
+
borderRadius: 1000,
|
|
97
|
+
backgroundColor: '$color',
|
|
98
|
+
pressTheme: true,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
} as const,
|
|
102
|
+
|
|
103
|
+
defaultVariants: {
|
|
104
|
+
unstyled: process.env.TAMAGUI_HEADLESS === '1',
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
const RADIO_GROUP_NAME = 'RadioGroup'
|
|
109
|
+
|
|
110
|
+
export const RadioGroupFrame = styled(YStack, {
|
|
111
|
+
name: RADIO_GROUP_NAME,
|
|
112
|
+
|
|
113
|
+
variants: {
|
|
114
|
+
orientation: {
|
|
115
|
+
horizontal: {
|
|
116
|
+
flexDirection: 'row',
|
|
117
|
+
spaceDirection: 'horizontal',
|
|
118
|
+
},
|
|
119
|
+
vertical: {
|
|
120
|
+
flexDirection: 'column',
|
|
121
|
+
spaceDirection: 'vertical',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
} as const,
|
|
125
|
+
})
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type { GetProps } from '@tamagui/core'
|
|
2
|
+
import { isWeb, withStaticProperties } from '@tamagui/core'
|
|
3
|
+
import type {
|
|
4
|
+
RadioGroupContextValue,
|
|
5
|
+
RadioGroupItemContextValue,
|
|
6
|
+
} from '@tamagui/radio-headless'
|
|
7
|
+
import {
|
|
8
|
+
useRadioGroup,
|
|
9
|
+
useRadioGroupItem,
|
|
10
|
+
useRadioGroupItemIndicator,
|
|
11
|
+
} from '@tamagui/radio-headless'
|
|
12
|
+
import { RovingFocusGroup } from '@tamagui/roving-focus'
|
|
13
|
+
import React from 'react'
|
|
14
|
+
import {
|
|
15
|
+
RadioGroupFrame,
|
|
16
|
+
RadioGroupIndicatorFrame,
|
|
17
|
+
RadioGroupItemFrame,
|
|
18
|
+
} from './RadioGroup'
|
|
19
|
+
|
|
20
|
+
const ensureContext = (x: any) => {
|
|
21
|
+
if (!x.context) {
|
|
22
|
+
x.context = RadioGroupContext
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type RadioIndicatorProps = GetProps<typeof RadioGroupIndicatorFrame> & {
|
|
27
|
+
forceMount?: boolean
|
|
28
|
+
unstyled?: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const RadioGroupContext = React.createContext<RadioGroupContextValue>({})
|
|
32
|
+
const RadioGroupItemContext = React.createContext<RadioGroupItemContextValue>({
|
|
33
|
+
checked: false,
|
|
34
|
+
disabled: false,
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
export type RadioGroupItemProps = GetProps<typeof RadioGroupItemFrame> & {
|
|
38
|
+
value: string
|
|
39
|
+
id?: string
|
|
40
|
+
labelledBy?: string
|
|
41
|
+
disabled?: boolean
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type RadioGroupProps = GetProps<typeof RadioGroupFrame> & {
|
|
45
|
+
value?: string
|
|
46
|
+
defaultValue?: string
|
|
47
|
+
onValueChange?: (value: string) => void
|
|
48
|
+
required?: boolean
|
|
49
|
+
disabled?: boolean
|
|
50
|
+
name?: string
|
|
51
|
+
native?: boolean
|
|
52
|
+
accentColor?: string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type RadioGroupComponent = (props: RadioGroupProps) => any
|
|
56
|
+
|
|
57
|
+
type RadioGroupIndicatorComponent = (props: RadioIndicatorProps) => any
|
|
58
|
+
|
|
59
|
+
type RadioGroupItemComponent = (props: RadioGroupItemProps) => any
|
|
60
|
+
|
|
61
|
+
export function createRadioGroup<
|
|
62
|
+
F extends RadioGroupComponent,
|
|
63
|
+
D extends RadioGroupIndicatorComponent,
|
|
64
|
+
I extends RadioGroupItemComponent,
|
|
65
|
+
>(createProps: { disableActiveTheme?: boolean; Frame?: F; Indicator?: D; Item?: I }) {
|
|
66
|
+
const {
|
|
67
|
+
disableActiveTheme,
|
|
68
|
+
Frame = RadioGroupFrame,
|
|
69
|
+
Indicator = RadioGroupIndicatorFrame,
|
|
70
|
+
Item = RadioGroupItemFrame,
|
|
71
|
+
} = createProps as any as {
|
|
72
|
+
disableActiveTheme?: boolean
|
|
73
|
+
Frame: typeof RadioGroupFrame
|
|
74
|
+
Indicator: typeof RadioGroupIndicatorFrame
|
|
75
|
+
Item: typeof RadioGroupItemFrame
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
ensureContext(Frame)
|
|
79
|
+
ensureContext(Indicator)
|
|
80
|
+
ensureContext(Item)
|
|
81
|
+
|
|
82
|
+
type RadioGroupProps = GetProps<typeof RadioGroupFrame> & {
|
|
83
|
+
value?: string
|
|
84
|
+
defaultValue?: string
|
|
85
|
+
onValueChange?: (value: string) => void
|
|
86
|
+
required?: boolean
|
|
87
|
+
disabled?: boolean
|
|
88
|
+
name?: string
|
|
89
|
+
native?: boolean
|
|
90
|
+
accentColor?: string
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const RadioGroupImp = Frame.styleable<RadioGroupProps>((props, ref) => {
|
|
94
|
+
const {
|
|
95
|
+
value,
|
|
96
|
+
defaultValue,
|
|
97
|
+
onValueChange,
|
|
98
|
+
required = false,
|
|
99
|
+
disabled = false,
|
|
100
|
+
name,
|
|
101
|
+
native,
|
|
102
|
+
accentColor,
|
|
103
|
+
orientation = 'vertical',
|
|
104
|
+
...rest
|
|
105
|
+
} = props
|
|
106
|
+
|
|
107
|
+
const { providerValue, frameAttrs, rovingFocusGroupAttrs } = useRadioGroup({
|
|
108
|
+
orientation,
|
|
109
|
+
name,
|
|
110
|
+
defaultValue,
|
|
111
|
+
value,
|
|
112
|
+
onValueChange,
|
|
113
|
+
required,
|
|
114
|
+
disabled,
|
|
115
|
+
native,
|
|
116
|
+
accentColor,
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<RadioGroupContext.Provider value={providerValue}>
|
|
121
|
+
<RovingFocusGroup {...rovingFocusGroupAttrs}>
|
|
122
|
+
<RadioGroupFrame {...frameAttrs} ref={ref} {...rest} />
|
|
123
|
+
</RovingFocusGroup>
|
|
124
|
+
</RadioGroupContext.Provider>
|
|
125
|
+
)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
const RadioGroupItemImp = Item.styleable<RadioGroupItemProps>((props, ref) => {
|
|
129
|
+
const { value, labelledBy, onPress, onKeyDown, disabled, id, ...rest } = props
|
|
130
|
+
|
|
131
|
+
const {
|
|
132
|
+
providerValue,
|
|
133
|
+
bubbleInput,
|
|
134
|
+
rovingFocusGroupAttrs,
|
|
135
|
+
frameAttrs,
|
|
136
|
+
isFormControl,
|
|
137
|
+
native,
|
|
138
|
+
} = useRadioGroupItem({
|
|
139
|
+
radioGroupContext: RadioGroupContext,
|
|
140
|
+
value,
|
|
141
|
+
id,
|
|
142
|
+
labelledBy,
|
|
143
|
+
disabled,
|
|
144
|
+
onPress: onPress!,
|
|
145
|
+
onKeyDown,
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<RadioGroupItemContext.Provider value={providerValue}>
|
|
150
|
+
{isWeb && native ? (
|
|
151
|
+
bubbleInput
|
|
152
|
+
) : (
|
|
153
|
+
<>
|
|
154
|
+
<RovingFocusGroup.Item {...rovingFocusGroupAttrs}>
|
|
155
|
+
<RadioGroupItemFrame {...frameAttrs} ref={ref} {...rest} />
|
|
156
|
+
</RovingFocusGroup.Item>
|
|
157
|
+
{isFormControl && bubbleInput}
|
|
158
|
+
</>
|
|
159
|
+
)}
|
|
160
|
+
</RadioGroupItemContext.Provider>
|
|
161
|
+
)
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
RadioGroupItemImp.displayName = 'RadioGroupItem'
|
|
165
|
+
|
|
166
|
+
const RadioIndicator = Indicator.styleable<RadioIndicatorProps>(
|
|
167
|
+
(props: RadioIndicatorProps, forwardedRef) => {
|
|
168
|
+
const { forceMount, disabled, ...indicatorProps } = props
|
|
169
|
+
const { checked, ...useIndicatorRest } = useRadioGroupItemIndicator({
|
|
170
|
+
radioGroupItemContext: RadioGroupItemContext,
|
|
171
|
+
disabled,
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
if (forceMount || checked) {
|
|
175
|
+
return <Indicator {...useIndicatorRest} ref={forwardedRef} {...indicatorProps} />
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return null
|
|
179
|
+
}
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
RadioIndicator.displayName = 'RadioIndicator'
|
|
183
|
+
|
|
184
|
+
const RadioGroup = withStaticProperties(RadioGroupImp, {
|
|
185
|
+
Item: RadioGroupItemImp,
|
|
186
|
+
Indicator: RadioIndicator,
|
|
187
|
+
})
|
|
188
|
+
RadioGroup.displayName = 'RadioGroup'
|
|
189
|
+
|
|
190
|
+
return RadioGroup
|
|
191
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RadioGroupFrame,
|
|
3
|
+
RadioGroupIndicatorFrame,
|
|
4
|
+
RadioGroupItemFrame,
|
|
5
|
+
} from './RadioGroup'
|
|
6
|
+
import { createRadioGroup } from './createRadioGroup'
|
|
7
|
+
|
|
8
|
+
export * from './createRadioGroup'
|
|
9
|
+
export * from './RadioGroup'
|
|
10
|
+
export * from './RadioGroupStyledContext'
|
|
11
|
+
|
|
12
|
+
export const RadioGroup = createRadioGroup({
|
|
13
|
+
Frame: RadioGroupFrame,
|
|
14
|
+
Indicator: RadioGroupIndicatorFrame,
|
|
15
|
+
Item: RadioGroupItemFrame,
|
|
16
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const RadioGroupItemFrame: import("@tamagui/core").TamaguiComponent<import("@tamagui/core").TamaDefer, import("@tamagui/core").TamaguiElement, import("@tamagui/core").RNTamaguiViewNonStyleProps, import("@tamagui/core").StackStyleBase, {
|
|
2
|
+
disabled?: boolean | undefined;
|
|
3
|
+
unstyled?: boolean | undefined;
|
|
4
|
+
elevation?: number | import("@tamagui/core").SizeTokens | undefined;
|
|
5
|
+
fullscreen?: boolean | undefined;
|
|
6
|
+
size?: import("@tamagui/core").SizeTokens | undefined;
|
|
7
|
+
}, import("@tamagui/core").StaticConfigPublic>;
|
|
8
|
+
export declare const RadioGroupIndicatorFrame: import("@tamagui/core").TamaguiComponent<import("@tamagui/core").TamaDefer, import("@tamagui/core").TamaguiElement, import("@tamagui/core").RNTamaguiViewNonStyleProps, import("@tamagui/core").StackStyleBase, {
|
|
9
|
+
unstyled?: boolean | undefined;
|
|
10
|
+
elevation?: number | import("@tamagui/core").SizeTokens | undefined;
|
|
11
|
+
fullscreen?: boolean | undefined;
|
|
12
|
+
}, import("@tamagui/core").StaticConfigPublic>;
|
|
13
|
+
export declare const RadioGroupFrame: import("@tamagui/core").TamaguiComponent<import("@tamagui/core").TamaDefer, import("@tamagui/core").TamaguiElement, import("@tamagui/core").RNTamaguiViewNonStyleProps, import("@tamagui/core").StackStyleBase, {
|
|
14
|
+
elevation?: number | import("@tamagui/core").SizeTokens | undefined;
|
|
15
|
+
fullscreen?: boolean | undefined;
|
|
16
|
+
orientation?: "horizontal" | "vertical" | undefined;
|
|
17
|
+
}, import("@tamagui/core").StaticConfigPublic>;
|
|
18
|
+
//# sourceMappingURL=RadioGroup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RadioGroup.d.ts","sourceRoot":"","sources":["../src/RadioGroup.tsx"],"names":[],"mappings":"AAMA,eAAO,MAAM,mBAAmB;;;;;;8CA6E9B,CAAA;AAIF,eAAO,MAAM,wBAAwB;;;;8CAkBnC,CAAA;AAIF,eAAO,MAAM,eAAe;;;;8CAe1B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RadioGroupStyledContext.d.ts","sourceRoot":"","sources":["../src/RadioGroupStyledContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAG/C,eAAO,MAAM,uBAAuB;UAEf,UAAU;;EAI9B,CAAA"}
|