idea-react 2.3.5 → 3.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +253 -0
- package/ReadMe.md +81 -67
- package/dist/index.d.mts +419 -203
- package/dist/index.d.ts +419 -203
- package/dist/index.js +18 -18
- package/dist/index.mjs +17 -17
- package/dist/style.css +5 -1
- package/package.json +36 -35
- package/source/Avatar.tsx +65 -12
- package/source/Badge.tsx +34 -0
- package/source/Button.tsx +73 -0
- package/source/ButtonGroup.tsx +28 -0
- package/source/Card.tsx +26 -0
- package/source/ClickBoundary.tsx +6 -5
- package/source/CloseButton.tsx +23 -0
- package/source/CodeBlock.tsx +5 -3
- package/source/Countdown.tsx +2 -0
- package/source/Drawer.tsx +62 -0
- package/source/Editor.tsx +5 -8
- package/source/Grid.tsx +92 -0
- package/source/HorizontalMarquee/index.tsx +4 -10
- package/source/Image.tsx +15 -0
- package/source/ListGroup.tsx +103 -0
- package/source/LiveTSX.tsx +1 -1
- package/source/Loading.tsx +4 -3
- package/source/Menu.tsx +282 -0
- package/source/MonthCalendar.tsx +60 -22
- package/source/NativeDialog/index.tsx +139 -0
- package/source/NativeDialog/style.module.css +4 -0
- package/source/Nav.tsx +52 -0
- package/source/Navbar.tsx +64 -0
- package/source/Overlay.ts +22 -0
- package/source/OverlayBox.tsx +200 -32
- package/source/PageNav.tsx +56 -32
- package/source/Popover.tsx +36 -0
- package/source/ScrollNav/Scroller.tsx +107 -0
- package/source/ScrollNav/index.tsx +12 -99
- package/source/Select.tsx +66 -55
- package/source/ShareBox.tsx +5 -11
- package/source/Spinner.tsx +30 -0
- package/source/SpinnerButton.tsx +8 -10
- package/source/Table.tsx +59 -0
- package/source/TableSpinner.tsx +7 -5
- package/source/{TextTruncate.tsx → TextTruncate/Content.tsx} +24 -20
- package/source/TextTruncate/index.tsx +25 -0
- package/source/Time.tsx +7 -33
- package/source/TimeDistance.tsx +1 -1
- package/source/Timeline/index.tsx +7 -7
- package/source/Toast.tsx +114 -29
- package/source/ToggleButton.tsx +47 -0
- package/source/Tooltip.tsx +32 -0
- package/source/TypeEcho/Content.tsx +58 -0
- package/source/TypeEcho/index.tsx +14 -0
- package/source/UserRank/index.module.less +9 -20
- package/source/UserRank/index.tsx +35 -32
- package/source/VerticalMarquee/index.module.less +0 -1
- package/source/VerticalMarquee/index.tsx +3 -5
- package/source/ZodiacBar.tsx +1 -1
- package/source/animate.ts +4 -2
- package/source/color.ts +3 -5
- package/source/index.ts +18 -0
- package/source/types.d.ts +4 -0
- package/tsconfig.json +6 -2
- package/source/TypeEcho.tsx +0 -49
package/source/Menu.tsx
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { action, observable } from 'mobx';
|
|
5
|
+
import { observer } from 'mobx-react';
|
|
6
|
+
import {
|
|
7
|
+
Component,
|
|
8
|
+
createRef,
|
|
9
|
+
FC,
|
|
10
|
+
FocusEvent,
|
|
11
|
+
HTMLAttributes,
|
|
12
|
+
KeyboardEvent,
|
|
13
|
+
MouseEvent,
|
|
14
|
+
PropsWithChildren,
|
|
15
|
+
ReactNode
|
|
16
|
+
} from 'react';
|
|
17
|
+
|
|
18
|
+
import { Button, ButtonProps } from './Button';
|
|
19
|
+
|
|
20
|
+
export const MenuItem: FC<ButtonProps> = ({ className, ...props }) => (
|
|
21
|
+
<Button {...props} className={classNames('menu-item', className)} />
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export const MenuPanel: FC<HTMLAttributes<HTMLDivElement>> = ({ className, ...props }) => (
|
|
25
|
+
<div {...props} className={classNames('menu', className)} />
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export const MenuText: FC<HTMLAttributes<HTMLSpanElement>> = ({ className, ...props }) => (
|
|
29
|
+
<span {...props} className={classNames('menu-text', className)} />
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export const MenuHeader: FC<HTMLAttributes<HTMLHeadingElement>> = ({ className, ...props }) => (
|
|
33
|
+
<h6 {...props} className={classNames('menu-header', className)} />
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export const MenuDivider: FC<HTMLAttributes<HTMLHRElement>> = ({ className, ...props }) => (
|
|
37
|
+
<hr {...props} className={classNames('menu-divider', className)} />
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const MenuItemContent: FC<HTMLAttributes<HTMLSpanElement>> = ({ className, ...props }) => (
|
|
41
|
+
<span {...props} className={classNames('menu-item-content', className)} />
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
export const MenuItemDescription: FC<HTMLAttributes<HTMLElement>> = ({ className, ...props }) => (
|
|
45
|
+
<small {...props} className={classNames('menu-item-description', className)} />
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
export interface MenuSubmenuProps extends PropsWithChildren {
|
|
49
|
+
label: ReactNode;
|
|
50
|
+
className?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@observer
|
|
54
|
+
export class MenuSubmenu extends Component<MenuSubmenuProps> {
|
|
55
|
+
@observable accessor open = false;
|
|
56
|
+
|
|
57
|
+
panel = createRef<HTMLDivElement>();
|
|
58
|
+
|
|
59
|
+
@action
|
|
60
|
+
setOpen = (open: boolean) => {
|
|
61
|
+
this.open = open;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
handleClick = () => this.setOpen(!this.open);
|
|
65
|
+
|
|
66
|
+
handleMouseEnter = () => this.setOpen(true);
|
|
67
|
+
|
|
68
|
+
handleMouseLeave = () => this.setOpen(false);
|
|
69
|
+
|
|
70
|
+
handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
71
|
+
const { key } = event;
|
|
72
|
+
|
|
73
|
+
if (key === 'ArrowRight') {
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
this.setOpen(true);
|
|
76
|
+
|
|
77
|
+
queueMicrotask(() =>
|
|
78
|
+
this.panel.current
|
|
79
|
+
?.querySelector<HTMLElement>('a[href], button:not(:disabled)')
|
|
80
|
+
?.focus()
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
if (key === 'ArrowLeft' && this.open) {
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
this.setOpen(false);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
render() {
|
|
90
|
+
const { label, className, children } = this.props;
|
|
91
|
+
const { open } = this;
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<div
|
|
95
|
+
className={classNames('submenu', { show: open }, className)}
|
|
96
|
+
onMouseEnter={this.handleMouseEnter}
|
|
97
|
+
onMouseLeave={this.handleMouseLeave}
|
|
98
|
+
onKeyDown={this.handleKeyDown}
|
|
99
|
+
>
|
|
100
|
+
<Button
|
|
101
|
+
className="menu-item"
|
|
102
|
+
aria-haspopup="true"
|
|
103
|
+
aria-expanded={open}
|
|
104
|
+
onClick={this.handleClick}
|
|
105
|
+
>
|
|
106
|
+
{label}
|
|
107
|
+
</Button>
|
|
108
|
+
<div
|
|
109
|
+
ref={this.panel}
|
|
110
|
+
className={classNames('menu start-100 top-0', { show: open })}
|
|
111
|
+
hidden={!open}
|
|
112
|
+
>
|
|
113
|
+
{children}
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface MenuProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> {
|
|
121
|
+
label: ReactNode;
|
|
122
|
+
autoClose?: boolean | 'inside' | 'outside';
|
|
123
|
+
align?: 'start' | 'end';
|
|
124
|
+
menuClassName?: string;
|
|
125
|
+
toggleProps?: Omit<
|
|
126
|
+
Extract<ButtonProps, { href?: never }>,
|
|
127
|
+
'children' | 'onClick' | 'onKeyDown'
|
|
128
|
+
>;
|
|
129
|
+
onOpenChange?: (open: boolean) => void;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@observer
|
|
133
|
+
export class Menu extends Component<MenuProps> {
|
|
134
|
+
@observable accessor open = false;
|
|
135
|
+
root = createRef<HTMLDivElement>();
|
|
136
|
+
trigger = createRef<HTMLButtonElement>();
|
|
137
|
+
panel = createRef<HTMLDivElement>();
|
|
138
|
+
|
|
139
|
+
componentDidMount() {
|
|
140
|
+
document.addEventListener('pointerdown', this.handleOutside);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
componentWillUnmount() {
|
|
144
|
+
document.removeEventListener('pointerdown', this.handleOutside);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@action
|
|
148
|
+
setOpen = (open: boolean) => {
|
|
149
|
+
if (this.open === open) return;
|
|
150
|
+
this.open = open;
|
|
151
|
+
this.props.onOpenChange?.(open);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
handleOutside = ({ target }: PointerEvent) => {
|
|
155
|
+
const { autoClose = true } = this.props;
|
|
156
|
+
if (
|
|
157
|
+
autoClose !== false &&
|
|
158
|
+
autoClose !== 'inside' &&
|
|
159
|
+
target instanceof Node &&
|
|
160
|
+
!this.root.current?.contains(target)
|
|
161
|
+
)
|
|
162
|
+
this.setOpen(false);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
items() {
|
|
166
|
+
return [
|
|
167
|
+
...(this.panel.current?.querySelectorAll<HTMLElement>(
|
|
168
|
+
'a[href]:not([aria-disabled="true"]), button:not(:disabled):not([aria-disabled="true"])'
|
|
169
|
+
) ?? [])
|
|
170
|
+
].filter(item => !item.closest('[hidden]'));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
174
|
+
this.props.onKeyDown?.(event);
|
|
175
|
+
|
|
176
|
+
const { key, defaultPrevented } = event;
|
|
177
|
+
if (defaultPrevented) return;
|
|
178
|
+
|
|
179
|
+
if (key === 'Escape' && this.open) {
|
|
180
|
+
event.preventDefault();
|
|
181
|
+
this.setOpen(false);
|
|
182
|
+
return this.trigger.current?.focus();
|
|
183
|
+
}
|
|
184
|
+
if (key === 'Tab') return this.setOpen(false);
|
|
185
|
+
if (!['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(key)) return;
|
|
186
|
+
|
|
187
|
+
event.preventDefault();
|
|
188
|
+
this.setOpen(true);
|
|
189
|
+
|
|
190
|
+
queueMicrotask(() => {
|
|
191
|
+
const items = this.items();
|
|
192
|
+
const index = items.findIndex(item => item === document.activeElement);
|
|
193
|
+
|
|
194
|
+
let next = key === 'Home' ? 0 : items.length - 1;
|
|
195
|
+
|
|
196
|
+
if (key === 'ArrowDown') next = (index + 1) % items.length;
|
|
197
|
+
if (key === 'ArrowUp') next = index <= 0 ? items.length - 1 : index - 1;
|
|
198
|
+
items[next]?.focus();
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
handleBlur = (event: FocusEvent<HTMLDivElement>) => {
|
|
203
|
+
const { onBlur, autoClose = true } = this.props;
|
|
204
|
+
onBlur?.(event);
|
|
205
|
+
|
|
206
|
+
const { defaultPrevented, currentTarget, relatedTarget } = event;
|
|
207
|
+
if (
|
|
208
|
+
!defaultPrevented &&
|
|
209
|
+
autoClose !== false &&
|
|
210
|
+
autoClose !== 'inside' &&
|
|
211
|
+
!currentTarget.contains(relatedTarget)
|
|
212
|
+
)
|
|
213
|
+
this.setOpen(false);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
handleToggle = () => this.setOpen(!this.open);
|
|
217
|
+
|
|
218
|
+
handleSelect = ({ target }: MouseEvent<HTMLDivElement>) => {
|
|
219
|
+
const { autoClose = true } = this.props;
|
|
220
|
+
if (
|
|
221
|
+
autoClose &&
|
|
222
|
+
autoClose !== 'outside' &&
|
|
223
|
+
target instanceof Element &&
|
|
224
|
+
!target.closest('.submenu > .menu-item') &&
|
|
225
|
+
target.closest('a[href], button:not(:disabled)')
|
|
226
|
+
)
|
|
227
|
+
this.setOpen(false);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
render() {
|
|
231
|
+
const {
|
|
232
|
+
label,
|
|
233
|
+
autoClose: _autoClose,
|
|
234
|
+
align = 'end',
|
|
235
|
+
menuClassName,
|
|
236
|
+
toggleProps,
|
|
237
|
+
onOpenChange: _onOpenChange,
|
|
238
|
+
onKeyDown: _onKeyDown,
|
|
239
|
+
onBlur: _onBlur,
|
|
240
|
+
children,
|
|
241
|
+
className,
|
|
242
|
+
id,
|
|
243
|
+
...props
|
|
244
|
+
} = this.props;
|
|
245
|
+
const { open } = this;
|
|
246
|
+
|
|
247
|
+
return (
|
|
248
|
+
<div
|
|
249
|
+
{...props}
|
|
250
|
+
ref={this.root}
|
|
251
|
+
id={id}
|
|
252
|
+
className={classNames('d-inline-block position-relative', className)}
|
|
253
|
+
onKeyDown={this.handleKeyDown}
|
|
254
|
+
onBlur={this.handleBlur}
|
|
255
|
+
>
|
|
256
|
+
<Button
|
|
257
|
+
{...toggleProps}
|
|
258
|
+
ref={this.trigger}
|
|
259
|
+
aria-expanded={open}
|
|
260
|
+
aria-controls={id ? `${id}-menu` : undefined}
|
|
261
|
+
onClick={this.handleToggle}
|
|
262
|
+
>
|
|
263
|
+
{label}
|
|
264
|
+
</Button>
|
|
265
|
+
<div
|
|
266
|
+
ref={this.panel}
|
|
267
|
+
id={id ? `${id}-menu` : undefined}
|
|
268
|
+
className={classNames(
|
|
269
|
+
'menu top-100',
|
|
270
|
+
align === 'end' ? 'end-0' : 'start-0',
|
|
271
|
+
{ show: open },
|
|
272
|
+
menuClassName
|
|
273
|
+
)}
|
|
274
|
+
hidden={!open}
|
|
275
|
+
onClick={this.handleSelect}
|
|
276
|
+
>
|
|
277
|
+
{children}
|
|
278
|
+
</div>
|
|
279
|
+
</div>
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}
|
package/source/MonthCalendar.tsx
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
1
3
|
import classNames from 'classnames';
|
|
2
|
-
import { computed, observable } from 'mobx';
|
|
4
|
+
import { action, computed, observable } from 'mobx';
|
|
3
5
|
import { observer } from 'mobx-react';
|
|
4
6
|
import { ObservedComponent } from 'mobx-react-helper';
|
|
5
|
-
import { ReactNode } from 'react';
|
|
6
|
-
import { Badge, Button, ButtonProps, Table, TableProps } from 'react-bootstrap';
|
|
7
|
+
import { HTMLAttributes, MouseEvent, ReactNode } from 'react';
|
|
7
8
|
import { changeMonth, Day, formatDate, splitArray, TimeData } from 'web-utility';
|
|
8
9
|
|
|
10
|
+
import { Badge } from './Badge';
|
|
11
|
+
import { Button, type ComponentTheme } from './Button';
|
|
9
12
|
import { text2color } from './color';
|
|
10
13
|
import { OverlayBox } from './OverlayBox';
|
|
11
14
|
|
|
@@ -15,13 +18,15 @@ export interface DateData {
|
|
|
15
18
|
link?: string;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
|
-
export interface MonthCalendarProps
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
export interface MonthCalendarProps extends Omit<
|
|
22
|
+
HTMLAttributes<HTMLTableElement>,
|
|
23
|
+
'onChange' | 'onSelect'
|
|
24
|
+
> {
|
|
21
25
|
locale?: Navigator['language'];
|
|
26
|
+
theme?: ComponentTheme;
|
|
22
27
|
value?: DateData[];
|
|
23
|
-
onSelect?: (value: DateData) =>
|
|
24
|
-
onChange?: (date: Date) =>
|
|
28
|
+
onSelect?: (value: DateData) => unknown;
|
|
29
|
+
onChange?: (date: Date) => void;
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
/**
|
|
@@ -54,14 +59,34 @@ export class MonthCalendar extends ObservedComponent<MonthCalendarProps> {
|
|
|
54
59
|
return splitArray(dateList, 7);
|
|
55
60
|
}
|
|
56
61
|
|
|
62
|
+
@action
|
|
57
63
|
changeMonth(delta: number) {
|
|
58
64
|
this.currentDate = changeMonth(this.currentDate, delta);
|
|
59
65
|
|
|
60
66
|
this.props.onChange?.(this.currentDate);
|
|
61
67
|
}
|
|
62
68
|
|
|
69
|
+
changePreviousMonth = () => this.changeMonth(-1);
|
|
70
|
+
changeNextMonth = () => this.changeMonth(1);
|
|
71
|
+
|
|
72
|
+
handleCellClick = ({ target, currentTarget }: MouseEvent<HTMLTableCellElement>) => {
|
|
73
|
+
if (!(target instanceof Element)) return;
|
|
74
|
+
|
|
75
|
+
const targetItem = target.closest<HTMLElement>('[data-calendar-index]');
|
|
76
|
+
if (!targetItem || !currentTarget.contains(targetItem)) return;
|
|
77
|
+
|
|
78
|
+
const date = targetItem.dataset.calendarDate;
|
|
79
|
+
const index = Number(targetItem.dataset.calendarIndex);
|
|
80
|
+
const items = this.props.value?.filter(
|
|
81
|
+
({ date: itemDate }) => formatDate(itemDate, 'YYYY-MM-DD') === date
|
|
82
|
+
);
|
|
83
|
+
const item = items?.[index];
|
|
84
|
+
|
|
85
|
+
if (item) this.props.onSelect?.(item);
|
|
86
|
+
};
|
|
87
|
+
|
|
63
88
|
renderDate = (date: Date) => {
|
|
64
|
-
const {
|
|
89
|
+
const { value } = this.observedProps,
|
|
65
90
|
dateText = formatDate(date, 'YYYY-MM-DD');
|
|
66
91
|
const list = value?.filter(({ date }) => formatDate(date, 'YYYY-MM-DD') === dateText);
|
|
67
92
|
|
|
@@ -72,22 +97,23 @@ export class MonthCalendar extends ObservedComponent<MonthCalendarProps> {
|
|
|
72
97
|
'opacity-50': date.getMonth() !== this.currentDate.getMonth(),
|
|
73
98
|
'fw-bold': dateText === formatDate(new Date(), 'YYYY-MM-DD')
|
|
74
99
|
})}
|
|
100
|
+
onClick={this.handleCellClick}
|
|
75
101
|
>
|
|
76
102
|
<time className="d-block" dateTime={date.toJSON()}>
|
|
77
103
|
{date.getDate()}
|
|
78
104
|
</time>
|
|
79
105
|
|
|
80
|
-
{list?.map(item =>
|
|
106
|
+
{list?.map((item, index) =>
|
|
81
107
|
typeof item.content === 'object' ? (
|
|
82
108
|
item.content
|
|
83
109
|
) : (
|
|
84
|
-
<OverlayBox key={
|
|
110
|
+
<OverlayBox key={`${dateText}-${index}`} title={item.content}>
|
|
85
111
|
<Badge
|
|
86
|
-
as="a"
|
|
87
112
|
className="d-inline-block text-decoration-none w-100 text-truncate"
|
|
88
|
-
|
|
113
|
+
theme={text2color(item.content + '', ['light'])}
|
|
114
|
+
data-calendar-date={dateText}
|
|
115
|
+
data-calendar-index={index}
|
|
89
116
|
href={item.link}
|
|
90
|
-
onClick={() => onSelect?.(item)}
|
|
91
117
|
>
|
|
92
118
|
{item.content}
|
|
93
119
|
</Badge>
|
|
@@ -100,19 +126,30 @@ export class MonthCalendar extends ObservedComponent<MonthCalendarProps> {
|
|
|
100
126
|
|
|
101
127
|
render() {
|
|
102
128
|
const { weekFormatter, currentDate, dateGrid } = this,
|
|
103
|
-
{
|
|
129
|
+
{
|
|
130
|
+
className = '',
|
|
131
|
+
style,
|
|
132
|
+
theme = 'primary',
|
|
133
|
+
onChange: _onChange,
|
|
134
|
+
onSelect: _onSelect,
|
|
135
|
+
...props
|
|
136
|
+
} = this.observedProps;
|
|
104
137
|
|
|
105
138
|
return (
|
|
106
|
-
<
|
|
139
|
+
<table
|
|
140
|
+
{...props}
|
|
141
|
+
className={`table ${className}`}
|
|
142
|
+
style={{ tableLayout: 'fixed', ...style }}
|
|
143
|
+
>
|
|
107
144
|
<caption>
|
|
108
145
|
<div className="d-flex justify-content-between align-items-center">
|
|
109
|
-
<Button
|
|
146
|
+
<Button theme={theme} onClick={this.changePreviousMonth}>
|
|
110
147
|
<
|
|
111
148
|
</Button>
|
|
112
149
|
|
|
113
150
|
{formatDate(currentDate, 'YYYY-MM')}
|
|
114
151
|
|
|
115
|
-
<Button
|
|
152
|
+
<Button theme={theme} onClick={this.changeNextMonth}>
|
|
116
153
|
>
|
|
117
154
|
</Button>
|
|
118
155
|
</div>
|
|
@@ -120,13 +157,14 @@ export class MonthCalendar extends ObservedComponent<MonthCalendarProps> {
|
|
|
120
157
|
<thead>
|
|
121
158
|
<tr>
|
|
122
159
|
{dateGrid[0].map((date, index, { length }) => (
|
|
123
|
-
<
|
|
160
|
+
<th
|
|
124
161
|
key={index}
|
|
125
|
-
className={`
|
|
162
|
+
className={`theme-${theme} theme-contrast`}
|
|
126
163
|
style={{ width: `calc(100% / ${length})` }}
|
|
164
|
+
scope="col"
|
|
127
165
|
>
|
|
128
166
|
{weekFormatter.format(date)}
|
|
129
|
-
</
|
|
167
|
+
</th>
|
|
130
168
|
))}
|
|
131
169
|
</tr>
|
|
132
170
|
</thead>
|
|
@@ -135,7 +173,7 @@ export class MonthCalendar extends ObservedComponent<MonthCalendarProps> {
|
|
|
135
173
|
<tr key={days[0] + ''}>{days.map(this.renderDate)}</tr>
|
|
136
174
|
))}
|
|
137
175
|
</tbody>
|
|
138
|
-
</
|
|
176
|
+
</table>
|
|
139
177
|
);
|
|
140
178
|
}
|
|
141
179
|
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import {
|
|
5
|
+
Component,
|
|
6
|
+
ComponentPropsWithRef,
|
|
7
|
+
createRef,
|
|
8
|
+
DialogHTMLAttributes,
|
|
9
|
+
FC,
|
|
10
|
+
KeyboardEvent,
|
|
11
|
+
MouseEvent,
|
|
12
|
+
SyntheticEvent
|
|
13
|
+
} from 'react';
|
|
14
|
+
|
|
15
|
+
import styles from './style.module.css';
|
|
16
|
+
|
|
17
|
+
export interface NativeDialogProps extends Omit<DialogHTMLAttributes<HTMLDialogElement>, 'open'> {
|
|
18
|
+
modal?: boolean;
|
|
19
|
+
dialog?: boolean;
|
|
20
|
+
theme?: 'light' | 'dark';
|
|
21
|
+
keyboard?: boolean;
|
|
22
|
+
backdrop?: boolean | 'static';
|
|
23
|
+
open?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const DialogHeader: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
|
|
27
|
+
<div {...props} className={classNames('dialog-header', className)} />
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export const DialogTitle: FC<ComponentPropsWithRef<'h1'>> = ({ className, ...props }) => (
|
|
31
|
+
<h1 {...props} className={classNames('dialog-title', className)} />
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
export const DialogBody: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
|
|
35
|
+
<div {...props} className={classNames('dialog-body', className)} />
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
export const DialogFooter: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
|
|
39
|
+
<div {...props} className={classNames('dialog-footer', className)} />
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
export class NativeDialog extends Component<NativeDialogProps> {
|
|
43
|
+
element = createRef<HTMLDialogElement>();
|
|
44
|
+
returnFocus?: HTMLElement;
|
|
45
|
+
|
|
46
|
+
get open() {
|
|
47
|
+
return this.element.current?.open ?? false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
componentDidMount() {
|
|
51
|
+
if (this.props.open) this.show();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
componentDidUpdate({ open }: NativeDialogProps) {
|
|
55
|
+
if (this.props.open === open) return;
|
|
56
|
+
|
|
57
|
+
if (this.props.open) this.show();
|
|
58
|
+
else this.close();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
show = () => {
|
|
62
|
+
if (this.open) return;
|
|
63
|
+
const element = this.element.current;
|
|
64
|
+
if (!element) return;
|
|
65
|
+
if (document.activeElement instanceof HTMLElement)
|
|
66
|
+
this.returnFocus = document.activeElement;
|
|
67
|
+
if (this.props.modal === false) element.show();
|
|
68
|
+
else element.showModal();
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
close = () => {
|
|
72
|
+
if (!this.open) return;
|
|
73
|
+
this.element.current?.close();
|
|
74
|
+
this.returnFocus?.focus();
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
componentWillUnmount() {
|
|
78
|
+
this.close();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
handleCancel = (event: SyntheticEvent<HTMLDialogElement>) => {
|
|
82
|
+
const { onCancel, keyboard = true } = this.props;
|
|
83
|
+
onCancel?.(event);
|
|
84
|
+
const { defaultPrevented } = event;
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
if (keyboard && !defaultPrevented) this.close();
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
handleKeyDown = (event: KeyboardEvent<HTMLDialogElement>) => {
|
|
90
|
+
const { onKeyDown, keyboard = true } = this.props;
|
|
91
|
+
onKeyDown?.(event);
|
|
92
|
+
const { key, defaultPrevented } = event;
|
|
93
|
+
if (key !== 'Escape' || !keyboard || defaultPrevented) return;
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
this.close();
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
handleClick = (event: MouseEvent<HTMLDialogElement>) => {
|
|
99
|
+
const { onClick, backdrop = true } = this.props;
|
|
100
|
+
onClick?.(event);
|
|
101
|
+
const { defaultPrevented, target, currentTarget, clientX, clientY } = event;
|
|
102
|
+
if (backdrop !== true || defaultPrevented || target !== currentTarget) return;
|
|
103
|
+
const { left, right, top, bottom } = currentTarget.getBoundingClientRect();
|
|
104
|
+
if (clientX < left || clientX > right || clientY < top || clientY > bottom) this.close();
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
render() {
|
|
108
|
+
const {
|
|
109
|
+
open: _open,
|
|
110
|
+
modal: _modal,
|
|
111
|
+
keyboard: _keyboard,
|
|
112
|
+
backdrop = true,
|
|
113
|
+
theme,
|
|
114
|
+
dialog = true,
|
|
115
|
+
className,
|
|
116
|
+
onCancel: _onCancel,
|
|
117
|
+
onClick: _onClick,
|
|
118
|
+
onKeyDown: _onKeyDown,
|
|
119
|
+
...props
|
|
120
|
+
} = this.props;
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<dialog
|
|
124
|
+
{...props}
|
|
125
|
+
ref={this.element}
|
|
126
|
+
className={classNames(
|
|
127
|
+
dialog && 'dialog',
|
|
128
|
+
backdrop === false && styles.hiddenBackdrop,
|
|
129
|
+
className
|
|
130
|
+
)}
|
|
131
|
+
data-backdrop={backdrop === false ? 'false' : undefined}
|
|
132
|
+
data-bs-theme={theme}
|
|
133
|
+
onCancel={this.handleCancel}
|
|
134
|
+
onKeyDown={this.handleKeyDown}
|
|
135
|
+
onClick={this.handleClick}
|
|
136
|
+
/>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
package/source/Nav.tsx
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
|
+
|
|
4
|
+
export interface NavProps extends ComponentPropsWithRef<'nav'> {
|
|
5
|
+
variant?: 'tabs' | 'pills' | 'underline';
|
|
6
|
+
vertical?: boolean;
|
|
7
|
+
fill?: boolean;
|
|
8
|
+
justified?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const Nav: FC<NavProps> = ({ variant, vertical, fill, justified, className, ...props }) => (
|
|
12
|
+
<nav
|
|
13
|
+
{...props}
|
|
14
|
+
className={classNames(
|
|
15
|
+
'nav',
|
|
16
|
+
variant && `nav-${variant}`,
|
|
17
|
+
vertical && (variant === 'pills' ? 'nav-pills-vertical' : 'flex-column'),
|
|
18
|
+
{ 'nav-fill': fill, 'nav-justified': justified },
|
|
19
|
+
className
|
|
20
|
+
)}
|
|
21
|
+
/>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export const NavItem: FC<ComponentPropsWithRef<'li'>> = ({ className, ...props }) => (
|
|
25
|
+
<li {...props} className={classNames('nav-item', className)} />
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export interface NavLinkProps extends ComponentPropsWithRef<'a'> {
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const NavLink: FC<NavLinkProps> = ({
|
|
33
|
+
disabled,
|
|
34
|
+
className,
|
|
35
|
+
href,
|
|
36
|
+
onClick,
|
|
37
|
+
tabIndex,
|
|
38
|
+
...props
|
|
39
|
+
}) => (
|
|
40
|
+
<a
|
|
41
|
+
{...props}
|
|
42
|
+
href={disabled ? undefined : href}
|
|
43
|
+
tabIndex={disabled ? -1 : tabIndex}
|
|
44
|
+
aria-disabled={disabled || undefined}
|
|
45
|
+
className={classNames('nav-link', { disabled, 'pe-none': disabled }, className)}
|
|
46
|
+
onClick={disabled ? undefined : onClick}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
Nav.displayName = 'Nav';
|
|
51
|
+
NavItem.displayName = 'NavItem';
|
|
52
|
+
NavLink.displayName = 'NavLink';
|