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.
Files changed (60) hide show
  1. package/AGENTS.md +31 -10
  2. package/ReadMe.md +42 -35
  3. package/dist/index.d.mts +301 -100
  4. package/dist/index.d.ts +301 -100
  5. package/dist/index.js +16 -16
  6. package/dist/index.mjs +15 -15
  7. package/dist/style.css +5 -5
  8. package/package.json +4 -7
  9. package/source/Avatar.tsx +65 -12
  10. package/source/Button.tsx +13 -4
  11. package/source/ButtonGroup.tsx +28 -0
  12. package/source/Card.tsx +26 -0
  13. package/source/ClickBoundary.tsx +6 -5
  14. package/source/CloseButton.tsx +23 -0
  15. package/source/CodeBlock.tsx +5 -3
  16. package/source/Countdown.tsx +2 -0
  17. package/source/Drawer.tsx +62 -0
  18. package/source/Editor.tsx +5 -8
  19. package/source/Grid.tsx +92 -0
  20. package/source/HorizontalMarquee/index.tsx +4 -10
  21. package/source/Image.tsx +15 -0
  22. package/source/ListGroup.tsx +103 -0
  23. package/source/LiveTSX.tsx +1 -1
  24. package/source/Loading.tsx +4 -3
  25. package/source/Menu.tsx +99 -1
  26. package/source/MonthCalendar.tsx +60 -22
  27. package/source/NativeDialog/index.tsx +37 -1
  28. package/source/Nav.tsx +52 -0
  29. package/source/Navbar.tsx +48 -1
  30. package/source/Overlay.ts +22 -0
  31. package/source/OverlayBox.tsx +200 -32
  32. package/source/PageNav.tsx +56 -32
  33. package/source/Popover.tsx +36 -0
  34. package/source/ScrollNav/Scroller.tsx +107 -0
  35. package/source/ScrollNav/index.tsx +12 -99
  36. package/source/Select.tsx +66 -55
  37. package/source/ShareBox.tsx +5 -11
  38. package/source/Spinner.tsx +30 -0
  39. package/source/SpinnerButton.tsx +8 -10
  40. package/source/Table.tsx +59 -0
  41. package/source/TableSpinner.tsx +7 -5
  42. package/source/{TextTruncate.tsx → TextTruncate/Content.tsx} +24 -20
  43. package/source/TextTruncate/index.tsx +25 -0
  44. package/source/Time.tsx +7 -33
  45. package/source/TimeDistance.tsx +1 -1
  46. package/source/Timeline/index.tsx +7 -7
  47. package/source/Toast.tsx +114 -29
  48. package/source/ToggleButton.tsx +47 -0
  49. package/source/Tooltip.tsx +32 -0
  50. package/source/TypeEcho/Content.tsx +58 -0
  51. package/source/TypeEcho/index.tsx +14 -0
  52. package/source/UserRank/index.module.less +9 -20
  53. package/source/UserRank/index.tsx +35 -32
  54. package/source/VerticalMarquee/index.module.less +0 -1
  55. package/source/VerticalMarquee/index.tsx +3 -5
  56. package/source/ZodiacBar.tsx +1 -1
  57. package/source/animate.ts +4 -2
  58. package/source/color.ts +3 -5
  59. package/source/index.ts +13 -0
  60. package/source/TypeEcho.tsx +0 -49
@@ -0,0 +1,59 @@
1
+ import classNames from 'classnames';
2
+ import { ComponentPropsWithRef, FC } from 'react';
3
+
4
+ import type { Breakpoint } from './Grid';
5
+
6
+ export interface TableProps extends ComponentPropsWithRef<'table'> {
7
+ striped?: boolean;
8
+ stripedColumns?: boolean;
9
+ hover?: boolean;
10
+ bordered?: boolean;
11
+ borderless?: boolean;
12
+ small?: boolean;
13
+ responsive?: boolean | Breakpoint;
14
+ }
15
+
16
+ export const Table: FC<TableProps> = ({
17
+ striped,
18
+ stripedColumns,
19
+ hover,
20
+ bordered,
21
+ borderless,
22
+ small,
23
+ responsive,
24
+ className,
25
+ ...props
26
+ }) => {
27
+ const table = (
28
+ <table
29
+ {...props}
30
+ className={classNames(
31
+ 'table',
32
+ {
33
+ 'table-striped': striped,
34
+ 'table-striped-columns': stripedColumns,
35
+ 'table-hover': hover,
36
+ 'table-bordered': bordered,
37
+ 'table-borderless': borderless,
38
+ 'table-sm': small
39
+ },
40
+ className
41
+ )}
42
+ />
43
+ );
44
+
45
+ return !responsive ? (
46
+ table
47
+ ) : (
48
+ <div
49
+ className={classNames(
50
+ 'table-responsive',
51
+ responsive !== true && `${responsive}:table-responsive`
52
+ )}
53
+ >
54
+ {table}
55
+ </div>
56
+ );
57
+ };
58
+
59
+ Table.displayName = 'Table';
@@ -1,22 +1,24 @@
1
1
  import { FC, HTMLAttributes } from 'react';
2
- import { Spinner, SpinnerProps } from 'react-bootstrap';
2
+
3
+ import { Spinner, SpinnerProps } from './Spinner';
3
4
 
4
5
  export interface TableSpinnerProps
5
- extends HTMLAttributes<HTMLTableRowElement>,
6
- Pick<SpinnerProps, 'animation' | 'variant' | 'size'> {
6
+ extends
7
+ HTMLAttributes<HTMLTableRowElement>,
8
+ Pick<SpinnerProps, 'animation' | 'theme' | 'size'> {
7
9
  colSpan: number;
8
10
  }
9
11
 
10
12
  export const TableSpinner: FC<TableSpinnerProps> = ({
11
13
  animation = 'border',
12
- variant = 'primary',
14
+ theme = 'primary',
13
15
  size,
14
16
  colSpan,
15
17
  ...props
16
18
  }) => (
17
19
  <tr {...props}>
18
20
  <td className="text-center p-4" colSpan={colSpan}>
19
- <Spinner {...{ animation, variant, size }} />
21
+ <Spinner {...{ animation, theme, size }} role="status" aria-label="Loading" />
20
22
  </td>
21
23
  </tr>
22
24
  );
@@ -1,16 +1,19 @@
1
- import { observable } from 'mobx';
1
+ 'use client';
2
+
3
+ import { action, observable } from 'mobx';
2
4
  import { observer } from 'mobx-react';
3
- import { Component, createRef, CSSProperties, HTMLAttributes, ReactNode } from 'react';
5
+ import { Component, createRef, CSSProperties, ReactNode } from 'react';
4
6
 
5
- export interface TextTruncateProps extends HTMLAttributes<HTMLDivElement> {
6
- rows?: number;
7
- expandText?: ReactNode;
8
- collapseText?: ReactNode;
7
+ export interface TextTruncateContentProps {
8
+ rows: number;
9
+ expandText: ReactNode;
10
+ collapseText: ReactNode;
11
+ children: ReactNode;
9
12
  }
10
13
 
11
14
  @observer
12
- export class TextTruncate extends Component<TextTruncateProps> {
13
- static displayName = 'TextTruncate';
15
+ export class TextTruncateContent extends Component<TextTruncateContentProps> {
16
+ static displayName = 'TextTruncateContent';
14
17
 
15
18
  @observable
16
19
  accessor expanded = false;
@@ -18,14 +21,14 @@ export class TextTruncate extends Component<TextTruncateProps> {
18
21
  @observable
19
22
  accessor overflowed = false;
20
23
 
21
- contentRef = createRef<HTMLParagraphElement>();
24
+ contentRef = createRef<HTMLDivElement>();
22
25
 
23
26
  componentDidMount() {
24
27
  this.checkOverflow();
25
28
  window.addEventListener('resize', this.checkOverflow);
26
29
  }
27
30
 
28
- componentDidUpdate({ rows, children }: TextTruncateProps) {
31
+ componentDidUpdate({ rows, children }: TextTruncateContentProps) {
29
32
  if (!this.expanded && (children !== this.props.children || rows !== this.props.rows))
30
33
  this.checkOverflow();
31
34
  }
@@ -34,32 +37,33 @@ export class TextTruncate extends Component<TextTruncateProps> {
34
37
  window.removeEventListener('resize', this.checkOverflow);
35
38
  }
36
39
 
37
- checkOverflow = () => {
40
+ checkOverflow = action(() => {
38
41
  const { current } = this.contentRef;
39
42
 
40
43
  if (current) this.overflowed = current.scrollHeight > current.clientHeight;
41
- };
44
+ });
42
45
 
43
- toggle = () => {
46
+ toggle = action(() => {
44
47
  this.expanded = !this.expanded;
45
48
 
46
49
  if (!this.expanded) requestAnimationFrame(this.checkOverflow);
47
- };
50
+ });
48
51
 
49
52
  render() {
50
- const { children, rows = 3, expandText = '⏬', collapseText = '⏫', ...props } = this.props;
53
+ const { children, rows = 3, expandText = '⏬', collapseText } = this.props;
51
54
  const { expanded, overflowed } = this;
52
- const style: CSSProperties = {
55
+ const clamp: CSSProperties = {
53
56
  overflow: 'hidden',
54
57
  display: '-webkit-box',
55
58
  WebkitBoxOrient: 'vertical',
56
59
  WebkitLineClamp: rows
57
60
  };
61
+
58
62
  return (
59
- <div {...props}>
60
- <p ref={this.contentRef} style={expanded ? undefined : style}>
63
+ <>
64
+ <div ref={this.contentRef} style={expanded ? undefined : clamp}>
61
65
  {children}
62
- </p>
66
+ </div>
63
67
  {(overflowed || expanded) && (
64
68
  <button
65
69
  type="button"
@@ -70,7 +74,7 @@ export class TextTruncate extends Component<TextTruncateProps> {
70
74
  {expanded ? collapseText : expandText}
71
75
  </button>
72
76
  )}
73
- </div>
77
+ </>
74
78
  );
75
79
  }
76
80
  }
@@ -0,0 +1,25 @@
1
+ import { FC, HTMLAttributes, ReactNode } from 'react';
2
+
3
+ import { TextTruncateContent } from './Content';
4
+
5
+ export interface TextTruncateProps extends HTMLAttributes<HTMLDivElement> {
6
+ rows?: number;
7
+ expandText?: ReactNode;
8
+ collapseText?: ReactNode;
9
+ }
10
+
11
+ export const TextTruncate: FC<TextTruncateProps> = ({
12
+ rows = 3,
13
+ expandText = '⏬',
14
+ collapseText = '⏫',
15
+ children,
16
+ ...props
17
+ }) => (
18
+ <div {...props}>
19
+ <TextTruncateContent rows={rows} expandText={expandText} collapseText={collapseText}>
20
+ {children}
21
+ </TextTruncateContent>
22
+ </div>
23
+ );
24
+
25
+ TextTruncate.displayName = 'TextTruncate';
package/source/Time.tsx CHANGED
@@ -1,7 +1,4 @@
1
- import { observable } from 'mobx';
2
- import { observer } from 'mobx-react';
3
- import { ObservedComponent, reaction } from 'mobx-react-helper';
4
- import { TimeHTMLAttributes } from 'react';
1
+ import { FC, TimeHTMLAttributes } from 'react';
5
2
  import { formatDate, TimeData } from 'web-utility';
6
3
 
7
4
  export interface TimeProps extends Omit<TimeHTMLAttributes<HTMLTimeElement>, 'dateTime'> {
@@ -9,33 +6,10 @@ export interface TimeProps extends Omit<TimeHTMLAttributes<HTMLTimeElement>, 'da
9
6
  format?: string;
10
7
  }
11
8
 
12
- @observer
13
- export class Time extends ObservedComponent<TimeProps> {
14
- static displayName = 'Time';
9
+ export const Time: FC<TimeProps> = ({ dateTime, format, ...props }) => (
10
+ <time dateTime={new Date(dateTime).toJSON()} {...props}>
11
+ {formatDate(dateTime, format)}
12
+ </time>
13
+ );
15
14
 
16
- @reaction(({ observedProps: { dateTime, format } }) => dateTime + format)
17
- updateText() {
18
- const { dateTime, format } = this.props;
19
-
20
- return formatDate(dateTime, format);
21
- }
22
-
23
- @observable
24
- accessor timeText = this.updateText();
25
-
26
- componentDidMount() {
27
- super.componentDidMount();
28
-
29
- this.timeText = this.updateText();
30
- }
31
-
32
- render() {
33
- const { dateTime, ...props } = this.props;
34
-
35
- return (
36
- <time dateTime={new Date(dateTime).toJSON()} {...props}>
37
- {this.timeText}
38
- </time>
39
- );
40
- }
41
- }
15
+ Time.displayName = 'Time';
@@ -8,7 +8,7 @@ export interface TimeDistanceProps extends HTMLAttributes<HTMLTimeElement> {
8
8
  afterWord?: string;
9
9
  }
10
10
 
11
- const UnitWords = {
11
+ const UnitWords: Record<string, string> = {
12
12
  ms: 'millisecond(s)',
13
13
  s: 'second(s)',
14
14
  m: 'minute(s)',
@@ -1,7 +1,7 @@
1
1
  import { FC, HTMLAttributes } from 'react';
2
- import { Card } from 'react-bootstrap';
3
2
  import { TimeData } from 'web-utility';
4
3
 
4
+ import { Card, CardBody, CardText, CardTitle } from '../Card';
5
5
  import { Nameplate, NameplateProps } from '../Nameplate';
6
6
  import { Time } from '../Time';
7
7
  import * as styles from './index.module.less';
@@ -31,13 +31,13 @@ export const Timeline: FC<TimelineProps> = ({ className, events, timeFormat, ...
31
31
  className={`position-relative ${styles.timelineItem} ${styles.right}`}
32
32
  >
33
33
  <Card>
34
- <Card.Body className="p-4 d-flex flex-column gap-3 align-items-center">
35
- <h3 className="h5 m-0">
34
+ <CardBody className="p-4 d-flex flex-column gap-3 align-items-center">
35
+ <CardTitle className="h5 m-0">
36
36
  <a className="text-decoration-none stretched-link" href={link}>
37
37
  {title as string}
38
38
  </a>
39
- </h3>
40
- <div className="small text-muted d-flex gap-2">
39
+ </CardTitle>
40
+ <div className="small fg-3 d-flex gap-2">
41
41
  ⏲️
42
42
  <Time dateTime={time[0]} format={timeFormat} />
43
43
  {time[1] && '~'}
@@ -50,8 +50,8 @@ export const Timeline: FC<TimelineProps> = ({ className, events, timeFormat, ...
50
50
  </li>
51
51
  ))}
52
52
  </ul>
53
- <p className="m-0">{summary as string}</p>
54
- </Card.Body>
53
+ <CardText className="m-0">{summary as string}</CardText>
54
+ </CardBody>
55
55
  </Card>
56
56
  </li>
57
57
  ))}
package/source/Toast.tsx CHANGED
@@ -1,79 +1,164 @@
1
- import { observable } from 'mobx';
1
+ 'use client';
2
+
3
+ import classNames from 'classnames';
4
+ import { action, observable } from 'mobx';
2
5
  import { observer } from 'mobx-react';
3
- import { FC, ReactNode } from 'react';
4
- import { Toast as BSToast, ToastContainer, ToastContainerProps } from 'react-bootstrap';
5
- import { Variant } from 'react-bootstrap/esm/types';
6
+ import { ComponentPropsWithRef, FC, MouseEvent, ReactNode } from 'react';
6
7
  import { Timestamp, uniqueID } from 'web-utility';
7
8
 
8
- const LIGHT_TEXT_VARIANTS = new Set<Variant>(['warning', 'info', 'light']);
9
+ import type { ComponentTheme } from './Button';
10
+
11
+ export type ToastPosition =
12
+ | 'top-start'
13
+ | 'top-center'
14
+ | 'top-end'
15
+ | 'middle-start'
16
+ | 'middle-center'
17
+ | 'middle-end'
18
+ | 'bottom-start'
19
+ | 'bottom-center'
20
+ | 'bottom-end';
21
+
22
+ const TOAST_POSITION_CLASSES: Record<ToastPosition, string> = {
23
+ 'top-start': 'top-0 start-0',
24
+ 'top-center': 'top-0 start-50 translate-middle-x',
25
+ 'top-end': 'top-0 end-0',
26
+ 'middle-start': 'top-50 start-0 translate-middle-y',
27
+ 'middle-center': 'top-50 start-50 translate-middle',
28
+ 'middle-end': 'top-50 end-0 translate-middle-y',
29
+ 'bottom-start': 'bottom-0 start-0',
30
+ 'bottom-center': 'bottom-0 start-50 translate-middle-x',
31
+ 'bottom-end': 'bottom-0 end-0'
32
+ };
9
33
 
10
34
  export interface ToastMessage {
11
35
  id?: string;
12
36
  title?: ReactNode;
13
37
  body: ReactNode;
14
- variant?: Variant;
38
+ theme?: ComponentTheme;
15
39
  delay?: number;
16
40
  }
17
41
 
18
- interface ToastItem extends ToastMessage {
42
+ interface ToastEntry extends ToastMessage {
19
43
  openedAt: number;
20
44
  closedAt?: number;
21
- resolve?: (value: ToastItem) => void;
45
+ timer?: ReturnType<typeof setTimeout>;
46
+ resolve?: (value: ToastEntry) => void;
47
+ }
48
+
49
+ export interface ToastContainerProps extends ComponentPropsWithRef<'div'> {
50
+ position?: ToastPosition;
51
+ }
52
+
53
+ export const ToastContainer: FC<ToastContainerProps> = ({
54
+ position = 'top-end',
55
+ className,
56
+ 'aria-live': ariaLive = 'polite',
57
+ 'aria-atomic': ariaAtomic = true,
58
+ ...props
59
+ }) => (
60
+ <div
61
+ {...props}
62
+ className={classNames(
63
+ 'toast-container position-fixed p-3',
64
+ TOAST_POSITION_CLASSES[position],
65
+ className
66
+ )}
67
+ aria-live={ariaLive}
68
+ aria-atomic={ariaAtomic}
69
+ />
70
+ );
71
+
72
+ export interface ToastItemProps extends ComponentPropsWithRef<'div'> {
73
+ theme?: ComponentTheme;
22
74
  }
23
75
 
76
+ export const ToastItem: FC<ToastItemProps> = ({ theme, role = 'status', className, ...props }) => (
77
+ <div
78
+ {...props}
79
+ className={classNames('toast show', theme && `theme-${theme}`, className)}
80
+ role={role}
81
+ />
82
+ );
83
+
84
+ export const ToastHeader: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
85
+ <div {...props} className={classNames('toast-header', className)} />
86
+ );
87
+
88
+ export const ToastBody: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
89
+ <div {...props} className={classNames('toast-body', className)} />
90
+ );
91
+
24
92
  export class Toast {
25
93
  @observable
26
- accessor messages: ToastItem[] = [];
94
+ accessor messages: ToastEntry[] = [];
27
95
 
28
- Component: FC<Pick<ToastContainerProps, 'position'>> = observer(({ position = 'top-end' }) => (
29
- <ToastContainer position={position} className="position-fixed p-3">
96
+ Component: FC<{ position?: ToastPosition }> = observer(({ position }) => (
97
+ <ToastContainer position={position} onClick={this.handleDismiss}>
30
98
  {this.messages.map(this.renderMessage)}
31
99
  </ToastContainer>
32
100
  ));
33
101
 
34
- renderMessage = ({ id, openedAt, title, body, variant, delay = 3000 }: ToastItem) => {
35
- const bodyClassName =
36
- variant && !LIGHT_TEXT_VARIANTS.has(variant) ? 'text-white' : undefined;
102
+ renderMessage = ({ id, openedAt, title, body, theme, delay = 3000 }: ToastEntry) => {
37
103
  const showHeader = !!title || delay === 0;
38
104
  const elapsed = this.TimeScalar.distanceOf<Timestamp>(Date.now(), openedAt).toShortString();
39
105
 
40
106
  return (
41
- <BSToast
42
- key={id}
43
- bg={variant}
44
- delay={delay}
45
- autohide={delay !== 0}
46
- onClose={() => this.close(id!)}
47
- >
107
+ <ToastItem key={id} theme={theme}>
48
108
  {showHeader && (
49
- <BSToast.Header>
109
+ <ToastHeader>
50
110
  <strong className="me-auto">{title}</strong>
51
111
  <small>{elapsed}</small>
52
- </BSToast.Header>
112
+ <button
113
+ type="button"
114
+ className="btn-close"
115
+ aria-label="Close"
116
+ data-toast-dismiss={id}
117
+ />
118
+ </ToastHeader>
53
119
  )}
54
- <BSToast.Body className={bodyClassName}>{body}</BSToast.Body>
55
- </BSToast>
120
+ <ToastBody>{body}</ToastBody>
121
+ </ToastItem>
56
122
  );
57
123
  };
58
124
 
125
+ handleDismiss = ({ target }: MouseEvent<HTMLDivElement>) => {
126
+ if (!(target instanceof Element)) return;
127
+
128
+ const id = target.closest<HTMLElement>('[data-toast-dismiss]')?.dataset.toastDismiss;
129
+ if (id) this.close(id);
130
+ };
131
+
59
132
  constructor(public TimeScalar = Timestamp) {
60
133
  this.Component.displayName = 'ToastComponent';
61
134
  }
62
135
 
136
+ @action
63
137
  open(message: ToastMessage) {
64
138
  const id = uniqueID();
65
139
  const openedAt = Date.now();
66
- const { promise, resolve } = Promise.withResolvers<ToastItem>();
140
+ const { promise, resolve } = Promise.withResolvers<ToastEntry>();
141
+ const timer =
142
+ message.delay === 0
143
+ ? undefined
144
+ : setTimeout(() => this.close(id), message.delay ?? 3000);
67
145
 
68
- this.messages = [...this.messages, { id, ...message, openedAt, resolve }];
146
+ const item: ToastEntry = { id, ...message, openedAt, resolve, timer };
147
+
148
+ this.messages = [...this.messages, item];
69
149
 
70
150
  return promise;
71
151
  }
72
152
 
153
+ @action
73
154
  close(id: string) {
74
- const { resolve, ...item } = this.messages.find(message => message.id === id) || {};
155
+ const message = this.messages.find(message => message.id === id);
156
+ if (!message) return;
157
+
158
+ const { resolve, timer, ...item } = message;
75
159
 
76
- resolve?.({ ...item, closedAt: Date.now() } as ToastItem);
160
+ clearTimeout(timer);
161
+ resolve?.({ ...item, closedAt: Date.now() } as ToastEntry);
77
162
 
78
163
  this.messages = this.messages.filter(message => message.id !== id);
79
164
  }
@@ -0,0 +1,47 @@
1
+ import classNames from 'classnames';
2
+ import { ComponentPropsWithRef, FC } from 'react';
3
+
4
+ import type { ComponentTheme } from './Button';
5
+
6
+ export interface ToggleButtonProps extends Omit<ComponentPropsWithRef<'label'>, 'onChange'> {
7
+ type?: 'checkbox' | 'radio';
8
+ variant?: 'solid' | 'outline' | 'subtle' | 'text';
9
+ theme?: ComponentTheme;
10
+ name?: string;
11
+ value?: string;
12
+ checked?: boolean;
13
+ defaultChecked?: boolean;
14
+ disabled?: boolean;
15
+ }
16
+
17
+ export const ToggleButton: FC<ToggleButtonProps> = ({
18
+ type = 'checkbox',
19
+ variant = 'solid',
20
+ theme,
21
+ name,
22
+ value,
23
+ checked,
24
+ defaultChecked,
25
+ disabled,
26
+ className,
27
+ children,
28
+ ...props
29
+ }) => (
30
+ <label
31
+ {...props}
32
+ className={classNames('btn-check', `btn-${variant}`, theme && `theme-${theme}`, className)}
33
+ >
34
+ <input
35
+ type={type}
36
+ name={name}
37
+ value={value}
38
+ checked={checked}
39
+ defaultChecked={defaultChecked}
40
+ disabled={disabled}
41
+ autoComplete="off"
42
+ />
43
+ {children}
44
+ </label>
45
+ );
46
+
47
+ ToggleButton.displayName = 'ToggleButton';
@@ -0,0 +1,32 @@
1
+ import classNames from 'classnames';
2
+ import { FC } from 'react';
3
+
4
+ import { OVERLAY_ARROW_POSITIONS, OVERLAY_DIRECTIONS, OverlayTriggerProps } from './Overlay';
5
+
6
+ export type TooltipProps = OverlayTriggerProps;
7
+
8
+ export const Tooltip: FC<TooltipProps> = ({
9
+ placement = 'top',
10
+ show = true,
11
+ role = 'tooltip',
12
+ className,
13
+ children,
14
+ ...props
15
+ }) => (
16
+ <div
17
+ {...props}
18
+ className={classNames(
19
+ 'tooltip',
20
+ { show },
21
+ `bs-tooltip-${OVERLAY_DIRECTIONS[placement]}`,
22
+ className
23
+ )}
24
+ role={role}
25
+ data-bs-placement={placement}
26
+ >
27
+ <div className={classNames('tooltip-arrow', OVERLAY_ARROW_POSITIONS[placement])} />
28
+ <div className="tooltip-inner">{children}</div>
29
+ </div>
30
+ );
31
+
32
+ Tooltip.displayName = 'Tooltip';
@@ -0,0 +1,58 @@
1
+ 'use client';
2
+
3
+ import classNames from 'classnames';
4
+ import { action, observable } from 'mobx';
5
+ import { observer } from 'mobx-react';
6
+ import { Component, HTMLAttributes, RefCallback } from 'react';
7
+ import { sleep } from 'web-utility';
8
+
9
+ export interface TypeEchoContentProps extends Omit<HTMLAttributes<HTMLPreElement>, 'children'> {
10
+ text: string;
11
+ intervals?: number;
12
+ }
13
+
14
+ @observer
15
+ export class TypeEchoContent extends Component<TypeEchoContentProps> {
16
+ @observable
17
+ accessor echoed = '';
18
+
19
+ @observable
20
+ accessor started = false;
21
+
22
+ componentDidMount() {
23
+ this.start();
24
+ }
25
+
26
+ start = action(() => (this.started = true));
27
+
28
+ echo = action((char: string) => (this.echoed += char));
29
+
30
+ init: RefCallback<HTMLPreElement> = node => {
31
+ if (!node) return;
32
+
33
+ new IntersectionObserver(async ([{ isIntersecting }], observer) => {
34
+ if (!isIntersecting) return;
35
+
36
+ observer.disconnect();
37
+
38
+ const { text, intervals = 150 } = this.props;
39
+
40
+ for (const char of text) {
41
+ await sleep(intervals / 1000);
42
+
43
+ this.echo(char);
44
+ }
45
+ }).observe(node);
46
+ };
47
+
48
+ render() {
49
+ const { className, text, intervals: _intervals, ...props } = this.props;
50
+ const { started, echoed } = this;
51
+
52
+ return (
53
+ <pre {...props} ref={this.init} className={classNames('text-wrap', className)}>
54
+ {started ? echoed + (echoed === text ? '' : '_') : text}
55
+ </pre>
56
+ );
57
+ }
58
+ }
@@ -0,0 +1,14 @@
1
+ import { FC, HTMLAttributes } from 'react';
2
+
3
+ import { TypeEchoContent } from './Content';
4
+
5
+ export interface TypeEchoProps extends HTMLAttributes<HTMLPreElement> {
6
+ text: string;
7
+ intervals?: number;
8
+ }
9
+
10
+ export const TypeEcho: FC<TypeEchoProps> = ({ text, intervals, ...props }) => (
11
+ <TypeEchoContent {...props} text={text} intervals={intervals} />
12
+ );
13
+
14
+ TypeEcho.displayName = 'TypeEcho';