@lattice-ui/system 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/out/density/DensityProvider.d.ts +4 -0
- package/out/density/DensityProvider.luau +62 -0
- package/out/density/density.d.ts +12 -0
- package/out/density/density.luau +99 -0
- package/out/density/types.d.ts +12 -0
- package/out/density/types.luau +2 -0
- package/out/index.d.ts +12 -0
- package/out/init.luau +17 -0
- package/out/layout/Row.d.ts +3 -0
- package/out/layout/Row.luau +13 -0
- package/out/layout/Stack.d.ts +3 -0
- package/out/layout/Stack.luau +117 -0
- package/out/layout/space.d.ts +11 -0
- package/out/layout/space.luau +94 -0
- package/out/layout/types.d.ts +29 -0
- package/out/layout/types.luau +2 -0
- package/out/surface/surface.d.ts +10 -0
- package/out/surface/surface.luau +48 -0
- package/out/surface/surfacePrimitive.d.ts +17 -0
- package/out/surface/surfacePrimitive.luau +55 -0
- package/out/system/SystemProvider.d.ts +4 -0
- package/out/system/SystemProvider.luau +43 -0
- package/out/system/baseThemeContext.d.ts +2 -0
- package/out/system/baseThemeContext.luau +10 -0
- package/out/system/systemThemeContext.d.ts +2 -0
- package/out/system/systemThemeContext.luau +10 -0
- package/out/system/types.d.ts +26 -0
- package/out/system/types.luau +2 -0
- package/package.json +20 -0
- package/src/density/DensityProvider.tsx +61 -0
- package/src/density/density.ts +102 -0
- package/src/density/types.ts +15 -0
- package/src/index.ts +22 -0
- package/src/layout/Row.tsx +7 -0
- package/src/layout/Stack.tsx +133 -0
- package/src/layout/space.ts +101 -0
- package/src/layout/types.ts +34 -0
- package/src/surface/surface.ts +45 -0
- package/src/surface/surfacePrimitive.tsx +59 -0
- package/src/system/SystemProvider.tsx +47 -0
- package/src/system/baseThemeContext.ts +5 -0
- package/src/system/systemThemeContext.ts +5 -0
- package/src/system/types.ts +29 -0
- package/tsconfig.json +16 -0
- package/tsconfig.typecheck.json +25 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { React } from "@lattice-ui/core";
|
|
2
|
+
import type { Sx } from "@lattice-ui/style";
|
|
3
|
+
import { mergeGuiProps, resolveSx, useTheme } from "@lattice-ui/style";
|
|
4
|
+
import type { SurfaceToken } from "./surface";
|
|
5
|
+
import { surface } from "./surface";
|
|
6
|
+
|
|
7
|
+
type StyleProps = React.Attributes & Record<string, unknown>;
|
|
8
|
+
|
|
9
|
+
export type SurfaceProps = {
|
|
10
|
+
tone?: SurfaceToken;
|
|
11
|
+
sx?: Sx<StyleProps>;
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
} & StyleProps;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Decorated surface host primitive.
|
|
17
|
+
* Unlike `surface()`, this renders instance-graph decoration via UICorner/UIStroke.
|
|
18
|
+
* Host border props are not the canonical border representation here.
|
|
19
|
+
* `asChild` is intentionally not supported in this milestone.
|
|
20
|
+
*/
|
|
21
|
+
export function Surface(props: SurfaceProps) {
|
|
22
|
+
const tone = props.tone ?? "surface";
|
|
23
|
+
const sx = props.sx;
|
|
24
|
+
const children = props.children;
|
|
25
|
+
|
|
26
|
+
const asChild = (props as { asChild?: unknown }).asChild;
|
|
27
|
+
if (asChild !== undefined) {
|
|
28
|
+
error("[Surface] `asChild` is not supported in M2.");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const restProps: StyleProps = {};
|
|
32
|
+
for (const [rawKey, value] of pairs(props as Record<string, unknown>)) {
|
|
33
|
+
if (!typeIs(rawKey, "string")) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (rawKey === "tone" || rawKey === "sx" || rawKey === "children" || rawKey === "asChild") {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
restProps[rawKey] = value;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const { theme } = useTheme();
|
|
45
|
+
const toneProps = resolveSx(surface<StyleProps>(tone), theme);
|
|
46
|
+
const sxProps = resolveSx(sx, theme);
|
|
47
|
+
const baseProps =
|
|
48
|
+
tone === "overlay" ? toneProps : mergeGuiProps(toneProps, { BorderSizePixel: 0 } as Partial<StyleProps>);
|
|
49
|
+
const mergedProps = mergeGuiProps(baseProps, sxProps, restProps);
|
|
50
|
+
const decorated = tone !== "overlay";
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<frame {...(mergedProps as Record<string, unknown>)}>
|
|
54
|
+
{decorated ? <uicorner CornerRadius={new UDim(0, theme.radius.lg)} /> : undefined}
|
|
55
|
+
{decorated ? <uistroke Color={theme.colors.border} Thickness={1} /> : undefined}
|
|
56
|
+
{children}
|
|
57
|
+
</frame>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { React, useControllableState } from "@lattice-ui/core";
|
|
2
|
+
import { defaultLightTheme } from "@lattice-ui/style";
|
|
3
|
+
import { DensityProvider } from "../density/DensityProvider";
|
|
4
|
+
import { SystemBaseThemeContextProvider } from "./baseThemeContext";
|
|
5
|
+
import { useSystemThemeContext } from "./systemThemeContext";
|
|
6
|
+
import type { SystemProviderProps, SystemThemeContextValue } from "./types";
|
|
7
|
+
|
|
8
|
+
export function SystemProvider(props: SystemProviderProps) {
|
|
9
|
+
// SystemProvider owns raw/base theme state. Density is applied in DensityProvider.
|
|
10
|
+
const [baseThemeValue, setBaseThemeValue] = useControllableState({
|
|
11
|
+
value: props.theme,
|
|
12
|
+
defaultValue: props.defaultTheme ?? defaultLightTheme,
|
|
13
|
+
onChange: props.onThemeChange,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const setBaseTheme = React.useCallback<SystemThemeContextValue["setBaseTheme"]>(
|
|
17
|
+
(nextTheme) => {
|
|
18
|
+
// Write-path contract: updates should target baseTheme, not resolved theme.
|
|
19
|
+
setBaseThemeValue(nextTheme);
|
|
20
|
+
},
|
|
21
|
+
[setBaseThemeValue],
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const baseThemeContextValue = React.useMemo(
|
|
25
|
+
() => ({
|
|
26
|
+
baseTheme: baseThemeValue,
|
|
27
|
+
setBaseTheme,
|
|
28
|
+
}),
|
|
29
|
+
[baseThemeValue, setBaseTheme],
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<SystemBaseThemeContextProvider value={baseThemeContextValue}>
|
|
34
|
+
<DensityProvider
|
|
35
|
+
defaultDensity={props.defaultDensity}
|
|
36
|
+
density={props.density}
|
|
37
|
+
onDensityChange={props.onDensityChange}
|
|
38
|
+
>
|
|
39
|
+
{props.children}
|
|
40
|
+
</DensityProvider>
|
|
41
|
+
</SystemBaseThemeContextProvider>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function useSystemTheme() {
|
|
46
|
+
return useSystemThemeContext();
|
|
47
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createStrictContext } from "@lattice-ui/core";
|
|
2
|
+
import type { SystemBaseThemeContextValue } from "./types";
|
|
3
|
+
|
|
4
|
+
export const [SystemBaseThemeContextProvider, useSystemBaseThemeContext] =
|
|
5
|
+
createStrictContext<SystemBaseThemeContextValue>("SystemBaseThemeContext");
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Theme } from "@lattice-ui/style";
|
|
2
|
+
import type React from "@rbxts/react";
|
|
3
|
+
import type { DensityToken } from "../density/types";
|
|
4
|
+
|
|
5
|
+
export type SystemProviderProps = {
|
|
6
|
+
theme?: Theme;
|
|
7
|
+
defaultTheme?: Theme;
|
|
8
|
+
onThemeChange?: (nextTheme: Theme) => void;
|
|
9
|
+
density?: DensityToken;
|
|
10
|
+
defaultDensity?: DensityToken;
|
|
11
|
+
onDensityChange?: (next: DensityToken) => void;
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type SystemThemeContextValue = {
|
|
16
|
+
/** Density-resolved theme for read usage in system-managed trees. */
|
|
17
|
+
theme: Theme;
|
|
18
|
+
/** Raw theme before density transforms. Writes must target this base theme. */
|
|
19
|
+
baseTheme: Theme;
|
|
20
|
+
density: DensityToken;
|
|
21
|
+
/** Use this to update the raw/base theme source. */
|
|
22
|
+
setBaseTheme: (next: Theme) => void;
|
|
23
|
+
setDensity: (next: DensityToken) => void;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type SystemBaseThemeContextValue = {
|
|
27
|
+
baseTheme: Theme;
|
|
28
|
+
setBaseTheme: (nextTheme: Theme) => void;
|
|
29
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "src",
|
|
5
|
+
"outDir": "out",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"typeRoots": [
|
|
8
|
+
"./node_modules/@rbxts",
|
|
9
|
+
"../../node_modules/@rbxts",
|
|
10
|
+
"./node_modules/@lattice-ui",
|
|
11
|
+
"../../node_modules/@lattice-ui"
|
|
12
|
+
],
|
|
13
|
+
"types": ["types", "compiler-types"]
|
|
14
|
+
},
|
|
15
|
+
"include": ["src"]
|
|
16
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"noEmit": true,
|
|
5
|
+
"baseUrl": "..",
|
|
6
|
+
"rootDir": "..",
|
|
7
|
+
"paths": {
|
|
8
|
+
"@lattice-ui/checkbox": ["checkbox/src/index.ts"],
|
|
9
|
+
"@lattice-ui/core": ["core/src/index.ts"],
|
|
10
|
+
"@lattice-ui/dialog": ["dialog/src/index.ts"],
|
|
11
|
+
"@lattice-ui/focus": ["focus/src/index.ts"],
|
|
12
|
+
"@lattice-ui/layer": ["layer/src/index.ts"],
|
|
13
|
+
"@lattice-ui/menu": ["menu/src/index.ts"],
|
|
14
|
+
"@lattice-ui/popover": ["popover/src/index.ts"],
|
|
15
|
+
"@lattice-ui/popper": ["popper/src/index.ts"],
|
|
16
|
+
"@lattice-ui/radio-group": ["radio-group/src/index.ts"],
|
|
17
|
+
"@lattice-ui/style": ["style/src/index.ts"],
|
|
18
|
+
"@lattice-ui/switch": ["switch/src/index.ts"],
|
|
19
|
+
"@lattice-ui/system": ["system/src/index.ts"],
|
|
20
|
+
"@lattice-ui/tabs": ["tabs/src/index.ts"],
|
|
21
|
+
"@lattice-ui/toggle-group": ["toggle-group/src/index.ts"],
|
|
22
|
+
"@lattice-ui/tooltip": ["tooltip/src/index.ts"]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|