Files
ox_lib/package/client/resource/interface/input.ts

163 lines
3.3 KiB
TypeScript
Raw Normal View History

import type { IconName, IconPrefix } from '@fortawesome/fontawesome-common-types';
2022-09-14 13:50:32 +02:00
type Icon = IconName | [IconName, IconPrefix];
interface BaseInput {
type?:
2023-02-15 13:51:46 +01:00
| 'input'
| 'number'
| 'checkbox'
| 'select'
| 'multi-select'
| 'slider'
| 'color'
| 'date'
| 'date-range'
| 'time'
| 'textarea';
2022-09-14 13:50:32 +02:00
label: string;
}
// Should really be improved at some point to only display properties depending on the input type
interface InputProps extends BaseInput {
type?: 'input';
description?: string;
placeholder?: string;
icon?: Icon;
required?: boolean;
disabled?: boolean;
default?: string;
2022-09-14 13:50:32 +02:00
password?: boolean;
min?: number;
max?: number;
}
interface NumberProps extends BaseInput {
type: 'number';
description?: string;
2022-09-14 13:50:32 +02:00
placeholder?: string;
icon?: Icon;
required?: boolean;
disabled?: boolean;
default?: number;
min?: number;
max?: number;
precision?: number;
step?: number;
}
interface CheckboxProps extends BaseInput {
type: 'checkbox';
2022-09-14 13:50:32 +02:00
checked?: boolean;
disabled?: boolean;
required?: boolean;
}
interface SelectProps extends BaseInput {
type: 'select' | 'multi-select';
options: { value: string; label?: string }[];
description?: string;
placeholder?: string;
icon?: Icon;
required?: boolean;
disabled?: boolean;
default?: string | string[];
clearable?: boolean;
searchable?: boolean;
}
interface SliderProps extends BaseInput {
type: 'slider';
placeholder?: string;
icon?: Icon;
required?: boolean;
disabled?: boolean;
default?: number;
2022-09-14 13:50:32 +02:00
min?: number;
max?: number;
step?: number;
}
interface ColorProps extends BaseInput {
type: 'color';
description?: string;
placeholder?: string;
icon?: Icon;
required?: boolean;
disabled?: boolean;
default?: string;
format?: 'hex' | 'hexa' | 'rgb' | 'rgba' | 'hsl' | 'hsla';
}
interface DateProps extends BaseInput {
type: 'date';
description?: string;
icon?: Icon;
required?: boolean;
disabled?: boolean;
default?: string | true;
format?: string;
returnString?: boolean;
clearable?: boolean;
min?: string;
max?: string;
}
interface DateRangeProps extends BaseInput {
type: 'date-range';
description?: string;
icon?: Icon;
2023-02-15 13:51:46 +01:00
required?: boolean;
disabled?: boolean;
default?: [string, string];
2023-02-15 13:51:46 +01:00
format?: string;
returnString?: boolean;
clearable?: boolean;
}
interface TimeProps extends BaseInput {
type: 'time';
description?: string;
icon?: Icon;
required?: boolean;
disabled?: boolean;
default?: string;
format?: '12' | '24';
clearable?: boolean;
}
interface TextAreaProps extends BaseInput {
type: 'textarea';
description?: string;
placeholder?: string;
icon?: Icon;
required?: boolean;
disabled?: boolean;
default?: number;
min?: number;
max?: number;
autosize?: boolean;
2022-09-14 13:50:32 +02:00
}
type RowInput =
| InputProps
| NumberProps
| CheckboxProps
| SelectProps
| SliderProps
| ColorProps
| DateProps
| DateRangeProps
| TimeProps;
2022-09-14 13:50:32 +02:00
type inputDialog = (
heading: string,
rows: string[] | RowInput[],
2023-02-15 13:51:46 +01:00
options: {
allowCancel?: boolean;
}
2022-09-14 13:50:32 +02:00
) => Promise<Array<string | number | boolean> | undefined>;
export const inputDialog: inputDialog = async (heading, rows) => await exports.ox_lib.inputDialog(heading, rows);
export const closeInputDialog = () => exports.ox_lib.closeInputDialog();