@korzun/design 0.0.6 → 0.1.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/AGENTS.md +5 -1
- package/dist/component/tag/index.d.ts +1 -1
- package/dist/component/tag/index.d.ts.map +1 -1
- package/dist/component/tag/index.js.map +1 -1
- package/dist/component/tag/style.d.ts +1 -1
- package/dist/component/tag/style.d.ts.map +1 -1
- package/dist/control/index.d.ts +1 -1
- package/dist/control/index.d.ts.map +1 -1
- package/dist/control/index.js +1 -1
- package/dist/control/index.js.map +1 -1
- package/dist/control/popover/index.d.ts +24 -8
- package/dist/control/popover/index.d.ts.map +1 -1
- package/dist/control/popover/index.js +60 -15
- package/dist/control/popover/index.js.map +1 -1
- package/dist/control/popover/position.d.ts +47 -0
- package/dist/control/popover/position.d.ts.map +1 -0
- package/dist/control/popover/position.js +29 -0
- package/dist/control/popover/position.js.map +1 -0
- package/dist/theme/theme.d.ts +24 -0
- package/dist/theme/theme.d.ts.map +1 -1
- package/dist/theme/theme.js +36 -0
- package/dist/theme/theme.js.map +1 -1
- package/docs/component/metadata-list.md +1 -1
- package/docs/component/tag.md +26 -6
- package/docs/control/popover.md +41 -10
- package/docs/theme.md +4 -2
- package/docs/tokens.md +3 -3
- package/package.json +1 -1
- package/src/component/tag/index.tsx +1 -1
- package/src/control/index.ts +6 -1
- package/src/control/popover/index.tsx +77 -19
- package/src/control/popover/position.ts +66 -0
- package/src/theme/theme.ts +45 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Which side of the anchor the popover prefers. */
|
|
2
|
+
export type PopoverSide = 'bottom' | 'top';
|
|
3
|
+
/** Horizontal alignment of the popover against the anchor. */
|
|
4
|
+
export type PopoverAlign = 'start' | 'center' | 'end';
|
|
5
|
+
/** Viewport-relative rectangle, as from getBoundingClientRect. */
|
|
6
|
+
export type Rect = { top: number; bottom: number; left: number; right: number; width: number };
|
|
7
|
+
/**
|
|
8
|
+
* Resolved popover position; `side` is the side actually used after flipping.
|
|
9
|
+
* Exactly one of `top` / `bottom` is set: the bottom side is anchored by its
|
|
10
|
+
* top edge (CSS `top`), the top side by its bottom edge (CSS `bottom`, measured
|
|
11
|
+
* from the viewport's bottom), so content that grows or shrinks while open
|
|
12
|
+
* stays attached to the anchor.
|
|
13
|
+
*/
|
|
14
|
+
export type Placement = {
|
|
15
|
+
top: number | undefined;
|
|
16
|
+
bottom: number | undefined;
|
|
17
|
+
left: number;
|
|
18
|
+
width: number | undefined;
|
|
19
|
+
side: PopoverSide;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Pure placement: picks the side (flipping when the preferred side does not
|
|
24
|
+
* fit and the other has more room), aligns horizontally, and clamps to the
|
|
25
|
+
* viewport horizontally unless `matchWidth` (then it lines up with the anchor).
|
|
26
|
+
*/
|
|
27
|
+
export function computePosition({
|
|
28
|
+
anchor,
|
|
29
|
+
content,
|
|
30
|
+
viewport,
|
|
31
|
+
side,
|
|
32
|
+
align,
|
|
33
|
+
gap,
|
|
34
|
+
matchWidth,
|
|
35
|
+
}: {
|
|
36
|
+
anchor: Rect;
|
|
37
|
+
content: { width: number; height: number };
|
|
38
|
+
viewport: { width: number; height: number };
|
|
39
|
+
side: PopoverSide;
|
|
40
|
+
align: PopoverAlign;
|
|
41
|
+
gap: number;
|
|
42
|
+
matchWidth: boolean;
|
|
43
|
+
}): Placement {
|
|
44
|
+
const w = matchWidth ? anchor.width : content.width;
|
|
45
|
+
const h = content.height;
|
|
46
|
+
|
|
47
|
+
const roomBelow = viewport.height - anchor.bottom - gap;
|
|
48
|
+
const roomAbove = anchor.top - gap;
|
|
49
|
+
const room = (s: PopoverSide) => (s === 'bottom' ? roomBelow : roomAbove);
|
|
50
|
+
const other: PopoverSide = side === 'bottom' ? 'top' : 'bottom';
|
|
51
|
+
const used = room(side) >= h || room(other) <= room(side) ? side : other;
|
|
52
|
+
const top = used === 'bottom' ? anchor.bottom + gap : undefined;
|
|
53
|
+
const bottom = used === 'top' ? viewport.height - anchor.top + gap : undefined;
|
|
54
|
+
|
|
55
|
+
let left: number;
|
|
56
|
+
if (align === 'start') left = anchor.left;
|
|
57
|
+
else if (align === 'center') left = anchor.left + anchor.width / 2 - w / 2;
|
|
58
|
+
else left = anchor.right - w;
|
|
59
|
+
|
|
60
|
+
if (!matchWidth) {
|
|
61
|
+
left =
|
|
62
|
+
w > viewport.width - 2 * gap ? gap : Math.max(gap, Math.min(left, viewport.width - w - gap));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return { top, bottom, left, width: matchWidth ? anchor.width : undefined, side: used };
|
|
66
|
+
}
|
package/src/theme/theme.ts
CHANGED
|
@@ -95,6 +95,10 @@ export interface Theme {
|
|
|
95
95
|
section: string;
|
|
96
96
|
};
|
|
97
97
|
success: string;
|
|
98
|
+
/** Solid warning colour for icons and accents. */
|
|
99
|
+
warning: string;
|
|
100
|
+
/** Solid info colour for icons and accents. */
|
|
101
|
+
info: string;
|
|
98
102
|
brand: {
|
|
99
103
|
default: string;
|
|
100
104
|
hover: string;
|
|
@@ -129,6 +133,11 @@ export interface Theme {
|
|
|
129
133
|
// Quiet grey for states that carry no category (e.g. "no change"), built
|
|
130
134
|
// from the mode's muted text colour.
|
|
131
135
|
neutral: { text: string; bg: string; border: string };
|
|
136
|
+
// Status tones for state, as opposed to the label tones above.
|
|
137
|
+
success: { text: string; bg: string; border: string };
|
|
138
|
+
warning: { text: string; bg: string; border: string };
|
|
139
|
+
danger: { text: string; bg: string; border: string };
|
|
140
|
+
info: { text: string; bg: string; border: string };
|
|
132
141
|
};
|
|
133
142
|
};
|
|
134
143
|
space: {
|
|
@@ -267,6 +276,8 @@ function buildTheme(mode: ThemeMode): Theme {
|
|
|
267
276
|
section: '#E6E6E9',
|
|
268
277
|
},
|
|
269
278
|
success: '#16a34a',
|
|
279
|
+
warning: '#ca8a04',
|
|
280
|
+
info: blue[500],
|
|
270
281
|
brand: {
|
|
271
282
|
default: blue[500],
|
|
272
283
|
hover: blue[400],
|
|
@@ -307,6 +318,22 @@ function buildTheme(mode: ThemeMode): Theme {
|
|
|
307
318
|
bg: applyTransparency(gray[600], 0.08),
|
|
308
319
|
border: applyTransparency(gray[600], 0.22),
|
|
309
320
|
},
|
|
321
|
+
success: {
|
|
322
|
+
text: '#15803d',
|
|
323
|
+
bg: applyTransparency('#16a34a', 0.08),
|
|
324
|
+
border: applyTransparency('#16a34a', 0.22),
|
|
325
|
+
},
|
|
326
|
+
warning: { text: '#854d0e', bg: 'rgba(234,179,8,0.16)', border: 'rgba(202,138,4,0.40)' },
|
|
327
|
+
danger: {
|
|
328
|
+
text: red[700],
|
|
329
|
+
bg: applyTransparency(red[500], 0.08),
|
|
330
|
+
border: applyTransparency(red[500], 0.22),
|
|
331
|
+
},
|
|
332
|
+
info: {
|
|
333
|
+
text: blue[700],
|
|
334
|
+
bg: applyTransparency(blue[500], 0.08),
|
|
335
|
+
border: applyTransparency(blue[500], 0.24),
|
|
336
|
+
},
|
|
310
337
|
},
|
|
311
338
|
};
|
|
312
339
|
|
|
@@ -359,6 +386,8 @@ function buildTheme(mode: ThemeMode): Theme {
|
|
|
359
386
|
section: '#2B2C30',
|
|
360
387
|
},
|
|
361
388
|
success: '#22C55E',
|
|
389
|
+
warning: '#EAB308',
|
|
390
|
+
info: blue[400],
|
|
362
391
|
brand: {
|
|
363
392
|
default: blue[400],
|
|
364
393
|
hover: blue[300],
|
|
@@ -400,6 +429,22 @@ function buildTheme(mode: ThemeMode): Theme {
|
|
|
400
429
|
bg: applyTransparency(darkMuted, 0.16),
|
|
401
430
|
border: applyTransparency(darkMuted, 0.3),
|
|
402
431
|
},
|
|
432
|
+
success: {
|
|
433
|
+
text: '#86EFAC',
|
|
434
|
+
bg: applyTransparency('#22C55E', 0.16),
|
|
435
|
+
border: applyTransparency('#22C55E', 0.3),
|
|
436
|
+
},
|
|
437
|
+
warning: { text: '#FDE047', bg: 'rgba(234,179,8,0.20)', border: 'rgba(234,179,8,0.42)' },
|
|
438
|
+
danger: {
|
|
439
|
+
text: red[400],
|
|
440
|
+
bg: applyTransparency(red[500], 0.16),
|
|
441
|
+
border: applyTransparency(red[500], 0.3),
|
|
442
|
+
},
|
|
443
|
+
info: {
|
|
444
|
+
text: blue[300],
|
|
445
|
+
bg: applyTransparency(blue[400], 0.18),
|
|
446
|
+
border: applyTransparency(blue[400], 0.36),
|
|
447
|
+
},
|
|
403
448
|
},
|
|
404
449
|
};
|
|
405
450
|
|