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
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef, CSSProperties, FC } from 'react';
|
|
3
|
+
|
|
4
|
+
import { Button, ButtonProps, ComponentTheme } from './Button';
|
|
5
|
+
|
|
6
|
+
export interface PlaceholderProps extends ComponentPropsWithRef<'span'> {
|
|
7
|
+
size?: 'xs' | 'sm' | 'lg';
|
|
8
|
+
animation?: 'wave' | 'pulse' | 'glow';
|
|
9
|
+
theme?: ComponentTheme;
|
|
10
|
+
width?: CSSProperties['width'];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const Placeholder: FC<PlaceholderProps> = ({
|
|
14
|
+
size,
|
|
15
|
+
animation,
|
|
16
|
+
theme,
|
|
17
|
+
width,
|
|
18
|
+
className,
|
|
19
|
+
style,
|
|
20
|
+
'aria-hidden': hidden = true,
|
|
21
|
+
...props
|
|
22
|
+
}) => (
|
|
23
|
+
<span
|
|
24
|
+
{...props}
|
|
25
|
+
className={classNames(
|
|
26
|
+
'placeholder',
|
|
27
|
+
size && `placeholder-${size}`,
|
|
28
|
+
animation && `placeholder-${animation}`,
|
|
29
|
+
theme && `bg-${theme}`,
|
|
30
|
+
className
|
|
31
|
+
)}
|
|
32
|
+
style={{ width, ...style }}
|
|
33
|
+
aria-hidden={hidden}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export interface PlaceholderAnimationProps extends ComponentPropsWithRef<'div'> {
|
|
38
|
+
animation?: PlaceholderProps['animation'];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const PlaceholderAnimation: FC<PlaceholderAnimationProps> = ({
|
|
42
|
+
animation = 'wave',
|
|
43
|
+
className,
|
|
44
|
+
...props
|
|
45
|
+
}) => (
|
|
46
|
+
<div
|
|
47
|
+
{...props}
|
|
48
|
+
className={classNames(`placeholder-${animation}`, className)}
|
|
49
|
+
aria-hidden="true"
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
export type PlaceholderButtonProps = ButtonProps;
|
|
54
|
+
|
|
55
|
+
export const PlaceholderButton: FC<PlaceholderButtonProps> = ({ className, ...props }) => (
|
|
56
|
+
<Button
|
|
57
|
+
{...props}
|
|
58
|
+
className={classNames('placeholder', className)}
|
|
59
|
+
aria-hidden="true"
|
|
60
|
+
disabled
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
Placeholder.displayName = 'Placeholder';
|
|
65
|
+
PlaceholderAnimation.displayName = 'PlaceholderAnimation';
|
|
66
|
+
PlaceholderButton.displayName = 'PlaceholderButton';
|
package/source/Popover.tsx
CHANGED
|
@@ -14,6 +14,7 @@ export const Popover: FC<PopoverProps> = ({
|
|
|
14
14
|
role = 'tooltip',
|
|
15
15
|
className,
|
|
16
16
|
children,
|
|
17
|
+
arrowStyle,
|
|
17
18
|
...props
|
|
18
19
|
}) => (
|
|
19
20
|
<div
|
|
@@ -25,10 +26,14 @@ export const Popover: FC<PopoverProps> = ({
|
|
|
25
26
|
className
|
|
26
27
|
)}
|
|
27
28
|
role={role}
|
|
29
|
+
hidden={!show}
|
|
28
30
|
data-bs-placement={placement}
|
|
29
31
|
>
|
|
30
|
-
<div
|
|
31
|
-
|
|
32
|
+
<div
|
|
33
|
+
style={arrowStyle}
|
|
34
|
+
className={classNames('popover-arrow', OVERLAY_ARROW_POSITIONS[placement])}
|
|
35
|
+
/>
|
|
36
|
+
{title != null && <h3 className="popover-header">{title}</h3>}
|
|
32
37
|
<div className="popover-body">{children}</div>
|
|
33
38
|
</div>
|
|
34
39
|
);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import './style.module.css';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { ComponentPropsWithRef, CSSProperties, FC } from 'react';
|
|
5
|
+
|
|
6
|
+
import { ComponentTheme } from '../Button';
|
|
7
|
+
|
|
8
|
+
export interface ProgressProps extends ComponentPropsWithRef<'div'> {
|
|
9
|
+
value: number;
|
|
10
|
+
min?: number;
|
|
11
|
+
max?: number;
|
|
12
|
+
theme?: ComponentTheme;
|
|
13
|
+
striped?: boolean;
|
|
14
|
+
animated?: boolean;
|
|
15
|
+
barProps?: ComponentPropsWithRef<'div'>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const Progress: FC<ProgressProps> = ({
|
|
19
|
+
value,
|
|
20
|
+
min = 0,
|
|
21
|
+
max = 100,
|
|
22
|
+
theme,
|
|
23
|
+
striped,
|
|
24
|
+
animated,
|
|
25
|
+
barProps = {},
|
|
26
|
+
className,
|
|
27
|
+
style,
|
|
28
|
+
children,
|
|
29
|
+
...props
|
|
30
|
+
}) => {
|
|
31
|
+
if (![value, min, max].every(Number.isFinite) || max <= min)
|
|
32
|
+
throw new RangeError('Progress requires finite values and max greater than min');
|
|
33
|
+
|
|
34
|
+
const current = Math.min(max, Math.max(min, value));
|
|
35
|
+
const width = `${((current - min) / (max - min)) * 100}%`;
|
|
36
|
+
const progressStyle: CSSProperties & { '--_progress-width': string } = {
|
|
37
|
+
...style,
|
|
38
|
+
'--_progress-width': width
|
|
39
|
+
};
|
|
40
|
+
const { className: barClass, style: barStyle, ...barAttributes } = barProps;
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div
|
|
44
|
+
{...props}
|
|
45
|
+
className={classNames('progress', className)}
|
|
46
|
+
style={progressStyle}
|
|
47
|
+
role="progressbar"
|
|
48
|
+
aria-valuenow={current}
|
|
49
|
+
aria-valuemin={min}
|
|
50
|
+
aria-valuemax={max}
|
|
51
|
+
>
|
|
52
|
+
<div
|
|
53
|
+
{...barAttributes}
|
|
54
|
+
className={classNames(
|
|
55
|
+
'progress-bar',
|
|
56
|
+
theme && `theme-${theme}`,
|
|
57
|
+
{
|
|
58
|
+
'progress-bar-striped': striped || animated,
|
|
59
|
+
'progress-bar-animated': animated
|
|
60
|
+
},
|
|
61
|
+
barClass
|
|
62
|
+
)}
|
|
63
|
+
style={barStyle}
|
|
64
|
+
>
|
|
65
|
+
{children}
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const ProgressStack: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
|
|
72
|
+
<div {...props} className={classNames('progress-stacked', className)} />
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
Progress.displayName = 'Progress';
|
|
76
|
+
ProgressStack.displayName = 'ProgressStack';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
:global(.progress) {
|
|
2
|
+
width: 100%;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
:global(.progress) > :global(.progress-bar) {
|
|
6
|
+
width: var(--_progress-width);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
:global(.progress-stacked) > :global(.progress) {
|
|
10
|
+
width: var(--_progress-width);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
:global(.progress-stacked) > :global(.progress) > :global(.progress-bar) {
|
|
14
|
+
width: 100%;
|
|
15
|
+
}
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { observer } from 'mobx-react';
|
|
5
|
+
import { Component, ComponentPropsWithRef, createRef, ReactNode } from 'react';
|
|
6
|
+
import { createPortal } from 'react-dom';
|
|
7
|
+
|
|
8
|
+
import { ScrollSpyModel } from './model';
|
|
9
|
+
|
|
10
|
+
export interface ScrollSpyProps extends Omit<
|
|
11
|
+
ComponentPropsWithRef<'div'>,
|
|
12
|
+
'onChange' | 'children'
|
|
13
|
+
> {
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
onActiveChange?: (id: string) => unknown;
|
|
17
|
+
rootMargin?: string | null;
|
|
18
|
+
scrollRoot?: 'self' | 'window';
|
|
19
|
+
smoothScroll?: boolean;
|
|
20
|
+
target?: string;
|
|
21
|
+
threshold?: number[];
|
|
22
|
+
topMargin?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface ScrollSpyEntry {
|
|
26
|
+
id: string;
|
|
27
|
+
link: HTMLAnchorElement;
|
|
28
|
+
section: HTMLElement;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@observer
|
|
32
|
+
export class ScrollSpy extends Component<ScrollSpyProps> {
|
|
33
|
+
static displayName = 'ScrollSpy';
|
|
34
|
+
|
|
35
|
+
root = createRef<HTMLDivElement>();
|
|
36
|
+
|
|
37
|
+
store = new ScrollSpyModel();
|
|
38
|
+
|
|
39
|
+
private entries: ScrollSpyEntry[] = [];
|
|
40
|
+
|
|
41
|
+
private observer?: IntersectionObserver;
|
|
42
|
+
|
|
43
|
+
private bottomObserver?: IntersectionObserver;
|
|
44
|
+
|
|
45
|
+
private intersecting = new Set<Element>();
|
|
46
|
+
|
|
47
|
+
private atBottom = false;
|
|
48
|
+
|
|
49
|
+
private mounted = false;
|
|
50
|
+
|
|
51
|
+
sentinel = createRef<HTMLDivElement>();
|
|
52
|
+
|
|
53
|
+
componentDidMount() {
|
|
54
|
+
this.mounted = true;
|
|
55
|
+
this.refresh();
|
|
56
|
+
|
|
57
|
+
this.root.current?.addEventListener('scroll', this.handleScroll, { passive: true });
|
|
58
|
+
window.addEventListener('scroll', this.handleScroll, { passive: true });
|
|
59
|
+
window.addEventListener('resize', this.handleResize);
|
|
60
|
+
document.addEventListener('click', this.handleNavigationClick);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
componentDidUpdate(previous: ScrollSpyProps) {
|
|
64
|
+
if (
|
|
65
|
+
previous.children !== this.props.children ||
|
|
66
|
+
previous.target !== this.props.target ||
|
|
67
|
+
previous.rootMargin !== this.props.rootMargin ||
|
|
68
|
+
previous.topMargin !== this.props.topMargin ||
|
|
69
|
+
previous.threshold !== this.props.threshold ||
|
|
70
|
+
previous.scrollRoot !== this.props.scrollRoot
|
|
71
|
+
)
|
|
72
|
+
this.refresh();
|
|
73
|
+
|
|
74
|
+
if (previous.debug !== this.props.debug) this.updateGuides();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
componentWillUnmount() {
|
|
78
|
+
this.mounted = false;
|
|
79
|
+
this.observer?.disconnect();
|
|
80
|
+
this.bottomObserver?.disconnect();
|
|
81
|
+
|
|
82
|
+
this.root.current?.removeEventListener('scroll', this.handleScroll);
|
|
83
|
+
window.removeEventListener('scroll', this.handleScroll);
|
|
84
|
+
window.removeEventListener('resize', this.handleResize);
|
|
85
|
+
document.removeEventListener('click', this.handleNavigationClick);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
refresh = () => {
|
|
89
|
+
const root = this.root.current;
|
|
90
|
+
if (!root) return;
|
|
91
|
+
|
|
92
|
+
const navigation = this.props.target
|
|
93
|
+
? document.querySelector<HTMLElement>(this.props.target)
|
|
94
|
+
: root;
|
|
95
|
+
const links = [...(navigation?.querySelectorAll<HTMLAnchorElement>('a[href^="#"]') ?? [])];
|
|
96
|
+
|
|
97
|
+
this.entries = links.flatMap(link => {
|
|
98
|
+
const hash = link.getAttribute('href')?.slice(1);
|
|
99
|
+
if (!hash) return [];
|
|
100
|
+
|
|
101
|
+
const id = decodeURIComponent(hash);
|
|
102
|
+
const section = document.getElementById(id);
|
|
103
|
+
|
|
104
|
+
return !section ||
|
|
105
|
+
section.hidden ||
|
|
106
|
+
section.closest('[hidden]') ||
|
|
107
|
+
section.getAttribute('aria-hidden') === 'true' ||
|
|
108
|
+
getComputedStyle(section).display === 'none' ||
|
|
109
|
+
getComputedStyle(section).visibility === 'hidden'
|
|
110
|
+
? []
|
|
111
|
+
: [{ id, link, section }];
|
|
112
|
+
});
|
|
113
|
+
this.entries.sort(
|
|
114
|
+
(first, second) =>
|
|
115
|
+
first.section.getBoundingClientRect().top -
|
|
116
|
+
second.section.getBoundingClientRect().top
|
|
117
|
+
);
|
|
118
|
+
this.rebuildObservers();
|
|
119
|
+
this.updateActive();
|
|
120
|
+
this.updateGuides();
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
handleResize = () => {
|
|
124
|
+
this.rebuildObservers();
|
|
125
|
+
this.updateGuides();
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
handleScroll = () => this.updateGuides();
|
|
129
|
+
|
|
130
|
+
private getRootHeight = () =>
|
|
131
|
+
this.props.scrollRoot === 'window'
|
|
132
|
+
? document.documentElement.clientHeight || window.innerHeight
|
|
133
|
+
: (this.root.current?.clientHeight ?? 0);
|
|
134
|
+
|
|
135
|
+
private getRootMargin = () => {
|
|
136
|
+
if (this.props.rootMargin != null) return this.props.rootMargin;
|
|
137
|
+
|
|
138
|
+
const { topMargin = '12%' } = this.props;
|
|
139
|
+
const value = Number.parseFloat(topMargin) || 0;
|
|
140
|
+
const height = this.getRootHeight();
|
|
141
|
+
const percent = topMargin.endsWith('%') ? value : height ? (value / height) * 100 : 12;
|
|
142
|
+
|
|
143
|
+
return `0px 0px -${Math.min(Math.max(100 - percent, 0), 100)}% 0px`;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
private rebuildObservers = () => {
|
|
147
|
+
this.observer?.disconnect();
|
|
148
|
+
this.bottomObserver?.disconnect();
|
|
149
|
+
this.intersecting.clear();
|
|
150
|
+
this.atBottom = false;
|
|
151
|
+
|
|
152
|
+
const root = this.props.scrollRoot === 'window' ? null : this.root.current;
|
|
153
|
+
const observer = new window.IntersectionObserver(
|
|
154
|
+
entries => {
|
|
155
|
+
if (!this.mounted || this.observer !== observer) return;
|
|
156
|
+
for (const entry of entries) {
|
|
157
|
+
if (entry.isIntersecting) this.intersecting.add(entry.target);
|
|
158
|
+
else this.intersecting.delete(entry.target);
|
|
159
|
+
}
|
|
160
|
+
this.updateActive();
|
|
161
|
+
},
|
|
162
|
+
{ root, rootMargin: this.getRootMargin(), threshold: this.props.threshold ?? [0] }
|
|
163
|
+
);
|
|
164
|
+
this.observer = observer;
|
|
165
|
+
|
|
166
|
+
for (const section of new Set(this.entries.map(entry => entry.section)))
|
|
167
|
+
observer.observe(section);
|
|
168
|
+
|
|
169
|
+
const bottomObserver = new window.IntersectionObserver(
|
|
170
|
+
entries => {
|
|
171
|
+
if (!this.mounted || this.bottomObserver !== bottomObserver) return;
|
|
172
|
+
|
|
173
|
+
const scroller = root ?? document.scrollingElement ?? document.documentElement;
|
|
174
|
+
this.atBottom =
|
|
175
|
+
Boolean(entries.at(-1)?.isIntersecting) &&
|
|
176
|
+
scroller.scrollHeight > scroller.clientHeight;
|
|
177
|
+
this.updateActive();
|
|
178
|
+
this.updateGuides();
|
|
179
|
+
},
|
|
180
|
+
{ root, threshold: [0] }
|
|
181
|
+
);
|
|
182
|
+
this.bottomObserver = bottomObserver;
|
|
183
|
+
if (this.sentinel.current) bottomObserver.observe(this.sentinel.current);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
handleNavigationClick = (event: globalThis.MouseEvent) => {
|
|
187
|
+
if (!this.props.smoothScroll || event.defaultPrevented) return;
|
|
188
|
+
|
|
189
|
+
const link =
|
|
190
|
+
event.target instanceof Element
|
|
191
|
+
? event.target.closest<HTMLAnchorElement>('a[href^="#"]')
|
|
192
|
+
: null;
|
|
193
|
+
const entry = this.entries.find(candidate => candidate.link === link);
|
|
194
|
+
if (!link || !entry) return;
|
|
195
|
+
|
|
196
|
+
event.preventDefault();
|
|
197
|
+
const root = this.root.current;
|
|
198
|
+
const { scrollRoot = 'self' } = this.props;
|
|
199
|
+
|
|
200
|
+
if (scrollRoot === 'window')
|
|
201
|
+
window.scrollTo({
|
|
202
|
+
top: window.scrollY + entry.section.getBoundingClientRect().top,
|
|
203
|
+
behavior: 'smooth'
|
|
204
|
+
});
|
|
205
|
+
else if (root) {
|
|
206
|
+
const top =
|
|
207
|
+
root.scrollTop +
|
|
208
|
+
entry.section.getBoundingClientRect().top -
|
|
209
|
+
root.getBoundingClientRect().top;
|
|
210
|
+
|
|
211
|
+
root.scrollTo({ top, behavior: 'smooth' });
|
|
212
|
+
}
|
|
213
|
+
window.history.replaceState(null, '', `#${encodeURIComponent(entry.id)}`);
|
|
214
|
+
|
|
215
|
+
const temporaryTabIndex = !entry.section.hasAttribute('tabindex');
|
|
216
|
+
if (temporaryTabIndex) entry.section.tabIndex = -1;
|
|
217
|
+
|
|
218
|
+
entry.section.focus({ preventScroll: true });
|
|
219
|
+
|
|
220
|
+
if (temporaryTabIndex) entry.section.removeAttribute('tabindex');
|
|
221
|
+
this.updateActive();
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
private getActivationLine = (rootHeight: number) => {
|
|
225
|
+
const margins = this.getRootMargin().trim().split(/\s+/);
|
|
226
|
+
const bottom = margins[2] ?? margins[0];
|
|
227
|
+
const parsed = Number.parseFloat(bottom) || 0;
|
|
228
|
+
|
|
229
|
+
return rootHeight + (bottom.endsWith('%') ? (rootHeight * parsed) / 100 : parsed);
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
private updateGuides = () => {
|
|
233
|
+
const root = this.root.current;
|
|
234
|
+
if (!this.props.debug || !root) return this.store.setGuides(undefined);
|
|
235
|
+
|
|
236
|
+
const rect = root.getBoundingClientRect();
|
|
237
|
+
const height = this.getRootHeight();
|
|
238
|
+
|
|
239
|
+
this.store.setGuides({
|
|
240
|
+
top: this.props.scrollRoot === 'window' ? 0 : rect.top,
|
|
241
|
+
left: this.props.scrollRoot === 'window' ? 0 : rect.left,
|
|
242
|
+
width: this.props.scrollRoot === 'window' ? window.innerWidth : root.clientWidth,
|
|
243
|
+
height,
|
|
244
|
+
line: this.getActivationLine(height),
|
|
245
|
+
atBottom: this.atBottom
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
private updateActive = () => {
|
|
250
|
+
const root = this.root.current;
|
|
251
|
+
if (!root || !this.entries.length) return;
|
|
252
|
+
|
|
253
|
+
const lastEntry = this.entries.at(-1);
|
|
254
|
+
const current =
|
|
255
|
+
(this.atBottom ? lastEntry : undefined) ??
|
|
256
|
+
[...this.entries].reverse().find(({ section }) => this.intersecting.has(section)) ??
|
|
257
|
+
this.entries.find(entry => entry.id === this.store.activeId) ??
|
|
258
|
+
this.entries[0];
|
|
259
|
+
const activeLinks = new Set(
|
|
260
|
+
this.entries.filter(entry => entry.id === current.id).map(entry => entry.link)
|
|
261
|
+
);
|
|
262
|
+
let nestedNav = current.link.closest('.nav');
|
|
263
|
+
let parentNav = nestedNav?.parentElement?.closest('.nav');
|
|
264
|
+
|
|
265
|
+
while (parentNav && parentNav !== this.root.current) {
|
|
266
|
+
const parentEntry = [...this.entries]
|
|
267
|
+
.reverse()
|
|
268
|
+
.find(
|
|
269
|
+
entry =>
|
|
270
|
+
entry.link.closest('.nav') === parentNav &&
|
|
271
|
+
Boolean(
|
|
272
|
+
entry.section.compareDocumentPosition(current.section) &
|
|
273
|
+
Node.DOCUMENT_POSITION_FOLLOWING
|
|
274
|
+
)
|
|
275
|
+
);
|
|
276
|
+
if (parentEntry) activeLinks.add(parentEntry.link);
|
|
277
|
+
nestedNav = parentNav;
|
|
278
|
+
parentNav = nestedNav.parentElement?.closest('.nav');
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
for (const { link } of this.entries) {
|
|
282
|
+
const active = activeLinks.has(link);
|
|
283
|
+
|
|
284
|
+
link.classList.toggle('active', active);
|
|
285
|
+
|
|
286
|
+
if (active) link.setAttribute('aria-current', 'location');
|
|
287
|
+
else link.removeAttribute('aria-current');
|
|
288
|
+
}
|
|
289
|
+
if (current.id === this.store.activeId) return;
|
|
290
|
+
|
|
291
|
+
this.store.setActiveId(current.id);
|
|
292
|
+
this.props.onActiveChange?.(current.id);
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
renderDebug = () => {
|
|
296
|
+
const guides = this.store.guides;
|
|
297
|
+
if (!this.props.debug || !guides) return null;
|
|
298
|
+
|
|
299
|
+
const { top, left, width, height, line, atBottom } = guides;
|
|
300
|
+
|
|
301
|
+
return createPortal(
|
|
302
|
+
<div
|
|
303
|
+
className="position-fixed overflow-hidden pe-none"
|
|
304
|
+
style={{ top, left, width, height, zIndex: 1080 }}
|
|
305
|
+
aria-hidden="true"
|
|
306
|
+
data-scrollspy-debug
|
|
307
|
+
>
|
|
308
|
+
<div
|
|
309
|
+
className="position-absolute start-0 end-0 border-top border-danger border-2"
|
|
310
|
+
style={{ top: line, borderTopStyle: 'dashed' }}
|
|
311
|
+
data-scrollspy-line
|
|
312
|
+
/>
|
|
313
|
+
<div
|
|
314
|
+
className="position-absolute bottom-0 start-0 end-0 border-top border-danger"
|
|
315
|
+
style={{
|
|
316
|
+
height: 12,
|
|
317
|
+
borderTop: '1px solid #dc3545',
|
|
318
|
+
background: atBottom ? 'rgb(220 53 69 / 40%)' : 'rgb(220 53 69 / 10%)'
|
|
319
|
+
}}
|
|
320
|
+
data-scrollspy-bottom={atBottom ? 'reached' : 'pending'}
|
|
321
|
+
/>
|
|
322
|
+
</div>,
|
|
323
|
+
document.body
|
|
324
|
+
);
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
render() {
|
|
328
|
+
const {
|
|
329
|
+
children,
|
|
330
|
+
className,
|
|
331
|
+
debug: _debug,
|
|
332
|
+
onActiveChange: _onActiveChange,
|
|
333
|
+
onClick: _onClick,
|
|
334
|
+
onKeyDown: _onKeyDown,
|
|
335
|
+
rootMargin: _rootMargin,
|
|
336
|
+
scrollRoot: _scrollRoot,
|
|
337
|
+
smoothScroll: _smoothScroll,
|
|
338
|
+
target: _target,
|
|
339
|
+
threshold: _threshold,
|
|
340
|
+
topMargin: _topMargin,
|
|
341
|
+
...props
|
|
342
|
+
} = this.props;
|
|
343
|
+
|
|
344
|
+
return (
|
|
345
|
+
<div
|
|
346
|
+
{...props}
|
|
347
|
+
ref={this.root}
|
|
348
|
+
className={classNames('scrollspy', className)}
|
|
349
|
+
data-active-id={this.store.activeId || undefined}
|
|
350
|
+
data-bs-root-margin={this.props.rootMargin ?? undefined}
|
|
351
|
+
tabIndex={this.props.tabIndex ?? 0}
|
|
352
|
+
onClick={this.props.onClick}
|
|
353
|
+
onKeyDown={this.props.onKeyDown}
|
|
354
|
+
>
|
|
355
|
+
{children}
|
|
356
|
+
<div
|
|
357
|
+
ref={this.sentinel}
|
|
358
|
+
className="position-relative invisible m-0 border-0 p-0 w-0 h-0"
|
|
359
|
+
aria-hidden="true"
|
|
360
|
+
/>
|
|
361
|
+
{this.renderDebug()}
|
|
362
|
+
</div>
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
@@ -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
|
@@ -2,6 +2,7 @@ import classNames from 'classnames';
|
|
|
2
2
|
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
3
|
|
|
4
4
|
import type { ComponentTheme } from './Button';
|
|
5
|
+
import { Icon, IconProps } from './Extension/Icon';
|
|
5
6
|
|
|
6
7
|
export type SpinnerAnimation = 'border' | 'grow';
|
|
7
8
|
|
|
@@ -16,10 +17,12 @@ export const Spinner: FC<SpinnerProps> = ({
|
|
|
16
17
|
size,
|
|
17
18
|
theme,
|
|
18
19
|
className,
|
|
20
|
+
role = 'status',
|
|
19
21
|
...props
|
|
20
22
|
}) => (
|
|
21
23
|
<span
|
|
22
24
|
{...props}
|
|
25
|
+
role={role}
|
|
23
26
|
className={classNames(
|
|
24
27
|
`spinner-${animation}`,
|
|
25
28
|
size && `spinner-${size}`,
|
|
@@ -28,3 +31,10 @@ export const Spinner: FC<SpinnerProps> = ({
|
|
|
28
31
|
)}
|
|
29
32
|
/>
|
|
30
33
|
);
|
|
34
|
+
|
|
35
|
+
export const SpinnerIcon: FC<IconProps> = ({ className, ...props }) => (
|
|
36
|
+
<Icon {...props} className={classNames('spinner-rotate', className)} />
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
Spinner.displayName = 'Spinner';
|
|
40
|
+
SpinnerIcon.displayName = 'SpinnerIcon';
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
|
+
|
|
4
|
+
import { ComponentTheme } from './Button';
|
|
5
|
+
import { Breakpoint } from './Grid';
|
|
6
|
+
|
|
7
|
+
export interface StepperProps extends ComponentPropsWithRef<'ol'> {
|
|
8
|
+
horizontal?: boolean | Breakpoint;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const stepperClasses = (horizontal: StepperProps['horizontal'], className?: string) =>
|
|
12
|
+
classNames(
|
|
13
|
+
'stepper',
|
|
14
|
+
horizontal === true
|
|
15
|
+
? 'stepper-horizontal'
|
|
16
|
+
: horizontal && `${horizontal}:stepper-horizontal`,
|
|
17
|
+
className
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export const Stepper: FC<StepperProps> = ({ horizontal, className, ...props }) => (
|
|
21
|
+
<ol {...props} className={stepperClasses(horizontal, className)} />
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export interface StepperNavProps extends ComponentPropsWithRef<'nav'> {
|
|
25
|
+
horizontal?: StepperProps['horizontal'];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const StepperNav: FC<StepperNavProps> = ({ horizontal, className, ...props }) => (
|
|
29
|
+
<nav {...props} className={stepperClasses(horizontal, className)} />
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
interface StepStyle {
|
|
33
|
+
active?: boolean;
|
|
34
|
+
theme?: ComponentTheme;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type StepperItemProps = ComponentPropsWithRef<'li'> & StepStyle;
|
|
38
|
+
|
|
39
|
+
export const StepperItem: FC<StepperItemProps> = ({ active, theme, className, ...props }) => (
|
|
40
|
+
<li
|
|
41
|
+
{...props}
|
|
42
|
+
className={classNames('stepper-item', { active }, theme && `theme-${theme}`, className)}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
export type StepperLinkProps = ComponentPropsWithRef<'a'> & StepStyle;
|
|
47
|
+
|
|
48
|
+
export const StepperLink: FC<StepperLinkProps> = ({ active, theme, className, ...props }) => (
|
|
49
|
+
<a
|
|
50
|
+
{...props}
|
|
51
|
+
className={classNames('stepper-item', { active }, theme && `theme-${theme}`, className)}
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export type StepperButtonProps = ComponentPropsWithRef<'button'> & StepStyle;
|
|
56
|
+
|
|
57
|
+
export const StepperButton: FC<StepperButtonProps> = ({
|
|
58
|
+
active,
|
|
59
|
+
theme,
|
|
60
|
+
className,
|
|
61
|
+
type = 'button',
|
|
62
|
+
...props
|
|
63
|
+
}) => (
|
|
64
|
+
<button
|
|
65
|
+
{...props}
|
|
66
|
+
type={type}
|
|
67
|
+
className={classNames(
|
|
68
|
+
'stepper-item p-0 border-0 bg-transparent',
|
|
69
|
+
{ active },
|
|
70
|
+
theme && `theme-${theme}`,
|
|
71
|
+
className
|
|
72
|
+
)}
|
|
73
|
+
/>
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
export const StepperOverflow: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
|
|
77
|
+
<div {...props} className={classNames('stepper-overflow', className)} />
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
Stepper.displayName = 'Stepper';
|
|
81
|
+
StepperNav.displayName = 'StepperNav';
|
|
82
|
+
StepperItem.displayName = 'StepperItem';
|
|
83
|
+
StepperLink.displayName = 'StepperLink';
|
|
84
|
+
StepperButton.displayName = 'StepperButton';
|
|
85
|
+
StepperOverflow.displayName = 'StepperOverflow';
|