@jsb188/form 0.0.0-stage → 1.1.2
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/README.md +132 -2
- package/css/form.css +2 -0
- package/package.json +40 -5
- package/src/assets.d.ts +1 -0
- package/src/libs/SchemaForm.tsx +158 -0
- package/src/libs/SchemaForm.types.ts +165 -0
- package/src/libs/defineForm.ts +11 -0
- package/src/libs/rules.ts +126 -0
- package/src/libs/useField.ts +16 -0
- package/src/libs/useSchemaForm.helpers.ts +71 -0
- package/src/libs/useSchemaForm.ts +268 -0
- package/src/libs/validation.ts +42 -0
- package/src/main.ts +40 -0
- package/src/modules/FieldLabel.tsx +28 -0
- package/src/modules/Form-Input.tsx +2 -0
- package/src/modules/Form-Line.tsx +126 -0
- package/src/modules/Form.helpers.ts +12 -0
- package/src/modules/Form.tsx +14 -0
- package/src/modules/FormItem.tsx +117 -0
- package/src/modules/FormOptions.tsx +12 -0
- package/src/modules/FormUI.tsx +2 -0
- package/src/modules/Input.tsx +16 -0
- package/src/modules/InputClick.tsx +48 -0
- package/src/modules/InputWithButton.tsx +37 -0
- package/src/modules/ListItemForm.tsx +345 -0
- package/src/modules/ListItemForm.types.ts +50 -0
- package/src/modules/PasswordInput.tsx +36 -0
- package/src/modules/PopOverInput.tsx +75 -0
- package/src/modules/SMSCodeInput.tsx +118 -0
- package/src/modules/SchemaField.tsx +104 -0
- package/src/modules/Select.tsx +163 -0
- package/src/modules/Textarea.tsx +33 -0
- package/src/modules/TimeInput.helpers.ts +73 -0
- package/src/modules/TimeInput.tsx +159 -0
- package/src/modules/TimeInput.types.ts +43 -0
- package/src/modules/UploadInput.tsx +141 -0
- package/src/modules/composeFormInput.tsx +88 -0
- package/src/types/form.ts +65 -0
- package/src/ui/ContentEditable.tsx +70 -0
- package/src/ui/Form.types.ts +138 -0
- package/src/ui/FormOptions.tsx +125 -0
- package/src/ui/FormUI.tsx +237 -0
- package/src/ui/Input.helpers.ts +7 -0
- package/src/ui/Input.tsx +199 -0
- package/src/ui/Input.types.ts +48 -0
- package/src/ui/InputButtons.tsx +41 -0
- package/src/ui/InputControls.tsx +68 -0
- package/src/ui/Label.tsx +46 -0
- package/src/ui/LineForm.tsx +34 -0
- package/src/ui/SMSCodeInput.tsx +51 -0
- package/src/ui/Select.tsx +33 -0
- package/src/ui/Textarea.tsx +96 -0
- package/src/ui/TimeInput.tsx +140 -0
- package/tests/controller.test.tsx +336 -0
- package/tests/controls.test.tsx +261 -0
- package/tests/schema-form.test.tsx +303 -0
- package/tests/settings-definitions.test.ts +129 -0
- package/tests/sms-input.test.tsx +131 -0
- package/tests/time-input.test.tsx +395 -0
- package/tests/types.ts +102 -0
- package/tests/upload-input.test.tsx +114 -0
- package/tests/validation.test.ts +65 -0
- package/tsconfig.json +13 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isDarkColor } from '@jsb188/app/utils/color.ts';
|
|
2
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
3
|
+
import { type CSSProperties, type InputHTMLAttributes, memo, type ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
export interface ColorInputSwatchProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'className' | 'style' | 'type' | 'value'> {
|
|
6
|
+
className?: string;
|
|
7
|
+
sizeClassName?: string;
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
value: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Render a custom color swatch over a visually hidden native color input.
|
|
14
|
+
*/
|
|
15
|
+
export const ColorInputSwatch = memo((p: ColorInputSwatchProps) => {
|
|
16
|
+
const { className, disabled, sizeClassName = 'w_14 h_14 r_2', style, value, ...inputProps } = p;
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<span
|
|
20
|
+
className={cn('rel block no_shrink of bd_1', sizeClassName, isDarkColor(value) ? 'bd_lighter_2' : 'bd_darker_2', className)}
|
|
21
|
+
style={{ ...style, backgroundColor: value }}
|
|
22
|
+
>
|
|
23
|
+
<input
|
|
24
|
+
{...inputProps}
|
|
25
|
+
className={cn('abs_full w_f h_f op_0', disabled ? '' : 'pointer')}
|
|
26
|
+
disabled={disabled}
|
|
27
|
+
type="color"
|
|
28
|
+
value={value}
|
|
29
|
+
/>
|
|
30
|
+
</span>
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
ColorInputSwatch.displayName = 'ColorInputSwatch';
|
|
35
|
+
|
|
36
|
+
export interface InputWithPostfixProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'className'> {
|
|
37
|
+
className?: string;
|
|
38
|
+
hideNumberSpinner?: boolean;
|
|
39
|
+
inputClassName?: string;
|
|
40
|
+
postfix?: ReactNode;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
* Render a compact outlined input with optional trailing content.
|
|
45
|
+
*/
|
|
46
|
+
export const InputWithPostfix = memo((p: InputWithPostfixProps) => {
|
|
47
|
+
const { className, hideNumberSpinner, inputClassName, postfix, style, ...inputProps } = p;
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div className={cn('input_with_postfix h_24 h_spread r_xs bd_1 bd_lt bg gap_5', className)}>
|
|
51
|
+
<input
|
|
52
|
+
{...inputProps}
|
|
53
|
+
className={cn('input_field_sizing f_stretch r_xs bd_0 px_5 ft_xxs', hideNumberSpinner && 'no_number_spinner', inputClassName)}
|
|
54
|
+
style={style}
|
|
55
|
+
/>
|
|
56
|
+
{postfix ? (
|
|
57
|
+
<span
|
|
58
|
+
aria-hidden="true"
|
|
59
|
+
className="pr_5 ft_xxs cl_md no_shrink"
|
|
60
|
+
>
|
|
61
|
+
{postfix}
|
|
62
|
+
</span>
|
|
63
|
+
) : null}
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
InputWithPostfix.displayName = 'InputWithPostfix';
|
package/src/ui/Label.tsx
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
+
import { Icon } from '@jsb188/react-web/svgs/Icon';
|
|
3
|
+
import { memo } from 'react';
|
|
4
|
+
|
|
5
|
+
export type LabelType = Partial<{
|
|
6
|
+
htmlFor?: string;
|
|
7
|
+
paddingClassName?: string;
|
|
8
|
+
fontSizeClassName?: string;
|
|
9
|
+
labelClassName?: string;
|
|
10
|
+
iconName?: string;
|
|
11
|
+
info?: string;
|
|
12
|
+
rightText?: string;
|
|
13
|
+
children: string;
|
|
14
|
+
accessory?: React.ReactNode;
|
|
15
|
+
}>;
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Render a field label with optional help and right-aligned supporting text.
|
|
19
|
+
*/
|
|
20
|
+
export const Label = memo((p: LabelType) => {
|
|
21
|
+
const { htmlFor, paddingClassName, fontSizeClassName, labelClassName, iconName, info, rightText, children, accessory } = p;
|
|
22
|
+
|
|
23
|
+
const hasRightIcon = !!accessory || !!iconName || !!info;
|
|
24
|
+
const hasRightText = !!rightText;
|
|
25
|
+
return (
|
|
26
|
+
<label
|
|
27
|
+
className={cn(fontSizeClassName ?? 'ft_sm', 'ic_sm h_spread', paddingClassName ?? 'pt_sm pb_3', labelClassName)}
|
|
28
|
+
htmlFor={htmlFor}
|
|
29
|
+
>
|
|
30
|
+
{children}
|
|
31
|
+
|
|
32
|
+
{(hasRightIcon || hasRightText) && <span className="f" />}
|
|
33
|
+
|
|
34
|
+
{hasRightText ? <span className="no_shrink pl_sm cl_lt">{rightText}</span> : null}
|
|
35
|
+
|
|
36
|
+
{hasRightIcon &&
|
|
37
|
+
(accessory || (
|
|
38
|
+
<span className="pl_5 shift_up label_r">
|
|
39
|
+
<Icon name={iconName || 'info-circle'} />
|
|
40
|
+
</span>
|
|
41
|
+
))}
|
|
42
|
+
</label>
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
Label.displayName = 'Label';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { memo } from 'react';
|
|
2
|
+
import { LineChip, LineRow } from './FormUI';
|
|
3
|
+
|
|
4
|
+
export interface LineSelectionItem {
|
|
5
|
+
id: string;
|
|
6
|
+
text: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* Render a display-only row of selected items as chips, with an optional summary at the end of the row.
|
|
11
|
+
*/
|
|
12
|
+
export const LineSelections = memo(
|
|
13
|
+
(p: {
|
|
14
|
+
// Width utility class of the label column; defaults to w_85.
|
|
15
|
+
labelWidthClassName?: string;
|
|
16
|
+
label: string;
|
|
17
|
+
selections: readonly LineSelectionItem[];
|
|
18
|
+
summary?: string;
|
|
19
|
+
}) => (
|
|
20
|
+
<LineRow
|
|
21
|
+
label={p.label}
|
|
22
|
+
labelWidthClassName={p.labelWidthClassName}
|
|
23
|
+
>
|
|
24
|
+
<div className="f h_item f_wrap gap_5 py_5 min_w_0">
|
|
25
|
+
{p.selections.map((item) => (
|
|
26
|
+
<LineChip key={item.id}>{item.text}</LineChip>
|
|
27
|
+
))}
|
|
28
|
+
</div>
|
|
29
|
+
{p.summary && <span className="ft_sm cl_md no_shrink pr_10">{p.summary}</span>}
|
|
30
|
+
</LineRow>
|
|
31
|
+
),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
LineSelections.displayName = 'LineSelections';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
+
|
|
3
|
+
/* Render the existing code slots and invisible native input as a fully controlled presentation component. */
|
|
4
|
+
export function SMSCodeInputUI(p: {
|
|
5
|
+
value: string;
|
|
6
|
+
codeLength: number;
|
|
7
|
+
saving?: boolean;
|
|
8
|
+
focused?: boolean;
|
|
9
|
+
inputRef?: React.Ref<HTMLInputElement>;
|
|
10
|
+
onFocus?: React.FocusEventHandler<HTMLInputElement>;
|
|
11
|
+
onBlur?: React.FocusEventHandler<HTMLInputElement>;
|
|
12
|
+
onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;
|
|
13
|
+
onChange: (value: string) => void;
|
|
14
|
+
}) {
|
|
15
|
+
return (
|
|
16
|
+
<div className={cn('p_5 r_df trans_color spd_1', p.focused ? 'bg_main' : 'bg_alt')}>
|
|
17
|
+
<div className={cn('bg px_df py_df r_sm rel h_spread ft_xxl a_c', p.saving ? 'cl_lt' : 'cl_df')}>
|
|
18
|
+
{[...Array(p.codeLength)].map((_, i) => {
|
|
19
|
+
const letter = p.value.charAt(i);
|
|
20
|
+
return (
|
|
21
|
+
<span
|
|
22
|
+
key={i}
|
|
23
|
+
className={cn('f', letter ? undefined : 'cl_lt')}
|
|
24
|
+
>
|
|
25
|
+
{letter || '#'}
|
|
26
|
+
</span>
|
|
27
|
+
);
|
|
28
|
+
})}
|
|
29
|
+
<input
|
|
30
|
+
ref={p.inputRef}
|
|
31
|
+
id="verification_code"
|
|
32
|
+
type="text"
|
|
33
|
+
inputMode="numeric"
|
|
34
|
+
autoComplete="one-time-code"
|
|
35
|
+
className="abs_full invis_input z2"
|
|
36
|
+
disabled={p.saving}
|
|
37
|
+
onFocus={p.onFocus}
|
|
38
|
+
onBlur={p.onBlur}
|
|
39
|
+
onKeyDown={p.onKeyDown}
|
|
40
|
+
onChange={(event) => p.onChange(event.target.value)}
|
|
41
|
+
onPaste={(event) => {
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
p.onChange(event.clipboardData.getData('text'));
|
|
44
|
+
}}
|
|
45
|
+
value={p.value}
|
|
46
|
+
maxLength={p.codeLength}
|
|
47
|
+
/>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
+
import { Icon } from '@jsb188/react-web/svgs/Icon';
|
|
3
|
+
import type { SelectOptionType, SelectType } from './Form.types';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Render the selected value, placeholder and dropdown icon inside an existing select trigger.
|
|
7
|
+
*/
|
|
8
|
+
export const SelectValueDisplay = (
|
|
9
|
+
p: Pick<SelectType, 'placeholder' | 'placeholderIconName' | 'leftIconClassName' | 'rightIconClassName' | 'locked' | 'disabled'> & {
|
|
10
|
+
selectedOption?: SelectOptionType;
|
|
11
|
+
},
|
|
12
|
+
) => {
|
|
13
|
+
const { selectedOption, placeholder, placeholderIconName, leftIconClassName, rightIconClassName, locked, disabled } = p;
|
|
14
|
+
return (
|
|
15
|
+
<>
|
|
16
|
+
<span className="h_item min_w_0 ellip">
|
|
17
|
+
{selectedOption?.iconName || (!selectedOption && placeholderIconName) ? (
|
|
18
|
+
<span className={cn('no_shrink mr_xs', leftIconClassName)}>
|
|
19
|
+
<Icon name={selectedOption?.iconName || placeholderIconName!} />
|
|
20
|
+
</span>
|
|
21
|
+
) : null}
|
|
22
|
+
<span className={cn('ellip', selectedOption?.textClassName, !selectedOption ? 'form_select_placeholder' : '')}>
|
|
23
|
+
{selectedOption?.text || placeholder || ''}
|
|
24
|
+
</span>
|
|
25
|
+
</span>
|
|
26
|
+
{locked || !disabled ? (
|
|
27
|
+
<span className={cn('no_shrink ml_xs cl_lt', rightIconClassName)}>
|
|
28
|
+
<Icon name={locked ? 'locked' : 'caret-down'} />
|
|
29
|
+
</span>
|
|
30
|
+
) : null}
|
|
31
|
+
</>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
+
import type { TextareaType } from './Form.types';
|
|
3
|
+
import { getHtmlFor } from './FormUI';
|
|
4
|
+
import { Label as DefaultLabel, type LabelType } from './Label';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Form; textarea
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const TextareaUI = (
|
|
11
|
+
p: TextareaType &
|
|
12
|
+
LabelType & { height: number; virtualizerRef?: React.Ref<HTMLDivElement>; labelComponent?: React.ComponentType<LabelType> },
|
|
13
|
+
) => {
|
|
14
|
+
const {
|
|
15
|
+
id,
|
|
16
|
+
className,
|
|
17
|
+
borderRadiusClassName,
|
|
18
|
+
preset,
|
|
19
|
+
autoFocus,
|
|
20
|
+
focusStyle,
|
|
21
|
+
name,
|
|
22
|
+
autoComplete,
|
|
23
|
+
spellCheck,
|
|
24
|
+
allowClearIfLocked,
|
|
25
|
+
label,
|
|
26
|
+
placeholder,
|
|
27
|
+
info,
|
|
28
|
+
onChange,
|
|
29
|
+
onInput,
|
|
30
|
+
onKeyDown,
|
|
31
|
+
onFocus,
|
|
32
|
+
onBlur,
|
|
33
|
+
value,
|
|
34
|
+
formValues,
|
|
35
|
+
fullWidth,
|
|
36
|
+
locked,
|
|
37
|
+
disabled,
|
|
38
|
+
error,
|
|
39
|
+
labelClassName,
|
|
40
|
+
textareaClassName,
|
|
41
|
+
maxLength,
|
|
42
|
+
height,
|
|
43
|
+
virtualizerRef,
|
|
44
|
+
labelComponent: Label = DefaultLabel,
|
|
45
|
+
} = p;
|
|
46
|
+
|
|
47
|
+
const minHeight = p.minHeight ?? 150; // Default minimum height
|
|
48
|
+
const htmlFor = getHtmlFor(id, name);
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div className={cn('form_el', fullWidth ? 'fs' : '', preset, className, error ? 'error' : '', `focus_${focusStyle || 'shadow'}`)}>
|
|
52
|
+
{!label ? null : (
|
|
53
|
+
<Label
|
|
54
|
+
htmlFor={htmlFor}
|
|
55
|
+
info={info}
|
|
56
|
+
iconName={locked && allowClearIfLocked && formValues ? 'locked' : undefined}
|
|
57
|
+
labelClassName={labelClassName}
|
|
58
|
+
>
|
|
59
|
+
{label}
|
|
60
|
+
</Label>
|
|
61
|
+
)}
|
|
62
|
+
|
|
63
|
+
<div className='rel'>
|
|
64
|
+
<div
|
|
65
|
+
ref={virtualizerRef}
|
|
66
|
+
className='tx_virtualizer'
|
|
67
|
+
aria-hidden='true'
|
|
68
|
+
>
|
|
69
|
+
{value}
|
|
70
|
+
</div>
|
|
71
|
+
<textarea
|
|
72
|
+
style={{ height, minHeight }}
|
|
73
|
+
className={cn('form_input bl of rel w_f', borderRadiusClassName ?? 'r_sm', disabled ? 'disabled' : '', textareaClassName)}
|
|
74
|
+
id={htmlFor}
|
|
75
|
+
aria-label={p['aria-label']}
|
|
76
|
+
name={name}
|
|
77
|
+
placeholder={placeholder}
|
|
78
|
+
value={value || ''}
|
|
79
|
+
maxLength={maxLength}
|
|
80
|
+
disabled={disabled || locked}
|
|
81
|
+
// biome-ignore lint/a11y/noAutofocus: Preserve explicit autofocus requested by the existing form flow.
|
|
82
|
+
autoFocus={autoFocus}
|
|
83
|
+
autoComplete={autoComplete}
|
|
84
|
+
spellCheck={spellCheck}
|
|
85
|
+
onFocus={onFocus}
|
|
86
|
+
onBlur={onBlur}
|
|
87
|
+
onInput={onInput && ((e) => onInput(e, name))}
|
|
88
|
+
onChange={onChange && ((e) => onChange(e, name))}
|
|
89
|
+
onKeyDown={onKeyDown && ((e) => onKeyDown(e, name))}
|
|
90
|
+
/>
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export { TextareaUI as Textarea };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
+
import type { ComponentType, ReactNode, Ref } from 'react';
|
|
3
|
+
import type { InputTimeProps, TimeFormErrors, TimeFormValues } from '../modules/TimeInput.types';
|
|
4
|
+
import { getHtmlFor } from './FormUI';
|
|
5
|
+
import { Label as DefaultLabel, type LabelType } from './Label';
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Render the existing time input layout using values, events and accessories supplied by its owner.
|
|
9
|
+
*/
|
|
10
|
+
export const TimeInputUI = (
|
|
11
|
+
p: InputTimeProps & {
|
|
12
|
+
timeFormValues: TimeFormValues;
|
|
13
|
+
timeErrors: TimeFormErrors;
|
|
14
|
+
periodControl: ReactNode;
|
|
15
|
+
containerRef?: Ref<HTMLDivElement>;
|
|
16
|
+
onCompositeBlur?: React.FocusEventHandler<HTMLDivElement>;
|
|
17
|
+
labelComponent?: ComponentType<LabelType>;
|
|
18
|
+
onChangeTime: (event: React.ChangeEvent<HTMLInputElement>, field: 'hours' | 'minutes') => void;
|
|
19
|
+
},
|
|
20
|
+
) => {
|
|
21
|
+
const {
|
|
22
|
+
id,
|
|
23
|
+
name,
|
|
24
|
+
className,
|
|
25
|
+
alertCount,
|
|
26
|
+
preset,
|
|
27
|
+
focusStyle,
|
|
28
|
+
autoFocus,
|
|
29
|
+
spellCheck,
|
|
30
|
+
allowClearIfLocked,
|
|
31
|
+
label,
|
|
32
|
+
info,
|
|
33
|
+
onKeyDown,
|
|
34
|
+
fullWidth,
|
|
35
|
+
locked,
|
|
36
|
+
disabled,
|
|
37
|
+
focused,
|
|
38
|
+
error,
|
|
39
|
+
labelClassName,
|
|
40
|
+
inputClassName,
|
|
41
|
+
borderRadiusClassName,
|
|
42
|
+
children,
|
|
43
|
+
timeFormValues,
|
|
44
|
+
timeErrors,
|
|
45
|
+
periodControl,
|
|
46
|
+
containerRef,
|
|
47
|
+
onCompositeBlur,
|
|
48
|
+
onBlur,
|
|
49
|
+
onChangeTime,
|
|
50
|
+
labelComponent: LabelComponent = DefaultLabel,
|
|
51
|
+
} = p;
|
|
52
|
+
const htmlFor = getHtmlFor(id, name);
|
|
53
|
+
const labelIconName = locked && allowClearIfLocked && p.setFormValues ? 'lock' : undefined;
|
|
54
|
+
return (
|
|
55
|
+
<div
|
|
56
|
+
ref={containerRef}
|
|
57
|
+
onBlurCapture={onCompositeBlur}
|
|
58
|
+
className={cn(
|
|
59
|
+
'form_el rel',
|
|
60
|
+
preset,
|
|
61
|
+
`focus_${focusStyle || 'shadow'}`,
|
|
62
|
+
fullWidth ? 'fs' : '',
|
|
63
|
+
className,
|
|
64
|
+
error ? 'error' : '',
|
|
65
|
+
focused ? 'focused' : '',
|
|
66
|
+
)}
|
|
67
|
+
>
|
|
68
|
+
{!label ? null : (
|
|
69
|
+
<LabelComponent
|
|
70
|
+
htmlFor={htmlFor}
|
|
71
|
+
info={info}
|
|
72
|
+
iconName={labelIconName}
|
|
73
|
+
labelClassName={labelClassName}
|
|
74
|
+
>
|
|
75
|
+
{label}
|
|
76
|
+
</LabelComponent>
|
|
77
|
+
)}
|
|
78
|
+
|
|
79
|
+
<div className="rel h_item">
|
|
80
|
+
{(['hours', null, 'minutes'] as const).map((field, index) => {
|
|
81
|
+
if (field === null) {
|
|
82
|
+
return (
|
|
83
|
+
<span
|
|
84
|
+
key={index}
|
|
85
|
+
className="mx_5"
|
|
86
|
+
>
|
|
87
|
+
:
|
|
88
|
+
</span>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const isHours = field === 'hours';
|
|
93
|
+
return (
|
|
94
|
+
<input
|
|
95
|
+
key={field}
|
|
96
|
+
className={cn(
|
|
97
|
+
'form_input',
|
|
98
|
+
timeErrors[field] ? 'error' : '',
|
|
99
|
+
borderRadiusClassName ?? 'r_sm',
|
|
100
|
+
inputClassName,
|
|
101
|
+
'w_70',
|
|
102
|
+
// Use .cl_md for faded color for "disabled" status,
|
|
103
|
+
// but we're combining "Edit" and "Create" forms together now,
|
|
104
|
+
// So I prefer if everything is not-faded.
|
|
105
|
+
// disabled ? 'disabled cl_md' : '',
|
|
106
|
+
disabled ? 'disabled' : '',
|
|
107
|
+
)}
|
|
108
|
+
id={isHours ? htmlFor : `${htmlFor}-minutes`}
|
|
109
|
+
name={`${name}_${field}`}
|
|
110
|
+
aria-invalid={error || timeErrors[field] || undefined}
|
|
111
|
+
type="number"
|
|
112
|
+
min={isHours ? 1 : 0}
|
|
113
|
+
max={isHours ? 12 : 59}
|
|
114
|
+
step={1}
|
|
115
|
+
placeholder="--"
|
|
116
|
+
value={timeFormValues[field] || ''}
|
|
117
|
+
disabled={disabled || locked}
|
|
118
|
+
// biome-ignore lint/a11y/noAutofocus: Preserve explicit autofocus requested by the existing form flow.
|
|
119
|
+
autoFocus={autoFocus && isHours}
|
|
120
|
+
autoComplete="off"
|
|
121
|
+
spellCheck={spellCheck}
|
|
122
|
+
maxLength={2}
|
|
123
|
+
onBlur={onBlur}
|
|
124
|
+
onChange={(e) => onChangeTime(e, field as 'hours' | 'minutes')}
|
|
125
|
+
onKeyDown={onKeyDown && ((e) => onKeyDown(e, name, field))}
|
|
126
|
+
/>
|
|
127
|
+
);
|
|
128
|
+
})}
|
|
129
|
+
|
|
130
|
+
{periodControl}
|
|
131
|
+
|
|
132
|
+
{!alertCount ? null : (
|
|
133
|
+
<span className="alert_ct bg_err ft_xxs v_center unsel r lh_1">{alertCount < 100 ? alertCount : '99+'}</span>
|
|
134
|
+
)}
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
{children}
|
|
138
|
+
</div>
|
|
139
|
+
);
|
|
140
|
+
};
|