@hanzogui/button 3.0.3 → 7.3.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.
Files changed (64) hide show
  1. package/LICENSE +40 -19
  2. package/dist/cjs/Button.cjs +195 -188
  3. package/dist/cjs/Button.native.js +194 -189
  4. package/dist/cjs/Button.native.js.map +1 -1
  5. package/dist/cjs/Button.test.cjs +33 -32
  6. package/dist/cjs/Button.test.native.js +33 -32
  7. package/dist/cjs/Button.test.native.js.map +1 -1
  8. package/dist/cjs/index.cjs +7 -5
  9. package/dist/cjs/index.native.js +7 -5
  10. package/dist/cjs/index.native.js.map +1 -1
  11. package/dist/cjs/v1/Button.cjs +216 -213
  12. package/dist/cjs/v1/Button.native.js +217 -215
  13. package/dist/cjs/v1/Button.native.js.map +1 -1
  14. package/dist/cjs/v1/Button.test.cjs +6 -6
  15. package/dist/cjs/v1/Button.test.native.js +6 -6
  16. package/dist/cjs/v1/Button.test.native.js.map +1 -1
  17. package/dist/cjs/v1/index.cjs +7 -5
  18. package/dist/cjs/v1/index.native.js +7 -5
  19. package/dist/cjs/v1/index.native.js.map +1 -1
  20. package/dist/esm/Button.mjs +173 -168
  21. package/dist/esm/Button.mjs.map +1 -1
  22. package/dist/esm/Button.native.js +174 -171
  23. package/dist/esm/Button.native.js.map +1 -1
  24. package/dist/esm/Button.test.mjs +27 -26
  25. package/dist/esm/Button.test.mjs.map +1 -1
  26. package/dist/esm/Button.test.native.js +27 -26
  27. package/dist/esm/Button.test.native.js.map +1 -1
  28. package/dist/esm/v1/Button.mjs +194 -193
  29. package/dist/esm/v1/Button.mjs.map +1 -1
  30. package/dist/esm/v1/Button.native.js +195 -195
  31. package/dist/esm/v1/Button.native.js.map +1 -1
  32. package/dist/esm/v1/Button.test.mjs +2 -2
  33. package/dist/esm/v1/Button.test.mjs.map +1 -1
  34. package/dist/esm/v1/Button.test.native.js +2 -2
  35. package/dist/esm/v1/Button.test.native.js.map +1 -1
  36. package/dist/jsx/Button.mjs +173 -168
  37. package/dist/jsx/Button.mjs.map +1 -1
  38. package/dist/jsx/Button.native.js +194 -189
  39. package/dist/jsx/Button.native.js.map +1 -1
  40. package/dist/jsx/Button.test.mjs +27 -26
  41. package/dist/jsx/Button.test.mjs.map +1 -1
  42. package/dist/jsx/Button.test.native.js +33 -32
  43. package/dist/jsx/Button.test.native.js.map +1 -1
  44. package/dist/jsx/index.native.js +7 -5
  45. package/dist/jsx/v1/Button.mjs +194 -193
  46. package/dist/jsx/v1/Button.mjs.map +1 -1
  47. package/dist/jsx/v1/Button.native.js +217 -215
  48. package/dist/jsx/v1/Button.native.js.map +1 -1
  49. package/dist/jsx/v1/Button.test.mjs +2 -2
  50. package/dist/jsx/v1/Button.test.mjs.map +1 -1
  51. package/dist/jsx/v1/Button.test.native.js +6 -6
  52. package/dist/jsx/v1/Button.test.native.js.map +1 -1
  53. package/dist/jsx/v1/index.native.js +7 -5
  54. package/package.json +19 -17
  55. package/src/Button.tsx +5 -5
  56. package/src/v1/Button.tsx +5 -5
  57. package/types/Button.d.ts +17 -17
  58. package/types/Button.d.ts.map +1 -0
  59. package/types/Button.test.d.ts.map +1 -0
  60. package/types/index.d.ts.map +1 -0
  61. package/types/v1/Button.d.ts +24 -24
  62. package/types/v1/Button.d.ts.map +1 -0
  63. package/types/v1/Button.test.d.ts.map +1 -0
  64. package/types/v1/index.d.ts.map +1 -0
package/LICENSE CHANGED
@@ -1,21 +1,42 @@
1
- MIT License
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026-present, Hanzo AI, Inc.
4
+
5
+ Portions of this software are derived from upstream code originally licensed under
6
+ the MIT License, with the following copyright notices retained per its terms:
2
7
 
3
8
  Copyright (c) 2020 Nate Wienert
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
9
+ Copyright (c) 2015-present, Nicolas Gallagher.
10
+ Copyright (c) 2015-present, Facebook, Inc.
11
+ Copyright (c) 2021 Radix
12
+ Copyright (c) 2017 Carmelo Pullara
13
+ Copyright (c) 2018 Framer B.V.
14
+ Copyright (c) 2022 WorkOS
15
+
16
+ All rights reserved.
17
+
18
+ Redistribution and use in source and binary forms, with or without
19
+ modification, are permitted provided that the following conditions are met:
20
+
21
+ 1. Redistributions of source code must retain the above copyright notice, this
22
+ list of conditions and the following disclaimer.
23
+
24
+ 2. Redistributions in binary form must reproduce the above copyright notice,
25
+ this list of conditions and the following disclaimer in the documentation
26
+ and/or other materials provided with the distribution.
27
+
28
+ 3. Neither the name of the copyright holder nor the names of its contributors
29
+ may be used to endorse or promote products derived from this software
30
+ without specific prior written permission.
31
+
32
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
33
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
36
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42
+ POSSIBILITY OF SUCH DAMAGE.
@@ -3,20 +3,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: !0
9
- });
10
- },
11
- __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
14
  get: () => from[key],
14
15
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
16
  });
16
- return to;
17
- };
17
+ }
18
+ return to;
19
+ };
18
20
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
- value: !0
21
+ value: true
20
22
  }), mod);
21
23
  var Button_exports = {};
22
24
  __export(Button_exports, {
@@ -24,195 +26,200 @@ __export(Button_exports, {
24
26
  ButtonContext: () => ButtonContext
25
27
  });
26
28
  module.exports = __toCommonJS(Button_exports);
27
- var import_gui_font_size = require("@hanzogui/font-size"),
28
- import_gui_get_button_sized = require("@hanzogui/get-button-sized"),
29
- import_gui_helpers = require("@hanzogui/helpers"),
30
- import_gui_stacks = require("@hanzogui/stacks"),
31
- import_gui_text = require("@hanzogui/text"),
32
- import_gui_web = require("@hanzogui/web"),
33
- import_react = require("react"),
34
- import_jsx_runtime = require("react/jsx-runtime");
35
- const context = (0, import_gui_web.createStyledContext)({
36
- size: void 0,
37
- variant: void 0,
38
- color: void 0,
39
- elevation: void 0
29
+ var import_font_size = require("@hanzogui/font-size");
30
+ var import_get_button_sized = require("@hanzogui/get-button-sized");
31
+ var import_component_helpers = require("@hanzogui/component-helpers");
32
+ var import_stacks = require("@hanzogui/stacks");
33
+ var import_text = require("@hanzogui/text");
34
+ var import_web = require("@hanzogui/web");
35
+ var import_react = require("react");
36
+ var import_jsx_runtime = require("react/jsx-runtime");
37
+ const context = (0, import_web.createStyledContext)({
38
+ size: void 0,
39
+ variant: void 0,
40
+ color: void 0,
41
+ elevation: void 0
42
+ });
43
+ const Frame = (0, import_web.styled)(import_web.View, {
44
+ context,
45
+ name: "Button",
46
+ role: "button",
47
+ render: /* @__PURE__ */(0, import_jsx_runtime.jsx)("button", {
48
+ type: "button"
40
49
  }),
41
- Frame = (0, import_gui_web.styled)(import_gui_web.View, {
42
- context,
43
- name: "Button",
44
- role: "button",
45
- render: /* @__PURE__ */(0, import_jsx_runtime.jsx)("button", {
46
- type: "button"
47
- }),
48
- tabIndex: 0,
49
- variants: {
50
- unstyled: {
51
- false: {
52
- size: "$true",
53
- justifyContent: "center",
54
- alignItems: "center",
55
- flexWrap: "nowrap",
56
- flexDirection: "row",
57
- cursor: "pointer",
58
- backgroundColor: "$background",
59
- borderWidth: 1,
60
- borderColor: "transparent",
61
- hoverStyle: {
62
- backgroundColor: "$backgroundHover",
63
- borderColor: "$borderColorHover"
64
- },
65
- pressStyle: {
66
- backgroundColor: "$backgroundPress",
67
- borderColor: "$borderColorHover"
68
- },
69
- focusVisibleStyle: {
70
- outlineColor: "$outlineColor",
71
- outlineStyle: "solid",
72
- outlineWidth: 2
73
- }
50
+ tabIndex: 0,
51
+ variants: {
52
+ unstyled: {
53
+ false: {
54
+ size: "$true",
55
+ justifyContent: "center",
56
+ alignItems: "center",
57
+ flexWrap: "nowrap",
58
+ flexDirection: "row",
59
+ cursor: "pointer",
60
+ backgroundColor: "$background",
61
+ borderWidth: 1,
62
+ borderColor: "transparent",
63
+ hoverStyle: {
64
+ backgroundColor: "$backgroundHover",
65
+ borderColor: "$borderColorHover"
66
+ },
67
+ pressStyle: {
68
+ backgroundColor: "$backgroundPress",
69
+ borderColor: "$borderColorHover"
70
+ },
71
+ focusVisibleStyle: {
72
+ outlineColor: "$outlineColor",
73
+ outlineStyle: "solid",
74
+ outlineWidth: 2
74
75
  }
75
- },
76
- variant: {
77
- outlined: process.env.HANZO_GUI_HEADLESS === "1" ? {} : {
76
+ }
77
+ },
78
+ variant: {
79
+ outlined: process.env.GUI_HEADLESS === "1" ? {} : {
80
+ backgroundColor: "transparent",
81
+ borderWidth: 1,
82
+ borderColor: "$borderColor",
83
+ hoverStyle: {
78
84
  backgroundColor: "transparent",
79
- borderWidth: 1,
80
- borderColor: "$borderColor",
81
- hoverStyle: {
82
- backgroundColor: "transparent",
83
- borderColor: "$borderColorHover"
84
- },
85
- pressStyle: {
86
- backgroundColor: "transparent",
87
- borderColor: "$borderColorPress"
88
- }
89
- }
90
- },
91
- circular: import_gui_stacks.themeableVariants.circular,
92
- chromeless: import_gui_stacks.themeableVariants.chromeless,
93
- size: {
94
- "...size": (val, extras) => {
95
- const buttonStyle = (0, import_gui_get_button_sized.getButtonSized)(val, extras),
96
- gap = (0, import_gui_web.getTokenValue)(val);
97
- return {
98
- ...buttonStyle,
99
- gap
100
- };
85
+ borderColor: "$borderColorHover"
101
86
  },
102
- ":number": (val, extras) => {
103
- const buttonStyle = (0, import_gui_get_button_sized.getButtonSized)(val, extras),
104
- gap = val * 0.4;
105
- return {
106
- ...buttonStyle,
107
- gap
108
- };
87
+ pressStyle: {
88
+ backgroundColor: "transparent",
89
+ borderColor: "$borderColorPress"
109
90
  }
91
+ }
92
+ },
93
+ circular: import_stacks.themeableVariants.circular,
94
+ chromeless: import_stacks.themeableVariants.chromeless,
95
+ size: {
96
+ "...size": (val, extras) => {
97
+ const buttonStyle = (0, import_get_button_sized.getButtonSized)(val, extras);
98
+ const gap = (0, import_web.getTokenValue)(val);
99
+ return {
100
+ ...buttonStyle,
101
+ gap
102
+ };
110
103
  },
111
- elevation: {
112
- "...size": import_gui_stacks.getElevation,
113
- ":number": import_gui_stacks.getElevation
114
- },
115
- disabled: {
116
- true: {
117
- pointerEvents: "none",
118
- // @ts-ignore
119
- "aria-disabled": !0
120
- }
104
+ ":number": (val, extras) => {
105
+ const buttonStyle = (0, import_get_button_sized.getButtonSized)(val, extras);
106
+ const gap = val * 0.4;
107
+ return {
108
+ ...buttonStyle,
109
+ gap
110
+ };
121
111
  }
122
112
  },
123
- defaultVariants: {
124
- unstyled: process.env.HANZO_GUI_HEADLESS === "1"
113
+ elevation: {
114
+ "...size": import_stacks.getElevation,
115
+ ":number": import_stacks.getElevation
116
+ },
117
+ disabled: {
118
+ true: {
119
+ pointerEvents: "none",
120
+ // @ts-ignore
121
+ "aria-disabled": true
122
+ }
125
123
  }
126
- }),
127
- Text = (0, import_gui_web.styled)(import_gui_text.SizableText, {
128
- context,
129
- variants: {
130
- unstyled: {
131
- false: {
132
- userSelect: "none",
133
- cursor: "pointer",
134
- // flexGrow 1 leads to inconsistent native style where text pushes to start of view
135
- flexGrow: 0,
136
- flexShrink: 1,
137
- ellipsis: !0,
138
- color: "$color"
139
- }
124
+ },
125
+ defaultVariants: {
126
+ unstyled: process.env.GUI_HEADLESS === "1"
127
+ }
128
+ });
129
+ const Text = (0, import_web.styled)(import_text.SizableText, {
130
+ context,
131
+ variants: {
132
+ unstyled: {
133
+ false: {
134
+ userSelect: "none",
135
+ cursor: "pointer",
136
+ // flexGrow 1 leads to inconsistent native style where text pushes to start of view
137
+ flexGrow: 0,
138
+ flexShrink: 1,
139
+ ellipsis: true,
140
+ color: "$color"
140
141
  }
141
- },
142
- defaultVariants: {
143
- unstyled: process.env.HANZO_GUI_HEADLESS === "1"
144
142
  }
145
- }),
146
- Icon = props => {
147
- const {
148
- children,
149
- scaleIcon = 1,
150
- size
151
- } = props,
152
- styledContext = context.useStyledContext();
153
- if (!styledContext) throw new Error("Button.Icon must be used within a Button");
154
- const sizeToken = size ?? styledContext.size,
155
- iconColor = (0, import_gui_helpers.useCurrentColor)(styledContext.color),
156
- iconSize = (typeof sizeToken == "number" ? sizeToken * 0.5 : (0, import_gui_font_size.getFontSize)(sizeToken)) * scaleIcon;
157
- return (0, import_gui_helpers.getIcon)(children, {
158
- size: iconSize,
143
+ },
144
+ defaultVariants: {
145
+ unstyled: process.env.GUI_HEADLESS === "1"
146
+ }
147
+ });
148
+ const Icon = props => {
149
+ const {
150
+ children,
151
+ scaleIcon = 1,
152
+ size
153
+ } = props;
154
+ const styledContext = context.useStyledContext();
155
+ if (!styledContext) {
156
+ throw new Error("Button.Icon must be used within a Button");
157
+ }
158
+ const sizeToken = size ?? styledContext.size;
159
+ const iconColor = (0, import_component_helpers.useCurrentColor)(styledContext.color);
160
+ const iconSize = (typeof sizeToken === "number" ? sizeToken * 0.5 : (0, import_font_size.getFontSize)(sizeToken)) * scaleIcon;
161
+ return (0, import_component_helpers.getIcon)(children, {
162
+ size: iconSize,
163
+ color: iconColor
164
+ });
165
+ };
166
+ const ButtonContext = (0, import_web.createStyledContext)({
167
+ size: void 0,
168
+ variant: void 0,
169
+ color: void 0
170
+ });
171
+ const ButtonComponent = Frame.styleable((propsIn, ref) => {
172
+ const isNested = (0, import_react.useContext)(import_stacks.ButtonNestingContext);
173
+ const processedProps = (0, import_web.useProps)(propsIn, {
174
+ noNormalize: true,
175
+ noExpand: true
176
+ });
177
+ const {
178
+ children,
179
+ iconSize,
180
+ icon,
181
+ iconAfter,
182
+ scaleIcon = 1,
183
+ ...props
184
+ } = processedProps;
185
+ const size = propsIn.size || (propsIn.unstyled ? void 0 : "$true");
186
+ const styledContext = context.useStyledContext();
187
+ const iconColor = (0, import_component_helpers.useCurrentColor)(styledContext?.color);
188
+ const finalSize = iconSize ?? size ?? styledContext?.size;
189
+ const iconSizeNumber = (typeof finalSize === "number" ? finalSize * 0.5 : (0, import_font_size.getFontSize)(finalSize)) * scaleIcon;
190
+ const [themedIcon, themedIconAfter] = [icon, iconAfter].map(icon2 => {
191
+ if (!icon2) return null;
192
+ return (0, import_component_helpers.getIcon)(icon2, {
193
+ size: iconSizeNumber,
159
194
  color: iconColor
195
+ // No marginLeft or marginRight needed - spacing is handled by the gap property in Frame's size variants
160
196
  });
161
- },
162
- ButtonContext = (0, import_gui_web.createStyledContext)({
163
- size: void 0,
164
- variant: void 0,
165
- color: void 0
166
- }),
167
- ButtonComponent = Frame.styleable((propsIn, ref) => {
168
- const isNested = (0, import_react.useContext)(import_gui_stacks.ButtonNestingContext),
169
- processedProps = (0, import_gui_web.useProps)(propsIn, {
170
- noNormalize: !0,
171
- noExpand: !0
197
+ });
198
+ const wrappedChildren = (0, import_text.wrapChildrenInText)(Text, {
199
+ children
200
+ }, {
201
+ unstyled: process.env.GUI_HEADLESS === "1",
202
+ size: finalSize ?? styledContext?.size
203
+ });
204
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_stacks.ButtonNestingContext.Provider, {
205
+ value: true,
206
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(Frame, {
207
+ ref,
208
+ ...props,
209
+ ...(isNested && {
210
+ render: "span"
172
211
  }),
173
- {
174
- children,
175
- iconSize,
176
- icon,
177
- iconAfter,
178
- scaleIcon = 1,
179
- ...props
180
- } = processedProps,
181
- size = propsIn.size || (propsIn.unstyled ? void 0 : "$true"),
182
- styledContext = context.useStyledContext(),
183
- iconColor = (0, import_gui_helpers.useCurrentColor)(styledContext?.color),
184
- finalSize = iconSize ?? size ?? styledContext?.size,
185
- iconSizeNumber = (typeof finalSize == "number" ? finalSize * 0.5 : (0, import_gui_font_size.getFontSize)(finalSize)) * scaleIcon,
186
- [themedIcon, themedIconAfter] = [icon, iconAfter].map(icon2 => icon2 ? (0, import_gui_helpers.getIcon)(icon2, {
187
- size: iconSizeNumber,
188
- color: iconColor
189
- // No marginLeft or marginRight needed - spacing is handled by the gap property in Frame's size variants
190
- }) : null),
191
- wrappedChildren = (0, import_gui_text.wrapChildrenInText)(Text, {
192
- children
193
- }, {
194
- unstyled: process.env.HANZO_GUI_HEADLESS === "1",
195
- size: finalSize ?? styledContext?.size
196
- });
197
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_stacks.ButtonNestingContext.Provider, {
198
- value: !0,
199
- children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(Frame, {
200
- ref,
201
- ...props,
202
- ...(isNested && {
203
- render: "span"
204
- }),
205
- ...(props.circular && !propsIn.size && {
206
- size
207
- }),
208
- tabIndex: 0,
209
- children: [themedIcon, wrappedChildren, themedIconAfter]
210
- })
211
- });
212
- }),
213
- Button = (0, import_gui_web.withStaticProperties)(ButtonComponent, {
214
- Apply: context.Provider,
215
- Frame,
216
- Text,
217
- Icon
218
- });
212
+ ...(props.circular && !propsIn.size && {
213
+ size
214
+ }),
215
+ tabIndex: 0,
216
+ children: [themedIcon, wrappedChildren, themedIconAfter]
217
+ })
218
+ });
219
+ });
220
+ const Button = (0, import_web.withStaticProperties)(ButtonComponent, {
221
+ Apply: context.Provider,
222
+ Frame,
223
+ Text,
224
+ Icon
225
+ });