idea-react 3.0.0-alpha.0 → 3.0.0-alpha.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 +31 -10
- package/ReadMe.md +42 -35
- package/dist/index.d.mts +301 -100
- package/dist/index.d.ts +301 -100
- package/dist/index.js +16 -16
- package/dist/index.mjs +15 -15
- package/dist/style.css +5 -5
- package/package.json +4 -7
- package/source/Avatar.tsx +65 -12
- package/source/Button.tsx +13 -4
- package/source/ButtonGroup.tsx +28 -0
- package/source/Card.tsx +26 -0
- package/source/ClickBoundary.tsx +6 -5
- package/source/CloseButton.tsx +23 -0
- package/source/CodeBlock.tsx +5 -3
- package/source/Countdown.tsx +2 -0
- package/source/Drawer.tsx +62 -0
- package/source/Editor.tsx +5 -8
- package/source/Grid.tsx +92 -0
- package/source/HorizontalMarquee/index.tsx +4 -10
- package/source/Image.tsx +15 -0
- package/source/ListGroup.tsx +103 -0
- package/source/LiveTSX.tsx +1 -1
- package/source/Loading.tsx +4 -3
- package/source/Menu.tsx +99 -1
- package/source/MonthCalendar.tsx +60 -22
- package/source/NativeDialog/index.tsx +37 -1
- package/source/Nav.tsx +52 -0
- package/source/Navbar.tsx +48 -1
- package/source/Overlay.ts +22 -0
- package/source/OverlayBox.tsx +200 -32
- package/source/PageNav.tsx +56 -32
- package/source/Popover.tsx +36 -0
- package/source/ScrollNav/Scroller.tsx +107 -0
- package/source/ScrollNav/index.tsx +12 -99
- package/source/Select.tsx +66 -55
- package/source/ShareBox.tsx +5 -11
- package/source/Spinner.tsx +30 -0
- package/source/SpinnerButton.tsx +8 -10
- package/source/Table.tsx +59 -0
- package/source/TableSpinner.tsx +7 -5
- package/source/{TextTruncate.tsx → TextTruncate/Content.tsx} +24 -20
- package/source/TextTruncate/index.tsx +25 -0
- package/source/Time.tsx +7 -33
- package/source/TimeDistance.tsx +1 -1
- package/source/Timeline/index.tsx +7 -7
- package/source/Toast.tsx +114 -29
- package/source/ToggleButton.tsx +47 -0
- package/source/Tooltip.tsx +32 -0
- package/source/TypeEcho/Content.tsx +58 -0
- package/source/TypeEcho/index.tsx +14 -0
- package/source/UserRank/index.module.less +9 -20
- package/source/UserRank/index.tsx +35 -32
- package/source/VerticalMarquee/index.module.less +0 -1
- package/source/VerticalMarquee/index.tsx +3 -5
- package/source/ZodiacBar.tsx +1 -1
- package/source/animate.ts +4 -2
- package/source/color.ts +3 -5
- package/source/index.ts +13 -0
- package/source/TypeEcho.tsx +0 -49
package/source/PageNav.tsx
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { action, computed, observable } from 'mobx';
|
|
2
4
|
import { observer } from 'mobx-react';
|
|
3
5
|
import { Component } from 'react';
|
|
4
|
-
import { Nav, NavProps } from 'react-bootstrap';
|
|
5
6
|
import { scrollTo, uniqueID } from 'web-utility';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
import { Nav, NavLink, NavProps } from './Nav';
|
|
9
|
+
|
|
10
|
+
const HeadingSelector = Array.from({ length: 6 }, (_, index) => `h${index + 1}`).join(',');
|
|
9
11
|
|
|
10
|
-
type HeadingMeta = Record<'id' | 'text', string> &
|
|
11
|
-
Record<'level' | 'top', number>;
|
|
12
|
+
type HeadingMeta = Record<'id' | 'text', string> & Record<'level' | 'top', number>;
|
|
12
13
|
|
|
13
14
|
export interface PageNavProps extends NavProps {
|
|
14
15
|
depth?: number;
|
|
15
|
-
|
|
16
|
+
minDepth?: number;
|
|
17
|
+
rootSelector?: string;
|
|
18
|
+
onItemClick?: (item: HeadingMeta) => void;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
@observer
|
|
@@ -33,26 +36,42 @@ export class PageNav extends Component<PageNavProps> {
|
|
|
33
36
|
return list[index - 1]?.id;
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
updateScrollY = () => (this.scrollY = window.scrollY);
|
|
39
|
+
updateScrollY = action(() => (this.scrollY = window.scrollY));
|
|
37
40
|
|
|
38
41
|
componentDidMount() {
|
|
39
42
|
if (!globalThis.document) return;
|
|
40
43
|
|
|
41
44
|
window.addEventListener('scroll', this.updateScrollY);
|
|
42
45
|
|
|
46
|
+
this.initList();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static slugOf(text: string) {
|
|
50
|
+
const slug = text
|
|
51
|
+
.toLowerCase()
|
|
52
|
+
.replace(/\W+/g, '-')
|
|
53
|
+
.replace(/^-+|-+$/g, '');
|
|
54
|
+
|
|
55
|
+
return !slug || document.getElementById(slug) ? uniqueID() : slug;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@action
|
|
59
|
+
initList() {
|
|
60
|
+
const { rootSelector } = this.props;
|
|
61
|
+
const root = rootSelector ? document.querySelector(rootSelector) : document;
|
|
62
|
+
|
|
63
|
+
if (!root) return;
|
|
64
|
+
|
|
43
65
|
this.list = Array.from(
|
|
44
|
-
|
|
66
|
+
root.querySelectorAll<HTMLHeadingElement>(HeadingSelector),
|
|
45
67
|
element => {
|
|
46
|
-
element.
|
|
68
|
+
const text = element.textContent.trim();
|
|
69
|
+
|
|
70
|
+
element.id ||= PageNav.slugOf(text);
|
|
47
71
|
|
|
48
|
-
const { id, tagName,
|
|
72
|
+
const { id, tagName, offsetTop } = element;
|
|
49
73
|
|
|
50
|
-
return {
|
|
51
|
-
id,
|
|
52
|
-
level: +tagName[1],
|
|
53
|
-
text: textContent.trim(),
|
|
54
|
-
top: offsetTop
|
|
55
|
-
};
|
|
74
|
+
return { id, level: +tagName[1], text, top: offsetTop };
|
|
56
75
|
}
|
|
57
76
|
);
|
|
58
77
|
}
|
|
@@ -69,32 +88,37 @@ export class PageNav extends Component<PageNavProps> {
|
|
|
69
88
|
|
|
70
89
|
renderLink = ({ id, level, text, top }: HeadingMeta) => {
|
|
71
90
|
const { currentActiveId } = this,
|
|
72
|
-
{ depth = Infinity } = this.props;
|
|
91
|
+
{ depth = Infinity, minDepth = 1 } = this.props;
|
|
73
92
|
|
|
74
93
|
return (
|
|
94
|
+
minDepth <= level &&
|
|
75
95
|
level <= depth && (
|
|
76
|
-
<
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
96
|
+
<NavLink
|
|
97
|
+
key={id}
|
|
98
|
+
className={currentActiveId === id ? ' active' : ''}
|
|
99
|
+
style={{ textIndent: `${level - minDepth}rem` }}
|
|
100
|
+
href={`#${id}`}
|
|
101
|
+
aria-current={currentActiveId === id ? 'location' : undefined}
|
|
102
|
+
onClick={this.scrollTo({ id, level, text, top })}
|
|
103
|
+
>
|
|
104
|
+
{text}
|
|
105
|
+
</NavLink>
|
|
85
106
|
)
|
|
86
107
|
);
|
|
87
108
|
};
|
|
88
109
|
|
|
89
110
|
render() {
|
|
90
111
|
const { list } = this,
|
|
91
|
-
{
|
|
112
|
+
{
|
|
113
|
+
depth: _depth,
|
|
114
|
+
minDepth: _minDepth,
|
|
115
|
+
rootSelector: _rootSelector,
|
|
116
|
+
onItemClick: _onItemClick,
|
|
117
|
+
...props
|
|
118
|
+
} = this.props;
|
|
92
119
|
|
|
93
120
|
return (
|
|
94
|
-
<Nav
|
|
95
|
-
{...{ ...props, variant }}
|
|
96
|
-
style={{ flexDirection: 'column', ...style }}
|
|
97
|
-
>
|
|
121
|
+
<Nav {...props} variant="underline" vertical>
|
|
98
122
|
{list.map(this.renderLink)}
|
|
99
123
|
</Nav>
|
|
100
124
|
);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { FC, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
import { OVERLAY_ARROW_POSITIONS, OVERLAY_DIRECTIONS, OverlayTriggerProps } from './Overlay';
|
|
5
|
+
|
|
6
|
+
export interface PopoverProps extends Omit<OverlayTriggerProps, 'title'> {
|
|
7
|
+
title?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const Popover: FC<PopoverProps> = ({
|
|
11
|
+
title,
|
|
12
|
+
placement = 'top',
|
|
13
|
+
show = true,
|
|
14
|
+
role = 'tooltip',
|
|
15
|
+
className,
|
|
16
|
+
children,
|
|
17
|
+
...props
|
|
18
|
+
}) => (
|
|
19
|
+
<div
|
|
20
|
+
{...props}
|
|
21
|
+
className={classNames(
|
|
22
|
+
'popover',
|
|
23
|
+
{ show },
|
|
24
|
+
`bs-popover-${OVERLAY_DIRECTIONS[placement]}`,
|
|
25
|
+
className
|
|
26
|
+
)}
|
|
27
|
+
role={role}
|
|
28
|
+
data-bs-placement={placement}
|
|
29
|
+
>
|
|
30
|
+
<div className={classNames('popover-arrow', OVERLAY_ARROW_POSITIONS[placement])} />
|
|
31
|
+
<h3 className="popover-header">{title}</h3>
|
|
32
|
+
<div className="popover-body">{children}</div>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
Popover.displayName = 'Popover';
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { action, computed, observable } from 'mobx';
|
|
4
|
+
import { observer } from 'mobx-react';
|
|
5
|
+
import { Component, createRef, ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
import { Icon } from '../Icon';
|
|
8
|
+
import * as style from './index.module.less';
|
|
9
|
+
|
|
10
|
+
export interface ScrollNavScrollerProps {
|
|
11
|
+
className?: string;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@observer
|
|
16
|
+
export class ScrollNavScroller extends Component<ScrollNavScrollerProps> {
|
|
17
|
+
scrollerRef = createRef<HTMLDivElement>();
|
|
18
|
+
|
|
19
|
+
@observable
|
|
20
|
+
accessor scrollLeft = 0;
|
|
21
|
+
|
|
22
|
+
@observable
|
|
23
|
+
accessor scrollWidth = 0;
|
|
24
|
+
|
|
25
|
+
@observable
|
|
26
|
+
accessor clientWidth = 0;
|
|
27
|
+
|
|
28
|
+
@computed
|
|
29
|
+
get canScrollLeft() {
|
|
30
|
+
return this.scrollLeft > 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@computed
|
|
34
|
+
get canScrollRight() {
|
|
35
|
+
return this.scrollLeft + this.clientWidth < this.scrollWidth;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@action
|
|
39
|
+
updateScroll = () => {
|
|
40
|
+
const scroller = this.scrollerRef.current;
|
|
41
|
+
if (scroller) {
|
|
42
|
+
this.scrollLeft = scroller.scrollLeft;
|
|
43
|
+
this.scrollWidth = scroller.scrollWidth;
|
|
44
|
+
this.clientWidth = scroller.clientWidth;
|
|
45
|
+
}
|
|
46
|
+
return scroller;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
private resizeObserver?: ResizeObserver;
|
|
50
|
+
|
|
51
|
+
componentDidMount() {
|
|
52
|
+
const scroller = this.updateScroll();
|
|
53
|
+
if (!scroller) return;
|
|
54
|
+
|
|
55
|
+
scroller.addEventListener('scroll', this.updateScroll);
|
|
56
|
+
this.resizeObserver = new ResizeObserver(this.updateScroll);
|
|
57
|
+
this.resizeObserver.observe(scroller);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
componentWillUnmount() {
|
|
61
|
+
this.resizeObserver?.disconnect();
|
|
62
|
+
this.scrollerRef.current?.removeEventListener('scroll', this.updateScroll);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
scrollBy = (direction: -1 | 1) => {
|
|
66
|
+
const scroller = this.scrollerRef.current;
|
|
67
|
+
|
|
68
|
+
scroller?.scrollBy({ left: direction * scroller.clientWidth * 0.8, behavior: 'smooth' });
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
scrollBackward = () => this.scrollBy(-1);
|
|
72
|
+
|
|
73
|
+
scrollForward = () => this.scrollBy(1);
|
|
74
|
+
|
|
75
|
+
render() {
|
|
76
|
+
const { canScrollLeft, canScrollRight } = this;
|
|
77
|
+
const { className = '', children } = this.props;
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div className={`position-relative overflow-y-hidden ${className}`}>
|
|
81
|
+
{canScrollLeft && (
|
|
82
|
+
<button
|
|
83
|
+
type="button"
|
|
84
|
+
className={`position-absolute top-0 bottom-0 start-0 z-1 border-0 px-2 ${style.scrollButtonLeft}`}
|
|
85
|
+
aria-label="Scroll left"
|
|
86
|
+
onClick={this.scrollBackward}
|
|
87
|
+
>
|
|
88
|
+
<Icon name="caret-left-fill" />
|
|
89
|
+
</button>
|
|
90
|
+
)}
|
|
91
|
+
<div ref={this.scrollerRef} className={`overflow-x-auto ${style.scrollerInner}`}>
|
|
92
|
+
{children}
|
|
93
|
+
</div>
|
|
94
|
+
{canScrollRight && (
|
|
95
|
+
<button
|
|
96
|
+
type="button"
|
|
97
|
+
className={`position-absolute top-0 bottom-0 end-0 z-1 border-0 px-2 ${style.scrollButtonRight}`}
|
|
98
|
+
aria-label="Scroll right"
|
|
99
|
+
onClick={this.scrollForward}
|
|
100
|
+
>
|
|
101
|
+
<Icon name="caret-right-fill" />
|
|
102
|
+
</button>
|
|
103
|
+
)}
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { observer } from 'mobx-react';
|
|
3
|
-
import { Component, createRef } from 'react';
|
|
4
|
-
import { Nav, NavProps } from 'react-bootstrap';
|
|
1
|
+
import { FC } from 'react';
|
|
5
2
|
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
3
|
+
import { Nav, NavProps } from '../Nav';
|
|
4
|
+
import { ScrollNavScroller } from './Scroller';
|
|
8
5
|
|
|
9
6
|
export type ScrollNavProps = NavProps;
|
|
10
7
|
|
|
@@ -14,96 +11,12 @@ export type ScrollNavProps = NavProps;
|
|
|
14
11
|
*
|
|
15
12
|
* @see {@link https://github.com/twbs/bootstrap/blob/main/site/src/assets/examples/offcanvas-navbar/index.astro#L50-L65}
|
|
16
13
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
@observable
|
|
27
|
-
accessor scrollWidth = 0;
|
|
28
|
-
|
|
29
|
-
@observable
|
|
30
|
-
accessor clientWidth = 0;
|
|
31
|
-
|
|
32
|
-
@computed
|
|
33
|
-
get canScrollLeft() {
|
|
34
|
-
return this.scrollLeft > 0;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@computed
|
|
38
|
-
get canScrollRight() {
|
|
39
|
-
return this.scrollLeft + this.clientWidth < this.scrollWidth;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
updateScroll = () => {
|
|
43
|
-
const scroller = this.scrollerRef.current;
|
|
44
|
-
if (scroller) {
|
|
45
|
-
this.scrollLeft = scroller.scrollLeft;
|
|
46
|
-
this.scrollWidth = scroller.scrollWidth;
|
|
47
|
-
this.clientWidth = scroller.clientWidth;
|
|
48
|
-
}
|
|
49
|
-
return scroller;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
private resizeObserver?: ResizeObserver;
|
|
53
|
-
|
|
54
|
-
componentDidMount() {
|
|
55
|
-
const scroller = this.updateScroll();
|
|
56
|
-
if (!scroller) return;
|
|
57
|
-
|
|
58
|
-
scroller.addEventListener('scroll', this.updateScroll);
|
|
59
|
-
this.resizeObserver = new ResizeObserver(this.updateScroll);
|
|
60
|
-
this.resizeObserver.observe(scroller);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
componentWillUnmount() {
|
|
64
|
-
this.resizeObserver?.disconnect();
|
|
65
|
-
this.scrollerRef.current?.removeEventListener('scroll', this.updateScroll);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
scrollBy = (direction: -1 | 1) => () => {
|
|
69
|
-
const scroller = this.scrollerRef.current;
|
|
70
|
-
if (!scroller) return;
|
|
71
|
-
|
|
72
|
-
scroller.scrollBy({ left: direction * scroller.clientWidth * 0.8, behavior: 'smooth' });
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
render() {
|
|
76
|
-
const { canScrollLeft, canScrollRight } = this;
|
|
77
|
-
const { className = '', children, ...props } = this.props;
|
|
78
|
-
|
|
79
|
-
return (
|
|
80
|
-
<div className={`position-relative overflow-y-hidden ${className}`}>
|
|
81
|
-
{canScrollLeft && (
|
|
82
|
-
<button
|
|
83
|
-
type="button"
|
|
84
|
-
className={`position-absolute top-0 bottom-0 start-0 z-1 border-0 px-2 ${style.scrollButtonLeft}`}
|
|
85
|
-
aria-label="Scroll left"
|
|
86
|
-
onClick={this.scrollBy(-1)}
|
|
87
|
-
>
|
|
88
|
-
<Icon name="caret-left-fill" />
|
|
89
|
-
</button>
|
|
90
|
-
)}
|
|
91
|
-
<div ref={this.scrollerRef} className={`overflow-x-auto ${style.scrollerInner}`}>
|
|
92
|
-
<Nav {...props} className="flex-nowrap">
|
|
93
|
-
{children}
|
|
94
|
-
</Nav>
|
|
95
|
-
</div>
|
|
96
|
-
{canScrollRight && (
|
|
97
|
-
<button
|
|
98
|
-
type="button"
|
|
99
|
-
className={`position-absolute top-0 bottom-0 end-0 z-1 border-0 px-2 ${style.scrollButtonRight}`}
|
|
100
|
-
aria-label="Scroll right"
|
|
101
|
-
onClick={this.scrollBy(1)}
|
|
102
|
-
>
|
|
103
|
-
<Icon name="caret-right-fill" />
|
|
104
|
-
</button>
|
|
105
|
-
)}
|
|
106
|
-
</div>
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
14
|
+
export const ScrollNav: FC<ScrollNavProps> = ({ className = '', children, ...props }) => (
|
|
15
|
+
<ScrollNavScroller className={className}>
|
|
16
|
+
<Nav {...props} className="flex-nowrap">
|
|
17
|
+
{children}
|
|
18
|
+
</Nav>
|
|
19
|
+
</ScrollNavScroller>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
ScrollNav.displayName = 'ScrollNav';
|
package/source/Select.tsx
CHANGED
|
@@ -1,83 +1,94 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
1
3
|
import classNames from 'classnames';
|
|
2
|
-
import { FC, isValidElement, ReactElement, ReactNode } from 'react';
|
|
3
4
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
ButtonHTMLAttributes,
|
|
6
|
+
Children,
|
|
7
|
+
FC,
|
|
8
|
+
isValidElement,
|
|
9
|
+
MouseEvent,
|
|
10
|
+
ReactElement,
|
|
11
|
+
ReactNode
|
|
12
|
+
} from 'react';
|
|
13
|
+
|
|
14
|
+
import { ButtonProps } from './Button';
|
|
15
|
+
import { Menu } from './Menu';
|
|
9
16
|
|
|
10
|
-
export interface OptionProps extends
|
|
17
|
+
export interface OptionProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
11
18
|
value?: string;
|
|
12
19
|
}
|
|
13
20
|
|
|
14
|
-
export const Option: FC<OptionProps> = ({ value, children, ...props }) => (
|
|
15
|
-
<
|
|
21
|
+
export const Option: FC<OptionProps> = ({ value, className, children, ...props }) => (
|
|
22
|
+
<button
|
|
23
|
+
{...props}
|
|
24
|
+
type="button"
|
|
25
|
+
className={classNames('menu-item', className)}
|
|
26
|
+
data-value={value}
|
|
27
|
+
>
|
|
16
28
|
{children}
|
|
17
|
-
</
|
|
29
|
+
</button>
|
|
18
30
|
);
|
|
19
31
|
|
|
20
32
|
Option.displayName = 'Option';
|
|
21
33
|
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
34
|
+
export type SelectProps = Pick<
|
|
35
|
+
ButtonProps,
|
|
36
|
+
'className' | 'style' | 'size' | 'theme' | 'variant' | 'disabled' | 'children'
|
|
37
|
+
> & {
|
|
38
|
+
align?: 'start' | 'end';
|
|
39
|
+
menuClassName?: string;
|
|
40
|
+
value?: string;
|
|
41
|
+
onChange?: (value: string) => void;
|
|
26
42
|
valueRender?: (value: string) => ReactNode;
|
|
27
|
-
}
|
|
43
|
+
};
|
|
28
44
|
|
|
29
45
|
export const Select: FC<SelectProps> = ({
|
|
46
|
+
align,
|
|
30
47
|
className,
|
|
31
|
-
|
|
32
|
-
variant,
|
|
33
|
-
menuVariant,
|
|
48
|
+
menuClassName,
|
|
34
49
|
children,
|
|
50
|
+
theme = 'primary',
|
|
51
|
+
variant = 'solid',
|
|
52
|
+
size,
|
|
53
|
+
disabled,
|
|
54
|
+
style,
|
|
35
55
|
value,
|
|
36
56
|
onChange,
|
|
37
57
|
valueRender
|
|
38
58
|
}) => {
|
|
39
|
-
const current = (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
isValidElement<OptionProps>(node) &&
|
|
44
|
-
node.type === Option &&
|
|
45
|
-
node.props.value === value
|
|
46
|
-
) as ReactElement<OptionProps, typeof Option>;
|
|
59
|
+
const current = Children.toArray(children).find(
|
|
60
|
+
node =>
|
|
61
|
+
isValidElement<OptionProps>(node) && node.type === Option && node.props.value === value
|
|
62
|
+
) as ReactElement<OptionProps> | undefined;
|
|
47
63
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
onClick={({ target }) => {
|
|
51
|
-
const option = (target as HTMLElement).closest<HTMLElement>(
|
|
52
|
-
'.dropdown-item'
|
|
53
|
-
);
|
|
54
|
-
if (!option) return;
|
|
64
|
+
const handleSelect = ({ target }: MouseEvent<HTMLDivElement>) => {
|
|
65
|
+
if (!(target instanceof Element)) return;
|
|
55
66
|
|
|
56
|
-
|
|
67
|
+
const option = target.closest<HTMLButtonElement>('[data-value]');
|
|
68
|
+
if (option) onChange?.(option.dataset.value || '');
|
|
69
|
+
};
|
|
57
70
|
|
|
58
|
-
|
|
71
|
+
return (
|
|
72
|
+
<Menu
|
|
73
|
+
align={align}
|
|
74
|
+
className="w-100"
|
|
75
|
+
menuClassName={menuClassName}
|
|
76
|
+
label={valueRender?.(value ?? '') ?? current?.props.children}
|
|
77
|
+
toggleProps={{
|
|
78
|
+
className: classNames(
|
|
79
|
+
'w-100 d-flex justify-content-between align-items-center',
|
|
80
|
+
className
|
|
81
|
+
),
|
|
82
|
+
theme,
|
|
83
|
+
variant,
|
|
84
|
+
size,
|
|
85
|
+
disabled,
|
|
86
|
+
style
|
|
59
87
|
}}
|
|
88
|
+
onClick={handleSelect}
|
|
60
89
|
>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
'w-100',
|
|
64
|
-
'd-flex',
|
|
65
|
-
'justify-content-between',
|
|
66
|
-
'align-items-center',
|
|
67
|
-
!variant && 'bg-white text-dark',
|
|
68
|
-
className
|
|
69
|
-
)}
|
|
70
|
-
{...{ style, variant }}
|
|
71
|
-
>
|
|
72
|
-
{valueRender?.(value) || (
|
|
73
|
-
<div className={current?.props.className}>
|
|
74
|
-
{current?.props.children}
|
|
75
|
-
</div>
|
|
76
|
-
)}
|
|
77
|
-
</Dropdown.Toggle>
|
|
78
|
-
|
|
79
|
-
<Dropdown.Menu variant={menuVariant}>{children}</Dropdown.Menu>
|
|
80
|
-
</Dropdown>
|
|
90
|
+
{children}
|
|
91
|
+
</Menu>
|
|
81
92
|
);
|
|
82
93
|
};
|
|
83
94
|
|
package/source/ShareBox.tsx
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
1
3
|
import html2canvas from 'html2canvas';
|
|
2
4
|
import { observable } from 'mobx';
|
|
3
5
|
import { observer } from 'mobx-react';
|
|
4
6
|
import { Component, createRef, HTMLAttributes, MouseEvent } from 'react';
|
|
5
|
-
import { Image } from 'react-bootstrap';
|
|
6
7
|
import { blobOf } from 'web-utility';
|
|
7
8
|
|
|
9
|
+
import { Image } from './Image';
|
|
8
10
|
import { Loading } from './Loading';
|
|
9
11
|
|
|
10
|
-
export async function elementToImage(
|
|
11
|
-
element: HTMLElement,
|
|
12
|
-
type?: string,
|
|
13
|
-
quality?: number
|
|
14
|
-
) {
|
|
12
|
+
export async function elementToImage(element: HTMLElement, type?: string, quality?: number) {
|
|
15
13
|
const canvas = await html2canvas(element, { useCORS: true });
|
|
16
14
|
|
|
17
15
|
return new Promise<string>((resolve, reject) =>
|
|
18
|
-
canvas.toBlob(
|
|
19
|
-
blob => (blob ? resolve(URL.createObjectURL(blob)) : reject()),
|
|
20
|
-
type,
|
|
21
|
-
quality
|
|
22
|
-
)
|
|
16
|
+
canvas.toBlob(blob => (blob ? resolve(URL.createObjectURL(blob)) : reject()), type, quality)
|
|
23
17
|
);
|
|
24
18
|
}
|
|
25
19
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
|
+
|
|
4
|
+
import type { ComponentTheme } from './Button';
|
|
5
|
+
|
|
6
|
+
export type SpinnerAnimation = 'border' | 'grow';
|
|
7
|
+
|
|
8
|
+
export interface SpinnerProps extends ComponentPropsWithRef<'span'> {
|
|
9
|
+
animation?: SpinnerAnimation;
|
|
10
|
+
size?: 'sm';
|
|
11
|
+
theme?: ComponentTheme;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const Spinner: FC<SpinnerProps> = ({
|
|
15
|
+
animation = 'border',
|
|
16
|
+
size,
|
|
17
|
+
theme,
|
|
18
|
+
className,
|
|
19
|
+
...props
|
|
20
|
+
}) => (
|
|
21
|
+
<span
|
|
22
|
+
{...props}
|
|
23
|
+
className={classNames(
|
|
24
|
+
`spinner-${animation}`,
|
|
25
|
+
size && `spinner-${size}`,
|
|
26
|
+
theme && `theme-${theme}`,
|
|
27
|
+
className
|
|
28
|
+
)}
|
|
29
|
+
/>
|
|
30
|
+
);
|
package/source/SpinnerButton.tsx
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
-
import { Button, ButtonProps, Spinner, SpinnerProps } from 'react-bootstrap';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import { Button, ButtonProps } from './Button';
|
|
4
|
+
import { Spinner, SpinnerProps } from './Spinner';
|
|
5
|
+
|
|
6
|
+
export type SpinnerButtonProps = ButtonProps &
|
|
7
|
+
Pick<SpinnerProps, 'animation'> & {
|
|
8
|
+
loading?: boolean;
|
|
9
|
+
};
|
|
9
10
|
|
|
10
11
|
export const SpinnerButton: FC<SpinnerButtonProps> = ({
|
|
11
12
|
animation,
|
|
@@ -18,16 +19,13 @@ export const SpinnerButton: FC<SpinnerButtonProps> = ({
|
|
|
18
19
|
{loading && (
|
|
19
20
|
<>
|
|
20
21
|
<Spinner
|
|
21
|
-
as="span"
|
|
22
22
|
className={children ? 'me-2' : ''}
|
|
23
23
|
size="sm"
|
|
24
24
|
animation={animation}
|
|
25
25
|
role="status"
|
|
26
26
|
aria-hidden="true"
|
|
27
27
|
/>
|
|
28
|
-
{!children &&
|
|
29
|
-
<span className="visually-hidden">Loading...</span>
|
|
30
|
-
)}
|
|
28
|
+
{!children && <span className="visually-hidden">Loading...</span>}
|
|
31
29
|
</>
|
|
32
30
|
)}
|
|
33
31
|
{children}
|