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,113 @@
|
|
|
1
|
+
import { action, observable } from 'mobx';
|
|
2
|
+
|
|
3
|
+
export type CarouselEnds = 'loop' | 'wrap' | 'stop';
|
|
4
|
+
|
|
5
|
+
export class CarouselModel {
|
|
6
|
+
@observable accessor activeIndex = 0;
|
|
7
|
+
|
|
8
|
+
@observable accessor playing = false;
|
|
9
|
+
|
|
10
|
+
private timer?: ReturnType<typeof setTimeout>;
|
|
11
|
+
|
|
12
|
+
private hovering = false;
|
|
13
|
+
|
|
14
|
+
private visible = true;
|
|
15
|
+
|
|
16
|
+
onChange?: (index: number) => unknown;
|
|
17
|
+
|
|
18
|
+
onNavigate?: (index: number, from: number, direction?: -1 | 1) => unknown;
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
private count: number,
|
|
22
|
+
private ends: CarouselEnds,
|
|
23
|
+
private interval: (index: number) => number
|
|
24
|
+
) {}
|
|
25
|
+
|
|
26
|
+
@action
|
|
27
|
+
setIndex = (index: number, userInitiated = false, direction?: -1 | 1, fromScroll = false) => {
|
|
28
|
+
const nextIndex = Math.max(0, Math.min(index, this.count - 1));
|
|
29
|
+
|
|
30
|
+
if (nextIndex !== this.activeIndex) {
|
|
31
|
+
const from = this.activeIndex;
|
|
32
|
+
this.activeIndex = nextIndex;
|
|
33
|
+
this.onChange?.(nextIndex);
|
|
34
|
+
if (!fromScroll) this.onNavigate?.(nextIndex, from, direction);
|
|
35
|
+
}
|
|
36
|
+
if (userInitiated) this.pause();
|
|
37
|
+
else this.schedule();
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
@action
|
|
41
|
+
next = (userInitiated = false) => {
|
|
42
|
+
if (this.activeIndex === this.count - 1 && this.ends === 'stop') {
|
|
43
|
+
if (!userInitiated) this.pause();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
this.setIndex(
|
|
47
|
+
this.activeIndex === this.count - 1 ? 0 : this.activeIndex + 1,
|
|
48
|
+
userInitiated,
|
|
49
|
+
1
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
@action
|
|
54
|
+
previous = (userInitiated = false) => {
|
|
55
|
+
if (this.activeIndex === 0 && this.ends === 'stop') {
|
|
56
|
+
if (!userInitiated) this.pause();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this.setIndex(
|
|
60
|
+
this.activeIndex === 0 ? this.count - 1 : this.activeIndex - 1,
|
|
61
|
+
userInitiated,
|
|
62
|
+
-1
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
@action
|
|
67
|
+
play = () => {
|
|
68
|
+
this.playing = true;
|
|
69
|
+
this.schedule();
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
@action
|
|
73
|
+
pause = () => {
|
|
74
|
+
this.playing = false;
|
|
75
|
+
this.clearTimer();
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
@action
|
|
79
|
+
toggle = () => (this.playing ? this.pause() : this.play());
|
|
80
|
+
|
|
81
|
+
setHovering = (hovering: boolean) => {
|
|
82
|
+
this.hovering = hovering;
|
|
83
|
+
this.schedule();
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
setVisible = (visible: boolean) => {
|
|
87
|
+
this.visible = visible;
|
|
88
|
+
this.schedule();
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
update = (count: number, ends: CarouselEnds, interval: (index: number) => number) => {
|
|
92
|
+
this.count = count;
|
|
93
|
+
this.ends = ends;
|
|
94
|
+
this.interval = interval;
|
|
95
|
+
|
|
96
|
+
if (this.activeIndex >= count) this.setIndex(Math.max(0, count - 1));
|
|
97
|
+
else this.schedule();
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
dispose = () => this.clearTimer();
|
|
101
|
+
|
|
102
|
+
private schedule = () => {
|
|
103
|
+
this.clearTimer();
|
|
104
|
+
if (!this.playing || this.hovering || !this.visible || this.count < 2) return;
|
|
105
|
+
|
|
106
|
+
this.timer = setTimeout(this.next, Math.max(0, this.interval(this.activeIndex)));
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
private clearTimer = () => {
|
|
110
|
+
if (this.timer) clearTimeout(this.timer);
|
|
111
|
+
this.timer = undefined;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export class CarouselScroll {
|
|
2
|
+
private frame?: number;
|
|
3
|
+
|
|
4
|
+
private clone?: HTMLElement;
|
|
5
|
+
|
|
6
|
+
private track?: HTMLElement;
|
|
7
|
+
|
|
8
|
+
private snap = '';
|
|
9
|
+
|
|
10
|
+
get looping() {
|
|
11
|
+
return Boolean(this.clone) || this.frame !== undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
navigate = (track: HTMLElement, left: number, smooth: boolean) => {
|
|
15
|
+
this.dispose();
|
|
16
|
+
if (!smooth || track.scrollLeft === left) {
|
|
17
|
+
track.scrollTo({ left, behavior: 'instant' });
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
this.track = track;
|
|
21
|
+
this.snap = track.style.scrollSnapType;
|
|
22
|
+
track.style.scrollSnapType = 'none';
|
|
23
|
+
this.animate(track, track.scrollLeft, left);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
loop = (track: HTMLElement, from: HTMLElement, destination: HTMLElement, forward: boolean) => {
|
|
27
|
+
this.dispose();
|
|
28
|
+
this.track = track;
|
|
29
|
+
this.snap = track.style.scrollSnapType;
|
|
30
|
+
|
|
31
|
+
const clone = destination.cloneNode(true) as HTMLElement;
|
|
32
|
+
clone.removeAttribute('id');
|
|
33
|
+
|
|
34
|
+
for (const element of clone.querySelectorAll('[id]')) element.removeAttribute('id');
|
|
35
|
+
|
|
36
|
+
clone.setAttribute('aria-hidden', 'true');
|
|
37
|
+
clone.inert = true;
|
|
38
|
+
clone.dataset.carouselClone = 'true';
|
|
39
|
+
clone.classList.remove('active');
|
|
40
|
+
this.clone = clone;
|
|
41
|
+
track.style.scrollSnapType = 'none';
|
|
42
|
+
|
|
43
|
+
if (forward) track.append(clone);
|
|
44
|
+
else track.prepend(clone);
|
|
45
|
+
|
|
46
|
+
const start = from.offsetLeft;
|
|
47
|
+
const end = clone.offsetLeft;
|
|
48
|
+
|
|
49
|
+
track.scrollTo({ left: start, behavior: 'instant' });
|
|
50
|
+
this.animate(track, start, end, () => {
|
|
51
|
+
this.dispose();
|
|
52
|
+
track.scrollTo({ left: destination.offsetLeft, behavior: 'instant' });
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
private animate = (track: HTMLElement, start: number, end: number, complete = this.dispose) => {
|
|
57
|
+
const startedAt = window.performance.now();
|
|
58
|
+
|
|
59
|
+
const animate = (time: number) => {
|
|
60
|
+
const progress = Math.min(1, (time - startedAt) / 400);
|
|
61
|
+
const eased = 1 - (1 - progress) ** 3;
|
|
62
|
+
|
|
63
|
+
track.scrollTo({ left: start + (end - start) * eased, behavior: 'instant' });
|
|
64
|
+
|
|
65
|
+
if (progress < 1) this.frame = window.requestAnimationFrame(animate);
|
|
66
|
+
else complete();
|
|
67
|
+
};
|
|
68
|
+
this.frame = window.requestAnimationFrame(animate);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
dispose = () => {
|
|
72
|
+
if (this.frame !== undefined) window.cancelAnimationFrame(this.frame);
|
|
73
|
+
this.frame = undefined;
|
|
74
|
+
this.clone?.remove();
|
|
75
|
+
this.clone = undefined;
|
|
76
|
+
if (this.track) this.track.style.scrollSnapType = this.snap;
|
|
77
|
+
this.track = undefined;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { action, observable } from 'mobx';
|
|
5
|
+
import { observer } from 'mobx-react';
|
|
6
|
+
import { Component, ComponentPropsWithoutRef, createRef, HTMLAttributes, MouseEvent } from 'react';
|
|
7
|
+
|
|
8
|
+
import { Button, ButtonProps } from './Button';
|
|
9
|
+
|
|
10
|
+
const TOGGLE = 'idea-react:collapse-toggle';
|
|
11
|
+
const CHANGE = 'idea-react:collapse-change';
|
|
12
|
+
const OPEN = 'idea-react:collapse-open';
|
|
13
|
+
|
|
14
|
+
export interface CollapseProps extends ComponentPropsWithoutRef<'div'> {
|
|
15
|
+
horizontal?: boolean;
|
|
16
|
+
open?: boolean;
|
|
17
|
+
defaultOpen?: boolean;
|
|
18
|
+
parent?: string;
|
|
19
|
+
onOpenChange?: (open: boolean) => unknown;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@observer
|
|
23
|
+
export class Collapse extends Component<CollapseProps> {
|
|
24
|
+
static displayName = 'Collapse';
|
|
25
|
+
|
|
26
|
+
@observable accessor expanded = this.props.defaultOpen ?? false;
|
|
27
|
+
|
|
28
|
+
root = createRef<HTMLDivElement>();
|
|
29
|
+
|
|
30
|
+
get isOpen() {
|
|
31
|
+
return this.props.open ?? this.expanded;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
componentDidMount() {
|
|
35
|
+
this.root.current!.addEventListener(TOGGLE, this.handleToggle);
|
|
36
|
+
document.addEventListener(OPEN, this.handlePeerOpen);
|
|
37
|
+
this.notify();
|
|
38
|
+
if (this.isOpen) this.notifyOpen();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
componentDidUpdate(previous: CollapseProps) {
|
|
42
|
+
if (previous.open !== this.props.open && this.isOpen) this.notifyOpen();
|
|
43
|
+
|
|
44
|
+
this.notify();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
componentWillUnmount() {
|
|
48
|
+
this.root.current!.removeEventListener(TOGGLE, this.handleToggle);
|
|
49
|
+
document.removeEventListener(OPEN, this.handlePeerOpen);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
notify = () => this.root.current!.dispatchEvent(new Event(CHANGE, { bubbles: true }));
|
|
53
|
+
|
|
54
|
+
notifyOpen = () => this.root.current!.dispatchEvent(new Event(OPEN, { bubbles: true }));
|
|
55
|
+
|
|
56
|
+
setOpen = action((open: boolean) => {
|
|
57
|
+
if (open === this.isOpen) return;
|
|
58
|
+
|
|
59
|
+
this.props.onOpenChange?.(open);
|
|
60
|
+
|
|
61
|
+
if (this.props.open === undefined) {
|
|
62
|
+
this.expanded = open;
|
|
63
|
+
if (open) this.notifyOpen();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
handleToggle = (event: Event) => {
|
|
68
|
+
if (event.target === this.root.current) this.setOpen(!this.isOpen);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
handlePeerOpen = ({ target }: Event) => {
|
|
72
|
+
const { parent } = this.props;
|
|
73
|
+
const root = this.root.current;
|
|
74
|
+
const group = parent ? root?.closest(parent) : null;
|
|
75
|
+
|
|
76
|
+
if (
|
|
77
|
+
parent &&
|
|
78
|
+
group &&
|
|
79
|
+
target instanceof Element &&
|
|
80
|
+
target !== root &&
|
|
81
|
+
target.closest(parent) === group
|
|
82
|
+
)
|
|
83
|
+
this.setOpen(false);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
render() {
|
|
87
|
+
const {
|
|
88
|
+
open: _open,
|
|
89
|
+
defaultOpen: _defaultOpen,
|
|
90
|
+
parent: _parent,
|
|
91
|
+
onOpenChange: _onOpenChange,
|
|
92
|
+
horizontal,
|
|
93
|
+
className,
|
|
94
|
+
...props
|
|
95
|
+
} = this.props;
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<div
|
|
99
|
+
{...props}
|
|
100
|
+
ref={this.root}
|
|
101
|
+
className={classNames(
|
|
102
|
+
'collapse',
|
|
103
|
+
{ 'collapse-horizontal': horizontal, show: this.isOpen },
|
|
104
|
+
className
|
|
105
|
+
)}
|
|
106
|
+
/>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface CollapseToggleProps
|
|
112
|
+
extends
|
|
113
|
+
HTMLAttributes<HTMLElement>,
|
|
114
|
+
Pick<ButtonProps, 'variant' | 'theme' | 'size' | 'disabled' | 'icon' | 'styled'> {
|
|
115
|
+
target: string;
|
|
116
|
+
href?: string;
|
|
117
|
+
type?: 'button' | 'submit' | 'reset';
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@observer
|
|
121
|
+
export class CollapseToggle extends Component<CollapseToggleProps> {
|
|
122
|
+
static displayName = 'CollapseToggle';
|
|
123
|
+
|
|
124
|
+
@observable accessor expanded = false;
|
|
125
|
+
@observable accessor controls = '';
|
|
126
|
+
|
|
127
|
+
get targets() {
|
|
128
|
+
return [...document.querySelectorAll<HTMLElement>(this.props.target)];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
componentDidMount() {
|
|
132
|
+
document.addEventListener(CHANGE, this.refresh);
|
|
133
|
+
this.refresh();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
componentDidUpdate(previous: CollapseToggleProps) {
|
|
137
|
+
if (previous.target !== this.props.target) this.refresh();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
componentWillUnmount() {
|
|
141
|
+
document.removeEventListener(CHANGE, this.refresh);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
refresh = action(() => {
|
|
145
|
+
const { targets } = this;
|
|
146
|
+
|
|
147
|
+
this.expanded = targets.some(element => element.classList.contains('show'));
|
|
148
|
+
this.controls = targets
|
|
149
|
+
.map(({ id }) => id)
|
|
150
|
+
.filter(Boolean)
|
|
151
|
+
.join(' ');
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
handleClick = (event: MouseEvent<HTMLElement>) => {
|
|
155
|
+
this.props.onClick?.(event);
|
|
156
|
+
|
|
157
|
+
if (event.defaultPrevented) return;
|
|
158
|
+
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
|
|
161
|
+
for (const target of this.targets) target.dispatchEvent(new Event(TOGGLE));
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
render() {
|
|
165
|
+
const { target: _target, href, ...props } = this.props;
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<Button
|
|
169
|
+
{...props}
|
|
170
|
+
role={props.role ?? 'button'}
|
|
171
|
+
href={href}
|
|
172
|
+
aria-controls={this.controls || undefined}
|
|
173
|
+
aria-expanded={this.expanded}
|
|
174
|
+
onClick={this.handleClick}
|
|
175
|
+
/>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
package/source/Drawer.tsx
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
|
-
import {
|
|
4
|
+
import { action, observable } from 'mobx';
|
|
5
|
+
import { observer } from 'mobx-react';
|
|
6
|
+
import { Component, ComponentPropsWithRef, createRef, FC, ReactNode } from 'react';
|
|
5
7
|
|
|
6
8
|
import { CloseButton } from './CloseButton';
|
|
9
|
+
import { Breakpoint } from './Grid';
|
|
7
10
|
import { NativeDialog, NativeDialogProps } from './NativeDialog';
|
|
8
11
|
|
|
9
12
|
export type DrawerPlacement = 'start' | 'end' | 'top' | 'bottom';
|
|
@@ -24,39 +27,133 @@ export const DrawerFooter: FC<ComponentPropsWithRef<'div'>> = ({ className, ...p
|
|
|
24
27
|
<div {...props} className={classNames('drawer-footer', className)} />
|
|
25
28
|
);
|
|
26
29
|
|
|
27
|
-
export interface DrawerProps extends Omit<
|
|
30
|
+
export interface DrawerProps extends Omit<
|
|
31
|
+
NativeDialogProps,
|
|
32
|
+
'dialog' | 'onClose' | 'title' | 'animation' | 'fullscreen'
|
|
33
|
+
> {
|
|
28
34
|
title?: ReactNode;
|
|
29
35
|
placement?: DrawerPlacement;
|
|
30
36
|
footer?: ReactNode;
|
|
31
37
|
bodyClassName?: string;
|
|
32
|
-
|
|
38
|
+
sheet?: boolean;
|
|
39
|
+
translucent?: boolean;
|
|
40
|
+
responsive?: Breakpoint;
|
|
41
|
+
fullscreen?: boolean;
|
|
42
|
+
animation?: 'slide' | 'instant';
|
|
43
|
+
onDismiss?: () => unknown;
|
|
33
44
|
}
|
|
34
45
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
);
|
|
46
|
+
const BREAKPOINT_WIDTHS: Record<Breakpoint, number> = {
|
|
47
|
+
sm: 576,
|
|
48
|
+
md: 768,
|
|
49
|
+
lg: 1024,
|
|
50
|
+
xl: 1280,
|
|
51
|
+
'2xl': 1536
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
@observer
|
|
55
|
+
export class Drawer extends Component<DrawerProps> {
|
|
56
|
+
static displayName = 'Drawer';
|
|
57
|
+
|
|
58
|
+
@observable accessor expanded = false;
|
|
59
|
+
|
|
60
|
+
dialog = createRef<NativeDialog>();
|
|
61
|
+
media?: MediaQueryList;
|
|
62
|
+
dismissed = false;
|
|
63
|
+
|
|
64
|
+
componentDidMount() {
|
|
65
|
+
this.observeBreakpoint();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
componentDidUpdate({ responsive, open }: DrawerProps) {
|
|
69
|
+
if (responsive !== this.props.responsive) this.observeBreakpoint();
|
|
70
|
+
|
|
71
|
+
if (open !== this.props.open && this.props.open) this.dismissed = false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
componentWillUnmount() {
|
|
75
|
+
this.media?.removeEventListener('change', this.handleBreakpoint);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
observeBreakpoint = () => {
|
|
79
|
+
this.media?.removeEventListener('change', this.handleBreakpoint);
|
|
61
80
|
|
|
62
|
-
|
|
81
|
+
const { responsive } = this.props;
|
|
82
|
+
this.media = responsive
|
|
83
|
+
? window.matchMedia(`(min-width: ${BREAKPOINT_WIDTHS[responsive]}px)`)
|
|
84
|
+
: undefined;
|
|
85
|
+
this.handleBreakpoint();
|
|
86
|
+
this.media?.addEventListener('change', this.handleBreakpoint);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
@action
|
|
90
|
+
handleBreakpoint = () => (this.expanded = this.media?.matches ?? false);
|
|
91
|
+
|
|
92
|
+
handleDismiss = () => {
|
|
93
|
+
this.props.onDismiss?.();
|
|
94
|
+
|
|
95
|
+
this.dismissed = true;
|
|
96
|
+
this.dialog.current?.close();
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
handleClose = () => {
|
|
100
|
+
if (!this.dismissed && !this.expanded) this.props.onDismiss?.();
|
|
101
|
+
|
|
102
|
+
this.dismissed = false;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
render() {
|
|
106
|
+
const {
|
|
107
|
+
title,
|
|
108
|
+
placement = 'end',
|
|
109
|
+
footer,
|
|
110
|
+
bodyClassName,
|
|
111
|
+
onDismiss: _onDismiss,
|
|
112
|
+
sheet,
|
|
113
|
+
translucent,
|
|
114
|
+
responsive,
|
|
115
|
+
animation = 'slide',
|
|
116
|
+
fullscreen,
|
|
117
|
+
open,
|
|
118
|
+
modal,
|
|
119
|
+
scroll,
|
|
120
|
+
backdrop,
|
|
121
|
+
className,
|
|
122
|
+
children,
|
|
123
|
+
...props
|
|
124
|
+
} = this.props;
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<NativeDialog
|
|
128
|
+
{...props}
|
|
129
|
+
ref={this.dialog}
|
|
130
|
+
open={this.expanded || open}
|
|
131
|
+
modal={this.expanded ? false : (modal ?? !(scroll && backdrop === false))}
|
|
132
|
+
scroll={scroll}
|
|
133
|
+
backdrop={backdrop}
|
|
134
|
+
dialog={false}
|
|
135
|
+
tabIndex={-1}
|
|
136
|
+
aria-label={typeof title === 'string' ? title : props['aria-label']}
|
|
137
|
+
className={classNames(
|
|
138
|
+
responsive ? `${responsive}:drawer` : 'drawer',
|
|
139
|
+
`drawer-${placement}`,
|
|
140
|
+
{
|
|
141
|
+
'drawer-sheet': sheet,
|
|
142
|
+
'drawer-translucent': translucent,
|
|
143
|
+
'drawer-instant': animation === 'instant',
|
|
144
|
+
'drawer-fullscreen': fullscreen === true
|
|
145
|
+
},
|
|
146
|
+
className
|
|
147
|
+
)}
|
|
148
|
+
onClose={this.handleClose}
|
|
149
|
+
>
|
|
150
|
+
<DrawerHeader>
|
|
151
|
+
<DrawerTitle>{title}</DrawerTitle>
|
|
152
|
+
<CloseButton onClick={this.handleDismiss} />
|
|
153
|
+
</DrawerHeader>
|
|
154
|
+
<DrawerBody className={bodyClassName}>{children}</DrawerBody>
|
|
155
|
+
{footer && <DrawerFooter>{footer}</DrawerFooter>}
|
|
156
|
+
</NativeDialog>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -4,11 +4,13 @@ import tsx from '@shikijs/langs/tsx';
|
|
|
4
4
|
import ts from '@shikijs/langs/typescript';
|
|
5
5
|
import githubDark from '@shikijs/themes/github-dark';
|
|
6
6
|
import githubLight from '@shikijs/themes/github-light';
|
|
7
|
-
import { FC, HTMLAttributes, isValidElement } from 'react';
|
|
7
|
+
import { FC, HTMLAttributes, isValidElement, ReactNode } from 'react';
|
|
8
8
|
import reactElementToJSXString from 'react-element-to-jsx-string';
|
|
9
9
|
import { createHighlighterCoreSync } from 'shiki/core';
|
|
10
10
|
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
|
|
11
11
|
|
|
12
|
+
import styles from './style.module.css';
|
|
13
|
+
|
|
12
14
|
const highlighter = createHighlighterCoreSync({
|
|
13
15
|
themes: [githubLight, githubDark],
|
|
14
16
|
langs: [js, jsx, ts, tsx],
|
|
@@ -17,9 +19,16 @@ const highlighter = createHighlighterCoreSync({
|
|
|
17
19
|
|
|
18
20
|
export interface CodeBlockProps extends HTMLAttributes<HTMLPreElement> {
|
|
19
21
|
language: string;
|
|
22
|
+
header?: ReactNode;
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
export const CodeBlock: FC<CodeBlockProps> = ({
|
|
25
|
+
export const CodeBlock: FC<CodeBlockProps> = ({
|
|
26
|
+
className = '',
|
|
27
|
+
language,
|
|
28
|
+
header,
|
|
29
|
+
children,
|
|
30
|
+
...props
|
|
31
|
+
}) => {
|
|
23
32
|
const sourceCode =
|
|
24
33
|
typeof children === 'string'
|
|
25
34
|
? children
|
|
@@ -28,13 +37,22 @@ export const CodeBlock: FC<CodeBlockProps> = ({ className = '', language, childr
|
|
|
28
37
|
const __html = highlighter.codeToHtml(sourceCode, {
|
|
29
38
|
lang: language,
|
|
30
39
|
themes: { light: 'github-light', dark: 'github-dark' },
|
|
31
|
-
defaultColor:
|
|
40
|
+
defaultColor: false,
|
|
32
41
|
structure: 'inline'
|
|
33
42
|
});
|
|
34
43
|
|
|
35
|
-
|
|
36
|
-
<pre className={`m-0 shiki language-${language} ${className}`} {...props}>
|
|
44
|
+
const code = (
|
|
45
|
+
<pre className={`m-0 shiki language-${language} ${styles.code} ${className}`} {...props}>
|
|
37
46
|
<code dangerouslySetInnerHTML={{ __html }} className={`language-${language}`} />
|
|
38
47
|
</pre>
|
|
39
48
|
);
|
|
49
|
+
|
|
50
|
+
return header ? (
|
|
51
|
+
<figure className="m-0 border rounded overflow-hidden">
|
|
52
|
+
<figcaption className="px-3 py-2 bg-body-tertiary border-bottom">{header}</figcaption>
|
|
53
|
+
{code}
|
|
54
|
+
</figure>
|
|
55
|
+
) : (
|
|
56
|
+
code
|
|
57
|
+
);
|
|
40
58
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Defer } from 'iterable-observer';
|
|
2
|
-
import { observable } from 'mobx';
|
|
2
|
+
import { action, observable } from 'mobx';
|
|
3
3
|
import { observer } from 'mobx-react';
|
|
4
4
|
import { FC } from 'react';
|
|
5
5
|
|
|
@@ -9,11 +9,11 @@ export class DialogClose extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export interface DialogProps<T =
|
|
12
|
+
export interface DialogProps<T = unknown> {
|
|
13
13
|
defer?: Defer<T>;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export class Dialog<I extends object = {}, O =
|
|
16
|
+
export class Dialog<I extends object = {}, O = unknown> {
|
|
17
17
|
@observable
|
|
18
18
|
accessor input = {} as I;
|
|
19
19
|
|
|
@@ -29,13 +29,17 @@ export class Dialog<I extends object = {}, O = any> {
|
|
|
29
29
|
this.Component.displayName = 'DialogComponent';
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
@action
|
|
32
33
|
open(input?: I) {
|
|
33
34
|
if (input) this.input = input;
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
const defer = new Defer<O>();
|
|
37
|
+
this.defer = defer;
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
const clear = action(() => this.defer === defer && (this.defer = undefined));
|
|
38
40
|
|
|
39
|
-
|
|
41
|
+
defer.promise.then(clear, clear);
|
|
42
|
+
|
|
43
|
+
return defer.promise;
|
|
40
44
|
}
|
|
41
45
|
}
|
|
@@ -3,7 +3,7 @@ import createParser from 'editorjs-html';
|
|
|
3
3
|
import { FC, HTMLAttributes } from 'react';
|
|
4
4
|
|
|
5
5
|
export const parser = createParser({
|
|
6
|
-
link: ({ data: { link } }
|
|
6
|
+
link: ({ data: { link } }) => `<a href="${link}">${link}</a>`
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
export interface EditorHTMLProps extends HTMLAttributes<HTMLDivElement> {
|
|
@@ -36,9 +36,7 @@
|
|
|
36
36
|
--scroll-height: 20px;
|
|
37
37
|
height: var(--scroll-height);
|
|
38
38
|
.scrollContainer {
|
|
39
|
-
transform: translateY(
|
|
40
|
-
calc(calc(-100% + var(--scroll-height) + var(--scroll-height)) * 2)
|
|
41
|
-
);
|
|
39
|
+
transform: translateY(calc(calc(-100% + var(--scroll-height) + var(--scroll-height)) * 2));
|
|
42
40
|
max-height: calc(var(--scroll-height) * 3);
|
|
43
41
|
.unScrollItem {
|
|
44
42
|
max-height: calc(var(--scroll-height) * 2);
|
|
@@ -7,13 +7,7 @@ export type IconProps = PropsWithRef<
|
|
|
7
7
|
size?: number;
|
|
8
8
|
}
|
|
9
9
|
>;
|
|
10
|
-
export const Icon: FC<IconProps> = ({
|
|
11
|
-
className,
|
|
12
|
-
style,
|
|
13
|
-
name,
|
|
14
|
-
size,
|
|
15
|
-
...props
|
|
16
|
-
}) => (
|
|
10
|
+
export const Icon: FC<IconProps> = ({ className, style, name, size, ...props }) => (
|
|
17
11
|
<span
|
|
18
12
|
className={classNames(`bi-${name}`, className)}
|
|
19
13
|
style={{ fontSize: size && `${size}rem`, ...style }}
|