@unison-ui/core 0.0.0-pr12-20261120174747
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 +21 -0
- package/README.md +17 -0
- package/dist/components/box/box.styles.d.ts +9 -0
- package/dist/components/box/box.styles.js +11 -0
- package/dist/components/box/box.types.d.ts +6 -0
- package/dist/concentric.d.ts +2 -0
- package/dist/concentric.js +4 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/theme.types.d.ts +20 -0
- package/dist/use-controllable-state.d.ts +9 -0
- package/dist/use-controllable-state.js +26 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mark de Graaff
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @unison-ui/core
|
|
2
|
+
|
|
3
|
+
Platform-free building blocks for Unison components: props types, state hooks and style specs.
|
|
4
|
+
|
|
5
|
+
You normally don't install this directly; the renderers depend on it.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @unison-ui/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Exports today: `useControllableState`, `boxStyles`, `BoxProps`.
|
|
12
|
+
|
|
13
|
+
`@unison-ui/core` never imports `react-dom` or `react-native`, so it runs on every platform.
|
|
14
|
+
|
|
15
|
+
> **Preview.** Only `0.0.0-pr…` snapshot builds exist so far; the API will change before `0.1.0`.
|
|
16
|
+
> Part of [Unison](https://github.com/m-de-graaff/unison), a design system for React on the web
|
|
17
|
+
> and React Native, with motion built in. MIT licensed.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { boxStyles } from "./components/box/box.styles.js";
|
|
2
|
+
import { BoxProps } from "./components/box/box.types.js";
|
|
3
|
+
import { concentric } from "./concentric.js";
|
|
4
|
+
import { ColorScheme, ResolvedScheme, ThemeScopeProps, ThemeState } from "./theme.types.js";
|
|
5
|
+
import { useControllableState } from "./use-controllable-state.js";
|
|
6
|
+
export { type BoxProps, type ColorScheme, type ResolvedScheme, type ThemeScopeProps, type ThemeState, boxStyles, concentric, useControllableState };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
/** What the user picked; `system` follows the OS. */
|
|
3
|
+
export type ColorScheme = "light" | "dark" | "system";
|
|
4
|
+
/** The scheme actually shown. */
|
|
5
|
+
export type ResolvedScheme = "light" | "dark";
|
|
6
|
+
/** Returned by `useTheme()` on web and native (native adds `tokens`). */
|
|
7
|
+
export interface ThemeState {
|
|
8
|
+
scheme: ColorScheme;
|
|
9
|
+
resolvedScheme: ResolvedScheme;
|
|
10
|
+
setScheme: (scheme: ColorScheme) => void;
|
|
11
|
+
theme: string;
|
|
12
|
+
setTheme: (theme: string) => void;
|
|
13
|
+
themes: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
/** Scopes a theme and/or scheme to a subtree. */
|
|
16
|
+
export interface ThemeScopeProps {
|
|
17
|
+
theme?: string;
|
|
18
|
+
scheme?: ResolvedScheme;
|
|
19
|
+
children?: ReactNode;
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Controlled when `value !== undefined`, otherwise keeps internal state.
|
|
3
|
+
* `onChange` fires only when the value actually changes (`Object.is`).
|
|
4
|
+
*/
|
|
5
|
+
export declare function useControllableState<T>(opts: {
|
|
6
|
+
value?: T;
|
|
7
|
+
defaultValue: T;
|
|
8
|
+
onChange?: (value: T) => void;
|
|
9
|
+
}): [T, (next: T | ((prev: T) => T)) => void];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useRef, useState } from "react";
|
|
3
|
+
// src/use-controllable-state.ts
|
|
4
|
+
/**
|
|
5
|
+
* Controlled when `value !== undefined`, otherwise keeps internal state.
|
|
6
|
+
* `onChange` fires only when the value actually changes (`Object.is`).
|
|
7
|
+
*/
|
|
8
|
+
function useControllableState(opts) {
|
|
9
|
+
const { value, defaultValue, onChange } = opts;
|
|
10
|
+
const [internal, setInternal] = useState(defaultValue);
|
|
11
|
+
const controlled = value !== void 0;
|
|
12
|
+
const current = controlled ? value : internal;
|
|
13
|
+
const currentRef = useRef(current);
|
|
14
|
+
currentRef.current = current;
|
|
15
|
+
const onChangeRef = useRef(onChange);
|
|
16
|
+
onChangeRef.current = onChange;
|
|
17
|
+
return [current, useCallback((next) => {
|
|
18
|
+
const prev = currentRef.current;
|
|
19
|
+
const resolved = typeof next === "function" ? next(prev) : next;
|
|
20
|
+
if (Object.is(resolved, prev)) return;
|
|
21
|
+
currentRef.current = resolved;
|
|
22
|
+
if (!controlled) setInternal(resolved);
|
|
23
|
+
onChangeRef.current?.(resolved);
|
|
24
|
+
}, [controlled])];
|
|
25
|
+
}
|
|
26
|
+
export { useControllableState };
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@unison-ui/core",
|
|
3
|
+
"version": "0.0.0-pr12-20261120174747",
|
|
4
|
+
"description": "Platform-free building blocks for Unison components: props types, state hooks and style specs.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/m-de-graaff/unison.git",
|
|
9
|
+
"directory": "packages/core"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/m-de-graaff/unison#readme",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": ">=19"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@testing-library/react": "^16.3.3",
|
|
28
|
+
"@types/react": "~19.3.0",
|
|
29
|
+
"@types/react-dom": "~19.3.0",
|
|
30
|
+
"@unison-ui/tsconfig": "0.0.0",
|
|
31
|
+
"@vitest/coverage-v8": "^5.1.1",
|
|
32
|
+
"jsdom": "^31.0.1",
|
|
33
|
+
"react": "19.3.0",
|
|
34
|
+
"react-dom": "19.3.0",
|
|
35
|
+
"tsdown": "^0.23.7",
|
|
36
|
+
"typescript": "7.0.2",
|
|
37
|
+
"vitest": "^5.1.1"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"provenance": true
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsdown",
|
|
45
|
+
"dev": "tsdown --watch --no-clean",
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"test": "vitest run --coverage"
|
|
48
|
+
}
|
|
49
|
+
}
|