uibee 2.7.17 → 2.7.18
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/dist/src/components/inputs/checkbox.d.ts +4 -9
- package/dist/src/components/inputs/checkbox.js +3 -2
- package/dist/src/components/inputs/input.d.ts +4 -11
- package/dist/src/components/inputs/input.js +11 -8
- package/dist/src/components/inputs/radio.d.ts +4 -10
- package/dist/src/components/inputs/radio.js +4 -2
- package/dist/src/components/inputs/range.d.ts +3 -11
- package/dist/src/components/inputs/range.js +4 -2
- package/dist/src/components/inputs/switch.d.ts +4 -9
- package/dist/src/components/inputs/switch.js +4 -3
- package/dist/src/components/inputs/textarea.d.ts +4 -11
- package/dist/src/components/inputs/textarea.js +5 -3
- package/package.json +1 -1
- package/src/components/inputs/checkbox.tsx +9 -25
- package/src/components/inputs/input.tsx +14 -36
- package/src/components/inputs/radio.tsx +10 -28
- package/src/components/inputs/range.tsx +8 -29
- package/src/components/inputs/switch.tsx +10 -27
- package/src/components/inputs/textarea.tsx +11 -32
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export type CheckboxProps = {
|
|
3
|
-
label?: string;
|
|
1
|
+
export type CheckboxProps = Omit<React.ComponentProps<'input'>, 'name'> & {
|
|
4
2
|
name: string;
|
|
5
|
-
|
|
6
|
-
onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
7
|
-
className?: string;
|
|
8
|
-
disabled?: boolean;
|
|
3
|
+
label?: string;
|
|
9
4
|
error?: string;
|
|
10
5
|
info?: string;
|
|
11
|
-
|
|
6
|
+
className?: string;
|
|
12
7
|
};
|
|
13
|
-
export default function Checkbox(
|
|
8
|
+
export default function Checkbox(props: CheckboxProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Check } from 'lucide-react';
|
|
3
3
|
import { SelectionWrapper } from './shared';
|
|
4
|
-
export default function Checkbox(
|
|
5
|
-
|
|
4
|
+
export default function Checkbox(props) {
|
|
5
|
+
const { name, label, error, info, className, ...inputProps } = props;
|
|
6
|
+
return (_jsx(SelectionWrapper, { label: label, name: name, required: inputProps.required, info: info, error: error, className: className, disabled: inputProps.disabled, children: _jsxs("div", { className: 'relative flex items-center', children: [_jsx("input", { ...inputProps, id: name, name: name, type: 'checkbox', className: `
|
|
6
7
|
peer appearance-none h-5 w-5 rounded border border-login-500 bg-login-500/50
|
|
7
8
|
checked:bg-login checked:border-login
|
|
8
9
|
focus:outline-none focus:ring-2 focus:ring-login/50
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export type InputProps = {
|
|
3
|
-
label?: string;
|
|
1
|
+
import { type JSX } from 'react';
|
|
2
|
+
export type InputProps = Omit<React.ComponentProps<'input'>, 'name'> & {
|
|
4
3
|
name: string;
|
|
5
|
-
|
|
6
|
-
placeholder?: string;
|
|
7
|
-
value?: string | number;
|
|
8
|
-
onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
4
|
+
label?: string;
|
|
9
5
|
error?: string;
|
|
10
6
|
className?: string;
|
|
11
|
-
disabled?: boolean;
|
|
12
|
-
required?: boolean;
|
|
13
7
|
icon?: JSX.Element;
|
|
14
8
|
info?: string;
|
|
15
|
-
multiple?: boolean;
|
|
16
9
|
};
|
|
17
|
-
export default function Input(
|
|
10
|
+
export default function Input(props: InputProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -4,20 +4,23 @@ import { Calendar, Clock } from 'lucide-react';
|
|
|
4
4
|
import { FieldWrapper } from './shared';
|
|
5
5
|
import DateTimePickerPopup from './shared/dateTimePickerPopup';
|
|
6
6
|
import useClickOutside from '../../hooks/useClickOutside';
|
|
7
|
-
export default function Input(
|
|
7
|
+
export default function Input(props) {
|
|
8
|
+
const { name, label, error, className, icon, info, ...inputProps } = props;
|
|
9
|
+
const { type = 'text', value } = inputProps;
|
|
8
10
|
const localRef = useRef(null);
|
|
9
11
|
const [isOpen, setIsOpen] = useState(false);
|
|
10
12
|
const containerRef = useClickOutside(() => setIsOpen(false));
|
|
11
13
|
const isDateType = ['date', 'datetime-local', 'time'].includes(type);
|
|
12
14
|
function handleIconClick() {
|
|
13
|
-
if (isDateType && !disabled) {
|
|
15
|
+
if (isDateType && !inputProps.disabled) {
|
|
14
16
|
setIsOpen(!isOpen);
|
|
15
17
|
}
|
|
16
|
-
else if (localRef.current && !disabled) {
|
|
18
|
+
else if (localRef.current && !inputProps.disabled) {
|
|
17
19
|
localRef.current.focus();
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
function handleDateChange(date) {
|
|
23
|
+
const onChange = inputProps.onChange;
|
|
21
24
|
if (!onChange)
|
|
22
25
|
return;
|
|
23
26
|
const pad = (n) => n.toString().padStart(2, '0');
|
|
@@ -61,10 +64,10 @@ export default function Input({ label, name, type = 'text', placeholder, value,
|
|
|
61
64
|
const date = new Date(value);
|
|
62
65
|
return isNaN(date.getTime()) ? null : date;
|
|
63
66
|
}
|
|
64
|
-
return (_jsx(FieldWrapper, { label: label, name: name, required: required, info: info, error: error, className: className, children: _jsxs("div", { className: 'relative flex items-center', ref: containerRef, children: [displayIcon && (_jsx("div", { className: `
|
|
67
|
+
return (_jsx(FieldWrapper, { label: label, name: name, required: inputProps.required, info: info, error: error, className: className, children: _jsxs("div", { className: 'relative flex items-center', ref: containerRef, children: [displayIcon && (_jsx("div", { className: `
|
|
65
68
|
absolute left-3 text-login-200
|
|
66
|
-
${isDateType && !disabled ? 'cursor-pointer hover:text-login-text' : 'pointer-events-none'}
|
|
67
|
-
`, onClick: handleIconClick, children: displayIcon })), _jsx("input", { ref: localRef, id: name, name: name, type: isDateType ? 'text' : type,
|
|
69
|
+
${isDateType && !inputProps.disabled ? 'cursor-pointer hover:text-login-text' : 'pointer-events-none'}
|
|
70
|
+
`, onClick: handleIconClick, children: displayIcon })), _jsx("input", { ...inputProps, ref: localRef, id: name, name: name, type: isDateType ? 'text' : type, value: value, readOnly: isDateType, onClick: () => isDateType && !inputProps.disabled && setIsOpen(true), title: label, "aria-invalid": !!error, "aria-describedby": error ? `${name}-error` : undefined, className: `
|
|
68
71
|
w-full rounded-md bg-login-500/50 border border-login-500
|
|
69
72
|
text-login-text placeholder-login-200
|
|
70
73
|
focus:outline-none focus:border-login focus:ring-1 focus:ring-login
|
|
@@ -73,6 +76,6 @@ export default function Input({ label, name, type = 'text', placeholder, value,
|
|
|
73
76
|
transition-all duration-200
|
|
74
77
|
input-reset
|
|
75
78
|
${error ? 'border-red-500 focus:border-red-500 focus:ring-red-500' : ''}
|
|
76
|
-
${isDateType && !disabled ? 'cursor-pointer' : ''}
|
|
77
|
-
` }), isOpen && isDateType && !disabled && (_jsx(DateTimePickerPopup, { value: getDateValue(), onChange: handleDateChange, type: type, onClose: () => setIsOpen(false) }))] }) }));
|
|
79
|
+
${isDateType && !inputProps.disabled ? 'cursor-pointer' : ''}
|
|
80
|
+
` }), isOpen && isDateType && !inputProps.disabled && (_jsx(DateTimePickerPopup, { value: getDateValue(), onChange: handleDateChange, type: type, onClose: () => setIsOpen(false) }))] }) }));
|
|
78
81
|
}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export type RadioProps = {
|
|
3
|
-
label?: string;
|
|
1
|
+
export type RadioProps = Omit<React.ComponentProps<'input'>, 'name'> & {
|
|
4
2
|
name: string;
|
|
5
|
-
|
|
6
|
-
checked?: boolean;
|
|
7
|
-
onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
8
|
-
className?: string;
|
|
9
|
-
disabled?: boolean;
|
|
3
|
+
label?: string;
|
|
10
4
|
error?: string;
|
|
11
5
|
info?: string;
|
|
12
|
-
|
|
6
|
+
className?: string;
|
|
13
7
|
};
|
|
14
|
-
export default function Radio(
|
|
8
|
+
export default function Radio(props: RadioProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { SelectionWrapper } from './shared';
|
|
3
|
-
export default function Radio(
|
|
3
|
+
export default function Radio(props) {
|
|
4
|
+
const { name, label, error, info, className, ...inputProps } = props;
|
|
5
|
+
const { value } = inputProps;
|
|
4
6
|
const id = `${name}-${value}`;
|
|
5
|
-
return (_jsx(SelectionWrapper, { label: label, name: id, required: required, info: info, error: error, className: className, disabled: disabled, children: _jsxs("div", { className: 'relative flex items-center', children: [_jsx("input", { id: id, name: name, type: 'radio',
|
|
7
|
+
return (_jsx(SelectionWrapper, { label: label, name: id, required: inputProps.required, info: info, error: error, className: className, disabled: inputProps.disabled, children: _jsxs("div", { className: 'relative flex items-center', children: [_jsx("input", { ...inputProps, id: id, name: name, type: 'radio', className: `
|
|
6
8
|
peer appearance-none h-5 w-5 rounded-full border border-login-500 bg-login-500/50
|
|
7
9
|
checked:bg-login checked:border-login
|
|
8
10
|
focus:outline-none focus:ring-2 focus:ring-login/50
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export type RangeProps = {
|
|
3
|
-
label?: string;
|
|
1
|
+
export type RangeProps = Omit<React.ComponentProps<'input'>, 'name'> & {
|
|
4
2
|
name: string;
|
|
5
|
-
|
|
6
|
-
max?: number;
|
|
7
|
-
step?: number;
|
|
8
|
-
value?: number;
|
|
9
|
-
onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
3
|
+
label?: string;
|
|
10
4
|
error?: string;
|
|
11
5
|
className?: string;
|
|
12
|
-
disabled?: boolean;
|
|
13
|
-
required?: boolean;
|
|
14
6
|
info?: string;
|
|
15
7
|
showValue?: boolean;
|
|
16
8
|
};
|
|
17
|
-
export default function Range(
|
|
9
|
+
export default function Range(props: RangeProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { FieldWrapper } from './shared';
|
|
3
|
-
export default function Range(
|
|
4
|
-
|
|
3
|
+
export default function Range(props) {
|
|
4
|
+
const { name, label, error, className, info, showValue = true, ...inputProps } = props;
|
|
5
|
+
const { min = 0, max = 100, step = 1, value = 0 } = inputProps;
|
|
6
|
+
return (_jsx(FieldWrapper, { label: label, name: name, required: inputProps.required, info: info, error: error, className: className, children: _jsxs("div", { className: 'flex items-center gap-4', children: [_jsx("input", { ...inputProps, id: name, name: name, type: 'range', min: min, max: max, step: step, value: value, title: label, "aria-invalid": !!error, "aria-describedby": error ? `${name}-error` : undefined, className: `
|
|
5
7
|
flex-1 h-2 bg-login-500 rounded-lg appearance-none cursor-pointer
|
|
6
8
|
accent-login
|
|
7
9
|
[&::-webkit-slider-thumb]:appearance-none
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export type SwitchProps = {
|
|
3
|
-
label?: string;
|
|
1
|
+
export type SwitchProps = Omit<React.ComponentProps<'input'>, 'name'> & {
|
|
4
2
|
name: string;
|
|
5
|
-
|
|
6
|
-
onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
7
|
-
className?: string;
|
|
8
|
-
disabled?: boolean;
|
|
3
|
+
label?: string;
|
|
9
4
|
error?: string;
|
|
10
5
|
info?: string;
|
|
11
|
-
|
|
6
|
+
className?: string;
|
|
12
7
|
switchOnly?: boolean;
|
|
13
8
|
};
|
|
14
|
-
export default function Switch(
|
|
9
|
+
export default function Switch(props: SwitchProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { SelectionWrapper } from './shared';
|
|
3
|
-
export default function Switch(
|
|
4
|
-
|
|
3
|
+
export default function Switch(props) {
|
|
4
|
+
const { name, label, error, info, className, switchOnly, ...inputProps } = props;
|
|
5
|
+
return (_jsx(SelectionWrapper, { label: label, name: name, required: inputProps.required, info: info, error: error, hideError: switchOnly, className: className, disabled: inputProps.disabled, children: _jsxs("label", { className: `relative inline-flex items-center cursor-pointer ${switchOnly ? 'h-fit' : 'h-10.5'}`, children: [_jsx("input", { ...inputProps, type: 'checkbox', id: name, name: name, className: 'sr-only peer' }), _jsx("div", { className: `
|
|
5
6
|
w-11 h-6 bg-login-500/50 rounded-full peer
|
|
6
7
|
peer-checked:after:translate-x-full peer-checked:after:border-white
|
|
7
8
|
after:content-[''] after:absolute ${switchOnly ? 'after:top-0.5' : 'after:top-2.75'} after:left-0.5
|
|
8
9
|
after:bg-white after:border-gray-300 after:border after:rounded-full
|
|
9
10
|
after:h-5 after:w-5 after:transition-all peer-checked:bg-login
|
|
10
|
-
${disabled ? 'opacity-50 cursor-not-allowed' : ''}
|
|
11
|
+
${inputProps.disabled ? 'opacity-50 cursor-not-allowed' : ''}
|
|
11
12
|
${error ? 'ring-1 ring-red-500' : ''}
|
|
12
13
|
` })] }) }));
|
|
13
14
|
}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export type TextareaProps = {
|
|
3
|
-
label?: string;
|
|
1
|
+
export type TextareaProps = Omit<React.ComponentProps<'textarea'>, 'name'> & {
|
|
4
2
|
name: string;
|
|
5
|
-
|
|
6
|
-
type?: 'markdown' | 'json' | 'text';
|
|
7
|
-
value?: string;
|
|
8
|
-
onChange?: (e: ChangeEvent<HTMLTextAreaElement>) => void;
|
|
3
|
+
label?: string;
|
|
9
4
|
error?: string;
|
|
10
5
|
className?: string;
|
|
11
|
-
disabled?: boolean;
|
|
12
|
-
required?: boolean;
|
|
13
|
-
rows?: number;
|
|
14
6
|
info?: string;
|
|
7
|
+
type?: 'markdown' | 'json' | 'text';
|
|
15
8
|
};
|
|
16
|
-
export default function Textarea(
|
|
9
|
+
export default function Textarea(props: TextareaProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -12,17 +12,19 @@ function isValidJson(str) {
|
|
|
12
12
|
return error.message;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
export default function Textarea(
|
|
15
|
+
export default function Textarea(props) {
|
|
16
|
+
const { name, label, error, className, info, type = 'text', rows = 4, ...textareaProps } = props;
|
|
17
|
+
const { value } = textareaProps;
|
|
16
18
|
const [preview, setPreview] = useState(false);
|
|
17
19
|
const jsonError = type === 'json' && value ? isValidJson(value) : undefined;
|
|
18
20
|
const displayError = jsonError || error;
|
|
19
|
-
return (_jsx(FieldWrapper, { label: label, name: name, required: required, info: info, error: displayError, className: className, children: _jsxs("div", { className: 'relative', children: [type === 'markdown' && (_jsx("div", { className: 'absolute right-2 top-2 z-10 flex gap-2', children: _jsx("button", { type: 'button', onClick: () => setPreview(!preview), className: 'p-1 rounded hover:bg-login-500/50 text-login-text transition-colors', title: preview ? 'Edit' : 'Preview', children: preview ? _jsx(Pencil, { size: 16 }) : _jsx(Eye, { size: 16 }) }) })), type === 'markdown' && preview ? (_jsx("div", { className: `
|
|
21
|
+
return (_jsx(FieldWrapper, { label: label, name: name, required: textareaProps.required, info: info, error: displayError, className: className, children: _jsxs("div", { className: 'relative', children: [type === 'markdown' && (_jsx("div", { className: 'absolute right-2 top-2 z-10 flex gap-2', children: _jsx("button", { type: 'button', onClick: () => setPreview(!preview), className: 'p-1 rounded hover:bg-login-500/50 text-login-text transition-colors', title: preview ? 'Edit' : 'Preview', children: preview ? _jsx(Pencil, { size: 16 }) : _jsx(Eye, { size: 16 }) }) })), type === 'markdown' && preview ? (_jsx("div", { className: `
|
|
20
22
|
w-full rounded-md bg-login-500/50 border border-login-500
|
|
21
23
|
text-login-text
|
|
22
24
|
p-3
|
|
23
25
|
prose prose-invert prose-sm max-w-none overflow-y-auto
|
|
24
26
|
${error ? 'border-red-500' : ''}
|
|
25
|
-
`, style: { minHeight: `${rows * 1.5}rem` }, children: _jsx(ReactMarkdown, { children: value || '' }) })) : (_jsx("textarea", { id: name, name: name,
|
|
27
|
+
`, style: { minHeight: `${rows * 1.5}rem` }, children: _jsx(ReactMarkdown, { children: String(value || '') }) })) : (_jsx("textarea", { ...textareaProps, id: name, name: name, rows: rows, title: label, "aria-invalid": !!error, "aria-describedby": error ? `${name}-error` : undefined, className: `
|
|
26
28
|
w-full rounded-md bg-login-500/50 border border-login-500
|
|
27
29
|
text-login-text placeholder-login-200
|
|
28
30
|
focus:outline-none focus:border-login focus:ring-1 focus:ring-login
|
package/package.json
CHANGED
|
@@ -1,49 +1,33 @@
|
|
|
1
|
-
import { type ChangeEvent } from 'react'
|
|
2
1
|
import { Check } from 'lucide-react'
|
|
3
2
|
import { SelectionWrapper } from './shared'
|
|
4
3
|
|
|
5
|
-
export type CheckboxProps = {
|
|
6
|
-
label?: string
|
|
4
|
+
export type CheckboxProps = Omit<React.ComponentProps<'input'>, 'name'> & {
|
|
7
5
|
name: string
|
|
8
|
-
|
|
9
|
-
onChange?: (e: ChangeEvent<HTMLInputElement>) => void
|
|
10
|
-
className?: string
|
|
11
|
-
disabled?: boolean
|
|
6
|
+
label?: string
|
|
12
7
|
error?: string
|
|
13
8
|
info?: string
|
|
14
|
-
|
|
9
|
+
className?: string
|
|
15
10
|
}
|
|
16
11
|
|
|
17
|
-
export default function Checkbox({
|
|
18
|
-
label,
|
|
19
|
-
|
|
20
|
-
checked,
|
|
21
|
-
onChange,
|
|
22
|
-
className,
|
|
23
|
-
disabled,
|
|
24
|
-
error,
|
|
25
|
-
info,
|
|
26
|
-
required,
|
|
27
|
-
}: CheckboxProps) {
|
|
12
|
+
export default function Checkbox(props: CheckboxProps) {
|
|
13
|
+
const { name, label, error, info, className, ...inputProps } = props
|
|
14
|
+
|
|
28
15
|
return (
|
|
29
16
|
<SelectionWrapper
|
|
30
17
|
label={label}
|
|
31
18
|
name={name}
|
|
32
|
-
required={required}
|
|
19
|
+
required={inputProps.required}
|
|
33
20
|
info={info}
|
|
34
21
|
error={error}
|
|
35
22
|
className={className}
|
|
36
|
-
disabled={disabled}
|
|
23
|
+
disabled={inputProps.disabled}
|
|
37
24
|
>
|
|
38
25
|
<div className='relative flex items-center'>
|
|
39
26
|
<input
|
|
27
|
+
{...inputProps}
|
|
40
28
|
id={name}
|
|
41
29
|
name={name}
|
|
42
30
|
type='checkbox'
|
|
43
|
-
checked={checked}
|
|
44
|
-
onChange={onChange}
|
|
45
|
-
disabled={disabled}
|
|
46
|
-
required={required}
|
|
47
31
|
className={`
|
|
48
32
|
peer appearance-none h-5 w-5 rounded border border-login-500 bg-login-500/50
|
|
49
33
|
checked:bg-login checked:border-login
|
|
@@ -4,37 +4,18 @@ import { FieldWrapper } from './shared'
|
|
|
4
4
|
import DateTimePickerPopup from './shared/dateTimePickerPopup'
|
|
5
5
|
import useClickOutside from '../../hooks/useClickOutside'
|
|
6
6
|
|
|
7
|
-
export type InputProps = {
|
|
8
|
-
label?: string
|
|
7
|
+
export type InputProps = Omit<React.ComponentProps<'input'>, 'name'> & {
|
|
9
8
|
name: string
|
|
10
|
-
|
|
11
|
-
placeholder?: string
|
|
12
|
-
value?: string | number
|
|
13
|
-
onChange?: (e: ChangeEvent<HTMLInputElement>) => void
|
|
9
|
+
label?: string
|
|
14
10
|
error?: string
|
|
15
11
|
className?: string
|
|
16
|
-
disabled?: boolean
|
|
17
|
-
required?: boolean
|
|
18
12
|
icon?: JSX.Element
|
|
19
13
|
info?: string
|
|
20
|
-
multiple?: boolean
|
|
21
14
|
}
|
|
22
15
|
|
|
23
|
-
export default function Input({
|
|
24
|
-
label,
|
|
25
|
-
|
|
26
|
-
type = 'text',
|
|
27
|
-
placeholder,
|
|
28
|
-
value,
|
|
29
|
-
onChange,
|
|
30
|
-
error,
|
|
31
|
-
className,
|
|
32
|
-
disabled,
|
|
33
|
-
required,
|
|
34
|
-
icon,
|
|
35
|
-
info,
|
|
36
|
-
multiple,
|
|
37
|
-
}: InputProps) {
|
|
16
|
+
export default function Input(props: InputProps) {
|
|
17
|
+
const { name, label, error, className, icon, info, ...inputProps } = props
|
|
18
|
+
const { type = 'text', value } = inputProps
|
|
38
19
|
const localRef = useRef<HTMLInputElement>(null)
|
|
39
20
|
const [isOpen, setIsOpen] = useState(false)
|
|
40
21
|
|
|
@@ -43,14 +24,15 @@ export default function Input({
|
|
|
43
24
|
const isDateType = ['date', 'datetime-local', 'time'].includes(type as string)
|
|
44
25
|
|
|
45
26
|
function handleIconClick() {
|
|
46
|
-
if (isDateType && !disabled) {
|
|
27
|
+
if (isDateType && !inputProps.disabled) {
|
|
47
28
|
setIsOpen(!isOpen)
|
|
48
|
-
} else if (localRef.current && !disabled) {
|
|
29
|
+
} else if (localRef.current && !inputProps.disabled) {
|
|
49
30
|
localRef.current.focus()
|
|
50
31
|
}
|
|
51
32
|
}
|
|
52
33
|
|
|
53
34
|
function handleDateChange(date: Date) {
|
|
35
|
+
const onChange = inputProps.onChange
|
|
54
36
|
if (!onChange) return
|
|
55
37
|
|
|
56
38
|
const pad = (n: number) => n.toString().padStart(2, '0')
|
|
@@ -98,7 +80,7 @@ export default function Input({
|
|
|
98
80
|
<FieldWrapper
|
|
99
81
|
label={label}
|
|
100
82
|
name={name}
|
|
101
|
-
required={required}
|
|
83
|
+
required={inputProps.required}
|
|
102
84
|
info={info}
|
|
103
85
|
error={error}
|
|
104
86
|
className={className}
|
|
@@ -108,7 +90,7 @@ export default function Input({
|
|
|
108
90
|
<div
|
|
109
91
|
className={`
|
|
110
92
|
absolute left-3 text-login-200
|
|
111
|
-
${isDateType && !disabled ? 'cursor-pointer hover:text-login-text' : 'pointer-events-none'}
|
|
93
|
+
${isDateType && !inputProps.disabled ? 'cursor-pointer hover:text-login-text' : 'pointer-events-none'}
|
|
112
94
|
`}
|
|
113
95
|
onClick={handleIconClick}
|
|
114
96
|
>
|
|
@@ -116,19 +98,15 @@ export default function Input({
|
|
|
116
98
|
</div>
|
|
117
99
|
)}
|
|
118
100
|
<input
|
|
101
|
+
{...inputProps}
|
|
119
102
|
ref={localRef}
|
|
120
103
|
id={name}
|
|
121
104
|
name={name}
|
|
122
105
|
type={isDateType ? 'text' : type}
|
|
123
|
-
placeholder={placeholder}
|
|
124
106
|
value={value}
|
|
125
|
-
onChange={onChange}
|
|
126
|
-
disabled={disabled}
|
|
127
|
-
required={required}
|
|
128
107
|
readOnly={isDateType}
|
|
129
|
-
onClick={() => isDateType && !disabled && setIsOpen(true)}
|
|
108
|
+
onClick={() => isDateType && !inputProps.disabled && setIsOpen(true)}
|
|
130
109
|
title={label}
|
|
131
|
-
multiple={multiple}
|
|
132
110
|
aria-invalid={!!error}
|
|
133
111
|
aria-describedby={error ? `${name}-error` : undefined}
|
|
134
112
|
className={`
|
|
@@ -140,10 +118,10 @@ export default function Input({
|
|
|
140
118
|
transition-all duration-200
|
|
141
119
|
input-reset
|
|
142
120
|
${error ? 'border-red-500 focus:border-red-500 focus:ring-red-500' : ''}
|
|
143
|
-
${isDateType && !disabled ? 'cursor-pointer' : ''}
|
|
121
|
+
${isDateType && !inputProps.disabled ? 'cursor-pointer' : ''}
|
|
144
122
|
`}
|
|
145
123
|
/>
|
|
146
|
-
{isOpen && isDateType && !disabled && (
|
|
124
|
+
{isOpen && isDateType && !inputProps.disabled && (
|
|
147
125
|
<DateTimePickerPopup
|
|
148
126
|
value={getDateValue()}
|
|
149
127
|
onChange={handleDateChange}
|
|
@@ -1,52 +1,34 @@
|
|
|
1
|
-
import { type ChangeEvent } from 'react'
|
|
2
1
|
import { SelectionWrapper } from './shared'
|
|
3
2
|
|
|
4
|
-
export type RadioProps = {
|
|
5
|
-
label?: string
|
|
3
|
+
export type RadioProps = Omit<React.ComponentProps<'input'>, 'name'> & {
|
|
6
4
|
name: string
|
|
7
|
-
|
|
8
|
-
checked?: boolean
|
|
9
|
-
onChange?: (e: ChangeEvent<HTMLInputElement>) => void
|
|
10
|
-
className?: string
|
|
11
|
-
disabled?: boolean
|
|
5
|
+
label?: string
|
|
12
6
|
error?: string
|
|
13
7
|
info?: string
|
|
14
|
-
|
|
8
|
+
className?: string
|
|
15
9
|
}
|
|
16
10
|
|
|
17
|
-
export default function Radio({
|
|
18
|
-
label,
|
|
19
|
-
|
|
20
|
-
value,
|
|
21
|
-
checked,
|
|
22
|
-
onChange,
|
|
23
|
-
className,
|
|
24
|
-
disabled,
|
|
25
|
-
error,
|
|
26
|
-
info,
|
|
27
|
-
required,
|
|
28
|
-
}: RadioProps) {
|
|
11
|
+
export default function Radio(props: RadioProps) {
|
|
12
|
+
const { name, label, error, info, className, ...inputProps } = props
|
|
13
|
+
const { value } = inputProps
|
|
29
14
|
const id = `${name}-${value}`
|
|
15
|
+
|
|
30
16
|
return (
|
|
31
17
|
<SelectionWrapper
|
|
32
18
|
label={label}
|
|
33
19
|
name={id}
|
|
34
|
-
required={required}
|
|
20
|
+
required={inputProps.required}
|
|
35
21
|
info={info}
|
|
36
22
|
error={error}
|
|
37
23
|
className={className}
|
|
38
|
-
disabled={disabled}
|
|
24
|
+
disabled={inputProps.disabled}
|
|
39
25
|
>
|
|
40
26
|
<div className='relative flex items-center'>
|
|
41
27
|
<input
|
|
28
|
+
{...inputProps}
|
|
42
29
|
id={id}
|
|
43
30
|
name={name}
|
|
44
31
|
type='radio'
|
|
45
|
-
value={value}
|
|
46
|
-
checked={checked}
|
|
47
|
-
onChange={onChange}
|
|
48
|
-
disabled={disabled}
|
|
49
|
-
required={required}
|
|
50
32
|
className={`
|
|
51
33
|
peer appearance-none h-5 w-5 rounded-full border border-login-500 bg-login-500/50
|
|
52
34
|
checked:bg-login checked:border-login
|
|
@@ -1,48 +1,30 @@
|
|
|
1
|
-
import { type ChangeEvent } from 'react'
|
|
2
1
|
import { FieldWrapper } from './shared'
|
|
3
2
|
|
|
4
|
-
export type RangeProps = {
|
|
5
|
-
label?: string
|
|
3
|
+
export type RangeProps = Omit<React.ComponentProps<'input'>, 'name'> & {
|
|
6
4
|
name: string
|
|
7
|
-
|
|
8
|
-
max?: number
|
|
9
|
-
step?: number
|
|
10
|
-
value?: number
|
|
11
|
-
onChange?: (e: ChangeEvent<HTMLInputElement>) => void
|
|
5
|
+
label?: string
|
|
12
6
|
error?: string
|
|
13
7
|
className?: string
|
|
14
|
-
disabled?: boolean
|
|
15
|
-
required?: boolean
|
|
16
8
|
info?: string
|
|
17
9
|
showValue?: boolean
|
|
18
10
|
}
|
|
19
11
|
|
|
20
|
-
export default function Range({
|
|
21
|
-
label,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
max = 100,
|
|
25
|
-
step = 1,
|
|
26
|
-
value = 0,
|
|
27
|
-
onChange,
|
|
28
|
-
error,
|
|
29
|
-
className,
|
|
30
|
-
disabled,
|
|
31
|
-
required,
|
|
32
|
-
info,
|
|
33
|
-
showValue = true,
|
|
34
|
-
}: RangeProps) {
|
|
12
|
+
export default function Range(props: RangeProps) {
|
|
13
|
+
const { name, label, error, className, info, showValue = true, ...inputProps } = props
|
|
14
|
+
const { min = 0, max = 100, step = 1, value = 0 } = inputProps
|
|
15
|
+
|
|
35
16
|
return (
|
|
36
17
|
<FieldWrapper
|
|
37
18
|
label={label}
|
|
38
19
|
name={name}
|
|
39
|
-
required={required}
|
|
20
|
+
required={inputProps.required}
|
|
40
21
|
info={info}
|
|
41
22
|
error={error}
|
|
42
23
|
className={className}
|
|
43
24
|
>
|
|
44
25
|
<div className='flex items-center gap-4'>
|
|
45
26
|
<input
|
|
27
|
+
{...inputProps}
|
|
46
28
|
id={name}
|
|
47
29
|
name={name}
|
|
48
30
|
type='range'
|
|
@@ -50,9 +32,6 @@ export default function Range({
|
|
|
50
32
|
max={max}
|
|
51
33
|
step={step}
|
|
52
34
|
value={value}
|
|
53
|
-
onChange={onChange}
|
|
54
|
-
disabled={disabled}
|
|
55
|
-
required={required}
|
|
56
35
|
title={label}
|
|
57
36
|
aria-invalid={!!error}
|
|
58
37
|
aria-describedby={error ? `${name}-error` : undefined}
|
|
@@ -1,51 +1,34 @@
|
|
|
1
|
-
import { type ChangeEvent } from 'react'
|
|
2
1
|
import { SelectionWrapper } from './shared'
|
|
3
2
|
|
|
4
|
-
export type SwitchProps = {
|
|
5
|
-
label?: string
|
|
3
|
+
export type SwitchProps = Omit<React.ComponentProps<'input'>, 'name'> & {
|
|
6
4
|
name: string
|
|
7
|
-
|
|
8
|
-
onChange?: (e: ChangeEvent<HTMLInputElement>) => void
|
|
9
|
-
className?: string
|
|
10
|
-
disabled?: boolean
|
|
5
|
+
label?: string
|
|
11
6
|
error?: string
|
|
12
7
|
info?: string
|
|
13
|
-
|
|
8
|
+
className?: string
|
|
14
9
|
switchOnly?: boolean
|
|
15
10
|
}
|
|
16
11
|
|
|
17
|
-
export default function Switch({
|
|
18
|
-
label,
|
|
19
|
-
|
|
20
|
-
checked,
|
|
21
|
-
onChange,
|
|
22
|
-
className,
|
|
23
|
-
disabled,
|
|
24
|
-
error,
|
|
25
|
-
info,
|
|
26
|
-
required,
|
|
27
|
-
switchOnly,
|
|
28
|
-
}: SwitchProps) {
|
|
12
|
+
export default function Switch(props: SwitchProps) {
|
|
13
|
+
const { name, label, error, info, className, switchOnly, ...inputProps } = props
|
|
14
|
+
|
|
29
15
|
return (
|
|
30
16
|
<SelectionWrapper
|
|
31
17
|
label={label}
|
|
32
18
|
name={name}
|
|
33
|
-
required={required}
|
|
19
|
+
required={inputProps.required}
|
|
34
20
|
info={info}
|
|
35
21
|
error={error}
|
|
36
22
|
hideError={switchOnly}
|
|
37
23
|
className={className}
|
|
38
|
-
disabled={disabled}
|
|
24
|
+
disabled={inputProps.disabled}
|
|
39
25
|
>
|
|
40
26
|
<label className={`relative inline-flex items-center cursor-pointer ${switchOnly ? 'h-fit' : 'h-10.5'}`}>
|
|
41
27
|
<input
|
|
28
|
+
{...inputProps}
|
|
42
29
|
type='checkbox'
|
|
43
30
|
id={name}
|
|
44
31
|
name={name}
|
|
45
|
-
checked={checked}
|
|
46
|
-
onChange={onChange}
|
|
47
|
-
disabled={disabled}
|
|
48
|
-
required={required}
|
|
49
32
|
className='sr-only peer'
|
|
50
33
|
/>
|
|
51
34
|
<div className={`
|
|
@@ -54,7 +37,7 @@ export default function Switch({
|
|
|
54
37
|
after:content-[''] after:absolute ${switchOnly ? 'after:top-0.5' : 'after:top-2.75'} after:left-0.5
|
|
55
38
|
after:bg-white after:border-gray-300 after:border after:rounded-full
|
|
56
39
|
after:h-5 after:w-5 after:transition-all peer-checked:bg-login
|
|
57
|
-
${disabled ? 'opacity-50 cursor-not-allowed' : ''}
|
|
40
|
+
${inputProps.disabled ? 'opacity-50 cursor-not-allowed' : ''}
|
|
58
41
|
${error ? 'ring-1 ring-red-500' : ''}
|
|
59
42
|
`}></div>
|
|
60
43
|
</label>
|
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useState } from 'react'
|
|
2
2
|
import ReactMarkdown from 'react-markdown'
|
|
3
3
|
import { Eye, Pencil } from 'lucide-react'
|
|
4
4
|
import { FieldWrapper } from './shared'
|
|
5
5
|
|
|
6
|
-
export type TextareaProps = {
|
|
7
|
-
label?: string
|
|
6
|
+
export type TextareaProps = Omit<React.ComponentProps<'textarea'>, 'name'> & {
|
|
8
7
|
name: string
|
|
9
|
-
|
|
10
|
-
type?: 'markdown' | 'json' | 'text'
|
|
11
|
-
value?: string
|
|
12
|
-
onChange?: (e: ChangeEvent<HTMLTextAreaElement>) => void
|
|
8
|
+
label?: string
|
|
13
9
|
error?: string
|
|
14
10
|
className?: string
|
|
15
|
-
disabled?: boolean
|
|
16
|
-
required?: boolean
|
|
17
|
-
rows?: number
|
|
18
11
|
info?: string
|
|
12
|
+
type?: 'markdown' | 'json' | 'text'
|
|
19
13
|
}
|
|
20
14
|
|
|
21
15
|
function isValidJson(str: string): string | null {
|
|
@@ -27,30 +21,19 @@ function isValidJson(str: string): string | null {
|
|
|
27
21
|
}
|
|
28
22
|
}
|
|
29
23
|
|
|
30
|
-
export default function Textarea({
|
|
31
|
-
label,
|
|
32
|
-
|
|
33
|
-
placeholder,
|
|
34
|
-
value,
|
|
35
|
-
onChange,
|
|
36
|
-
error,
|
|
37
|
-
className,
|
|
38
|
-
disabled,
|
|
39
|
-
required,
|
|
40
|
-
rows = 4,
|
|
41
|
-
info,
|
|
42
|
-
type = 'text',
|
|
43
|
-
}: TextareaProps) {
|
|
24
|
+
export default function Textarea(props: TextareaProps) {
|
|
25
|
+
const { name, label, error, className, info, type = 'text', rows = 4, ...textareaProps } = props
|
|
26
|
+
const { value } = textareaProps
|
|
44
27
|
const [preview, setPreview] = useState(false)
|
|
45
28
|
|
|
46
|
-
const jsonError = type === 'json' && value ? isValidJson(value) : undefined
|
|
29
|
+
const jsonError = type === 'json' && value ? isValidJson(value as string) : undefined
|
|
47
30
|
const displayError = jsonError || error
|
|
48
31
|
|
|
49
32
|
return (
|
|
50
33
|
<FieldWrapper
|
|
51
34
|
label={label}
|
|
52
35
|
name={name}
|
|
53
|
-
required={required}
|
|
36
|
+
required={textareaProps.required}
|
|
54
37
|
info={info}
|
|
55
38
|
error={displayError}
|
|
56
39
|
className={className}
|
|
@@ -80,17 +63,13 @@ export default function Textarea({
|
|
|
80
63
|
`}
|
|
81
64
|
style={{ minHeight: `${rows * 1.5}rem` }}
|
|
82
65
|
>
|
|
83
|
-
<ReactMarkdown>{value || ''}</ReactMarkdown>
|
|
66
|
+
<ReactMarkdown>{String(value || '')}</ReactMarkdown>
|
|
84
67
|
</div>
|
|
85
68
|
) : (
|
|
86
69
|
<textarea
|
|
70
|
+
{...textareaProps}
|
|
87
71
|
id={name}
|
|
88
72
|
name={name}
|
|
89
|
-
placeholder={placeholder}
|
|
90
|
-
value={value}
|
|
91
|
-
onChange={onChange}
|
|
92
|
-
disabled={disabled}
|
|
93
|
-
required={required}
|
|
94
73
|
rows={rows}
|
|
95
74
|
title={label}
|
|
96
75
|
aria-invalid={!!error}
|