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,30 @@
|
|
|
1
|
+
import { Button, ButtonProps } from '../Button';
|
|
2
|
+
import { polymorphic } from '../Polymorphic';
|
|
3
|
+
import { Spinner, SpinnerProps } from '../Spinner';
|
|
4
|
+
|
|
5
|
+
export type SpinnerButtonProps = ButtonProps &
|
|
6
|
+
Pick<SpinnerProps, 'animation'> & {
|
|
7
|
+
loading?: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const SpinnerButton = polymorphic<SpinnerButtonProps>(
|
|
11
|
+
({ as: RootAs, animation, loading, disabled, children, ...props }) => (
|
|
12
|
+
<Button as={RootAs} {...props} disabled={loading || disabled}>
|
|
13
|
+
{loading && (
|
|
14
|
+
<>
|
|
15
|
+
<Spinner
|
|
16
|
+
className={children ? 'me-2' : ''}
|
|
17
|
+
size="sm"
|
|
18
|
+
animation={animation}
|
|
19
|
+
role="status"
|
|
20
|
+
aria-hidden="true"
|
|
21
|
+
/>
|
|
22
|
+
{!children && <span className="visually-hidden">Loading...</span>}
|
|
23
|
+
</>
|
|
24
|
+
)}
|
|
25
|
+
{children}
|
|
26
|
+
</Button>
|
|
27
|
+
)
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
SpinnerButton.displayName = 'SpinnerButton';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
import { polymorphic } from '../Polymorphic';
|
|
4
|
+
import { Spinner, SpinnerProps } from '../Spinner';
|
|
5
|
+
|
|
6
|
+
export interface TableSpinnerProps
|
|
7
|
+
extends
|
|
8
|
+
HTMLAttributes<HTMLTableRowElement>,
|
|
9
|
+
Pick<SpinnerProps, 'animation' | 'theme' | 'size'> {
|
|
10
|
+
colSpan: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const TableSpinner = polymorphic<TableSpinnerProps>(
|
|
14
|
+
({ as: Root = 'tr', animation = 'border', theme = 'primary', size, colSpan, ...props }) => (
|
|
15
|
+
<Root {...props}>
|
|
16
|
+
<td className="text-center p-4" colSpan={colSpan}>
|
|
17
|
+
<Spinner {...{ animation, theme, size }} role="status" aria-label="Loading" />
|
|
18
|
+
</td>
|
|
19
|
+
</Root>
|
|
20
|
+
)
|
|
21
|
+
);
|
|
22
|
+
TableSpinner.displayName = 'TableSpinner';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import { polymorphic } from '../../Polymorphic';
|
|
4
|
+
import { TextTruncateContent } from './Content';
|
|
5
|
+
|
|
6
|
+
export interface TextTruncateProps extends HTMLAttributes<HTMLDivElement> {
|
|
7
|
+
rows?: number;
|
|
8
|
+
expandText?: ReactNode;
|
|
9
|
+
collapseText?: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const TextTruncate = polymorphic<TextTruncateProps>(
|
|
13
|
+
({
|
|
14
|
+
as: Root = 'div',
|
|
15
|
+
rows = 3,
|
|
16
|
+
expandText = '⏬',
|
|
17
|
+
collapseText = '⏫',
|
|
18
|
+
children,
|
|
19
|
+
...props
|
|
20
|
+
}) => (
|
|
21
|
+
<Root {...props}>
|
|
22
|
+
<TextTruncateContent rows={rows} expandText={expandText} collapseText={collapseText}>
|
|
23
|
+
{children}
|
|
24
|
+
</TextTruncateContent>
|
|
25
|
+
</Root>
|
|
26
|
+
)
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
TextTruncate.displayName = 'TextTruncate';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TimeHTMLAttributes } from 'react';
|
|
2
|
+
import { formatDate, TimeData } from 'web-utility';
|
|
3
|
+
|
|
4
|
+
import { polymorphic } from '../Polymorphic';
|
|
5
|
+
|
|
6
|
+
export interface TimeProps extends Omit<TimeHTMLAttributes<HTMLTimeElement>, 'dateTime'> {
|
|
7
|
+
dateTime: TimeData;
|
|
8
|
+
format?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const Time = polymorphic<TimeProps>(({ as: Root = 'time', dateTime, format, ...props }) => (
|
|
12
|
+
<Root dateTime={new Date(dateTime).toJSON()} {...props}>
|
|
13
|
+
{formatDate(dateTime, format)}
|
|
14
|
+
</Root>
|
|
15
|
+
));
|
|
16
|
+
|
|
17
|
+
Time.displayName = 'Time';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
|
+
import { diffTime, TimeData } from 'web-utility';
|
|
3
|
+
|
|
4
|
+
import { polymorphic } from '../Polymorphic';
|
|
5
|
+
|
|
6
|
+
export interface TimeDistanceProps extends HTMLAttributes<HTMLTimeElement> {
|
|
7
|
+
date: TimeData;
|
|
8
|
+
unitWords?: Record<string, string>;
|
|
9
|
+
beforeWord?: string;
|
|
10
|
+
afterWord?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const UnitWords: Record<string, string> = {
|
|
14
|
+
ms: 'millisecond(s)',
|
|
15
|
+
s: 'second(s)',
|
|
16
|
+
m: 'minute(s)',
|
|
17
|
+
H: 'hour(s)',
|
|
18
|
+
D: 'day(s)',
|
|
19
|
+
W: 'week(s)',
|
|
20
|
+
M: 'month(s)',
|
|
21
|
+
Y: 'year(s)'
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const TimeDistance = polymorphic<TimeDistanceProps>(
|
|
25
|
+
({
|
|
26
|
+
as: Root = 'time',
|
|
27
|
+
date,
|
|
28
|
+
unitWords = UnitWords,
|
|
29
|
+
beforeWord = ' before',
|
|
30
|
+
afterWord = ' after',
|
|
31
|
+
...props
|
|
32
|
+
}) => {
|
|
33
|
+
date = new Date(date);
|
|
34
|
+
|
|
35
|
+
const { distance, unit } = diffTime(date);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Root {...props} dateTime={date.toJSON()} title={date.toLocaleString()}>
|
|
39
|
+
{Math.abs(distance)} {unitWords[unit]}
|
|
40
|
+
{distance < 0 ? beforeWord : afterWord}
|
|
41
|
+
</Root>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
TimeDistance.displayName = 'TimeDistance';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
|
+
import { TimeData } from 'web-utility';
|
|
3
|
+
|
|
4
|
+
import { Card, CardBody, CardText, CardTitle } from '../../Card';
|
|
5
|
+
import { polymorphic } from '../../Polymorphic';
|
|
6
|
+
import { Nameplate, NameplateProps } from '../Nameplate';
|
|
7
|
+
import { Time } from '../Time';
|
|
8
|
+
import * as styles from './index.module.less';
|
|
9
|
+
|
|
10
|
+
export interface TimelineEvent {
|
|
11
|
+
title: string;
|
|
12
|
+
summary?: string;
|
|
13
|
+
time: [TimeData, TimeData?];
|
|
14
|
+
|
|
15
|
+
link?: string;
|
|
16
|
+
people?: NameplateProps[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface TimelineProps extends HTMLAttributes<HTMLOListElement> {
|
|
20
|
+
events: TimelineEvent[];
|
|
21
|
+
timeFormat?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @see {@link https://mdbootstrap.com/docs/standard/extended/timeline/#section-timeline-gradient-bg}
|
|
26
|
+
*/
|
|
27
|
+
export const Timeline = polymorphic<TimelineProps>(
|
|
28
|
+
({ as: Root = 'ol', className, events, timeFormat, ...props }) => (
|
|
29
|
+
<Root className={`list-unstyled ${styles.timeline} ${className}`} {...props}>
|
|
30
|
+
{events.map(({ title, summary, time, link, people }) => (
|
|
31
|
+
<li
|
|
32
|
+
key={title as string}
|
|
33
|
+
className={`position-relative ${styles.timelineItem} ${styles.right}`}
|
|
34
|
+
>
|
|
35
|
+
<Card>
|
|
36
|
+
<CardBody className="p-4 d-flex flex-column gap-3 align-items-center">
|
|
37
|
+
<CardTitle className="h5 m-0">
|
|
38
|
+
<a className="text-decoration-none stretched-link" href={link}>
|
|
39
|
+
{title as string}
|
|
40
|
+
</a>
|
|
41
|
+
</CardTitle>
|
|
42
|
+
<div className="small fg-3 d-flex gap-2">
|
|
43
|
+
⏲️
|
|
44
|
+
<Time dateTime={time[0]} format={timeFormat} />
|
|
45
|
+
{time[1] && '~'}
|
|
46
|
+
{time[1] && <Time dateTime={time[1]} format={timeFormat} />}
|
|
47
|
+
</div>
|
|
48
|
+
<ul className="list-unstyled m-0 d-flex gap-2 flex-wrap justify-content-around">
|
|
49
|
+
{people?.map(person => (
|
|
50
|
+
<li key={person.name}>
|
|
51
|
+
<Nameplate {...person} />
|
|
52
|
+
</li>
|
|
53
|
+
))}
|
|
54
|
+
</ul>
|
|
55
|
+
<CardText className="m-0">{summary as string}</CardText>
|
|
56
|
+
</CardBody>
|
|
57
|
+
</Card>
|
|
58
|
+
</li>
|
|
59
|
+
))}
|
|
60
|
+
</Root>
|
|
61
|
+
)
|
|
62
|
+
);
|
|
63
|
+
Timeline.displayName = 'Timeline';
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { action, observable } from 'mobx';
|
|
5
|
+
import { observer } from 'mobx-react';
|
|
6
|
+
import { Component, ElementType, HTMLAttributes, Ref, RefCallback } from 'react';
|
|
7
|
+
import { sleep } from 'web-utility';
|
|
8
|
+
|
|
9
|
+
import { AsProps, PolymorphicClassProps } from '../../Polymorphic';
|
|
10
|
+
|
|
11
|
+
export interface TypeEchoContentProps extends Omit<HTMLAttributes<HTMLPreElement>, 'children'> {
|
|
12
|
+
text: string;
|
|
13
|
+
intervals?: number;
|
|
14
|
+
rootRef?: Ref<HTMLElement>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@observer
|
|
18
|
+
export class TypeEchoContent<T extends ElementType | undefined = 'pre'> extends Component<
|
|
19
|
+
PolymorphicClassProps<T, TypeEchoContentProps>
|
|
20
|
+
> {
|
|
21
|
+
static displayName = 'TypeEchoContent';
|
|
22
|
+
|
|
23
|
+
declare readonly props: PolymorphicClassProps<T, TypeEchoContentProps>;
|
|
24
|
+
|
|
25
|
+
protected get componentProps(): Readonly<TypeEchoContentProps & AsProps> {
|
|
26
|
+
return this.props;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@observable
|
|
30
|
+
accessor echoed = '';
|
|
31
|
+
|
|
32
|
+
@observable
|
|
33
|
+
accessor started = false;
|
|
34
|
+
|
|
35
|
+
visibilityObserver?: IntersectionObserver;
|
|
36
|
+
|
|
37
|
+
private root?: HTMLElement | null;
|
|
38
|
+
private forwardedRootRef?: Ref<HTMLElement>;
|
|
39
|
+
private releaseRootRef?: () => unknown;
|
|
40
|
+
|
|
41
|
+
componentDidMount() {
|
|
42
|
+
this.start();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
start = action(() => (this.started = true));
|
|
46
|
+
|
|
47
|
+
echo = action((char: string) => (this.echoed += char));
|
|
48
|
+
|
|
49
|
+
componentWillUnmount() {
|
|
50
|
+
this.visibilityObserver?.disconnect();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
componentDidUpdate() {
|
|
54
|
+
this.forwardRootRef(this.root ?? null);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
forwardRootRef = (node: HTMLElement | null) => {
|
|
58
|
+
const { rootRef } = this.componentProps;
|
|
59
|
+
|
|
60
|
+
if (this.root === node && this.forwardedRootRef === rootRef) return;
|
|
61
|
+
|
|
62
|
+
this.releaseRootRef?.();
|
|
63
|
+
this.releaseRootRef = undefined;
|
|
64
|
+
this.root = node;
|
|
65
|
+
this.forwardedRootRef = rootRef;
|
|
66
|
+
|
|
67
|
+
if (!node) return;
|
|
68
|
+
|
|
69
|
+
if (typeof rootRef === 'function') {
|
|
70
|
+
const cleanup = rootRef(node);
|
|
71
|
+
|
|
72
|
+
this.releaseRootRef = typeof cleanup === 'function' ? cleanup : () => rootRef(null);
|
|
73
|
+
} else if (rootRef) {
|
|
74
|
+
rootRef.current = node;
|
|
75
|
+
this.releaseRootRef = () => (rootRef.current = null);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
init: RefCallback<HTMLElement> = node => {
|
|
80
|
+
this.visibilityObserver?.disconnect();
|
|
81
|
+
|
|
82
|
+
this.forwardRootRef(node);
|
|
83
|
+
|
|
84
|
+
if (!node) return;
|
|
85
|
+
|
|
86
|
+
this.visibilityObserver = new IntersectionObserver(
|
|
87
|
+
async ([{ isIntersecting }], observer) => {
|
|
88
|
+
if (!isIntersecting) return;
|
|
89
|
+
|
|
90
|
+
observer.disconnect();
|
|
91
|
+
|
|
92
|
+
const { text, intervals = 150 } = this.componentProps;
|
|
93
|
+
|
|
94
|
+
for (const char of text) {
|
|
95
|
+
await sleep(intervals / 1000);
|
|
96
|
+
|
|
97
|
+
this.echo(char);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
this.visibilityObserver.observe(node);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
render() {
|
|
105
|
+
const Root: ElementType = this.componentProps.as ?? 'pre';
|
|
106
|
+
|
|
107
|
+
const {
|
|
108
|
+
as: _as,
|
|
109
|
+
rootRef: _rootRef,
|
|
110
|
+
className,
|
|
111
|
+
text,
|
|
112
|
+
intervals: _intervals,
|
|
113
|
+
...props
|
|
114
|
+
} = this.componentProps;
|
|
115
|
+
const { started, echoed } = this;
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<Root {...props} ref={this.init} className={classNames('text-wrap', className)}>
|
|
119
|
+
{started ? echoed + (echoed === text ? '' : '_') : text}
|
|
120
|
+
</Root>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ComponentPropsWithRef, ElementType } from 'react';
|
|
2
|
+
|
|
3
|
+
import { polymorphic } from '../../Polymorphic';
|
|
4
|
+
import { TypeEchoContent } from './Content';
|
|
5
|
+
|
|
6
|
+
export interface TypeEchoProps extends ComponentPropsWithRef<'pre'> {
|
|
7
|
+
text: string;
|
|
8
|
+
intervals?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const TypeEcho = polymorphic<TypeEchoProps>(
|
|
12
|
+
({ as: RootAs, text, intervals, ref, ...props }) => (
|
|
13
|
+
<TypeEchoContent<ElementType>
|
|
14
|
+
as={RootAs}
|
|
15
|
+
{...props}
|
|
16
|
+
rootRef={ref}
|
|
17
|
+
text={text}
|
|
18
|
+
intervals={intervals}
|
|
19
|
+
/>
|
|
20
|
+
)
|
|
21
|
+
);
|
|
22
|
+
TypeEcho.displayName = 'TypeEcho';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { polymorphic } from '../../Polymorphic';
|
|
2
|
+
import { Icon } from '../Icon';
|
|
3
|
+
|
|
4
|
+
export type UserAddressProps = Partial<Record<'email' | 'website', string>>;
|
|
5
|
+
|
|
6
|
+
export const UserAddress = polymorphic<UserAddressProps>(
|
|
7
|
+
({ as: Root = 'address', email, website }) => (
|
|
8
|
+
<Root className="mb-0 d-flex justify-content-around gap-2">
|
|
9
|
+
{email && (
|
|
10
|
+
<a rel="noreferrer" target="_blank" href={'mailto:' + email}>
|
|
11
|
+
<Icon name="envelope" />
|
|
12
|
+
</a>
|
|
13
|
+
)}
|
|
14
|
+
{website && (
|
|
15
|
+
<a rel="noreferrer" target="_blank" href={website}>
|
|
16
|
+
<Icon name="globe2" />
|
|
17
|
+
</a>
|
|
18
|
+
)}
|
|
19
|
+
</Root>
|
|
20
|
+
)
|
|
21
|
+
);
|
|
22
|
+
UserAddress.displayName = 'UserAddress';
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Badge } from '../../Badge';
|
|
4
|
+
import { Col, Container, Row } from '../../Grid';
|
|
5
|
+
import { Image } from '../../Image';
|
|
6
|
+
import { polymorphic } from '../../Polymorphic';
|
|
7
|
+
import { Table } from '../../Table';
|
|
8
|
+
import { UserAddress, UserAddressProps } from './Address';
|
|
9
|
+
import * as style from './index.module.less';
|
|
10
|
+
|
|
11
|
+
export interface UserRank extends UserAddressProps {
|
|
12
|
+
id: number | string;
|
|
13
|
+
name: string;
|
|
14
|
+
avatar?: string;
|
|
15
|
+
score: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface UserRankViewProps extends HTMLAttributes<HTMLDivElement> {
|
|
19
|
+
title: string;
|
|
20
|
+
rank: UserRank[];
|
|
21
|
+
linkOf?: (user: UserRank) => string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const UserRankView = polymorphic<UserRankViewProps>(
|
|
25
|
+
({ as: RootAs, className = '', title, rank = [], linkOf, ...props }) => {
|
|
26
|
+
const renderMedal = (user: UserRank) => (
|
|
27
|
+
<li key={user.id} className="col">
|
|
28
|
+
<div className={`shadow-lg overflow-hidden rounded-circle m-auto ${style.image}`}>
|
|
29
|
+
<Image src={user.avatar} alt={user.name} loading="lazy" fluid />
|
|
30
|
+
</div>
|
|
31
|
+
<div className={`position-relative overflow-hidden ${style.topUser}`}>
|
|
32
|
+
<div className="position-relative">
|
|
33
|
+
<i className="d-block overflow-hidden m-auto mb-1 rounded-circle" />
|
|
34
|
+
<a className="d-block mb-0 stretched-link" href={linkOf?.(user) || '#'}>
|
|
35
|
+
{user.name}
|
|
36
|
+
</a>
|
|
37
|
+
<strong>{user.score}</strong>
|
|
38
|
+
</div>
|
|
39
|
+
<UserAddress {...user} />
|
|
40
|
+
</div>
|
|
41
|
+
</li>
|
|
42
|
+
);
|
|
43
|
+
const renderRow = (user: UserRank, index: number, { length }: UserRank[]) => (
|
|
44
|
+
<tr key={user.id} className="position-relative">
|
|
45
|
+
<td className="align-middle">
|
|
46
|
+
<Badge className="fw-bold fst-italic">
|
|
47
|
+
{(index + 4 + '').padStart((length + '').length, '0')}
|
|
48
|
+
</Badge>
|
|
49
|
+
</td>
|
|
50
|
+
<td className={`position-relative text-truncate ${style.name}`}>
|
|
51
|
+
<div
|
|
52
|
+
className={`d-inline-block overflow-hidden align-middle rounded-circle ${style.image}`}
|
|
53
|
+
>
|
|
54
|
+
<Image src={user.avatar} alt={user.name} loading="lazy" fluid />
|
|
55
|
+
</div>
|
|
56
|
+
<a
|
|
57
|
+
className="ms-2 d-inline-block align-middle stretched-link"
|
|
58
|
+
style={{
|
|
59
|
+
color: `rgb(248, ${(index + 2) * 15}, ${(index + 2) * 35})`
|
|
60
|
+
}}
|
|
61
|
+
href={linkOf?.(user) || '#'}
|
|
62
|
+
>
|
|
63
|
+
{user.name}
|
|
64
|
+
</a>
|
|
65
|
+
</td>
|
|
66
|
+
<td className="align-middle">{user.score}</td>
|
|
67
|
+
<td className="align-middle">
|
|
68
|
+
<UserAddress {...user} />
|
|
69
|
+
</td>
|
|
70
|
+
</tr>
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<Container as={RootAs} className={className} {...props}>
|
|
75
|
+
<Row className={style.rankBox}>
|
|
76
|
+
<Col span={12} lg={7}>
|
|
77
|
+
<div className={`shadow rounded-3 ${style.title}`}>
|
|
78
|
+
<div className={style.medal}>
|
|
79
|
+
<i className="d-inline-block ms-1 overflow-hidden rounded-circle" />
|
|
80
|
+
<i className="d-inline-block ms-1 overflow-hidden rounded-circle" />
|
|
81
|
+
<i className="d-inline-block ms-1 overflow-hidden rounded-circle" />
|
|
82
|
+
</div>
|
|
83
|
+
<h3
|
|
84
|
+
data-text={title}
|
|
85
|
+
className="position-relative m-auto mb-0 fw-bold text-center"
|
|
86
|
+
>
|
|
87
|
+
{title}
|
|
88
|
+
</h3>
|
|
89
|
+
</div>
|
|
90
|
+
<ul
|
|
91
|
+
className={`row mt-2 g-0 align-items-end text-center ps-0 pt-2 list-unstyled ${style.topUsers}`}
|
|
92
|
+
>
|
|
93
|
+
{rank.slice(0, 3).map(renderMedal)}
|
|
94
|
+
</ul>
|
|
95
|
+
</Col>
|
|
96
|
+
<Col span={12} lg={5}>
|
|
97
|
+
<Table className={`my-3 pt-2 ${style.restUsers}`} responsive>
|
|
98
|
+
<tbody>{rank.slice(3, 10).map(renderRow)}</tbody>
|
|
99
|
+
</Table>
|
|
100
|
+
</Col>
|
|
101
|
+
</Row>
|
|
102
|
+
</Container>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
UserRankView.displayName = 'UserRankView';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
import { polymorphic } from '../../Polymorphic';
|
|
4
|
+
import * as style from './index.module.less';
|
|
5
|
+
|
|
6
|
+
export interface VerticalMarqueeProps extends HTMLAttributes<HTMLDivElement> {
|
|
7
|
+
duration?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const VerticalMarquee = polymorphic<VerticalMarqueeProps>(
|
|
11
|
+
({ as: Root = 'div', className = '', children, duration, ...props }) => (
|
|
12
|
+
<Root className={`overflow-hidden h-100 ${className}`} {...props}>
|
|
13
|
+
<div
|
|
14
|
+
className={`d-inline-block max-w-100 max-h-100 ${style.scrollWrap}`}
|
|
15
|
+
// @ts-expect-error remove after React 19 released
|
|
16
|
+
style={{ '--duration': duration }}
|
|
17
|
+
>
|
|
18
|
+
<div className={`d-inline-block ${style.scrollItem}`}>{children}</div>
|
|
19
|
+
</div>
|
|
20
|
+
</Root>
|
|
21
|
+
)
|
|
22
|
+
);
|
|
23
|
+
VerticalMarquee.displayName = 'VerticalMarquee';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import { polymorphic } from '../Polymorphic';
|
|
4
|
+
|
|
5
|
+
export const ZodiacSigns = ['🐵', '🐔', '🐶', '🐷', '🐭', '🐮', '🐯', '🐰', '🐲', '🐍', '🐴', '🐐'];
|
|
6
|
+
|
|
7
|
+
export const zodiacOf = (year: number) => {
|
|
8
|
+
// Historical year numbering has no year 0: 1 BCE is represented as year -1.
|
|
9
|
+
const astronomicalYear = year < 0 ? year + 1 : year;
|
|
10
|
+
|
|
11
|
+
return ZodiacSigns[((astronomicalYear % 12) + 12) % 12];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export interface ZodiacBarProps extends HTMLAttributes<HTMLOListElement> {
|
|
15
|
+
itemClassName?: string;
|
|
16
|
+
startYear: number;
|
|
17
|
+
endYear?: number;
|
|
18
|
+
itemOf?: (year: number, zodiac: string) => { link?: string; title?: ReactNode };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const ZodiacBar = polymorphic<ZodiacBarProps>(
|
|
22
|
+
({
|
|
23
|
+
as: Root = 'ol',
|
|
24
|
+
className = '',
|
|
25
|
+
itemClassName = 'border rounded px-4 py-3 d-flex flex-column justify-content-center align-items-center',
|
|
26
|
+
startYear,
|
|
27
|
+
endYear = new Date().getFullYear(),
|
|
28
|
+
itemOf,
|
|
29
|
+
...props
|
|
30
|
+
}) => (
|
|
31
|
+
<Root
|
|
32
|
+
className={`list-unstyled m-0 d-flex flex-wrap justify-content-center gap-3 ${className}`}
|
|
33
|
+
{...props}
|
|
34
|
+
>
|
|
35
|
+
{Array.from({ length: endYear - startYear + 1 }, (_, index) => {
|
|
36
|
+
const year = endYear - index;
|
|
37
|
+
|
|
38
|
+
if (year === 0) return null;
|
|
39
|
+
|
|
40
|
+
const zodiac = zodiacOf(year);
|
|
41
|
+
const { link = '#', title } = itemOf?.(year, zodiac) || {};
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<li key={year} className={itemClassName}>
|
|
45
|
+
<a
|
|
46
|
+
className="d-inline-block p-3 text-decoration-none text-center"
|
|
47
|
+
href={link}
|
|
48
|
+
>
|
|
49
|
+
<div className="fs-3xl">{zodiac}</div>
|
|
50
|
+
|
|
51
|
+
{title}
|
|
52
|
+
</a>
|
|
53
|
+
</li>
|
|
54
|
+
);
|
|
55
|
+
})}
|
|
56
|
+
</Root>
|
|
57
|
+
)
|
|
58
|
+
);
|
|
59
|
+
ZodiacBar.displayName = 'ZodiacBar';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export * from './ClickBoundary';
|
|
2
|
+
export * from './CodeBlock';
|
|
3
|
+
export * from './Countdown';
|
|
4
|
+
export * from './Dialog';
|
|
5
|
+
export * from './Editor';
|
|
6
|
+
export * from './EditorHTML';
|
|
7
|
+
export * from './HorizontalMarquee';
|
|
8
|
+
export * from './Icon';
|
|
9
|
+
export * from './LiveTSX';
|
|
10
|
+
export * from './Loading';
|
|
11
|
+
export * from './MonthCalendar';
|
|
12
|
+
export * from './Nameplate';
|
|
13
|
+
export * from './OverlayBox';
|
|
14
|
+
export * from './PageNav';
|
|
15
|
+
export * from './ScrollNav';
|
|
16
|
+
export * from './Select';
|
|
17
|
+
export * from './ShareBox';
|
|
18
|
+
export * from './SpinnerButton';
|
|
19
|
+
export * from './TableSpinner';
|
|
20
|
+
export * from './TextTruncate';
|
|
21
|
+
export * from './Time';
|
|
22
|
+
export * from './TimeDistance';
|
|
23
|
+
export * from './Timeline';
|
|
24
|
+
export * from './TypeEcho';
|
|
25
|
+
export * from './UserRank';
|
|
26
|
+
export * from './VerticalMarquee';
|
|
27
|
+
export * from './ZodiacBar';
|