idea-react 3.0.0-beta.0 → 3.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/AGENTS.md +11 -2
  2. package/ReadMe.md +62 -49
  3. package/dist/DatePickerPlugin-CpGuQRsi.js +1 -0
  4. package/dist/DatePickerPlugin-DB3nnslN.mjs +1 -0
  5. package/dist/index.d.mts +1116 -442
  6. package/dist/index.d.ts +1116 -442
  7. package/dist/index.js +16 -16
  8. package/dist/index.mjs +15 -15
  9. package/dist/rolldown-runtime-5iZMYShA.js +1 -0
  10. package/dist/style.css +69 -66
  11. package/package.json +1 -1
  12. package/source/Accordion.tsx +137 -0
  13. package/source/Alert.tsx +138 -0
  14. package/source/Avatar.tsx +7 -1
  15. package/source/Badge.tsx +2 -0
  16. package/source/Breadcrumb.tsx +36 -0
  17. package/source/Button.tsx +40 -5
  18. package/source/ButtonGroup.tsx +10 -1
  19. package/source/Card.tsx +65 -4
  20. package/source/Carousel/index.tsx +391 -0
  21. package/source/Carousel/model.ts +113 -0
  22. package/source/Carousel/scroll.ts +79 -0
  23. package/source/Collapse.tsx +178 -0
  24. package/source/Drawer.tsx +127 -30
  25. package/source/{CodeBlock.tsx → Extension/CodeBlock/index.tsx} +23 -5
  26. package/source/Extension/CodeBlock/style.module.css +3 -0
  27. package/source/{Dialog.tsx → Extension/Dialog.tsx} +10 -6
  28. package/source/{EditorHTML.tsx → Extension/EditorHTML.tsx} +1 -1
  29. package/source/{HorizontalMarquee → Extension/HorizontalMarquee}/index.module.less +1 -3
  30. package/source/{Icon.tsx → Extension/Icon.tsx} +1 -7
  31. package/source/{Loading.tsx → Extension/Loading.tsx} +8 -3
  32. package/source/{MonthCalendar.tsx → Extension/MonthCalendar.tsx} +3 -3
  33. package/source/{Nameplate.tsx → Extension/Nameplate.tsx} +1 -1
  34. package/source/Extension/OverlayBox.tsx +280 -0
  35. package/source/{PageNav.tsx → Extension/PageNav.tsx} +27 -9
  36. package/source/{ScrollNav → Extension/ScrollNav}/index.tsx +1 -1
  37. package/source/Extension/Select.tsx +127 -0
  38. package/source/{ShareBox.tsx → Extension/ShareBox.tsx} +1 -1
  39. package/source/{SpinnerButton.tsx → Extension/SpinnerButton.tsx} +2 -2
  40. package/source/{TableSpinner.tsx → Extension/TableSpinner.tsx} +1 -1
  41. package/source/{Timeline → Extension/Timeline}/index.tsx +1 -1
  42. package/source/{UserRank → Extension/UserRank}/index.tsx +4 -4
  43. package/source/Extension/index.ts +27 -0
  44. package/source/Form/Adorn.tsx +32 -11
  45. package/source/Form/Checkbox.tsx +11 -6
  46. package/source/Form/ChipInput.tsx +125 -0
  47. package/source/Form/Chips.tsx +42 -24
  48. package/source/Form/Combobox.tsx +337 -72
  49. package/source/Form/Control.tsx +50 -15
  50. package/source/Form/DatePicker.tsx +231 -40
  51. package/source/Form/DatePickerPlugin.ts +37 -0
  52. package/source/Form/Feedback.tsx +10 -4
  53. package/source/Form/FloatingLabel.tsx +24 -7
  54. package/source/Form/InputGroup.tsx +155 -5
  55. package/source/Form/OTP.tsx +138 -45
  56. package/source/Form/PasswordStrength.tsx +43 -17
  57. package/source/Form/Plugin.tsx +53 -0
  58. package/source/Form/Primitives.tsx +51 -9
  59. package/source/Form/Radio.tsx +20 -28
  60. package/source/Form/Range.tsx +103 -52
  61. package/source/Form/Switch.tsx +30 -7
  62. package/source/Form/index.ts +1 -0
  63. package/source/Grid.tsx +4 -0
  64. package/source/ListGroup.tsx +28 -15
  65. package/source/Menu.tsx +226 -17
  66. package/source/NativeDialog/index.tsx +109 -5
  67. package/source/Nav.tsx +18 -2
  68. package/source/NavOverflow/index.tsx +307 -0
  69. package/source/NavOverflow/model.ts +21 -0
  70. package/source/Navbar.tsx +18 -3
  71. package/source/Overlay.ts +163 -1
  72. package/source/Pagination.tsx +92 -0
  73. package/source/Placeholder.tsx +66 -0
  74. package/source/Popover.tsx +7 -2
  75. package/source/Progress/index.tsx +76 -0
  76. package/source/Progress/style.module.css +15 -0
  77. package/source/ScrollSpy/index.tsx +365 -0
  78. package/source/ScrollSpy/model.ts +17 -0
  79. package/source/Spinner.tsx +10 -0
  80. package/source/Stepper.tsx +85 -0
  81. package/source/Tab.tsx +248 -0
  82. package/source/Toast.tsx +46 -14
  83. package/source/ToggleButton.tsx +21 -7
  84. package/source/Toggler.tsx +108 -0
  85. package/source/Tooltip.tsx +6 -1
  86. package/source/index.ts +15 -27
  87. package/source/OverlayBox.tsx +0 -208
  88. package/source/Select.tsx +0 -95
  89. /package/source/{ClickBoundary.tsx → Extension/ClickBoundary.tsx} +0 -0
  90. /package/source/{Countdown.tsx → Extension/Countdown.tsx} +0 -0
  91. /package/source/{Editor.tsx → Extension/Editor.tsx} +0 -0
  92. /package/source/{HorizontalMarquee → Extension/HorizontalMarquee}/index.tsx +0 -0
  93. /package/source/{LiveTSX.tsx → Extension/LiveTSX.tsx} +0 -0
  94. /package/source/{ScrollNav → Extension/ScrollNav}/Scroller.tsx +0 -0
  95. /package/source/{ScrollNav → Extension/ScrollNav}/index.module.less +0 -0
  96. /package/source/{TextTruncate → Extension/TextTruncate}/Content.tsx +0 -0
  97. /package/source/{TextTruncate → Extension/TextTruncate}/index.tsx +0 -0
  98. /package/source/{Time.tsx → Extension/Time.tsx} +0 -0
  99. /package/source/{TimeDistance.tsx → Extension/TimeDistance.tsx} +0 -0
  100. /package/source/{Timeline → Extension/Timeline}/index.module.less +0 -0
  101. /package/source/{TypeEcho → Extension/TypeEcho}/Content.tsx +0 -0
  102. /package/source/{TypeEcho → Extension/TypeEcho}/index.tsx +0 -0
  103. /package/source/{UserRank → Extension/UserRank}/Address.tsx +0 -0
  104. /package/source/{UserRank → Extension/UserRank}/index.module.less +0 -0
  105. /package/source/{VerticalMarquee → Extension/VerticalMarquee}/index.module.less +0 -0
  106. /package/source/{VerticalMarquee → Extension/VerticalMarquee}/index.tsx +0 -0
  107. /package/source/{ZodiacBar.tsx → Extension/ZodiacBar.tsx} +0 -0
@@ -0,0 +1,307 @@
1
+ 'use client';
2
+
3
+ import classNames from 'classnames';
4
+ import { observer } from 'mobx-react';
5
+ import {
6
+ Children,
7
+ cloneElement,
8
+ Component,
9
+ ComponentPropsWithRef,
10
+ createRef,
11
+ CSSProperties,
12
+ isValidElement,
13
+ KeyboardEvent,
14
+ MouseEvent,
15
+ ReactElement,
16
+ ReactNode
17
+ } from 'react';
18
+
19
+ import { Icon } from '../Extension/Icon';
20
+ import { Menu, MenuProps } from '../Menu';
21
+ import { Nav, NavProps } from '../Nav';
22
+ import { NavOverflowModel } from './model';
23
+
24
+ interface OverflowChildProps {
25
+ 'aria-hidden'?: boolean;
26
+ className?: string;
27
+ role?: string;
28
+ style?: CSSProperties;
29
+ tabIndex?: number;
30
+ }
31
+
32
+ export interface NavOverflowProps
33
+ extends
34
+ Omit<ComponentPropsWithRef<'div'>, 'onChange' | 'children'>,
35
+ Pick<NavProps, 'variant' | 'fill' | 'justified'> {
36
+ children: ReactNode;
37
+ collapseBelow?: number | string;
38
+ id: string;
39
+ iconPlacement?: 'start' | 'end';
40
+ menuPlacement?: string;
41
+ menuStrategy?: 'absolute' | 'fixed';
42
+ minimumVisibleItems?: number;
43
+ moreIcon?: ReactNode;
44
+ moreText?: string | false;
45
+ onOverflowChange?: (overflowCount: number, visibleCount: number) => unknown;
46
+ threshold?: number;
47
+ }
48
+
49
+ @observer
50
+ export class NavOverflow extends Component<NavOverflowProps> {
51
+ static displayName = 'NavOverflow';
52
+
53
+ root = createRef<HTMLDivElement>();
54
+
55
+ nav = createRef<HTMLElement>();
56
+
57
+ toggleButton = createRef<HTMLButtonElement>();
58
+
59
+ store = new NavOverflowModel();
60
+
61
+ private resizeObserver?: ResizeObserver;
62
+
63
+ componentDidMount() {
64
+ this.updateOverflow();
65
+ window.addEventListener('resize', this.updateOverflow);
66
+ document.addEventListener('pointerdown', this.handleOutside);
67
+
68
+ if (typeof ResizeObserver !== 'undefined') {
69
+ this.resizeObserver = new ResizeObserver(this.updateOverflow);
70
+
71
+ if (this.root.current) this.resizeObserver.observe(this.root.current);
72
+ if (this.nav.current) this.resizeObserver.observe(this.nav.current);
73
+
74
+ for (const item of this.nav.current?.children ?? []) this.resizeObserver.observe(item);
75
+ }
76
+ }
77
+
78
+ componentDidUpdate() {
79
+ this.updateOverflow();
80
+ }
81
+
82
+ componentWillUnmount() {
83
+ this.resizeObserver?.disconnect();
84
+ window.removeEventListener('resize', this.updateOverflow);
85
+ document.removeEventListener('pointerdown', this.handleOutside);
86
+ }
87
+
88
+ updateOverflow = () => {
89
+ const root = this.root.current;
90
+ const nav = this.nav.current;
91
+ if (!root || !nav) return;
92
+
93
+ const items = [...nav.children].filter(
94
+ item => item !== this.toggleButton.current?.parentElement
95
+ ) as HTMLElement[];
96
+ const widths = items.map(item => item.getBoundingClientRect().width || item.offsetWidth);
97
+ const gap = Number.parseFloat(getComputedStyle(nav).columnGap) || 0;
98
+ const allWidth =
99
+ widths.reduce((total, width) => total + width, 0) + gap * Math.max(0, items.length - 1);
100
+ const toggleWidth =
101
+ this.toggleButton.current?.getBoundingClientRect().width ||
102
+ this.toggleButton.current?.offsetWidth ||
103
+ 0;
104
+ const containerWidth = root.clientWidth;
105
+ const collapseBelow = this.getCollapseBelow();
106
+ const shouldCollapseAll =
107
+ collapseBelow > 0 && containerWidth > 0 && containerWidth < collapseBelow;
108
+ const keep = items.map(item => item.classList.contains('nav-overflow-keep'));
109
+ const visible = items.map((_, index) => index);
110
+ const minimum = Math.max(
111
+ 0,
112
+ Math.min(this.props.minimumVisibleItems ?? this.props.threshold ?? 0, items.length)
113
+ );
114
+ let visibleWidth = allWidth;
115
+
116
+ if (shouldCollapseAll) {
117
+ for (let index = visible.length - 1; index >= 0; index--)
118
+ if (!keep[index]) visible.splice(index, 1);
119
+ } else if (containerWidth > 0 && allWidth > containerWidth)
120
+ while (visibleWidth + toggleWidth > containerWidth && visible.length > minimum) {
121
+ const index = visible.findLast(candidate => !keep[candidate]);
122
+ if (index === undefined) break;
123
+
124
+ visibleWidth -= widths[index] + (visible.length > 1 ? gap : 0);
125
+ visible.splice(visible.indexOf(index), 1);
126
+ }
127
+ const visibleSet = new Set(visible);
128
+ const overflowIndices = items
129
+ .map((_, index) => index)
130
+ .filter(index => !visibleSet.has(index));
131
+ const current = this.store.overflowIndices;
132
+ const changed =
133
+ current.length !== overflowIndices.length ||
134
+ current.some((index, position) => index !== overflowIndices[position]);
135
+
136
+ if (!this.store.initialized || changed) this.store.setOverflowIndices(overflowIndices);
137
+ if (changed) this.props.onOverflowChange?.(overflowIndices.length, visible.length);
138
+ };
139
+
140
+ private getCollapseBelow = () => {
141
+ const { collapseBelow = 0 } = this.props;
142
+ if (typeof collapseBelow === 'number') return collapseBelow;
143
+
144
+ const value = getComputedStyle(this.root.current as HTMLElement).getPropertyValue(
145
+ `--bs-breakpoint-${collapseBelow}`
146
+ );
147
+ return Number.parseFloat(value) || 0;
148
+ };
149
+
150
+ handleClick = (event: MouseEvent<HTMLDivElement>) => {
151
+ this.props.onClick?.(event);
152
+
153
+ const target = event.target instanceof Element ? event.target : null;
154
+ if (event.defaultPrevented) return;
155
+
156
+ if (target?.closest('[data-overflow-toggle]')) this.store.toggle();
157
+ else if (target?.closest('.nav-overflow-menu') && !target.closest('[aria-haspopup="true"]'))
158
+ this.store.setOpen(false);
159
+ };
160
+
161
+ handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
162
+ this.props.onKeyDown?.(event);
163
+ if (event.defaultPrevented) return;
164
+
165
+ if (event.key === 'Escape' && this.store.open) {
166
+ this.store.setOpen(false);
167
+ this.toggleButton.current?.focus();
168
+ } else if (event.key === 'ArrowDown' && event.target === this.toggleButton.current) {
169
+ event.preventDefault();
170
+ this.store.setOpen(true);
171
+
172
+ queueMicrotask(() =>
173
+ this.root.current
174
+ ?.querySelector<HTMLElement>(
175
+ '.nav-overflow-menu a[href]:not([aria-disabled="true"]), .nav-overflow-menu button:not(:disabled)'
176
+ )
177
+ ?.focus()
178
+ );
179
+ }
180
+ };
181
+
182
+ handleOutside = (event: PointerEvent) => {
183
+ if (event.target instanceof Node && !this.root.current?.contains(event.target))
184
+ this.store.setOpen(false);
185
+ };
186
+
187
+ renderChild = (child: ReactNode, index: number, overflow = false) => {
188
+ if (!isValidElement<OverflowChildProps>(child)) return <span key={index}>{child}</span>;
189
+
190
+ if (overflow) {
191
+ if (child.type === Menu)
192
+ return cloneElement(child as ReactElement<MenuProps>, {
193
+ className: classNames(child.props.className, 'nav-overflow-submenu')
194
+ });
195
+ return cloneElement(child as ReactElement<OverflowChildProps>, {
196
+ className: classNames(child.props.className, 'menu-item'),
197
+ role: 'menuitem'
198
+ });
199
+ }
200
+ const hidden = this.store.overflowIndices.includes(index);
201
+
202
+ return cloneElement(child as ReactElement<OverflowChildProps>, {
203
+ className: classNames(child.props.className, hidden && 'position-absolute invisible'),
204
+ 'aria-hidden': hidden || undefined,
205
+ tabIndex: hidden ? -1 : child.props.tabIndex
206
+ });
207
+ };
208
+
209
+ render() {
210
+ const {
211
+ children,
212
+ className,
213
+ collapseBelow: _collapseBelow,
214
+ fill,
215
+ iconPlacement = 'start',
216
+ justified,
217
+ menuPlacement = 'bottom-end',
218
+ menuStrategy = 'absolute',
219
+ minimumVisibleItems: _minimumVisibleItems,
220
+ moreIcon,
221
+ moreText = 'More',
222
+ onClick: _onClick,
223
+ onKeyDown: _onKeyDown,
224
+ onOverflowChange: _onOverflowChange,
225
+ threshold: _threshold,
226
+ 'aria-label': ariaLabel,
227
+ variant,
228
+ ...props
229
+ } = this.props;
230
+ const items = Children.toArray(children);
231
+ const hasOverflow = this.store.overflowIndices.length > 0;
232
+ const menuId = `${this.props.id}-menu`;
233
+ const [vertical, horizontal] = menuPlacement.split('-');
234
+ const placementClasses =
235
+ vertical === 'top'
236
+ ? ['bottom-100', horizontal === 'end' ? 'end-0' : 'start-0']
237
+ : vertical === 'bottom'
238
+ ? ['top-100', horizontal === 'end' ? 'end-0' : 'start-0']
239
+ : vertical === 'left'
240
+ ? ['end-100', horizontal === 'end' ? 'bottom-0' : 'top-0']
241
+ : ['start-100', horizontal === 'end' ? 'bottom-0' : 'top-0'];
242
+ const icon = moreIcon ?? <Icon name="three-dots" aria-hidden="true" />;
243
+ const text = moreText === false ? null : moreText;
244
+
245
+ return (
246
+ <div
247
+ {...props}
248
+ ref={this.root}
249
+ className={classNames(
250
+ 'nav-overflow d-flex align-items-start position-relative',
251
+ this.store.initialized && 'nav-overflow-initialized',
252
+ className
253
+ )}
254
+ onClick={this.handleClick}
255
+ onKeyDown={this.handleKeyDown}
256
+ >
257
+ <Nav
258
+ ref={this.nav}
259
+ variant={variant}
260
+ fill={fill}
261
+ justified={justified}
262
+ aria-label={ariaLabel}
263
+ className="flex-nowrap flex-grow-1"
264
+ >
265
+ {items.map((child, index) => this.renderChild(child, index))}
266
+ <div
267
+ className={classNames(
268
+ 'nav-item nav-overflow-item flex-shrink-0',
269
+ !hasOverflow && 'position-absolute invisible'
270
+ )}
271
+ data-menu-placement={menuPlacement}
272
+ >
273
+ <button
274
+ ref={this.toggleButton}
275
+ type="button"
276
+ className="nav-link"
277
+ aria-haspopup="menu"
278
+ aria-expanded={this.store.open}
279
+ aria-controls={menuId}
280
+ aria-label={text ? undefined : 'More'}
281
+ data-overflow-toggle
282
+ >
283
+ {iconPlacement === 'start' && icon}
284
+ {text}
285
+ {iconPlacement === 'end' && icon}
286
+ </button>
287
+ <div
288
+ id={menuId}
289
+ className={classNames(
290
+ 'menu nav-overflow-menu',
291
+ placementClasses,
292
+ menuStrategy === 'fixed' && 'position-fixed',
293
+ { show: this.store.open && hasOverflow }
294
+ )}
295
+ role="menu"
296
+ hidden={!this.store.open || !hasOverflow}
297
+ >
298
+ {this.store.overflowIndices.map(index =>
299
+ this.renderChild(items[index], index, true)
300
+ )}
301
+ </div>
302
+ </div>
303
+ </Nav>
304
+ </div>
305
+ );
306
+ }
307
+ }
@@ -0,0 +1,21 @@
1
+ import { action, observable } from 'mobx';
2
+
3
+ export class NavOverflowModel {
4
+ @observable accessor initialized = false;
5
+
6
+ @observable accessor open = false;
7
+
8
+ @observable accessor overflowIndices: number[] = [];
9
+
10
+ @action
11
+ setOpen = (open: boolean) => (this.open = open);
12
+
13
+ @action
14
+ toggle = () => (this.open = !this.open);
15
+
16
+ @action
17
+ setOverflowIndices = (indices: number[]) => {
18
+ this.initialized = true;
19
+ this.overflowIndices = indices;
20
+ };
21
+ }
package/source/Navbar.tsx CHANGED
@@ -6,13 +6,15 @@ import { Button } from './Button';
6
6
  export interface NavbarProps extends ComponentPropsWithRef<'nav'> {
7
7
  theme?: 'light' | 'dark';
8
8
  expand?: boolean | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
9
+ translucent?: boolean;
9
10
  }
10
11
 
11
- export const Navbar: FC<NavbarProps> = ({ expand, theme, className, ...props }) => (
12
+ export const Navbar: FC<NavbarProps> = ({ expand, theme, translucent, className, ...props }) => (
12
13
  <nav
13
14
  {...props}
14
15
  className={classNames(
15
16
  'navbar',
17
+ translucent && 'navbar-translucent',
16
18
  expand && (expand === true ? 'navbar-expand' : `${expand}:navbar-expand`),
17
19
  className
18
20
  )}
@@ -34,8 +36,21 @@ export const NavbarBrand: FC<NavbarBrandProps> = props => {
34
36
  return <a {...anchorProps} className={classNames('navbar-brand', className)} />;
35
37
  };
36
38
 
37
- export const NavbarNav: FC<ComponentPropsWithRef<'ul'>> = ({ className, ...props }) => (
38
- <ul {...props} className={classNames('navbar-nav', className)} />
39
+ export interface NavbarNavProps extends ComponentPropsWithRef<'ul'> {
40
+ variant?: 'tabs' | 'pills' | 'underline';
41
+ nav?: boolean;
42
+ }
43
+
44
+ export const NavbarNav: FC<NavbarNavProps> = ({ variant, nav, className, ...props }) => (
45
+ <ul
46
+ {...props}
47
+ className={classNames(
48
+ 'navbar-nav',
49
+ (nav || variant) && 'nav',
50
+ variant && `nav-${variant}`,
51
+ className
52
+ )}
53
+ />
39
54
  );
40
55
 
41
56
  export const NavbarText: FC<ComponentPropsWithRef<'span'>> = ({ className, ...props }) => (
package/source/Overlay.ts CHANGED
@@ -1,10 +1,172 @@
1
- import { ComponentPropsWithRef } from 'react';
1
+ import { action, observable } from 'mobx';
2
+ import { ComponentPropsWithRef, CSSProperties } from 'react';
3
+
4
+ import { Breakpoint } from './Grid';
2
5
 
3
6
  export type OverlayPlacement = 'top' | 'right' | 'bottom' | 'left';
7
+ export type FloatingPlacement = OverlayPlacement | `${OverlayPlacement}-${'start' | 'end'}`;
8
+ export type OverlayOffset = number | readonly [number, number];
9
+ export type OverlayContainer = string | HTMLElement | (() => HTMLElement);
10
+
11
+ export interface FloatingOptions {
12
+ placement?: FloatingPlacement;
13
+ responsivePlacement?: Partial<Record<Breakpoint, FloatingPlacement>>;
14
+ offset?: OverlayOffset;
15
+ padding?: number;
16
+ flip?: boolean;
17
+ }
18
+
19
+ const BREAKPOINTS: Record<Breakpoint, number> = {
20
+ sm: 576,
21
+ md: 768,
22
+ lg: 1024,
23
+ xl: 1280,
24
+ '2xl': 1536
25
+ };
26
+ const OPPOSITE: Record<OverlayPlacement, OverlayPlacement> = {
27
+ top: 'bottom',
28
+ bottom: 'top',
29
+ left: 'right',
30
+ right: 'left'
31
+ };
32
+
33
+ /** Owns geometry and subscriptions shared by menus, tooltips and popovers. */
34
+ export class FloatingPosition {
35
+ @observable accessor placement: FloatingPlacement = 'top';
36
+ @observable accessor style: CSSProperties = {};
37
+ @observable accessor arrowStyle: CSSProperties = {};
38
+
39
+ reference?: HTMLElement;
40
+ element?: HTMLElement;
41
+ resize?: ResizeObserver;
42
+ options: FloatingOptions = {};
43
+
44
+ attach(reference: HTMLElement, element: HTMLElement, options: FloatingOptions) {
45
+ this.dispose();
46
+ this.reference = reference;
47
+ this.element = element;
48
+ this.options = options;
49
+
50
+ window.addEventListener('resize', this.update);
51
+ document.addEventListener('scroll', this.update, true);
52
+
53
+ this.resize = new window.ResizeObserver(this.update);
54
+ this.resize.observe(reference);
55
+ this.resize.observe(element);
56
+ this.update();
57
+ }
58
+
59
+ dispose = () => {
60
+ window.removeEventListener('resize', this.update);
61
+ document.removeEventListener('scroll', this.update, true);
62
+ this.resize?.disconnect();
63
+ this.resize = undefined;
64
+ this.reference = undefined;
65
+ this.element = undefined;
66
+ };
67
+
68
+ @action
69
+ update = () => {
70
+ const { reference, element, options } = this;
71
+ if (!reference || !element) return;
72
+
73
+ const { responsivePlacement, offset = 0, padding = 8, flip = true } = options;
74
+ const responsive = (Object.keys(BREAKPOINTS) as Breakpoint[])
75
+ .reverse()
76
+ .find(key => window.innerWidth >= BREAKPOINTS[key] && responsivePlacement?.[key]);
77
+ const preferred =
78
+ (responsive && responsivePlacement?.[responsive]) || options.placement || 'top';
79
+ const [side, alignment] = preferred.split('-') as [
80
+ OverlayPlacement,
81
+ 'start' | 'end' | undefined
82
+ ];
83
+ const anchor = reference.getBoundingClientRect();
84
+ const box = element.getBoundingClientRect();
85
+ const [skid, distance] = typeof offset === 'number' ? [0, offset] : offset;
86
+ const available: Record<OverlayPlacement, number> = {
87
+ top: anchor.top - padding,
88
+ bottom: window.innerHeight - anchor.bottom - padding,
89
+ left: anchor.left - padding,
90
+ right: window.innerWidth - anchor.right - padding
91
+ };
92
+ const required = (side === 'top' || side === 'bottom' ? box.height : box.width) + distance;
93
+ const actual =
94
+ flip && available[side] < required && available[OPPOSITE[side]] > available[side]
95
+ ? OPPOSITE[side]
96
+ : side;
97
+ let left = anchor.left + (anchor.width - box.width) / 2;
98
+ let top = anchor.top + (anchor.height - box.height) / 2;
99
+
100
+ if (actual === 'top' || actual === 'bottom') {
101
+ top = actual === 'top' ? anchor.top - box.height - distance : anchor.bottom + distance;
102
+ if (alignment) left = alignment === 'start' ? anchor.left : anchor.right - box.width;
103
+ left += skid;
104
+ } else {
105
+ left = actual === 'left' ? anchor.left - box.width - distance : anchor.right + distance;
106
+ if (alignment) top = alignment === 'start' ? anchor.top : anchor.bottom - box.height;
107
+ top += skid;
108
+ }
109
+ left = Math.max(padding, Math.min(left, window.innerWidth - box.width - padding));
110
+ top = Math.max(padding, Math.min(top, window.innerHeight - box.height - padding));
111
+
112
+ const arrowStyle: CSSProperties =
113
+ actual === 'top' || actual === 'bottom'
114
+ ? {
115
+ left: Math.max(
116
+ 8,
117
+ Math.min(box.width - 8, anchor.left + anchor.width / 2 - left)
118
+ )
119
+ }
120
+ : {
121
+ top: Math.max(
122
+ 8,
123
+ Math.min(box.height - 8, anchor.top + anchor.height / 2 - top)
124
+ )
125
+ };
126
+ if (this.arrowStyle.left !== arrowStyle.left || this.arrowStyle.top !== arrowStyle.top)
127
+ this.arrowStyle = arrowStyle;
128
+
129
+ const parent = element.offsetParent;
130
+ const positionedParent =
131
+ parent instanceof HTMLElement &&
132
+ !(parent === document.body && getComputedStyle(parent).position === 'static')
133
+ ? parent
134
+ : undefined;
135
+ const parentBox = positionedParent?.getBoundingClientRect();
136
+ left += positionedParent
137
+ ? positionedParent.scrollLeft - parentBox!.left - positionedParent.clientLeft
138
+ : window.scrollX;
139
+ top += positionedParent
140
+ ? positionedParent.scrollTop - parentBox!.top - positionedParent.clientTop
141
+ : window.scrollY;
142
+ const placement: FloatingPlacement = alignment ? `${actual}-${alignment}` : actual;
143
+ if (this.placement !== placement) this.placement = placement;
144
+
145
+ const maxWidth = Math.max(0, window.innerWidth - padding * 2);
146
+ const maxHeight = Math.max(0, window.innerHeight - padding * 2);
147
+ if (
148
+ this.style.left !== left ||
149
+ this.style.top !== top ||
150
+ this.style.maxWidth !== maxWidth ||
151
+ this.style.maxHeight !== maxHeight
152
+ )
153
+ this.style = {
154
+ position: 'absolute',
155
+ left,
156
+ top,
157
+ right: 'auto',
158
+ bottom: 'auto',
159
+ margin: 0,
160
+ maxWidth,
161
+ maxHeight
162
+ };
163
+ };
164
+ }
4
165
 
5
166
  export interface OverlayTriggerProps extends ComponentPropsWithRef<'div'> {
6
167
  placement?: OverlayPlacement;
7
168
  show?: boolean;
169
+ arrowStyle?: CSSProperties;
8
170
  }
9
171
 
10
172
  export const OVERLAY_DIRECTIONS: Record<OverlayPlacement, string> = {
@@ -0,0 +1,92 @@
1
+ import classNames from 'classnames';
2
+ import { cloneElement, ComponentPropsWithRef, FC, isValidElement } from 'react';
3
+
4
+ import { ComponentTheme } from './Button';
5
+
6
+ export interface PaginationProps extends ComponentPropsWithRef<'ul'> {
7
+ theme?: ComponentTheme;
8
+ size?: 'sm' | 'lg';
9
+ }
10
+
11
+ export const Pagination: FC<PaginationProps> = ({ theme, size, className, ...props }) => (
12
+ <ul
13
+ {...props}
14
+ className={classNames(
15
+ 'pagination',
16
+ theme && `theme-${theme}`,
17
+ size && `pagination-${size}`,
18
+ className
19
+ )}
20
+ />
21
+ );
22
+
23
+ type PageState = Partial<Record<'active' | 'disabled', boolean>>;
24
+
25
+ export type PageItemProps = ComponentPropsWithRef<'li'> & PageState;
26
+
27
+ export const PageItem: FC<PageItemProps> = ({
28
+ active,
29
+ disabled,
30
+ className,
31
+ children,
32
+ ...props
33
+ }) => {
34
+ const child =
35
+ isValidElement<PageLinkProps>(children) && children.type === PageLink
36
+ ? cloneElement(children, {
37
+ active: children.props.active ?? active,
38
+ disabled: children.props.disabled ?? disabled
39
+ })
40
+ : children;
41
+
42
+ return (
43
+ <li {...props} className={classNames('page-item', { active, disabled }, className)}>
44
+ {child}
45
+ </li>
46
+ );
47
+ };
48
+
49
+ export type PageLinkProps = ComponentPropsWithRef<'a'> & PageState;
50
+
51
+ export const PageLink: FC<PageLinkProps> = ({
52
+ active,
53
+ disabled,
54
+ className,
55
+ href,
56
+ tabIndex,
57
+ onClick,
58
+ 'aria-current': current,
59
+ ...props
60
+ }) => {
61
+ const linkProps = {
62
+ ...props,
63
+ className: classNames('page-link', className),
64
+ tabIndex: disabled ? -1 : tabIndex,
65
+ 'aria-disabled': disabled || undefined,
66
+ 'aria-current': current ?? (active ? 'page' : undefined)
67
+ };
68
+
69
+ return href !== undefined ? (
70
+ <a
71
+ {...linkProps}
72
+ href={disabled ? undefined : href}
73
+ onClick={disabled ? undefined : onClick}
74
+ />
75
+ ) : (
76
+ <span
77
+ {...props}
78
+ className={classNames('page-link', className)}
79
+ aria-disabled={disabled || undefined}
80
+ aria-current={current ?? (active ? 'page' : undefined)}
81
+ />
82
+ );
83
+ };
84
+
85
+ export const PageText: FC<ComponentPropsWithRef<'span'>> = ({ className, ...props }) => (
86
+ <span {...props} className={classNames('page-link', className)} />
87
+ );
88
+
89
+ Pagination.displayName = 'Pagination';
90
+ PageItem.displayName = 'PageItem';
91
+ PageLink.displayName = 'PageLink';
92
+ PageText.displayName = 'PageText';