@stevederico/skateboard-ui 5.5.0 → 5.7.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ 5.7.0
2
+
3
+ Add optional Turnstile
4
+ Show sign-up errors
5
+
6
+ 5.6.0
7
+
8
+ Add Sheet onUserClose
9
+
1
10
  5.5.0
2
11
 
3
12
  Enlarge tap targets
@@ -11,6 +11,8 @@ export interface SheetProps {
11
11
  title?: string;
12
12
  minHeight?: string;
13
13
  children?: ReactNode;
14
+ /** Called when the person closes the sheet (swipe, outside tap, Escape), not when code calls hide(). */
15
+ onUserClose?: () => void;
14
16
  }
15
17
  /**
16
18
  * Bottom sheet (drawer) component with imperative open/close API.
@@ -21,6 +23,7 @@ export interface SheetProps {
21
23
  * @param {string} [props.title=""] - Sheet header title
22
24
  * @param {string} [props.minHeight="auto"] - Minimum sheet height CSS value
23
25
  * @param {React.ReactNode} props.children - Sheet body content
26
+ * @param {Function} [props.onUserClose] - Called when the person closes the sheet, not when code calls hide()
24
27
  * @param {React.Ref} ref - Ref exposing { show, hide, open, close, toggle }
25
28
  * @returns {JSX.Element} Drawer sheet
26
29
  *
@@ -10,6 +10,7 @@ import { Drawer, DrawerContent, DrawerHeader, DrawerTitle, } from "../ui/drawer.
10
10
  * @param {string} [props.title=""] - Sheet header title
11
11
  * @param {string} [props.minHeight="auto"] - Minimum sheet height CSS value
12
12
  * @param {React.ReactNode} props.children - Sheet body content
13
+ * @param {Function} [props.onUserClose] - Called when the person closes the sheet, not when code calls hide()
13
14
  * @param {React.Ref} ref - Ref exposing { show, hide, open, close, toggle }
14
15
  * @returns {JSX.Element} Drawer sheet
15
16
  *
@@ -30,7 +31,7 @@ import { Drawer, DrawerContent, DrawerHeader, DrawerTitle, } from "../ui/drawer.
30
31
  * }
31
32
  */
32
33
  const MySheet = forwardRef(function MySheet(props, ref) {
33
- const { title = "", minHeight = "auto", children } = props;
34
+ const { title = "", minHeight = "auto", children, onUserClose } = props;
34
35
  const [isOpen, setIsOpen] = useState(false);
35
36
  useImperativeHandle(ref, () => ({
36
37
  show: () => setIsOpen(true),
@@ -39,6 +40,10 @@ const MySheet = forwardRef(function MySheet(props, ref) {
39
40
  close: () => setIsOpen(false),
40
41
  toggle: () => setIsOpen(prev => !prev)
41
42
  }));
42
- return (_jsx(Drawer, { open: isOpen, onOpenChange: setIsOpen, children: _jsxs(DrawerContent, { style: { minHeight }, children: [_jsx(DrawerHeader, { children: _jsx(DrawerTitle, { children: title }) }), _jsx("div", { className: "px-4 pb-4", children: children })] }) }));
43
+ return (_jsx(Drawer, { open: isOpen, onOpenChange: (open) => {
44
+ setIsOpen(open);
45
+ if (!open)
46
+ onUserClose?.();
47
+ }, children: _jsxs(DrawerContent, { style: { minHeight }, children: [_jsx(DrawerHeader, { children: _jsx(DrawerTitle, { children: title }) }), _jsx("div", { className: "px-4 pb-4", children: children })] }) }));
43
48
  });
44
49
  export default MySheet;
@@ -10,6 +10,24 @@ import ConstantsIcon from '../core/constantsIcon.js';
10
10
  import { Sparkles } from 'lucide-react';
11
11
  import { getState } from "../core/Context.js";
12
12
  import { getBackendURL, useSafeNavigate, getAppKey } from '../core/Utilities.js';
13
+ let turnstileScript = null;
14
+ /** Load Cloudflare's Turnstile script once. */
15
+ function loadTurnstile() {
16
+ if (!turnstileScript) {
17
+ turnstileScript = new Promise((resolve, reject) => {
18
+ const script = document.createElement('script');
19
+ script.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit';
20
+ script.async = true;
21
+ script.onload = () => resolve();
22
+ script.onerror = () => {
23
+ turnstileScript = null;
24
+ reject(new Error('Turnstile failed to load'));
25
+ };
26
+ document.head.appendChild(script);
27
+ });
28
+ }
29
+ return turnstileScript;
30
+ }
13
31
  export default function SignUpView({ className, embedded = false, onSuccess, onSwitchMode, ...props }) {
14
32
  const { state, dispatch } = getState();
15
33
  const constants = state.constants;
@@ -20,6 +38,42 @@ export default function SignUpView({ className, embedded = false, onSuccess, onS
20
38
  const [isSubmitting, setIsSubmitting] = useState(false);
21
39
  const navigate = useSafeNavigate();
22
40
  const nameInputRef = useRef(null);
41
+ const turnstileRef = useRef(null);
42
+ const turnstileIdRef = useRef(null);
43
+ const [turnstileToken, setTurnstileToken] = useState('');
44
+ // Optional Cloudflare Turnstile: the backend hands out a site key from
45
+ // GET /signup/options. No key, or no endpoint, means no widget.
46
+ useEffect(() => {
47
+ let cancelled = false;
48
+ (async () => {
49
+ try {
50
+ const res = await fetch(`${getBackendURL()}/signup/options`, { credentials: 'include' });
51
+ if (!res.ok)
52
+ return;
53
+ const { turnstileSiteKey } = (await res.json());
54
+ if (!turnstileSiteKey || cancelled)
55
+ return;
56
+ await loadTurnstile();
57
+ const container = turnstileRef.current;
58
+ const api = window.turnstile;
59
+ if (!container || !api || cancelled)
60
+ return;
61
+ turnstileIdRef.current = api.render(container, {
62
+ sitekey: turnstileSiteKey,
63
+ appearance: 'interaction-only',
64
+ callback: (token) => setTurnstileToken(token),
65
+ 'expired-callback': () => setTurnstileToken(''),
66
+ 'error-callback': () => setTurnstileToken(''),
67
+ });
68
+ }
69
+ catch {
70
+ /* Turnstile is optional; sign-up works without it. */
71
+ }
72
+ })();
73
+ return () => {
74
+ cancelled = true;
75
+ };
76
+ }, []);
23
77
  // Focus the first input on mount
24
78
  useEffect(() => {
25
79
  if (!name && nameInputRef.current) {
@@ -45,7 +99,7 @@ export default function SignUpView({ className, embedded = false, onSuccess, onS
45
99
  method: 'POST',
46
100
  credentials: 'include',
47
101
  headers: { 'Content-Type': 'application/json' },
48
- body: JSON.stringify({ email, password, name })
102
+ body: JSON.stringify({ email, password, name, ...(turnstileToken ? { turnstileToken } : {}) })
49
103
  });
50
104
  if (response.ok) {
51
105
  const data = await response.json();
@@ -64,7 +118,13 @@ export default function SignUpView({ className, embedded = false, onSuccess, onS
64
118
  }
65
119
  }
66
120
  else {
67
- setErrorMessage('Invalid Credentials');
121
+ const failure = (await response.json().catch(() => null));
122
+ setErrorMessage(failure?.error || 'Invalid Credentials');
123
+ const api = window.turnstile;
124
+ if (api && turnstileIdRef.current) {
125
+ api.reset(turnstileIdRef.current);
126
+ setTurnstileToken('');
127
+ }
68
128
  }
69
129
  }
70
130
  catch (error) {
@@ -84,7 +144,7 @@ export default function SignUpView({ className, embedded = false, onSuccess, onS
84
144
  } })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { htmlFor: "password", children: "Password" }), _jsx(Input, { id: "password", type: "password", placeholder: "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022", autoComplete: "new-password", required: true, minLength: 6, maxLength: 72, value: password, onChange: (e) => {
85
145
  setPassword(e.target.value);
86
146
  setErrorMessage('');
87
- } }), _jsx("p", { className: "text-xs text-muted-foreground", children: "Minimum 6 characters" })] }), _jsx(Button, { type: "submit", variant: "gradient", size: "cta", className: "w-full", disabled: isSubmitting, children: _jsxs("span", { className: "relative z-20 flex items-center justify-center gap-2 drop-shadow-sm", children: [_jsx(Sparkles, { size: 16, color: "currentColor", strokeWidth: 2, className: "animate-pulse" }), isSubmitting ? "Signing up..." : "Sign Up"] }) }), _jsxs("div", { className: "text-center text-sm", children: [_jsx("span", { className: "text-muted-foreground", children: "Already have an account?" }), " ", _jsx(Button, { variant: "link", className: "p-0 h-auto", onClick: (e) => { e.preventDefault(); embedded && onSwitchMode ? onSwitchMode() : navigate('/signin'); }, children: "Sign In" })] })] }), _jsxs("div", { className: "mt-4 text-center text-xs text-muted-foreground", children: ["By registering you agree to our", " ", _jsx("a", { href: "/terms", className: "underline underline-offset-4 hover:text-foreground", children: "Terms of Service" }), ",", " ", _jsx("a", { href: "/eula", className: "underline underline-offset-4 hover:text-foreground", children: "EULA" }), ",", " ", _jsx("a", { href: "/privacy", className: "underline underline-offset-4 hover:text-foreground", children: "Privacy Policy" })] })] }));
147
+ } }), _jsx("p", { className: "text-xs text-muted-foreground", children: "Minimum 6 characters" })] }), _jsx("div", { ref: turnstileRef }), _jsx(Button, { type: "submit", variant: "gradient", size: "cta", className: "w-full", disabled: isSubmitting, children: _jsxs("span", { className: "relative z-20 flex items-center justify-center gap-2 drop-shadow-sm", children: [_jsx(Sparkles, { size: 16, color: "currentColor", strokeWidth: 2, className: "animate-pulse" }), isSubmitting ? "Signing up..." : "Sign Up"] }) }), _jsxs("div", { className: "text-center text-sm", children: [_jsx("span", { className: "text-muted-foreground", children: "Already have an account?" }), " ", _jsx(Button, { variant: "link", className: "p-0 h-auto", onClick: (e) => { e.preventDefault(); embedded && onSwitchMode ? onSwitchMode() : navigate('/signin'); }, children: "Sign In" })] })] }), _jsxs("div", { className: "mt-4 text-center text-xs text-muted-foreground", children: ["By registering you agree to our", " ", _jsx("a", { href: "/terms", className: "underline underline-offset-4 hover:text-foreground", children: "Terms of Service" }), ",", " ", _jsx("a", { href: "/eula", className: "underline underline-offset-4 hover:text-foreground", children: "EULA" }), ",", " ", _jsx("a", { href: "/privacy", className: "underline underline-offset-4 hover:text-foreground", children: "Privacy Policy" })] })] }));
88
148
  if (embedded) {
89
149
  return formContent;
90
150
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stevederico/skateboard-ui",
3
3
  "private": false,
4
- "version": "5.5.0",
4
+ "version": "5.7.0",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {