@lanfermann/ui 0.0.0-stage → 0.1.1
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/LICENSE +24 -0
- package/README.md +17 -2
- package/TRADEMARK.md +10 -0
- package/brand/app-icon.svg +1 -0
- package/brand/avatar.svg +1 -0
- package/brand/favicon.svg +1 -0
- package/dist/components/accordion/accordion.d.ts +26 -0
- package/dist/components/accordion/accordion.js +78 -0
- package/dist/components/alert/alert.d.ts +19 -0
- package/dist/components/alert/alert.js +68 -0
- package/dist/components/alert-dialog/alert-dialog.d.ts +20 -0
- package/dist/components/alert-dialog/alert-dialog.js +75 -0
- package/dist/components/anchor-heading/anchor-heading.d.ts +19 -0
- package/dist/components/anchor-heading/anchor-heading.js +39 -0
- package/dist/components/avatar/avatar.d.ts +14 -0
- package/dist/components/avatar/avatar.js +42 -0
- package/dist/components/badge/badge.d.ts +12 -0
- package/dist/components/badge/badge.js +27 -0
- package/dist/components/breadcrumbs/breadcrumbs.d.ts +23 -0
- package/dist/components/breadcrumbs/breadcrumbs.js +63 -0
- package/dist/components/button/button-variants.d.ts +15 -0
- package/dist/components/button/button-variants.js +76 -0
- package/dist/components/button/button.d.ts +25 -0
- package/dist/components/button/button.js +50 -0
- package/dist/components/calendar/calendar-selection.js +216 -0
- package/dist/components/calendar/calendar.d.ts +44 -0
- package/dist/components/calendar/calendar.js +208 -0
- package/dist/components/callout/callout.d.ts +21 -0
- package/dist/components/callout/callout.js +75 -0
- package/dist/components/card/card.d.ts +16 -0
- package/dist/components/card/card.js +53 -0
- package/dist/components/checkbox/checkbox.d.ts +9 -0
- package/dist/components/checkbox/checkbox.js +33 -0
- package/dist/components/checkbox-group/checkbox-group.d.ts +18 -0
- package/dist/components/checkbox-group/checkbox-group.js +33 -0
- package/dist/components/code/code.d.ts +7 -0
- package/dist/components/code/code.js +16 -0
- package/dist/components/code-block/code-block-frame.js +146 -0
- package/dist/components/code-block/code-block-live.d.ts +45 -0
- package/dist/components/code-block/code-block-live.js +51 -0
- package/dist/components/code-block/code-block.d.ts +36 -0
- package/dist/components/code-block/code-block.js +51 -0
- package/dist/components/code-block/code-copy.d.ts +12 -0
- package/dist/components/code-block/code-copy.js +71 -0
- package/dist/components/code-block/code-lines-view.d.ts +16 -0
- package/dist/components/code-block/code-lines-view.js +48 -0
- package/dist/components/code-block/code-lines.js +17 -0
- package/dist/components/code-block/code-scroll.js +29 -0
- package/dist/components/code-block/code-surface.js +13 -0
- package/dist/components/code-block/code-tabs-frame.js +85 -0
- package/dist/components/code-block/code-tabs-store.js +25 -0
- package/dist/components/code-block/code-tabs.d.ts +28 -0
- package/dist/components/code-block/code-tabs.js +29 -0
- package/dist/components/code-block/highlight.d.ts +34 -0
- package/dist/components/code-block/highlight.js +258 -0
- package/dist/components/code-block/lines.d.ts +5 -0
- package/dist/components/code-block/lines.js +40 -0
- package/dist/components/collapsible/collapsible.d.ts +19 -0
- package/dist/components/collapsible/collapsible.js +54 -0
- package/dist/components/combobox/combobox.d.ts +84 -0
- package/dist/components/combobox/combobox.js +169 -0
- package/dist/components/container/container.d.ts +16 -0
- package/dist/components/container/container.js +30 -0
- package/dist/components/copy-pill/copy-pill.d.ts +52 -0
- package/dist/components/copy-pill/copy-pill.js +232 -0
- package/dist/components/cta/cta.d.ts +109 -0
- package/dist/components/cta/cta.js +375 -0
- package/dist/components/date-field/date-field.d.ts +40 -0
- package/dist/components/date-field/date-field.js +99 -0
- package/dist/components/date-range-field/date-range-field.d.ts +41 -0
- package/dist/components/date-range-field/date-range-field.js +155 -0
- package/dist/components/dialog/dialog.d.ts +29 -0
- package/dist/components/dialog/dialog.js +96 -0
- package/dist/components/docs-layout/docs-layout.d.ts +17 -0
- package/dist/components/docs-layout/docs-layout.js +46 -0
- package/dist/components/drawer/drawer.d.ts +39 -0
- package/dist/components/drawer/drawer.js +181 -0
- package/dist/components/field/field.d.ts +18 -0
- package/dist/components/field/field.js +77 -0
- package/dist/components/fieldset/fieldset.d.ts +8 -0
- package/dist/components/fieldset/fieldset.js +25 -0
- package/dist/components/figure/figure.d.ts +14 -0
- package/dist/components/figure/figure.js +35 -0
- package/dist/components/form/form.d.ts +31 -0
- package/dist/components/form/form.js +55 -0
- package/dist/components/ground/ground.d.ts +20 -0
- package/dist/components/ground/ground.js +31 -0
- package/dist/components/heading/heading.d.ts +16 -0
- package/dist/components/heading/heading.js +36 -0
- package/dist/components/icon/icon.d.ts +22 -0
- package/dist/components/icon/icon.js +24 -0
- package/dist/components/input/input.d.ts +19 -0
- package/dist/components/input/input.js +46 -0
- package/dist/components/input-group/input-group.d.ts +34 -0
- package/dist/components/input-group/input-group.js +61 -0
- package/dist/components/kbd/kbd.d.ts +6 -0
- package/dist/components/kbd/kbd.js +15 -0
- package/dist/components/link/link-variants.d.ts +13 -0
- package/dist/components/link/link-variants.js +27 -0
- package/dist/components/link/link.d.ts +9 -0
- package/dist/components/link/link.js +18 -0
- package/dist/components/logo/logo-paths.js +22 -0
- package/dist/components/logo/logomark.d.ts +19 -0
- package/dist/components/logo/logomark.js +49 -0
- package/dist/components/logo/wordmark.d.ts +35 -0
- package/dist/components/logo/wordmark.js +48 -0
- package/dist/components/menu/menu.d.ts +26 -0
- package/dist/components/menu/menu.js +132 -0
- package/dist/components/meter/meter.d.ts +29 -0
- package/dist/components/meter/meter.js +68 -0
- package/dist/components/navigation-menu/navigation-menu-variants.d.ts +12 -0
- package/dist/components/navigation-menu/navigation-menu-variants.js +18 -0
- package/dist/components/navigation-menu/navigation-menu.d.ts +42 -0
- package/dist/components/navigation-menu/navigation-menu.js +128 -0
- package/dist/components/number-field/number-field.d.ts +32 -0
- package/dist/components/number-field/number-field.js +85 -0
- package/dist/components/page-header/page-header.d.ts +27 -0
- package/dist/components/page-header/page-header.js +48 -0
- package/dist/components/pager/pager.d.ts +24 -0
- package/dist/components/pager/pager.js +51 -0
- package/dist/components/parameter-list/parameter-list.d.ts +34 -0
- package/dist/components/parameter-list/parameter-list.js +70 -0
- package/dist/components/popover/popover.d.ts +15 -0
- package/dist/components/popover/popover.js +64 -0
- package/dist/components/progress/progress.d.ts +19 -0
- package/dist/components/progress/progress.js +67 -0
- package/dist/components/prose/prose.d.ts +13 -0
- package/dist/components/prose/prose.js +22 -0
- package/dist/components/quote/quote.d.ts +21 -0
- package/dist/components/quote/quote.js +46 -0
- package/dist/components/radio/radio.d.ts +12 -0
- package/dist/components/radio/radio.js +37 -0
- package/dist/components/reference-entry/reference-entry.d.ts +25 -0
- package/dist/components/reference-entry/reference-entry.js +66 -0
- package/dist/components/section/section.d.ts +13 -0
- package/dist/components/section/section.js +30 -0
- package/dist/components/segmented-control/segmented-control.d.ts +42 -0
- package/dist/components/segmented-control/segmented-control.js +413 -0
- package/dist/components/select/select.d.ts +70 -0
- package/dist/components/select/select.js +189 -0
- package/dist/components/separator/separator.d.ts +12 -0
- package/dist/components/separator/separator.js +29 -0
- package/dist/components/side-nav/side-nav.d.ts +48 -0
- package/dist/components/side-nav/side-nav.js +89 -0
- package/dist/components/site-footer/site-footer-floor.js +48 -0
- package/dist/components/site-footer/site-footer.d.ts +38 -0
- package/dist/components/site-footer/site-footer.js +96 -0
- package/dist/components/site-header/site-header.d.ts +77 -0
- package/dist/components/site-header/site-header.js +214 -0
- package/dist/components/slider/slider.d.ts +42 -0
- package/dist/components/slider/slider.js +279 -0
- package/dist/components/spinner/spinner.d.ts +15 -0
- package/dist/components/spinner/spinner.js +34 -0
- package/dist/components/switch/switch.d.ts +8 -0
- package/dist/components/switch/switch.js +28 -0
- package/dist/components/table/table.d.ts +83 -0
- package/dist/components/table/table.js +123 -0
- package/dist/components/table-of-contents/table-of-contents.d.ts +32 -0
- package/dist/components/table-of-contents/table-of-contents.js +187 -0
- package/dist/components/tabs/tabs.d.ts +28 -0
- package/dist/components/tabs/tabs.js +124 -0
- package/dist/components/text/text.d.ts +16 -0
- package/dist/components/text/text.js +63 -0
- package/dist/components/textarea/textarea.d.ts +19 -0
- package/dist/components/textarea/textarea.js +30 -0
- package/dist/components/time-field/time-field.d.ts +40 -0
- package/dist/components/time-field/time-field.js +123 -0
- package/dist/components/toast/toast.d.ts +55 -0
- package/dist/components/toast/toast.js +129 -0
- package/dist/components/tooltip/tooltip.d.ts +16 -0
- package/dist/components/tooltip/tooltip.js +41 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.js +77 -0
- package/dist/internal/arrow.js +41 -0
- package/dist/internal/disclosure.js +20 -0
- package/dist/internal/field-context.js +21 -0
- package/dist/internal/field.d.ts +23 -0
- package/dist/internal/field.js +49 -0
- package/dist/internal/glyphs.js +84 -0
- package/dist/internal/iso-date.d.ts +2 -0
- package/dist/internal/iso-date.js +268 -0
- package/dist/internal/overlay.js +40 -0
- package/dist/internal/picker-sheet.js +74 -0
- package/dist/internal/popup.js +37 -0
- package/dist/internal/range-shape.js +295 -0
- package/dist/internal/reduced-motion.js +19 -0
- package/dist/internal/scroll-edges.js +45 -0
- package/dist/internal/trough.js +39 -0
- package/dist/internal/typed-input.d.ts +16 -0
- package/dist/internal/typed-input.js +133 -0
- package/dist/lib/cn.d.ts +11 -0
- package/dist/lib/cn.js +98 -0
- package/dist/motion/inertia.js +111 -0
- package/dist/motion/spring-step.js +35 -0
- package/dist/motion/springs.d.ts +78 -0
- package/dist/motion/springs.js +81 -0
- package/package.json +107 -4
- package/src/styles/base.css +93 -0
- package/src/styles/calendar.css +117 -0
- package/src/styles/code.css +252 -0
- package/src/styles/density.css +53 -0
- package/src/styles/depth.css +501 -0
- package/src/styles/grounds.css +191 -0
- package/src/styles/marks.css +50 -0
- package/src/styles/motion.css +55 -0
- package/src/styles/motion.generated.css +101 -0
- package/src/styles/prose.css +252 -0
- package/src/styles/radius.css +20 -0
- package/src/styles/segmented.css +208 -0
- package/src/styles/slider.css +110 -0
- package/src/styles/status.css +108 -0
- package/src/styles/tabs.css +39 -0
- package/src/styles/toast.css +106 -0
- package/src/styles/touch.css +41 -0
- package/src/styles/type.css +54 -0
- package/src/styles.css +38 -0
package/dist/lib/cn.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { springNames } from "../motion/springs.js";
|
|
2
|
+
import { clsx } from "clsx";
|
|
3
|
+
import { extendTailwindMerge } from "tailwind-merge";
|
|
4
|
+
// src/lib/cn.ts
|
|
5
|
+
/**
|
|
6
|
+
* The `depth-*` utilities defined in src/styles/depth.css. tailwind-merge has to be told about
|
|
7
|
+
* every custom utility, otherwise it treats e.g. `shadow-raised` as a colour and keeps both sides
|
|
8
|
+
* of a conflict. A test asserts these lists match the stylesheet.
|
|
9
|
+
*/
|
|
10
|
+
const depthNames = [
|
|
11
|
+
"raised",
|
|
12
|
+
"raised-hover",
|
|
13
|
+
"pressed",
|
|
14
|
+
"flat",
|
|
15
|
+
"plug",
|
|
16
|
+
"socket",
|
|
17
|
+
"trough",
|
|
18
|
+
"field",
|
|
19
|
+
"field-focus",
|
|
20
|
+
"field-invalid",
|
|
21
|
+
"card",
|
|
22
|
+
"floating",
|
|
23
|
+
"overlay",
|
|
24
|
+
"bar",
|
|
25
|
+
"none"
|
|
26
|
+
];
|
|
27
|
+
const depthToneNames = [
|
|
28
|
+
"key",
|
|
29
|
+
"accent",
|
|
30
|
+
"danger",
|
|
31
|
+
"thumb"
|
|
32
|
+
];
|
|
33
|
+
const shadowNames = [
|
|
34
|
+
"raised",
|
|
35
|
+
"raised-hover",
|
|
36
|
+
"pressed",
|
|
37
|
+
"flat",
|
|
38
|
+
"plug",
|
|
39
|
+
"socket",
|
|
40
|
+
"field",
|
|
41
|
+
"field-focus",
|
|
42
|
+
"field-invalid",
|
|
43
|
+
"card",
|
|
44
|
+
"floating",
|
|
45
|
+
"overlay",
|
|
46
|
+
"bar"
|
|
47
|
+
];
|
|
48
|
+
const insetShadowNames = [
|
|
49
|
+
"raised",
|
|
50
|
+
"pressed",
|
|
51
|
+
"flat",
|
|
52
|
+
"socket",
|
|
53
|
+
"trough",
|
|
54
|
+
"field",
|
|
55
|
+
"card",
|
|
56
|
+
"sheet",
|
|
57
|
+
"bar"
|
|
58
|
+
];
|
|
59
|
+
const springKeys = springNames.map((name) => `spring-${name}`);
|
|
60
|
+
const twMerge = extendTailwindMerge({ extend: {
|
|
61
|
+
theme: {
|
|
62
|
+
text: ["control"],
|
|
63
|
+
shadow: shadowNames,
|
|
64
|
+
"inset-shadow": insetShadowNames,
|
|
65
|
+
ease: springKeys,
|
|
66
|
+
animate: [
|
|
67
|
+
"spinner",
|
|
68
|
+
"indeterminate",
|
|
69
|
+
"breathe"
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
classGroups: {
|
|
73
|
+
depth: [{ depth: [...depthNames] }],
|
|
74
|
+
"depth-tone": [{ "depth-tone": [...depthToneNames] }],
|
|
75
|
+
spring: [{ spring: [...springNames] }],
|
|
76
|
+
duration: [{ duration: springKeys }]
|
|
77
|
+
},
|
|
78
|
+
conflictingClassGroups: {
|
|
79
|
+
depth: ["shadow", "inset-shadow"],
|
|
80
|
+
spring: ["duration", "ease"]
|
|
81
|
+
}
|
|
82
|
+
} });
|
|
83
|
+
/**
|
|
84
|
+
* Joins class names conditionally and resolves conflicting Tailwind utilities, last one wins.
|
|
85
|
+
* Use it for every `className` a component composes from defaults plus caller overrides.
|
|
86
|
+
*/
|
|
87
|
+
function cn(...inputs) {
|
|
88
|
+
return twMerge(clsx(inputs));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Merges a component's own classes with the caller's `className`, which on Base UI parts may be a
|
|
92
|
+
* function of the part's state. The function form is preserved, so callers keep access to state.
|
|
93
|
+
*/
|
|
94
|
+
function mergeClassName(base, className) {
|
|
95
|
+
if (typeof className === "function") return (state) => cn(base, className(state));
|
|
96
|
+
return cn(base, className);
|
|
97
|
+
}
|
|
98
|
+
export { cn, depthNames, depthToneNames, mergeClassName };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// src/motion/inertia.ts
|
|
2
|
+
/** A slider's thumb, 14px across: a flick of 500px/s adds 6px to it. */
|
|
3
|
+
const THUMB_GIVE = {
|
|
4
|
+
gain: .012,
|
|
5
|
+
max: 6
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A pill (the thumb of a segmented control) is five to eight times as long. Stretched by the
|
|
9
|
+
* same 6px it would look rigid, so it gives by a share of its length instead: 15% at a normal
|
|
10
|
+
* pull of 400px/s, a fifth at the most.
|
|
11
|
+
*/
|
|
12
|
+
const PILL_GAIN = 375e-6;
|
|
13
|
+
const PILL_MAX = .2;
|
|
14
|
+
/** How a pill `size` px long gives. */
|
|
15
|
+
function pillGive(size) {
|
|
16
|
+
return {
|
|
17
|
+
gain: size * PILL_GAIN,
|
|
18
|
+
max: size * PILL_MAX
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Below this speed, in px/s, the part counts as standing. */
|
|
22
|
+
const MIN_SPEED = 20;
|
|
23
|
+
/**
|
|
24
|
+
* A move that comes later than this after the last one starts from rest: whatever speed the
|
|
25
|
+
* part had has gone by then.
|
|
26
|
+
*/
|
|
27
|
+
const STALE_MS = 120;
|
|
28
|
+
function restingMotion(x, time) {
|
|
29
|
+
return {
|
|
30
|
+
x,
|
|
31
|
+
time,
|
|
32
|
+
speed: 0,
|
|
33
|
+
direction: 1,
|
|
34
|
+
stretch: 1
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The part has moved: it now stands at `x` (px) at `time` (ms). `size` is its length at rest,
|
|
39
|
+
* in px; `give` is how it deforms (a slider's thumb unless said otherwise). Returns how it should
|
|
40
|
+
* look from now on.
|
|
41
|
+
*/
|
|
42
|
+
function trackMotion(previous, x, time, size, give = THUMB_GIVE) {
|
|
43
|
+
const elapsed = time - previous.time;
|
|
44
|
+
const distance = x - previous.x;
|
|
45
|
+
if (elapsed <= 0 || distance === 0 || size <= 0) return {
|
|
46
|
+
...previous,
|
|
47
|
+
x
|
|
48
|
+
};
|
|
49
|
+
const measured = Math.abs(distance) / elapsed * 1e3;
|
|
50
|
+
const speed = elapsed > STALE_MS ? measured : (previous.speed + measured) / 2;
|
|
51
|
+
const longer = speed < MIN_SPEED ? 0 : Math.min(speed * give.gain, give.max);
|
|
52
|
+
return {
|
|
53
|
+
x,
|
|
54
|
+
time,
|
|
55
|
+
speed,
|
|
56
|
+
direction: distance > 0 ? 1 : -1,
|
|
57
|
+
stretch: 1 + longer / size
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A part in a trough cannot lag through its wall: `room` is the free way behind it, in px, and
|
|
62
|
+
* the stretch is cut to what fits there. Pulled off a wall it starts rigid and gives as it
|
|
63
|
+
* leaves.
|
|
64
|
+
*/
|
|
65
|
+
function withinRoom(stretch, room, size) {
|
|
66
|
+
if (size <= 0) return 1;
|
|
67
|
+
return Math.min(stretch, 1 + Math.max(0, room) / size);
|
|
68
|
+
}
|
|
69
|
+
/** px longer per px of travel: 100px of way stretch a thumb by 15px. */
|
|
70
|
+
const TRAVEL_GAIN = .18;
|
|
71
|
+
/** The most a travelling part stretches, as a share of its length. */
|
|
72
|
+
const TRAVEL_MAX = .3;
|
|
73
|
+
/** How long a part `size` px long gets for a trip of `distance` px: 1 at rest. */
|
|
74
|
+
function travelStretch(distance, size) {
|
|
75
|
+
if (size <= 0 || distance === 0) return 1;
|
|
76
|
+
return 1 + Math.min(Math.abs(distance) * TRAVEL_GAIN, size * TRAVEL_MAX) / size;
|
|
77
|
+
}
|
|
78
|
+
/** The least and the most a thumb leans, in px, and how much more per px of distance. */
|
|
79
|
+
const LEAN_MIN = 2;
|
|
80
|
+
const LEAN_MAX = 5;
|
|
81
|
+
const LEAN_GAIN = .02;
|
|
82
|
+
/**
|
|
83
|
+
* How far to lean, in px, signed: `offset` is how far the pointer is beyond the thumb's nearer
|
|
84
|
+
* edge, negative to its left. 0 when the pointer is over the thumb.
|
|
85
|
+
*/
|
|
86
|
+
function leanToward(offset) {
|
|
87
|
+
if (offset === 0) return 0;
|
|
88
|
+
return Math.sign(offset) * Math.min(LEAN_MIN + Math.abs(offset) * LEAN_GAIN, LEAN_MAX);
|
|
89
|
+
}
|
|
90
|
+
/** Of the way its near edge leans, the far edge follows this share. The rest is reach. */
|
|
91
|
+
const LEAN_FOLLOW = .5;
|
|
92
|
+
/**
|
|
93
|
+
* The shape of a lean for a part `size` px long: `offset` as for `leanToward`. `room` is the free
|
|
94
|
+
* way on the pointer's side, in px: a thumb that stands at the wall does not lean into it.
|
|
95
|
+
*/
|
|
96
|
+
function leanShape(offset, size, room = Number.POSITIVE_INFINITY) {
|
|
97
|
+
const reach = Math.min(Math.abs(leanToward(offset)), Math.max(0, room));
|
|
98
|
+
if (reach === 0 || size <= 0) return {
|
|
99
|
+
shift: 0,
|
|
100
|
+
stretch: 1,
|
|
101
|
+
hold: 1
|
|
102
|
+
};
|
|
103
|
+
const side = offset > 0 ? 1 : -1;
|
|
104
|
+
const shift = reach * LEAN_FOLLOW;
|
|
105
|
+
return {
|
|
106
|
+
shift: side * shift,
|
|
107
|
+
stretch: 1 + (reach - shift) / size,
|
|
108
|
+
hold: side > 0 ? -1 : 1
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export { leanShape, leanToward, pillGive, restingMotion, trackMotion, travelStretch, withinRoom };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/motion/spring-step.ts
|
|
2
|
+
/** The longest step a frame may take, in s: a tab that was in the background does not leap. */
|
|
3
|
+
const LONGEST_FRAME = 1 / 30;
|
|
4
|
+
/** The spring is worked out in steps of this, in s, so it is the same at any frame rate. */
|
|
5
|
+
const SUBSTEP = 1 / 240;
|
|
6
|
+
/**
|
|
7
|
+
* Stiffness and damping of a spring from the table, for a mass of one: the same reading of
|
|
8
|
+
* `visualDuration` and `bounce` that Motion and the generated CSS use.
|
|
9
|
+
*/
|
|
10
|
+
function springForce({ visualDuration, bounce }) {
|
|
11
|
+
return {
|
|
12
|
+
stiffness: (2 * Math.PI / visualDuration) ** 2,
|
|
13
|
+
damping: 4 * Math.PI * (1 - bounce) / visualDuration
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** Moves a value towards its target for `seconds`. */
|
|
17
|
+
function stepSpring(moving, target, force, seconds) {
|
|
18
|
+
let { value, velocity } = moving;
|
|
19
|
+
let left = Math.min(seconds, LONGEST_FRAME);
|
|
20
|
+
while (left > 0) {
|
|
21
|
+
const step = Math.min(SUBSTEP, left);
|
|
22
|
+
velocity += (force.stiffness * (target - value) - force.damping * velocity) * step;
|
|
23
|
+
value += velocity * step;
|
|
24
|
+
left -= step;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
value,
|
|
28
|
+
velocity
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Whether a value has arrived: as good as there, and as good as still. */
|
|
32
|
+
function atRest(moving, target, within = .002) {
|
|
33
|
+
return Math.abs(target - moving.value) < within && Math.abs(moving.velocity) < within * 20;
|
|
34
|
+
}
|
|
35
|
+
export { atRest, springForce, stepSpring };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The spring table: the single source of truth for motion in @lanfermann/ui.
|
|
3
|
+
*
|
|
4
|
+
* It feeds two consumers so that CSS and JavaScript animation feel identical:
|
|
5
|
+
* - Motion (`motion/react`) through `transitions` below;
|
|
6
|
+
* - plain CSS through `src/styles/motion.generated.css`, written by `bun run gen:motion`
|
|
7
|
+
* (a test fails when the two drift).
|
|
8
|
+
*
|
|
9
|
+
* `visualDuration` is the time until the motion looks finished; a bouncy spring keeps settling a
|
|
10
|
+
* little longer. `bounce` 0 is critically damped. Bounce is reserved for small parts (24px or
|
|
11
|
+
* less), for things the user threw, and for parts let go where there is room for their swing.
|
|
12
|
+
*
|
|
13
|
+
* This module is pure data: no "use client", no Motion import, safe on the server.
|
|
14
|
+
*/
|
|
15
|
+
export declare const springs: {
|
|
16
|
+
/** Press down, hover, pointer focus. */
|
|
17
|
+
readonly snap: {
|
|
18
|
+
readonly visualDuration: 0.12;
|
|
19
|
+
readonly bounce: 0;
|
|
20
|
+
};
|
|
21
|
+
/** The default: popups entering, panels opening, an error revealing. */
|
|
22
|
+
readonly settle: {
|
|
23
|
+
readonly visualDuration: 0.24;
|
|
24
|
+
readonly bounce: 0;
|
|
25
|
+
};
|
|
26
|
+
/** A small part seating: ring to disc, a check, a switch thumb, a button released. */
|
|
27
|
+
readonly seat: {
|
|
28
|
+
readonly visualDuration: 0.28;
|
|
29
|
+
readonly bounce: 0.22;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* A mark travelling inside its container: the tab highlight, the segment thumb. No bounce: a
|
|
33
|
+
* thumb that overshoots would poke through the wall of its trough.
|
|
34
|
+
*/
|
|
35
|
+
readonly glide: {
|
|
36
|
+
readonly visualDuration: 0.32;
|
|
37
|
+
readonly bounce: 0;
|
|
38
|
+
};
|
|
39
|
+
/** A sheet arriving: dialog, toast. */
|
|
40
|
+
readonly sheet: {
|
|
41
|
+
readonly visualDuration: 0.36;
|
|
42
|
+
readonly bounce: 0;
|
|
43
|
+
};
|
|
44
|
+
/** Every exit: faster than the entrance, no bounce, no travel. */
|
|
45
|
+
readonly leave: {
|
|
46
|
+
readonly visualDuration: 0.16;
|
|
47
|
+
readonly bounce: 0;
|
|
48
|
+
};
|
|
49
|
+
/** Releasing a drag with its velocity (Motion only). */
|
|
50
|
+
readonly throw: {
|
|
51
|
+
readonly visualDuration: 0.4;
|
|
52
|
+
readonly bounce: 0.15;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Parts that were pushed together and are let go: the marks of a `CopyPill` fanning back out.
|
|
56
|
+
* Each swings past its place once, by about a twentieth of its way, and settles. Only for a
|
|
57
|
+
* transform, and only where the container leaves room for that swing: a width on this spring
|
|
58
|
+
* makes the container itself swing.
|
|
59
|
+
*/
|
|
60
|
+
readonly recoil: {
|
|
61
|
+
readonly visualDuration: 0.36;
|
|
62
|
+
readonly bounce: 0.3;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* A soft body coming to rest: a slider's thumb that was stretched by its own travel. It swings
|
|
66
|
+
* past its shape once, visibly (the squash), and settles. Only for a deformation of a few
|
|
67
|
+
* pixels; nothing travels on it.
|
|
68
|
+
*/
|
|
69
|
+
readonly rebound: {
|
|
70
|
+
readonly visualDuration: 0.3;
|
|
71
|
+
readonly bounce: 0.5;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
export type SpringName = keyof typeof springs;
|
|
75
|
+
/** The springs as Motion transitions: `transition={transitions.seat}`. */
|
|
76
|
+
export declare const transitions: { [K in SpringName]: {
|
|
77
|
+
type: "spring";
|
|
78
|
+
} & (typeof springs)[K]; };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// src/motion/springs.ts
|
|
2
|
+
/**
|
|
3
|
+
* The spring table: the single source of truth for motion in @lanfermann/ui.
|
|
4
|
+
*
|
|
5
|
+
* It feeds two consumers so that CSS and JavaScript animation feel identical:
|
|
6
|
+
* - Motion (`motion/react`) through `transitions` below;
|
|
7
|
+
* - plain CSS through `src/styles/motion.generated.css`, written by `bun run gen:motion`
|
|
8
|
+
* (a test fails when the two drift).
|
|
9
|
+
*
|
|
10
|
+
* `visualDuration` is the time until the motion looks finished; a bouncy spring keeps settling a
|
|
11
|
+
* little longer. `bounce` 0 is critically damped. Bounce is reserved for small parts (24px or
|
|
12
|
+
* less), for things the user threw, and for parts let go where there is room for their swing.
|
|
13
|
+
*
|
|
14
|
+
* This module is pure data: no "use client", no Motion import, safe on the server.
|
|
15
|
+
*/
|
|
16
|
+
const springs = {
|
|
17
|
+
/** Press down, hover, pointer focus. */
|
|
18
|
+
snap: {
|
|
19
|
+
visualDuration: .12,
|
|
20
|
+
bounce: 0
|
|
21
|
+
},
|
|
22
|
+
/** The default: popups entering, panels opening, an error revealing. */
|
|
23
|
+
settle: {
|
|
24
|
+
visualDuration: .24,
|
|
25
|
+
bounce: 0
|
|
26
|
+
},
|
|
27
|
+
/** A small part seating: ring to disc, a check, a switch thumb, a button released. */
|
|
28
|
+
seat: {
|
|
29
|
+
visualDuration: .28,
|
|
30
|
+
bounce: .22
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* A mark travelling inside its container: the tab highlight, the segment thumb. No bounce: a
|
|
34
|
+
* thumb that overshoots would poke through the wall of its trough.
|
|
35
|
+
*/
|
|
36
|
+
glide: {
|
|
37
|
+
visualDuration: .32,
|
|
38
|
+
bounce: 0
|
|
39
|
+
},
|
|
40
|
+
/** A sheet arriving: dialog, toast. */
|
|
41
|
+
sheet: {
|
|
42
|
+
visualDuration: .36,
|
|
43
|
+
bounce: 0
|
|
44
|
+
},
|
|
45
|
+
/** Every exit: faster than the entrance, no bounce, no travel. */
|
|
46
|
+
leave: {
|
|
47
|
+
visualDuration: .16,
|
|
48
|
+
bounce: 0
|
|
49
|
+
},
|
|
50
|
+
/** Releasing a drag with its velocity (Motion only). */
|
|
51
|
+
throw: {
|
|
52
|
+
visualDuration: .4,
|
|
53
|
+
bounce: .15
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* Parts that were pushed together and are let go: the marks of a `CopyPill` fanning back out.
|
|
57
|
+
* Each swings past its place once, by about a twentieth of its way, and settles. Only for a
|
|
58
|
+
* transform, and only where the container leaves room for that swing: a width on this spring
|
|
59
|
+
* makes the container itself swing.
|
|
60
|
+
*/
|
|
61
|
+
recoil: {
|
|
62
|
+
visualDuration: .36,
|
|
63
|
+
bounce: .3
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* A soft body coming to rest: a slider's thumb that was stretched by its own travel. It swings
|
|
67
|
+
* past its shape once, visibly (the squash), and settles. Only for a deformation of a few
|
|
68
|
+
* pixels; nothing travels on it.
|
|
69
|
+
*/
|
|
70
|
+
rebound: {
|
|
71
|
+
visualDuration: .3,
|
|
72
|
+
bounce: .5
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const springNames = Object.keys(springs);
|
|
76
|
+
/** The springs as Motion transitions: `transition={transitions.seat}`. */
|
|
77
|
+
const transitions = Object.fromEntries(springNames.map((name) => [name, {
|
|
78
|
+
type: "spring",
|
|
79
|
+
...springs[name]
|
|
80
|
+
}]));
|
|
81
|
+
export { springNames, springs, transitions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,109 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lanfermann/ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Lanfermann design system components for Next.js + Tailwind CSS v4, built on Base UI.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Justin Lanfermann",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/jaylann/lanfermann-system.git",
|
|
10
|
+
"directory": "packages/ui"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/jaylann/lanfermann-system#readme",
|
|
13
|
+
"bugs": "https://github.com/jaylann/lanfermann-system/issues",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"react",
|
|
16
|
+
"nextjs",
|
|
17
|
+
"tailwindcss",
|
|
18
|
+
"base-ui",
|
|
19
|
+
"design-system",
|
|
20
|
+
"components"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public",
|
|
24
|
+
"provenance": true
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": [
|
|
28
|
+
"**/*.css"
|
|
29
|
+
],
|
|
30
|
+
"files": [
|
|
31
|
+
"brand",
|
|
32
|
+
"dist",
|
|
33
|
+
"src/styles.css",
|
|
34
|
+
"src/styles/*.css",
|
|
35
|
+
"TRADEMARK.md"
|
|
36
|
+
],
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"default": "./dist/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./styles.css": "./src/styles.css",
|
|
43
|
+
"./brand/*": "./brand/*",
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"dev": "tsdown --watch",
|
|
48
|
+
"build": "tsdown",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
50
|
+
"test": "vitest run --project unit",
|
|
51
|
+
"test:stories": "vitest run --project storybook",
|
|
52
|
+
"storybook": "storybook dev -p 6006 --host 127.0.0.1 --no-open",
|
|
53
|
+
"build-storybook": "storybook build -o storybook-static",
|
|
54
|
+
"storybook:phone": "node scripts/serve-static.ts",
|
|
55
|
+
"visual:check": "node scripts/visual/docker.ts check",
|
|
56
|
+
"visual:baseline": "node scripts/visual/docker.ts baseline",
|
|
57
|
+
"gen:motion": "node scripts/generate-motion-css.ts",
|
|
58
|
+
"brand:check": "node scripts/brand/check-copy.ts",
|
|
59
|
+
"brand:grade": "node scripts/brand/grade-skill.ts",
|
|
60
|
+
"shots": "node scripts/visual/capture.ts"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@base-ui/react": "^1.9.0",
|
|
64
|
+
"@hugeicons/core-free-icons": "^4.4.0",
|
|
65
|
+
"@hugeicons/react": "^1.1.10",
|
|
66
|
+
"class-variance-authority": "^0.7.1",
|
|
67
|
+
"clsx": "^2.1.1",
|
|
68
|
+
"react-day-picker": "^10.0.2",
|
|
69
|
+
"shiki": "^4.6.0",
|
|
70
|
+
"tailwind-merge": "^3.7.0"
|
|
71
|
+
},
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"motion": "^14.0.0",
|
|
74
|
+
"react": "^19.0.0",
|
|
75
|
+
"react-dom": "^19.0.0",
|
|
76
|
+
"tailwindcss": "^4.0.0"
|
|
77
|
+
},
|
|
78
|
+
"peerDependenciesMeta": {
|
|
79
|
+
"motion": {
|
|
80
|
+
"optional": true
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"devDependencies": {
|
|
84
|
+
"@fontsource-variable/jetbrains-mono": "^5.3.0",
|
|
85
|
+
"@fontsource-variable/sofia-sans": "^5.3.0",
|
|
86
|
+
"@storybook/addon-a11y": "^10.6.7",
|
|
87
|
+
"@storybook/addon-docs": "^10.6.7",
|
|
88
|
+
"@storybook/addon-vitest": "^10.6.7",
|
|
89
|
+
"@storybook/react-vite": "^10.6.7",
|
|
90
|
+
"@tailwindcss/vite": "^4.3.5",
|
|
91
|
+
"@types/node": "^26.6.6",
|
|
92
|
+
"@types/pngjs": "^6.0.5",
|
|
93
|
+
"@types/react": "^19.3.0",
|
|
94
|
+
"@types/react-dom": "^19.3.0",
|
|
95
|
+
"@vitest/browser-playwright": "^5.1.0",
|
|
96
|
+
"motion": "^14.14.0",
|
|
97
|
+
"pixelmatch": "^8.0.0",
|
|
98
|
+
"playwright": "^1.65.0",
|
|
99
|
+
"pngjs": "^7.0.0",
|
|
100
|
+
"react": "^19.3.1",
|
|
101
|
+
"react-dom": "^19.3.1",
|
|
102
|
+
"storybook": "^10.6.7",
|
|
103
|
+
"tailwindcss": "^4.3.5",
|
|
104
|
+
"tsdown": "^0.23.7",
|
|
105
|
+
"typescript": "^6.0.3",
|
|
106
|
+
"vite": "^8.3.8",
|
|
107
|
+
"vitest": "^5.1.0"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The little this library sets globally. Everything else is opt-in through utilities.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
@layer base {
|
|
6
|
+
/* A ground paints itself, so nesting `data-theme` switches a whole region. */
|
|
7
|
+
[data-theme] {
|
|
8
|
+
background-color: var(--lf-ground);
|
|
9
|
+
color: var(--lf-text-body);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* At the floor of a page that ends on a `SiteFooter`, the window around the page takes the
|
|
14
|
+
* footer's colour. Safari 26 fills what lies beyond the page (above it behind the status bar,
|
|
15
|
+
* under it behind the toolbar, and past either end when the page is pulled) from <html> and
|
|
16
|
+
* <body> blended, the body on top. So the body stays transparent and the app's wrapper paints
|
|
17
|
+
* the ground (README, "Root"), and the root takes the colour of the end the reader is at: the
|
|
18
|
+
* ground at the top, the footer's once its end is near (`SiteFooterFloor` sets the attribute).
|
|
19
|
+
* One colour for both ends left a strip of the wrong one at the other (Justin's iPhone,
|
|
20
|
+
* 2026-11-16: under the footer, then above the docs).
|
|
21
|
+
*/
|
|
22
|
+
html[data-site-floor] {
|
|
23
|
+
background-color: var(--lf-surface-quiet);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
* While the site's menu covers the window, the window around it takes the menu's colour, so
|
|
28
|
+
* Safari's toolbar under it is the menu's ground and not the footer's colour from the rule
|
|
29
|
+
* above (Justin's iPhone, 2026-11-16: "the bottom tab bar doesn't fill"). Later and as
|
|
30
|
+
* specific, so it wins.
|
|
31
|
+
*/
|
|
32
|
+
html:has(> body [data-slot="site-header-menu-sheet"]) {
|
|
33
|
+
background-color: var(--lf-ground);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
* And the page under the open menu is hidden. Safari 26 draws the page itself behind its
|
|
38
|
+
* floating toolbar, below where a fixed layer reaches (`100lvh` ends above the toolbar there),
|
|
39
|
+
* so the page showed through under the menu (Justin's iPhone, 2026-11-16). Hidden, the root
|
|
40
|
+
* shows there, in the menu's colour. It hides once the menu has mostly risen, so the page does
|
|
41
|
+
* not blink away under a menu still fading in, and it is back the moment the menu starts to
|
|
42
|
+
* close (`data-open` goes first). Everything in the body but the menu's portal is hidden.
|
|
43
|
+
*/
|
|
44
|
+
html:has(> body [data-slot="site-header-menu-sheet"][data-open])
|
|
45
|
+
body
|
|
46
|
+
> :not(:has([data-slot="site-header-menu-sheet"])) {
|
|
47
|
+
visibility: hidden;
|
|
48
|
+
transition: visibility 0s linear calc(var(--transition-duration-spring-sheet) / 2);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/*
|
|
52
|
+
* The body holds the margins of what it starts with (the site bar stands 8px down), so they
|
|
53
|
+
* never push it down and leave the canvas showing above the bar. The app's wrapper needs the
|
|
54
|
+
* same (`flow-root`).
|
|
55
|
+
*/
|
|
56
|
+
body {
|
|
57
|
+
display: flow-root;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
html {
|
|
61
|
+
-webkit-font-smoothing: antialiased;
|
|
62
|
+
-moz-osx-font-smoothing: grayscale;
|
|
63
|
+
/* Sofia Sans has real italics and weights; never fake them. */
|
|
64
|
+
font-synthesis: none;
|
|
65
|
+
text-rendering: optimizeLegibility;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
::selection {
|
|
69
|
+
background-color: color-mix(in oklab, var(--lf-accent) 28%, transparent);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/*
|
|
74
|
+
* The drag handle of a resizable field, for Chromium and Safari: two short strokes that end
|
|
75
|
+
* square, like the glyphs' butt ends, in the line colour of the ground. Other browsers keep
|
|
76
|
+
* their own grip.
|
|
77
|
+
*
|
|
78
|
+
* Keeping the grip clear of a rounded corner is not done here: the field moves it inward with
|
|
79
|
+
* transparent borders (see Textarea), which works in every browser.
|
|
80
|
+
*/
|
|
81
|
+
@utility resize-grip {
|
|
82
|
+
&::-webkit-resizer {
|
|
83
|
+
background: linear-gradient(
|
|
84
|
+
135deg,
|
|
85
|
+
transparent 0 53%,
|
|
86
|
+
var(--lf-line) 53% 65%,
|
|
87
|
+
transparent 65% 80%,
|
|
88
|
+
var(--lf-line) 80% 92%,
|
|
89
|
+
transparent 92%
|
|
90
|
+
)
|
|
91
|
+
no-repeat calc(100% - 1px) calc(100% - 1px) / 9px 9px;
|
|
92
|
+
}
|
|
93
|
+
}
|