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.
- package/AGENTS.md +11 -2
- package/ReadMe.md +62 -49
- package/dist/DatePickerPlugin-CpGuQRsi.js +1 -0
- package/dist/DatePickerPlugin-DB3nnslN.mjs +1 -0
- package/dist/index.d.mts +1116 -442
- package/dist/index.d.ts +1116 -442
- package/dist/index.js +16 -16
- package/dist/index.mjs +15 -15
- package/dist/rolldown-runtime-5iZMYShA.js +1 -0
- package/dist/style.css +69 -66
- package/package.json +1 -1
- package/source/Accordion.tsx +137 -0
- package/source/Alert.tsx +138 -0
- package/source/Avatar.tsx +7 -1
- package/source/Badge.tsx +2 -0
- package/source/Breadcrumb.tsx +36 -0
- package/source/Button.tsx +40 -5
- package/source/ButtonGroup.tsx +10 -1
- package/source/Card.tsx +65 -4
- package/source/Carousel/index.tsx +391 -0
- package/source/Carousel/model.ts +113 -0
- package/source/Carousel/scroll.ts +79 -0
- package/source/Collapse.tsx +178 -0
- package/source/Drawer.tsx +127 -30
- package/source/{CodeBlock.tsx → Extension/CodeBlock/index.tsx} +23 -5
- package/source/Extension/CodeBlock/style.module.css +3 -0
- package/source/{Dialog.tsx → Extension/Dialog.tsx} +10 -6
- package/source/{EditorHTML.tsx → Extension/EditorHTML.tsx} +1 -1
- package/source/{HorizontalMarquee → Extension/HorizontalMarquee}/index.module.less +1 -3
- package/source/{Icon.tsx → Extension/Icon.tsx} +1 -7
- package/source/{Loading.tsx → Extension/Loading.tsx} +8 -3
- package/source/{MonthCalendar.tsx → Extension/MonthCalendar.tsx} +3 -3
- package/source/{Nameplate.tsx → Extension/Nameplate.tsx} +1 -1
- package/source/Extension/OverlayBox.tsx +280 -0
- package/source/{PageNav.tsx → Extension/PageNav.tsx} +27 -9
- package/source/{ScrollNav → Extension/ScrollNav}/index.tsx +1 -1
- package/source/Extension/Select.tsx +127 -0
- package/source/{ShareBox.tsx → Extension/ShareBox.tsx} +1 -1
- package/source/{SpinnerButton.tsx → Extension/SpinnerButton.tsx} +2 -2
- package/source/{TableSpinner.tsx → Extension/TableSpinner.tsx} +1 -1
- package/source/{Timeline → Extension/Timeline}/index.tsx +1 -1
- package/source/{UserRank → Extension/UserRank}/index.tsx +4 -4
- package/source/Extension/index.ts +27 -0
- package/source/Form/Adorn.tsx +32 -11
- package/source/Form/Checkbox.tsx +11 -6
- package/source/Form/ChipInput.tsx +125 -0
- package/source/Form/Chips.tsx +42 -24
- package/source/Form/Combobox.tsx +337 -72
- package/source/Form/Control.tsx +50 -15
- package/source/Form/DatePicker.tsx +231 -40
- package/source/Form/DatePickerPlugin.ts +37 -0
- package/source/Form/Feedback.tsx +10 -4
- package/source/Form/FloatingLabel.tsx +24 -7
- package/source/Form/InputGroup.tsx +155 -5
- package/source/Form/OTP.tsx +138 -45
- package/source/Form/PasswordStrength.tsx +43 -17
- package/source/Form/Plugin.tsx +53 -0
- package/source/Form/Primitives.tsx +51 -9
- package/source/Form/Radio.tsx +20 -28
- package/source/Form/Range.tsx +103 -52
- package/source/Form/Switch.tsx +30 -7
- package/source/Form/index.ts +1 -0
- package/source/Grid.tsx +4 -0
- package/source/ListGroup.tsx +28 -15
- package/source/Menu.tsx +226 -17
- package/source/NativeDialog/index.tsx +109 -5
- package/source/Nav.tsx +18 -2
- package/source/NavOverflow/index.tsx +307 -0
- package/source/NavOverflow/model.ts +21 -0
- package/source/Navbar.tsx +18 -3
- package/source/Overlay.ts +163 -1
- package/source/Pagination.tsx +92 -0
- package/source/Placeholder.tsx +66 -0
- package/source/Popover.tsx +7 -2
- package/source/Progress/index.tsx +76 -0
- package/source/Progress/style.module.css +15 -0
- package/source/ScrollSpy/index.tsx +365 -0
- package/source/ScrollSpy/model.ts +17 -0
- package/source/Spinner.tsx +10 -0
- package/source/Stepper.tsx +85 -0
- package/source/Tab.tsx +248 -0
- package/source/Toast.tsx +46 -14
- package/source/ToggleButton.tsx +21 -7
- package/source/Toggler.tsx +108 -0
- package/source/Tooltip.tsx +6 -1
- package/source/index.ts +15 -27
- package/source/OverlayBox.tsx +0 -208
- package/source/Select.tsx +0 -95
- /package/source/{ClickBoundary.tsx → Extension/ClickBoundary.tsx} +0 -0
- /package/source/{Countdown.tsx → Extension/Countdown.tsx} +0 -0
- /package/source/{Editor.tsx → Extension/Editor.tsx} +0 -0
- /package/source/{HorizontalMarquee → Extension/HorizontalMarquee}/index.tsx +0 -0
- /package/source/{LiveTSX.tsx → Extension/LiveTSX.tsx} +0 -0
- /package/source/{ScrollNav → Extension/ScrollNav}/Scroller.tsx +0 -0
- /package/source/{ScrollNav → Extension/ScrollNav}/index.module.less +0 -0
- /package/source/{TextTruncate → Extension/TextTruncate}/Content.tsx +0 -0
- /package/source/{TextTruncate → Extension/TextTruncate}/index.tsx +0 -0
- /package/source/{Time.tsx → Extension/Time.tsx} +0 -0
- /package/source/{TimeDistance.tsx → Extension/TimeDistance.tsx} +0 -0
- /package/source/{Timeline → Extension/Timeline}/index.module.less +0 -0
- /package/source/{TypeEcho → Extension/TypeEcho}/Content.tsx +0 -0
- /package/source/{TypeEcho → Extension/TypeEcho}/index.tsx +0 -0
- /package/source/{UserRank → Extension/UserRank}/Address.tsx +0 -0
- /package/source/{UserRank → Extension/UserRank}/index.module.less +0 -0
- /package/source/{VerticalMarquee → Extension/VerticalMarquee}/index.module.less +0 -0
- /package/source/{VerticalMarquee → Extension/VerticalMarquee}/index.tsx +0 -0
- /package/source/{ZodiacBar.tsx → Extension/ZodiacBar.tsx} +0 -0
package/source/Avatar.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
|
-
import { CSSProperties, FC, HTMLAttributes } from 'react';
|
|
2
|
+
import { ComponentPropsWithRef, CSSProperties, FC, HTMLAttributes } from 'react';
|
|
3
3
|
|
|
4
4
|
import type { ComponentTheme } from './Button';
|
|
5
5
|
|
|
@@ -66,6 +66,12 @@ export interface AvatarStackProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
66
66
|
size?: AvatarSize;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
export const AvatarImage: FC<ComponentPropsWithRef<'img'>> = ({ className, ...props }) => (
|
|
70
|
+
<img {...props} className={classNames('avatar-img', className)} />
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
AvatarImage.displayName = 'AvatarImage';
|
|
74
|
+
|
|
69
75
|
export const AvatarStack: FC<AvatarStackProps> = ({ className, size, children, ...props }) => (
|
|
70
76
|
<div
|
|
71
77
|
className={classNames('avatar-stack', size && `avatar-stack-${size}`, className)}
|
package/source/Badge.tsx
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
|
+
|
|
4
|
+
export const Breadcrumb: FC<ComponentPropsWithRef<'ol'>> = ({ className, ...props }) => (
|
|
5
|
+
<ol {...props} className={classNames('breadcrumb', className)} />
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
export const BreadcrumbItem: FC<ComponentPropsWithRef<'li'>> = props => (
|
|
9
|
+
<li {...props} className={classNames('breadcrumb-item', props.className)} />
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export interface BreadcrumbLinkProps extends ComponentPropsWithRef<'a'> {
|
|
13
|
+
active?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const BreadcrumbLink: FC<BreadcrumbLinkProps> = ({
|
|
17
|
+
active,
|
|
18
|
+
className,
|
|
19
|
+
'aria-current': current = active ? 'page' : undefined,
|
|
20
|
+
...props
|
|
21
|
+
}) => (
|
|
22
|
+
<a
|
|
23
|
+
{...props}
|
|
24
|
+
className={classNames('breadcrumb-link', { active }, className)}
|
|
25
|
+
aria-current={current}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export const BreadcrumbDivider: FC<ComponentPropsWithRef<'li'>> = ({ className, ...props }) => (
|
|
30
|
+
<li {...props} className={classNames('breadcrumb-divider', className)} aria-hidden="true" />
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
Breadcrumb.displayName = 'Breadcrumb';
|
|
34
|
+
BreadcrumbItem.displayName = 'BreadcrumbItem';
|
|
35
|
+
BreadcrumbLink.displayName = 'BreadcrumbLink';
|
|
36
|
+
BreadcrumbDivider.displayName = 'BreadcrumbDivider';
|
package/source/Button.tsx
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
1
|
import classNames from 'classnames';
|
|
4
2
|
import { ComponentPropsWithRef, FC, MouseEvent } from 'react';
|
|
5
3
|
|
|
@@ -16,12 +14,13 @@ export type ComponentTheme =
|
|
|
16
14
|
| 'inverse';
|
|
17
15
|
|
|
18
16
|
interface ButtonStyleProps {
|
|
19
|
-
variant?: 'solid' | 'outline' | 'subtle' | 'text' | 'link';
|
|
17
|
+
variant?: 'solid' | 'outline' | 'subtle' | 'text' | 'link' | false;
|
|
20
18
|
theme?: ComponentTheme;
|
|
21
19
|
size?: 'xs' | 'sm' | 'lg';
|
|
22
20
|
icon?: boolean;
|
|
23
21
|
styled?: boolean;
|
|
24
22
|
disabled?: boolean;
|
|
23
|
+
active?: boolean;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
type ButtonLinkAttributes = ComponentPropsWithRef<'a'> & { href: string };
|
|
@@ -41,15 +40,16 @@ export const Button: FC<ButtonProps> = ({
|
|
|
41
40
|
icon,
|
|
42
41
|
styled,
|
|
43
42
|
disabled,
|
|
43
|
+
active,
|
|
44
44
|
className,
|
|
45
45
|
...props
|
|
46
46
|
}) => {
|
|
47
47
|
const attributes: ButtonElementAttributes = props;
|
|
48
48
|
const classes = classNames(
|
|
49
|
-
variant ? `btn-${variant}` : icon ? undefined : 'btn',
|
|
49
|
+
variant === false ? undefined : variant ? `btn-${variant}` : icon ? undefined : 'btn',
|
|
50
50
|
theme && `theme-${theme}`,
|
|
51
51
|
size && `btn-${size}`,
|
|
52
|
-
{ 'btn-icon': icon, 'btn-styled': styled, disabled },
|
|
52
|
+
{ 'btn-icon': icon, 'btn-styled': styled, disabled, active },
|
|
53
53
|
className
|
|
54
54
|
);
|
|
55
55
|
|
|
@@ -59,6 +59,11 @@ export const Button: FC<ButtonProps> = ({
|
|
|
59
59
|
className={classes}
|
|
60
60
|
href={disabled ? undefined : attributes.href}
|
|
61
61
|
aria-disabled={disabled || undefined}
|
|
62
|
+
aria-pressed={
|
|
63
|
+
attributes.role === 'button'
|
|
64
|
+
? (active ?? attributes['aria-pressed'])
|
|
65
|
+
: attributes['aria-pressed']
|
|
66
|
+
}
|
|
62
67
|
tabIndex={disabled ? -1 : attributes.tabIndex}
|
|
63
68
|
onClick={disabled ? preventNavigation : attributes.onClick}
|
|
64
69
|
/>
|
|
@@ -68,6 +73,36 @@ export const Button: FC<ButtonProps> = ({
|
|
|
68
73
|
type={attributes.type || 'button'}
|
|
69
74
|
className={classes}
|
|
70
75
|
disabled={disabled}
|
|
76
|
+
aria-pressed={active ?? attributes['aria-pressed']}
|
|
71
77
|
/>
|
|
72
78
|
);
|
|
73
79
|
};
|
|
80
|
+
|
|
81
|
+
export type ButtonInputProps = Omit<ComponentPropsWithRef<'input'>, 'size'> & ButtonStyleProps;
|
|
82
|
+
|
|
83
|
+
export const ButtonInput: FC<ButtonInputProps> = ({
|
|
84
|
+
variant,
|
|
85
|
+
theme,
|
|
86
|
+
size,
|
|
87
|
+
icon,
|
|
88
|
+
styled,
|
|
89
|
+
active,
|
|
90
|
+
className,
|
|
91
|
+
type = 'button',
|
|
92
|
+
...props
|
|
93
|
+
}) => (
|
|
94
|
+
<input
|
|
95
|
+
{...props}
|
|
96
|
+
type={type}
|
|
97
|
+
className={classNames(
|
|
98
|
+
variant === false ? undefined : variant ? `btn-${variant}` : 'btn',
|
|
99
|
+
theme && `theme-${theme}`,
|
|
100
|
+
size && `btn-${size}`,
|
|
101
|
+
{ 'btn-icon': icon, 'btn-styled': styled, active },
|
|
102
|
+
className
|
|
103
|
+
)}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
Button.displayName = 'Button';
|
|
108
|
+
ButtonInput.displayName = 'ButtonInput';
|
package/source/ButtonGroup.tsx
CHANGED
|
@@ -3,10 +3,14 @@ import { ComponentPropsWithRef, FC } from 'react';
|
|
|
3
3
|
|
|
4
4
|
export interface ButtonGroupProps extends ComponentPropsWithRef<'div'> {
|
|
5
5
|
vertical?: boolean;
|
|
6
|
+
size?: 'xs' | 'sm' | 'lg';
|
|
7
|
+
divider?: boolean;
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
export const ButtonGroup: FC<ButtonGroupProps> = ({
|
|
9
11
|
vertical,
|
|
12
|
+
size,
|
|
13
|
+
divider,
|
|
10
14
|
role = 'group',
|
|
11
15
|
className,
|
|
12
16
|
...props
|
|
@@ -14,7 +18,12 @@ export const ButtonGroup: FC<ButtonGroupProps> = ({
|
|
|
14
18
|
<div
|
|
15
19
|
role={role}
|
|
16
20
|
{...props}
|
|
17
|
-
className={classNames(
|
|
21
|
+
className={classNames(
|
|
22
|
+
vertical ? 'btn-group-vertical' : 'btn-group',
|
|
23
|
+
size && `btn-group-${size}`,
|
|
24
|
+
divider && 'btn-group-divider',
|
|
25
|
+
className
|
|
26
|
+
)}
|
|
18
27
|
/>
|
|
19
28
|
);
|
|
20
29
|
ButtonGroup.displayName = 'ButtonGroup';
|
package/source/Card.tsx
CHANGED
|
@@ -1,8 +1,54 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
2
|
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { ComponentTheme } from './Button';
|
|
5
|
+
|
|
6
|
+
export interface CardProps extends ComponentPropsWithRef<'div'> {
|
|
7
|
+
row?: boolean;
|
|
8
|
+
body?: boolean;
|
|
9
|
+
theme?: ComponentTheme;
|
|
10
|
+
subtle?: boolean;
|
|
11
|
+
translucent?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const Card: FC<CardProps> = ({
|
|
15
|
+
row,
|
|
16
|
+
body,
|
|
17
|
+
theme,
|
|
18
|
+
subtle,
|
|
19
|
+
translucent,
|
|
20
|
+
className,
|
|
21
|
+
...props
|
|
22
|
+
}) => (
|
|
23
|
+
<div
|
|
24
|
+
{...props}
|
|
25
|
+
className={classNames(
|
|
26
|
+
'card',
|
|
27
|
+
{
|
|
28
|
+
'card-row': row,
|
|
29
|
+
'card-body': body,
|
|
30
|
+
'card-subtle': subtle,
|
|
31
|
+
'card-translucent': translucent
|
|
32
|
+
},
|
|
33
|
+
theme && `theme-${theme}`,
|
|
34
|
+
className
|
|
35
|
+
)}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export interface CardImageProps extends ComponentPropsWithRef<'img'> {
|
|
40
|
+
placement?: 'top' | 'bottom' | 'start' | 'end';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const CardImage: FC<CardImageProps> = ({ placement, className, ...props }) => (
|
|
44
|
+
<img
|
|
45
|
+
{...props}
|
|
46
|
+
className={classNames(placement ? `card-img-${placement}` : 'card-img', className)}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export const CardSubtitle: FC<ComponentPropsWithRef<'p'>> = ({ className, ...props }) => (
|
|
51
|
+
<p {...props} className={classNames('card-subtitle', className)} />
|
|
6
52
|
);
|
|
7
53
|
|
|
8
54
|
export const CardGroup: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
|
|
@@ -25,10 +71,25 @@ export const CardFooter: FC<ComponentPropsWithRef<'div'>> = ({ className, ...pro
|
|
|
25
71
|
<div {...props} className={classNames('card-footer', className)} />
|
|
26
72
|
);
|
|
27
73
|
|
|
28
|
-
export
|
|
29
|
-
|
|
74
|
+
export interface CardTitleProps extends ComponentPropsWithRef<'h4'> {
|
|
75
|
+
as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const CardTitle: FC<CardTitleProps> = ({ as: Tag = 'h4', className, ...props }) => (
|
|
79
|
+
<Tag {...props} className={classNames('card-title', className)} />
|
|
30
80
|
);
|
|
31
81
|
|
|
32
82
|
export const CardText: FC<ComponentPropsWithRef<'p'>> = ({ className, ...props }) => (
|
|
33
83
|
<p {...props} className={classNames('card-text', className)} />
|
|
34
84
|
);
|
|
85
|
+
|
|
86
|
+
Card.displayName = 'Card';
|
|
87
|
+
CardImage.displayName = 'CardImage';
|
|
88
|
+
CardSubtitle.displayName = 'CardSubtitle';
|
|
89
|
+
CardGroup.displayName = 'CardGroup';
|
|
90
|
+
CardImageOverlay.displayName = 'CardImageOverlay';
|
|
91
|
+
CardHeader.displayName = 'CardHeader';
|
|
92
|
+
CardBody.displayName = 'CardBody';
|
|
93
|
+
CardFooter.displayName = 'CardFooter';
|
|
94
|
+
CardTitle.displayName = 'CardTitle';
|
|
95
|
+
CardText.displayName = 'CardText';
|
|
@@ -0,0 +1,391 @@
|
|
|
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
|
+
FC,
|
|
13
|
+
isValidElement,
|
|
14
|
+
KeyboardEvent,
|
|
15
|
+
MouseEvent,
|
|
16
|
+
ReactNode
|
|
17
|
+
} from 'react';
|
|
18
|
+
|
|
19
|
+
import { Icon } from '../Extension/Icon';
|
|
20
|
+
import { CarouselEnds, CarouselModel } from './model';
|
|
21
|
+
import { CarouselScroll } from './scroll';
|
|
22
|
+
|
|
23
|
+
export interface CarouselSlideProps extends ComponentPropsWithRef<'div'> {
|
|
24
|
+
interval?: number;
|
|
25
|
+
active?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const CarouselSlide: FC<CarouselSlideProps> = ({
|
|
29
|
+
interval,
|
|
30
|
+
active,
|
|
31
|
+
className,
|
|
32
|
+
children,
|
|
33
|
+
...props
|
|
34
|
+
}) => (
|
|
35
|
+
<div
|
|
36
|
+
{...props}
|
|
37
|
+
className={classNames('carousel-item', { active }, className)}
|
|
38
|
+
data-bs-interval={interval}
|
|
39
|
+
>
|
|
40
|
+
{children}
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
CarouselSlide.displayName = 'CarouselSlide';
|
|
45
|
+
|
|
46
|
+
export interface CarouselProps extends Omit<ComponentPropsWithRef<'div'>, 'onChange'> {
|
|
47
|
+
autoplay?: boolean;
|
|
48
|
+
center?: boolean;
|
|
49
|
+
controls?: boolean;
|
|
50
|
+
controlsPlacement?: 'overlay' | 'top' | 'bottom';
|
|
51
|
+
dark?: boolean;
|
|
52
|
+
ends?: CarouselEnds;
|
|
53
|
+
fade?: boolean;
|
|
54
|
+
indicators?: boolean;
|
|
55
|
+
interval?: number;
|
|
56
|
+
items?: number;
|
|
57
|
+
itemsGap?: string | number;
|
|
58
|
+
itemsPeek?: string | number;
|
|
59
|
+
keyboard?: boolean;
|
|
60
|
+
onChange?: (index: number) => unknown;
|
|
61
|
+
pause?: boolean | 'hover';
|
|
62
|
+
playPause?: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@observer
|
|
66
|
+
export class Carousel extends Component<CarouselProps> {
|
|
67
|
+
static displayName = 'Carousel';
|
|
68
|
+
|
|
69
|
+
root = createRef<HTMLDivElement>();
|
|
70
|
+
|
|
71
|
+
track = createRef<HTMLDivElement>();
|
|
72
|
+
|
|
73
|
+
store = new CarouselModel(0, 'loop', () => 5000);
|
|
74
|
+
|
|
75
|
+
scroller = new CarouselScroll();
|
|
76
|
+
|
|
77
|
+
componentDidMount() {
|
|
78
|
+
this.updateStore();
|
|
79
|
+
if (this.props.autoplay) this.store.play();
|
|
80
|
+
|
|
81
|
+
document.addEventListener('visibilitychange', this.handleVisibilityChange);
|
|
82
|
+
this.track.current?.addEventListener('scroll', this.handleScroll, { passive: true });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
componentDidUpdate() {
|
|
86
|
+
this.updateStore();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
componentWillUnmount() {
|
|
90
|
+
this.store.dispose();
|
|
91
|
+
this.scroller.dispose();
|
|
92
|
+
|
|
93
|
+
document.removeEventListener('visibilitychange', this.handleVisibilityChange);
|
|
94
|
+
this.track.current?.removeEventListener('scroll', this.handleScroll);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private getSlides = () => Children.toArray(this.props.children);
|
|
98
|
+
|
|
99
|
+
private getSlideInterval = (index: number) => {
|
|
100
|
+
const slide = this.getSlides()[index];
|
|
101
|
+
const itemInterval = isValidElement<CarouselSlideProps>(slide)
|
|
102
|
+
? slide.props.interval
|
|
103
|
+
: undefined;
|
|
104
|
+
|
|
105
|
+
return itemInterval ?? this.props.interval ?? 5000;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
private updateStore = () => {
|
|
109
|
+
const slides = this.getSlides();
|
|
110
|
+
|
|
111
|
+
this.store.onChange = this.props.onChange;
|
|
112
|
+
this.store.onNavigate = this.scrollToActive;
|
|
113
|
+
this.store.update(slides.length, this.props.ends ?? 'loop', this.getSlideInterval);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
handleVisibilityChange = () => this.store.setVisible(!document.hidden);
|
|
117
|
+
|
|
118
|
+
handleMouseEnter = () => {
|
|
119
|
+
if (this.props.pause !== false) this.store.setHovering(true);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
handleMouseLeave = () => this.store.setHovering(false);
|
|
123
|
+
|
|
124
|
+
handleFocusCapture = () => {
|
|
125
|
+
if (this.props.pause !== false) this.store.setHovering(true);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
handleBlurCapture = ({ currentTarget, relatedTarget }: React.FocusEvent<HTMLDivElement>) => {
|
|
129
|
+
if (relatedTarget instanceof Node && currentTarget.contains(relatedTarget)) return;
|
|
130
|
+
|
|
131
|
+
this.store.setHovering(false);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
handleScroll = () => {
|
|
135
|
+
const track = this.track.current;
|
|
136
|
+
if (!track || this.scroller.looping) return;
|
|
137
|
+
|
|
138
|
+
const slides = [...track.children] as HTMLElement[];
|
|
139
|
+
const index = slides.reduce(
|
|
140
|
+
(closest, slide, candidate) =>
|
|
141
|
+
Math.abs(slide.offsetLeft - track.scrollLeft) <
|
|
142
|
+
Math.abs(slides[closest]?.offsetLeft - track.scrollLeft)
|
|
143
|
+
? candidate
|
|
144
|
+
: closest,
|
|
145
|
+
0
|
|
146
|
+
);
|
|
147
|
+
if (index !== this.store.activeIndex) this.store.setIndex(index, true, undefined, true);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
151
|
+
this.props.onKeyDown?.(event);
|
|
152
|
+
|
|
153
|
+
if (event.defaultPrevented || this.scroller.looping) return;
|
|
154
|
+
if (this.props.keyboard === false || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
155
|
+
if (
|
|
156
|
+
event.target instanceof HTMLElement &&
|
|
157
|
+
/^(INPUT|TEXTAREA|SELECT)$/.test(event.target.tagName)
|
|
158
|
+
)
|
|
159
|
+
return;
|
|
160
|
+
|
|
161
|
+
if (event.key === 'ArrowLeft') {
|
|
162
|
+
event.preventDefault();
|
|
163
|
+
this.store.previous(true);
|
|
164
|
+
} else if (event.key === 'ArrowRight') {
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
this.store.next(true);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
handleClick = (event: MouseEvent<HTMLDivElement>) => {
|
|
171
|
+
this.props.onClick?.(event);
|
|
172
|
+
if (event.defaultPrevented || this.scroller.looping) return;
|
|
173
|
+
|
|
174
|
+
const button =
|
|
175
|
+
event.target instanceof Element
|
|
176
|
+
? event.target.closest<HTMLButtonElement>('[data-carousel-action]')
|
|
177
|
+
: null;
|
|
178
|
+
const { carouselAction, index } = button?.dataset ?? {};
|
|
179
|
+
|
|
180
|
+
switch (carouselAction) {
|
|
181
|
+
case 'previous':
|
|
182
|
+
this.store.previous(true);
|
|
183
|
+
break;
|
|
184
|
+
case 'next':
|
|
185
|
+
this.store.next(true);
|
|
186
|
+
break;
|
|
187
|
+
case 'slide':
|
|
188
|
+
if (index !== undefined) this.store.setIndex(Number(index), true);
|
|
189
|
+
break;
|
|
190
|
+
case 'toggle':
|
|
191
|
+
this.store.toggle();
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
scrollToActive = (index: number, from: number, direction?: -1 | 1) => {
|
|
196
|
+
const track = this.track.current;
|
|
197
|
+
const root = this.root.current;
|
|
198
|
+
if (!track || !root) return;
|
|
199
|
+
|
|
200
|
+
this.scroller.dispose();
|
|
201
|
+
const slides = [...track.children] as HTMLElement[];
|
|
202
|
+
const destination = slides[index];
|
|
203
|
+
if (!destination) return;
|
|
204
|
+
|
|
205
|
+
const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
206
|
+
const styles = getComputedStyle(root);
|
|
207
|
+
const items = Number.parseFloat(styles.getPropertyValue('--bs-carousel-items')) || 1;
|
|
208
|
+
const peek = Number.parseFloat(styles.getPropertyValue('--bs-carousel-items-peek')) || 0;
|
|
209
|
+
const variableWidth = slides.some(slide => slide.style.width || slide.style.flexBasis);
|
|
210
|
+
const crossingEnd =
|
|
211
|
+
(direction === 1 && index === 0 && from === slides.length - 1) ||
|
|
212
|
+
(direction === -1 && from === 0 && index === slides.length - 1);
|
|
213
|
+
const canLoop =
|
|
214
|
+
(this.props.ends ?? 'loop') === 'loop' &&
|
|
215
|
+
!this.props.fade &&
|
|
216
|
+
!reducedMotion &&
|
|
217
|
+
items === 1 &&
|
|
218
|
+
peek === 0 &&
|
|
219
|
+
!this.props.center &&
|
|
220
|
+
!variableWidth;
|
|
221
|
+
|
|
222
|
+
if (crossingEnd && canLoop)
|
|
223
|
+
this.scroller.loop(track, slides[from], destination, direction === 1);
|
|
224
|
+
else this.scroller.navigate(track, destination.offsetLeft, !crossingEnd && !reducedMotion);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
renderSlide = (slide: ReactNode, index: number) => {
|
|
228
|
+
const active = this.store.activeIndex === index;
|
|
229
|
+
|
|
230
|
+
return isValidElement<CarouselSlideProps>(slide) && typeof slide.type !== 'string' ? (
|
|
231
|
+
cloneElement(slide, { active, 'aria-hidden': !active })
|
|
232
|
+
) : (
|
|
233
|
+
<CarouselSlide key={index} active={active} aria-hidden={!active}>
|
|
234
|
+
{slide}
|
|
235
|
+
</CarouselSlide>
|
|
236
|
+
);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
renderControls = () => {
|
|
240
|
+
const { controls = true, ends = 'loop' } = this.props;
|
|
241
|
+
if (!controls) return null;
|
|
242
|
+
|
|
243
|
+
const atStart = this.store.activeIndex === 0;
|
|
244
|
+
const atEnd = this.store.activeIndex === this.getSlides().length - 1;
|
|
245
|
+
const buttonClass =
|
|
246
|
+
this.props.controlsPlacement === 'overlay'
|
|
247
|
+
? 'carousel-control-prev'
|
|
248
|
+
: 'btn btn-subtle theme-secondary';
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<>
|
|
252
|
+
<button
|
|
253
|
+
type="button"
|
|
254
|
+
className={buttonClass}
|
|
255
|
+
data-carousel-action="previous"
|
|
256
|
+
aria-label="Previous"
|
|
257
|
+
disabled={ends === 'stop' && atStart}
|
|
258
|
+
>
|
|
259
|
+
<Icon name="chevron-left" aria-hidden="true" />
|
|
260
|
+
<span className="visually-hidden">Previous</span>
|
|
261
|
+
</button>
|
|
262
|
+
<button
|
|
263
|
+
type="button"
|
|
264
|
+
className={
|
|
265
|
+
this.props.controlsPlacement === 'overlay'
|
|
266
|
+
? 'carousel-control-next'
|
|
267
|
+
: 'btn btn-subtle theme-secondary'
|
|
268
|
+
}
|
|
269
|
+
data-carousel-action="next"
|
|
270
|
+
aria-label="Next"
|
|
271
|
+
disabled={ends === 'stop' && atEnd}
|
|
272
|
+
>
|
|
273
|
+
<Icon name="chevron-right" aria-hidden="true" />
|
|
274
|
+
<span className="visually-hidden">Next</span>
|
|
275
|
+
</button>
|
|
276
|
+
</>
|
|
277
|
+
);
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
renderIndicators = () =>
|
|
281
|
+
this.props.indicators && this.getSlides().length > 1 ? (
|
|
282
|
+
<div className="carousel-indicators">
|
|
283
|
+
{this.getSlides().map((_, index) => (
|
|
284
|
+
<button
|
|
285
|
+
key={index}
|
|
286
|
+
type="button"
|
|
287
|
+
data-carousel-action="slide"
|
|
288
|
+
data-index={index}
|
|
289
|
+
aria-label={`Slide ${index + 1}`}
|
|
290
|
+
aria-current={this.store.activeIndex === index ? 'true' : undefined}
|
|
291
|
+
className={classNames({ active: this.store.activeIndex === index })}
|
|
292
|
+
/>
|
|
293
|
+
))}
|
|
294
|
+
</div>
|
|
295
|
+
) : null;
|
|
296
|
+
|
|
297
|
+
renderPlayPause = () =>
|
|
298
|
+
(this.props.playPause || this.props.autoplay) && (
|
|
299
|
+
<button
|
|
300
|
+
type="button"
|
|
301
|
+
className="btn-icon btn-sm carousel-control-play-pause"
|
|
302
|
+
data-carousel-action="toggle"
|
|
303
|
+
aria-label={this.store.playing ? 'Pause' : 'Play'}
|
|
304
|
+
>
|
|
305
|
+
<Icon name={this.store.playing ? 'pause-fill' : 'play-fill'} aria-hidden="true" />
|
|
306
|
+
</button>
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
render() {
|
|
310
|
+
const slides = this.getSlides();
|
|
311
|
+
const {
|
|
312
|
+
autoplay: _autoplay,
|
|
313
|
+
center,
|
|
314
|
+
children: _children,
|
|
315
|
+
className,
|
|
316
|
+
controls: _controls,
|
|
317
|
+
controlsPlacement = 'overlay',
|
|
318
|
+
dark,
|
|
319
|
+
ends: _ends,
|
|
320
|
+
fade: _fade,
|
|
321
|
+
fade,
|
|
322
|
+
indicators: _indicators,
|
|
323
|
+
interval: _interval,
|
|
324
|
+
items,
|
|
325
|
+
itemsGap,
|
|
326
|
+
itemsPeek,
|
|
327
|
+
keyboard: _keyboard,
|
|
328
|
+
onChange: _onChange,
|
|
329
|
+
onClick: _onClick,
|
|
330
|
+
pause: _pause,
|
|
331
|
+
playPause: _playPause,
|
|
332
|
+
style,
|
|
333
|
+
...props
|
|
334
|
+
} = this.props;
|
|
335
|
+
const placement = controlsPlacement === 'overlay';
|
|
336
|
+
const styleWithItems = {
|
|
337
|
+
...style,
|
|
338
|
+
...(items && { '--bs-carousel-items': items }),
|
|
339
|
+
...(itemsGap !== undefined && { '--bs-carousel-items-gap': itemsGap }),
|
|
340
|
+
...(itemsPeek !== undefined && { '--bs-carousel-items-peek': itemsPeek })
|
|
341
|
+
} as CSSProperties;
|
|
342
|
+
const outerControls = (
|
|
343
|
+
<div className="d-flex justify-content-between align-items-center gap-2">
|
|
344
|
+
{this.renderIndicators()}
|
|
345
|
+
<div className="d-flex align-items-center gap-2">
|
|
346
|
+
{this.renderPlayPause()}
|
|
347
|
+
{this.renderControls()}
|
|
348
|
+
</div>
|
|
349
|
+
</div>
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
return (
|
|
353
|
+
<div
|
|
354
|
+
{...props}
|
|
355
|
+
ref={this.root}
|
|
356
|
+
className={classNames(
|
|
357
|
+
'carousel',
|
|
358
|
+
{ 'carousel-fade': fade, 'carousel-dark': dark, 'carousel-center': center },
|
|
359
|
+
className
|
|
360
|
+
)}
|
|
361
|
+
style={styleWithItems}
|
|
362
|
+
role="region"
|
|
363
|
+
aria-label={this.props['aria-label'] ?? 'Carousel'}
|
|
364
|
+
aria-roledescription="carousel"
|
|
365
|
+
onClick={this.handleClick}
|
|
366
|
+
onKeyDown={this.handleKeyDown}
|
|
367
|
+
onMouseEnter={this.handleMouseEnter}
|
|
368
|
+
onMouseLeave={this.handleMouseLeave}
|
|
369
|
+
onFocusCapture={this.handleFocusCapture}
|
|
370
|
+
onBlurCapture={this.handleBlurCapture}
|
|
371
|
+
>
|
|
372
|
+
{controlsPlacement === 'top' && outerControls}
|
|
373
|
+
<div
|
|
374
|
+
ref={this.track}
|
|
375
|
+
className="carousel-inner"
|
|
376
|
+
tabIndex={0}
|
|
377
|
+
aria-label={this.props['aria-label'] ?? 'Carousel slides'}
|
|
378
|
+
onScroll={this.handleScroll}
|
|
379
|
+
>
|
|
380
|
+
{slides.map(this.renderSlide)}
|
|
381
|
+
</div>
|
|
382
|
+
{placement && this.renderControls()}
|
|
383
|
+
{controlsPlacement === 'bottom' && outerControls}
|
|
384
|
+
{placement &&
|
|
385
|
+
(this.props.playPause || this.props.autoplay) &&
|
|
386
|
+
this.renderPlayPause()}
|
|
387
|
+
{placement && this.renderIndicators()}
|
|
388
|
+
</div>
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
}
|