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,280 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { action, observable } from 'mobx';
|
|
5
|
+
import { observer } from 'mobx-react';
|
|
6
|
+
import {
|
|
7
|
+
cloneElement,
|
|
8
|
+
Component,
|
|
9
|
+
createRef,
|
|
10
|
+
FocusEvent,
|
|
11
|
+
HTMLAttributes,
|
|
12
|
+
isValidElement,
|
|
13
|
+
KeyboardEvent,
|
|
14
|
+
MouseEvent,
|
|
15
|
+
ReactElement,
|
|
16
|
+
ReactNode
|
|
17
|
+
} from 'react';
|
|
18
|
+
import { createPortal } from 'react-dom';
|
|
19
|
+
import { uniqueID } from 'web-utility';
|
|
20
|
+
|
|
21
|
+
import { FloatingOptions, FloatingPosition, OverlayContainer, OverlayPlacement } from '../Overlay';
|
|
22
|
+
import { Popover } from '../Popover';
|
|
23
|
+
import { Tooltip } from '../Tooltip';
|
|
24
|
+
|
|
25
|
+
export type OverlayTrigger = 'click' | 'focus' | 'hover';
|
|
26
|
+
|
|
27
|
+
export interface OverlayBoxProps extends Omit<
|
|
28
|
+
HTMLAttributes<HTMLSpanElement>,
|
|
29
|
+
'children' | 'title'
|
|
30
|
+
> {
|
|
31
|
+
title: ReactNode;
|
|
32
|
+
detail?: ReactNode;
|
|
33
|
+
placement?: OverlayPlacement;
|
|
34
|
+
responsivePlacement?: FloatingOptions['responsivePlacement'];
|
|
35
|
+
container?: OverlayContainer;
|
|
36
|
+
offset?: FloatingOptions['offset'];
|
|
37
|
+
padding?: number;
|
|
38
|
+
flip?: boolean;
|
|
39
|
+
trigger?: OverlayTrigger | OverlayTrigger[];
|
|
40
|
+
delay?: number | { show: number; hide: number };
|
|
41
|
+
overlayClassName?: string;
|
|
42
|
+
children: ReactElement<{ 'aria-describedby'?: string }>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@observer
|
|
46
|
+
export class OverlayBox extends Component<OverlayBoxProps> {
|
|
47
|
+
static displayName = 'OverlayBox';
|
|
48
|
+
|
|
49
|
+
@observable accessor open = false;
|
|
50
|
+
|
|
51
|
+
id = uniqueID();
|
|
52
|
+
root = createRef<HTMLSpanElement>();
|
|
53
|
+
overlay = createRef<HTMLDivElement>();
|
|
54
|
+
position = new FloatingPosition();
|
|
55
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
56
|
+
|
|
57
|
+
@action
|
|
58
|
+
setOpen = (open: boolean) => (this.open = open);
|
|
59
|
+
|
|
60
|
+
hide = () => {
|
|
61
|
+
clearTimeout(this.timer);
|
|
62
|
+
this.setOpen(false);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
setOpenAfterDelay = (open: boolean) => {
|
|
66
|
+
clearTimeout(this.timer);
|
|
67
|
+
|
|
68
|
+
const { delay } = this.props;
|
|
69
|
+
const timeout = typeof delay === 'number' ? delay : delay?.[open ? 'show' : 'hide'];
|
|
70
|
+
|
|
71
|
+
if (!timeout) return this.setOpen(open);
|
|
72
|
+
|
|
73
|
+
this.timer = setTimeout(() => this.setOpen(open), timeout);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
componentWillUnmount() {
|
|
77
|
+
document.removeEventListener('pointerdown', this.handleOutside);
|
|
78
|
+
clearTimeout(this.timer);
|
|
79
|
+
this.position.dispose();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
componentDidMount() {
|
|
83
|
+
document.addEventListener('pointerdown', this.handleOutside);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
componentDidUpdate(previous: OverlayBoxProps) {
|
|
87
|
+
const { open, root, overlay, props, position } = this;
|
|
88
|
+
const {
|
|
89
|
+
placement = 'top',
|
|
90
|
+
responsivePlacement,
|
|
91
|
+
offset = props.detail == null ? 8 : 12,
|
|
92
|
+
padding,
|
|
93
|
+
flip,
|
|
94
|
+
container
|
|
95
|
+
} = props;
|
|
96
|
+
|
|
97
|
+
if (!open) return position.dispose();
|
|
98
|
+
if (!root.current || !overlay.current) return;
|
|
99
|
+
if (
|
|
100
|
+
position.element !== overlay.current ||
|
|
101
|
+
previous.placement !== props.placement ||
|
|
102
|
+
previous.responsivePlacement !== responsivePlacement ||
|
|
103
|
+
previous.offset !== props.offset ||
|
|
104
|
+
previous.padding !== padding ||
|
|
105
|
+
previous.flip !== flip ||
|
|
106
|
+
previous.container !== container
|
|
107
|
+
)
|
|
108
|
+
position.attach(root.current, overlay.current, {
|
|
109
|
+
placement,
|
|
110
|
+
responsivePlacement,
|
|
111
|
+
offset,
|
|
112
|
+
padding,
|
|
113
|
+
flip
|
|
114
|
+
});
|
|
115
|
+
else position.update();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
contains = (target: EventTarget | null) =>
|
|
119
|
+
target instanceof Node &&
|
|
120
|
+
(!!this.root.current?.contains(target) || !!this.overlay.current?.contains(target));
|
|
121
|
+
|
|
122
|
+
hasTrigger = (trigger: OverlayTrigger) => {
|
|
123
|
+
const triggers: OverlayTrigger[] = this.props.trigger
|
|
124
|
+
? Array.isArray(this.props.trigger)
|
|
125
|
+
? this.props.trigger
|
|
126
|
+
: [this.props.trigger]
|
|
127
|
+
: ['hover', 'focus'];
|
|
128
|
+
|
|
129
|
+
return triggers.includes(trigger);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
handleMouseEnter = (event: MouseEvent<HTMLSpanElement>) => {
|
|
133
|
+
this.props.onMouseEnter?.(event);
|
|
134
|
+
|
|
135
|
+
if (!event.defaultPrevented && this.hasTrigger('hover')) this.setOpenAfterDelay(true);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
handleMouseLeave = (event: MouseEvent<HTMLSpanElement>) => {
|
|
139
|
+
this.props.onMouseLeave?.(event);
|
|
140
|
+
|
|
141
|
+
if (
|
|
142
|
+
!event.defaultPrevented &&
|
|
143
|
+
this.hasTrigger('hover') &&
|
|
144
|
+
!this.contains(event.relatedTarget) &&
|
|
145
|
+
!this.contains(document.activeElement)
|
|
146
|
+
)
|
|
147
|
+
this.setOpenAfterDelay(false);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
handleFocus = (event: FocusEvent<HTMLSpanElement>) => {
|
|
151
|
+
this.props.onFocus?.(event);
|
|
152
|
+
|
|
153
|
+
if (!event.defaultPrevented && this.hasTrigger('focus')) this.setOpenAfterDelay(true);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
handleBlur = (event: FocusEvent<HTMLSpanElement>) => {
|
|
157
|
+
this.props.onBlur?.(event);
|
|
158
|
+
|
|
159
|
+
if (
|
|
160
|
+
!event.defaultPrevented &&
|
|
161
|
+
this.hasTrigger('focus') &&
|
|
162
|
+
!this.contains(event.relatedTarget)
|
|
163
|
+
)
|
|
164
|
+
this.setOpenAfterDelay(false);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
handleClick = (event: MouseEvent<HTMLSpanElement>) => {
|
|
168
|
+
this.props.onClick?.(event);
|
|
169
|
+
|
|
170
|
+
if (
|
|
171
|
+
!event.defaultPrevented &&
|
|
172
|
+
this.hasTrigger('click') &&
|
|
173
|
+
!(event.target instanceof Node && this.overlay.current?.contains(event.target))
|
|
174
|
+
)
|
|
175
|
+
this.setOpenAfterDelay(!this.open);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
handleOutside = ({ target }: PointerEvent) => {
|
|
179
|
+
if (target instanceof Node && !this.contains(target)) this.hide();
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
handleKeyDown = (event: KeyboardEvent<HTMLSpanElement>) => {
|
|
183
|
+
this.props.onKeyDown?.(event);
|
|
184
|
+
|
|
185
|
+
if (!event.defaultPrevented && event.key === 'Escape' && this.open) {
|
|
186
|
+
event.preventDefault();
|
|
187
|
+
this.hide();
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
render() {
|
|
192
|
+
const {
|
|
193
|
+
title,
|
|
194
|
+
detail,
|
|
195
|
+
placement = 'top',
|
|
196
|
+
responsivePlacement: _responsivePlacement,
|
|
197
|
+
container,
|
|
198
|
+
offset: _offset,
|
|
199
|
+
padding: _padding,
|
|
200
|
+
flip: _flip,
|
|
201
|
+
trigger: _trigger,
|
|
202
|
+
delay: _delay,
|
|
203
|
+
overlayClassName,
|
|
204
|
+
children,
|
|
205
|
+
className = '',
|
|
206
|
+
onMouseEnter: _onMouseEnter,
|
|
207
|
+
onMouseLeave: _onMouseLeave,
|
|
208
|
+
onFocus: _onFocus,
|
|
209
|
+
onBlur: _onBlur,
|
|
210
|
+
onClick: _onClick,
|
|
211
|
+
onKeyDown: _onKeyDown,
|
|
212
|
+
...props
|
|
213
|
+
} = this.props;
|
|
214
|
+
const id = this.open ? this.id : undefined;
|
|
215
|
+
const direction = this.position.element
|
|
216
|
+
? (this.position.placement.split('-')[0] as OverlayPlacement)
|
|
217
|
+
: placement;
|
|
218
|
+
const overlayClass = classNames('w-max', overlayClassName);
|
|
219
|
+
const overlay =
|
|
220
|
+
detail != null ? (
|
|
221
|
+
<Popover
|
|
222
|
+
ref={this.overlay}
|
|
223
|
+
id={id}
|
|
224
|
+
style={{ ...this.position.style }}
|
|
225
|
+
arrowStyle={{ ...this.position.arrowStyle }}
|
|
226
|
+
className={overlayClass}
|
|
227
|
+
title={title}
|
|
228
|
+
placement={direction}
|
|
229
|
+
>
|
|
230
|
+
{detail}
|
|
231
|
+
</Popover>
|
|
232
|
+
) : (
|
|
233
|
+
<Tooltip
|
|
234
|
+
ref={this.overlay}
|
|
235
|
+
id={id}
|
|
236
|
+
style={{ ...this.position.style }}
|
|
237
|
+
arrowStyle={{ ...this.position.arrowStyle }}
|
|
238
|
+
className={overlayClass}
|
|
239
|
+
placement={direction}
|
|
240
|
+
>
|
|
241
|
+
{title}
|
|
242
|
+
</Tooltip>
|
|
243
|
+
);
|
|
244
|
+
const target =
|
|
245
|
+
this.open && container
|
|
246
|
+
? typeof container === 'string'
|
|
247
|
+
? document.querySelector<HTMLElement>(container)
|
|
248
|
+
: typeof container === 'function'
|
|
249
|
+
? container()
|
|
250
|
+
: container
|
|
251
|
+
: undefined;
|
|
252
|
+
if (this.open && container && !target) throw new Error('Overlay container was not found');
|
|
253
|
+
|
|
254
|
+
const trigger = isValidElement(children)
|
|
255
|
+
? cloneElement(children, {
|
|
256
|
+
'aria-describedby':
|
|
257
|
+
[children.props['aria-describedby'], id].filter(Boolean).join(' ') ||
|
|
258
|
+
undefined
|
|
259
|
+
})
|
|
260
|
+
: children;
|
|
261
|
+
|
|
262
|
+
return (
|
|
263
|
+
<span
|
|
264
|
+
{...props}
|
|
265
|
+
ref={this.root}
|
|
266
|
+
className={`position-relative d-inline-block ${className}`}
|
|
267
|
+
onMouseEnter={this.handleMouseEnter}
|
|
268
|
+
onMouseLeave={this.handleMouseLeave}
|
|
269
|
+
onFocus={this.handleFocus}
|
|
270
|
+
onBlur={this.handleBlur}
|
|
271
|
+
onClick={this.handleClick}
|
|
272
|
+
onKeyDown={this.handleKeyDown}
|
|
273
|
+
>
|
|
274
|
+
{trigger}
|
|
275
|
+
|
|
276
|
+
{this.open && (target ? createPortal(overlay, target) : overlay)}
|
|
277
|
+
</span>
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import classNames from 'classnames';
|
|
3
4
|
import { action, computed, observable } from 'mobx';
|
|
4
5
|
import { observer } from 'mobx-react';
|
|
5
6
|
import { Component } from 'react';
|
|
6
7
|
import { scrollTo, uniqueID } from 'web-utility';
|
|
7
8
|
|
|
8
|
-
import { Nav, NavLink, NavProps } from '
|
|
9
|
+
import { Nav, NavLink, NavProps } from '../Nav';
|
|
9
10
|
|
|
10
11
|
const HeadingSelector = Array.from({ length: 6 }, (_, index) => `h${index + 1}`).join(',');
|
|
11
12
|
|
|
12
13
|
type HeadingMeta = Record<'id' | 'text', string> & Record<'level' | 'top', number>;
|
|
13
14
|
|
|
14
|
-
export interface PageNavProps extends NavProps {
|
|
15
|
+
export interface PageNavProps extends Omit<NavProps, 'ref'> {
|
|
15
16
|
depth?: number;
|
|
16
17
|
minDepth?: number;
|
|
17
18
|
rootSelector?: string;
|
|
@@ -33,17 +34,29 @@ export class PageNav extends Component<PageNavProps> {
|
|
|
33
34
|
const { list, scrollY } = this;
|
|
34
35
|
const index = list.findIndex(({ top }) => top > scrollY);
|
|
35
36
|
|
|
36
|
-
return list[index - 1]?.id;
|
|
37
|
+
return list[index < 0 ? list.length - 1 : index - 1]?.id;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
updateScrollY = action(() =>
|
|
40
|
+
updateScrollY = action(() => {
|
|
41
|
+
this.scrollY = window.scrollY;
|
|
42
|
+
|
|
43
|
+
this.list = this.list.map(item => {
|
|
44
|
+
const element = document.getElementById(item.id);
|
|
45
|
+
|
|
46
|
+
return element
|
|
47
|
+
? { ...item, top: element.getBoundingClientRect().top + this.scrollY }
|
|
48
|
+
: item;
|
|
49
|
+
});
|
|
50
|
+
});
|
|
40
51
|
|
|
41
52
|
componentDidMount() {
|
|
42
53
|
if (!globalThis.document) return;
|
|
43
54
|
|
|
44
55
|
window.addEventListener('scroll', this.updateScrollY);
|
|
56
|
+
window.addEventListener('resize', this.updateScrollY);
|
|
45
57
|
|
|
46
58
|
this.initList();
|
|
59
|
+
this.updateScrollY();
|
|
47
60
|
}
|
|
48
61
|
|
|
49
62
|
static slugOf(text: string) {
|
|
@@ -69,15 +82,17 @@ export class PageNav extends Component<PageNavProps> {
|
|
|
69
82
|
|
|
70
83
|
element.id ||= PageNav.slugOf(text);
|
|
71
84
|
|
|
72
|
-
const { id, tagName
|
|
85
|
+
const { id, tagName } = element;
|
|
86
|
+
const top = element.getBoundingClientRect().top + window.scrollY;
|
|
73
87
|
|
|
74
|
-
return { id, level: +tagName[1], text, top
|
|
88
|
+
return { id, level: +tagName[1], text, top };
|
|
75
89
|
}
|
|
76
90
|
);
|
|
77
91
|
}
|
|
78
92
|
|
|
79
93
|
componentWillUnmount(): void {
|
|
80
|
-
|
|
94
|
+
window.removeEventListener('scroll', this.updateScrollY);
|
|
95
|
+
window.removeEventListener('resize', this.updateScrollY);
|
|
81
96
|
}
|
|
82
97
|
|
|
83
98
|
scrollTo = (meta: HeadingMeta) => () => {
|
|
@@ -95,8 +110,11 @@ export class PageNav extends Component<PageNavProps> {
|
|
|
95
110
|
level <= depth && (
|
|
96
111
|
<NavLink
|
|
97
112
|
key={id}
|
|
98
|
-
className={
|
|
99
|
-
|
|
113
|
+
className={classNames(
|
|
114
|
+
'justify-content-start text-wrap min-w-0',
|
|
115
|
+
currentActiveId === id && 'active'
|
|
116
|
+
)}
|
|
117
|
+
style={{ paddingInlineStart: `${level - minDepth + 0.75}rem` }}
|
|
100
118
|
href={`#${id}`}
|
|
101
119
|
aria-current={currentActiveId === id ? 'location' : undefined}
|
|
102
120
|
onClick={this.scrollTo({ id, level, text, top })}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import {
|
|
5
|
+
ButtonHTMLAttributes,
|
|
6
|
+
Children,
|
|
7
|
+
cloneElement,
|
|
8
|
+
Component,
|
|
9
|
+
FC,
|
|
10
|
+
isValidElement,
|
|
11
|
+
MouseEvent,
|
|
12
|
+
ReactElement,
|
|
13
|
+
ReactNode
|
|
14
|
+
} from 'react';
|
|
15
|
+
|
|
16
|
+
import { ButtonProps } from '../Button';
|
|
17
|
+
import { Menu } from '../Menu';
|
|
18
|
+
|
|
19
|
+
export interface OptionProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
20
|
+
value?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const Option: FC<OptionProps> = ({ value, className, children, ...props }) => (
|
|
24
|
+
<button
|
|
25
|
+
{...props}
|
|
26
|
+
type="button"
|
|
27
|
+
className={classNames('menu-item', className)}
|
|
28
|
+
data-value={value}
|
|
29
|
+
>
|
|
30
|
+
{children}
|
|
31
|
+
</button>
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
Option.displayName = 'Option';
|
|
35
|
+
|
|
36
|
+
export type SelectProps = Pick<
|
|
37
|
+
ButtonProps,
|
|
38
|
+
'className' | 'style' | 'size' | 'theme' | 'variant' | 'disabled' | 'children'
|
|
39
|
+
> & {
|
|
40
|
+
align?: 'start' | 'end';
|
|
41
|
+
menuClassName?: string;
|
|
42
|
+
value?: string;
|
|
43
|
+
name?: string;
|
|
44
|
+
placeholder?: ReactNode;
|
|
45
|
+
'aria-label'?: string;
|
|
46
|
+
onChange?: (value: string) => unknown;
|
|
47
|
+
valueRender?: (value: string) => ReactNode;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export class Select extends Component<SelectProps> {
|
|
51
|
+
static displayName = 'Select';
|
|
52
|
+
|
|
53
|
+
private handleSelect = ({ target, defaultPrevented }: MouseEvent<HTMLDivElement>) => {
|
|
54
|
+
if (defaultPrevented || this.props.disabled || !(target instanceof Element)) return;
|
|
55
|
+
|
|
56
|
+
const option = target.closest<HTMLButtonElement>('[data-value]');
|
|
57
|
+
|
|
58
|
+
if (option && !option.disabled && option.getAttribute('aria-disabled') !== 'true')
|
|
59
|
+
this.props.onChange?.(option.dataset.value ?? '');
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
private renderOption = (child: ReactNode) =>
|
|
63
|
+
isValidElement<OptionProps>(child) && child.type === Option
|
|
64
|
+
? cloneElement(child, {
|
|
65
|
+
className: classNames(
|
|
66
|
+
child.props.className,
|
|
67
|
+
child.props.value === this.props.value && 'selected'
|
|
68
|
+
),
|
|
69
|
+
'aria-selected': child.props.value === this.props.value
|
|
70
|
+
})
|
|
71
|
+
: child;
|
|
72
|
+
|
|
73
|
+
render() {
|
|
74
|
+
const {
|
|
75
|
+
align,
|
|
76
|
+
className,
|
|
77
|
+
menuClassName,
|
|
78
|
+
children,
|
|
79
|
+
theme = 'primary',
|
|
80
|
+
variant = 'solid',
|
|
81
|
+
size,
|
|
82
|
+
disabled,
|
|
83
|
+
style,
|
|
84
|
+
value,
|
|
85
|
+
onChange: _onChange,
|
|
86
|
+
valueRender,
|
|
87
|
+
name,
|
|
88
|
+
placeholder,
|
|
89
|
+
'aria-label': label
|
|
90
|
+
} = this.props;
|
|
91
|
+
const current = Children.toArray(children).find(
|
|
92
|
+
node =>
|
|
93
|
+
isValidElement<OptionProps>(node) &&
|
|
94
|
+
node.type === Option &&
|
|
95
|
+
node.props.value === value
|
|
96
|
+
) as ReactElement<OptionProps> | undefined;
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<>
|
|
100
|
+
<Menu
|
|
101
|
+
align={align}
|
|
102
|
+
className="w-100"
|
|
103
|
+
menuClassName={menuClassName}
|
|
104
|
+
label={valueRender?.(value ?? '') ?? current?.props.children ?? placeholder}
|
|
105
|
+
toggleProps={{
|
|
106
|
+
className: classNames(
|
|
107
|
+
'w-100 d-flex justify-content-between align-items-center',
|
|
108
|
+
className
|
|
109
|
+
),
|
|
110
|
+
theme,
|
|
111
|
+
variant,
|
|
112
|
+
size,
|
|
113
|
+
disabled,
|
|
114
|
+
style,
|
|
115
|
+
'aria-label': label
|
|
116
|
+
}}
|
|
117
|
+
onClick={this.handleSelect}
|
|
118
|
+
>
|
|
119
|
+
{Children.map(children, this.renderOption)}
|
|
120
|
+
</Menu>
|
|
121
|
+
{name && (
|
|
122
|
+
<input type="hidden" name={name} value={value ?? ''} disabled={disabled} />
|
|
123
|
+
)}
|
|
124
|
+
</>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -6,7 +6,7 @@ import { observer } from 'mobx-react';
|
|
|
6
6
|
import { Component, createRef, HTMLAttributes, MouseEvent } from 'react';
|
|
7
7
|
import { blobOf } from 'web-utility';
|
|
8
8
|
|
|
9
|
-
import { Image } from '
|
|
9
|
+
import { Image } from '../Image';
|
|
10
10
|
import { Loading } from './Loading';
|
|
11
11
|
|
|
12
12
|
export async function elementToImage(element: HTMLElement, type?: string, quality?: number) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
2
|
|
|
3
|
-
import { Button, ButtonProps } from '
|
|
4
|
-
import { Spinner, SpinnerProps } from '
|
|
3
|
+
import { Button, ButtonProps } from '../Button';
|
|
4
|
+
import { Spinner, SpinnerProps } from '../Spinner';
|
|
5
5
|
|
|
6
6
|
export type SpinnerButtonProps = ButtonProps &
|
|
7
7
|
Pick<SpinnerProps, 'animation'> & {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FC, HTMLAttributes } from 'react';
|
|
2
2
|
import { TimeData } from 'web-utility';
|
|
3
3
|
|
|
4
|
-
import { Card, CardBody, CardText, CardTitle } from '
|
|
4
|
+
import { Card, CardBody, CardText, CardTitle } from '../../Card';
|
|
5
5
|
import { Nameplate, NameplateProps } from '../Nameplate';
|
|
6
6
|
import { Time } from '../Time';
|
|
7
7
|
import * as styles from './index.module.less';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { FC, HTMLAttributes } from 'react';
|
|
2
2
|
|
|
3
|
-
import { Badge } from '
|
|
4
|
-
import { Col, Container, Row } from '
|
|
5
|
-
import { Image } from '
|
|
6
|
-
import { Table } from '
|
|
3
|
+
import { Badge } from '../../Badge';
|
|
4
|
+
import { Col, Container, Row } from '../../Grid';
|
|
5
|
+
import { Image } from '../../Image';
|
|
6
|
+
import { Table } from '../../Table';
|
|
7
7
|
import { UserAddress, UserAddressProps } from './Address';
|
|
8
8
|
import * as style from './index.module.less';
|
|
9
9
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export * from './ClickBoundary';
|
|
2
|
+
export * from './CodeBlock';
|
|
3
|
+
export * from './Countdown';
|
|
4
|
+
export * from './Dialog';
|
|
5
|
+
export * from './Editor';
|
|
6
|
+
export * from './EditorHTML';
|
|
7
|
+
export * from './HorizontalMarquee';
|
|
8
|
+
export * from './Icon';
|
|
9
|
+
export * from './LiveTSX';
|
|
10
|
+
export * from './Loading';
|
|
11
|
+
export * from './MonthCalendar';
|
|
12
|
+
export * from './Nameplate';
|
|
13
|
+
export * from './OverlayBox';
|
|
14
|
+
export * from './PageNav';
|
|
15
|
+
export * from './ScrollNav';
|
|
16
|
+
export * from './Select';
|
|
17
|
+
export * from './ShareBox';
|
|
18
|
+
export * from './SpinnerButton';
|
|
19
|
+
export * from './TableSpinner';
|
|
20
|
+
export * from './TextTruncate';
|
|
21
|
+
export * from './Time';
|
|
22
|
+
export * from './TimeDistance';
|
|
23
|
+
export * from './Timeline';
|
|
24
|
+
export * from './TypeEcho';
|
|
25
|
+
export * from './UserRank';
|
|
26
|
+
export * from './VerticalMarquee';
|
|
27
|
+
export * from './ZodiacBar';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
|
+
|
|
4
|
+
import { Icon, IconProps } from '../Extension/Icon';
|
|
5
|
+
import { FormValidationProps } from './Primitives';
|
|
6
|
+
|
|
7
|
+
export type FormAdornmentProps = Omit<ComponentPropsWithRef<'label'>, 'htmlFor'> &
|
|
8
|
+
FormValidationProps & {
|
|
9
|
+
end?: boolean;
|
|
10
|
+
size?: 'sm' | 'lg';
|
|
11
|
+
htmlFor?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const FormAdornment: FC<FormAdornmentProps> = ({
|
|
15
|
+
className,
|
|
16
|
+
end,
|
|
17
|
+
size,
|
|
18
|
+
validation,
|
|
19
|
+
...props
|
|
20
|
+
}) => (
|
|
21
|
+
<label
|
|
22
|
+
{...props}
|
|
23
|
+
className={classNames(
|
|
24
|
+
'form-control form-adorn',
|
|
25
|
+
end && 'form-adorn-end',
|
|
26
|
+
size && `form-control-${size}`,
|
|
27
|
+
validation && `is-${validation}`,
|
|
28
|
+
className
|
|
29
|
+
)}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
FormAdornment.displayName = 'FormAdornment';
|
|
34
|
+
|
|
35
|
+
export type FormAdornmentTextProps = ComponentPropsWithRef<'span'>;
|
|
36
|
+
|
|
37
|
+
export const FormAdornmentText: FC<FormAdornmentTextProps> = ({ className, ...props }) => (
|
|
38
|
+
<span {...props} className={classNames('form-adorn-text', className)} />
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
FormAdornmentText.displayName = 'FormAdornmentText';
|
|
42
|
+
|
|
43
|
+
export const FormAdornmentIcon: FC<IconProps> = ({ className, ...props }) => (
|
|
44
|
+
<Icon {...props} className={classNames('form-adorn-icon', className)} />
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
FormAdornmentIcon.displayName = 'FormAdornmentIcon';
|
|
48
|
+
|
|
49
|
+
export type FormGhostProps = ComponentPropsWithRef<'input'> & FormValidationProps;
|
|
50
|
+
|
|
51
|
+
export const FormGhost: FC<FormGhostProps> = ({ className, validation, ...props }) => (
|
|
52
|
+
<input
|
|
53
|
+
{...props}
|
|
54
|
+
aria-invalid={validation ? validation === 'invalid' : props['aria-invalid']}
|
|
55
|
+
className={classNames('form-ghost', validation && `is-${validation}`, className)}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
FormGhost.displayName = 'FormGhost';
|