@tamagui/checkbox 2.7.7 → 3.0.0-beta.637.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.
Files changed (67) hide show
  1. package/dist/cjs/Checkbox.cjs +105 -101
  2. package/dist/cjs/Checkbox.native.cjs +137 -0
  3. package/dist/cjs/Checkbox.native.js +120 -100
  4. package/dist/cjs/Checkbox.native.js.map +1 -1
  5. package/dist/cjs/CheckboxStyledContext.cjs +18 -23
  6. package/dist/cjs/CheckboxStyledContext.native.cjs +32 -0
  7. package/dist/cjs/CheckboxStyledContext.native.js +18 -22
  8. package/dist/cjs/CheckboxStyledContext.native.js.map +1 -1
  9. package/dist/cjs/index.cjs +9 -26
  10. package/dist/cjs/index.native.cjs +22 -0
  11. package/dist/cjs/index.native.js +10 -26
  12. package/dist/cjs/index.native.js.map +1 -1
  13. package/dist/esm/Checkbox.mjs +83 -87
  14. package/dist/esm/Checkbox.mjs.map +1 -1
  15. package/dist/esm/Checkbox.native.js +99 -87
  16. package/dist/esm/Checkbox.native.js.map +1 -1
  17. package/dist/esm/CheckboxStyledContext.mjs +5 -5
  18. package/dist/esm/CheckboxStyledContext.mjs.map +1 -1
  19. package/dist/esm/CheckboxStyledContext.native.js +5 -5
  20. package/dist/esm/CheckboxStyledContext.native.js.map +1 -1
  21. package/dist/esm/index.js +3 -11
  22. package/dist/esm/index.mjs +3 -11
  23. package/dist/esm/index.native.js +3 -11
  24. package/dist/jsx/Checkbox.mjs +83 -87
  25. package/dist/jsx/Checkbox.mjs.map +1 -1
  26. package/dist/jsx/Checkbox.native.cjs +137 -0
  27. package/dist/jsx/Checkbox.native.js +120 -100
  28. package/dist/jsx/Checkbox.native.js.map +1 -1
  29. package/dist/jsx/CheckboxStyledContext.mjs +5 -5
  30. package/dist/jsx/CheckboxStyledContext.mjs.map +1 -1
  31. package/dist/jsx/CheckboxStyledContext.native.cjs +32 -0
  32. package/dist/jsx/CheckboxStyledContext.native.js +18 -22
  33. package/dist/jsx/CheckboxStyledContext.native.js.map +1 -1
  34. package/dist/jsx/index.js +3 -11
  35. package/dist/jsx/index.mjs +3 -11
  36. package/dist/jsx/index.native.cjs +22 -0
  37. package/dist/jsx/index.native.js +10 -26
  38. package/dist/jsx/index.native.js.map +1 -1
  39. package/package.json +6 -16
  40. package/src/Checkbox.tsx +189 -81
  41. package/src/CheckboxStyledContext.tsx +2 -6
  42. package/src/index.ts +0 -9
  43. package/types/Checkbox.d.ts +446 -24
  44. package/types/Checkbox.d.ts.map +1 -1
  45. package/types/CheckboxStyledContext.d.ts +2 -4
  46. package/types/CheckboxStyledContext.d.ts.map +1 -1
  47. package/types/index.d.ts +0 -320
  48. package/types/index.d.ts.map +1 -1
  49. package/dist/cjs/createCheckbox.cjs +0 -194
  50. package/dist/cjs/createCheckbox.native.js +0 -213
  51. package/dist/cjs/createCheckbox.native.js.map +0 -1
  52. package/dist/esm/createCheckbox.mjs +0 -150
  53. package/dist/esm/createCheckbox.mjs.map +0 -1
  54. package/dist/esm/createCheckbox.native.js +0 -167
  55. package/dist/esm/createCheckbox.native.js.map +0 -1
  56. package/dist/esm/index.js.map +0 -1
  57. package/dist/esm/index.mjs.map +0 -1
  58. package/dist/esm/index.native.js.map +0 -1
  59. package/dist/jsx/createCheckbox.mjs +0 -150
  60. package/dist/jsx/createCheckbox.mjs.map +0 -1
  61. package/dist/jsx/createCheckbox.native.js +0 -213
  62. package/dist/jsx/createCheckbox.native.js.map +0 -1
  63. package/dist/jsx/index.js.map +0 -1
  64. package/dist/jsx/index.mjs.map +0 -1
  65. package/src/createCheckbox.tsx +0 -280
  66. package/types/createCheckbox.d.ts +0 -196
  67. package/types/createCheckbox.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAS;;AACT,IAAAA,SAAS,GAAAC,MAAA,CAAAC,cAAsB;AAE/B,IAAAC,gBAAc,GAAAF,MAAA,CAAAG,wBAAA;AACd,IAAAC,iBAAc,GAAAJ,MAAA,CAAAK,mBAAA;AACd,IAAAC,YAAc,GAAAN,MAAA,CAAAO,SAAA,CAAAC,cAAA;AAGP,IAAAC,QAAM,GAAAA,CAAAC,MAAW,EAAAC,GAAA,KAAe;EACrC,SAAOC,IAAA,IAAAD,GAAA,EACPZ,SAAW,CAAAW,MAAA,EAAAE,IAAA;IAAAC,GAAA,EAAAF,GAAA,CAAAC,IAAA;IAAAE,UAAA;EAAA;AACb,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"index.native.js","names":[],"sources":["jsx/index.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, \"default\"), secondTarget && __copyProps(secondTarget, mod, \"default\"));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar index_exports = {};\nmodule.exports = __toCommonJS(index_exports);\n__reExport(index_exports, require(\"./Checkbox\"), module.exports);\n__reExport(index_exports, require(\"./CheckboxStyledContext\"), module.exports);\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,cAAc,QAAQ,KAAK,kBAAkB,YAAY,QAAQ,KAAK,SAAS,GAAG,gBAAgB,YAAY,cAAc,KAAK,SAAS;AAC9I,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,gBAAgB,CAAC;AACrB,OAAO,UAAU,aAAa,aAAa;AAC3C,WAAW,eAAe,QAAQ,sBAAY,GAAG,OAAO,OAAO;AAC/D,WAAW,eAAe,QAAQ,mCAAyB,GAAG,OAAO,OAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/checkbox",
3
- "version": "2.7.7",
3
+ "version": "3.0.0-beta.637.1",
4
4
  "gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
5
5
  "source": "src/index.ts",
6
6
  "files": [
@@ -35,23 +35,13 @@
35
35
  "clean:build": "tamagui-build clean:build"
36
36
  },
37
37
  "dependencies": {
38
- "@tamagui/checkbox-headless": "2.7.7",
39
- "@tamagui/compose-refs": "2.7.7",
40
- "@tamagui/constants": "2.7.7",
41
- "@tamagui/core": "2.7.7",
42
- "@tamagui/create-context": "2.7.7",
43
- "@tamagui/focusable": "2.7.7",
44
- "@tamagui/get-token": "2.7.7",
45
- "@tamagui/helpers": "2.7.7",
46
- "@tamagui/helpers-tamagui": "2.7.7",
47
- "@tamagui/label": "2.7.7",
48
- "@tamagui/stacks": "2.7.7",
49
- "@tamagui/use-controllable-state": "2.7.7",
50
- "@tamagui/font-size": "2.7.7",
51
- "@tamagui/use-previous": "2.7.7"
38
+ "@tamagui/checkbox-headless": "3.0.0-beta.637.1",
39
+ "@tamagui/core": "3.0.0-beta.637.1",
40
+ "@tamagui/focusable": "3.0.0-beta.637.1",
41
+ "@tamagui/use-controllable-state": "3.0.0-beta.637.1"
52
42
  },
53
43
  "devDependencies": {
54
- "@tamagui/build": "2.7.7",
44
+ "@tamagui/build": "3.0.0-beta.637.1",
55
45
  "react": ">=19"
56
46
  },
57
47
  "peerDependencies": {
package/src/Checkbox.tsx CHANGED
@@ -1,31 +1,35 @@
1
1
  // fork of radix
2
2
  // https://github.com/radix-ui/primitives/tree/main/packages/react/checkbox/src/Checkbox.tsx
3
3
 
4
- import { getVariableValue, styled } from '@tamagui/core'
5
- import { getSize } from '@tamagui/get-token'
6
- import { YStack } from '@tamagui/stacks'
4
+ import type {
5
+ CheckedState,
6
+ CheckboxExtraProps as HeadlessCheckboxExtraProps,
7
+ } from '@tamagui/checkbox-headless'
8
+ import { isIndeterminate, useCheckbox } from '@tamagui/checkbox-headless'
9
+ import type { GetProps, NativeValue, SizeTokens } from '@tamagui/core'
10
+ import {
11
+ createStyledHOC,
12
+ isWeb,
13
+ shouldRenderNativePlatform,
14
+ styled,
15
+ useProps,
16
+ View,
17
+ withStaticProperties,
18
+ } from '@tamagui/core'
19
+ import { registerFocusable } from '@tamagui/focusable'
20
+ import { useControllableState } from '@tamagui/use-controllable-state'
21
+ import React, { useMemo } from 'react'
7
22
 
8
23
  import { CheckboxStyledContext } from './CheckboxStyledContext'
9
24
 
10
- /* -------------------------------------------------------------------------------------------------
11
- * CheckboxIndicator
12
- * -----------------------------------------------------------------------------------------------*/
13
25
  const INDICATOR_NAME = 'CheckboxIndicator'
14
26
 
15
27
  export const CheckboxIndicatorFrame = styled(
16
- YStack,
28
+ View,
17
29
  {
18
30
  // use Checkbox for easier themes
19
- name: INDICATOR_NAME,
31
+ displayName: INDICATOR_NAME,
20
32
  context: CheckboxStyledContext,
21
- variants: {
22
- unstyled: {
23
- false: {},
24
- },
25
- } as const,
26
- defaultVariants: {
27
- unstyled: process.env.TAMAGUI_HEADLESS === '1',
28
- },
29
33
  },
30
34
  {
31
35
  accept: {
@@ -34,85 +38,25 @@ export const CheckboxIndicatorFrame = styled(
34
38
  }
35
39
  )
36
40
 
37
- /* -------------------------------------------------------------------------------------------------
38
- * Checkbox
39
- * -----------------------------------------------------------------------------------------------*/
40
-
41
41
  const CHECKBOX_NAME = 'Checkbox'
42
42
 
43
43
  export const CheckboxFrame = styled(
44
- YStack,
44
+ View,
45
45
  {
46
- name: CHECKBOX_NAME,
46
+ displayName: CHECKBOX_NAME,
47
47
  render: 'button',
48
-
49
48
  context: CheckboxStyledContext,
50
- variants: {
51
- unstyled: {
52
- false: {
53
- size: '$true',
54
- backgroundColor: '$background',
55
- alignItems: 'center',
56
- justifyContent: 'center',
57
- borderWidth: 1,
58
- borderColor: '$borderColor',
59
-
60
- hoverStyle: {
61
- borderColor: '$borderColorHover',
62
- },
63
-
64
- pressStyle: {
65
- backgroundColor: '$backgroundPress',
66
- borderColor: '$borderColorPress',
67
- },
68
-
69
- focusStyle: {
70
- borderColor: '$borderColorFocus',
71
- },
72
-
73
- focusVisibleStyle: {
74
- outlineStyle: 'solid',
75
- outlineWidth: 2,
76
- outlineColor: '$outlineColor',
77
- },
78
- },
79
- },
49
+ alignItems: 'center',
50
+ justifyContent: 'center',
80
51
 
52
+ variants: {
81
53
  disabled: {
82
54
  true: {
83
55
  pointerEvents: 'none',
84
56
  userSelect: 'none',
85
- cursor: 'not-allowed',
86
-
87
- hoverStyle: {
88
- borderColor: '$borderColor',
89
- backgroundColor: '$background',
90
- },
91
-
92
- pressStyle: {
93
- borderColor: '$borderColor',
94
- backgroundColor: '$background',
95
- },
96
-
97
- focusStyle: {
98
- outlineWidth: 0,
99
- },
100
- },
101
- },
102
-
103
- size: {
104
- '...size': (val) => {
105
- const radiusToken = getVariableValue(getSize(val)) / 8
106
- return {
107
- borderRadius: radiusToken,
108
- }
109
57
  },
110
58
  },
111
59
  } as const,
112
-
113
- defaultVariants: {
114
- unstyled: process.env.TAMAGUI_HEADLESS === '1',
115
- },
116
60
  },
117
61
  {
118
62
  accept: {
@@ -120,3 +64,167 @@ export const CheckboxFrame = styled(
120
64
  } as const,
121
65
  }
122
66
  )
67
+
68
+ type CheckboxExpectingVariantProps = {
69
+ size?: SizeTokens | true
70
+ }
71
+
72
+ type CheckboxExtraProps = HeadlessCheckboxExtraProps & {
73
+ native?: NativeValue<'web'>
74
+ }
75
+
76
+ type CheckboxFrameActiveStyleProps = {
77
+ activeStyle?: GetProps<typeof CheckboxFrame>
78
+ activeTheme?: string | null
79
+ }
80
+
81
+ type CheckboxIndicatorActiveStyleProps = {
82
+ activeStyle?: GetProps<typeof CheckboxIndicatorFrame>
83
+ }
84
+
85
+ export type CheckboxProps = GetProps<typeof CheckboxFrame> &
86
+ CheckboxExtraProps &
87
+ CheckboxExpectingVariantProps &
88
+ CheckboxFrameActiveStyleProps
89
+
90
+ type CheckboxIndicatorExtraProps = {
91
+ /**
92
+ * Used to force mounting when more control is needed. Useful when
93
+ * controlling animation with React animation libraries.
94
+ */
95
+ forceMount?: boolean
96
+ }
97
+
98
+ export type CheckboxIndicatorProps = GetProps<typeof CheckboxIndicatorFrame> &
99
+ CheckboxIndicatorExtraProps &
100
+ CheckboxIndicatorActiveStyleProps
101
+
102
+ export const CheckboxContext = React.createContext<{
103
+ checked: CheckedState
104
+ disabled?: boolean
105
+ }>({
106
+ checked: false,
107
+ disabled: false,
108
+ })
109
+
110
+ const CheckboxComponent = createStyledHOC(
111
+ CheckboxFrame,
112
+ function Checkbox(_props: CheckboxProps, forwardedRef) {
113
+ const {
114
+ checked: checkedProp,
115
+ defaultChecked,
116
+ onCheckedChange,
117
+ native,
118
+ activeStyle,
119
+ activeTheme,
120
+ ...props
121
+ } = _props
122
+ const propsActive = useProps(props)
123
+
124
+ const styledContext = React.useContext(CheckboxStyledContext.context)
125
+ const [checked = false, setChecked] = useControllableState({
126
+ prop: checkedProp,
127
+ defaultProp: defaultChecked!,
128
+ onChange: onCheckedChange,
129
+ })
130
+
131
+ const { checkboxProps, checkboxRef, bubbleInput } = useCheckbox(
132
+ // @ts-ignore
133
+ propsActive,
134
+ [checked, setChecked],
135
+ forwardedRef
136
+ )
137
+
138
+ if (process.env.TAMAGUI_TARGET === 'native') {
139
+ React.useEffect(() => {
140
+ if (!props.id) return
141
+ if (props.disabled) return
142
+
143
+ return registerFocusable(props.id, {
144
+ focusAndSelect: () => {
145
+ setChecked?.((value) => !value)
146
+ },
147
+ focus: () => {},
148
+ })
149
+ }, [props.id, props.disabled])
150
+ }
151
+
152
+ const renderNative = shouldRenderNativePlatform(native)
153
+ if (renderNative === 'web') {
154
+ return (
155
+ <input
156
+ type="checkbox"
157
+ defaultChecked={isIndeterminate(checked) ? false : checked}
158
+ tabIndex={-1}
159
+ ref={checkboxRef as any}
160
+ disabled={checkboxProps.disabled}
161
+ style={checkboxProps.style as any}
162
+ />
163
+ )
164
+ }
165
+
166
+ const memoizedContext = useMemo(
167
+ () => ({
168
+ checked,
169
+ disabled: checkboxProps.disabled,
170
+ }),
171
+ [checked, checkboxProps.disabled]
172
+ )
173
+
174
+ const isActive = !!checked
175
+ const disabled = checkboxProps.disabled
176
+
177
+ return (
178
+ <CheckboxContext.Provider value={memoizedContext}>
179
+ <CheckboxStyledContext.Provider
180
+ size={propsActive.size ?? styledContext?.size ?? true}
181
+ active={isActive}
182
+ disabled={disabled}
183
+ >
184
+ <CheckboxFrame
185
+ render="button"
186
+ ref={checkboxRef}
187
+ theme={activeTheme ?? null}
188
+ {...(isWeb && { type: 'button' })}
189
+ checked={checked}
190
+ disabled={disabled}
191
+ {...(checkboxProps as CheckboxProps)}
192
+ {...props}
193
+ {...(isActive && activeStyle ? (activeStyle as object) : undefined)}
194
+ >
195
+ {propsActive.children}
196
+ </CheckboxFrame>
197
+ {bubbleInput}
198
+ </CheckboxStyledContext.Provider>
199
+ </CheckboxContext.Provider>
200
+ )
201
+ }
202
+ )
203
+
204
+ const CheckboxIndicator = createStyledHOC(
205
+ CheckboxIndicatorFrame,
206
+ (props: CheckboxIndicatorProps, forwardedRef) => {
207
+ const { children, forceMount, activeStyle, ...indicatorProps } = props
208
+ const { active } = CheckboxStyledContext.useStyledContext()
209
+ const context = React.useContext(CheckboxContext)
210
+
211
+ if (forceMount || isIndeterminate(context.checked) || context.checked === true) {
212
+ return (
213
+ <CheckboxIndicatorFrame
214
+ pointerEvents="none"
215
+ {...indicatorProps}
216
+ {...(active && activeStyle ? (activeStyle as object) : undefined)}
217
+ ref={forwardedRef}
218
+ >
219
+ {children}
220
+ </CheckboxIndicatorFrame>
221
+ )
222
+ }
223
+
224
+ return null
225
+ }
226
+ )
227
+
228
+ export const Checkbox = withStaticProperties(CheckboxComponent, {
229
+ Indicator: CheckboxIndicator,
230
+ })
@@ -2,15 +2,11 @@ import type { SizeTokens } from '@tamagui/core'
2
2
  import { createStyledContext } from '@tamagui/core'
3
3
 
4
4
  export const CheckboxStyledContext = createStyledContext<{
5
- size: SizeTokens
6
- scaleIcon: number
7
- unstyled?: boolean
5
+ size: SizeTokens | true
8
6
  active?: boolean
9
7
  disabled?: boolean
10
8
  }>({
11
- size: '$true' as SizeTokens,
12
- scaleIcon: 1,
13
- unstyled: process.env.TAMAGUI_HEADLESS === '1',
9
+ size: true,
14
10
  active: false,
15
11
  disabled: false,
16
12
  })
package/src/index.ts CHANGED
@@ -1,12 +1,3 @@
1
- import { CheckboxFrame, CheckboxIndicatorFrame } from './Checkbox'
2
- import { createCheckbox } from './createCheckbox'
3
-
4
- export * from './createCheckbox'
5
1
  export * from './Checkbox'
6
2
  export * from './CheckboxStyledContext'
7
3
  export type { CheckedState } from '@tamagui/checkbox-headless'
8
-
9
- export const Checkbox = createCheckbox({
10
- Frame: CheckboxFrame,
11
- Indicator: CheckboxIndicatorFrame,
12
- })