@jcsoftdev/ui 0.4.0 → 0.5.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 +97 -0
- package/README.md +1 -1
- package/dist/atoms/button/button.d.ts +8 -1
- package/dist/atoms/button/button.js +10 -3
- package/dist/atoms/divider/divider.d.ts +15 -0
- package/dist/atoms/divider/divider.js +27 -0
- package/dist/atoms/divider/index.d.ts +1 -0
- package/dist/atoms/divider/index.js +1 -0
- package/dist/atoms/icon-button/icon-button.d.ts +1 -1
- package/dist/atoms/index.d.ts +1 -0
- package/dist/atoms/index.js +1 -0
- package/dist/auth/auth-illustration/auth-illustration.d.ts +35 -0
- package/dist/auth/auth-illustration/auth-illustration.js +72 -0
- package/dist/auth/auth-illustration/index.d.ts +3 -0
- package/dist/auth/auth-illustration/index.js +11 -0
- package/dist/auth/auth-illustration/look.d.ts +30 -0
- package/dist/auth/auth-illustration/look.js +0 -0
- package/dist/auth/auth-illustration/model.d.ts +133 -0
- package/dist/auth/auth-illustration/model.js +202 -0
- package/dist/auth/auth-illustration/use-art-pointer.d.ts +9 -0
- package/dist/auth/auth-illustration/use-art-pointer.js +69 -0
- package/dist/auth/auth-layout/auth-layout.d.ts +80 -0
- package/dist/auth/auth-layout/auth-layout.js +190 -0
- package/dist/auth/auth-layout/index.d.ts +1 -0
- package/dist/auth/auth-layout/index.js +1 -0
- package/dist/auth/character/character.d.ts +12 -0
- package/dist/auth/character/character.js +333 -0
- package/dist/auth/character/index.d.ts +1 -0
- package/dist/auth/character/index.js +1 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.js +4 -0
- package/dist/auth/internal/auth-context.d.ts +17 -0
- package/dist/auth/internal/auth-context.js +10 -0
- package/dist/auth/internal/auth-styles.d.ts +1 -0
- package/dist/auth/internal/auth-styles.js +29 -0
- package/dist/auth/internal/portal-glyphs.d.ts +6 -0
- package/dist/auth/internal/portal-glyphs.js +39 -0
- package/dist/auth/login-form/context.d.ts +51 -0
- package/dist/auth/login-form/context.js +12 -0
- package/dist/auth/login-form/index.d.ts +2 -0
- package/dist/auth/login-form/index.js +23 -0
- package/dist/auth/login-form/login-form.d.ts +66 -0
- package/dist/auth/login-form/login-form.js +233 -0
- package/dist/auth/login-form/parts.d.ts +71 -0
- package/dist/auth/login-form/parts.js +371 -0
- package/dist/auth/looks/auth-illustration-any.d.ts +16 -0
- package/dist/auth/looks/auth-illustration-any.js +24 -0
- package/dist/auth/looks/index.d.ts +1 -0
- package/dist/auth/looks/index.js +1 -0
- package/dist/auth/mosaic/index.d.ts +1 -0
- package/dist/auth/mosaic/index.js +1 -0
- package/dist/auth/mosaic/mosaic.d.ts +11 -0
- package/dist/auth/mosaic/mosaic.js +195 -0
- package/dist/auth/slabs/index.d.ts +1 -0
- package/dist/auth/slabs/index.js +1 -0
- package/dist/auth/slabs/slabs.d.ts +13 -0
- package/dist/auth/slabs/slabs.js +136 -0
- package/dist/auth/stack/index.d.ts +1 -0
- package/dist/auth/stack/index.js +1 -0
- package/dist/auth/stack/stack.d.ts +6 -0
- package/dist/auth/stack/stack.js +222 -0
- package/dist/auth/statement/index.d.ts +1 -0
- package/dist/auth/statement/index.js +1 -0
- package/dist/auth/statement/statement.d.ts +13 -0
- package/dist/auth/statement/statement.js +99 -0
- package/dist/forms/index.d.ts +1 -0
- package/dist/forms/index.js +1 -0
- package/dist/forms/input/input.js +2 -1
- package/dist/forms/password-input/index.d.ts +1 -0
- package/dist/forms/password-input/index.js +1 -0
- package/dist/forms/password-input/password-input.d.ts +16 -0
- package/dist/forms/password-input/password-input.js +45 -0
- package/dist/i18n/strings.d.ts +64 -0
- package/dist/i18n/strings.js +34 -2
- package/dist/icons/eye.d.ts +2 -0
- package/dist/icons/eye.js +11 -0
- package/dist/icons/graduation-cap.d.ts +2 -0
- package/dist/icons/graduation-cap.js +12 -0
- package/dist/icons/house.d.ts +2 -0
- package/dist/icons/house.js +11 -0
- package/dist/icons/index.d.ts +4 -0
- package/dist/icons/index.js +8 -0
- package/dist/icons/mail.d.ts +2 -0
- package/dist/icons/mail.js +11 -0
- package/icons/svg/eye.svg +4 -0
- package/icons/svg/graduation-cap.svg +5 -0
- package/icons/svg/house.svg +4 -0
- package/icons/svg/mail.svg +4 -0
- package/package.json +2 -2
- package/src/atoms/button/button.tsx +25 -3
- package/src/atoms/divider/divider.tsx +40 -0
- package/src/atoms/divider/index.ts +1 -0
- package/src/atoms/icon-button/icon-button.tsx +1 -1
- package/src/atoms/index.ts +1 -0
- package/src/auth/auth-illustration/auth-illustration.tsx +100 -0
- package/src/auth/auth-illustration/index.ts +8 -0
- package/src/auth/auth-illustration/look.ts +32 -0
- package/src/auth/auth-illustration/model.ts +330 -0
- package/src/auth/auth-illustration/use-art-pointer.ts +78 -0
- package/src/auth/auth-layout/auth-layout.tsx +282 -0
- package/src/auth/auth-layout/index.ts +1 -0
- package/src/auth/character/character.tsx +346 -0
- package/src/auth/character/index.ts +1 -0
- package/src/auth/index.ts +4 -0
- package/src/auth/internal/auth-context.ts +26 -0
- package/src/auth/internal/auth-styles.tsx +39 -0
- package/src/auth/internal/portal-glyphs.tsx +32 -0
- package/src/auth/login-form/context.ts +78 -0
- package/src/auth/login-form/index.ts +21 -0
- package/src/auth/login-form/login-form.tsx +330 -0
- package/src/auth/login-form/parts.tsx +457 -0
- package/src/auth/looks/auth-illustration-any.tsx +38 -0
- package/src/auth/looks/index.ts +1 -0
- package/src/auth/mosaic/index.ts +1 -0
- package/src/auth/mosaic/mosaic.tsx +255 -0
- package/src/auth/slabs/index.ts +1 -0
- package/src/auth/slabs/slabs.tsx +181 -0
- package/src/auth/stack/index.ts +1 -0
- package/src/auth/stack/stack.tsx +267 -0
- package/src/auth/statement/index.ts +1 -0
- package/src/auth/statement/statement.tsx +122 -0
- package/src/forms/index.ts +1 -0
- package/src/forms/input/input.tsx +2 -0
- package/src/forms/password-input/index.ts +1 -0
- package/src/forms/password-input/password-input.tsx +57 -0
- package/src/i18n/strings.ts +64 -0
- package/src/icons/eye.tsx +12 -0
- package/src/icons/graduation-cap.tsx +13 -0
- package/src/icons/house.tsx +12 -0
- package/src/icons/index.ts +4 -0
- package/src/icons/mail.tsx +12 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
const AUTH_STATES = [
|
|
2
|
+
"idle",
|
|
3
|
+
"typing",
|
|
4
|
+
"password",
|
|
5
|
+
"error",
|
|
6
|
+
"success"
|
|
7
|
+
];
|
|
8
|
+
const clamp01 = (value) => Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : 0;
|
|
9
|
+
const IDENTIFIER_SHARE = 0.5;
|
|
10
|
+
const SPREAD = { idle: 0.85, error: 1.35, success: 0 };
|
|
11
|
+
const TYPING = { start: 0.65, end: 0.35 };
|
|
12
|
+
const PASSWORD = { start: 0.22, end: 0.05 };
|
|
13
|
+
const lerp = (from, to, t) => from + (to - from) * clamp01(t);
|
|
14
|
+
function slabSpread(state, progress) {
|
|
15
|
+
const p = clamp01(progress);
|
|
16
|
+
switch (state) {
|
|
17
|
+
case "typing":
|
|
18
|
+
return lerp(TYPING.start, TYPING.end, p / IDENTIFIER_SHARE);
|
|
19
|
+
case "password":
|
|
20
|
+
return lerp(PASSWORD.start, PASSWORD.end, (p - IDENTIFIER_SHARE) / (1 - IDENTIFIER_SHARE));
|
|
21
|
+
default:
|
|
22
|
+
return SPREAD[state];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const SLAB_COUNT = 3;
|
|
26
|
+
const SLAB_BASE = { x: 277, y: 149 };
|
|
27
|
+
const SLAB_ASSEMBLED = [
|
|
28
|
+
{ x: 0, y: 0 },
|
|
29
|
+
{ x: 86.6, y: 50 },
|
|
30
|
+
{ x: 0, y: 100 }
|
|
31
|
+
];
|
|
32
|
+
const SLAB_TRAVEL = [
|
|
33
|
+
{ x: -120, y: 14, lift: 34 },
|
|
34
|
+
{ x: 104, y: -44, lift: 62 },
|
|
35
|
+
{ x: 14, y: 78, lift: 14 }
|
|
36
|
+
];
|
|
37
|
+
const ACTIVE_LIFT = 20;
|
|
38
|
+
const round = (value) => Math.round(value * 100) / 100;
|
|
39
|
+
function slabPlacement(index, spread, activeIndex) {
|
|
40
|
+
const assembled = SLAB_ASSEMBLED[index];
|
|
41
|
+
const travel = SLAB_TRAVEL[index];
|
|
42
|
+
if (!assembled || !travel) return { x: SLAB_BASE.x, y: SLAB_BASE.y, lift: 0 };
|
|
43
|
+
return {
|
|
44
|
+
x: round(SLAB_BASE.x + assembled.x + travel.x * spread),
|
|
45
|
+
y: round(SLAB_BASE.y + assembled.y + travel.y * spread),
|
|
46
|
+
lift: round(travel.lift * spread + (index === activeIndex ? ACTIVE_LIFT : 0))
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function sparkVectors(count = 12) {
|
|
50
|
+
return Array.from({ length: count }, (_, n) => {
|
|
51
|
+
const angle = n / count * Math.PI * 2;
|
|
52
|
+
const distance = 90 + n * 37 % 90;
|
|
53
|
+
return { dx: round(Math.cos(angle) * distance), dy: round(Math.sin(angle) * distance * 0.7) };
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const ERROR_HOLD_MS = 1100;
|
|
57
|
+
function shownState(state, errorHeld) {
|
|
58
|
+
return state === "error" && errorHeld ? "password" : state;
|
|
59
|
+
}
|
|
60
|
+
const KEYSTROKES_PER_FIELD = 10;
|
|
61
|
+
function formProgress(identifierLength, passwordFilled) {
|
|
62
|
+
const identifier = Math.min(1, Math.max(0, identifierLength) / KEYSTROKES_PER_FIELD);
|
|
63
|
+
return (identifier + (passwordFilled ? 1 : 0)) / 2;
|
|
64
|
+
}
|
|
65
|
+
function keystroke(progress, pieces = 3) {
|
|
66
|
+
const count = Math.round(clamp01(progress) * KEYSTROKES_PER_FIELD * 2);
|
|
67
|
+
return { count, target: count % pieces, phase: Math.floor(count / pieces) % 2 };
|
|
68
|
+
}
|
|
69
|
+
function pointerOffset(point, box) {
|
|
70
|
+
const axis = (value, start, size) => size > 0 ? Math.round(Math.max(-1, Math.min(1, (value - start - size / 2) / (size / 2))) * 1e3) / 1e3 : 0;
|
|
71
|
+
return { x: axis(point.x, box.left, box.width), y: axis(point.y, box.top, box.height) };
|
|
72
|
+
}
|
|
73
|
+
const ISO_X = 0.866;
|
|
74
|
+
const ISO_Y = 0.5;
|
|
75
|
+
function isoPoint(u, v, z = 0) {
|
|
76
|
+
return { x: round(ISO_X * (u - v)), y: round(ISO_Y * (u + v) - z) };
|
|
77
|
+
}
|
|
78
|
+
const pathOf = (points) => `M${points.map((p) => `${p.x} ${p.y}`).join("L")}Z`;
|
|
79
|
+
function isoBox(w, d, h) {
|
|
80
|
+
const [u0, u1, v0, v1] = [-w / 2, w / 2, -d / 2, d / 2];
|
|
81
|
+
return {
|
|
82
|
+
top: pathOf([
|
|
83
|
+
isoPoint(u0, v0, h),
|
|
84
|
+
isoPoint(u1, v0, h),
|
|
85
|
+
isoPoint(u1, v1, h),
|
|
86
|
+
isoPoint(u0, v1, h)
|
|
87
|
+
]),
|
|
88
|
+
left: pathOf([
|
|
89
|
+
isoPoint(u0, v1, h),
|
|
90
|
+
isoPoint(u1, v1, h),
|
|
91
|
+
isoPoint(u1, v1, 0),
|
|
92
|
+
isoPoint(u0, v1, 0)
|
|
93
|
+
]),
|
|
94
|
+
right: pathOf([
|
|
95
|
+
isoPoint(u1, v0, h),
|
|
96
|
+
isoPoint(u1, v1, h),
|
|
97
|
+
isoPoint(u1, v1, 0),
|
|
98
|
+
isoPoint(u1, v0, 0)
|
|
99
|
+
])
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const STACK_BOOKS = [
|
|
103
|
+
{ w: 178, d: 128, h: 30, du: 0, dv: 0, tone: 0 },
|
|
104
|
+
{ w: 152, d: 112, h: 22, du: 8, dv: -6, tone: 1 },
|
|
105
|
+
{ w: 164, d: 104, h: 26, du: -10, dv: 6, tone: 2 },
|
|
106
|
+
{ w: 140, d: 112, h: 20, du: 6, dv: 4, tone: 3 },
|
|
107
|
+
{ w: 150, d: 98, h: 24, du: -6, dv: -8, tone: 1 },
|
|
108
|
+
{ w: 128, d: 100, h: 20, du: 4, dv: 6, tone: 0 }
|
|
109
|
+
];
|
|
110
|
+
const STACK_COUNTS = [4, 5, 6];
|
|
111
|
+
function stackPlaced(state, progress, count) {
|
|
112
|
+
if (state === "success") return count;
|
|
113
|
+
return Math.min(count, 1 + Math.floor(clamp01(progress) * (count - 1) + 1e-9));
|
|
114
|
+
}
|
|
115
|
+
function stackSlots(books = STACK_BOOKS) {
|
|
116
|
+
let z = 0;
|
|
117
|
+
return books.map((book) => {
|
|
118
|
+
const at = isoPoint(book.du, book.dv, z);
|
|
119
|
+
z += book.h;
|
|
120
|
+
return at;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function stackTop(count, books = STACK_BOOKS) {
|
|
124
|
+
const shown = books.slice(0, count);
|
|
125
|
+
const last = shown[shown.length - 1];
|
|
126
|
+
if (!last) return { x: 0, y: 0 };
|
|
127
|
+
const z = shown.reduce((sum, book) => sum + book.h, 0);
|
|
128
|
+
return isoPoint(last.du, last.dv, z);
|
|
129
|
+
}
|
|
130
|
+
const MOSAIC_SIZES = [4, 5, 6];
|
|
131
|
+
function mosaicFilled(state, progress, n) {
|
|
132
|
+
const diagonals = n * 2 - 1;
|
|
133
|
+
if (state === "success") return diagonals;
|
|
134
|
+
return Math.min(diagonals, Math.floor(clamp01(progress) * diagonals + 1e-9));
|
|
135
|
+
}
|
|
136
|
+
function mosaicTiles(n) {
|
|
137
|
+
const middle = (n - 1) / 2;
|
|
138
|
+
return Array.from({ length: n * n }, (_, k) => {
|
|
139
|
+
const row = Math.floor(k / n);
|
|
140
|
+
const col = k % n;
|
|
141
|
+
return {
|
|
142
|
+
row,
|
|
143
|
+
col,
|
|
144
|
+
diagonal: row + col,
|
|
145
|
+
ring: Math.round(Math.abs(row - middle) + Math.abs(col - middle))
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
const MOSAIC_GLYPH_TILES = {
|
|
150
|
+
4: [
|
|
151
|
+
[1, 0],
|
|
152
|
+
[0, 2],
|
|
153
|
+
[2, 3]
|
|
154
|
+
],
|
|
155
|
+
5: [
|
|
156
|
+
[1, 1],
|
|
157
|
+
[0, 3],
|
|
158
|
+
[3, 3]
|
|
159
|
+
],
|
|
160
|
+
6: [
|
|
161
|
+
[1, 1],
|
|
162
|
+
[1, 4],
|
|
163
|
+
[4, 3]
|
|
164
|
+
]
|
|
165
|
+
};
|
|
166
|
+
function mosaicGlint(count, n) {
|
|
167
|
+
return count > 0 ? count * 7 % (n * n) : -1;
|
|
168
|
+
}
|
|
169
|
+
const BOARD_LIGHTS = 5;
|
|
170
|
+
function boardLit(state, progress) {
|
|
171
|
+
if (state === "success") return BOARD_LIGHTS;
|
|
172
|
+
return Math.min(BOARD_LIGHTS, Math.floor(clamp01(progress) * BOARD_LIGHTS + 1e-9));
|
|
173
|
+
}
|
|
174
|
+
export {
|
|
175
|
+
AUTH_STATES,
|
|
176
|
+
BOARD_LIGHTS,
|
|
177
|
+
ERROR_HOLD_MS,
|
|
178
|
+
IDENTIFIER_SHARE,
|
|
179
|
+
KEYSTROKES_PER_FIELD,
|
|
180
|
+
MOSAIC_GLYPH_TILES,
|
|
181
|
+
MOSAIC_SIZES,
|
|
182
|
+
SLAB_COUNT,
|
|
183
|
+
STACK_BOOKS,
|
|
184
|
+
STACK_COUNTS,
|
|
185
|
+
boardLit,
|
|
186
|
+
clamp01,
|
|
187
|
+
formProgress,
|
|
188
|
+
isoBox,
|
|
189
|
+
isoPoint,
|
|
190
|
+
keystroke,
|
|
191
|
+
mosaicFilled,
|
|
192
|
+
mosaicGlint,
|
|
193
|
+
mosaicTiles,
|
|
194
|
+
pointerOffset,
|
|
195
|
+
shownState,
|
|
196
|
+
slabPlacement,
|
|
197
|
+
slabSpread,
|
|
198
|
+
sparkVectors,
|
|
199
|
+
stackPlaced,
|
|
200
|
+
stackSlots,
|
|
201
|
+
stackTop
|
|
202
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Writes where the pointer is, relative to the art, as `--px` and `--py` (-1 to 1) on the art
|
|
4
|
+
* element. It listens on the surrounding `AuthLayout` so the art also reacts while the pointer is
|
|
5
|
+
* over the form. One write per animation frame at most; nothing runs for touch, coarse pointers or
|
|
6
|
+
* reduced motion, and it follows those settings when they change while the page is open (the art
|
|
7
|
+
* recentres when the parallax switches off). The listeners go away with the component.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useArtPointer(ref: RefObject<HTMLElement | null>): void;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { pointerOffset } from "./model.js";
|
|
4
|
+
const FINE_POINTER = "(hover: hover) and (pointer: fine)";
|
|
5
|
+
const REDUCED_MOTION = "(prefers-reduced-motion: reduce)";
|
|
6
|
+
function useArtPointer(ref) {
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const art = ref.current;
|
|
9
|
+
if (!art || typeof window.matchMedia !== "function") return;
|
|
10
|
+
const fine = window.matchMedia(FINE_POINTER);
|
|
11
|
+
const reduced = window.matchMedia(REDUCED_MOTION);
|
|
12
|
+
const area = art.closest("[data-layout]") ?? art;
|
|
13
|
+
let frame = 0;
|
|
14
|
+
let point = null;
|
|
15
|
+
let listening = false;
|
|
16
|
+
const write = () => {
|
|
17
|
+
frame = 0;
|
|
18
|
+
if (!point) {
|
|
19
|
+
art.style.setProperty("--px", "0");
|
|
20
|
+
art.style.setProperty("--py", "0");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const offset = pointerOffset(point, art.getBoundingClientRect());
|
|
24
|
+
art.style.setProperty("--px", String(offset.x));
|
|
25
|
+
art.style.setProperty("--py", String(offset.y));
|
|
26
|
+
};
|
|
27
|
+
const schedule = () => {
|
|
28
|
+
if (!frame) frame = requestAnimationFrame(write);
|
|
29
|
+
};
|
|
30
|
+
const move = (event) => {
|
|
31
|
+
if (event.pointerType !== "mouse" && event.pointerType !== "pen") return;
|
|
32
|
+
point = { x: event.clientX, y: event.clientY };
|
|
33
|
+
schedule();
|
|
34
|
+
};
|
|
35
|
+
const leave = () => {
|
|
36
|
+
point = null;
|
|
37
|
+
schedule();
|
|
38
|
+
};
|
|
39
|
+
const stop = () => {
|
|
40
|
+
if (!listening) return;
|
|
41
|
+
listening = false;
|
|
42
|
+
area.removeEventListener("pointermove", move);
|
|
43
|
+
area.removeEventListener("pointerleave", leave);
|
|
44
|
+
if (frame) cancelAnimationFrame(frame);
|
|
45
|
+
frame = 0;
|
|
46
|
+
point = null;
|
|
47
|
+
art.style.removeProperty("--px");
|
|
48
|
+
art.style.removeProperty("--py");
|
|
49
|
+
};
|
|
50
|
+
const sync = () => {
|
|
51
|
+
if (!fine.matches || reduced.matches) return stop();
|
|
52
|
+
if (listening) return;
|
|
53
|
+
listening = true;
|
|
54
|
+
area.addEventListener("pointermove", move, { passive: true });
|
|
55
|
+
area.addEventListener("pointerleave", leave, { passive: true });
|
|
56
|
+
};
|
|
57
|
+
sync();
|
|
58
|
+
fine.addEventListener("change", sync);
|
|
59
|
+
reduced.addEventListener("change", sync);
|
|
60
|
+
return () => {
|
|
61
|
+
fine.removeEventListener("change", sync);
|
|
62
|
+
reduced.removeEventListener("change", sync);
|
|
63
|
+
stop();
|
|
64
|
+
};
|
|
65
|
+
}, [ref]);
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
useArtPointer
|
|
69
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef } from "react";
|
|
2
|
+
import type { ClassNames } from "../../utils/class-names.js";
|
|
3
|
+
import { type AuthIllustrationProps } from "../auth-illustration/auth-illustration.js";
|
|
4
|
+
import type { AuthLook } from "../auth-illustration/look.js";
|
|
5
|
+
import type { AuthState } from "../auth-illustration/model.js";
|
|
6
|
+
import { type AuthContextValue, type AuthPanel } from "../internal/auth-context.js";
|
|
7
|
+
export type AuthLayoutKind = "split" | "split-reverse" | "centered";
|
|
8
|
+
export type AuthLayoutPart = "root" | "content" | "brand" | "art" | "panel" | "footer";
|
|
9
|
+
/** State shared by the illustration and the form of an `AuthLayout`. Throws outside one. */
|
|
10
|
+
export declare function useAuthLayout(): AuthContextValue;
|
|
11
|
+
export interface AuthLayoutProps extends ComponentPropsWithoutRef<"div"> {
|
|
12
|
+
/**
|
|
13
|
+
* `split` puts the art beside the panel once the layout is 768px wide, `split-reverse` swaps the
|
|
14
|
+
* sides, `centered` centers the panel over a faded illustration. Narrower than that the art
|
|
15
|
+
* stacks above the panel, and under 448px it is dropped. All of it follows the layout's own
|
|
16
|
+
* width, not the viewport's.
|
|
17
|
+
*/
|
|
18
|
+
layout?: AuthLayoutKind;
|
|
19
|
+
/**
|
|
20
|
+
* `paper` is the card over a tinted page. `solid` fills one side with a solid color for the art
|
|
21
|
+
* and leaves the form open on the other (no card). It applies to `split` and `split-reverse`;
|
|
22
|
+
* `centered` ignores it. A solid root sets `--auth-art-bg` and `--auth-art-ink` for the art, the
|
|
23
|
+
* brand and the illustration, which carries `data-panel="solid"`.
|
|
24
|
+
*/
|
|
25
|
+
panel?: AuthPanel;
|
|
26
|
+
/** What the screen is doing, for the illustration. Controlled; `LoginForm` keeps it current when left alone. */
|
|
27
|
+
state?: AuthState;
|
|
28
|
+
defaultState?: AuthState;
|
|
29
|
+
onStateChange?: (state: AuthState) => void;
|
|
30
|
+
/** Fill of the whole form, 0 to 1. */
|
|
31
|
+
progress?: number;
|
|
32
|
+
defaultProgress?: number;
|
|
33
|
+
onProgressChange?: (progress: number) => void;
|
|
34
|
+
/** Index of the portal in use (0 to 2). */
|
|
35
|
+
activeIndex?: number;
|
|
36
|
+
defaultActiveIndex?: number;
|
|
37
|
+
onActiveIndexChange?: (index: number) => void;
|
|
38
|
+
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the root and is merged last. */
|
|
39
|
+
classNames?: ClassNames<AuthLayoutPart>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Screen for signing in: a brand, an illustration that reacts to the form and the form itself,
|
|
43
|
+
* laid out by the width of the layout. It owns the sign-in state (controlled or not) and shares it
|
|
44
|
+
* with `AuthIllustration` and `LoginForm`, so wiring them is just placing them inside.
|
|
45
|
+
*
|
|
46
|
+
* Parts: `AuthLayout.Brand`, `AuthLayout.Art`, `AuthLayout.Panel` and `AuthLayout.Footer`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function AuthLayout({ layout, panel: panelProp, state: stateProp, defaultState, onStateChange, progress: progressProp, defaultProgress, onProgressChange, activeIndex: activeIndexProp, defaultActiveIndex, onActiveIndexChange, className, classNames, children, ...props }: AuthLayoutProps): import("react").JSX.Element;
|
|
49
|
+
export declare namespace AuthLayout {
|
|
50
|
+
var Brand: typeof AuthLayoutBrand;
|
|
51
|
+
var Art: typeof AuthLayoutArt;
|
|
52
|
+
var Panel: typeof AuthLayoutPanel;
|
|
53
|
+
var Footer: typeof AuthLayoutFooter;
|
|
54
|
+
}
|
|
55
|
+
export interface AuthLayoutBrandProps extends ComponentPropsWithoutRef<"div"> {
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Logo or wordmark pinned to the top corner on the art's side: left in `split` and `centered`,
|
|
59
|
+
* right in `split-reverse` once the art sits beside the panel, so it never lands on the card.
|
|
60
|
+
*/
|
|
61
|
+
export declare function AuthLayoutBrand({ className, ...props }: AuthLayoutBrandProps): import("react").JSX.Element;
|
|
62
|
+
export interface AuthLayoutArtProps extends ComponentPropsWithoutRef<"div">, Pick<AuthIllustrationProps, "headline" | "caption" | "action"> {
|
|
63
|
+
/** Look of the default illustration, used when there are no children (default `Slabs`). */
|
|
64
|
+
look?: AuthLook;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Holds the illustration (a default `AuthIllustration` when empty). It hides under 448px of layout
|
|
68
|
+
* width and, in `centered`, sits faded behind the panel. A drawn look is at most 12rem tall while
|
|
69
|
+
* it is stacked above the panel, so the form stays in reach, and 34rem beside it; set
|
|
70
|
+
* `--auth-art-max-h` on this part to change that.
|
|
71
|
+
*/
|
|
72
|
+
export declare function AuthLayoutArt({ look, headline, caption, action, className, children, ...props }: AuthLayoutArtProps): import("react").JSX.Element;
|
|
73
|
+
export interface AuthLayoutPanelProps extends ComponentPropsWithoutRef<"div"> {
|
|
74
|
+
}
|
|
75
|
+
/** The card that holds the form. */
|
|
76
|
+
export declare function AuthLayoutPanel({ className, ...props }: AuthLayoutPanelProps): import("react").JSX.Element;
|
|
77
|
+
export interface AuthLayoutFooterProps extends ComponentPropsWithoutRef<"div"> {
|
|
78
|
+
}
|
|
79
|
+
/** Line under the panel, across the full width (terms, support, a language switch). */
|
|
80
|
+
export declare function AuthLayoutFooter({ className, ...props }: AuthLayoutFooterProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useContext,
|
|
6
|
+
useMemo
|
|
7
|
+
} from "react";
|
|
8
|
+
import { cn } from "../../utils/cn.js";
|
|
9
|
+
import { useControllableState } from "../../utils/use-controllable-state.js";
|
|
10
|
+
import {
|
|
11
|
+
AuthIllustration
|
|
12
|
+
} from "../auth-illustration/auth-illustration.js";
|
|
13
|
+
import { AuthContext } from "../internal/auth-context.js";
|
|
14
|
+
import { AuthStyles } from "../internal/auth-styles.js";
|
|
15
|
+
const AuthLayoutPartsContext = createContext(null);
|
|
16
|
+
function useAuthLayoutParts(part) {
|
|
17
|
+
const parts = useContext(AuthLayoutPartsContext);
|
|
18
|
+
if (!parts) throw new Error(`AuthLayout.${part} must be rendered inside an AuthLayout`);
|
|
19
|
+
return parts;
|
|
20
|
+
}
|
|
21
|
+
function useAuthLayout() {
|
|
22
|
+
const auth = useContext(AuthContext);
|
|
23
|
+
if (!auth) throw new Error("useAuthLayout must be called inside an AuthLayout");
|
|
24
|
+
return auth;
|
|
25
|
+
}
|
|
26
|
+
function AuthLayout({
|
|
27
|
+
layout = "split",
|
|
28
|
+
panel: panelProp = "paper",
|
|
29
|
+
state: stateProp,
|
|
30
|
+
defaultState = "idle",
|
|
31
|
+
onStateChange,
|
|
32
|
+
progress: progressProp,
|
|
33
|
+
defaultProgress = 0,
|
|
34
|
+
onProgressChange,
|
|
35
|
+
activeIndex: activeIndexProp,
|
|
36
|
+
defaultActiveIndex = 0,
|
|
37
|
+
onActiveIndexChange,
|
|
38
|
+
className,
|
|
39
|
+
classNames,
|
|
40
|
+
children,
|
|
41
|
+
...props
|
|
42
|
+
}) {
|
|
43
|
+
const [state, setState] = useControllableState({
|
|
44
|
+
prop: stateProp,
|
|
45
|
+
defaultProp: defaultState,
|
|
46
|
+
onChange: onStateChange
|
|
47
|
+
});
|
|
48
|
+
const [progress, setProgress] = useControllableState({
|
|
49
|
+
prop: progressProp,
|
|
50
|
+
defaultProp: defaultProgress,
|
|
51
|
+
onChange: onProgressChange
|
|
52
|
+
});
|
|
53
|
+
const [activeIndex, setActiveIndex] = useControllableState({
|
|
54
|
+
prop: activeIndexProp,
|
|
55
|
+
defaultProp: defaultActiveIndex,
|
|
56
|
+
onChange: onActiveIndexChange
|
|
57
|
+
});
|
|
58
|
+
const panel = layout === "centered" ? "paper" : panelProp;
|
|
59
|
+
const auth = useMemo(
|
|
60
|
+
() => ({ panel, state, setState, progress, setProgress, activeIndex, setActiveIndex }),
|
|
61
|
+
[panel, state, setState, progress, setProgress, activeIndex, setActiveIndex]
|
|
62
|
+
);
|
|
63
|
+
const parts = useMemo(() => ({ layout, panel, classNames }), [layout, panel, classNames]);
|
|
64
|
+
return /* @__PURE__ */ jsx(AuthContext, { value: auth, children: /* @__PURE__ */ jsxs(AuthLayoutPartsContext, { value: parts, children: [
|
|
65
|
+
/* @__PURE__ */ jsx(AuthStyles, {}),
|
|
66
|
+
/* @__PURE__ */ jsx(
|
|
67
|
+
"div",
|
|
68
|
+
{
|
|
69
|
+
...props,
|
|
70
|
+
style: panel === "solid" ? { ...SOLID_ART_VARS, ...props.style } : props.style,
|
|
71
|
+
"data-layout": layout,
|
|
72
|
+
"data-panel": panel,
|
|
73
|
+
"data-state": state,
|
|
74
|
+
className: cn(
|
|
75
|
+
"@container/auth relative isolate min-h-164 min-w-0 overflow-hidden",
|
|
76
|
+
panel === "solid" ? "bg-surface" : "rounded-card border-divider bg-[color-mix(in_srgb,var(--accent)_14%,var(--bg))]",
|
|
77
|
+
classNames?.root,
|
|
78
|
+
className
|
|
79
|
+
),
|
|
80
|
+
children: /* @__PURE__ */ jsx(
|
|
81
|
+
"div",
|
|
82
|
+
{
|
|
83
|
+
className: cn(
|
|
84
|
+
"grid min-h-[inherit] grid-cols-1",
|
|
85
|
+
panel === "solid" ? "content-start items-stretch @3xl/auth:grid-cols-2 @3xl/auth:content-stretch" : [
|
|
86
|
+
"content-center items-center gap-2 px-4 pt-14 pb-6 @max-md/auth:content-start @max-md/auth:bg-surface @lg/auth:px-8 @3xl/auth:px-14 @3xl/auth:pt-7 @3xl/auth:pb-8",
|
|
87
|
+
layout !== "centered" && "@3xl/auth:grid-cols-[minmax(0,1.1fr)_minmax(0,.9fr)] @3xl/auth:gap-12"
|
|
88
|
+
],
|
|
89
|
+
classNames?.content
|
|
90
|
+
),
|
|
91
|
+
children
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
] }) });
|
|
97
|
+
}
|
|
98
|
+
const SOLID_ART_VARS = {
|
|
99
|
+
"--auth-art-bg": "var(--accent)",
|
|
100
|
+
"--auth-art-ink": "var(--on-accent)"
|
|
101
|
+
};
|
|
102
|
+
function AuthLayoutBrand({ className, ...props }) {
|
|
103
|
+
const { layout, panel, classNames } = useAuthLayoutParts("Brand");
|
|
104
|
+
const onSolid = panel === "solid";
|
|
105
|
+
return /* @__PURE__ */ jsx(
|
|
106
|
+
"div",
|
|
107
|
+
{
|
|
108
|
+
...props,
|
|
109
|
+
className: cn(
|
|
110
|
+
"absolute top-5.5 left-4 z-[3] font-bold text-lg tracking-tight @lg/auth:left-8 @3xl/auth:left-14",
|
|
111
|
+
layout === "split-reverse" && "@3xl/auth:right-14 @3xl/auth:left-auto",
|
|
112
|
+
!onSolid && "text-ink",
|
|
113
|
+
onSolid && "text-[var(--auth-art-ink)] @max-md/auth:text-ink",
|
|
114
|
+
classNames?.brand,
|
|
115
|
+
className
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
function AuthLayoutArt({
|
|
121
|
+
look,
|
|
122
|
+
headline,
|
|
123
|
+
caption,
|
|
124
|
+
action,
|
|
125
|
+
className,
|
|
126
|
+
children,
|
|
127
|
+
...props
|
|
128
|
+
}) {
|
|
129
|
+
const { layout, panel, classNames } = useAuthLayoutParts("Art");
|
|
130
|
+
const solid = panel === "solid";
|
|
131
|
+
const art = children ?? /* @__PURE__ */ jsx(AuthIllustration, { look, headline, caption, action });
|
|
132
|
+
return /* @__PURE__ */ jsx(
|
|
133
|
+
"div",
|
|
134
|
+
{
|
|
135
|
+
...props,
|
|
136
|
+
className: cn(
|
|
137
|
+
"grid min-w-0 place-items-center [--auth-art-max-h:12rem] @max-md/auth:hidden @3xl/auth:[--auth-art-max-h:34rem]",
|
|
138
|
+
layout === "centered" && "pointer-events-none absolute inset-0 -z-10 px-8 opacity-35",
|
|
139
|
+
layout !== "centered" && !solid && "relative mx-auto w-full max-w-90 @3xl/auth:max-w-160",
|
|
140
|
+
layout !== "centered" && solid && "bg-[var(--auth-art-bg)] px-4 pt-16 pb-6 text-[var(--auth-art-ink)] @lg/auth:px-8 @3xl/auth:px-14 @3xl/auth:py-14",
|
|
141
|
+
layout === "split-reverse" && "@3xl/auth:order-2",
|
|
142
|
+
classNames?.art,
|
|
143
|
+
className
|
|
144
|
+
),
|
|
145
|
+
children: solid ? /* @__PURE__ */ jsx("div", { className: "w-full max-w-90 @3xl/auth:max-w-160", children: art }) : art
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
function AuthLayoutPanel({ className, ...props }) {
|
|
150
|
+
const { layout, panel, classNames } = useAuthLayoutParts("Panel");
|
|
151
|
+
return /* @__PURE__ */ jsx(
|
|
152
|
+
"div",
|
|
153
|
+
{
|
|
154
|
+
...props,
|
|
155
|
+
className: cn(
|
|
156
|
+
panel === "solid" ? "relative z-[2] grid min-w-0 content-center px-4 py-10 text-ink @max-md/auth:pt-20 @lg/auth:px-8 @3xl/auth:px-14 @3xl/auth:py-14" : "ui-auth-rise relative z-[2] w-full max-w-110 min-w-0 justify-self-center overflow-hidden rounded-card border-[1.5px] border-ink bg-surface text-ink shadow-[0_3px_0_var(--ink),0_24px_50px_-12px_color-mix(in_srgb,black_20%,transparent)] @max-md/auth:overflow-visible @max-md/auth:rounded-none @max-md/auth:border-0 @max-md/auth:shadow-none",
|
|
157
|
+
layout === "split-reverse" && "@3xl/auth:order-1",
|
|
158
|
+
classNames?.panel,
|
|
159
|
+
className
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
function AuthLayoutFooter({ className, ...props }) {
|
|
165
|
+
const { panel, classNames } = useAuthLayoutParts("Footer");
|
|
166
|
+
return /* @__PURE__ */ jsx(
|
|
167
|
+
"div",
|
|
168
|
+
{
|
|
169
|
+
...props,
|
|
170
|
+
className: cn(
|
|
171
|
+
"relative z-[2] col-span-full text-center text-ink-3 text-meta",
|
|
172
|
+
panel === "solid" && "px-4 pb-6",
|
|
173
|
+
classNames?.footer,
|
|
174
|
+
className
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
AuthLayout.Brand = AuthLayoutBrand;
|
|
180
|
+
AuthLayout.Art = AuthLayoutArt;
|
|
181
|
+
AuthLayout.Panel = AuthLayoutPanel;
|
|
182
|
+
AuthLayout.Footer = AuthLayoutFooter;
|
|
183
|
+
export {
|
|
184
|
+
AuthLayout,
|
|
185
|
+
AuthLayoutArt,
|
|
186
|
+
AuthLayoutBrand,
|
|
187
|
+
AuthLayoutFooter,
|
|
188
|
+
AuthLayoutPanel,
|
|
189
|
+
useAuthLayout
|
|
190
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./auth-layout.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./auth-layout.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AuthVariantProps } from "../auth-illustration/look.js";
|
|
2
|
+
/**
|
|
3
|
+
* A student with a backpack riding a hover board over a pulsing shadow, for the art panel. They bob,
|
|
4
|
+
* blink and follow the pointer; while the form is typed into they look toward it and nod per
|
|
5
|
+
* keystroke, for the password they cover their eyes, on an error they shake their head and on
|
|
6
|
+
* success they hop with a boost. The deck lamps fill with progress and the chest badge carries the
|
|
7
|
+
* active portal's glyph.
|
|
8
|
+
*/
|
|
9
|
+
export declare function Character({ state, progress, activeIndex, uid }: AuthVariantProps): import("react").JSX.Element;
|
|
10
|
+
export declare namespace Character {
|
|
11
|
+
var variant: string;
|
|
12
|
+
}
|