idea-react 3.0.0-beta.0 → 3.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +19 -2
- package/ReadMe.md +95 -54
- package/dist/DatePickerPlugin-CpGuQRsi.js +1 -0
- package/dist/DatePickerPlugin-DB3nnslN.mjs +1 -0
- package/dist/index.d.mts +1232 -474
- package/dist/index.d.ts +1232 -474
- package/dist/index.js +16 -16
- package/dist/index.mjs +15 -15
- package/dist/rolldown-runtime-5iZMYShA.js +1 -0
- package/dist/style.css +66 -66
- package/package.json +1 -1
- package/source/Accordion.tsx +161 -0
- package/source/Alert.tsx +153 -0
- package/source/Avatar.tsx +57 -46
- package/source/Badge.tsx +17 -15
- package/source/Breadcrumb.tsx +50 -0
- package/source/Button.tsx +69 -40
- package/source/ButtonGroup.tsx +23 -18
- package/source/Card.tsx +86 -17
- package/source/Carousel/index.tsx +392 -0
- package/source/Carousel/model.ts +113 -0
- package/source/Carousel/scroll.ts +79 -0
- package/source/CloseButton.tsx +20 -15
- package/source/Collapse.tsx +233 -0
- package/source/Drawer.tsx +158 -38
- package/source/{ClickBoundary.tsx → Extension/ClickBoundary.tsx} +24 -5
- package/source/Extension/CodeBlock.tsx +64 -0
- package/source/{Countdown.tsx → Extension/Countdown.tsx} +21 -9
- package/source/{Dialog.tsx → Extension/Dialog.tsx} +10 -6
- package/source/Extension/Editor.tsx +78 -0
- package/source/Extension/EditorHTML.tsx +20 -0
- package/source/{HorizontalMarquee → Extension/HorizontalMarquee}/index.module.less +1 -3
- package/source/Extension/HorizontalMarquee/index.tsx +85 -0
- package/source/Extension/Icon.tsx +19 -0
- package/source/Extension/Loading.tsx +30 -0
- package/source/{MonthCalendar.tsx → Extension/MonthCalendar.tsx} +29 -13
- package/source/{Nameplate.tsx → Extension/Nameplate.tsx} +1 -1
- package/source/Extension/OverlayBox.tsx +293 -0
- package/source/{PageNav.tsx → Extension/PageNav.tsx} +43 -16
- package/source/{ScrollNav → Extension/ScrollNav}/Scroller.tsx +21 -5
- package/source/Extension/ScrollNav/index.tsx +47 -0
- package/source/Extension/Select.tsx +128 -0
- package/source/{ShareBox.tsx → Extension/ShareBox.tsx} +1 -1
- package/source/Extension/SpinnerButton.tsx +30 -0
- package/source/Extension/TableSpinner.tsx +22 -0
- package/source/Extension/TextTruncate/index.tsx +29 -0
- package/source/Extension/Time.tsx +17 -0
- package/source/Extension/TimeDistance.tsx +45 -0
- package/source/Extension/Timeline/index.tsx +63 -0
- package/source/Extension/TypeEcho/Content.tsx +123 -0
- package/source/Extension/TypeEcho/index.tsx +22 -0
- package/source/Extension/UserRank/Address.tsx +22 -0
- package/source/Extension/UserRank/index.tsx +106 -0
- package/source/Extension/VerticalMarquee/index.tsx +23 -0
- package/source/Extension/ZodiacBar.tsx +59 -0
- package/source/Extension/index.ts +27 -0
- package/source/Form/Adorn.tsx +45 -26
- package/source/Form/Checkbox.tsx +20 -11
- package/source/Form/ChipInput.tsx +129 -0
- package/source/Form/Chips.tsx +57 -37
- package/source/Form/Combobox.tsx +362 -78
- package/source/Form/Control.tsx +72 -42
- package/source/Form/DatePicker.tsx +245 -45
- package/source/Form/DatePickerPlugin.ts +37 -0
- package/source/Form/Feedback.tsx +21 -16
- package/source/Form/FloatingLabel.tsx +21 -7
- package/source/Form/InputGroup.tsx +162 -11
- package/source/Form/OTP.tsx +156 -45
- package/source/Form/PasswordStrength.tsx +43 -17
- package/source/Form/Plugin.tsx +53 -0
- package/source/Form/Primitives.tsx +70 -20
- package/source/Form/Radio.tsx +35 -40
- package/source/Form/Range.tsx +125 -56
- package/source/Form/Switch.tsx +53 -27
- package/source/Form/index.ts +1 -0
- package/source/Grid.tsx +68 -56
- package/source/Image.tsx +10 -6
- package/source/ListGroup.tsx +59 -58
- package/source/Menu.tsx +317 -46
- package/source/NativeDialog/index.tsx +148 -22
- package/source/Nav.tsx +49 -33
- package/source/NavOverflow/index.tsx +323 -0
- package/source/NavOverflow/model.ts +21 -0
- package/source/Navbar.tsx +65 -45
- package/source/Overlay.ts +163 -1
- package/source/Pagination.tsx +86 -0
- package/source/Placeholder.tsx +70 -0
- package/source/Polymorphic.ts +57 -0
- package/source/Popover.tsx +34 -26
- package/source/Progress/index.tsx +81 -0
- package/source/Progress/style.module.css +15 -0
- package/source/ScrollSpy/index.tsx +380 -0
- package/source/ScrollSpy/model.ts +17 -0
- package/source/Spinner.tsx +31 -17
- package/source/Stack.tsx +25 -0
- package/source/Stepper.tsx +91 -0
- package/source/Tab.tsx +261 -0
- package/source/Table.tsx +53 -42
- package/source/Toast.tsx +93 -46
- package/source/ToggleButton.tsx +47 -30
- package/source/Toggler.tsx +117 -0
- package/source/Tooltip.tsx +31 -24
- package/source/index.ts +17 -27
- package/source/CodeBlock.tsx +0 -40
- package/source/Editor.tsx +0 -43
- package/source/EditorHTML.tsx +0 -16
- package/source/HorizontalMarquee/index.tsx +0 -61
- package/source/Icon.tsx +0 -24
- package/source/Loading.tsx +0 -22
- package/source/OverlayBox.tsx +0 -208
- package/source/ScrollNav/index.tsx +0 -22
- package/source/Select.tsx +0 -95
- package/source/SpinnerButton.tsx +0 -35
- package/source/TableSpinner.tsx +0 -26
- package/source/TextTruncate/index.tsx +0 -25
- package/source/Time.tsx +0 -15
- package/source/TimeDistance.tsx +0 -41
- package/source/Timeline/index.tsx +0 -60
- package/source/TypeEcho/Content.tsx +0 -58
- package/source/TypeEcho/index.tsx +0 -14
- package/source/UserRank/Address.tsx +0 -20
- package/source/UserRank/index.tsx +0 -111
- package/source/VerticalMarquee/index.tsx +0 -25
- package/source/ZodiacBar.tsx +0 -51
- /package/source/{LiveTSX.tsx → Extension/LiveTSX.tsx} +0 -0
- /package/source/{ScrollNav → Extension/ScrollNav}/index.module.less +0 -0
- /package/source/{TextTruncate → Extension/TextTruncate}/Content.tsx +0 -0
- /package/source/{Timeline → Extension/Timeline}/index.module.less +0 -0
- /package/source/{UserRank → Extension/UserRank}/index.module.less +0 -0
- /package/source/{VerticalMarquee → Extension/VerticalMarquee}/index.module.less +0 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { observer } from 'mobx-react';
|
|
5
|
+
import { Component, ComponentPropsWithRef, createRef, ElementType, ReactNode } from 'react';
|
|
6
|
+
import { createPortal } from 'react-dom';
|
|
7
|
+
|
|
8
|
+
import { AsProps, PolymorphicClassProps } from '../Polymorphic';
|
|
9
|
+
import { ScrollSpyModel } from './model';
|
|
10
|
+
|
|
11
|
+
export interface ScrollSpyProps extends Omit<
|
|
12
|
+
ComponentPropsWithRef<'div'>,
|
|
13
|
+
'onChange' | 'children'
|
|
14
|
+
> {
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
debug?: boolean;
|
|
17
|
+
onActiveChange?: (id: string) => unknown;
|
|
18
|
+
rootMargin?: string | null;
|
|
19
|
+
scrollRoot?: 'self' | 'window';
|
|
20
|
+
smoothScroll?: boolean;
|
|
21
|
+
target?: string;
|
|
22
|
+
threshold?: number[];
|
|
23
|
+
topMargin?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface ScrollSpyEntry {
|
|
27
|
+
id: string;
|
|
28
|
+
link: HTMLAnchorElement;
|
|
29
|
+
section: HTMLElement;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@observer
|
|
33
|
+
export class ScrollSpy<T extends ElementType | undefined = 'div'> extends Component<
|
|
34
|
+
PolymorphicClassProps<T, ScrollSpyProps>
|
|
35
|
+
> {
|
|
36
|
+
declare readonly props: PolymorphicClassProps<T, ScrollSpyProps>;
|
|
37
|
+
|
|
38
|
+
protected get componentProps(): Readonly<ScrollSpyProps & AsProps> {
|
|
39
|
+
return this.props;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static displayName = 'ScrollSpy';
|
|
43
|
+
|
|
44
|
+
root = createRef<HTMLDivElement>();
|
|
45
|
+
|
|
46
|
+
store = new ScrollSpyModel();
|
|
47
|
+
|
|
48
|
+
private entries: ScrollSpyEntry[] = [];
|
|
49
|
+
|
|
50
|
+
private observer?: IntersectionObserver;
|
|
51
|
+
|
|
52
|
+
private bottomObserver?: IntersectionObserver;
|
|
53
|
+
|
|
54
|
+
private intersecting = new Set<Element>();
|
|
55
|
+
|
|
56
|
+
private atBottom = false;
|
|
57
|
+
|
|
58
|
+
private mounted = false;
|
|
59
|
+
|
|
60
|
+
sentinel = createRef<HTMLDivElement>();
|
|
61
|
+
|
|
62
|
+
componentDidMount() {
|
|
63
|
+
this.mounted = true;
|
|
64
|
+
this.refresh();
|
|
65
|
+
|
|
66
|
+
this.root.current?.addEventListener('scroll', this.handleScroll, { passive: true });
|
|
67
|
+
window.addEventListener('scroll', this.handleScroll, { passive: true });
|
|
68
|
+
window.addEventListener('resize', this.handleResize);
|
|
69
|
+
document.addEventListener('click', this.handleNavigationClick);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
componentDidUpdate(previous: ScrollSpyProps) {
|
|
73
|
+
if (
|
|
74
|
+
previous.children !== this.componentProps.children ||
|
|
75
|
+
previous.target !== this.componentProps.target ||
|
|
76
|
+
previous.rootMargin !== this.componentProps.rootMargin ||
|
|
77
|
+
previous.topMargin !== this.componentProps.topMargin ||
|
|
78
|
+
previous.threshold !== this.componentProps.threshold ||
|
|
79
|
+
previous.scrollRoot !== this.componentProps.scrollRoot
|
|
80
|
+
)
|
|
81
|
+
this.refresh();
|
|
82
|
+
|
|
83
|
+
if (previous.debug !== this.componentProps.debug) this.updateGuides();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
componentWillUnmount() {
|
|
87
|
+
this.mounted = false;
|
|
88
|
+
this.observer?.disconnect();
|
|
89
|
+
this.bottomObserver?.disconnect();
|
|
90
|
+
|
|
91
|
+
this.root.current?.removeEventListener('scroll', this.handleScroll);
|
|
92
|
+
window.removeEventListener('scroll', this.handleScroll);
|
|
93
|
+
window.removeEventListener('resize', this.handleResize);
|
|
94
|
+
document.removeEventListener('click', this.handleNavigationClick);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
refresh = () => {
|
|
98
|
+
const root = this.root.current;
|
|
99
|
+
if (!root) return;
|
|
100
|
+
|
|
101
|
+
const navigation = this.componentProps.target
|
|
102
|
+
? document.querySelector<HTMLElement>(this.componentProps.target)
|
|
103
|
+
: root;
|
|
104
|
+
const links = [...(navigation?.querySelectorAll<HTMLAnchorElement>('a[href^="#"]') ?? [])];
|
|
105
|
+
|
|
106
|
+
this.entries = links.flatMap(link => {
|
|
107
|
+
const hash = link.getAttribute('href')?.slice(1);
|
|
108
|
+
if (!hash) return [];
|
|
109
|
+
|
|
110
|
+
const id = decodeURIComponent(hash);
|
|
111
|
+
const section = document.getElementById(id);
|
|
112
|
+
|
|
113
|
+
return !section ||
|
|
114
|
+
section.hidden ||
|
|
115
|
+
section.closest('[hidden]') ||
|
|
116
|
+
section.getAttribute('aria-hidden') === 'true' ||
|
|
117
|
+
getComputedStyle(section).display === 'none' ||
|
|
118
|
+
getComputedStyle(section).visibility === 'hidden'
|
|
119
|
+
? []
|
|
120
|
+
: [{ id, link, section }];
|
|
121
|
+
});
|
|
122
|
+
this.entries.sort(
|
|
123
|
+
(first, second) =>
|
|
124
|
+
first.section.getBoundingClientRect().top -
|
|
125
|
+
second.section.getBoundingClientRect().top
|
|
126
|
+
);
|
|
127
|
+
this.rebuildObservers();
|
|
128
|
+
this.updateActive();
|
|
129
|
+
this.updateGuides();
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
handleResize = () => {
|
|
133
|
+
this.rebuildObservers();
|
|
134
|
+
this.updateGuides();
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
handleScroll = () => this.updateGuides();
|
|
138
|
+
|
|
139
|
+
private getRootHeight = () =>
|
|
140
|
+
this.componentProps.scrollRoot === 'window'
|
|
141
|
+
? document.documentElement.clientHeight || window.innerHeight
|
|
142
|
+
: (this.root.current?.clientHeight ?? 0);
|
|
143
|
+
|
|
144
|
+
private getRootMargin = () => {
|
|
145
|
+
if (this.componentProps.rootMargin != null) return this.componentProps.rootMargin;
|
|
146
|
+
const { topMargin = '12%' } = this.componentProps;
|
|
147
|
+
const value = Number.parseFloat(topMargin) || 0;
|
|
148
|
+
const height = this.getRootHeight();
|
|
149
|
+
const percent = topMargin.endsWith('%') ? value : height ? (value / height) * 100 : 12;
|
|
150
|
+
|
|
151
|
+
return `0px 0px -${Math.min(Math.max(100 - percent, 0), 100)}% 0px`;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
private rebuildObservers = () => {
|
|
155
|
+
this.observer?.disconnect();
|
|
156
|
+
this.bottomObserver?.disconnect();
|
|
157
|
+
this.intersecting.clear();
|
|
158
|
+
this.atBottom = false;
|
|
159
|
+
|
|
160
|
+
const root = this.componentProps.scrollRoot === 'window' ? null : this.root.current;
|
|
161
|
+
const observer = new window.IntersectionObserver(
|
|
162
|
+
entries => {
|
|
163
|
+
if (!this.mounted || this.observer !== observer) return;
|
|
164
|
+
for (const entry of entries) {
|
|
165
|
+
if (entry.isIntersecting) this.intersecting.add(entry.target);
|
|
166
|
+
else this.intersecting.delete(entry.target);
|
|
167
|
+
}
|
|
168
|
+
this.updateActive();
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
root,
|
|
172
|
+
rootMargin: this.getRootMargin(),
|
|
173
|
+
threshold: this.componentProps.threshold ?? [0]
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
this.observer = observer;
|
|
177
|
+
|
|
178
|
+
for (const section of new Set(this.entries.map(entry => entry.section)))
|
|
179
|
+
observer.observe(section);
|
|
180
|
+
|
|
181
|
+
const bottomObserver = new window.IntersectionObserver(
|
|
182
|
+
entries => {
|
|
183
|
+
if (!this.mounted || this.bottomObserver !== bottomObserver) return;
|
|
184
|
+
|
|
185
|
+
const scroller = root ?? document.scrollingElement ?? document.documentElement;
|
|
186
|
+
this.atBottom =
|
|
187
|
+
Boolean(entries.at(-1)?.isIntersecting) &&
|
|
188
|
+
scroller.scrollHeight > scroller.clientHeight;
|
|
189
|
+
this.updateActive();
|
|
190
|
+
this.updateGuides();
|
|
191
|
+
},
|
|
192
|
+
{ root, threshold: [0] }
|
|
193
|
+
);
|
|
194
|
+
this.bottomObserver = bottomObserver;
|
|
195
|
+
if (this.sentinel.current) bottomObserver.observe(this.sentinel.current);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
handleNavigationClick = (event: globalThis.MouseEvent) => {
|
|
199
|
+
if (!this.componentProps.smoothScroll || event.defaultPrevented) return;
|
|
200
|
+
|
|
201
|
+
const link =
|
|
202
|
+
event.target instanceof Element
|
|
203
|
+
? event.target.closest<HTMLAnchorElement>('a[href^="#"]')
|
|
204
|
+
: null;
|
|
205
|
+
const entry = this.entries.find(candidate => candidate.link === link);
|
|
206
|
+
if (!link || !entry) return;
|
|
207
|
+
|
|
208
|
+
event.preventDefault();
|
|
209
|
+
const root = this.root.current;
|
|
210
|
+
const { scrollRoot = 'self' } = this.componentProps;
|
|
211
|
+
if (scrollRoot === 'window')
|
|
212
|
+
window.scrollTo({
|
|
213
|
+
top: window.scrollY + entry.section.getBoundingClientRect().top,
|
|
214
|
+
behavior: 'smooth'
|
|
215
|
+
});
|
|
216
|
+
else if (root) {
|
|
217
|
+
const top =
|
|
218
|
+
root.scrollTop +
|
|
219
|
+
entry.section.getBoundingClientRect().top -
|
|
220
|
+
root.getBoundingClientRect().top;
|
|
221
|
+
|
|
222
|
+
root.scrollTo({ top, behavior: 'smooth' });
|
|
223
|
+
}
|
|
224
|
+
window.history.replaceState(null, '', `#${encodeURIComponent(entry.id)}`);
|
|
225
|
+
|
|
226
|
+
const temporaryTabIndex = !entry.section.hasAttribute('tabindex');
|
|
227
|
+
if (temporaryTabIndex) entry.section.tabIndex = -1;
|
|
228
|
+
|
|
229
|
+
entry.section.focus({ preventScroll: true });
|
|
230
|
+
|
|
231
|
+
if (temporaryTabIndex) entry.section.removeAttribute('tabindex');
|
|
232
|
+
this.updateActive();
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
private getActivationLine = (rootHeight: number) => {
|
|
236
|
+
const margins = this.getRootMargin().trim().split(/\s+/);
|
|
237
|
+
const bottom = margins[2] ?? margins[0];
|
|
238
|
+
const parsed = Number.parseFloat(bottom) || 0;
|
|
239
|
+
|
|
240
|
+
return rootHeight + (bottom.endsWith('%') ? (rootHeight * parsed) / 100 : parsed);
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
private updateGuides = () => {
|
|
244
|
+
const root = this.root.current;
|
|
245
|
+
if (!this.componentProps.debug || !root) return this.store.setGuides(undefined);
|
|
246
|
+
|
|
247
|
+
const rect = root.getBoundingClientRect();
|
|
248
|
+
const height = this.getRootHeight();
|
|
249
|
+
|
|
250
|
+
this.store.setGuides({
|
|
251
|
+
top: this.componentProps.scrollRoot === 'window' ? 0 : rect.top,
|
|
252
|
+
left: this.componentProps.scrollRoot === 'window' ? 0 : rect.left,
|
|
253
|
+
width:
|
|
254
|
+
this.componentProps.scrollRoot === 'window' ? window.innerWidth : root.clientWidth,
|
|
255
|
+
height,
|
|
256
|
+
line: this.getActivationLine(height),
|
|
257
|
+
atBottom: this.atBottom
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
private updateActive = () => {
|
|
262
|
+
const root = this.root.current;
|
|
263
|
+
if (!root || !this.entries.length) return;
|
|
264
|
+
|
|
265
|
+
const lastEntry = this.entries.at(-1);
|
|
266
|
+
const current =
|
|
267
|
+
(this.atBottom ? lastEntry : undefined) ??
|
|
268
|
+
[...this.entries].reverse().find(({ section }) => this.intersecting.has(section)) ??
|
|
269
|
+
this.entries.find(entry => entry.id === this.store.activeId) ??
|
|
270
|
+
this.entries[0];
|
|
271
|
+
const activeLinks = new Set(
|
|
272
|
+
this.entries.filter(entry => entry.id === current.id).map(entry => entry.link)
|
|
273
|
+
);
|
|
274
|
+
let nestedNav = current.link.closest('.nav');
|
|
275
|
+
let parentNav = nestedNav?.parentElement?.closest('.nav');
|
|
276
|
+
|
|
277
|
+
while (parentNav && parentNav !== this.root.current) {
|
|
278
|
+
const parentEntry = [...this.entries]
|
|
279
|
+
.reverse()
|
|
280
|
+
.find(
|
|
281
|
+
entry =>
|
|
282
|
+
entry.link.closest('.nav') === parentNav &&
|
|
283
|
+
Boolean(
|
|
284
|
+
entry.section.compareDocumentPosition(current.section) &
|
|
285
|
+
Node.DOCUMENT_POSITION_FOLLOWING
|
|
286
|
+
)
|
|
287
|
+
);
|
|
288
|
+
if (parentEntry) activeLinks.add(parentEntry.link);
|
|
289
|
+
nestedNav = parentNav;
|
|
290
|
+
parentNav = nestedNav.parentElement?.closest('.nav');
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
for (const { link } of this.entries) {
|
|
294
|
+
const active = activeLinks.has(link);
|
|
295
|
+
|
|
296
|
+
link.classList.toggle('active', active);
|
|
297
|
+
|
|
298
|
+
if (active) link.setAttribute('aria-current', 'location');
|
|
299
|
+
else link.removeAttribute('aria-current');
|
|
300
|
+
}
|
|
301
|
+
if (current.id === this.store.activeId) return;
|
|
302
|
+
|
|
303
|
+
this.store.setActiveId(current.id);
|
|
304
|
+
this.componentProps.onActiveChange?.(current.id);
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
renderDebug = () => {
|
|
308
|
+
const guides = this.store.guides;
|
|
309
|
+
if (!this.componentProps.debug || !guides) return null;
|
|
310
|
+
|
|
311
|
+
const { top, left, width, height, line, atBottom } = guides;
|
|
312
|
+
|
|
313
|
+
return createPortal(
|
|
314
|
+
<div
|
|
315
|
+
className="position-fixed overflow-hidden pe-none"
|
|
316
|
+
style={{ top, left, width, height, zIndex: 1080 }}
|
|
317
|
+
aria-hidden="true"
|
|
318
|
+
data-scrollspy-debug
|
|
319
|
+
>
|
|
320
|
+
<div
|
|
321
|
+
className="position-absolute start-0 end-0 border-top border-danger border-2"
|
|
322
|
+
style={{ top: line, borderTopStyle: 'dashed' }}
|
|
323
|
+
data-scrollspy-line
|
|
324
|
+
/>
|
|
325
|
+
<div
|
|
326
|
+
className="position-absolute bottom-0 start-0 end-0 border-top border-danger"
|
|
327
|
+
style={{
|
|
328
|
+
height: 12,
|
|
329
|
+
borderTop: '1px solid #dc3545',
|
|
330
|
+
background: atBottom ? 'rgb(220 53 69 / 40%)' : 'rgb(220 53 69 / 10%)'
|
|
331
|
+
}}
|
|
332
|
+
data-scrollspy-bottom={atBottom ? 'reached' : 'pending'}
|
|
333
|
+
/>
|
|
334
|
+
</div>,
|
|
335
|
+
document.body
|
|
336
|
+
);
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
render() {
|
|
340
|
+
const Root: ElementType = this.componentProps.as ?? 'div';
|
|
341
|
+
|
|
342
|
+
const {
|
|
343
|
+
as: _as,
|
|
344
|
+
children,
|
|
345
|
+
className,
|
|
346
|
+
debug: _debug,
|
|
347
|
+
onActiveChange: _onActiveChange,
|
|
348
|
+
onClick: _onClick,
|
|
349
|
+
onKeyDown: _onKeyDown,
|
|
350
|
+
rootMargin: _rootMargin,
|
|
351
|
+
scrollRoot: _scrollRoot,
|
|
352
|
+
smoothScroll: _smoothScroll,
|
|
353
|
+
target: _target,
|
|
354
|
+
threshold: _threshold,
|
|
355
|
+
topMargin: _topMargin,
|
|
356
|
+
...props
|
|
357
|
+
} = this.componentProps;
|
|
358
|
+
|
|
359
|
+
return (
|
|
360
|
+
<Root
|
|
361
|
+
{...props}
|
|
362
|
+
ref={this.root}
|
|
363
|
+
className={classNames('scrollspy', className)}
|
|
364
|
+
data-active-id={this.store.activeId || undefined}
|
|
365
|
+
data-bs-root-margin={this.componentProps.rootMargin ?? undefined}
|
|
366
|
+
tabIndex={this.componentProps.tabIndex ?? 0}
|
|
367
|
+
onClick={this.componentProps.onClick}
|
|
368
|
+
onKeyDown={this.componentProps.onKeyDown}
|
|
369
|
+
>
|
|
370
|
+
{children}
|
|
371
|
+
<div
|
|
372
|
+
ref={this.sentinel}
|
|
373
|
+
className="position-relative invisible m-0 border-0 p-0 w-0 h-0"
|
|
374
|
+
aria-hidden="true"
|
|
375
|
+
/>
|
|
376
|
+
{this.renderDebug()}
|
|
377
|
+
</Root>
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { action, observable } from 'mobx';
|
|
2
|
+
|
|
3
|
+
export class ScrollSpyModel {
|
|
4
|
+
@observable accessor activeId = '';
|
|
5
|
+
|
|
6
|
+
@observable accessor guides:
|
|
7
|
+
| (Record<'top' | 'left' | 'width' | 'height' | 'line', number> & {
|
|
8
|
+
atBottom: boolean;
|
|
9
|
+
})
|
|
10
|
+
| undefined;
|
|
11
|
+
|
|
12
|
+
@action
|
|
13
|
+
setGuides = (guides: ScrollSpyModel['guides']) => (this.guides = guides);
|
|
14
|
+
|
|
15
|
+
@action
|
|
16
|
+
setActiveId = (id: string) => (this.activeId = id);
|
|
17
|
+
}
|
package/source/Spinner.tsx
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
|
-
import { ComponentPropsWithRef
|
|
2
|
+
import { ComponentPropsWithRef } from 'react';
|
|
3
3
|
|
|
4
4
|
import type { ComponentTheme } from './Button';
|
|
5
|
+
import { Icon, IconProps } from './Extension/Icon';
|
|
6
|
+
import { polymorphic } from './Polymorphic';
|
|
5
7
|
|
|
6
8
|
export type SpinnerAnimation = 'border' | 'grow';
|
|
7
9
|
|
|
@@ -11,20 +13,32 @@ export interface SpinnerProps extends ComponentPropsWithRef<'span'> {
|
|
|
11
13
|
theme?: ComponentTheme;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
export const Spinner
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
className
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
export const Spinner = polymorphic<SpinnerProps>(
|
|
17
|
+
({
|
|
18
|
+
as: Root = 'span',
|
|
19
|
+
animation = 'border',
|
|
20
|
+
size,
|
|
21
|
+
theme,
|
|
22
|
+
className,
|
|
23
|
+
role = 'status',
|
|
24
|
+
...props
|
|
25
|
+
}) => (
|
|
26
|
+
<Root
|
|
27
|
+
{...props}
|
|
28
|
+
role={role}
|
|
29
|
+
className={classNames(
|
|
30
|
+
`spinner-${animation}`,
|
|
31
|
+
size && `spinner-${size}`,
|
|
32
|
+
theme && `theme-${theme}`,
|
|
33
|
+
className
|
|
34
|
+
)}
|
|
35
|
+
/>
|
|
36
|
+
)
|
|
30
37
|
);
|
|
38
|
+
Spinner.displayName = 'Spinner';
|
|
39
|
+
|
|
40
|
+
export const SpinnerIcon = polymorphic<IconProps>(({ as: RootAs, className, ...props }) => (
|
|
41
|
+
<Icon as={RootAs} {...props} className={classNames('spinner-rotate', className)} />
|
|
42
|
+
));
|
|
43
|
+
|
|
44
|
+
SpinnerIcon.displayName = 'SpinnerIcon';
|
package/source/Stack.tsx
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef } from 'react';
|
|
3
|
+
|
|
4
|
+
import { polymorphic } from './Polymorphic';
|
|
5
|
+
|
|
6
|
+
export type StackDirection = 'horizontal' | 'vertical';
|
|
7
|
+
|
|
8
|
+
export interface StackProps extends ComponentPropsWithRef<'div'> {
|
|
9
|
+
direction?: StackDirection;
|
|
10
|
+
gap?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const Stack = polymorphic<StackProps>(
|
|
14
|
+
({ as: Root = 'div', direction = 'vertical', gap, className, ...props }) => (
|
|
15
|
+
<Root
|
|
16
|
+
{...props}
|
|
17
|
+
className={classNames(
|
|
18
|
+
direction === 'horizontal' ? 'hstack' : 'vstack',
|
|
19
|
+
gap !== undefined && `gap-${gap}`,
|
|
20
|
+
className
|
|
21
|
+
)}
|
|
22
|
+
/>
|
|
23
|
+
)
|
|
24
|
+
);
|
|
25
|
+
Stack.displayName = 'Stack';
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef } from 'react';
|
|
3
|
+
|
|
4
|
+
import { ComponentTheme } from './Button';
|
|
5
|
+
import { Breakpoint } from './Grid';
|
|
6
|
+
import { polymorphic } from './Polymorphic';
|
|
7
|
+
|
|
8
|
+
export interface StepperProps extends ComponentPropsWithRef<'ol'> {
|
|
9
|
+
horizontal?: boolean | Breakpoint;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const stepperClasses = (horizontal: StepperProps['horizontal'], className?: string) =>
|
|
13
|
+
classNames(
|
|
14
|
+
'stepper',
|
|
15
|
+
horizontal === true
|
|
16
|
+
? 'stepper-horizontal'
|
|
17
|
+
: horizontal && `${horizontal}:stepper-horizontal`,
|
|
18
|
+
className
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const Stepper = polymorphic<StepperProps>(
|
|
22
|
+
({ as: Root = 'ol', horizontal, className, ...props }) => (
|
|
23
|
+
<Root {...props} className={stepperClasses(horizontal, className)} />
|
|
24
|
+
)
|
|
25
|
+
);
|
|
26
|
+
Stepper.displayName = 'Stepper';
|
|
27
|
+
|
|
28
|
+
export interface StepperNavProps extends ComponentPropsWithRef<'nav'> {
|
|
29
|
+
horizontal?: StepperProps['horizontal'];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const StepperNav = polymorphic<StepperNavProps>(
|
|
33
|
+
({ as: Root = 'nav', horizontal, className, ...props }) => (
|
|
34
|
+
<Root {...props} className={stepperClasses(horizontal, className)} />
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
StepperNav.displayName = 'StepperNav';
|
|
38
|
+
|
|
39
|
+
interface StepStyle {
|
|
40
|
+
active?: boolean;
|
|
41
|
+
theme?: ComponentTheme;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type StepperItemProps = ComponentPropsWithRef<'li'> & StepStyle;
|
|
45
|
+
|
|
46
|
+
export const StepperItem = polymorphic<StepperItemProps>(
|
|
47
|
+
({ as: Root = 'li', active, theme, className, ...props }) => (
|
|
48
|
+
<Root
|
|
49
|
+
{...props}
|
|
50
|
+
className={classNames('stepper-item', { active }, theme && `theme-${theme}`, className)}
|
|
51
|
+
/>
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
StepperItem.displayName = 'StepperItem';
|
|
55
|
+
|
|
56
|
+
export type StepperLinkProps = ComponentPropsWithRef<'a'> & StepStyle;
|
|
57
|
+
|
|
58
|
+
export const StepperLink = polymorphic<StepperLinkProps>(
|
|
59
|
+
({ as: Root = 'a', active, theme, className, ...props }) => (
|
|
60
|
+
<Root
|
|
61
|
+
{...props}
|
|
62
|
+
className={classNames('stepper-item', { active }, theme && `theme-${theme}`, className)}
|
|
63
|
+
/>
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
StepperLink.displayName = 'StepperLink';
|
|
67
|
+
|
|
68
|
+
export type StepperButtonProps = ComponentPropsWithRef<'button'> & StepStyle;
|
|
69
|
+
|
|
70
|
+
export const StepperButton = polymorphic<StepperButtonProps>(
|
|
71
|
+
({ as: Root = 'button', active, theme, className, type = 'button', ...props }) => (
|
|
72
|
+
<Root
|
|
73
|
+
{...props}
|
|
74
|
+
type={type}
|
|
75
|
+
className={classNames(
|
|
76
|
+
'stepper-item p-0 border-0 bg-transparent',
|
|
77
|
+
{ active },
|
|
78
|
+
theme && `theme-${theme}`,
|
|
79
|
+
className
|
|
80
|
+
)}
|
|
81
|
+
/>
|
|
82
|
+
)
|
|
83
|
+
);
|
|
84
|
+
StepperButton.displayName = 'StepperButton';
|
|
85
|
+
|
|
86
|
+
export const StepperOverflow = polymorphic<ComponentPropsWithRef<'div'>>(
|
|
87
|
+
({ as: Root = 'div', className, ...props }) => (
|
|
88
|
+
<Root {...props} className={classNames('stepper-overflow', className)} />
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
StepperOverflow.displayName = 'StepperOverflow';
|