idea-react 3.0.0-alpha.1 → 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 +86 -46
- package/dist/DatePickerPlugin-CpGuQRsi.js +1 -0
- package/dist/DatePickerPlugin-DB3nnslN.mjs +1 -0
- package/dist/index.d.mts +1069 -245
- package/dist/index.d.ts +1069 -245
- 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 +4 -2
- 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 +73 -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 +59 -0
- package/source/Form/Checkbox.tsx +78 -0
- package/source/Form/ChipInput.tsx +125 -0
- package/source/Form/Chips.tsx +69 -0
- package/source/Form/Combobox.tsx +374 -0
- package/source/Form/Control.tsx +94 -0
- package/source/Form/DatePicker.tsx +280 -0
- package/source/Form/DatePickerPlugin.ts +37 -0
- package/source/Form/Feedback.tsx +35 -0
- package/source/Form/FloatingLabel.tsx +32 -0
- package/source/Form/InputGroup.tsx +173 -0
- package/source/Form/OTP.tsx +141 -0
- package/source/Form/PasswordStrength.tsx +183 -0
- package/source/Form/Plugin.tsx +53 -0
- package/source/Form/Primitives.tsx +88 -0
- package/source/Form/Radio.tsx +43 -0
- package/source/Form/Range.tsx +116 -0
- package/source/Form/Switch.tsx +58 -0
- package/source/Form/index.ts +16 -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 +31 -6
- 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 +65 -27
- package/source/ToggleButton.tsx +21 -7
- package/source/Toggler.tsx +108 -0
- package/source/Tooltip.tsx +6 -1
- package/source/index.ts +16 -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
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type OtpInput from 'bootstrap/js/src/otp-input.js';
|
|
4
|
+
import classNames from 'classnames';
|
|
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
|
+
));
|
|
140
|
+
|
|
141
|
+
OTPInput.displayName = 'OTPInput';
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { Component, ComponentPropsWithoutRef, forwardRef, Ref } from 'react';
|
|
5
|
+
|
|
6
|
+
export type PasswordStrengthLevel = 'weak' | 'fair' | 'good' | 'strong';
|
|
7
|
+
|
|
8
|
+
export interface PasswordStrengthProps extends ComponentPropsWithoutRef<'div'> {
|
|
9
|
+
input?: string | HTMLInputElement | null;
|
|
10
|
+
variant?: 'segments' | 'bar';
|
|
11
|
+
minLength?: number;
|
|
12
|
+
messages?: Partial<Record<PasswordStrengthLevel, string>>;
|
|
13
|
+
weights?: Record<string, number>;
|
|
14
|
+
thresholds?: number[];
|
|
15
|
+
scorer?: (password: string) => number;
|
|
16
|
+
strength?: PasswordStrengthLevel;
|
|
17
|
+
showText?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface PasswordStrengthComponentProps extends PasswordStrengthProps {
|
|
21
|
+
forwardedRef?: Ref<HTMLDivElement>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface StrengthInstance {
|
|
25
|
+
dispose(): void;
|
|
26
|
+
getStrength(): string | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const levels: PasswordStrengthLevel[] = ['weak', 'fair', 'good', 'strong'];
|
|
30
|
+
|
|
31
|
+
class PasswordStrengthComponent extends Component<PasswordStrengthComponentProps> {
|
|
32
|
+
private meter?: HTMLDivElement;
|
|
33
|
+
private instance?: StrengthInstance;
|
|
34
|
+
private instanceElement?: HTMLDivElement;
|
|
35
|
+
private passwordInput?: HTMLInputElement;
|
|
36
|
+
private mounted = false;
|
|
37
|
+
private revision = 0;
|
|
38
|
+
|
|
39
|
+
componentDidMount() {
|
|
40
|
+
this.mounted = true;
|
|
41
|
+
this.initialize();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
componentDidUpdate(previousProps: PasswordStrengthProps) {
|
|
45
|
+
if (
|
|
46
|
+
previousProps.input !== this.props.input ||
|
|
47
|
+
previousProps.minLength !== this.props.minLength ||
|
|
48
|
+
previousProps.messages !== this.props.messages ||
|
|
49
|
+
previousProps.weights !== this.props.weights ||
|
|
50
|
+
previousProps.thresholds !== this.props.thresholds ||
|
|
51
|
+
previousProps.scorer !== this.props.scorer ||
|
|
52
|
+
previousProps.variant !== this.props.variant ||
|
|
53
|
+
previousProps.strength !== this.props.strength ||
|
|
54
|
+
previousProps.showText !== this.props.showText
|
|
55
|
+
) {
|
|
56
|
+
this.dispose();
|
|
57
|
+
this.initialize();
|
|
58
|
+
} else if (this.props.strength === undefined) this.handleInput();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
componentWillUnmount() {
|
|
62
|
+
this.mounted = false;
|
|
63
|
+
this.dispose();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private initialize = async () => {
|
|
67
|
+
const revision = ++this.revision;
|
|
68
|
+
const element = this.meter;
|
|
69
|
+
if (!element || this.props.strength !== undefined) return;
|
|
70
|
+
|
|
71
|
+
const { default: Strength } = await import('bootstrap/js/src/strength.js');
|
|
72
|
+
const { input, minLength, messages, weights, thresholds, scorer } = this.props;
|
|
73
|
+
const config = {
|
|
74
|
+
...(input !== undefined && { input }),
|
|
75
|
+
...(minLength !== undefined && { minLength }),
|
|
76
|
+
...(messages !== undefined && {
|
|
77
|
+
messages: { ...Strength.Default.messages, ...messages }
|
|
78
|
+
}),
|
|
79
|
+
...(weights !== undefined && { weights }),
|
|
80
|
+
...(thresholds !== undefined && { thresholds }),
|
|
81
|
+
...(scorer !== undefined && { scorer })
|
|
82
|
+
};
|
|
83
|
+
if (!this.mounted || this.meter !== element || revision !== this.revision) return;
|
|
84
|
+
|
|
85
|
+
this.instanceElement = element;
|
|
86
|
+
this.instance = Strength.getOrCreateInstance(element, config);
|
|
87
|
+
this.passwordInput =
|
|
88
|
+
typeof input === 'string'
|
|
89
|
+
? document.querySelector<HTMLInputElement>(input) || undefined
|
|
90
|
+
: input ||
|
|
91
|
+
element.parentElement?.querySelector<HTMLInputElement>(
|
|
92
|
+
'input[type="password"]'
|
|
93
|
+
) ||
|
|
94
|
+
undefined;
|
|
95
|
+
this.passwordInput?.addEventListener('input', this.handleInput);
|
|
96
|
+
this.passwordInput?.addEventListener('change', this.handleInput);
|
|
97
|
+
this.handleInput();
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
private handleInput = () => {
|
|
101
|
+
const strength = this.instance?.getStrength();
|
|
102
|
+
const levelIndex = strength ? levels.indexOf(strength as PasswordStrengthLevel) + 1 : 0;
|
|
103
|
+
const element = this.instanceElement;
|
|
104
|
+
|
|
105
|
+
element?.setAttribute('aria-valuenow', String(levelIndex));
|
|
106
|
+
element?.setAttribute('aria-valuetext', strength || 'Empty');
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
private dispose = () => {
|
|
110
|
+
this.revision++;
|
|
111
|
+
this.passwordInput?.removeEventListener('input', this.handleInput);
|
|
112
|
+
this.passwordInput?.removeEventListener('change', this.handleInput);
|
|
113
|
+
this.instance?.dispose();
|
|
114
|
+
this.instance = undefined;
|
|
115
|
+
this.instanceElement = undefined;
|
|
116
|
+
this.passwordInput = undefined;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
private setMeterRef = (element: HTMLDivElement | null) => {
|
|
120
|
+
this.meter = element || undefined;
|
|
121
|
+
const { forwardedRef } = this.props;
|
|
122
|
+
|
|
123
|
+
if (typeof forwardedRef === 'function') forwardedRef(element);
|
|
124
|
+
else if (forwardedRef) forwardedRef.current = element;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
render() {
|
|
128
|
+
const {
|
|
129
|
+
className,
|
|
130
|
+
input: _input,
|
|
131
|
+
minLength: _minLength,
|
|
132
|
+
messages: _messages,
|
|
133
|
+
weights: _weights,
|
|
134
|
+
thresholds: _thresholds,
|
|
135
|
+
scorer: _scorer,
|
|
136
|
+
forwardedRef: _forwardedRef,
|
|
137
|
+
variant = 'segments',
|
|
138
|
+
strength,
|
|
139
|
+
showText = true,
|
|
140
|
+
...props
|
|
141
|
+
} = this.props;
|
|
142
|
+
const isBar = variant === 'bar';
|
|
143
|
+
const levelIndex = strength ? levels.indexOf(strength) + 1 : 0;
|
|
144
|
+
|
|
145
|
+
return (
|
|
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
|
+
</>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export const PasswordStrength = forwardRef<HTMLDivElement, PasswordStrengthProps>(
|
|
180
|
+
(props, forwardedRef) => <PasswordStrengthComponent {...props} forwardedRef={forwardedRef} />
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
PasswordStrength.displayName = 'PasswordStrength';
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
|
+
|
|
4
|
+
export type FormProps = ComponentPropsWithRef<'form'> & {
|
|
5
|
+
validated?: boolean;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const Form: FC<FormProps> = ({ className, validated, ...props }) => (
|
|
9
|
+
<form {...props} className={classNames(validated && 'was-validated', className)} />
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
Form.displayName = 'Form';
|
|
13
|
+
|
|
14
|
+
export type FormFieldsetProps = ComponentPropsWithRef<'fieldset'>;
|
|
15
|
+
|
|
16
|
+
export const FormFieldset: FC<FormFieldsetProps> = props => <fieldset {...props} />;
|
|
17
|
+
|
|
18
|
+
FormFieldset.displayName = 'FormFieldset';
|
|
19
|
+
|
|
20
|
+
export type FormFieldProps = ComponentPropsWithRef<'div'> & {
|
|
21
|
+
card?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const FormField: FC<FormFieldProps> = ({ className, card, ...props }) => (
|
|
25
|
+
<div {...props} className={classNames('form-field', card && 'form-field-card', className)} />
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
FormField.displayName = 'FormField';
|
|
29
|
+
|
|
30
|
+
export type FormGroupProps = ComponentPropsWithRef<'div'>;
|
|
31
|
+
|
|
32
|
+
export const FormGroup: FC<FormGroupProps> = ({ className, ...props }) => (
|
|
33
|
+
<div {...props} className={classNames('form-group', className)} />
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
FormGroup.displayName = 'FormGroup';
|
|
37
|
+
|
|
38
|
+
export type FormFieldContentProps = ComponentPropsWithRef<'div'>;
|
|
39
|
+
|
|
40
|
+
export const FormFieldContent: FC<FormFieldContentProps> = ({ className, ...props }) => (
|
|
41
|
+
<div {...props} className={classNames('form-field-content', className)} />
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
FormFieldContent.displayName = 'FormFieldContent';
|
|
45
|
+
|
|
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
|
+
/>
|
|
71
|
+
);
|
|
72
|
+
|
|
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';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
|
+
|
|
4
|
+
import type { ComponentTheme } from '../Button';
|
|
5
|
+
import { Checkbox, CheckboxProps } from './Checkbox';
|
|
6
|
+
import { FormValidationProps } from './Primitives';
|
|
7
|
+
|
|
8
|
+
export type RadioProps = Omit<ComponentPropsWithRef<'input'>, 'type' | 'size'> &
|
|
9
|
+
FormValidationProps & {
|
|
10
|
+
size?: 'sm' | 'lg';
|
|
11
|
+
theme?: ComponentTheme;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const Radio: FC<RadioProps> = ({ className, size, theme, validation, ...props }) => (
|
|
15
|
+
<input
|
|
16
|
+
{...props}
|
|
17
|
+
type="radio"
|
|
18
|
+
aria-invalid={validation ? validation === 'invalid' : props['aria-invalid']}
|
|
19
|
+
className={classNames(
|
|
20
|
+
'radio',
|
|
21
|
+
size && `radio-${size}`,
|
|
22
|
+
theme && `theme-${theme}`,
|
|
23
|
+
validation && `is-${validation}`,
|
|
24
|
+
className
|
|
25
|
+
)}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
Radio.displayName = 'Radio';
|
|
30
|
+
|
|
31
|
+
export type FormCheckProps = CheckboxProps &
|
|
32
|
+
Pick<ComponentPropsWithRef<'input'>, 'ref'> & {
|
|
33
|
+
type?: 'checkbox' | 'radio';
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const FormCheck: FC<FormCheckProps> = ({ type = 'checkbox', indeterminate, ...props }) =>
|
|
37
|
+
type === 'checkbox' ? (
|
|
38
|
+
<Checkbox {...props} indeterminate={indeterminate} />
|
|
39
|
+
) : (
|
|
40
|
+
<Radio {...props} />
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
FormCheck.displayName = 'FormCheck';
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type Range from 'bootstrap/js/src/range.js';
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
import { ComponentPropsWithoutRef, CSSProperties, forwardRef, Ref } from 'react';
|
|
6
|
+
|
|
7
|
+
import { ComponentTheme } from '../Button';
|
|
8
|
+
import { FormPlugin } from './Plugin';
|
|
9
|
+
import { FormValidationProps } from './Primitives';
|
|
10
|
+
|
|
11
|
+
export type FormRangeProps = Omit<ComponentPropsWithoutRef<'input'>, 'type'> &
|
|
12
|
+
FormValidationProps & {
|
|
13
|
+
bubble?: boolean;
|
|
14
|
+
theme?: ComponentTheme;
|
|
15
|
+
formatter?: (value: number) => string;
|
|
16
|
+
wrapperClassName?: string;
|
|
17
|
+
onValueChange?: (value: number) => unknown;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
interface FormRangeComponentProps extends FormRangeProps {
|
|
21
|
+
forwardedRef?: Ref<HTMLInputElement>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class FormRangeComponent extends FormPlugin<FormRangeComponentProps, Range> {
|
|
25
|
+
protected configurationChanged = (previous: FormRangeComponentProps) =>
|
|
26
|
+
previous.bubble !== this.props.bubble ||
|
|
27
|
+
previous.formatter !== this.props.formatter ||
|
|
28
|
+
previous.list !== this.props.list ||
|
|
29
|
+
previous.min !== this.props.min ||
|
|
30
|
+
previous.max !== this.props.max;
|
|
31
|
+
|
|
32
|
+
protected load = async () => {
|
|
33
|
+
const { default: Plugin } = await import('bootstrap/js/src/range.js');
|
|
34
|
+
const { bubble = false, formatter = null } = this.props;
|
|
35
|
+
|
|
36
|
+
return (element: HTMLDivElement) => {
|
|
37
|
+
element.addEventListener('changed.bs.range', this.handleValueChange);
|
|
38
|
+
|
|
39
|
+
return Plugin.getOrCreateInstance(element, { bubble, formatter });
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
protected updatePlugin = () => this.instance?.update();
|
|
44
|
+
|
|
45
|
+
protected dispose() {
|
|
46
|
+
this.element.current?.removeEventListener('changed.bs.range', this.handleValueChange);
|
|
47
|
+
super.dispose();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private handleValueChange = (event: Event) =>
|
|
51
|
+
this.props.onValueChange?.((event as Event & { value: number }).value);
|
|
52
|
+
|
|
53
|
+
render() {
|
|
54
|
+
const {
|
|
55
|
+
className,
|
|
56
|
+
wrapperClassName,
|
|
57
|
+
min = 0,
|
|
58
|
+
max = 100,
|
|
59
|
+
value,
|
|
60
|
+
defaultValue,
|
|
61
|
+
bubble,
|
|
62
|
+
theme,
|
|
63
|
+
formatter: _formatter,
|
|
64
|
+
onValueChange: _onValueChange,
|
|
65
|
+
forwardedRef,
|
|
66
|
+
validation,
|
|
67
|
+
style,
|
|
68
|
+
...props
|
|
69
|
+
} = this.props;
|
|
70
|
+
const currentValue = Number(value ?? defaultValue ?? (Number(min) + Number(max)) / 2);
|
|
71
|
+
const fill =
|
|
72
|
+
Number(max) <= Number(min)
|
|
73
|
+
? 0
|
|
74
|
+
: Math.max(
|
|
75
|
+
0,
|
|
76
|
+
Math.min(1, (currentValue - Number(min)) / (Number(max) - Number(min)))
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div
|
|
81
|
+
ref={this.element}
|
|
82
|
+
className={classNames(
|
|
83
|
+
'form-range',
|
|
84
|
+
theme && `theme-${theme}`,
|
|
85
|
+
validation && `is-${validation}`,
|
|
86
|
+
wrapperClassName
|
|
87
|
+
)}
|
|
88
|
+
data-bs-bubble={bubble || undefined}
|
|
89
|
+
style={{ '--bs-range-fill': fill } as CSSProperties}
|
|
90
|
+
>
|
|
91
|
+
<input
|
|
92
|
+
{...props}
|
|
93
|
+
ref={forwardedRef}
|
|
94
|
+
type="range"
|
|
95
|
+
min={min}
|
|
96
|
+
max={max}
|
|
97
|
+
value={value}
|
|
98
|
+
defaultValue={defaultValue}
|
|
99
|
+
aria-invalid={validation ? validation === 'invalid' : props['aria-invalid']}
|
|
100
|
+
className={classNames(
|
|
101
|
+
'form-range-input',
|
|
102
|
+
validation && `is-${validation}`,
|
|
103
|
+
className
|
|
104
|
+
)}
|
|
105
|
+
style={style}
|
|
106
|
+
/>
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export const FormRange = forwardRef<HTMLInputElement, FormRangeProps>((props, forwardedRef) => (
|
|
113
|
+
<FormRangeComponent {...props} forwardedRef={forwardedRef} />
|
|
114
|
+
));
|
|
115
|
+
|
|
116
|
+
FormRange.displayName = 'FormRange';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef, CSSProperties, FC, PropsWithChildren } from 'react';
|
|
3
|
+
|
|
4
|
+
import type { ComponentTheme } from '../Button';
|
|
5
|
+
import { FormValidationProps } from './Primitives';
|
|
6
|
+
|
|
7
|
+
export type FormSwitchProps = Omit<ComponentPropsWithRef<'label'>, 'children'> &
|
|
8
|
+
PropsWithChildren<
|
|
9
|
+
FormValidationProps & {
|
|
10
|
+
inputProps?: Omit<ComponentPropsWithRef<'input'>, 'type'>;
|
|
11
|
+
size?: 'sm' | 'lg';
|
|
12
|
+
theme?: ComponentTheme;
|
|
13
|
+
width?: string;
|
|
14
|
+
indicatorWidth?: string;
|
|
15
|
+
}
|
|
16
|
+
>;
|
|
17
|
+
|
|
18
|
+
export const FormSwitch: FC<FormSwitchProps> = ({
|
|
19
|
+
className,
|
|
20
|
+
inputProps,
|
|
21
|
+
size,
|
|
22
|
+
theme,
|
|
23
|
+
validation,
|
|
24
|
+
width,
|
|
25
|
+
indicatorWidth,
|
|
26
|
+
style,
|
|
27
|
+
children,
|
|
28
|
+
...props
|
|
29
|
+
}) => (
|
|
30
|
+
<label
|
|
31
|
+
{...props}
|
|
32
|
+
className={classNames(
|
|
33
|
+
'switch',
|
|
34
|
+
size && `switch-${size}`,
|
|
35
|
+
theme && `theme-${theme}`,
|
|
36
|
+
validation && `is-${validation}`,
|
|
37
|
+
className
|
|
38
|
+
)}
|
|
39
|
+
style={
|
|
40
|
+
{
|
|
41
|
+
'--bs-switch-width': width,
|
|
42
|
+
'--bs-switch-indicator-width': indicatorWidth,
|
|
43
|
+
...style
|
|
44
|
+
} as CSSProperties
|
|
45
|
+
}
|
|
46
|
+
>
|
|
47
|
+
<input
|
|
48
|
+
role="switch"
|
|
49
|
+
{...inputProps}
|
|
50
|
+
type="checkbox"
|
|
51
|
+
aria-invalid={validation ? validation === 'invalid' : inputProps?.['aria-invalid']}
|
|
52
|
+
className={classNames(validation && `is-${validation}`, inputProps?.className)}
|
|
53
|
+
/>
|
|
54
|
+
{children}
|
|
55
|
+
</label>
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
FormSwitch.displayName = 'FormSwitch';
|