@lattice-ui/checkbox 0.1.1 → 0.3.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/out/index.d.ts +7 -2
- package/out/init.luau +11 -6
- package/package.json +8 -4
- package/src/Checkbox/CheckboxIndicator.tsx +0 -34
- package/src/Checkbox/CheckboxRoot.tsx +0 -86
- package/src/Checkbox/context.ts +0 -6
- package/src/Checkbox/types.ts +0 -28
- package/src/index.ts +0 -3
- package/tsconfig.json +0 -16
- package/tsconfig.typecheck.json +0 -25
package/out/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { CheckboxIndicator } from "./Checkbox/CheckboxIndicator";
|
|
2
|
+
import { CheckboxRoot } from "./Checkbox/CheckboxRoot";
|
|
3
|
+
export declare const Checkbox: {
|
|
4
|
+
readonly Root: typeof CheckboxRoot;
|
|
5
|
+
readonly Indicator: typeof CheckboxIndicator;
|
|
6
|
+
};
|
|
7
|
+
export { CheckboxIndicator, CheckboxRoot };
|
|
3
8
|
export type { CheckboxContextValue, CheckboxIndicatorProps, CheckboxProps, CheckedState } from "./Checkbox/types";
|
package/out/init.luau
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
-- Compiled with roblox-ts v3.0.0
|
|
2
2
|
local TS = _G[script]
|
|
3
|
-
local
|
|
4
|
-
|
|
5
|
-
local
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
local CheckboxIndicator = TS.import(script, script, "Checkbox", "CheckboxIndicator").CheckboxIndicator
|
|
4
|
+
local CheckboxRoot = TS.import(script, script, "Checkbox", "CheckboxRoot").CheckboxRoot
|
|
5
|
+
local Checkbox = {
|
|
6
|
+
Root = CheckboxRoot,
|
|
7
|
+
Indicator = CheckboxIndicator,
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
Checkbox = Checkbox,
|
|
11
|
+
CheckboxIndicator = CheckboxIndicator,
|
|
12
|
+
CheckboxRoot = CheckboxRoot,
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lattice-ui/checkbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "out/init.luau",
|
|
6
6
|
"types": "out/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"out",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
7
11
|
"dependencies": {
|
|
8
|
-
"@lattice-ui/core": "0.
|
|
12
|
+
"@lattice-ui/core": "0.3.0"
|
|
9
13
|
},
|
|
10
14
|
"devDependencies": {
|
|
11
15
|
"@rbxts/react": "17.3.7-ts.1",
|
|
@@ -17,7 +21,7 @@
|
|
|
17
21
|
},
|
|
18
22
|
"scripts": {
|
|
19
23
|
"build": "rbxtsc -p tsconfig.json",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
24
|
+
"typecheck": "tsc -p tsconfig.typecheck.json",
|
|
25
|
+
"watch": "rbxtsc -p tsconfig.json -w"
|
|
22
26
|
}
|
|
23
27
|
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { React, Slot } from "@lattice-ui/core";
|
|
2
|
-
import { useCheckboxContext } from "./context";
|
|
3
|
-
import type { CheckboxIndicatorProps } from "./types";
|
|
4
|
-
|
|
5
|
-
export function CheckboxIndicator(props: CheckboxIndicatorProps) {
|
|
6
|
-
const checkboxContext = useCheckboxContext();
|
|
7
|
-
const visible = checkboxContext.checked !== false;
|
|
8
|
-
const forceMount = props.forceMount === true;
|
|
9
|
-
|
|
10
|
-
if (!visible && !forceMount) {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const child = props.children;
|
|
15
|
-
|
|
16
|
-
if (props.asChild) {
|
|
17
|
-
if (!React.isValidElement(child)) {
|
|
18
|
-
error("[CheckboxIndicator] `asChild` requires a child element.");
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return <Slot Visible={visible}>{child}</Slot>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<frame
|
|
26
|
-
BackgroundColor3={Color3.fromRGB(240, 244, 252)}
|
|
27
|
-
BorderSizePixel={0}
|
|
28
|
-
Size={UDim2.fromOffset(12, 12)}
|
|
29
|
-
Visible={visible}
|
|
30
|
-
>
|
|
31
|
-
{child}
|
|
32
|
-
</frame>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { React, Slot, useControllableState } from "@lattice-ui/core";
|
|
2
|
-
import { CheckboxContextProvider } from "./context";
|
|
3
|
-
import type { CheckboxProps, CheckedState } from "./types";
|
|
4
|
-
|
|
5
|
-
function getNextCheckedState(checked: CheckedState) {
|
|
6
|
-
if (checked === "indeterminate") {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return !checked;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function CheckboxRoot(props: CheckboxProps) {
|
|
14
|
-
const [checked, setCheckedState] = useControllableState<CheckedState>({
|
|
15
|
-
value: props.checked,
|
|
16
|
-
defaultValue: props.defaultChecked ?? false,
|
|
17
|
-
onChange: props.onCheckedChange,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const disabled = props.disabled === true;
|
|
21
|
-
const required = props.required === true;
|
|
22
|
-
|
|
23
|
-
const setChecked = React.useCallback(
|
|
24
|
-
(nextChecked: CheckedState) => {
|
|
25
|
-
if (disabled) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
setCheckedState(nextChecked);
|
|
30
|
-
},
|
|
31
|
-
[disabled, setCheckedState],
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
const toggle = React.useCallback(() => {
|
|
35
|
-
if (disabled) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
setCheckedState(getNextCheckedState(checked));
|
|
40
|
-
}, [checked, disabled, setCheckedState]);
|
|
41
|
-
|
|
42
|
-
const contextValue = React.useMemo(
|
|
43
|
-
() => ({
|
|
44
|
-
checked,
|
|
45
|
-
setChecked,
|
|
46
|
-
disabled,
|
|
47
|
-
required,
|
|
48
|
-
}),
|
|
49
|
-
[checked, disabled, required, setChecked],
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
const child = props.children;
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<CheckboxContextProvider value={contextValue}>
|
|
56
|
-
{props.asChild ? (
|
|
57
|
-
(() => {
|
|
58
|
-
if (!React.isValidElement(child)) {
|
|
59
|
-
error("[Checkbox] `asChild` requires a child element.");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return (
|
|
63
|
-
<Slot Active={!disabled} Event={{ Activated: toggle }} Selectable={!disabled}>
|
|
64
|
-
{child}
|
|
65
|
-
</Slot>
|
|
66
|
-
);
|
|
67
|
-
})()
|
|
68
|
-
) : (
|
|
69
|
-
<textbutton
|
|
70
|
-
Active={!disabled}
|
|
71
|
-
AutoButtonColor={false}
|
|
72
|
-
BackgroundColor3={checked !== false ? Color3.fromRGB(88, 142, 255) : Color3.fromRGB(59, 66, 84)}
|
|
73
|
-
BorderSizePixel={0}
|
|
74
|
-
Event={{ Activated: toggle }}
|
|
75
|
-
Selectable={!disabled}
|
|
76
|
-
Size={UDim2.fromOffset(160, 36)}
|
|
77
|
-
Text={checked === "indeterminate" ? "Indeterminate" : checked ? "Checked" : "Unchecked"}
|
|
78
|
-
TextColor3={disabled ? Color3.fromRGB(145, 152, 168) : Color3.fromRGB(240, 244, 252)}
|
|
79
|
-
TextSize={15}
|
|
80
|
-
>
|
|
81
|
-
{child}
|
|
82
|
-
</textbutton>
|
|
83
|
-
)}
|
|
84
|
-
</CheckboxContextProvider>
|
|
85
|
-
);
|
|
86
|
-
}
|
package/src/Checkbox/context.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { createStrictContext } from "@lattice-ui/core";
|
|
2
|
-
import type { CheckboxContextValue } from "./types";
|
|
3
|
-
|
|
4
|
-
const [CheckboxContextProvider, useCheckboxContext] = createStrictContext<CheckboxContextValue>("Checkbox");
|
|
5
|
-
|
|
6
|
-
export { CheckboxContextProvider, useCheckboxContext };
|
package/src/Checkbox/types.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type React from "@rbxts/react";
|
|
2
|
-
|
|
3
|
-
export type CheckedState = boolean | "indeterminate";
|
|
4
|
-
|
|
5
|
-
export type CheckboxSetChecked = (checked: CheckedState) => void;
|
|
6
|
-
|
|
7
|
-
export type CheckboxContextValue = {
|
|
8
|
-
checked: CheckedState;
|
|
9
|
-
setChecked: CheckboxSetChecked;
|
|
10
|
-
disabled: boolean;
|
|
11
|
-
required: boolean;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type CheckboxProps = {
|
|
15
|
-
checked?: CheckedState;
|
|
16
|
-
defaultChecked?: CheckedState;
|
|
17
|
-
onCheckedChange?: (checked: CheckedState) => void;
|
|
18
|
-
disabled?: boolean;
|
|
19
|
-
required?: boolean;
|
|
20
|
-
asChild?: boolean;
|
|
21
|
-
children?: React.ReactNode;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type CheckboxIndicatorProps = {
|
|
25
|
-
forceMount?: boolean;
|
|
26
|
-
asChild?: boolean;
|
|
27
|
-
children?: React.ReactNode;
|
|
28
|
-
};
|
package/src/index.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
}
|
package/tsconfig.typecheck.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
}
|