beacon-ui 3.1.5 → 3.1.7

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.
@@ -1,64 +1,322 @@
1
1
  "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useState, useCallback } from "react";
4
- import { SwitchPreview } from "./SwitchPreview";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState, useCallback, useMemo } from "react";
5
4
  import { useThemeSafe } from "../providers/ThemeProvider";
6
- export function Switch({ checked = false, onChange, disabled = false, id, ariaLabel, showIcons = false, }) {
7
- const themeContext = useThemeSafe();
8
- const theme = themeContext?.theme;
9
- const hue = themeContext?.hue;
10
- const [status, setStatus] = useState("default");
11
- const handleClick = useCallback(() => {
5
+ import { SunIcon, MoonIcon } from "../icons";
6
+ const TRACK_WIDTH = "52px";
7
+ const HANDLE_SIZE = 24;
8
+ const ICON_CONTAINER_SIZE = 32;
9
+ const ICON_SIZE = 20;
10
+ export function Switch({ checked = false, onChange, disabled = false, id, "aria-label": ariaLabel, showIcons = false, status: statusProp, className, style, onClick, onKeyDown, onMouseEnter, onMouseLeave, onFocus, onBlur, onMouseDown, onMouseUp, ref, ...rest }) {
11
+ useThemeSafe(); // Ensure theme context is available
12
+ const [internalStatus, setInternalStatus] = useState("default");
13
+ const status = statusProp ?? internalStatus;
14
+ const handleClick = useCallback((e) => {
12
15
  if (!disabled && onChange) {
13
16
  onChange(!checked);
14
17
  }
15
- }, [checked, disabled, onChange]);
18
+ onClick?.(e);
19
+ }, [checked, disabled, onChange, onClick]);
16
20
  const handleKeyDown = useCallback((e) => {
17
- if (disabled)
21
+ if (disabled) {
22
+ onKeyDown?.(e);
18
23
  return;
24
+ }
19
25
  if (e.key === " " || e.key === "Enter") {
20
26
  e.preventDefault();
21
27
  if (onChange) {
22
28
  onChange(!checked);
23
29
  }
24
30
  }
25
- }, [checked, disabled, onChange]);
26
- const handleMouseEnter = useCallback(() => {
27
- if (!disabled) {
28
- setStatus("hovered");
31
+ onKeyDown?.(e);
32
+ }, [checked, disabled, onChange, onKeyDown]);
33
+ const handleMouseEnter = useCallback((e) => {
34
+ if (!disabled && !statusProp) {
35
+ setInternalStatus("hovered");
29
36
  }
30
- }, [disabled]);
31
- const handleMouseLeave = useCallback(() => {
32
- if (!disabled) {
33
- setStatus("default");
37
+ onMouseEnter?.(e);
38
+ }, [disabled, statusProp, onMouseEnter]);
39
+ const handleMouseLeave = useCallback((e) => {
40
+ if (!disabled && !statusProp) {
41
+ setInternalStatus("default");
34
42
  }
35
- }, [disabled]);
36
- const handleFocus = useCallback(() => {
37
- if (!disabled) {
38
- setStatus("focused");
43
+ onMouseLeave?.(e);
44
+ }, [disabled, statusProp, onMouseLeave]);
45
+ const handleFocus = useCallback((e) => {
46
+ if (!disabled && !statusProp) {
47
+ setInternalStatus("focused");
39
48
  }
40
- }, [disabled]);
41
- const handleBlur = useCallback(() => {
42
- if (!disabled) {
43
- setStatus("default");
49
+ onFocus?.(e);
50
+ }, [disabled, statusProp, onFocus]);
51
+ const handleBlur = useCallback((e) => {
52
+ if (!disabled && !statusProp) {
53
+ setInternalStatus("default");
44
54
  }
45
- }, [disabled]);
46
- const handleMouseDown = useCallback(() => {
47
- if (!disabled) {
48
- setStatus("pressed");
55
+ onBlur?.(e);
56
+ }, [disabled, statusProp, onBlur]);
57
+ const handleMouseDown = useCallback((e) => {
58
+ if (!disabled && !statusProp) {
59
+ setInternalStatus("pressed");
49
60
  }
50
- }, [disabled]);
51
- const handleMouseUp = useCallback(() => {
52
- if (!disabled) {
53
- setStatus("hovered");
61
+ onMouseDown?.(e);
62
+ }, [disabled, statusProp, onMouseDown]);
63
+ const handleMouseUp = useCallback((e) => {
64
+ if (!disabled && !statusProp) {
65
+ setInternalStatus("hovered");
54
66
  }
55
- }, [disabled]);
67
+ onMouseUp?.(e);
68
+ }, [disabled, statusProp, onMouseUp]);
56
69
  const currentStatus = disabled ? "disabled" : status;
57
- return (_jsx("button", { type: "button", id: id, role: "switch", "aria-checked": checked, "aria-label": ariaLabel, "aria-disabled": disabled, disabled: disabled, onClick: handleClick, onKeyDown: handleKeyDown, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, onFocus: handleFocus, onBlur: handleBlur, onMouseDown: handleMouseDown, onMouseUp: handleMouseUp, style: {
70
+ const isDisabled = disabled;
71
+ const trackStyles = useMemo(() => {
72
+ const baseStyles = {
73
+ display: "flex",
74
+ alignItems: "center",
75
+ padding: "var(--spacing-50)",
76
+ borderRadius: "var(--corner-radius-full)",
77
+ borderWidth: "var(--border-width-25)",
78
+ borderStyle: "solid",
79
+ position: "relative",
80
+ transition: "background-color 0.15s ease, border-color 0.15s ease",
81
+ };
82
+ if (showIcons) {
83
+ // With icons variant
84
+ if (currentStatus === "disabled") {
85
+ return {
86
+ ...baseStyles,
87
+ width: "auto",
88
+ backgroundColor: "var(--bg-page-primary)",
89
+ borderColor: "var(--border-strong-100)",
90
+ justifyContent: "flex-end",
91
+ };
92
+ }
93
+ if (currentStatus === "hovered") {
94
+ return {
95
+ ...baseStyles,
96
+ width: "auto",
97
+ backgroundColor: "var(--bg-page-secondary)",
98
+ borderColor: "var(--border-strong-200)",
99
+ justifyContent: "flex-end",
100
+ };
101
+ }
102
+ if (currentStatus === "focused" || currentStatus === "pressed") {
103
+ return {
104
+ ...baseStyles,
105
+ width: "auto",
106
+ backgroundColor: "var(--bg-page-secondary)",
107
+ borderColor: "var(--border-neutral-primary)",
108
+ justifyContent: "flex-end",
109
+ };
110
+ }
111
+ return {
112
+ ...baseStyles,
113
+ width: "auto",
114
+ backgroundColor: "var(--bg-page-primary)",
115
+ borderColor: "var(--border-strong-200)",
116
+ justifyContent: "flex-end",
117
+ };
118
+ }
119
+ // Default variant (no icons)
120
+ if (currentStatus === "disabled") {
121
+ if (checked) {
122
+ return {
123
+ ...baseStyles,
124
+ width: TRACK_WIDTH,
125
+ backgroundColor: "var(--bg-primary-disabled)",
126
+ borderColor: "var(--border-strong-100)",
127
+ justifyContent: "flex-end",
128
+ };
129
+ }
130
+ else {
131
+ return {
132
+ ...baseStyles,
133
+ width: TRACK_WIDTH,
134
+ backgroundColor: "var(--bg-disabled)",
135
+ borderColor: "var(--border-strong-100)",
136
+ justifyContent: "flex-start",
137
+ };
138
+ }
139
+ }
140
+ if (checked) {
141
+ if (currentStatus === "hovered") {
142
+ return {
143
+ ...baseStyles,
144
+ width: TRACK_WIDTH,
145
+ backgroundColor: "var(--bg-primary-on-hover)",
146
+ borderColor: "var(--border-strong-100)",
147
+ justifyContent: "flex-end",
148
+ };
149
+ }
150
+ if (currentStatus === "focused") {
151
+ return {
152
+ ...baseStyles,
153
+ width: TRACK_WIDTH,
154
+ backgroundColor: "var(--bg-primary-on-focused)",
155
+ borderColor: "var(--border-primary)",
156
+ justifyContent: "flex-end",
157
+ };
158
+ }
159
+ if (currentStatus === "pressed") {
160
+ return {
161
+ ...baseStyles,
162
+ width: TRACK_WIDTH,
163
+ backgroundColor: "var(--bg-primary-pressed)",
164
+ borderColor: "var(--border-primary)",
165
+ justifyContent: "flex-end",
166
+ };
167
+ }
168
+ return {
169
+ ...baseStyles,
170
+ width: TRACK_WIDTH,
171
+ backgroundColor: "var(--bg-primary)",
172
+ borderColor: "var(--border-strong-100)",
173
+ justifyContent: "flex-end",
174
+ };
175
+ }
176
+ else {
177
+ if (currentStatus === "hovered") {
178
+ return {
179
+ ...baseStyles,
180
+ width: TRACK_WIDTH,
181
+ backgroundColor: "var(--bg-page-secondary)",
182
+ borderColor: "var(--border-strong-100)",
183
+ justifyContent: "flex-start",
184
+ };
185
+ }
186
+ if (currentStatus === "focused") {
187
+ return {
188
+ ...baseStyles,
189
+ width: TRACK_WIDTH,
190
+ backgroundColor: "var(--bg-page-secondary)",
191
+ borderColor: "var(--border-neutral-secondary)",
192
+ justifyContent: "flex-start",
193
+ };
194
+ }
195
+ if (currentStatus === "pressed") {
196
+ return {
197
+ ...baseStyles,
198
+ width: TRACK_WIDTH,
199
+ backgroundColor: "var(--bg-page-secondary)",
200
+ borderColor: "var(--border-strong)",
201
+ justifyContent: "flex-start",
202
+ };
203
+ }
204
+ return {
205
+ ...baseStyles,
206
+ width: TRACK_WIDTH,
207
+ backgroundColor: "var(--bg-page-primary)",
208
+ borderColor: "var(--border-strong-100)",
209
+ justifyContent: "flex-start",
210
+ };
211
+ }
212
+ }, [checked, currentStatus, showIcons]);
213
+ const handleStyles = useMemo(() => {
214
+ return {
215
+ width: `${HANDLE_SIZE}px`,
216
+ height: `${HANDLE_SIZE}px`,
217
+ borderRadius: "var(--corner-radius-full)",
218
+ backgroundColor: checked ? "var(--fg-on-action)" : "var(--fg-disabled)",
219
+ flexShrink: 0,
220
+ boxShadow: "var(--shadow-subtle)",
221
+ };
222
+ }, [checked]);
223
+ const nightContainerStyles = useMemo(() => {
224
+ const baseStyles = {
225
+ display: "flex",
226
+ alignItems: "center",
227
+ justifyContent: "center",
228
+ width: `${ICON_CONTAINER_SIZE}px`,
229
+ height: `${ICON_CONTAINER_SIZE}px`,
230
+ borderRadius: "var(--corner-radius-full)",
231
+ flexShrink: 0,
232
+ border: "none",
233
+ };
234
+ if (checked) {
235
+ return {
236
+ ...baseStyles,
237
+ backgroundColor: "transparent",
238
+ };
239
+ }
240
+ else {
241
+ if (currentStatus === "disabled") {
242
+ return {
243
+ ...baseStyles,
244
+ backgroundColor: "var(--bg-page-secondary)",
245
+ };
246
+ }
247
+ if (currentStatus === "pressed") {
248
+ return {
249
+ ...baseStyles,
250
+ backgroundColor: "var(--bg-page-tertiary)",
251
+ };
252
+ }
253
+ return {
254
+ ...baseStyles,
255
+ backgroundColor: "var(--bg-page-tertiary)",
256
+ };
257
+ }
258
+ }, [checked, currentStatus]);
259
+ const dayContainerStyles = useMemo(() => {
260
+ const baseStyles = {
261
+ display: "flex",
262
+ alignItems: "center",
263
+ justifyContent: "center",
264
+ width: `${ICON_CONTAINER_SIZE}px`,
265
+ height: `${ICON_CONTAINER_SIZE}px`,
266
+ borderRadius: "var(--corner-radius-full)",
267
+ flexShrink: 0,
268
+ border: "none",
269
+ };
270
+ if (checked) {
271
+ if (currentStatus === "disabled") {
272
+ return {
273
+ ...baseStyles,
274
+ backgroundColor: "var(--bg-page-secondary)",
275
+ };
276
+ }
277
+ if (currentStatus === "pressed") {
278
+ return {
279
+ ...baseStyles,
280
+ backgroundColor: "var(--bg-page-tertiary)",
281
+ };
282
+ }
283
+ return {
284
+ ...baseStyles,
285
+ backgroundColor: "var(--bg-page-tertiary)",
286
+ };
287
+ }
288
+ else {
289
+ return {
290
+ ...baseStyles,
291
+ backgroundColor: "transparent",
292
+ };
293
+ }
294
+ }, [checked, currentStatus]);
295
+ const nightIconColor = useMemo(() => {
296
+ if (currentStatus === "disabled") {
297
+ return "var(--fg-disabled)";
298
+ }
299
+ if (checked) {
300
+ return "var(--fg-primary)";
301
+ }
302
+ return "var(--fg-neutral)";
303
+ }, [checked, currentStatus]);
304
+ const dayIconColor = useMemo(() => {
305
+ if (currentStatus === "disabled") {
306
+ return "var(--fg-disabled)";
307
+ }
308
+ if (checked) {
309
+ return "var(--fg-neutral)";
310
+ }
311
+ return "var(--fg-warning)";
312
+ }, [checked, currentStatus]);
313
+ const switchElement = showIcons ? (_jsxs("div", { style: trackStyles, children: [_jsx("div", { style: nightContainerStyles, children: _jsx("div", { style: { color: nightIconColor, display: "flex", alignItems: "center", justifyContent: "center" }, children: _jsx(MoonIcon, { size: ICON_SIZE }) }) }), _jsx("div", { style: dayContainerStyles, children: _jsx("div", { style: { color: dayIconColor, display: "flex", alignItems: "center", justifyContent: "center" }, children: _jsx(SunIcon, { size: ICON_SIZE }) }) })] })) : (_jsx("div", { style: trackStyles, children: _jsx("div", { style: handleStyles }) }));
314
+ return (_jsx("button", { ref: ref, type: "button", id: id, role: "switch", "aria-checked": checked, "aria-label": ariaLabel, "aria-disabled": disabled, disabled: disabled, className: className, style: {
58
315
  border: "none",
59
316
  background: "none",
60
317
  padding: 0,
61
318
  cursor: disabled ? "not-allowed" : "pointer",
62
319
  outline: "none",
63
- }, children: _jsx(SwitchPreview, { checked: checked, status: currentStatus, showIcons: showIcons, theme: theme, hue: hue }) }));
320
+ ...style,
321
+ }, onClick: handleClick, onKeyDown: handleKeyDown, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, onFocus: handleFocus, onBlur: handleBlur, onMouseDown: handleMouseDown, onMouseUp: handleMouseUp, ...rest, children: switchElement }));
64
322
  }
package/dist/index.d.ts CHANGED
@@ -7,6 +7,15 @@ export { Avatar } from "./components/Avatar";
7
7
  export { Chip } from "./components/Chip";
8
8
  export { Menu } from "./components/Menu";
9
9
  export { RadioButton } from "./components/RadioButton";
10
+ export type { ButtonProps, ButtonVariant, ButtonSize, CornerRadiusStep, JustifyContent, ButtonState } from "./components/Button";
11
+ export type { CardProps, CardType, ProductCardSize, ProductCardStatus, ExperienceCardType, GenericCardStatus } from "./components/Card";
12
+ export type { CheckboxProps, CheckboxStatus } from "./components/Checkbox";
13
+ export type { SwitchProps, SwitchStatus } from "./components/Switch";
14
+ export type { InputProps, InputSize, InputStatus } from "./components/Input";
15
+ export type { AvatarProps, AvatarSize, AvatarType, AvatarColor, AvatarVariant } from "./components/Avatar";
16
+ export type { ChipProps, ChipSize, ChipColor } from "./components/Chip";
17
+ export type { MenuProps } from "./components/Menu";
18
+ export type { RadioButtonProps, RadioButtonStatus } from "./components/RadioButton";
10
19
  export { ThemeProvider, useTheme, useThemeSafe } from "./providers/ThemeProvider";
11
20
  export type { Theme, HueVariant } from "./tokens/types";
12
21
  export type { ColorPrimitive, SemanticColor, SpacingToken, BackgroundToken, ForegroundToken, BorderToken, } from "./tokens/types";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE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I,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACxI,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC3E,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACrE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC7E,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC3G,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACxE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGpF,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGlF,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACxD,YAAY,EACV,cAAc,EACd,aAAa,EACb,YAAY,EACZ,eAAe,EACf,eAAe,EACf,WAAW,GACZ,MAAM,gBAAgB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beacon-ui",
3
- "version": "3.1.5",
3
+ "version": "3.1.7",
4
4
  "description": "Beacon Design System - Components and tokens",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",