@lattice-ui/radio-group 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.
@@ -0,0 +1,3 @@
1
+ import { React } from "@lattice-ui/core";
2
+ import type { RadioGroupIndicatorProps } from "./types";
3
+ export declare function RadioGroupIndicator(props: RadioGroupIndicatorProps): React.JSX.Element | undefined;
@@ -0,0 +1,32 @@
1
+ -- Compiled with roblox-ts v3.0.0
2
+ local TS = _G[script]
3
+ local _core = TS.import(script, TS.getModule(script, "@lattice-ui", "core").out)
4
+ local React = _core.React
5
+ local Slot = _core.Slot
6
+ local useRadioGroupItemContext = TS.import(script, script.Parent, "context").useRadioGroupItemContext
7
+ local function RadioGroupIndicator(props)
8
+ local radioGroupItemContext = useRadioGroupItemContext()
9
+ local visible = radioGroupItemContext.checked
10
+ local forceMount = props.forceMount == true
11
+ if not visible and not forceMount then
12
+ return nil
13
+ end
14
+ local child = props.children
15
+ if props.asChild then
16
+ if not React.isValidElement(child) then
17
+ error("[RadioGroupIndicator] `asChild` requires a child element.")
18
+ end
19
+ return React.createElement(Slot, {
20
+ Visible = visible,
21
+ }, child)
22
+ end
23
+ return React.createElement("frame", {
24
+ BackgroundColor3 = Color3.fromRGB(240, 244, 252),
25
+ BorderSizePixel = 0,
26
+ Size = UDim2.fromOffset(10, 10),
27
+ Visible = visible,
28
+ }, child)
29
+ end
30
+ return {
31
+ RadioGroupIndicator = RadioGroupIndicator,
32
+ }
@@ -0,0 +1,3 @@
1
+ import { React } from "@lattice-ui/core";
2
+ import type { RadioGroupItemProps } from "./types";
3
+ export declare function RadioGroupItem(props: RadioGroupItemProps): React.JSX.Element;
@@ -0,0 +1,76 @@
1
+ -- Compiled with roblox-ts v3.0.0
2
+ local TS = _G[script]
3
+ local _core = TS.import(script, TS.getModule(script, "@lattice-ui", "core").out)
4
+ local React = _core.React
5
+ local Slot = _core.Slot
6
+ local RovingFocusItem = TS.import(script, TS.getModule(script, "@lattice-ui", "focus").out).RovingFocusItem
7
+ local _context = TS.import(script, script.Parent, "context")
8
+ local RadioGroupItemContextProvider = _context.RadioGroupItemContextProvider
9
+ local useRadioGroupContext = _context.useRadioGroupContext
10
+ local function RadioGroupItem(props)
11
+ local radioGroupContext = useRadioGroupContext()
12
+ local disabled = radioGroupContext.disabled or props.disabled == true
13
+ local checked = radioGroupContext.value == props.value
14
+ local handleSelect = React.useCallback(function()
15
+ if disabled then
16
+ return nil
17
+ end
18
+ radioGroupContext.setValue(props.value)
19
+ end, { disabled, props.value, radioGroupContext })
20
+ local handleInputBegan = React.useCallback(function(_rbx, inputObject)
21
+ if disabled then
22
+ return nil
23
+ end
24
+ local keyCode = inputObject.KeyCode
25
+ if keyCode ~= Enum.KeyCode.Return and keyCode ~= Enum.KeyCode.Space then
26
+ return nil
27
+ end
28
+ radioGroupContext.setValue(props.value)
29
+ end, { disabled, props.value, radioGroupContext })
30
+ local eventHandlers = React.useMemo(function()
31
+ return {
32
+ Activated = handleSelect,
33
+ SelectionGained = handleSelect,
34
+ InputBegan = handleInputBegan,
35
+ }
36
+ end, { handleInputBegan, handleSelect })
37
+ local itemContextValue = React.useMemo(function()
38
+ return {
39
+ checked = checked,
40
+ disabled = disabled,
41
+ }
42
+ end, { checked, disabled })
43
+ return React.createElement(RadioGroupItemContextProvider, {
44
+ value = itemContextValue,
45
+ }, if props.asChild then ((function()
46
+ local child = props.children
47
+ if not child then
48
+ error("[RadioGroupItem] `asChild` requires a child element.")
49
+ end
50
+ return React.createElement(RovingFocusItem, {
51
+ asChild = true,
52
+ disabled = disabled,
53
+ }, React.createElement(Slot, {
54
+ Active = not disabled,
55
+ Event = eventHandlers,
56
+ Selectable = not disabled,
57
+ }, child))
58
+ end)()) else (React.createElement(RovingFocusItem, {
59
+ asChild = true,
60
+ disabled = disabled,
61
+ }, React.createElement("textbutton", {
62
+ Active = not disabled,
63
+ AutoButtonColor = false,
64
+ BackgroundColor3 = if checked then Color3.fromRGB(88, 142, 255) else Color3.fromRGB(47, 53, 68),
65
+ BorderSizePixel = 0,
66
+ Event = eventHandlers,
67
+ Selectable = not disabled,
68
+ Size = UDim2.fromOffset(170, 34),
69
+ Text = props.value,
70
+ TextColor3 = if disabled then Color3.fromRGB(139, 146, 160) else Color3.fromRGB(236, 241, 249),
71
+ TextSize = 15,
72
+ }, props.children))))
73
+ end
74
+ return {
75
+ RadioGroupItem = RadioGroupItem,
76
+ }
@@ -0,0 +1,3 @@
1
+ import { React } from "@lattice-ui/core";
2
+ import type { RadioGroupProps } from "./types";
3
+ export declare function RadioGroupRoot(props: RadioGroupProps): React.JSX.Element;
@@ -0,0 +1,56 @@
1
+ -- Compiled with roblox-ts v3.0.0
2
+ local TS = _G[script]
3
+ local _core = TS.import(script, TS.getModule(script, "@lattice-ui", "core").out)
4
+ local React = _core.React
5
+ local useControllableState = _core.useControllableState
6
+ local RovingFocusGroup = TS.import(script, TS.getModule(script, "@lattice-ui", "focus").out).RovingFocusGroup
7
+ local RadioGroupContextProvider = TS.import(script, script.Parent, "context").RadioGroupContextProvider
8
+ local function RadioGroupRoot(props)
9
+ local _binding = useControllableState({
10
+ value = props.value,
11
+ defaultValue = props.defaultValue,
12
+ onChange = function(nextValue)
13
+ if nextValue ~= nil then
14
+ local _result = props.onValueChange
15
+ if _result ~= nil then
16
+ _result(nextValue)
17
+ end
18
+ end
19
+ end,
20
+ })
21
+ local value = _binding[1]
22
+ local setValueState = _binding[2]
23
+ local disabled = props.disabled == true
24
+ local required = props.required == true
25
+ local _condition = props.loop
26
+ if _condition == nil then
27
+ _condition = true
28
+ end
29
+ local loop = _condition
30
+ local orientation = props.orientation or "vertical"
31
+ local setValue = React.useCallback(function(nextValue)
32
+ if disabled then
33
+ return nil
34
+ end
35
+ setValueState(nextValue)
36
+ end, { disabled, setValueState })
37
+ local contextValue = React.useMemo(function()
38
+ return {
39
+ value = value,
40
+ setValue = setValue,
41
+ disabled = disabled,
42
+ required = required,
43
+ }
44
+ end, { disabled, required, setValue, value })
45
+ return React.createElement(RadioGroupContextProvider, {
46
+ value = contextValue,
47
+ }, React.createElement(RovingFocusGroup, {
48
+ active = not disabled,
49
+ autoFocus = "none",
50
+ loop = loop,
51
+ orientation = orientation,
52
+ }, props.children))
53
+ end
54
+ return {
55
+ RadioGroupRoot = RadioGroupRoot,
56
+ }
@@ -0,0 +1,4 @@
1
+ import type { RadioGroupContextValue, RadioGroupItemContextValue } from "./types";
2
+ declare const RadioGroupContextProvider: import("@rbxts/react").Provider<RadioGroupContextValue | undefined>, useRadioGroupContext: () => RadioGroupContextValue;
3
+ declare const RadioGroupItemContextProvider: import("@rbxts/react").Provider<RadioGroupItemContextValue | undefined>, useRadioGroupItemContext: () => RadioGroupItemContextValue;
4
+ export { RadioGroupContextProvider, RadioGroupItemContextProvider, useRadioGroupContext, useRadioGroupItemContext };
@@ -0,0 +1,15 @@
1
+ -- Compiled with roblox-ts v3.0.0
2
+ local TS = _G[script]
3
+ local createStrictContext = TS.import(script, TS.getModule(script, "@lattice-ui", "core").out).createStrictContext
4
+ local _binding = createStrictContext("RadioGroup")
5
+ local RadioGroupContextProvider = _binding[1]
6
+ local useRadioGroupContext = _binding[2]
7
+ local _binding_1 = createStrictContext("RadioGroupItem")
8
+ local RadioGroupItemContextProvider = _binding_1[1]
9
+ local useRadioGroupItemContext = _binding_1[2]
10
+ return {
11
+ RadioGroupContextProvider = RadioGroupContextProvider,
12
+ RadioGroupItemContextProvider = RadioGroupItemContextProvider,
13
+ useRadioGroupContext = useRadioGroupContext,
14
+ useRadioGroupItemContext = useRadioGroupItemContext,
15
+ }
@@ -0,0 +1,34 @@
1
+ import type React from "@rbxts/react";
2
+ export type RadioGroupOrientation = "horizontal" | "vertical" | "both";
3
+ export type RadioGroupSetValue = (value: string) => void;
4
+ export type RadioGroupContextValue = {
5
+ value?: string;
6
+ setValue: RadioGroupSetValue;
7
+ disabled: boolean;
8
+ required: boolean;
9
+ };
10
+ export type RadioGroupItemContextValue = {
11
+ checked: boolean;
12
+ disabled: boolean;
13
+ };
14
+ export type RadioGroupProps = {
15
+ value?: string;
16
+ defaultValue?: string;
17
+ onValueChange?: (value: string) => void;
18
+ disabled?: boolean;
19
+ required?: boolean;
20
+ loop?: boolean;
21
+ orientation?: RadioGroupOrientation;
22
+ children?: React.ReactNode;
23
+ };
24
+ export type RadioGroupItemProps = {
25
+ value: string;
26
+ disabled?: boolean;
27
+ asChild?: boolean;
28
+ children?: React.ReactElement;
29
+ };
30
+ export type RadioGroupIndicatorProps = {
31
+ forceMount?: boolean;
32
+ asChild?: boolean;
33
+ children?: React.ReactNode;
34
+ };
@@ -0,0 +1,2 @@
1
+ -- Compiled with roblox-ts v3.0.0
2
+ return nil
package/out/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { RadioGroupIndicator } from "./RadioGroup/RadioGroupIndicator";
2
+ export { RadioGroupItem } from "./RadioGroup/RadioGroupItem";
3
+ export { RadioGroupRoot, RadioGroupRoot as RadioGroup } from "./RadioGroup/RadioGroupRoot";
4
+ export type { RadioGroupContextValue, RadioGroupIndicatorProps, RadioGroupItemContextValue, RadioGroupItemProps, RadioGroupProps, RadioGroupSetValue, } from "./RadioGroup/types";
package/out/init.luau ADDED
@@ -0,0 +1,9 @@
1
+ -- Compiled with roblox-ts v3.0.0
2
+ local TS = _G[script]
3
+ local exports = {}
4
+ exports.RadioGroupIndicator = TS.import(script, script, "RadioGroup", "RadioGroupIndicator").RadioGroupIndicator
5
+ exports.RadioGroupItem = TS.import(script, script, "RadioGroup", "RadioGroupItem").RadioGroupItem
6
+ local _RadioGroupRoot = TS.import(script, script, "RadioGroup", "RadioGroupRoot")
7
+ exports.RadioGroupRoot = _RadioGroupRoot.RadioGroupRoot
8
+ exports.RadioGroup = _RadioGroupRoot.RadioGroupRoot
9
+ return exports
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@lattice-ui/radio-group",
3
+ "version": "0.1.1",
4
+ "private": false,
5
+ "main": "out/init.luau",
6
+ "types": "out/index.d.ts",
7
+ "dependencies": {
8
+ "@lattice-ui/core": "0.1.1",
9
+ "@lattice-ui/focus": "0.1.1"
10
+ },
11
+ "devDependencies": {
12
+ "@rbxts/react": "17.3.7-ts.1",
13
+ "@rbxts/react-roblox": "17.3.7-ts.1"
14
+ },
15
+ "peerDependencies": {
16
+ "@rbxts/react": "^17",
17
+ "@rbxts/react-roblox": "^17"
18
+ },
19
+ "scripts": {
20
+ "build": "rbxtsc -p tsconfig.json",
21
+ "watch": "rbxtsc -p tsconfig.json -w",
22
+ "typecheck": "tsc -p tsconfig.typecheck.json"
23
+ }
24
+ }
@@ -0,0 +1,34 @@
1
+ import { React, Slot } from "@lattice-ui/core";
2
+ import { useRadioGroupItemContext } from "./context";
3
+ import type { RadioGroupIndicatorProps } from "./types";
4
+
5
+ export function RadioGroupIndicator(props: RadioGroupIndicatorProps) {
6
+ const radioGroupItemContext = useRadioGroupItemContext();
7
+ const visible = radioGroupItemContext.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("[RadioGroupIndicator] `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(10, 10)}
29
+ Visible={visible}
30
+ >
31
+ {child}
32
+ </frame>
33
+ );
34
+ }
@@ -0,0 +1,89 @@
1
+ import { React, Slot } from "@lattice-ui/core";
2
+ import { RovingFocusItem } from "@lattice-ui/focus";
3
+ import { RadioGroupItemContextProvider, useRadioGroupContext } from "./context";
4
+ import type { RadioGroupItemProps } from "./types";
5
+
6
+ export function RadioGroupItem(props: RadioGroupItemProps) {
7
+ const radioGroupContext = useRadioGroupContext();
8
+ const disabled = radioGroupContext.disabled || props.disabled === true;
9
+ const checked = radioGroupContext.value === props.value;
10
+
11
+ const handleSelect = React.useCallback(() => {
12
+ if (disabled) {
13
+ return;
14
+ }
15
+
16
+ radioGroupContext.setValue(props.value);
17
+ }, [disabled, props.value, radioGroupContext]);
18
+
19
+ const handleInputBegan = React.useCallback(
20
+ (_rbx: TextButton, inputObject: InputObject) => {
21
+ if (disabled) {
22
+ return;
23
+ }
24
+
25
+ const keyCode = inputObject.KeyCode;
26
+ if (keyCode !== Enum.KeyCode.Return && keyCode !== Enum.KeyCode.Space) {
27
+ return;
28
+ }
29
+
30
+ radioGroupContext.setValue(props.value);
31
+ },
32
+ [disabled, props.value, radioGroupContext],
33
+ );
34
+
35
+ const eventHandlers = React.useMemo(
36
+ () => ({
37
+ Activated: handleSelect,
38
+ SelectionGained: handleSelect,
39
+ InputBegan: handleInputBegan,
40
+ }),
41
+ [handleInputBegan, handleSelect],
42
+ );
43
+
44
+ const itemContextValue = React.useMemo(
45
+ () => ({
46
+ checked,
47
+ disabled,
48
+ }),
49
+ [checked, disabled],
50
+ );
51
+
52
+ return (
53
+ <RadioGroupItemContextProvider value={itemContextValue}>
54
+ {props.asChild ? (
55
+ (() => {
56
+ const child = props.children;
57
+ if (!child) {
58
+ error("[RadioGroupItem] `asChild` requires a child element.");
59
+ }
60
+
61
+ return (
62
+ <RovingFocusItem asChild disabled={disabled}>
63
+ <Slot Active={!disabled} Event={eventHandlers} Selectable={!disabled}>
64
+ {child}
65
+ </Slot>
66
+ </RovingFocusItem>
67
+ );
68
+ })()
69
+ ) : (
70
+ <RovingFocusItem asChild disabled={disabled}>
71
+ <textbutton
72
+ Active={!disabled}
73
+ AutoButtonColor={false}
74
+ BackgroundColor3={checked ? Color3.fromRGB(88, 142, 255) : Color3.fromRGB(47, 53, 68)}
75
+ BorderSizePixel={0}
76
+ Event={eventHandlers}
77
+ Selectable={!disabled}
78
+ Size={UDim2.fromOffset(170, 34)}
79
+ Text={props.value}
80
+ TextColor3={disabled ? Color3.fromRGB(139, 146, 160) : Color3.fromRGB(236, 241, 249)}
81
+ TextSize={15}
82
+ >
83
+ {props.children}
84
+ </textbutton>
85
+ </RovingFocusItem>
86
+ )}
87
+ </RadioGroupItemContextProvider>
88
+ );
89
+ }
@@ -0,0 +1,50 @@
1
+ import { React, useControllableState } from "@lattice-ui/core";
2
+ import { RovingFocusGroup } from "@lattice-ui/focus";
3
+ import { RadioGroupContextProvider } from "./context";
4
+ import type { RadioGroupProps } from "./types";
5
+
6
+ export function RadioGroupRoot(props: RadioGroupProps) {
7
+ const [value, setValueState] = useControllableState<string | undefined>({
8
+ value: props.value,
9
+ defaultValue: props.defaultValue,
10
+ onChange: (nextValue) => {
11
+ if (nextValue !== undefined) {
12
+ props.onValueChange?.(nextValue);
13
+ }
14
+ },
15
+ });
16
+
17
+ const disabled = props.disabled === true;
18
+ const required = props.required === true;
19
+ const loop = props.loop ?? true;
20
+ const orientation = props.orientation ?? "vertical";
21
+
22
+ const setValue = React.useCallback(
23
+ (nextValue: string) => {
24
+ if (disabled) {
25
+ return;
26
+ }
27
+
28
+ setValueState(nextValue);
29
+ },
30
+ [disabled, setValueState],
31
+ );
32
+
33
+ const contextValue = React.useMemo(
34
+ () => ({
35
+ value,
36
+ setValue,
37
+ disabled,
38
+ required,
39
+ }),
40
+ [disabled, required, setValue, value],
41
+ );
42
+
43
+ return (
44
+ <RadioGroupContextProvider value={contextValue}>
45
+ <RovingFocusGroup active={!disabled} autoFocus="none" loop={loop} orientation={orientation}>
46
+ {props.children}
47
+ </RovingFocusGroup>
48
+ </RadioGroupContextProvider>
49
+ );
50
+ }
@@ -0,0 +1,8 @@
1
+ import { createStrictContext } from "@lattice-ui/core";
2
+ import type { RadioGroupContextValue, RadioGroupItemContextValue } from "./types";
3
+
4
+ const [RadioGroupContextProvider, useRadioGroupContext] = createStrictContext<RadioGroupContextValue>("RadioGroup");
5
+ const [RadioGroupItemContextProvider, useRadioGroupItemContext] =
6
+ createStrictContext<RadioGroupItemContextValue>("RadioGroupItem");
7
+
8
+ export { RadioGroupContextProvider, RadioGroupItemContextProvider, useRadioGroupContext, useRadioGroupItemContext };
@@ -0,0 +1,41 @@
1
+ import type React from "@rbxts/react";
2
+
3
+ export type RadioGroupOrientation = "horizontal" | "vertical" | "both";
4
+
5
+ export type RadioGroupSetValue = (value: string) => void;
6
+
7
+ export type RadioGroupContextValue = {
8
+ value?: string;
9
+ setValue: RadioGroupSetValue;
10
+ disabled: boolean;
11
+ required: boolean;
12
+ };
13
+
14
+ export type RadioGroupItemContextValue = {
15
+ checked: boolean;
16
+ disabled: boolean;
17
+ };
18
+
19
+ export type RadioGroupProps = {
20
+ value?: string;
21
+ defaultValue?: string;
22
+ onValueChange?: (value: string) => void;
23
+ disabled?: boolean;
24
+ required?: boolean;
25
+ loop?: boolean;
26
+ orientation?: RadioGroupOrientation;
27
+ children?: React.ReactNode;
28
+ };
29
+
30
+ export type RadioGroupItemProps = {
31
+ value: string;
32
+ disabled?: boolean;
33
+ asChild?: boolean;
34
+ children?: React.ReactElement;
35
+ };
36
+
37
+ export type RadioGroupIndicatorProps = {
38
+ forceMount?: boolean;
39
+ asChild?: boolean;
40
+ children?: React.ReactNode;
41
+ };
package/src/index.ts ADDED
@@ -0,0 +1,11 @@
1
+ export { RadioGroupIndicator } from "./RadioGroup/RadioGroupIndicator";
2
+ export { RadioGroupItem } from "./RadioGroup/RadioGroupItem";
3
+ export { RadioGroupRoot, RadioGroupRoot as RadioGroup } from "./RadioGroup/RadioGroupRoot";
4
+ export type {
5
+ RadioGroupContextValue,
6
+ RadioGroupIndicatorProps,
7
+ RadioGroupItemContextValue,
8
+ RadioGroupItemProps,
9
+ RadioGroupProps,
10
+ RadioGroupSetValue,
11
+ } from "./RadioGroup/types";
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
+ }