@refineui/utilities 0.0.1 → 0.0.2
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 +86 -0
- package/package.json +60 -58
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @refineui/utilities
|
|
2
|
+
|
|
3
|
+
Shared helpers behind [RefineUI](https://ui.pelagornis.com) components — token references, DOM attribute normalization, and React composition primitives.
|
|
4
|
+
|
|
5
|
+
This package holds the logic that would otherwise be duplicated across components. It depends only on `@refineui/version`, never on `@refineui/tokens`, so token packages stay at the bottom of the dependency graph.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @refineui/utilities
|
|
11
|
+
yarn add @refineui/utilities
|
|
12
|
+
pnpm add @refineui/utilities
|
|
13
|
+
bun add @refineui/utilities
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
React 18+ is a peer dependency, required only for the `react` entry point.
|
|
17
|
+
|
|
18
|
+
## Entry points
|
|
19
|
+
|
|
20
|
+
| Import | Contents |
|
|
21
|
+
|--------|----------|
|
|
22
|
+
| `@refineui/utilities` | animation + color + dom + react + typography |
|
|
23
|
+
| `@refineui/utilities/color` | Color token refs, CSS var resolution, `hexToRgba`, `shadowWithColor` |
|
|
24
|
+
| `@refineui/utilities/typography` | Semantic text and Foundation typography token refs |
|
|
25
|
+
| `@refineui/utilities/animation` | Motion presets, transition/animation style builders, reduced-motion query |
|
|
26
|
+
| `@refineui/utilities/react` | `useComposedRefs`, `composeRefs`, `acquireBodyScrollLock`, `getMergeableTriggerChild` |
|
|
27
|
+
|
|
28
|
+
Subpath imports keep React out of the bundle when you only need token helpers.
|
|
29
|
+
|
|
30
|
+
## Color tokens
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import {
|
|
34
|
+
hexToRgba,
|
|
35
|
+
resolveColorTokenValue,
|
|
36
|
+
semanticColorToken,
|
|
37
|
+
} from "@refineui/utilities/color";
|
|
38
|
+
|
|
39
|
+
const surface = semanticColorToken("background-surface");
|
|
40
|
+
resolveColorTokenValue(surface); // var(--refineui-color-alias-background-surface)
|
|
41
|
+
hexToRgba("#1a1a1a", 0.6); // rgba(26, 26, 26, 0.6)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Raw strings pass through `resolveColorTokenValue` unchanged, so a token ref and a literal can share one prop type.
|
|
45
|
+
|
|
46
|
+
## Motion
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { createTransitionStyle, getReducedMotionQuery } from "@refineui/utilities/animation";
|
|
50
|
+
|
|
51
|
+
const style = createTransitionStyle({
|
|
52
|
+
properties: ["opacity", "transform"],
|
|
53
|
+
duration: "fast", // instant | fast | normal | slow | toast
|
|
54
|
+
easing: "standard", // standard | emphasized | linear
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Durations and easings resolve to token CSS variables, so motion stays in step with `@refineui/tokens`. Pass `reduceMotion: true` to collapse a transition to `instant`, and use `getReducedMotionQuery()` — which returns the `@media (prefers-reduced-motion: reduce)` at-rule — when emitting the same contract in a stylesheet.
|
|
59
|
+
|
|
60
|
+
## React composition
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import { useComposedRefs, acquireBodyScrollLock } from "@refineui/utilities/react";
|
|
64
|
+
|
|
65
|
+
const ref = useComposedRefs(localRef, forwardedRef);
|
|
66
|
+
|
|
67
|
+
// Overlay surfaces lock the body once and release on the last unmount.
|
|
68
|
+
useEffect(() => acquireBodyScrollLock(), []);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`acquireBodyScrollLock` is reference counted, so nested Dialog and Drawer instances do not fight over `overflow`.
|
|
72
|
+
|
|
73
|
+
## DOM attributes
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { ariaAttr, dataAttr } from "@refineui/utilities";
|
|
77
|
+
|
|
78
|
+
dataAttr(isSelected); // "" | undefined → renders data-selected only when true
|
|
79
|
+
ariaAttr(isDisabled); // "true" | undefined → omits aria-disabled when false
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Development
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
bun run build # one tsup pass per entry point
|
|
86
|
+
```
|
package/package.json
CHANGED
|
@@ -1,66 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@refineui/utilities",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "RefineUI React utilities for building components",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"repository": {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
"scripts": {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
"exports": {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
"./color": {
|
|
27
|
-
"types": "./lib/color.d.ts",
|
|
28
|
-
"import": "./lib/color.js",
|
|
29
|
-
"require": "./lib/color.cjs"
|
|
30
|
-
},
|
|
31
|
-
"./typography": {
|
|
32
|
-
"types": "./lib/typography.d.ts",
|
|
33
|
-
"import": "./lib/typography.js",
|
|
34
|
-
"require": "./lib/typography.cjs"
|
|
35
|
-
},
|
|
36
|
-
"./animation": {
|
|
37
|
-
"types": "./lib/animation.d.ts",
|
|
38
|
-
"import": "./lib/animation.js",
|
|
39
|
-
"require": "./lib/animation.cjs"
|
|
40
|
-
},
|
|
41
|
-
"./react": {
|
|
42
|
-
"types": "./lib/react.d.ts",
|
|
43
|
-
"import": "./lib/react.js",
|
|
44
|
-
"require": "./lib/react.cjs"
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"main": "./lib/index.cjs",
|
|
48
|
-
"files": [
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
"react
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/pelagornis/refineui",
|
|
11
|
+
"directory": "packages/utilities"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsup src/color.ts --format cjs,esm --dts --clean --out-dir lib --external react --external react-dom && tsup src/typography.ts --format cjs,esm --dts --out-dir lib --external react --external react-dom && tsup src/animation.ts --format cjs,esm --dts --out-dir lib --external react --external react-dom && tsup src/react.ts --format cjs,esm --dts --out-dir lib --external react --external react-dom && tsup src/index.ts --format cjs,esm --dts --out-dir lib --external react --external react-dom",
|
|
15
|
+
"build:color": "tsup src/color.ts --format cjs,esm --dts --clean --out-dir lib --external react --external react-dom",
|
|
16
|
+
"build:animation": "tsup src/animation.ts --format cjs,esm --dts --out-dir lib --external react --external react-dom",
|
|
17
|
+
"build:react": "tsup src/react.ts --format cjs,esm --dts --out-dir lib --external react --external react-dom",
|
|
18
|
+
"build:index": "tsup src/index.ts --format cjs,esm --dts --out-dir lib --external react --external react-dom"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./lib/index.d.ts",
|
|
23
|
+
"import": "./lib/index.js",
|
|
24
|
+
"require": "./lib/index.cjs"
|
|
25
|
+
},
|
|
26
|
+
"./color": {
|
|
27
|
+
"types": "./lib/color.d.ts",
|
|
28
|
+
"import": "./lib/color.js",
|
|
29
|
+
"require": "./lib/color.cjs"
|
|
30
|
+
},
|
|
31
|
+
"./typography": {
|
|
32
|
+
"types": "./lib/typography.d.ts",
|
|
33
|
+
"import": "./lib/typography.js",
|
|
34
|
+
"require": "./lib/typography.cjs"
|
|
35
|
+
},
|
|
36
|
+
"./animation": {
|
|
37
|
+
"types": "./lib/animation.d.ts",
|
|
38
|
+
"import": "./lib/animation.js",
|
|
39
|
+
"require": "./lib/animation.cjs"
|
|
40
|
+
},
|
|
41
|
+
"./react": {
|
|
42
|
+
"types": "./lib/react.d.ts",
|
|
43
|
+
"import": "./lib/react.js",
|
|
44
|
+
"require": "./lib/react.cjs"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"main": "./lib/index.cjs",
|
|
48
|
+
"files": [
|
|
49
|
+
"lib"
|
|
50
|
+
],
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@refineui/version": "1.0.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"react": ">=18.0.0",
|
|
56
|
+
"react-dom": ">=18.0.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@types/react": "^18.3.20",
|
|
60
|
+
"react": "^18.3.1",
|
|
61
|
+
"react-dom": "^18.3.1",
|
|
62
|
+
"tsup": "^8.0.0",
|
|
63
|
+
"typescript": "^5.0.0"
|
|
64
|
+
},
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public"
|
|
67
|
+
}
|
|
66
68
|
}
|