idea-react 3.0.0-alpha.0 → 3.0.0-beta.0
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 +31 -10
- package/ReadMe.md +75 -41
- package/dist/index.d.mts +451 -100
- package/dist/index.d.ts +451 -100
- package/dist/index.js +16 -16
- package/dist/index.mjs +15 -15
- package/dist/style.css +5 -5
- package/package.json +7 -8
- package/source/Avatar.tsx +65 -12
- package/source/Button.tsx +13 -4
- package/source/ButtonGroup.tsx +28 -0
- package/source/Card.tsx +34 -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/Form/Adorn.tsx +38 -0
- package/source/Form/Checkbox.tsx +73 -0
- package/source/Form/Chips.tsx +51 -0
- package/source/Form/Combobox.tsx +109 -0
- package/source/Form/Control.tsx +59 -0
- package/source/Form/DatePicker.tsx +89 -0
- package/source/Form/Feedback.tsx +29 -0
- package/source/Form/FloatingLabel.tsx +15 -0
- package/source/Form/InputGroup.tsx +23 -0
- package/source/Form/OTP.tsx +48 -0
- package/source/Form/PasswordStrength.tsx +157 -0
- package/source/Form/Primitives.tsx +46 -0
- package/source/Form/Radio.tsx +51 -0
- package/source/Form/Range.tsx +65 -0
- package/source/Form/Switch.tsx +35 -0
- package/source/Form/index.ts +15 -0
- 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 +99 -1
- package/source/MonthCalendar.tsx +60 -22
- package/source/NativeDialog/index.tsx +37 -1
- package/source/Nav.tsx +52 -0
- package/source/Navbar.tsx +58 -1
- 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 +120 -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 +14 -0
- package/source/TypeEcho.tsx +0 -49
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
|
+
|
|
4
|
+
import type { ComponentTheme } from './Button';
|
|
5
|
+
import type { Breakpoint } from './Grid';
|
|
6
|
+
|
|
7
|
+
export type ListGroupHorizontal = boolean | Breakpoint;
|
|
8
|
+
|
|
9
|
+
export interface ListGroupProps extends ComponentPropsWithRef<'ul'> {
|
|
10
|
+
flush?: boolean;
|
|
11
|
+
numbered?: boolean;
|
|
12
|
+
horizontal?: ListGroupHorizontal;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const ListGroup: FC<ListGroupProps> = ({
|
|
16
|
+
flush,
|
|
17
|
+
numbered,
|
|
18
|
+
horizontal,
|
|
19
|
+
className,
|
|
20
|
+
...props
|
|
21
|
+
}) => (
|
|
22
|
+
<ul
|
|
23
|
+
{...props}
|
|
24
|
+
className={classNames(
|
|
25
|
+
'list-group',
|
|
26
|
+
{ 'list-group-flush': flush, 'list-group-numbered': numbered },
|
|
27
|
+
horizontal &&
|
|
28
|
+
(horizontal === true
|
|
29
|
+
? 'list-group-horizontal'
|
|
30
|
+
: `${horizontal}:list-group-horizontal`),
|
|
31
|
+
className
|
|
32
|
+
)}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
interface ListGroupItemStyleProps {
|
|
37
|
+
theme?: ComponentTheme;
|
|
38
|
+
action?: boolean;
|
|
39
|
+
active?: boolean;
|
|
40
|
+
disabled?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type ListGroupItemLinkAttributes = ComponentPropsWithRef<'a'> & { href: string };
|
|
44
|
+
type ListGroupItemButtonAttributes = ComponentPropsWithRef<'button'> & { href?: never };
|
|
45
|
+
type ListGroupItemAttributes = ComponentPropsWithRef<'li'> & { href?: never; type?: never };
|
|
46
|
+
type ListGroupItemElementAttributes =
|
|
47
|
+
ListGroupItemLinkAttributes | ListGroupItemButtonAttributes | ListGroupItemAttributes;
|
|
48
|
+
|
|
49
|
+
export type ListGroupItemProps = ListGroupItemStyleProps & ListGroupItemElementAttributes;
|
|
50
|
+
|
|
51
|
+
const isLink = (props: ListGroupItemElementAttributes): props is ListGroupItemLinkAttributes =>
|
|
52
|
+
typeof props.href === 'string';
|
|
53
|
+
|
|
54
|
+
const isButton = (props: ListGroupItemElementAttributes): props is ListGroupItemButtonAttributes =>
|
|
55
|
+
typeof props.type === 'string';
|
|
56
|
+
|
|
57
|
+
export const ListGroupItem: FC<ListGroupItemProps> = ({
|
|
58
|
+
theme,
|
|
59
|
+
action,
|
|
60
|
+
active,
|
|
61
|
+
disabled,
|
|
62
|
+
className,
|
|
63
|
+
...props
|
|
64
|
+
}) => {
|
|
65
|
+
const classes = classNames(
|
|
66
|
+
'list-group-item',
|
|
67
|
+
theme && `theme-${theme}`,
|
|
68
|
+
action && 'list-group-item-action',
|
|
69
|
+
{ active, disabled },
|
|
70
|
+
disabled && 'pe-none',
|
|
71
|
+
className
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
return isLink(props) ? (
|
|
75
|
+
<a
|
|
76
|
+
{...props}
|
|
77
|
+
className={classes}
|
|
78
|
+
href={disabled ? undefined : props.href}
|
|
79
|
+
aria-current={active ? 'true' : undefined}
|
|
80
|
+
aria-disabled={disabled || undefined}
|
|
81
|
+
tabIndex={disabled ? -1 : props.tabIndex}
|
|
82
|
+
onClick={disabled ? undefined : props.onClick}
|
|
83
|
+
/>
|
|
84
|
+
) : isButton(props) ? (
|
|
85
|
+
<button
|
|
86
|
+
{...props}
|
|
87
|
+
type={props.type || 'button'}
|
|
88
|
+
className={classes}
|
|
89
|
+
aria-current={active ? 'true' : undefined}
|
|
90
|
+
disabled={disabled}
|
|
91
|
+
/>
|
|
92
|
+
) : (
|
|
93
|
+
<li
|
|
94
|
+
{...(props as ListGroupItemAttributes)}
|
|
95
|
+
className={classes}
|
|
96
|
+
aria-current={active ? 'true' : undefined}
|
|
97
|
+
aria-disabled={disabled || undefined}
|
|
98
|
+
/>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
ListGroup.displayName = 'ListGroup';
|
|
103
|
+
ListGroupItem.displayName = 'ListGroupItem';
|
package/source/LiveTSX.tsx
CHANGED
|
@@ -12,7 +12,7 @@ export const LiveTSX: FC<LiveTSXProps> = ({ scope, children }) => {
|
|
|
12
12
|
<LiveProvider code={code} scope={scope} language="tsx">
|
|
13
13
|
<LivePreview className="mb-3" />
|
|
14
14
|
<LiveEditor />
|
|
15
|
-
<LiveError className="
|
|
15
|
+
<LiveError className="fg-danger small p-2" />
|
|
16
16
|
</LiveProvider>
|
|
17
17
|
);
|
|
18
18
|
};
|
package/source/Loading.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FC, HTMLAttributes } from 'react';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { Spinner } from './Spinner';
|
|
3
4
|
|
|
4
5
|
export type LoadingProps = HTMLAttributes<HTMLDivElement>;
|
|
5
6
|
|
|
@@ -12,9 +13,9 @@ export const Loading: FC<LoadingProps> = ({
|
|
|
12
13
|
className={`fixed-top h-100 w-100 d-flex justify-content-center align-items-center opacity-25 bg-black ${className}`}
|
|
13
14
|
{...props}
|
|
14
15
|
>
|
|
15
|
-
<Spinner
|
|
16
|
+
<Spinner theme="success" />
|
|
16
17
|
|
|
17
|
-
<span className="
|
|
18
|
+
<span className="ms-3 fg-white">{children}</span>
|
|
18
19
|
</div>
|
|
19
20
|
);
|
|
20
21
|
|
package/source/Menu.tsx
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
HTMLAttributes,
|
|
12
12
|
KeyboardEvent,
|
|
13
13
|
MouseEvent,
|
|
14
|
+
PropsWithChildren,
|
|
14
15
|
ReactNode
|
|
15
16
|
} from 'react';
|
|
16
17
|
|
|
@@ -20,6 +21,102 @@ export const MenuItem: FC<ButtonProps> = ({ className, ...props }) => (
|
|
|
20
21
|
<Button {...props} className={classNames('menu-item', className)} />
|
|
21
22
|
);
|
|
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
|
+
|
|
23
120
|
export interface MenuProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> {
|
|
24
121
|
label: ReactNode;
|
|
25
122
|
autoClose?: boolean | 'inside' | 'outside';
|
|
@@ -124,6 +221,7 @@ export class Menu extends Component<MenuProps> {
|
|
|
124
221
|
autoClose &&
|
|
125
222
|
autoClose !== 'outside' &&
|
|
126
223
|
target instanceof Element &&
|
|
224
|
+
!target.closest('.submenu > .menu-item') &&
|
|
127
225
|
target.closest('a[href], button:not(:disabled)')
|
|
128
226
|
)
|
|
129
227
|
this.setOpen(false);
|
|
@@ -151,7 +249,7 @@ export class Menu extends Component<MenuProps> {
|
|
|
151
249
|
{...props}
|
|
152
250
|
ref={this.root}
|
|
153
251
|
id={id}
|
|
154
|
-
className={classNames('position-relative', className)}
|
|
252
|
+
className={classNames('d-inline-block position-relative', className)}
|
|
155
253
|
onKeyDown={this.handleKeyDown}
|
|
156
254
|
onBlur={this.handleBlur}
|
|
157
255
|
>
|
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
|
}
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import {
|
|
5
5
|
Component,
|
|
6
|
+
ComponentPropsWithRef,
|
|
6
7
|
createRef,
|
|
7
8
|
DialogHTMLAttributes,
|
|
9
|
+
FC,
|
|
8
10
|
KeyboardEvent,
|
|
9
11
|
MouseEvent,
|
|
10
12
|
SyntheticEvent
|
|
@@ -14,10 +16,29 @@ import styles from './style.module.css';
|
|
|
14
16
|
|
|
15
17
|
export interface NativeDialogProps extends Omit<DialogHTMLAttributes<HTMLDialogElement>, 'open'> {
|
|
16
18
|
modal?: boolean;
|
|
19
|
+
dialog?: boolean;
|
|
20
|
+
theme?: 'light' | 'dark';
|
|
17
21
|
keyboard?: boolean;
|
|
18
22
|
backdrop?: boolean | 'static';
|
|
23
|
+
open?: boolean;
|
|
19
24
|
}
|
|
20
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
|
+
|
|
21
42
|
export class NativeDialog extends Component<NativeDialogProps> {
|
|
22
43
|
element = createRef<HTMLDialogElement>();
|
|
23
44
|
returnFocus?: HTMLElement;
|
|
@@ -26,6 +47,17 @@ export class NativeDialog extends Component<NativeDialogProps> {
|
|
|
26
47
|
return this.element.current?.open ?? false;
|
|
27
48
|
}
|
|
28
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
|
+
|
|
29
61
|
show = () => {
|
|
30
62
|
if (this.open) return;
|
|
31
63
|
const element = this.element.current;
|
|
@@ -74,9 +106,12 @@ export class NativeDialog extends Component<NativeDialogProps> {
|
|
|
74
106
|
|
|
75
107
|
render() {
|
|
76
108
|
const {
|
|
109
|
+
open: _open,
|
|
77
110
|
modal: _modal,
|
|
78
111
|
keyboard: _keyboard,
|
|
79
112
|
backdrop = true,
|
|
113
|
+
theme,
|
|
114
|
+
dialog = true,
|
|
80
115
|
className,
|
|
81
116
|
onCancel: _onCancel,
|
|
82
117
|
onClick: _onClick,
|
|
@@ -89,11 +124,12 @@ export class NativeDialog extends Component<NativeDialogProps> {
|
|
|
89
124
|
{...props}
|
|
90
125
|
ref={this.element}
|
|
91
126
|
className={classNames(
|
|
92
|
-
'dialog',
|
|
127
|
+
dialog && 'dialog',
|
|
93
128
|
backdrop === false && styles.hiddenBackdrop,
|
|
94
129
|
className
|
|
95
130
|
)}
|
|
96
131
|
data-backdrop={backdrop === false ? 'false' : undefined}
|
|
132
|
+
data-bs-theme={theme}
|
|
97
133
|
onCancel={this.handleCancel}
|
|
98
134
|
onKeyDown={this.handleKeyDown}
|
|
99
135
|
onClick={this.handleClick}
|
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';
|
package/source/Navbar.tsx
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
2
|
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
3
|
|
|
4
|
+
import { Button } from './Button';
|
|
5
|
+
|
|
4
6
|
export interface NavbarProps extends ComponentPropsWithRef<'nav'> {
|
|
7
|
+
theme?: 'light' | 'dark';
|
|
5
8
|
expand?: boolean | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
|
|
6
9
|
}
|
|
7
10
|
|
|
8
|
-
export const Navbar: FC<NavbarProps> = ({ expand, className, ...props }) => (
|
|
11
|
+
export const Navbar: FC<NavbarProps> = ({ expand, theme, className, ...props }) => (
|
|
9
12
|
<nav
|
|
10
13
|
{...props}
|
|
11
14
|
className={classNames(
|
|
@@ -13,5 +16,59 @@ export const Navbar: FC<NavbarProps> = ({ expand, className, ...props }) => (
|
|
|
13
16
|
expand && (expand === true ? 'navbar-expand' : `${expand}:navbar-expand`),
|
|
14
17
|
className
|
|
15
18
|
)}
|
|
19
|
+
data-bs-theme={theme}
|
|
16
20
|
/>
|
|
17
21
|
);
|
|
22
|
+
|
|
23
|
+
export type NavbarBrandProps =
|
|
24
|
+
(ComponentPropsWithRef<'a'> & { as?: 'a' }) | (ComponentPropsWithRef<'span'> & { as: 'span' });
|
|
25
|
+
|
|
26
|
+
export const NavbarBrand: FC<NavbarBrandProps> = props => {
|
|
27
|
+
if (props.as === 'span') {
|
|
28
|
+
const { as: _as, className, ...spanProps } = props;
|
|
29
|
+
|
|
30
|
+
return <span {...spanProps} className={classNames('navbar-brand', className)} />;
|
|
31
|
+
}
|
|
32
|
+
const { as: _as, className, ...anchorProps } = props;
|
|
33
|
+
|
|
34
|
+
return <a {...anchorProps} className={classNames('navbar-brand', className)} />;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const NavbarNav: FC<ComponentPropsWithRef<'ul'>> = ({ className, ...props }) => (
|
|
38
|
+
<ul {...props} className={classNames('navbar-nav', className)} />
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export const NavbarText: FC<ComponentPropsWithRef<'span'>> = ({ className, ...props }) => (
|
|
42
|
+
<span {...props} className={classNames('navbar-text', className)} />
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export interface NavbarTogglerProps extends Omit<
|
|
46
|
+
ComponentPropsWithRef<'button'>,
|
|
47
|
+
'children' | 'type'
|
|
48
|
+
> {
|
|
49
|
+
expanded?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const NavbarToggler: FC<NavbarTogglerProps> = ({
|
|
53
|
+
expanded,
|
|
54
|
+
className,
|
|
55
|
+
'aria-label': ariaLabel = 'Toggle navigation',
|
|
56
|
+
...props
|
|
57
|
+
}) => (
|
|
58
|
+
<Button
|
|
59
|
+
{...props}
|
|
60
|
+
type="button"
|
|
61
|
+
className={classNames('navbar-toggler', className)}
|
|
62
|
+
aria-label={ariaLabel}
|
|
63
|
+
aria-expanded={expanded}
|
|
64
|
+
icon
|
|
65
|
+
>
|
|
66
|
+
<span className="navbar-toggler-icon" aria-hidden="true" />
|
|
67
|
+
</Button>
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
Navbar.displayName = 'Navbar';
|
|
71
|
+
NavbarBrand.displayName = 'NavbarBrand';
|
|
72
|
+
NavbarNav.displayName = 'NavbarNav';
|
|
73
|
+
NavbarText.displayName = 'NavbarText';
|
|
74
|
+
NavbarToggler.displayName = 'NavbarToggler';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ComponentPropsWithRef } from 'react';
|
|
2
|
+
|
|
3
|
+
export type OverlayPlacement = 'top' | 'right' | 'bottom' | 'left';
|
|
4
|
+
|
|
5
|
+
export interface OverlayTriggerProps extends ComponentPropsWithRef<'div'> {
|
|
6
|
+
placement?: OverlayPlacement;
|
|
7
|
+
show?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const OVERLAY_DIRECTIONS: Record<OverlayPlacement, string> = {
|
|
11
|
+
top: 'top',
|
|
12
|
+
right: 'end',
|
|
13
|
+
bottom: 'bottom',
|
|
14
|
+
left: 'start'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const OVERLAY_ARROW_POSITIONS: Record<OverlayPlacement, string> = {
|
|
18
|
+
top: 'position-absolute start-50 translate-middle-x',
|
|
19
|
+
right: 'position-absolute top-50 translate-middle-y',
|
|
20
|
+
bottom: 'position-absolute start-50 translate-middle-x',
|
|
21
|
+
left: 'position-absolute top-50 translate-middle-y'
|
|
22
|
+
};
|