Skip to content

Commit

Permalink
add text entry to settings UI
Browse files Browse the repository at this point in the history
  • Loading branch information
x37v committed Jun 6, 2024
1 parent 77ca89d commit 8170e25
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const getSettingUITypeForConfig = (config: ConfigRecord): SettingsItemType => {

switch (config.oscType) {
case OSCQueryValueType.String:
return SettingsItemType.Select;
return config.options ? SettingsItemType.Select : SettingsItemType.Text;
case OSCQueryValueType.True:
case OSCQueryValueType.False:
return SettingsItemType.OnOff;
Expand Down
27 changes: 24 additions & 3 deletions src/components/settings/item.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Group, SegmentedControl, Switch, NumberInput, Select, ActionIcon } from "@mantine/core";
import { Group, SegmentedControl, Switch, NumberInput, TextInput, Select, ActionIcon } from "@mantine/core";
import { ChangeEvent, FunctionComponent, ReactNode, memo } from "react";
import classes from "./settings.module.css";
import { SettingTarget } from "../../lib/constants";
Expand All @@ -10,7 +10,8 @@ export enum SettingsItemType {
OnOff,
Select,
Switch,
Numeric
Numeric,
Text
}

export type SettingsItemValue = string | number | boolean;
Expand All @@ -34,6 +35,11 @@ export interface SettingsNumericProps extends BaseSettingsItemProps {
value: number;
}

export interface SettingsTextProps extends BaseSettingsItemProps {
type: SettingsItemType.Text;
value: number;
}

export interface SettingsOnOffProps extends BaseSettingsItemProps {
type: SettingsItemType.OnOff,
value: boolean;
Expand All @@ -51,7 +57,7 @@ export interface SettingsToggleProps extends BaseSettingsItemProps {
value: string;
}

export type SettingsItemProps = SettingsNumericProps | SettingsOnOffProps | SettingsSelectProps | SettingsToggleProps;
export type SettingsItemProps = SettingsNumericProps | SettingsTextProps | SettingsOnOffProps | SettingsSelectProps | SettingsToggleProps;

const SettingsNumericInput = ({ onChange, min, max, name, target, value }: Pick<SettingsNumericProps, "max" | "min" | "name" | "onChange" | "target" | "value">) => {
return (
Expand All @@ -65,6 +71,16 @@ const SettingsNumericInput = ({ onChange, min, max, name, target, value }: Pick<
);
};

const SettingsTextInput = ({ onChange, name, target, value }: Pick<SettingsTextProps, "name" | "onChange" | "target" | "value">) => {
return (
<TextInput
onChange={ (ev: ChangeEvent<HTMLInputElement>) => onChange(target, name, ev.currentTarget.value) }
name={ name }
value={ value }
/>
);
};

const SettingOnOffInput = ({ onChange, name, target, value }: Pick<SettingsOnOffProps, "name" | "onChange" | "target" | "value">) => {
return (
<Switch
Expand Down Expand Up @@ -110,6 +126,11 @@ export const SettingsItem: FunctionComponent<BaseSettingsItemProps> = memo(funct
el = <SettingsNumericInput { ...commonProps } max={ compProps.max } min={ compProps.min } value={ compProps.value } />;
break;
}
case SettingsItemType.Text: {
const compProps = props as SettingsTextProps;
el = <SettingsTextInput { ...commonProps } value={ compProps.value } />;
break;
}
case SettingsItemType.OnOff: {
const compProps = props as SettingsOnOffProps;
el = <SettingOnOffInput { ...commonProps } value={ compProps.value } />;
Expand Down

0 comments on commit 8170e25

Please sign in to comment.