mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 07:55:52 +01:00
Add Select for option types
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
Text,
|
Text,
|
||||||
NumberInput,
|
NumberInput,
|
||||||
Slider,
|
Slider,
|
||||||
|
Select,
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { ContextModalProps } from '@mantine/modals';
|
import { ContextModalProps } from '@mantine/modals';
|
||||||
import { IconAlertTriangle } from '@tabler/icons';
|
import { IconAlertTriangle } from '@tabler/icons';
|
||||||
@@ -101,15 +102,7 @@ export const WidgetsEditModal = ({
|
|||||||
</Alert>
|
</Alert>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return WidgetOptionTypeSwitch(
|
return WidgetOptionTypeSwitch(option, index, t, key, value, handleChange);
|
||||||
option,
|
|
||||||
index,
|
|
||||||
t,
|
|
||||||
key,
|
|
||||||
value,
|
|
||||||
handleChange,
|
|
||||||
getMutliselectData
|
|
||||||
);
|
|
||||||
})}
|
})}
|
||||||
<Group position="right">
|
<Group position="right">
|
||||||
<Button onClick={() => context.closeModal(id)} variant="light">
|
<Button onClick={() => context.closeModal(id)} variant="light">
|
||||||
@@ -130,8 +123,7 @@ function WidgetOptionTypeSwitch(
|
|||||||
t: any,
|
t: any,
|
||||||
key: string,
|
key: string,
|
||||||
value: string | number | boolean | string[],
|
value: string | number | boolean | string[],
|
||||||
handleChange: (key: string, value: IntegrationOptionsValueType) => void,
|
handleChange: (key: string, value: IntegrationOptionsValueType) => void
|
||||||
getMutliselectData: (option: string) => any
|
|
||||||
) {
|
) {
|
||||||
const { primaryColor, secondaryColor } = useColorTheme();
|
const { primaryColor, secondaryColor } = useColorTheme();
|
||||||
switch (option.type) {
|
switch (option.type) {
|
||||||
@@ -159,9 +151,22 @@ function WidgetOptionTypeSwitch(
|
|||||||
<MultiSelect
|
<MultiSelect
|
||||||
color={primaryColor}
|
color={primaryColor}
|
||||||
key={`${option.type}-${index}`}
|
key={`${option.type}-${index}`}
|
||||||
data={getMutliselectData(key)}
|
data={option.data}
|
||||||
label={t(`descriptor.settings.${key}.label`)}
|
label={t(`descriptor.settings.${key}.label`)}
|
||||||
value={value as string[]}
|
value={value as string[]}
|
||||||
|
defaultValue={option.defaultValue}
|
||||||
|
onChange={(v) => handleChange(key, v)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
case 'select':
|
||||||
|
return (
|
||||||
|
<Select
|
||||||
|
color={primaryColor}
|
||||||
|
key={`${option.type}-${index}`}
|
||||||
|
defaultValue={option.defaultValue}
|
||||||
|
data={option.data}
|
||||||
|
label={t(`descriptor.settings.${key}.label`)}
|
||||||
|
value={value as string}
|
||||||
onChange={(v) => handleChange(key, v)}
|
onChange={(v) => handleChange(key, v)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -34,13 +34,27 @@ export type IWidgetOptionValue =
|
|||||||
| ISwitchOptionValue
|
| ISwitchOptionValue
|
||||||
| ITextInputOptionValue
|
| ITextInputOptionValue
|
||||||
| ISliderInputOptionValue
|
| ISliderInputOptionValue
|
||||||
|
| ISelectOptionValue
|
||||||
| INumberInputOptionValue;
|
| INumberInputOptionValue;
|
||||||
|
|
||||||
|
// Interface for data type
|
||||||
|
interface DataType {
|
||||||
|
label: string
|
||||||
|
value: string
|
||||||
|
}
|
||||||
|
|
||||||
// will show a multi-select with specified data
|
// will show a multi-select with specified data
|
||||||
export type IMultiSelectOptionValue = {
|
export type IMultiSelectOptionValue = {
|
||||||
type: 'multi-select';
|
type: 'multi-select';
|
||||||
defaultValue: string[];
|
defaultValue: string[];
|
||||||
data: string[];
|
data: DataType[];
|
||||||
|
};
|
||||||
|
|
||||||
|
// will show a multi-select with specified data
|
||||||
|
export type ISelectOptionValue = {
|
||||||
|
type: 'select';
|
||||||
|
defaultValue: string;
|
||||||
|
data: DataType[];
|
||||||
};
|
};
|
||||||
|
|
||||||
// will show a switch
|
// will show a switch
|
||||||
|
|||||||
Reference in New Issue
Block a user