@lattice-ui/switch 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 +6 -2
- package/out/init.luau +9 -6
- package/package.json +8 -4
- package/src/Switch/SwitchRoot.tsx +0 -76
- package/src/Switch/SwitchThumb.tsx +0 -34
- package/src/Switch/context.ts +0 -6
- package/src/Switch/types.ts +0 -24
- 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,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { SwitchRoot } from "./Switch/SwitchRoot";
|
|
2
|
+
import { SwitchThumb } from "./Switch/SwitchThumb";
|
|
3
|
+
export declare const Switch: {
|
|
4
|
+
readonly Root: typeof SwitchRoot;
|
|
5
|
+
readonly Thumb: typeof SwitchThumb;
|
|
6
|
+
};
|
|
3
7
|
export type { SwitchContextValue, SwitchProps, SwitchThumbProps } from "./Switch/types";
|
package/out/init.luau
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
-- Compiled with roblox-ts v3.0.0
|
|
2
2
|
local TS = _G[script]
|
|
3
|
-
local
|
|
4
|
-
local
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
local SwitchRoot = TS.import(script, script, "Switch", "SwitchRoot").SwitchRoot
|
|
4
|
+
local SwitchThumb = TS.import(script, script, "Switch", "SwitchThumb").SwitchThumb
|
|
5
|
+
local Switch = {
|
|
6
|
+
Root = SwitchRoot,
|
|
7
|
+
Thumb = SwitchThumb,
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
Switch = Switch,
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lattice-ui/switch",
|
|
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,76 +0,0 @@
|
|
|
1
|
-
import { React, Slot, useControllableState } from "@lattice-ui/core";
|
|
2
|
-
import { SwitchContextProvider } from "./context";
|
|
3
|
-
import type { SwitchProps } from "./types";
|
|
4
|
-
|
|
5
|
-
export function SwitchRoot(props: SwitchProps) {
|
|
6
|
-
const [checked, setCheckedState] = useControllableState<boolean>({
|
|
7
|
-
value: props.checked,
|
|
8
|
-
defaultValue: props.defaultChecked ?? false,
|
|
9
|
-
onChange: props.onCheckedChange,
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
const disabled = props.disabled === true;
|
|
13
|
-
|
|
14
|
-
const setChecked = React.useCallback(
|
|
15
|
-
(nextChecked: boolean) => {
|
|
16
|
-
if (disabled) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
setCheckedState(nextChecked);
|
|
21
|
-
},
|
|
22
|
-
[disabled, setCheckedState],
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
const toggle = React.useCallback(() => {
|
|
26
|
-
if (disabled) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
setCheckedState(!checked);
|
|
31
|
-
}, [checked, disabled, setCheckedState]);
|
|
32
|
-
|
|
33
|
-
const contextValue = React.useMemo(
|
|
34
|
-
() => ({
|
|
35
|
-
checked,
|
|
36
|
-
setChecked,
|
|
37
|
-
disabled,
|
|
38
|
-
}),
|
|
39
|
-
[checked, disabled, setChecked],
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const child = props.children;
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<SwitchContextProvider value={contextValue}>
|
|
46
|
-
{props.asChild ? (
|
|
47
|
-
(() => {
|
|
48
|
-
if (!React.isValidElement(child)) {
|
|
49
|
-
error("[Switch] `asChild` requires a child element.");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<Slot Active={!disabled} Event={{ Activated: toggle }} Selectable={!disabled}>
|
|
54
|
-
{child}
|
|
55
|
-
</Slot>
|
|
56
|
-
);
|
|
57
|
-
})()
|
|
58
|
-
) : (
|
|
59
|
-
<textbutton
|
|
60
|
-
Active={!disabled}
|
|
61
|
-
AutoButtonColor={false}
|
|
62
|
-
BackgroundColor3={checked ? Color3.fromRGB(86, 141, 255) : Color3.fromRGB(66, 73, 91)}
|
|
63
|
-
BorderSizePixel={0}
|
|
64
|
-
Event={{ Activated: toggle }}
|
|
65
|
-
Selectable={!disabled}
|
|
66
|
-
Size={UDim2.fromOffset(160, 36)}
|
|
67
|
-
Text={checked ? "On" : "Off"}
|
|
68
|
-
TextColor3={disabled ? Color3.fromRGB(145, 152, 168) : Color3.fromRGB(240, 244, 252)}
|
|
69
|
-
TextSize={15}
|
|
70
|
-
>
|
|
71
|
-
{child}
|
|
72
|
-
</textbutton>
|
|
73
|
-
)}
|
|
74
|
-
</SwitchContextProvider>
|
|
75
|
-
);
|
|
76
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { React, Slot } from "@lattice-ui/core";
|
|
2
|
-
import { useSwitchContext } from "./context";
|
|
3
|
-
import type { SwitchThumbProps } from "./types";
|
|
4
|
-
|
|
5
|
-
export function SwitchThumb(props: SwitchThumbProps) {
|
|
6
|
-
const switchContext = useSwitchContext();
|
|
7
|
-
const visible = switchContext.checked;
|
|
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("[SwitchThumb] `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(16, 16)}
|
|
29
|
-
Visible={visible}
|
|
30
|
-
>
|
|
31
|
-
{child}
|
|
32
|
-
</frame>
|
|
33
|
-
);
|
|
34
|
-
}
|
package/src/Switch/context.ts
DELETED
package/src/Switch/types.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type React from "@rbxts/react";
|
|
2
|
-
|
|
3
|
-
export type SwitchSetChecked = (checked: boolean) => void;
|
|
4
|
-
|
|
5
|
-
export type SwitchContextValue = {
|
|
6
|
-
checked: boolean;
|
|
7
|
-
setChecked: SwitchSetChecked;
|
|
8
|
-
disabled: boolean;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type SwitchProps = {
|
|
12
|
-
checked?: boolean;
|
|
13
|
-
defaultChecked?: boolean;
|
|
14
|
-
onCheckedChange?: (checked: boolean) => void;
|
|
15
|
-
disabled?: boolean;
|
|
16
|
-
asChild?: boolean;
|
|
17
|
-
children?: React.ReactNode;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export type SwitchThumbProps = {
|
|
21
|
-
forceMount?: boolean;
|
|
22
|
-
asChild?: boolean;
|
|
23
|
-
children?: React.ReactNode;
|
|
24
|
-
};
|
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
|
-
}
|