idea-react 2.0.0-rc.1 → 2.0.0-rc.11
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/ReadMe.md +34 -39
- package/dist/index.css +2 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +112 -35
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/eslint.config.ts +69 -0
- package/package.json +77 -58
- package/source/CodeBlock.tsx +13 -16
- package/source/Dialog.tsx +41 -34
- package/source/Editor.tsx +46 -46
- package/source/EditorHTML.tsx +7 -14
- package/source/HorizontalMarquee/index.module.less +52 -0
- package/source/HorizontalMarquee/index.tsx +67 -0
- package/source/Icon.tsx +1 -1
- package/source/Loading.tsx +21 -13
- package/source/MonthCalendar.tsx +10 -34
- package/source/PageNav.tsx +102 -102
- package/source/Select.tsx +84 -89
- package/source/ShareBox.tsx +99 -0
- package/source/TableSpinner.tsx +24 -14
- package/source/Time.tsx +14 -0
- package/source/TimeDistance.tsx +41 -46
- package/source/Timeline/index.module.less +53 -0
- package/source/Timeline/index.tsx +60 -0
- package/source/TypeEcho.tsx +49 -46
- package/source/UserRank/Address.tsx +20 -0
- package/source/UserRank/index.module.less +227 -0
- package/source/UserRank/index.tsx +108 -0
- package/source/VerticalMarquee/index.module.less +43 -0
- package/source/VerticalMarquee/index.tsx +27 -0
- package/source/index.ts +25 -19
- package/tsconfig.build.json +11 -11
- package/tsconfig.json +2 -1
- package/dist/index.js.map +0 -1
package/source/Select.tsx
CHANGED
|
@@ -1,89 +1,84 @@
|
|
|
1
|
-
import classNames from 'classnames';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
children
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
className
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
</Dropdown>
|
|
86
|
-
);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
Select.displayName = 'Select';
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { FC, isValidElement, ReactElement, ReactNode } from 'react';
|
|
3
|
+
import {
|
|
4
|
+
Dropdown,
|
|
5
|
+
DropdownButtonProps,
|
|
6
|
+
DropdownItemProps
|
|
7
|
+
} from 'react-bootstrap';
|
|
8
|
+
import { makeArray } from 'web-utility';
|
|
9
|
+
|
|
10
|
+
export interface OptionProps extends DropdownItemProps {
|
|
11
|
+
value?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const Option: FC<OptionProps> = ({ value, children, ...props }) => (
|
|
15
|
+
<Dropdown.Item {...props} data-value={value}>
|
|
16
|
+
{children}
|
|
17
|
+
</Dropdown.Item>
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
Option.displayName = 'Option';
|
|
21
|
+
|
|
22
|
+
export interface SelectProps
|
|
23
|
+
extends Omit<OptionProps, 'onChange'>,
|
|
24
|
+
Pick<DropdownButtonProps, 'variant' | 'menuVariant'> {
|
|
25
|
+
onChange?: (value: string) => any;
|
|
26
|
+
valueRender?: (value: string) => ReactNode;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const Select: FC<SelectProps> = ({
|
|
30
|
+
className,
|
|
31
|
+
style,
|
|
32
|
+
variant,
|
|
33
|
+
menuVariant,
|
|
34
|
+
children,
|
|
35
|
+
value,
|
|
36
|
+
onChange,
|
|
37
|
+
valueRender
|
|
38
|
+
}) => {
|
|
39
|
+
const current = (makeArray(children) as ReactNode[])
|
|
40
|
+
.flat(Infinity)
|
|
41
|
+
.find(
|
|
42
|
+
node =>
|
|
43
|
+
isValidElement<OptionProps>(node) &&
|
|
44
|
+
node.type === Option &&
|
|
45
|
+
node.props.value === value
|
|
46
|
+
) as ReactElement<OptionProps, typeof Option>;
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Dropdown
|
|
50
|
+
onClick={({ target }) => {
|
|
51
|
+
const option = (target as HTMLElement).closest<HTMLElement>(
|
|
52
|
+
'.dropdown-item'
|
|
53
|
+
);
|
|
54
|
+
if (!option) return;
|
|
55
|
+
|
|
56
|
+
const { value } = option.dataset;
|
|
57
|
+
|
|
58
|
+
onChange?.(value);
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
61
|
+
<Dropdown.Toggle
|
|
62
|
+
className={classNames(
|
|
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>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
Select.displayName = 'Select';
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import html2canvas from 'html2canvas';
|
|
2
|
+
import { observable } from 'mobx';
|
|
3
|
+
import { observer } from 'mobx-react';
|
|
4
|
+
import { Component, createRef, HTMLAttributes, MouseEvent } from 'react';
|
|
5
|
+
import { Image } from 'react-bootstrap';
|
|
6
|
+
import { blobOf } from 'web-utility';
|
|
7
|
+
|
|
8
|
+
import { Loading } from './Loading';
|
|
9
|
+
|
|
10
|
+
export async function elementToImage(
|
|
11
|
+
element: HTMLElement,
|
|
12
|
+
type?: string,
|
|
13
|
+
quality?: number
|
|
14
|
+
) {
|
|
15
|
+
const canvas = await html2canvas(element, { useCORS: true });
|
|
16
|
+
|
|
17
|
+
return new Promise<string>((resolve, reject) =>
|
|
18
|
+
canvas.toBlob(
|
|
19
|
+
blob => (blob ? resolve(URL.createObjectURL(blob)) : reject()),
|
|
20
|
+
type,
|
|
21
|
+
quality
|
|
22
|
+
)
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type ShareBoxProps = HTMLAttributes<HTMLDivElement> & ShareData;
|
|
27
|
+
|
|
28
|
+
@observer
|
|
29
|
+
export class ShareBox extends Component<ShareBoxProps> {
|
|
30
|
+
static displayName = 'ShareBox';
|
|
31
|
+
|
|
32
|
+
root = createRef<HTMLDivElement>();
|
|
33
|
+
|
|
34
|
+
@observable
|
|
35
|
+
accessor loading = false;
|
|
36
|
+
|
|
37
|
+
@observable
|
|
38
|
+
accessor imageURI = '';
|
|
39
|
+
|
|
40
|
+
componentDidMount() {
|
|
41
|
+
globalThis.addEventListener?.('resize', this.generateImage);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
componentWillUnmount() {
|
|
45
|
+
globalThis.removeEventListener?.('resize', this.generateImage);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
generateImage = async () => {
|
|
49
|
+
if (this.imageURI) {
|
|
50
|
+
URL.revokeObjectURL(this.imageURI);
|
|
51
|
+
this.imageURI = '';
|
|
52
|
+
}
|
|
53
|
+
this.loading = true;
|
|
54
|
+
this.imageURI = await elementToImage(this.root.current!);
|
|
55
|
+
this.loading = false;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
share = async (event: MouseEvent<HTMLImageElement>) => {
|
|
59
|
+
event.stopPropagation();
|
|
60
|
+
|
|
61
|
+
const image = await blobOf(this.imageURI);
|
|
62
|
+
|
|
63
|
+
const file = new File([image], `${this.props.title}.png`, {
|
|
64
|
+
type: image.type
|
|
65
|
+
});
|
|
66
|
+
await navigator.share?.({ files: [file], ...this.props });
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
render() {
|
|
70
|
+
const { className = '', children, ...props } = this.props,
|
|
71
|
+
{ loading, imageURI } = this;
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<>
|
|
75
|
+
{loading && <Loading />}
|
|
76
|
+
|
|
77
|
+
<div
|
|
78
|
+
{...props}
|
|
79
|
+
ref={this.root}
|
|
80
|
+
className={`position-relative ${className}`}
|
|
81
|
+
onMouseEnter={imageURI ? undefined : this.generateImage}
|
|
82
|
+
onTouchStart={imageURI ? undefined : this.generateImage}
|
|
83
|
+
>
|
|
84
|
+
{children}
|
|
85
|
+
|
|
86
|
+
{imageURI && (
|
|
87
|
+
<Image
|
|
88
|
+
className="position-absolute start-0 top-0 w-100 h-100"
|
|
89
|
+
src={imageURI}
|
|
90
|
+
alt="Share Image"
|
|
91
|
+
fluid
|
|
92
|
+
onClick={this.share}
|
|
93
|
+
/>
|
|
94
|
+
)}
|
|
95
|
+
</div>
|
|
96
|
+
</>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
package/source/TableSpinner.tsx
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
import { FC,
|
|
2
|
-
import { Spinner } from 'react-bootstrap';
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { FC, HTMLAttributes } from 'react';
|
|
2
|
+
import { Spinner, SpinnerProps } from 'react-bootstrap';
|
|
3
|
+
|
|
4
|
+
export interface TableSpinnerProps
|
|
5
|
+
extends HTMLAttributes<HTMLTableRowElement>,
|
|
6
|
+
Pick<SpinnerProps, 'animation' | 'variant' | 'size'> {
|
|
7
|
+
colSpan: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const TableSpinner: FC<TableSpinnerProps> = ({
|
|
11
|
+
animation = 'border',
|
|
12
|
+
variant = 'primary',
|
|
13
|
+
size,
|
|
14
|
+
colSpan,
|
|
15
|
+
...props
|
|
16
|
+
}) => (
|
|
17
|
+
<tr {...props}>
|
|
18
|
+
<td className="text-center p-4" colSpan={colSpan}>
|
|
19
|
+
<Spinner {...{ animation, variant, size }} />
|
|
20
|
+
</td>
|
|
21
|
+
</tr>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
TableSpinner.displayName = 'TableSpinner';
|
package/source/Time.tsx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FC, TimeHTMLAttributes } from 'react';
|
|
2
|
+
import { formatDate, TimeData } from 'web-utility';
|
|
3
|
+
|
|
4
|
+
export interface TimeProps
|
|
5
|
+
extends Omit<TimeHTMLAttributes<HTMLTimeElement>, 'dateTime'> {
|
|
6
|
+
dateTime: TimeData;
|
|
7
|
+
format?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const Time: FC<TimeProps> = ({ dateTime, format, ...props }) => (
|
|
11
|
+
<time dateTime={new Date(dateTime).toJSON()} {...props}>
|
|
12
|
+
{formatDate(dateTime, format)}
|
|
13
|
+
</time>
|
|
14
|
+
);
|
package/source/TimeDistance.tsx
CHANGED
|
@@ -1,46 +1,41 @@
|
|
|
1
|
-
import { FC,
|
|
2
|
-
import { diffTime, TimeData } from 'web-utility';
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
</time>
|
|
43
|
-
);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
TimeDistance.displayName = 'TimeDistance';
|
|
1
|
+
import { FC, HTMLAttributes } from 'react';
|
|
2
|
+
import { diffTime, TimeData } from 'web-utility';
|
|
3
|
+
|
|
4
|
+
export interface TimeDistanceProps extends HTMLAttributes<HTMLTimeElement> {
|
|
5
|
+
date: TimeData;
|
|
6
|
+
unitWords?: Record<string, string>;
|
|
7
|
+
beforeWord?: string;
|
|
8
|
+
afterWord?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const UnitWords = {
|
|
12
|
+
ms: 'millisecond(s)',
|
|
13
|
+
s: 'second(s)',
|
|
14
|
+
m: 'minute(s)',
|
|
15
|
+
H: 'hour(s)',
|
|
16
|
+
D: 'day(s)',
|
|
17
|
+
W: 'week(s)',
|
|
18
|
+
M: 'month(s)',
|
|
19
|
+
Y: 'year(s)'
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const TimeDistance: FC<TimeDistanceProps> = ({
|
|
23
|
+
date,
|
|
24
|
+
unitWords = UnitWords,
|
|
25
|
+
beforeWord = ' before',
|
|
26
|
+
afterWord = ' after',
|
|
27
|
+
...props
|
|
28
|
+
}) => {
|
|
29
|
+
date = new Date(date);
|
|
30
|
+
|
|
31
|
+
const { distance, unit } = diffTime(date);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<time {...props} dateTime={date.toJSON()} title={date.toLocaleString()}>
|
|
35
|
+
{Math.abs(distance)} {unitWords[unit]}
|
|
36
|
+
{distance < 0 ? beforeWord : afterWord}
|
|
37
|
+
</time>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
TimeDistance.displayName = 'TimeDistance';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
.timeline {
|
|
2
|
+
position: relative;
|
|
3
|
+
margin: 0 auto;
|
|
4
|
+
max-width: 50%;
|
|
5
|
+
@media (max-width: 991px) {
|
|
6
|
+
max-width: 100%;
|
|
7
|
+
}
|
|
8
|
+
&::after {
|
|
9
|
+
position: absolute;
|
|
10
|
+
top: 0;
|
|
11
|
+
bottom: 0;
|
|
12
|
+
left: 10px;
|
|
13
|
+
margin-left: -3px;
|
|
14
|
+
background-color: #fff;
|
|
15
|
+
width: 3px;
|
|
16
|
+
content: '';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
.timelineItem {
|
|
20
|
+
position: relative;
|
|
21
|
+
background-color: inherit;
|
|
22
|
+
width: 100%;
|
|
23
|
+
|
|
24
|
+
&::after {
|
|
25
|
+
position: absolute;
|
|
26
|
+
top: 18px;
|
|
27
|
+
right: 1px;
|
|
28
|
+
z-index: 1;
|
|
29
|
+
border-radius: 50%;
|
|
30
|
+
background-color: #fff;
|
|
31
|
+
width: 17px;
|
|
32
|
+
height: 17px;
|
|
33
|
+
content: '';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
.right {
|
|
37
|
+
left: auto;
|
|
38
|
+
padding: 0px 0px 20px 40px;
|
|
39
|
+
|
|
40
|
+
&::before {
|
|
41
|
+
position: absolute;
|
|
42
|
+
top: 18px;
|
|
43
|
+
left: 30px;
|
|
44
|
+
z-index: 1;
|
|
45
|
+
border: medium solid #fff;
|
|
46
|
+
border-width: 10px 10px 10px 0;
|
|
47
|
+
border-color: transparent #fff transparent transparent;
|
|
48
|
+
content: ' ';
|
|
49
|
+
}
|
|
50
|
+
&::after {
|
|
51
|
+
left: 0;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { FC, HTMLAttributes } from 'react';
|
|
2
|
+
import { Card } from 'react-bootstrap';
|
|
3
|
+
import { TimeData } from 'web-utility';
|
|
4
|
+
|
|
5
|
+
import { Nameplate, NameplateProps } from '../Nameplate';
|
|
6
|
+
import { Time } from '../Time';
|
|
7
|
+
import * as styles from './index.module.less';
|
|
8
|
+
|
|
9
|
+
export interface TimelineEvent {
|
|
10
|
+
title: string;
|
|
11
|
+
summary?: string;
|
|
12
|
+
time: [TimeData, TimeData?];
|
|
13
|
+
|
|
14
|
+
link?: string;
|
|
15
|
+
people?: NameplateProps[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface TimelineProps extends HTMLAttributes<HTMLOListElement> {
|
|
19
|
+
events: TimelineEvent[];
|
|
20
|
+
timeFormat?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @see {@link https://mdbootstrap.com/docs/standard/extended/timeline/#section-timeline-gradient-bg}
|
|
25
|
+
*/
|
|
26
|
+
export const Timeline: FC<TimelineProps> = ({ className, events, timeFormat, ...props }) => (
|
|
27
|
+
<ol className={`list-unstyled ${styles.timeline} ${className}`} {...props}>
|
|
28
|
+
{events.map(({ title, summary, time, link, people }) => (
|
|
29
|
+
<li
|
|
30
|
+
key={title as string}
|
|
31
|
+
className={`position-relative ${styles.timelineItem} ${styles.right}`}
|
|
32
|
+
>
|
|
33
|
+
<Card>
|
|
34
|
+
<Card.Body className="p-4 d-flex flex-column gap-3 align-items-center">
|
|
35
|
+
<h3 className="h5 m-0">
|
|
36
|
+
<a className="text-decoration-none stretched-link" href={link}>
|
|
37
|
+
{title as string}
|
|
38
|
+
</a>
|
|
39
|
+
</h3>
|
|
40
|
+
<div className="small text-muted d-flex gap-2">
|
|
41
|
+
⏲️
|
|
42
|
+
<Time dateTime={time[0]} format={timeFormat} />
|
|
43
|
+
{time[1] && '~'}
|
|
44
|
+
{time[1] && <Time dateTime={time[1]} format={timeFormat} />}
|
|
45
|
+
</div>
|
|
46
|
+
<ul className="list-unstyled m-0 d-flex gap-2 flex-wrap justify-content-around">
|
|
47
|
+
{people?.map(person => (
|
|
48
|
+
<li key={person.name}>
|
|
49
|
+
<Nameplate {...person} />
|
|
50
|
+
</li>
|
|
51
|
+
))}
|
|
52
|
+
</ul>
|
|
53
|
+
<p className="m-0">{summary as string}</p>
|
|
54
|
+
</Card.Body>
|
|
55
|
+
</Card>
|
|
56
|
+
</li>
|
|
57
|
+
))}
|
|
58
|
+
</ol>
|
|
59
|
+
);
|
|
60
|
+
Timeline.displayName = 'Timeline';
|
package/source/TypeEcho.tsx
CHANGED
|
@@ -1,46 +1,49 @@
|
|
|
1
|
-
import classNames from 'classnames';
|
|
2
|
-
import { observable } from 'mobx';
|
|
3
|
-
import { observer } from 'mobx-react';
|
|
4
|
-
import {
|
|
5
|
-
import { sleep } from 'web-utility';
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
{
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { observable } from 'mobx';
|
|
3
|
+
import { observer } from 'mobx-react';
|
|
4
|
+
import { Component, HTMLAttributes, RefCallback } from 'react';
|
|
5
|
+
import { sleep } from 'web-utility';
|
|
6
|
+
|
|
7
|
+
export interface TypeEchoProps extends HTMLAttributes<HTMLPreElement> {
|
|
8
|
+
text: string;
|
|
9
|
+
intervals?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@observer
|
|
13
|
+
export class TypeEcho extends Component<TypeEchoProps> {
|
|
14
|
+
static displayName = 'TypeEcho';
|
|
15
|
+
|
|
16
|
+
@observable
|
|
17
|
+
accessor echoed = '';
|
|
18
|
+
|
|
19
|
+
init: RefCallback<HTMLPreElement> = node =>
|
|
20
|
+
node &&
|
|
21
|
+
new IntersectionObserver(async ([{ isIntersecting }], observer) => {
|
|
22
|
+
if (!isIntersecting) return;
|
|
23
|
+
|
|
24
|
+
observer.disconnect();
|
|
25
|
+
|
|
26
|
+
const { text, intervals = 150 } = this.props;
|
|
27
|
+
|
|
28
|
+
for (const char of text) {
|
|
29
|
+
await sleep(intervals / 1000);
|
|
30
|
+
|
|
31
|
+
this.echoed += char;
|
|
32
|
+
}
|
|
33
|
+
}).observe(node);
|
|
34
|
+
|
|
35
|
+
render() {
|
|
36
|
+
const { className, text, ...props } = this.props,
|
|
37
|
+
{ echoed } = this;
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<pre
|
|
41
|
+
{...props}
|
|
42
|
+
ref={this.init}
|
|
43
|
+
className={classNames('text-wrap', className)}
|
|
44
|
+
>
|
|
45
|
+
{echoed + (echoed === text ? '' : '_')}
|
|
46
|
+
</pre>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Icon } from '../Icon';
|
|
4
|
+
|
|
5
|
+
export type UserAddressProps = Partial<Record<'email' | 'website', string>>;
|
|
6
|
+
|
|
7
|
+
export const UserAddress: FC<UserAddressProps> = ({ email, website }) => (
|
|
8
|
+
<address 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
|
+
</address>
|
|
20
|
+
);
|