idea-react 3.0.0-beta.0 → 3.0.0-beta.1
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/AGENTS.md +11 -2
- package/ReadMe.md +62 -49
- package/dist/DatePickerPlugin-CpGuQRsi.js +1 -0
- package/dist/DatePickerPlugin-DB3nnslN.mjs +1 -0
- package/dist/index.d.mts +1116 -442
- package/dist/index.d.ts +1116 -442
- package/dist/index.js +16 -16
- package/dist/index.mjs +15 -15
- package/dist/rolldown-runtime-5iZMYShA.js +1 -0
- package/dist/style.css +69 -66
- package/package.json +1 -1
- package/source/Accordion.tsx +137 -0
- package/source/Alert.tsx +138 -0
- package/source/Avatar.tsx +7 -1
- package/source/Badge.tsx +2 -0
- package/source/Breadcrumb.tsx +36 -0
- package/source/Button.tsx +40 -5
- package/source/ButtonGroup.tsx +10 -1
- package/source/Card.tsx +65 -4
- package/source/Carousel/index.tsx +391 -0
- package/source/Carousel/model.ts +113 -0
- package/source/Carousel/scroll.ts +79 -0
- package/source/Collapse.tsx +178 -0
- package/source/Drawer.tsx +127 -30
- package/source/{CodeBlock.tsx → Extension/CodeBlock/index.tsx} +23 -5
- package/source/Extension/CodeBlock/style.module.css +3 -0
- package/source/{Dialog.tsx → Extension/Dialog.tsx} +10 -6
- package/source/{EditorHTML.tsx → Extension/EditorHTML.tsx} +1 -1
- package/source/{HorizontalMarquee → Extension/HorizontalMarquee}/index.module.less +1 -3
- package/source/{Icon.tsx → Extension/Icon.tsx} +1 -7
- package/source/{Loading.tsx → Extension/Loading.tsx} +8 -3
- package/source/{MonthCalendar.tsx → Extension/MonthCalendar.tsx} +3 -3
- package/source/{Nameplate.tsx → Extension/Nameplate.tsx} +1 -1
- package/source/Extension/OverlayBox.tsx +280 -0
- package/source/{PageNav.tsx → Extension/PageNav.tsx} +27 -9
- package/source/{ScrollNav → Extension/ScrollNav}/index.tsx +1 -1
- package/source/Extension/Select.tsx +127 -0
- package/source/{ShareBox.tsx → Extension/ShareBox.tsx} +1 -1
- package/source/{SpinnerButton.tsx → Extension/SpinnerButton.tsx} +2 -2
- package/source/{TableSpinner.tsx → Extension/TableSpinner.tsx} +1 -1
- package/source/{Timeline → Extension/Timeline}/index.tsx +1 -1
- package/source/{UserRank → Extension/UserRank}/index.tsx +4 -4
- package/source/Extension/index.ts +27 -0
- package/source/Form/Adorn.tsx +32 -11
- package/source/Form/Checkbox.tsx +11 -6
- package/source/Form/ChipInput.tsx +125 -0
- package/source/Form/Chips.tsx +42 -24
- package/source/Form/Combobox.tsx +337 -72
- package/source/Form/Control.tsx +50 -15
- package/source/Form/DatePicker.tsx +231 -40
- package/source/Form/DatePickerPlugin.ts +37 -0
- package/source/Form/Feedback.tsx +10 -4
- package/source/Form/FloatingLabel.tsx +24 -7
- package/source/Form/InputGroup.tsx +155 -5
- package/source/Form/OTP.tsx +138 -45
- package/source/Form/PasswordStrength.tsx +43 -17
- package/source/Form/Plugin.tsx +53 -0
- package/source/Form/Primitives.tsx +51 -9
- package/source/Form/Radio.tsx +20 -28
- package/source/Form/Range.tsx +103 -52
- package/source/Form/Switch.tsx +30 -7
- package/source/Form/index.ts +1 -0
- package/source/Grid.tsx +4 -0
- package/source/ListGroup.tsx +28 -15
- package/source/Menu.tsx +226 -17
- package/source/NativeDialog/index.tsx +109 -5
- package/source/Nav.tsx +18 -2
- package/source/NavOverflow/index.tsx +307 -0
- package/source/NavOverflow/model.ts +21 -0
- package/source/Navbar.tsx +18 -3
- package/source/Overlay.ts +163 -1
- package/source/Pagination.tsx +92 -0
- package/source/Placeholder.tsx +66 -0
- package/source/Popover.tsx +7 -2
- package/source/Progress/index.tsx +76 -0
- package/source/Progress/style.module.css +15 -0
- package/source/ScrollSpy/index.tsx +365 -0
- package/source/ScrollSpy/model.ts +17 -0
- package/source/Spinner.tsx +10 -0
- package/source/Stepper.tsx +85 -0
- package/source/Tab.tsx +248 -0
- package/source/Toast.tsx +46 -14
- package/source/ToggleButton.tsx +21 -7
- package/source/Toggler.tsx +108 -0
- package/source/Tooltip.tsx +6 -1
- package/source/index.ts +15 -27
- package/source/OverlayBox.tsx +0 -208
- package/source/Select.tsx +0 -95
- /package/source/{ClickBoundary.tsx → Extension/ClickBoundary.tsx} +0 -0
- /package/source/{Countdown.tsx → Extension/Countdown.tsx} +0 -0
- /package/source/{Editor.tsx → Extension/Editor.tsx} +0 -0
- /package/source/{HorizontalMarquee → Extension/HorizontalMarquee}/index.tsx +0 -0
- /package/source/{LiveTSX.tsx → Extension/LiveTSX.tsx} +0 -0
- /package/source/{ScrollNav → Extension/ScrollNav}/Scroller.tsx +0 -0
- /package/source/{ScrollNav → Extension/ScrollNav}/index.module.less +0 -0
- /package/source/{TextTruncate → Extension/TextTruncate}/Content.tsx +0 -0
- /package/source/{TextTruncate → Extension/TextTruncate}/index.tsx +0 -0
- /package/source/{Time.tsx → Extension/Time.tsx} +0 -0
- /package/source/{TimeDistance.tsx → Extension/TimeDistance.tsx} +0 -0
- /package/source/{Timeline → Extension/Timeline}/index.module.less +0 -0
- /package/source/{TypeEcho → Extension/TypeEcho}/Content.tsx +0 -0
- /package/source/{TypeEcho → Extension/TypeEcho}/index.tsx +0 -0
- /package/source/{UserRank → Extension/UserRank}/Address.tsx +0 -0
- /package/source/{UserRank → Extension/UserRank}/index.module.less +0 -0
- /package/source/{VerticalMarquee → Extension/VerticalMarquee}/index.module.less +0 -0
- /package/source/{VerticalMarquee → Extension/VerticalMarquee}/index.tsx +0 -0
- /package/source/{ZodiacBar.tsx → Extension/ZodiacBar.tsx} +0 -0
package/source/Form/OTP.tsx
CHANGED
|
@@ -1,48 +1,141 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type OtpInput from 'bootstrap/js/src/otp-input.js';
|
|
1
4
|
import classNames from 'classnames';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
5
|
+
import { ComponentPropsWithoutRef, forwardRef, Ref } from 'react';
|
|
6
|
+
|
|
7
|
+
import { FormPlugin } from './Plugin';
|
|
8
|
+
import { FormValidationProps } from './Primitives';
|
|
9
|
+
|
|
10
|
+
export type OTPInputProps = Omit<ComponentPropsWithoutRef<'input'>, 'type' | 'maxLength' | 'size'> &
|
|
11
|
+
FormValidationProps & {
|
|
12
|
+
length: number;
|
|
13
|
+
type?: 'numeric' | 'alphanumeric' | 'alpha';
|
|
14
|
+
mask?: boolean;
|
|
15
|
+
groups?: number[];
|
|
16
|
+
separator?: string;
|
|
17
|
+
connected?: boolean;
|
|
18
|
+
size?: 'sm' | 'lg';
|
|
19
|
+
wrapperClassName?: string;
|
|
20
|
+
onComplete?: (value: string) => unknown;
|
|
21
|
+
onValueChange?: (value: string) => unknown;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
interface OTPInputComponentProps extends OTPInputProps {
|
|
25
|
+
forwardedRef?: Ref<HTMLInputElement>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
class OTPInputComponent extends FormPlugin<OTPInputComponentProps, OtpInput> {
|
|
29
|
+
protected configurationChanged = (previous: OTPInputComponentProps) =>
|
|
30
|
+
previous.length !== this.props.length ||
|
|
31
|
+
previous.type !== this.props.type ||
|
|
32
|
+
previous.mask !== this.props.mask ||
|
|
33
|
+
previous.separator !== this.props.separator ||
|
|
34
|
+
JSON.stringify(previous.groups) !== JSON.stringify(this.props.groups);
|
|
35
|
+
|
|
36
|
+
protected load = async () => {
|
|
37
|
+
const { default: Plugin } = await import('bootstrap/js/src/otp-input.js');
|
|
38
|
+
const {
|
|
39
|
+
length,
|
|
40
|
+
type = 'numeric',
|
|
41
|
+
mask = false,
|
|
42
|
+
groups = null,
|
|
43
|
+
separator = '·'
|
|
44
|
+
} = this.props;
|
|
45
|
+
|
|
46
|
+
return (element: HTMLDivElement) => {
|
|
47
|
+
element.addEventListener('complete.bs.otpInput', this.handleComplete);
|
|
48
|
+
element.addEventListener('input.bs.otpInput', this.handleValueChange);
|
|
49
|
+
|
|
50
|
+
return Plugin.getOrCreateInstance(element, { length, type, mask, groups, separator });
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
protected updatePlugin() {
|
|
55
|
+
const { value } = this.props;
|
|
56
|
+
const slots = this.element.current?.querySelector('.otp-slots');
|
|
57
|
+
|
|
58
|
+
slots?.classList.add('min-w-0', 'max-w-100');
|
|
59
|
+
|
|
60
|
+
for (const slot of slots?.querySelectorAll('.otp-slot') ?? [])
|
|
61
|
+
slot.classList.add('min-w-0');
|
|
62
|
+
|
|
63
|
+
if (value !== undefined && this.instance?.getValue() !== String(value))
|
|
64
|
+
this.instance?.setValue(String(value));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected dispose() {
|
|
68
|
+
this.element.current?.removeEventListener('complete.bs.otpInput', this.handleComplete);
|
|
69
|
+
this.element.current?.removeEventListener('input.bs.otpInput', this.handleValueChange);
|
|
70
|
+
super.dispose();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private handleComplete = (event: Event) =>
|
|
74
|
+
this.props.onComplete?.((event as Event & { value: string }).value);
|
|
75
|
+
|
|
76
|
+
private handleValueChange = (event: Event) =>
|
|
77
|
+
this.props.onValueChange?.((event as Event & { value: string }).value);
|
|
78
|
+
|
|
79
|
+
render() {
|
|
80
|
+
const {
|
|
81
|
+
className,
|
|
82
|
+
wrapperClassName,
|
|
83
|
+
length,
|
|
84
|
+
type = 'numeric',
|
|
85
|
+
mask,
|
|
86
|
+
groups,
|
|
87
|
+
separator,
|
|
88
|
+
connected,
|
|
89
|
+
size,
|
|
90
|
+
validation,
|
|
91
|
+
onComplete: _onComplete,
|
|
92
|
+
onValueChange: _onValueChange,
|
|
93
|
+
forwardedRef,
|
|
94
|
+
autoComplete = 'one-time-code',
|
|
95
|
+
...props
|
|
96
|
+
} = this.props;
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<div
|
|
100
|
+
ref={this.element}
|
|
101
|
+
className={classNames(
|
|
102
|
+
'otp min-w-0 max-w-100',
|
|
103
|
+
connected && 'otp-connected',
|
|
104
|
+
size && `otp-${size}`,
|
|
105
|
+
validation && `is-${validation}`,
|
|
106
|
+
wrapperClassName
|
|
107
|
+
)}
|
|
108
|
+
data-bs-otp=""
|
|
109
|
+
data-bs-length={length}
|
|
110
|
+
data-bs-type={type}
|
|
111
|
+
data-bs-mask={mask || undefined}
|
|
112
|
+
data-bs-groups={groups ? JSON.stringify(groups) : undefined}
|
|
113
|
+
data-bs-separator={separator}
|
|
114
|
+
>
|
|
115
|
+
<input
|
|
116
|
+
{...props}
|
|
117
|
+
ref={forwardedRef}
|
|
118
|
+
type="text"
|
|
119
|
+
maxLength={length}
|
|
120
|
+
autoComplete={autoComplete}
|
|
121
|
+
inputMode={type === 'numeric' ? 'numeric' : 'text'}
|
|
122
|
+
aria-invalid={validation ? validation === 'invalid' : props['aria-invalid']}
|
|
123
|
+
pattern={
|
|
124
|
+
type === 'numeric'
|
|
125
|
+
? '[0-9]*'
|
|
126
|
+
: type === 'alpha'
|
|
127
|
+
? '[A-Za-z]*'
|
|
128
|
+
: '[A-Za-z0-9]*'
|
|
129
|
+
}
|
|
130
|
+
className={classNames('otp-input', className)}
|
|
131
|
+
/>
|
|
132
|
+
</div>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export const OTPInput = forwardRef<HTMLInputElement, OTPInputProps>((props, forwardedRef) => (
|
|
138
|
+
<OTPInputComponent {...props} forwardedRef={forwardedRef} />
|
|
139
|
+
));
|
|
47
140
|
|
|
48
141
|
OTPInput.displayName = 'OTPInput';
|
|
@@ -13,6 +13,8 @@ export interface PasswordStrengthProps extends ComponentPropsWithoutRef<'div'> {
|
|
|
13
13
|
weights?: Record<string, number>;
|
|
14
14
|
thresholds?: number[];
|
|
15
15
|
scorer?: (password: string) => number;
|
|
16
|
+
strength?: PasswordStrengthLevel;
|
|
17
|
+
showText?: boolean;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
interface PasswordStrengthComponentProps extends PasswordStrengthProps {
|
|
@@ -32,6 +34,7 @@ class PasswordStrengthComponent extends Component<PasswordStrengthComponentProps
|
|
|
32
34
|
private instanceElement?: HTMLDivElement;
|
|
33
35
|
private passwordInput?: HTMLInputElement;
|
|
34
36
|
private mounted = false;
|
|
37
|
+
private revision = 0;
|
|
35
38
|
|
|
36
39
|
componentDidMount() {
|
|
37
40
|
this.mounted = true;
|
|
@@ -46,11 +49,13 @@ class PasswordStrengthComponent extends Component<PasswordStrengthComponentProps
|
|
|
46
49
|
previousProps.weights !== this.props.weights ||
|
|
47
50
|
previousProps.thresholds !== this.props.thresholds ||
|
|
48
51
|
previousProps.scorer !== this.props.scorer ||
|
|
49
|
-
previousProps.variant !== this.props.variant
|
|
52
|
+
previousProps.variant !== this.props.variant ||
|
|
53
|
+
previousProps.strength !== this.props.strength ||
|
|
54
|
+
previousProps.showText !== this.props.showText
|
|
50
55
|
) {
|
|
51
56
|
this.dispose();
|
|
52
57
|
this.initialize();
|
|
53
|
-
}
|
|
58
|
+
} else if (this.props.strength === undefined) this.handleInput();
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
componentWillUnmount() {
|
|
@@ -59,8 +64,9 @@ class PasswordStrengthComponent extends Component<PasswordStrengthComponentProps
|
|
|
59
64
|
}
|
|
60
65
|
|
|
61
66
|
private initialize = async () => {
|
|
67
|
+
const revision = ++this.revision;
|
|
62
68
|
const element = this.meter;
|
|
63
|
-
if (!element) return;
|
|
69
|
+
if (!element || this.props.strength !== undefined) return;
|
|
64
70
|
|
|
65
71
|
const { default: Strength } = await import('bootstrap/js/src/strength.js');
|
|
66
72
|
const { input, minLength, messages, weights, thresholds, scorer } = this.props;
|
|
@@ -74,7 +80,7 @@ class PasswordStrengthComponent extends Component<PasswordStrengthComponentProps
|
|
|
74
80
|
...(thresholds !== undefined && { thresholds }),
|
|
75
81
|
...(scorer !== undefined && { scorer })
|
|
76
82
|
};
|
|
77
|
-
if (!this.mounted || this.meter !== element) return;
|
|
83
|
+
if (!this.mounted || this.meter !== element || revision !== this.revision) return;
|
|
78
84
|
|
|
79
85
|
this.instanceElement = element;
|
|
80
86
|
this.instance = Strength.getOrCreateInstance(element, config);
|
|
@@ -101,6 +107,7 @@ class PasswordStrengthComponent extends Component<PasswordStrengthComponentProps
|
|
|
101
107
|
};
|
|
102
108
|
|
|
103
109
|
private dispose = () => {
|
|
110
|
+
this.revision++;
|
|
104
111
|
this.passwordInput?.removeEventListener('input', this.handleInput);
|
|
105
112
|
this.passwordInput?.removeEventListener('change', this.handleInput);
|
|
106
113
|
this.instance?.dispose();
|
|
@@ -128,24 +135,43 @@ class PasswordStrengthComponent extends Component<PasswordStrengthComponentProps
|
|
|
128
135
|
scorer: _scorer,
|
|
129
136
|
forwardedRef: _forwardedRef,
|
|
130
137
|
variant = 'segments',
|
|
138
|
+
strength,
|
|
139
|
+
showText = true,
|
|
131
140
|
...props
|
|
132
141
|
} = this.props;
|
|
133
142
|
const isBar = variant === 'bar';
|
|
143
|
+
const levelIndex = strength ? levels.indexOf(strength) + 1 : 0;
|
|
134
144
|
|
|
135
145
|
return (
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
<>
|
|
147
|
+
<div
|
|
148
|
+
{...props}
|
|
149
|
+
ref={this.setMeterRef}
|
|
150
|
+
className={classNames(isBar ? 'strength-bar' : 'strength', className)}
|
|
151
|
+
data-bs-strength={strength}
|
|
152
|
+
role="meter"
|
|
153
|
+
aria-valuemin={0}
|
|
154
|
+
aria-valuemax={levels.length}
|
|
155
|
+
aria-valuenow={levelIndex}
|
|
156
|
+
aria-valuetext={strength || 'Empty'}
|
|
157
|
+
>
|
|
158
|
+
{!isBar &&
|
|
159
|
+
levels.map((level, index) => (
|
|
160
|
+
<div
|
|
161
|
+
key={level}
|
|
162
|
+
className={classNames(
|
|
163
|
+
'strength-segment',
|
|
164
|
+
index < levelIndex && 'active'
|
|
165
|
+
)}
|
|
166
|
+
/>
|
|
167
|
+
))}
|
|
168
|
+
</div>
|
|
169
|
+
{showText && (
|
|
170
|
+
<span className="strength-text" data-bs-strength={strength}>
|
|
171
|
+
{strength && (this.props.messages?.[strength] ?? strength)}
|
|
172
|
+
</span>
|
|
173
|
+
)}
|
|
174
|
+
</>
|
|
149
175
|
);
|
|
150
176
|
}
|
|
151
177
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Component, createRef } from 'react';
|
|
4
|
+
|
|
5
|
+
interface Disposable {
|
|
6
|
+
dispose(): void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export abstract class FormPlugin<
|
|
10
|
+
P,
|
|
11
|
+
I extends Disposable,
|
|
12
|
+
E extends HTMLElement = HTMLDivElement
|
|
13
|
+
> extends Component<P> {
|
|
14
|
+
protected element = createRef<E>();
|
|
15
|
+
protected instance?: I;
|
|
16
|
+
private revision = 0;
|
|
17
|
+
|
|
18
|
+
protected abstract load(): Promise<(element: E) => I>;
|
|
19
|
+
protected abstract configurationChanged(previous: P): boolean;
|
|
20
|
+
|
|
21
|
+
protected updatePlugin() {}
|
|
22
|
+
|
|
23
|
+
componentDidMount() {
|
|
24
|
+
this.initialize();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
componentDidUpdate(previous: P) {
|
|
28
|
+
if (this.configurationChanged(previous)) {
|
|
29
|
+
this.dispose();
|
|
30
|
+
this.initialize();
|
|
31
|
+
} else this.updatePlugin();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
componentWillUnmount() {
|
|
35
|
+
this.dispose();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private initialize = async () => {
|
|
39
|
+
const revision = ++this.revision;
|
|
40
|
+
const create = await this.load();
|
|
41
|
+
|
|
42
|
+
if (revision !== this.revision || !this.element.current) return;
|
|
43
|
+
|
|
44
|
+
this.instance = create(this.element.current);
|
|
45
|
+
this.updatePlugin();
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
protected dispose() {
|
|
49
|
+
this.revision++;
|
|
50
|
+
this.instance?.dispose();
|
|
51
|
+
this.instance = undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
2
|
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
3
|
|
|
4
|
-
export type FormProps = ComponentPropsWithRef<'form'
|
|
4
|
+
export type FormProps = ComponentPropsWithRef<'form'> & {
|
|
5
|
+
validated?: boolean;
|
|
6
|
+
};
|
|
5
7
|
|
|
6
|
-
export const Form: FC<FormProps> =
|
|
8
|
+
export const Form: FC<FormProps> = ({ className, validated, ...props }) => (
|
|
9
|
+
<form {...props} className={classNames(validated && 'was-validated', className)} />
|
|
10
|
+
);
|
|
7
11
|
|
|
8
12
|
Form.displayName = 'Form';
|
|
9
13
|
|
|
@@ -13,10 +17,12 @@ export const FormFieldset: FC<FormFieldsetProps> = props => <fieldset {...props}
|
|
|
13
17
|
|
|
14
18
|
FormFieldset.displayName = 'FormFieldset';
|
|
15
19
|
|
|
16
|
-
export type FormFieldProps = ComponentPropsWithRef<'div'
|
|
20
|
+
export type FormFieldProps = ComponentPropsWithRef<'div'> & {
|
|
21
|
+
card?: boolean;
|
|
22
|
+
};
|
|
17
23
|
|
|
18
|
-
export const FormField: FC<FormFieldProps> = ({ className, ...props }) => (
|
|
19
|
-
<div {...props} className={classNames('form-field', className)} />
|
|
24
|
+
export const FormField: FC<FormFieldProps> = ({ className, card, ...props }) => (
|
|
25
|
+
<div {...props} className={classNames('form-field', card && 'form-field-card', className)} />
|
|
20
26
|
);
|
|
21
27
|
|
|
22
28
|
FormField.displayName = 'FormField';
|
|
@@ -37,10 +43,46 @@ export const FormFieldContent: FC<FormFieldContentProps> = ({ className, ...prop
|
|
|
37
43
|
|
|
38
44
|
FormFieldContent.displayName = 'FormFieldContent';
|
|
39
45
|
|
|
40
|
-
export
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
export interface FormValidationProps {
|
|
47
|
+
validation?: 'valid' | 'invalid';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type FormLabelProps = ComponentPropsWithRef<'label'> & {
|
|
51
|
+
plain?: boolean;
|
|
52
|
+
column?: boolean;
|
|
53
|
+
controlSize?: 'sm' | 'lg';
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const FormLabel: FC<FormLabelProps> = ({
|
|
57
|
+
className,
|
|
58
|
+
plain,
|
|
59
|
+
column,
|
|
60
|
+
controlSize,
|
|
61
|
+
...props
|
|
62
|
+
}) => (
|
|
63
|
+
<label
|
|
64
|
+
{...props}
|
|
65
|
+
className={classNames(
|
|
66
|
+
column ? 'col-form-label' : !plain && 'form-label',
|
|
67
|
+
column && controlSize && `col-form-label-${controlSize}`,
|
|
68
|
+
className
|
|
69
|
+
)}
|
|
70
|
+
/>
|
|
44
71
|
);
|
|
45
72
|
|
|
46
73
|
FormLabel.displayName = 'FormLabel';
|
|
74
|
+
|
|
75
|
+
export type FormLegendProps = ComponentPropsWithRef<'legend'> &
|
|
76
|
+
Pick<FormLabelProps, 'column' | 'controlSize'>;
|
|
77
|
+
|
|
78
|
+
export const FormLegend: FC<FormLegendProps> = ({ className, column, controlSize, ...props }) => (
|
|
79
|
+
<legend
|
|
80
|
+
{...props}
|
|
81
|
+
className={classNames(
|
|
82
|
+
column && 'col-form-label',
|
|
83
|
+
column && controlSize && `col-form-label-${controlSize}`,
|
|
84
|
+
className
|
|
85
|
+
)}
|
|
86
|
+
/>
|
|
87
|
+
);
|
|
88
|
+
FormLegend.displayName = 'FormLegend';
|
package/source/Form/Radio.tsx
CHANGED
|
@@ -2,20 +2,25 @@ import classNames from 'classnames';
|
|
|
2
2
|
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
3
|
|
|
4
4
|
import type { ComponentTheme } from '../Button';
|
|
5
|
+
import { Checkbox, CheckboxProps } from './Checkbox';
|
|
6
|
+
import { FormValidationProps } from './Primitives';
|
|
5
7
|
|
|
6
|
-
export type RadioProps = Omit<ComponentPropsWithRef<'input'>, 'type' | 'size'> &
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
export type RadioProps = Omit<ComponentPropsWithRef<'input'>, 'type' | 'size'> &
|
|
9
|
+
FormValidationProps & {
|
|
10
|
+
size?: 'sm' | 'lg';
|
|
11
|
+
theme?: ComponentTheme;
|
|
12
|
+
};
|
|
10
13
|
|
|
11
|
-
export const Radio: FC<RadioProps> = ({ className, size, theme, ...props }) => (
|
|
14
|
+
export const Radio: FC<RadioProps> = ({ className, size, theme, validation, ...props }) => (
|
|
12
15
|
<input
|
|
13
16
|
{...props}
|
|
14
17
|
type="radio"
|
|
18
|
+
aria-invalid={validation ? validation === 'invalid' : props['aria-invalid']}
|
|
15
19
|
className={classNames(
|
|
16
20
|
'radio',
|
|
17
21
|
size && `radio-${size}`,
|
|
18
22
|
theme && `theme-${theme}`,
|
|
23
|
+
validation && `is-${validation}`,
|
|
19
24
|
className
|
|
20
25
|
)}
|
|
21
26
|
/>
|
|
@@ -23,29 +28,16 @@ export const Radio: FC<RadioProps> = ({ className, size, theme, ...props }) => (
|
|
|
23
28
|
|
|
24
29
|
Radio.displayName = 'Radio';
|
|
25
30
|
|
|
26
|
-
export type FormCheckProps =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
+
export type FormCheckProps = CheckboxProps &
|
|
32
|
+
Pick<ComponentPropsWithRef<'input'>, 'ref'> & {
|
|
33
|
+
type?: 'checkbox' | 'radio';
|
|
34
|
+
};
|
|
31
35
|
|
|
32
|
-
export const FormCheck: FC<FormCheckProps> = ({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}) => (
|
|
39
|
-
<input
|
|
40
|
-
{...props}
|
|
41
|
-
type={type}
|
|
42
|
-
className={classNames(
|
|
43
|
-
type === 'checkbox' ? 'check' : 'radio',
|
|
44
|
-
size && `${type === 'checkbox' ? 'check' : 'radio'}-${size}`,
|
|
45
|
-
theme && `theme-${theme}`,
|
|
46
|
-
className
|
|
47
|
-
)}
|
|
48
|
-
/>
|
|
49
|
-
);
|
|
36
|
+
export const FormCheck: FC<FormCheckProps> = ({ type = 'checkbox', indeterminate, ...props }) =>
|
|
37
|
+
type === 'checkbox' ? (
|
|
38
|
+
<Checkbox {...props} indeterminate={indeterminate} />
|
|
39
|
+
) : (
|
|
40
|
+
<Radio {...props} />
|
|
41
|
+
);
|
|
50
42
|
|
|
51
43
|
FormCheck.displayName = 'FormCheck';
|