@eqtylab/equality 3.7.0 → 3.9.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/README.md +118 -0
- package/dist/index.cjs +72 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -13
- package/dist/index.d.ts +25 -13
- package/dist/index.js +72 -17
- package/dist/index.js.map +1 -1
- package/package.json +8 -3
- package/LICENSE +0 -190
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# @eqtylab/equality
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@eqtylab/equality)
|
|
4
|
+
[](https://github.com/eqtylab/equality/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
EQTY Lab's design system: accessible React components and design tokens, built on Radix UI and Tailwind CSS v4.
|
|
7
|
+
|
|
8
|
+
**[Documentation](https://equality.eqtylab.io/)** · **[Components](https://equality.eqtylab.io/components/button/)** · **[GitHub](https://github.com/eqtylab/equality)**
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @eqtylab/equality
|
|
14
|
+
# or
|
|
15
|
+
pnpm add @eqtylab/equality
|
|
16
|
+
# or
|
|
17
|
+
yarn add @eqtylab/equality
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Requires `react` and `react-dom` 18.2 or newer.
|
|
21
|
+
|
|
22
|
+
## Setup
|
|
23
|
+
|
|
24
|
+
### Tailwind CSS v4 (recommended)
|
|
25
|
+
|
|
26
|
+
Import the theme config, then a preflight, in your global stylesheet:
|
|
27
|
+
|
|
28
|
+
```css
|
|
29
|
+
@import '@eqtylab/equality/theme-config.css';
|
|
30
|
+
@import '@eqtylab/equality/preflight.css' layer(base);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`theme-config.css` must come first, because it declares the layer order the preflight relies on. It builds on Tailwind, so `tailwindcss` v4 must be installed in your project.
|
|
34
|
+
|
|
35
|
+
| Stylesheet | Contains |
|
|
36
|
+
| ---------------------------------------- | ----------------------------------------------------- |
|
|
37
|
+
| `@eqtylab/equality/theme-config.css` | Tokens, theme, utilities and components. No reset. |
|
|
38
|
+
| `@eqtylab/equality/preflight.css` | Base styles reset for `html` and everything under it. |
|
|
39
|
+
| `@eqtylab/equality/preflight-scoped.css` | The same reset, only inside `[data-equality-root]`. |
|
|
40
|
+
|
|
41
|
+
If you're embedding Equality in a site that has its own base styles, use `preflight-scoped.css` instead so the reset doesn't affect the rest of the page.
|
|
42
|
+
|
|
43
|
+
### Without Tailwind
|
|
44
|
+
|
|
45
|
+
Wrap your app, or the part of it that uses Equality, in `ThemeProvider`:
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
import { ThemeProvider } from '@eqtylab/equality';
|
|
49
|
+
|
|
50
|
+
export function Root() {
|
|
51
|
+
return (
|
|
52
|
+
<ThemeProvider>
|
|
53
|
+
<App />
|
|
54
|
+
</ThemeProvider>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
See the [Usage guide](https://equality.eqtylab.io/getting-started/usage/) for embedding in host sites, shadow DOM, and portalled surfaces.
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import { Button, Card, CardContent } from '@eqtylab/equality';
|
|
65
|
+
|
|
66
|
+
export function Example() {
|
|
67
|
+
return (
|
|
68
|
+
<Card>
|
|
69
|
+
<CardContent>
|
|
70
|
+
<Button>Save changes</Button>
|
|
71
|
+
</CardContent>
|
|
72
|
+
</Card>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Every component accepts a `className` prop for local style overrides. Component styles are scoped with CSS Modules, so overrides don't leak into other components.
|
|
78
|
+
|
|
79
|
+
## Themes
|
|
80
|
+
|
|
81
|
+
Equality ships `light` and `dark` themes. Set the active theme on the root element:
|
|
82
|
+
|
|
83
|
+
```html
|
|
84
|
+
<html data-equality-theme="dark"></html>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
To apply a stored or system preference before first paint, inline the `initializeTheme` script in your document `<head>`:
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
import { initializeTheme } from '@eqtylab/equality/scripts';
|
|
91
|
+
|
|
92
|
+
<head>
|
|
93
|
+
<script>{initializeTheme()}</script>
|
|
94
|
+
</head>;
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
See [Themes](https://equality.eqtylab.io/getting-started/themes/) for options.
|
|
98
|
+
|
|
99
|
+
## Entry points
|
|
100
|
+
|
|
101
|
+
| Import path | Contents |
|
|
102
|
+
| ---------------------------------------- | -------------------------------------------------- |
|
|
103
|
+
| `@eqtylab/equality` | Components, `ThemeProvider`, and hooks |
|
|
104
|
+
| `@eqtylab/equality/scripts` | `initializeTheme` inline script for theme startup |
|
|
105
|
+
| `@eqtylab/equality/syntax-language` | File name to syntax grammar mapping for CodeBlock |
|
|
106
|
+
| `@eqtylab/equality/theme-config.css` | Tailwind v4 theme config |
|
|
107
|
+
| `@eqtylab/equality/preflight.css` | Global base styles reset |
|
|
108
|
+
| `@eqtylab/equality/preflight-scoped.css` | Base styles reset scoped to `[data-equality-root]` |
|
|
109
|
+
|
|
110
|
+
The package ships ES modules and CommonJS builds with TypeScript types.
|
|
111
|
+
|
|
112
|
+
## Accessibility
|
|
113
|
+
|
|
114
|
+
Components are built on [Radix UI](https://www.radix-ui.com/) primitives and designed for keyboard navigation and screen readers.
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
[Apache-2.0](https://github.com/eqtylab/equality/blob/main/LICENSE)
|
package/dist/index.cjs
CHANGED
|
@@ -1227,23 +1227,25 @@ function CopyButton({
|
|
|
1227
1227
|
var CODE_BLOCK_ATTRIBUTE = "data-equality-code-block";
|
|
1228
1228
|
var SELECTOR = `pre[${CODE_BLOCK_ATTRIBUTE}] > code`;
|
|
1229
1229
|
var tail = Promise.resolve();
|
|
1230
|
-
var queued =
|
|
1230
|
+
var queued = /* @__PURE__ */ new Map();
|
|
1231
1231
|
var isSupported = () => typeof window !== "undefined" && typeof CSS !== "undefined" && Boolean(CSS.highlights);
|
|
1232
|
-
var scheduleHighlight = () => {
|
|
1232
|
+
var scheduleHighlight = (root) => {
|
|
1233
1233
|
if (!isSupported()) return Promise.resolve();
|
|
1234
|
-
|
|
1234
|
+
const tree = root ?? document;
|
|
1235
|
+
const pending = queued.get(tree);
|
|
1236
|
+
if (pending) return pending;
|
|
1235
1237
|
const pass = tail.then(
|
|
1236
1238
|
() => new Promise((resolve) => {
|
|
1237
1239
|
window.requestAnimationFrame(() => {
|
|
1238
|
-
queued
|
|
1239
|
-
microlighter.highlightAll({ selector: SELECTOR }).then(
|
|
1240
|
+
queued.delete(tree);
|
|
1241
|
+
microlighter.highlightAll({ root: tree, selector: SELECTOR }).then(
|
|
1240
1242
|
() => resolve(),
|
|
1241
1243
|
() => resolve()
|
|
1242
1244
|
);
|
|
1243
1245
|
});
|
|
1244
1246
|
})
|
|
1245
1247
|
);
|
|
1246
|
-
queued
|
|
1248
|
+
queued.set(tree, pass);
|
|
1247
1249
|
tail = pass;
|
|
1248
1250
|
return pass;
|
|
1249
1251
|
};
|
|
@@ -1257,9 +1259,11 @@ var CodeBlock = ({
|
|
|
1257
1259
|
copy,
|
|
1258
1260
|
lineNumbers = false
|
|
1259
1261
|
}) => {
|
|
1262
|
+
const preRef = React15.useRef(null);
|
|
1260
1263
|
React15.useEffect(() => {
|
|
1261
|
-
|
|
1262
|
-
|
|
1264
|
+
const root = preRef.current?.getRootNode();
|
|
1265
|
+
void scheduleHighlight(root);
|
|
1266
|
+
return () => void scheduleHighlight(root);
|
|
1263
1267
|
}, [code, language]);
|
|
1264
1268
|
const gutter = React15.useMemo(() => {
|
|
1265
1269
|
if (!lineNumbers) return null;
|
|
@@ -1283,7 +1287,7 @@ var CodeBlock = ({
|
|
|
1283
1287
|
"aria-label": title ? `${title}, code block` : "Code block",
|
|
1284
1288
|
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn(styles15__default.default.body, { [styles15__default.default.numbered]: lineNumbers }), children: [
|
|
1285
1289
|
gutter && /* @__PURE__ */ jsxRuntime.jsx("pre", { "aria-hidden": "true", className: styles15__default.default.gutter, children: gutter }),
|
|
1286
|
-
/* @__PURE__ */ jsxRuntime.jsx("pre", { className: styles15__default.default.pre, ...{ [CODE_BLOCK_ATTRIBUTE]: "" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1290
|
+
/* @__PURE__ */ jsxRuntime.jsx("pre", { ref: preRef, className: styles15__default.default.pre, ...{ [CODE_BLOCK_ATTRIBUTE]: "" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1287
1291
|
"code",
|
|
1288
1292
|
{
|
|
1289
1293
|
className: cn(styles15__default.default.code, `language-${language}`, { [styles15__default.default.wrap]: !lineNumbers }),
|
|
@@ -3772,6 +3776,22 @@ var RELATIVE_DIVISIONS = [
|
|
|
3772
3776
|
{ amount: Number.POSITIVE_INFINITY, unit: "year" }
|
|
3773
3777
|
];
|
|
3774
3778
|
var LIVE_INTERVAL_MS = 3e4;
|
|
3779
|
+
var MINUTE_MS = 6e4;
|
|
3780
|
+
var HOUR_MS = 60 * MINUTE_MS;
|
|
3781
|
+
var DAY_MS = 24 * HOUR_MS;
|
|
3782
|
+
var YEAR_MS = 365.25 * DAY_MS;
|
|
3783
|
+
var MONTH_MS = YEAR_MS / 12;
|
|
3784
|
+
var JUST_NOW_MS = 45e3;
|
|
3785
|
+
var COARSE_AFTER_MS = 90 * DAY_MS;
|
|
3786
|
+
var FINE_UNITS = [
|
|
3787
|
+
{ ms: DAY_MS, unit: "day" },
|
|
3788
|
+
{ ms: HOUR_MS, unit: "hour" },
|
|
3789
|
+
{ ms: MINUTE_MS, unit: "minute" }
|
|
3790
|
+
];
|
|
3791
|
+
var COARSE_UNITS = [
|
|
3792
|
+
{ ms: YEAR_MS, unit: "year" },
|
|
3793
|
+
{ ms: MONTH_MS, unit: "month" }
|
|
3794
|
+
];
|
|
3775
3795
|
var NO_DATE_PLACEHOLDER = "---";
|
|
3776
3796
|
function isMissing(value) {
|
|
3777
3797
|
return value == null || typeof value === "string" && value.trim() === "";
|
|
@@ -3784,8 +3804,8 @@ function formatAbsolute(date, timeZone, options, locale) {
|
|
|
3784
3804
|
return new Intl.DateTimeFormat(locale, { ...options, timeZone }).format(date);
|
|
3785
3805
|
}
|
|
3786
3806
|
function formatRelative(date, now, locale) {
|
|
3807
|
+
if (Math.abs(date.getTime() - now.getTime()) < JUST_NOW_MS) return "Just now";
|
|
3787
3808
|
let duration = (date.getTime() - now.getTime()) / 1e3;
|
|
3788
|
-
if (Math.abs(duration) < 45) return "Just now";
|
|
3789
3809
|
const rtf = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
|
|
3790
3810
|
for (const division of RELATIVE_DIVISIONS) {
|
|
3791
3811
|
if (Math.abs(duration) < division.amount) {
|
|
@@ -3795,6 +3815,30 @@ function formatRelative(date, now, locale) {
|
|
|
3795
3815
|
}
|
|
3796
3816
|
return "Just now";
|
|
3797
3817
|
}
|
|
3818
|
+
function measureSpan(spanMs) {
|
|
3819
|
+
const units = spanMs < COARSE_AFTER_MS ? FINE_UNITS : COARSE_UNITS;
|
|
3820
|
+
const index = units.findIndex(({ ms: ms2 }) => spanMs >= ms2);
|
|
3821
|
+
if (index === -1) return { value: 1, unit: units[units.length - 1].unit };
|
|
3822
|
+
const { ms, unit } = units[index];
|
|
3823
|
+
const value = Math.round(spanMs / ms);
|
|
3824
|
+
const next = units[index - 1];
|
|
3825
|
+
if (next && value * ms >= next.ms) {
|
|
3826
|
+
return { value: Math.round(spanMs / next.ms), unit: next.unit };
|
|
3827
|
+
}
|
|
3828
|
+
return { value, unit };
|
|
3829
|
+
}
|
|
3830
|
+
function formatDirected(date, now, mode, locale) {
|
|
3831
|
+
const spanMs = mode === "until" ? date.getTime() - now.getTime() : now.getTime() - date.getTime();
|
|
3832
|
+
if (spanMs <= 0) return null;
|
|
3833
|
+
if (mode === "since" && spanMs < JUST_NOW_MS) return "Just now";
|
|
3834
|
+
const { value, unit } = measureSpan(spanMs);
|
|
3835
|
+
if (mode === "until") {
|
|
3836
|
+
return new Intl.NumberFormat(locale, { style: "unit", unit, unitDisplay: "long" }).format(
|
|
3837
|
+
value
|
|
3838
|
+
);
|
|
3839
|
+
}
|
|
3840
|
+
return new Intl.RelativeTimeFormat(locale, { numeric: "always" }).format(-value, unit);
|
|
3841
|
+
}
|
|
3798
3842
|
function FormatDate({
|
|
3799
3843
|
date,
|
|
3800
3844
|
displayAs = "absolute",
|
|
@@ -3810,13 +3854,13 @@ function FormatDate({
|
|
|
3810
3854
|
const parsed = React15__namespace.useMemo(() => isMissing(date) ? null : toDate(date), [date]);
|
|
3811
3855
|
const [now, setNow] = React15__namespace.useState(() => /* @__PURE__ */ new Date());
|
|
3812
3856
|
const [mounted, setMounted] = React15__namespace.useState(false);
|
|
3813
|
-
const
|
|
3857
|
+
const isAbsolute = displayAs === "absolute";
|
|
3814
3858
|
React15__namespace.useEffect(() => setMounted(true), []);
|
|
3815
3859
|
React15__namespace.useEffect(() => {
|
|
3816
|
-
if (
|
|
3860
|
+
if (isAbsolute || !live) return;
|
|
3817
3861
|
const id = setInterval(() => setNow(/* @__PURE__ */ new Date()), LIVE_INTERVAL_MS);
|
|
3818
3862
|
return () => clearInterval(id);
|
|
3819
|
-
}, [
|
|
3863
|
+
}, [isAbsolute, live]);
|
|
3820
3864
|
if (missing) {
|
|
3821
3865
|
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn(styles57__default.default["format-date"], className), "aria-label": "No date", ...props, children: NO_DATE_PLACEHOLDER });
|
|
3822
3866
|
}
|
|
@@ -3830,12 +3874,23 @@ function FormatDate({
|
|
|
3830
3874
|
absoluteOptions ?? DEFAULT_ABSOLUTE_OPTIONS,
|
|
3831
3875
|
locale
|
|
3832
3876
|
);
|
|
3833
|
-
if (
|
|
3877
|
+
if (isAbsolute) {
|
|
3834
3878
|
return /* @__PURE__ */ jsxRuntime.jsx("time", { dateTime: machineValue, className: cn(styles57__default.default["format-date"], className), ...props, children: absolute });
|
|
3835
3879
|
}
|
|
3836
|
-
const
|
|
3880
|
+
const measured = !mounted ? absolute : displayAs === "relative" ? formatRelative(parsed, now, locale) : formatDirected(parsed, now, displayAs, locale);
|
|
3881
|
+
if (measured === null) {
|
|
3882
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3883
|
+
"span",
|
|
3884
|
+
{
|
|
3885
|
+
className: cn(styles57__default.default["format-date"], className),
|
|
3886
|
+
"aria-label": displayAs === "until" ? "Date has passed" : "Date not yet reached",
|
|
3887
|
+
...props,
|
|
3888
|
+
children: NO_DATE_PLACEHOLDER
|
|
3889
|
+
}
|
|
3890
|
+
);
|
|
3891
|
+
}
|
|
3837
3892
|
if (!tooltip) {
|
|
3838
|
-
return /* @__PURE__ */ jsxRuntime.jsx("time", { dateTime: machineValue, className: cn(styles57__default.default["format-date"], className), ...props, children:
|
|
3893
|
+
return /* @__PURE__ */ jsxRuntime.jsx("time", { dateTime: machineValue, className: cn(styles57__default.default["format-date"], className), ...props, children: measured });
|
|
3839
3894
|
}
|
|
3840
3895
|
return /* @__PURE__ */ jsxRuntime.jsx(TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
|
|
3841
3896
|
/* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -3845,7 +3900,7 @@ function FormatDate({
|
|
|
3845
3900
|
tabIndex: 0,
|
|
3846
3901
|
className: cn(styles57__default.default["format-date"], styles57__default.default["format-date--interactive"], className),
|
|
3847
3902
|
...props,
|
|
3848
|
-
children:
|
|
3903
|
+
children: measured
|
|
3849
3904
|
}
|
|
3850
3905
|
) }),
|
|
3851
3906
|
/* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { children: absolute })
|