@jsb188/form 0.0.0-stage → 1.1.12

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.
Files changed (64) hide show
  1. package/README.md +132 -2
  2. package/css/form.css +2 -0
  3. package/package.json +40 -5
  4. package/src/assets.d.ts +1 -0
  5. package/src/libs/SchemaForm.tsx +158 -0
  6. package/src/libs/SchemaForm.types.ts +165 -0
  7. package/src/libs/defineForm.ts +11 -0
  8. package/src/libs/rules.ts +126 -0
  9. package/src/libs/useField.ts +16 -0
  10. package/src/libs/useSchemaForm.helpers.ts +71 -0
  11. package/src/libs/useSchemaForm.ts +268 -0
  12. package/src/libs/validation.ts +42 -0
  13. package/src/main.ts +40 -0
  14. package/src/modules/FieldLabel.tsx +28 -0
  15. package/src/modules/Form-Input.tsx +2 -0
  16. package/src/modules/Form-Line.tsx +126 -0
  17. package/src/modules/Form.helpers.ts +12 -0
  18. package/src/modules/Form.tsx +14 -0
  19. package/src/modules/FormItem.tsx +117 -0
  20. package/src/modules/FormOptions.tsx +12 -0
  21. package/src/modules/FormUI.tsx +2 -0
  22. package/src/modules/Input.tsx +16 -0
  23. package/src/modules/InputClick.tsx +48 -0
  24. package/src/modules/InputWithButton.tsx +37 -0
  25. package/src/modules/ListItemForm.tsx +345 -0
  26. package/src/modules/ListItemForm.types.ts +50 -0
  27. package/src/modules/PasswordInput.tsx +36 -0
  28. package/src/modules/PopOverInput.tsx +75 -0
  29. package/src/modules/SMSCodeInput.tsx +118 -0
  30. package/src/modules/SchemaField.tsx +104 -0
  31. package/src/modules/Select.tsx +163 -0
  32. package/src/modules/Textarea.tsx +33 -0
  33. package/src/modules/TimeInput.helpers.ts +73 -0
  34. package/src/modules/TimeInput.tsx +159 -0
  35. package/src/modules/TimeInput.types.ts +43 -0
  36. package/src/modules/UploadInput.tsx +141 -0
  37. package/src/modules/composeFormInput.tsx +88 -0
  38. package/src/types/form.ts +65 -0
  39. package/src/ui/ContentEditable.tsx +70 -0
  40. package/src/ui/Form.types.ts +138 -0
  41. package/src/ui/FormOptions.tsx +125 -0
  42. package/src/ui/FormUI.tsx +237 -0
  43. package/src/ui/Input.helpers.ts +7 -0
  44. package/src/ui/Input.tsx +199 -0
  45. package/src/ui/Input.types.ts +48 -0
  46. package/src/ui/InputButtons.tsx +41 -0
  47. package/src/ui/InputControls.tsx +68 -0
  48. package/src/ui/Label.tsx +46 -0
  49. package/src/ui/LineForm.tsx +34 -0
  50. package/src/ui/SMSCodeInput.tsx +51 -0
  51. package/src/ui/Select.tsx +33 -0
  52. package/src/ui/Textarea.tsx +96 -0
  53. package/src/ui/TimeInput.tsx +140 -0
  54. package/tests/controller.test.tsx +336 -0
  55. package/tests/controls.test.tsx +261 -0
  56. package/tests/schema-form.test.tsx +303 -0
  57. package/tests/settings-definitions.test.ts +129 -0
  58. package/tests/sms-input.test.tsx +131 -0
  59. package/tests/time-input.test.tsx +395 -0
  60. package/tests/types.ts +102 -0
  61. package/tests/upload-input.test.tsx +114 -0
  62. package/tests/validation.test.ts +65 -0
  63. package/tsconfig.json +13 -0
  64. package/vitest.config.ts +8 -0
@@ -0,0 +1,125 @@
1
+ import { cn } from '@jsb188/app/utils/string.ts';
2
+ import { Icon } from '@jsb188/react-web/svgs/Icon';
3
+ import { InlineBlockLabel } from '@jsb188/react-web/ui/Button';
4
+ import { memo } from 'react';
5
+ import type { OptionType, OptionsType } from './Form.types';
6
+ import { getHtmlFor } from './FormUI';
7
+ import { Label as DefaultLabel, type LabelType } from './Label';
8
+
9
+ /**
10
+ * Form options; item
11
+ */
12
+
13
+ const FormOptionItem = memo((p: OptionType) => {
14
+ const { value, text, className, iconName, name, index, checked, disabled, hideCheckIcon, rightLabel, rightLabelColor, onChange } = p;
15
+ const htmlFor = getHtmlFor(index?.toString(), name);
16
+
17
+ return (
18
+ // biome-ignore lint/a11y/useSemanticElements: Preserve the existing radio option wrapper, which contains a native input.
19
+ <div
20
+ role="button"
21
+ tabIndex={0}
22
+ onClick={disabled ? undefined : (e: React.MouseEvent<HTMLDivElement>) => onChange(e, name, value!)}
23
+ className={cn(
24
+ 'r_xs h_item px_4 py_4 my_1',
25
+ disabled ? 'cl_darker_2' : 'link cl_df bg_active_hv',
26
+ // checked ? 'cl_df' : disabled ? 'cl_darker_2' : 'cl_md',
27
+ className,
28
+ )}
29
+ >
30
+ <label
31
+ className="h_item f"
32
+ htmlFor={htmlFor}
33
+ >
34
+ <input
35
+ id={htmlFor}
36
+ type="radio"
37
+ value={value || '?'}
38
+ defaultChecked={checked}
39
+ disabled={disabled}
40
+ />
41
+ {iconName ? (
42
+ <span className="w_25 mr_xs h_center">
43
+ <Icon name={iconName} />
44
+ </span>
45
+ ) : (
46
+ <span className="w_2" />
47
+ )}
48
+
49
+ <span className="shift_down">{text}</span>
50
+ </label>
51
+
52
+ {!rightLabel ? null : (
53
+ <InlineBlockLabel
54
+ as="span"
55
+ color={rightLabelColor}
56
+ text={rightLabel}
57
+ />
58
+ )}
59
+
60
+ {checked && !hideCheckIcon ? <Icon name="check" /> : null}
61
+ </div>
62
+ );
63
+ });
64
+
65
+ FormOptionItem.displayName = 'FormOptionItem';
66
+
67
+ /**
68
+ * Form options
69
+ */
70
+
71
+ export function FormOptionsUI(p: OptionsType & { labelComponent?: React.ComponentType<LabelType> }) {
72
+ const {
73
+ labelComponent: Label = DefaultLabel,
74
+ className,
75
+ name,
76
+ locked,
77
+ label,
78
+ labelClassName,
79
+ info,
80
+ options,
81
+ value,
82
+ disabled,
83
+ onChange,
84
+ } = p;
85
+ // const htmlFor = getHtmlFor(id, name);
86
+
87
+ let labelIconName: string | undefined;
88
+ if (locked) {
89
+ labelIconName = 'locked';
90
+ }
91
+
92
+ return (
93
+ <fieldset className={className}>
94
+ {!label ? null : (
95
+ <div className="form_el">
96
+ <Label
97
+ // htmlFor={htmlFor}
98
+ info={info}
99
+ iconName={labelIconName}
100
+ labelClassName={labelClassName}
101
+ >
102
+ {label}
103
+ </Label>
104
+ </div>
105
+ )}
106
+
107
+ {/* y-margin has to be 1 less because of 1px margin in items */}
108
+ <div className="bd_1 bd_lt px_5 py_4 r_sm">
109
+ {options.map((option, i) => (
110
+ <FormOptionItem
111
+ key={option.value}
112
+ {...option}
113
+ name={name}
114
+ index={i}
115
+ disabled={disabled || locked || option.disabled}
116
+ checked={value === option.value}
117
+ onChange={onChange}
118
+ />
119
+ ))}
120
+ </div>
121
+ </fieldset>
122
+ );
123
+ }
124
+
125
+ export { FormOptionsUI as FormOptions };
@@ -0,0 +1,237 @@
1
+ export type { InputPresetName, InputFocusStyle } from './Input.types';
2
+ import { cn } from '@jsb188/app/utils/string.ts';
3
+ import { memo, type ReactNode } from 'react';
4
+
5
+ /**
6
+ * Types
7
+ */
8
+
9
+ export type ToggleSwitchSize = 'xxs' | 'xs' | 'sm' | 'df' | 'md' | 'lg' | 'xl';
10
+
11
+ export {
12
+ ColorInputSwatch,
13
+ InputWithPostfix,
14
+ type ColorInputSwatchProps,
15
+ type InputWithPostfixProps,
16
+ } from './InputControls';
17
+
18
+ export interface ToggleSwitchProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'color' | 'size' | 'type'> {
19
+ color?: string;
20
+ size?: ToggleSwitchSize;
21
+ }
22
+
23
+ /**
24
+ * Render a native checkbox as an accessible, color-aware toggle switch.
25
+ */
26
+
27
+ export const ToggleSwitch = memo((p: ToggleSwitchProps) => {
28
+ const { className, color = 'primary', size = 'df', ...inputProps } = p;
29
+
30
+ return (
31
+ <input
32
+ {...inputProps}
33
+ aria-checked={Boolean(inputProps.checked)}
34
+ type="checkbox"
35
+ role="switch"
36
+ className={cn('toggle_switch pill r unsel', `av_${size}`, inputProps.checked ? `bg_${color} ol_${color}_focus` : '', className)}
37
+ />
38
+ );
39
+ });
40
+
41
+ ToggleSwitch.displayName = 'ToggleSwitch';
42
+
43
+ /**
44
+ * Container with label and any form element inside
45
+ */
46
+
47
+ interface FormElementProps {
48
+ htmlFor?: string;
49
+ label: string;
50
+ children: React.ReactNode;
51
+ className?: string;
52
+ labelClassName?: string;
53
+ forceClickId?: string;
54
+ }
55
+
56
+ export const FormElement = memo((p: FormElementProps) => {
57
+ const { htmlFor, label, children, className, labelClassName, forceClickId } = p;
58
+
59
+ return (
60
+ <label
61
+ htmlFor={htmlFor}
62
+ className={cn('h_spread mb_xs', className)}
63
+ onClick={
64
+ !forceClickId
65
+ ? undefined
66
+ : () => {
67
+ const input = document.getElementById(forceClickId) as HTMLInputElement | null;
68
+ if (input) {
69
+ input.click();
70
+ }
71
+ }
72
+ }
73
+ >
74
+ {/* <span className={cn('ft_bold cl_lt', labelClassName)}> */}
75
+ <span className={cn(labelClassName, 'ellip')}>{label}</span>
76
+ {children}
77
+ </label>
78
+ );
79
+ });
80
+
81
+ FormElement.displayName = 'FormElement';
82
+
83
+ export { getHtmlFor } from './Input.helpers';
84
+
85
+ /**
86
+ * Display helper; label & value
87
+ */
88
+
89
+ export const LabelValue = memo(
90
+ (p: {
91
+ label: React.ReactNode;
92
+ value?: React.ReactNode;
93
+ className?: string;
94
+ labelClassName?: string;
95
+ valueClassName?: string;
96
+ nullClassName?: string;
97
+ separator?: React.ReactNode;
98
+ placeholder?: React.ReactNode;
99
+ }) => {
100
+ const {
101
+ label,
102
+ value,
103
+ className,
104
+ labelClassName,
105
+ valueClassName,
106
+ separator = ':',
107
+ placeholder = '-',
108
+ nullClassName = 'cl_darker_2',
109
+ } = p;
110
+
111
+ return (
112
+ <div className={cn('h_left py_5', className)}>
113
+ <div className={cn('ft_medium no_shrink', labelClassName)}>
114
+ {label}
115
+ {separator}
116
+ </div>
117
+
118
+ <div className={cn(valueClassName, !value && nullClassName)}>{value || placeholder}</div>
119
+ </div>
120
+ );
121
+ },
122
+ );
123
+
124
+ LabelValue.displayName = 'LabelValue';
125
+
126
+ /**
127
+ * Form; label & value
128
+ */
129
+
130
+ export { Label, type LabelType } from './Label';
131
+
132
+ /**
133
+ * Fieldset with a simple legend label and nested form content.
134
+ */
135
+
136
+ export const Fieldset = memo(
137
+ (p: {
138
+ label: React.ReactNode;
139
+ children: React.ReactNode;
140
+ className?: string;
141
+ labelClassName?: string;
142
+ backgroundClassName?: string;
143
+ }) => {
144
+ const { label, children, className, labelClassName, backgroundClassName } = p;
145
+
146
+ return (
147
+ <fieldset className={cn('form_cnt r_sm', className, backgroundClassName ?? 'bd_1 bd_lt')}>
148
+ {label ? <legend className={cn('ft_sm cl_md', labelClassName)}>{label}</legend> : <div className="h_8" />}
149
+
150
+ {children}
151
+ </fieldset>
152
+ );
153
+ },
154
+ );
155
+
156
+ Fieldset.displayName = 'Fieldset';
157
+
158
+ /**
159
+ * Form section title
160
+ */
161
+
162
+ export const FormSectionTitle = memo((p: { title?: string; description?: string }) => {
163
+ const { title, description } = p;
164
+ return (
165
+ <div className="mt_md cl_lt">
166
+ {title && <p className="ft_xl ls_4">{title}</p>}
167
+ {description && <p className="-mt_5 pb_10 lh_3">{description}</p>}
168
+ </div>
169
+ );
170
+ });
171
+
172
+ FormSectionTitle.displayName = 'FormSectionTitle';
173
+
174
+ /**
175
+ * Form break
176
+ */
177
+
178
+ export const FormBreak = memo((p: { children?: string; className?: string; heightClassName?: string; colorClassName?: string }) => {
179
+ const { children, className, heightClassName, colorClassName } = p;
180
+ return (
181
+ <div className={cn('pattern_texture rel h_center', colorClassName ?? 'strong_bf', heightClassName ?? 'h_10', className)}>
182
+ {children ? <span className="text ft_sm bg rel z2 px_xs lh_1 cl_bd">{children}</span> : null}
183
+ </div>
184
+ );
185
+ });
186
+
187
+ FormBreak.displayName = 'FormBreak';
188
+
189
+ /**
190
+ * Line form; one compact labelled row
191
+ */
192
+
193
+ export interface LineRowProps {
194
+ children: ReactNode;
195
+ label: string;
196
+ // With a control name the label targets that control; without one the row is display-only.
197
+ name?: string;
198
+ className?: string;
199
+ labelClassName?: string;
200
+ // Width utility class of the label column; defaults to w_85.
201
+ labelWidthClassName?: string;
202
+ }
203
+
204
+ /*
205
+ * Render one compact labelled row of a line form: a fixed-width label followed by the row's content.
206
+ */
207
+ export const LineRow = memo((p: LineRowProps) => {
208
+ const { children, label, name, className, labelClassName, labelWidthClassName } = p;
209
+ const labelClass = cn('py_10 cl_md', labelWidthClassName ?? 'w_85', labelClassName);
210
+
211
+ return (
212
+ <div className={cn('bd_b_1 bd_lt h_item', className)}>
213
+ {name ? (
214
+ <label
215
+ className={labelClass}
216
+ htmlFor={name}
217
+ >
218
+ {label}:
219
+ </label>
220
+ ) : (
221
+ <span className={labelClass}>{label}:</span>
222
+ )}
223
+ {children}
224
+ </div>
225
+ );
226
+ });
227
+
228
+ LineRow.displayName = 'LineRow';
229
+
230
+ /*
231
+ * Render one selected item as a chip inside a line form row.
232
+ */
233
+ export const LineChip = memo((p: { children: ReactNode; className?: string }) => (
234
+ <span className={cn('rel ls_5 h_32 max_w_200 px_8 py_3 h_item r_sm bg_alt bd_1 bd_lt', p.className)}>{p.children}</span>
235
+ ));
236
+
237
+ LineChip.displayName = 'LineChip';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Build the shared input ID used by the input and its label.
3
+ */
4
+
5
+ export function getHtmlFor(id?: string, name?: string) {
6
+ return name ? `${name}-${id || 'form'}` : id;
7
+ }
@@ -0,0 +1,199 @@
1
+ import { cn } from '@jsb188/app/utils/string.ts';
2
+ import { Icon } from '@jsb188/react-web/svgs/Icon';
3
+ import { createElement } from 'react';
4
+ import type { InputPresentationProps } from './Input.types';
5
+ import type { InputType } from './Form.types';
6
+ import { getHtmlFor } from './Input.helpers';
7
+ import { Label as DefaultLabel, type LabelType } from './Label';
8
+
9
+ /**
10
+ * Form; input
11
+ */
12
+
13
+ export function InputUI(
14
+ p: Partial<InputPresentationProps> &
15
+ Pick<InputType, 'formValues' | 'setFormValues'> &
16
+ Omit<LabelType, 'children' | 'paddingClassName'> & {
17
+ disabledButClickable?: boolean;
18
+ InputOverlayComponent?: React.ReactNode;
19
+ labelPaddingClassName?: string;
20
+ labelComponent?: React.ComponentType<LabelType>;
21
+ onClearLocked?: () => void;
22
+ },
23
+ ) {
24
+ const {
25
+ ariaLabel,
26
+ id,
27
+ className,
28
+ alertCount,
29
+ preset,
30
+ focusStyle,
31
+ autoFocus,
32
+ name,
33
+ type,
34
+ autoComplete,
35
+ spellCheck,
36
+ allowClearIfLocked,
37
+ label,
38
+ placeholder,
39
+ info,
40
+ step,
41
+ min,
42
+ max,
43
+ onChange,
44
+ onInput,
45
+ onKeyDown,
46
+ onFocus,
47
+ onBlur,
48
+ onClick,
49
+ value,
50
+ onClearLocked,
51
+ labelComponent: Label = DefaultLabel,
52
+ fullWidth,
53
+ locked,
54
+ disabled,
55
+ disabledButClickable,
56
+ InputOverlayComponent,
57
+ editable,
58
+ focused,
59
+ error,
60
+ RightIconComponent,
61
+ fontSizeClassName,
62
+ labelClassName,
63
+ labelPaddingClassName,
64
+ inputClassName,
65
+ rightIconClassName,
66
+ borderRadiusClassName,
67
+ maxLength,
68
+ hideMaxLength,
69
+ rightText,
70
+ getter,
71
+ children,
72
+ } = p;
73
+ const htmlFor = getHtmlFor(id, name);
74
+ const inputValue = (getter ? getter(value) : value) ?? '';
75
+
76
+ let onClickRight: React.MouseEventHandler<HTMLButtonElement> | undefined;
77
+ let rightIconName: string | undefined;
78
+ let labelIconName: string | undefined;
79
+
80
+ if (locked && allowClearIfLocked && onClearLocked) {
81
+ onClickRight = onClearLocked;
82
+ rightIconName = 'circle-x';
83
+ labelIconName = 'locked';
84
+ } else if (p.rightIconName) {
85
+ rightIconName = p.rightIconName;
86
+ onClickRight = p.onClickRight;
87
+ } else if (locked) {
88
+ rightIconName = 'locked';
89
+ }
90
+
91
+ const hasRight = !!(rightIconName || RightIconComponent);
92
+ const isLarge = preset === 'fill_large';
93
+ const onClickItem = onClick ? (e: React.MouseEvent) => onClick(e, name!) : undefined;
94
+
95
+ return (
96
+ <div
97
+ className={cn(
98
+ 'form_el no_link rel',
99
+ preset,
100
+ `focus_${focusStyle || 'shadow'}`,
101
+ fullWidth ? 'fs' : '',
102
+ hasRight ? 'has_r' : '',
103
+ className,
104
+ error ? 'error' : '',
105
+ focused ? 'focused' : '',
106
+ disabled || locked ? 'disabled' : '',
107
+ )}
108
+ >
109
+ {!label ? null : (
110
+ <Label
111
+ htmlFor={htmlFor}
112
+ rightText={hideMaxLength !== true && maxLength != null ? `${String(inputValue).length}/${maxLength}` : rightText}
113
+ info={info}
114
+ iconName={labelIconName}
115
+ fontSizeClassName={fontSizeClassName ?? (preset === 'tiny' ? 'ft_xs' : undefined)}
116
+ labelClassName={labelClassName}
117
+ paddingClassName={labelPaddingClassName}
118
+ >
119
+ {label}
120
+ </Label>
121
+ )}
122
+ <div
123
+ onClick={onClickItem}
124
+ className={cn('rel', onClick ? 'link form_el_hv' : '', locked ? 'strong_bf pattern_stripes' : '')}
125
+ >
126
+ <input
127
+ suppressHydrationWarning={p.suppressHydrationWarning}
128
+ aria-label={ariaLabel}
129
+ className={cn(
130
+ 'w_f form_input rel',
131
+ borderRadiusClassName ?? 'r_sm',
132
+ inputClassName,
133
+ // Use .cl_md for faded color for "disabled" status,
134
+ // but we're combining "Edit" and "Create" forms together now,
135
+ // So I prefer if everything is not-faded.
136
+ // disabled ? 'disabled cl_md' : '',
137
+ editable === false ? 'cl_md' : disabled ? 'disabled' : '',
138
+ // Need .error on both container + input
139
+ error ? 'error' : '',
140
+ )}
141
+ id={htmlFor}
142
+ name={name}
143
+ type={type || 'text'}
144
+ step={step}
145
+ min={min}
146
+ max={max}
147
+ placeholder={placeholder || ''}
148
+ value={inputValue}
149
+ disabled={disabled || locked || editable === false || disabledButClickable}
150
+ // biome-ignore lint/a11y/noAutofocus: Preserve explicit autofocus requested by the existing form flow.
151
+ autoFocus={autoFocus}
152
+ autoComplete={autoComplete || 'off'}
153
+ spellCheck={spellCheck}
154
+ maxLength={maxLength}
155
+ onFocus={onFocus}
156
+ onBlur={onBlur}
157
+ onInput={onInput && ((e) => onInput(e, name!))}
158
+ onChange={onChange && ((e) => onChange(e, name!))}
159
+ onKeyDown={onKeyDown && ((e) => onKeyDown(e, name!))}
160
+ />
161
+
162
+ {!rightIconName
163
+ ? RightIconComponent
164
+ : createElement(
165
+ onClickRight ? 'button' : 'span',
166
+ {
167
+ type: onClickRight ? 'button' : undefined,
168
+ 'aria-label': p.rightIconAriaLabel,
169
+ className: cn(
170
+ 'form_el_r cl_lt v_center',
171
+ borderRadiusClassName ?? 'r_sm',
172
+ onClickRight ? 'btn' : '',
173
+ isLarge ? 'ic_df' : onClick ? 'pointer' : '',
174
+ rightIconClassName,
175
+ ),
176
+ onClick: onClickRight,
177
+ },
178
+ <Icon name={rightIconName} />,
179
+ )}
180
+
181
+ {!alertCount ? null : (
182
+ <span className="alert_ct bg_err ft_xxs v_center unsel r lh_1">{alertCount < 100 ? alertCount : '99+'}</span>
183
+ )}
184
+
185
+ {onClickItem && (
186
+ // This prevents <input> from disabling click handlers;
187
+ // thus allowing entire input + right icon to be a clickable area as one.
188
+ <div className="abs_full pointer" />
189
+ )}
190
+
191
+ {InputOverlayComponent}
192
+ </div>
193
+
194
+ {children}
195
+ </div>
196
+ );
197
+ }
198
+
199
+ export { InputUI as Input };
@@ -0,0 +1,48 @@
1
+ export type InputPresetName = 'none' | 'fill' | 'fill_large' | 'inside_outline' | 'lighter' | 'subtle' | 'tiny';
2
+ export type InputFocusStyle = 'outline' | 'shadow';
3
+
4
+ export interface InputPresentationProps {
5
+ ariaLabel?: string;
6
+ id?: string;
7
+ type?: 'text' | 'email' | 'password' | 'number' | 'tel' | 'url' | string;
8
+ alertCount?: number;
9
+ autoFocus?: boolean;
10
+ autoComplete?: 'on' | 'off' | string;
11
+ spellCheck?: boolean;
12
+ suppressHydrationWarning?: boolean;
13
+ name: string;
14
+ step?: number;
15
+ min?: number;
16
+ max?: number;
17
+ getter?: (value?: unknown) => string;
18
+ allowClearIfLocked?: boolean;
19
+ locked?: boolean;
20
+ disabled?: boolean;
21
+ editable?: boolean;
22
+ focused?: boolean;
23
+ error?: boolean;
24
+ fullWidth?: boolean;
25
+ className?: string;
26
+ inputClassName?: string;
27
+ borderRadiusClassName?: string;
28
+ preset?: InputPresetName;
29
+ focusStyle?: InputFocusStyle;
30
+ maxLength?: number;
31
+ hideMaxLength?: boolean;
32
+ onFocus?: React.FocusEventHandler<HTMLInputElement>;
33
+ onBlur?: React.FocusEventHandler<HTMLInputElement>;
34
+ onChange?: (e: React.ChangeEvent<HTMLInputElement>, name: string) => void;
35
+ onInput?: (e: React.FormEvent, name: string) => void;
36
+ onKeyDown?: (e: React.KeyboardEvent, name: string) => void;
37
+ onClick?: (e: React.MouseEvent, name: string) => void;
38
+ onSubmit?: (e: React.MouseEvent, name: string) => void;
39
+ value?: string | number | null;
40
+ label?: string;
41
+ placeholder?: string;
42
+ RightIconComponent?: React.ReactNode;
43
+ rightIconName?: string;
44
+ rightIconAriaLabel?: string;
45
+ rightIconClassName?: string;
46
+ onClickRight?: (e: React.MouseEvent) => void;
47
+ children?: React.ReactNode;
48
+ }
@@ -0,0 +1,41 @@
1
+ import { cn } from '@jsb188/app/utils/string.ts';
2
+ import { Button } from '@jsb188/react-web/ui/Button';
3
+ import { Icon } from '@jsb188/react-web/svgs/Icon';
4
+ import type { SideInputButtonProps, InputRightButtonProps } from './Form.types';
5
+
6
+ /**
7
+ * Side button meant to be placed next to an input (e.g. search bar)
8
+ */
9
+
10
+ export function SideInputButton(p: SideInputButtonProps) {
11
+ const { href, className, alertCount, iconName, text, onClick, selected, disabled, offsetRight } = p;
12
+ return (
13
+ <a
14
+ role={href ? undefined : 'button'}
15
+ className={cn('v_center mt_df mb_sm r_sm form_input_btn', className, selected ? 'bg_main' : 'cl_md', offsetRight ? 'r' : '')}
16
+ href={href}
17
+ onClick={disabled ? undefined : onClick}
18
+ >
19
+ {iconName ? <Icon name={iconName} /> : null}
20
+ {text ? <strong>{text}</strong> : null}
21
+ {!alertCount ? null : (
22
+ <span className="alert_ct bg_err ft_xxs v_center unsel r lh_1">{alertCount < 100 ? alertCount : '99+'}</span>
23
+ )}
24
+ </a>
25
+ );
26
+ }
27
+
28
+ /**
29
+ * Inline button meant to be placed inside <Input /> on the right;
30
+ * e.g. "Enter with arrow" button in a large search input.
31
+ */
32
+
33
+ export function InputRightButton(p: InputRightButtonProps) {
34
+ const { className, ...rest } = p;
35
+ return (
36
+ <Button
37
+ {...rest}
38
+ className={cn('form_el_inline_btn', className)}
39
+ />
40
+ );
41
+ }