idea-react 3.0.0-beta.1 → 3.0.0-beta.2
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 +9 -1
- package/ReadMe.md +34 -6
- package/dist/index.d.mts +270 -186
- package/dist/index.d.ts +270 -186
- package/dist/index.js +16 -16
- package/dist/index.mjs +15 -15
- package/dist/style.css +0 -3
- package/package.json +1 -1
- package/source/Accordion.tsx +61 -37
- package/source/Alert.tsx +30 -15
- package/source/Avatar.tsx +55 -50
- package/source/Badge.tsx +16 -16
- package/source/Breadcrumb.tsx +36 -22
- package/source/Button.tsx +63 -69
- package/source/ButtonGroup.tsx +21 -25
- package/source/Card.tsx +67 -59
- package/source/Carousel/index.tsx +22 -21
- package/source/CloseButton.tsx +20 -15
- package/source/Collapse.tsx +74 -19
- package/source/Drawer.tsx +40 -17
- package/source/Extension/ClickBoundary.tsx +24 -5
- package/source/Extension/CodeBlock.tsx +64 -0
- package/source/Extension/Countdown.tsx +21 -9
- package/source/Extension/Editor.tsx +53 -18
- package/source/Extension/EditorHTML.tsx +7 -3
- package/source/Extension/HorizontalMarquee/index.tsx +69 -45
- package/source/Extension/Icon.tsx +15 -14
- package/source/Extension/Loading.tsx +20 -17
- package/source/Extension/MonthCalendar.tsx +26 -10
- package/source/Extension/OverlayBox.tsx +28 -15
- package/source/Extension/PageNav.tsx +16 -7
- package/source/Extension/ScrollNav/Scroller.tsx +21 -5
- package/source/Extension/ScrollNav/index.tsx +32 -7
- package/source/Extension/Select.tsx +12 -11
- package/source/Extension/SpinnerButton.tsx +19 -24
- package/source/Extension/TableSpinner.tsx +10 -14
- package/source/Extension/TextTruncate/index.tsx +17 -13
- package/source/Extension/Time.tsx +7 -5
- package/source/Extension/TimeDistance.tsx +22 -18
- package/source/Extension/Timeline/index.tsx +37 -34
- package/source/Extension/TypeEcho/Content.tsx +79 -14
- package/source/Extension/TypeEcho/index.tsx +13 -5
- package/source/Extension/UserRank/Address.tsx +17 -15
- package/source/Extension/UserRank/index.tsx +79 -84
- package/source/Extension/VerticalMarquee/index.tsx +14 -16
- package/source/Extension/ZodiacBar.tsx +40 -32
- package/source/Form/Adorn.tsx +30 -32
- package/source/Form/Checkbox.tsx +9 -5
- package/source/Form/ChipInput.tsx +9 -5
- package/source/Form/Chips.tsx +41 -39
- package/source/Form/Combobox.tsx +80 -61
- package/source/Form/Control.tsx +53 -58
- package/source/Form/DatePicker.tsx +74 -65
- package/source/Form/Feedback.tsx +18 -19
- package/source/Form/FloatingLabel.tsx +16 -19
- package/source/Form/InputGroup.tsx +27 -26
- package/source/Form/OTP.tsx +30 -12
- package/source/Form/Primitives.tsx +47 -39
- package/source/Form/Radio.tsx +25 -22
- package/source/Form/Range.tsx +30 -12
- package/source/Form/Switch.tsx +43 -40
- package/source/Grid.tsx +67 -59
- package/source/Image.tsx +10 -6
- package/source/ListGroup.tsx +57 -69
- package/source/Menu.tsx +128 -66
- package/source/NativeDialog/index.tsx +51 -29
- package/source/Nav.tsx +46 -46
- package/source/NavOverflow/index.tsx +26 -10
- package/source/Navbar.tsx +60 -55
- package/source/Pagination.tsx +63 -69
- package/source/Placeholder.tsx +47 -43
- package/source/Polymorphic.ts +57 -0
- package/source/Popover.tsx +34 -31
- package/source/Progress/index.tsx +59 -54
- package/source/ScrollSpy/index.tsx +48 -33
- package/source/Spinner.tsx +27 -23
- package/source/Stack.tsx +25 -0
- package/source/Stepper.tsx +46 -40
- package/source/Tab.tsx +40 -27
- package/source/Table.tsx +53 -42
- package/source/Toast.tsx +62 -47
- package/source/ToggleButton.tsx +40 -37
- package/source/Toggler.tsx +17 -8
- package/source/Tooltip.tsx +31 -29
- package/source/index.ts +2 -0
- package/source/Extension/CodeBlock/index.tsx +0 -58
- package/source/Extension/CodeBlock/style.module.css +0 -3
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
2
|
|
|
3
3
|
import { Badge } from '../../Badge';
|
|
4
4
|
import { Col, Container, Row } from '../../Grid';
|
|
5
5
|
import { Image } from '../../Image';
|
|
6
|
+
import { polymorphic } from '../../Polymorphic';
|
|
6
7
|
import { Table } from '../../Table';
|
|
7
8
|
import { UserAddress, UserAddressProps } from './Address';
|
|
8
9
|
import * as style from './index.module.less';
|
|
@@ -20,92 +21,86 @@ export interface UserRankViewProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
20
21
|
linkOf?: (user: UserRank) => string;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
export const UserRankView
|
|
24
|
-
className = '',
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
...props
|
|
29
|
-
}) => {
|
|
30
|
-
const renderMedal = (user: UserRank) => (
|
|
31
|
-
<li key={user.id} className="col">
|
|
32
|
-
<div className={`shadow-lg overflow-hidden rounded-circle m-auto ${style.image}`}>
|
|
33
|
-
<Image src={user.avatar} alt={user.name} loading="lazy" fluid />
|
|
34
|
-
</div>
|
|
35
|
-
<div className={`position-relative overflow-hidden ${style.topUser}`}>
|
|
36
|
-
<div className="position-relative">
|
|
37
|
-
<i className="d-block overflow-hidden m-auto mb-1 rounded-circle" />
|
|
38
|
-
<a className="d-block mb-0 stretched-link" href={linkOf?.(user) || '#'}>
|
|
39
|
-
{user.name}
|
|
40
|
-
</a>
|
|
41
|
-
<strong>{user.score}</strong>
|
|
42
|
-
</div>
|
|
43
|
-
<UserAddress {...user} />
|
|
44
|
-
</div>
|
|
45
|
-
</li>
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const renderRow = (user: UserRank, index: number, { length }: UserRank[]) => (
|
|
49
|
-
<tr key={user.id} className="position-relative">
|
|
50
|
-
<td className="align-middle">
|
|
51
|
-
<Badge className="fw-bold fst-italic">
|
|
52
|
-
{(index + 4 + '').padStart((length + '').length, '0')}
|
|
53
|
-
</Badge>
|
|
54
|
-
</td>
|
|
55
|
-
<td className={`position-relative text-truncate ${style.name}`}>
|
|
56
|
-
<div
|
|
57
|
-
className={`d-inline-block overflow-hidden align-middle rounded-circle ${style.image}`}
|
|
58
|
-
>
|
|
24
|
+
export const UserRankView = polymorphic<UserRankViewProps>(
|
|
25
|
+
({ as: RootAs, className = '', title, rank = [], linkOf, ...props }) => {
|
|
26
|
+
const renderMedal = (user: UserRank) => (
|
|
27
|
+
<li key={user.id} className="col">
|
|
28
|
+
<div className={`shadow-lg overflow-hidden rounded-circle m-auto ${style.image}`}>
|
|
59
29
|
<Image src={user.avatar} alt={user.name} loading="lazy" fluid />
|
|
60
30
|
</div>
|
|
61
|
-
<
|
|
62
|
-
className="
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
{user.name}
|
|
69
|
-
</a>
|
|
70
|
-
</td>
|
|
71
|
-
<td className="align-middle">{user.score}</td>
|
|
72
|
-
<td className="align-middle">
|
|
73
|
-
<UserAddress {...user} />
|
|
74
|
-
</td>
|
|
75
|
-
</tr>
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
return (
|
|
79
|
-
<Container className={className} {...props}>
|
|
80
|
-
<Row className={style.rankBox}>
|
|
81
|
-
<Col span={12} lg={7}>
|
|
82
|
-
<div className={`shadow rounded-3 ${style.title}`}>
|
|
83
|
-
<div className={style.medal}>
|
|
84
|
-
<i className="d-inline-block ms-1 overflow-hidden rounded-circle" />
|
|
85
|
-
<i className="d-inline-block ms-1 overflow-hidden rounded-circle" />
|
|
86
|
-
<i className="d-inline-block ms-1 overflow-hidden rounded-circle" />
|
|
87
|
-
</div>
|
|
88
|
-
<h3
|
|
89
|
-
data-text={title}
|
|
90
|
-
className="position-relative m-auto mb-0 fw-bold text-center"
|
|
91
|
-
>
|
|
92
|
-
{title}
|
|
93
|
-
</h3>
|
|
31
|
+
<div className={`position-relative overflow-hidden ${style.topUser}`}>
|
|
32
|
+
<div className="position-relative">
|
|
33
|
+
<i className="d-block overflow-hidden m-auto mb-1 rounded-circle" />
|
|
34
|
+
<a className="d-block mb-0 stretched-link" href={linkOf?.(user) || '#'}>
|
|
35
|
+
{user.name}
|
|
36
|
+
</a>
|
|
37
|
+
<strong>{user.score}</strong>
|
|
94
38
|
</div>
|
|
95
|
-
<
|
|
96
|
-
|
|
39
|
+
<UserAddress {...user} />
|
|
40
|
+
</div>
|
|
41
|
+
</li>
|
|
42
|
+
);
|
|
43
|
+
const renderRow = (user: UserRank, index: number, { length }: UserRank[]) => (
|
|
44
|
+
<tr key={user.id} className="position-relative">
|
|
45
|
+
<td className="align-middle">
|
|
46
|
+
<Badge className="fw-bold fst-italic">
|
|
47
|
+
{(index + 4 + '').padStart((length + '').length, '0')}
|
|
48
|
+
</Badge>
|
|
49
|
+
</td>
|
|
50
|
+
<td className={`position-relative text-truncate ${style.name}`}>
|
|
51
|
+
<div
|
|
52
|
+
className={`d-inline-block overflow-hidden align-middle rounded-circle ${style.image}`}
|
|
53
|
+
>
|
|
54
|
+
<Image src={user.avatar} alt={user.name} loading="lazy" fluid />
|
|
55
|
+
</div>
|
|
56
|
+
<a
|
|
57
|
+
className="ms-2 d-inline-block align-middle stretched-link"
|
|
58
|
+
style={{
|
|
59
|
+
color: `rgb(248, ${(index + 2) * 15}, ${(index + 2) * 35})`
|
|
60
|
+
}}
|
|
61
|
+
href={linkOf?.(user) || '#'}
|
|
97
62
|
>
|
|
98
|
-
{
|
|
99
|
-
</
|
|
100
|
-
</
|
|
101
|
-
<
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
</Container>
|
|
108
|
-
);
|
|
109
|
-
};
|
|
63
|
+
{user.name}
|
|
64
|
+
</a>
|
|
65
|
+
</td>
|
|
66
|
+
<td className="align-middle">{user.score}</td>
|
|
67
|
+
<td className="align-middle">
|
|
68
|
+
<UserAddress {...user} />
|
|
69
|
+
</td>
|
|
70
|
+
</tr>
|
|
71
|
+
);
|
|
110
72
|
|
|
73
|
+
return (
|
|
74
|
+
<Container as={RootAs} className={className} {...props}>
|
|
75
|
+
<Row className={style.rankBox}>
|
|
76
|
+
<Col span={12} lg={7}>
|
|
77
|
+
<div className={`shadow rounded-3 ${style.title}`}>
|
|
78
|
+
<div className={style.medal}>
|
|
79
|
+
<i className="d-inline-block ms-1 overflow-hidden rounded-circle" />
|
|
80
|
+
<i className="d-inline-block ms-1 overflow-hidden rounded-circle" />
|
|
81
|
+
<i className="d-inline-block ms-1 overflow-hidden rounded-circle" />
|
|
82
|
+
</div>
|
|
83
|
+
<h3
|
|
84
|
+
data-text={title}
|
|
85
|
+
className="position-relative m-auto mb-0 fw-bold text-center"
|
|
86
|
+
>
|
|
87
|
+
{title}
|
|
88
|
+
</h3>
|
|
89
|
+
</div>
|
|
90
|
+
<ul
|
|
91
|
+
className={`row mt-2 g-0 align-items-end text-center ps-0 pt-2 list-unstyled ${style.topUsers}`}
|
|
92
|
+
>
|
|
93
|
+
{rank.slice(0, 3).map(renderMedal)}
|
|
94
|
+
</ul>
|
|
95
|
+
</Col>
|
|
96
|
+
<Col span={12} lg={5}>
|
|
97
|
+
<Table className={`my-3 pt-2 ${style.restUsers}`} responsive>
|
|
98
|
+
<tbody>{rank.slice(3, 10).map(renderRow)}</tbody>
|
|
99
|
+
</Table>
|
|
100
|
+
</Col>
|
|
101
|
+
</Row>
|
|
102
|
+
</Container>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
);
|
|
111
106
|
UserRankView.displayName = 'UserRankView';
|
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
2
|
|
|
3
|
+
import { polymorphic } from '../../Polymorphic';
|
|
3
4
|
import * as style from './index.module.less';
|
|
4
5
|
|
|
5
6
|
export interface VerticalMarqueeProps extends HTMLAttributes<HTMLDivElement> {
|
|
6
7
|
duration?: string;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export const VerticalMarquee
|
|
10
|
-
className = '',
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
<div className={`d-inline-block ${style.scrollItem}`}>{children}</div>
|
|
22
|
-
</div>
|
|
23
|
-
</div>
|
|
10
|
+
export const VerticalMarquee = polymorphic<VerticalMarqueeProps>(
|
|
11
|
+
({ as: Root = 'div', className = '', children, duration, ...props }) => (
|
|
12
|
+
<Root className={`overflow-hidden h-100 ${className}`} {...props}>
|
|
13
|
+
<div
|
|
14
|
+
className={`d-inline-block max-w-100 max-h-100 ${style.scrollWrap}`}
|
|
15
|
+
// @ts-expect-error remove after React 19 released
|
|
16
|
+
style={{ '--duration': duration }}
|
|
17
|
+
>
|
|
18
|
+
<div className={`d-inline-block ${style.scrollItem}`}>{children}</div>
|
|
19
|
+
</div>
|
|
20
|
+
</Root>
|
|
21
|
+
)
|
|
24
22
|
);
|
|
25
23
|
VerticalMarquee.displayName = 'VerticalMarquee';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import { polymorphic } from '../Polymorphic';
|
|
2
4
|
|
|
3
5
|
export const ZodiacSigns = ['🐵', '🐔', '🐶', '🐷', '🐭', '🐮', '🐯', '🐰', '🐲', '🐍', '🐴', '🐐'];
|
|
4
6
|
|
|
@@ -16,36 +18,42 @@ export interface ZodiacBarProps extends HTMLAttributes<HTMLOListElement> {
|
|
|
16
18
|
itemOf?: (year: number, zodiac: string) => { link?: string; title?: ReactNode };
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
export const ZodiacBar
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
21
|
+
export const ZodiacBar = polymorphic<ZodiacBarProps>(
|
|
22
|
+
({
|
|
23
|
+
as: Root = 'ol',
|
|
24
|
+
className = '',
|
|
25
|
+
itemClassName = 'border rounded px-4 py-3 d-flex flex-column justify-content-center align-items-center',
|
|
26
|
+
startYear,
|
|
27
|
+
endYear = new Date().getFullYear(),
|
|
28
|
+
itemOf,
|
|
29
|
+
...props
|
|
30
|
+
}) => (
|
|
31
|
+
<Root
|
|
32
|
+
className={`list-unstyled m-0 d-flex flex-wrap justify-content-center gap-3 ${className}`}
|
|
33
|
+
{...props}
|
|
34
|
+
>
|
|
35
|
+
{Array.from({ length: endYear - startYear + 1 }, (_, index) => {
|
|
36
|
+
const year = endYear - index;
|
|
37
|
+
|
|
38
|
+
if (year === 0) return null;
|
|
39
|
+
|
|
40
|
+
const zodiac = zodiacOf(year);
|
|
41
|
+
const { link = '#', title } = itemOf?.(year, zodiac) || {};
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<li key={year} className={itemClassName}>
|
|
45
|
+
<a
|
|
46
|
+
className="d-inline-block p-3 text-decoration-none text-center"
|
|
47
|
+
href={link}
|
|
48
|
+
>
|
|
49
|
+
<div className="fs-3xl">{zodiac}</div>
|
|
50
|
+
|
|
51
|
+
{title}
|
|
52
|
+
</a>
|
|
53
|
+
</li>
|
|
54
|
+
);
|
|
55
|
+
})}
|
|
56
|
+
</Root>
|
|
57
|
+
)
|
|
50
58
|
);
|
|
51
59
|
ZodiacBar.displayName = 'ZodiacBar';
|
package/source/Form/Adorn.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
|
-
import { ComponentPropsWithRef
|
|
2
|
+
import { ComponentPropsWithRef } from 'react';
|
|
3
3
|
|
|
4
4
|
import { Icon, IconProps } from '../Extension/Icon';
|
|
5
|
+
import { polymorphic } from '../Polymorphic';
|
|
5
6
|
import { FormValidationProps } from './Primitives';
|
|
6
7
|
|
|
7
8
|
export type FormAdornmentProps = Omit<ComponentPropsWithRef<'label'>, 'htmlFor'> &
|
|
@@ -11,49 +12,46 @@ export type FormAdornmentProps = Omit<ComponentPropsWithRef<'label'>, 'htmlFor'>
|
|
|
11
12
|
htmlFor?: string;
|
|
12
13
|
};
|
|
13
14
|
|
|
14
|
-
export const FormAdornment
|
|
15
|
-
className,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
validation && `is-${validation}`,
|
|
28
|
-
className
|
|
29
|
-
)}
|
|
30
|
-
/>
|
|
15
|
+
export const FormAdornment = polymorphic<FormAdornmentProps>(
|
|
16
|
+
({ as: Root = 'label', className, end, size, validation, ...props }) => (
|
|
17
|
+
<Root
|
|
18
|
+
{...props}
|
|
19
|
+
className={classNames(
|
|
20
|
+
'form-control form-adorn',
|
|
21
|
+
end && 'form-adorn-end',
|
|
22
|
+
size && `form-control-${size}`,
|
|
23
|
+
validation && `is-${validation}`,
|
|
24
|
+
className
|
|
25
|
+
)}
|
|
26
|
+
/>
|
|
27
|
+
)
|
|
31
28
|
);
|
|
32
|
-
|
|
33
29
|
FormAdornment.displayName = 'FormAdornment';
|
|
34
30
|
|
|
35
31
|
export type FormAdornmentTextProps = ComponentPropsWithRef<'span'>;
|
|
36
32
|
|
|
37
|
-
export const FormAdornmentText
|
|
38
|
-
|
|
33
|
+
export const FormAdornmentText = polymorphic<FormAdornmentTextProps>(
|
|
34
|
+
({ as: Root = 'span', className, ...props }) => (
|
|
35
|
+
<Root {...props} className={classNames('form-adorn-text', className)} />
|
|
36
|
+
)
|
|
39
37
|
);
|
|
40
|
-
|
|
41
38
|
FormAdornmentText.displayName = 'FormAdornmentText';
|
|
42
39
|
|
|
43
|
-
export const FormAdornmentIcon
|
|
44
|
-
<Icon {...props} className={classNames('form-adorn-icon', className)} />
|
|
45
|
-
);
|
|
40
|
+
export const FormAdornmentIcon = polymorphic<IconProps>(({ as: RootAs, className, ...props }) => (
|
|
41
|
+
<Icon as={RootAs} {...props} className={classNames('form-adorn-icon', className)} />
|
|
42
|
+
));
|
|
46
43
|
|
|
47
44
|
FormAdornmentIcon.displayName = 'FormAdornmentIcon';
|
|
48
45
|
|
|
49
46
|
export type FormGhostProps = ComponentPropsWithRef<'input'> & FormValidationProps;
|
|
50
47
|
|
|
51
|
-
export const FormGhost
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
export const FormGhost = polymorphic<FormGhostProps>(
|
|
49
|
+
({ as: Root = 'input', className, validation, ...props }) => (
|
|
50
|
+
<Root
|
|
51
|
+
{...props}
|
|
52
|
+
aria-invalid={validation ? validation === 'invalid' : props['aria-invalid']}
|
|
53
|
+
className={classNames('form-ghost', validation && `is-${validation}`, className)}
|
|
54
|
+
/>
|
|
55
|
+
)
|
|
57
56
|
);
|
|
58
|
-
|
|
59
57
|
FormGhost.displayName = 'FormGhost';
|
package/source/Form/Checkbox.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import classNames from 'classnames';
|
|
|
4
4
|
import { Component, ComponentPropsWithoutRef, forwardRef, Ref } from 'react';
|
|
5
5
|
|
|
6
6
|
import type { ComponentTheme } from '../Button';
|
|
7
|
+
import { AsProps, polymorphic } from '../Polymorphic';
|
|
7
8
|
import { FormValidationProps } from './Primitives';
|
|
8
9
|
|
|
9
10
|
export type CheckboxProps = Omit<ComponentPropsWithoutRef<'input'>, 'type' | 'size'> &
|
|
@@ -13,7 +14,7 @@ export type CheckboxProps = Omit<ComponentPropsWithoutRef<'input'>, 'type' | 'si
|
|
|
13
14
|
indeterminate?: boolean;
|
|
14
15
|
};
|
|
15
16
|
|
|
16
|
-
interface CheckboxComponentProps extends CheckboxProps {
|
|
17
|
+
interface CheckboxComponentProps extends CheckboxProps, AsProps {
|
|
17
18
|
forwardedRef?: Ref<HTMLInputElement>;
|
|
18
19
|
}
|
|
19
20
|
|
|
@@ -43,6 +44,7 @@ class CheckboxComponent extends Component<CheckboxComponentProps> {
|
|
|
43
44
|
|
|
44
45
|
render() {
|
|
45
46
|
const {
|
|
47
|
+
as: Root = 'input',
|
|
46
48
|
className,
|
|
47
49
|
size,
|
|
48
50
|
theme,
|
|
@@ -53,7 +55,7 @@ class CheckboxComponent extends Component<CheckboxComponentProps> {
|
|
|
53
55
|
} = this.props;
|
|
54
56
|
|
|
55
57
|
return (
|
|
56
|
-
<
|
|
58
|
+
<Root
|
|
57
59
|
{...props}
|
|
58
60
|
ref={this.setInputRef}
|
|
59
61
|
type="checkbox"
|
|
@@ -71,8 +73,10 @@ class CheckboxComponent extends Component<CheckboxComponentProps> {
|
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
export const Checkbox =
|
|
75
|
-
<
|
|
76
|
-
|
|
76
|
+
export const Checkbox = polymorphic<CheckboxProps & { ref?: Ref<HTMLInputElement> }>(
|
|
77
|
+
forwardRef<HTMLInputElement, CheckboxProps & AsProps>((props, forwardedRef) => (
|
|
78
|
+
<CheckboxComponent {...props} forwardedRef={forwardedRef} />
|
|
79
|
+
))
|
|
80
|
+
);
|
|
77
81
|
|
|
78
82
|
Checkbox.displayName = 'Checkbox';
|
|
@@ -7,6 +7,7 @@ import { renderToStaticMarkup } from 'react-dom/server';
|
|
|
7
7
|
|
|
8
8
|
import { ComponentTheme } from '../Button';
|
|
9
9
|
import { Icon } from '../Extension/Icon';
|
|
10
|
+
import { AsProps, polymorphic } from '../Polymorphic';
|
|
10
11
|
import { FormPlugin } from './Plugin';
|
|
11
12
|
import { FormValidationProps } from './Primitives';
|
|
12
13
|
|
|
@@ -22,7 +23,7 @@ export type ChipInputProps = ComponentPropsWithoutRef<'div'> &
|
|
|
22
23
|
onValuesChange?: (values: string[]) => unknown;
|
|
23
24
|
};
|
|
24
25
|
|
|
25
|
-
interface ChipInputComponentProps extends ChipInputProps {
|
|
26
|
+
interface ChipInputComponentProps extends ChipInputProps, AsProps {
|
|
26
27
|
forwardedRef?: Ref<HTMLDivElement>;
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -84,6 +85,7 @@ class ChipInputComponent extends FormPlugin<ChipInputComponentProps, Pick<Chips,
|
|
|
84
85
|
|
|
85
86
|
render() {
|
|
86
87
|
const {
|
|
88
|
+
as: Root = 'div',
|
|
87
89
|
className,
|
|
88
90
|
theme,
|
|
89
91
|
separator,
|
|
@@ -99,7 +101,7 @@ class ChipInputComponent extends FormPlugin<ChipInputComponentProps, Pick<Chips,
|
|
|
99
101
|
} = this.props;
|
|
100
102
|
|
|
101
103
|
return (
|
|
102
|
-
<
|
|
104
|
+
<Root
|
|
103
105
|
{...props}
|
|
104
106
|
ref={this.setRef}
|
|
105
107
|
className={classNames(
|
|
@@ -118,8 +120,10 @@ class ChipInputComponent extends FormPlugin<ChipInputComponentProps, Pick<Chips,
|
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
|
|
121
|
-
export const ChipInput =
|
|
122
|
-
<
|
|
123
|
-
|
|
123
|
+
export const ChipInput = polymorphic<ChipInputProps & { ref?: Ref<HTMLDivElement> }>(
|
|
124
|
+
forwardRef<HTMLDivElement, ChipInputProps & AsProps>((props, forwardedRef) => (
|
|
125
|
+
<ChipInputComponent {...props} forwardedRef={forwardedRef} />
|
|
126
|
+
))
|
|
127
|
+
);
|
|
124
128
|
|
|
125
129
|
ChipInput.displayName = 'ChipInput';
|
package/source/Form/Chips.tsx
CHANGED
|
@@ -1,69 +1,71 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
|
-
import { ComponentPropsWithRef
|
|
2
|
+
import { ComponentPropsWithRef } from 'react';
|
|
3
3
|
|
|
4
4
|
import { ComponentTheme } from '../Button';
|
|
5
5
|
import { Icon, IconProps } from '../Extension/Icon';
|
|
6
|
+
import { polymorphic } from '../Polymorphic';
|
|
6
7
|
|
|
7
8
|
export type ChipProps = ComponentPropsWithRef<'button'> & {
|
|
8
9
|
active?: boolean;
|
|
9
10
|
theme?: ComponentTheme;
|
|
10
11
|
};
|
|
11
12
|
|
|
12
|
-
export const Chip
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
export const Chip = polymorphic<ChipProps>(
|
|
14
|
+
({ as: Root = 'button', className, active, theme, ...props }) => (
|
|
15
|
+
<Root
|
|
16
|
+
{...props}
|
|
17
|
+
className={classNames('chip', { active }, theme && `theme-${theme}`, className)}
|
|
18
|
+
type="button"
|
|
19
|
+
aria-pressed={active}
|
|
20
|
+
/>
|
|
21
|
+
)
|
|
19
22
|
);
|
|
20
|
-
|
|
21
23
|
Chip.displayName = 'Chip';
|
|
22
24
|
|
|
23
|
-
export const ChipIcon
|
|
24
|
-
<Icon {...props} className={classNames('chip-icon', className)} />
|
|
25
|
-
);
|
|
25
|
+
export const ChipIcon = polymorphic<IconProps>(({ as: RootAs, className, ...props }) => (
|
|
26
|
+
<Icon as={RootAs} {...props} className={classNames('chip-icon', className)} />
|
|
27
|
+
));
|
|
26
28
|
|
|
27
29
|
ChipIcon.displayName = 'ChipIcon';
|
|
28
30
|
|
|
29
|
-
export const ChipImage
|
|
30
|
-
|
|
31
|
+
export const ChipImage = polymorphic<ComponentPropsWithRef<'img'>>(
|
|
32
|
+
({ as: Root = 'img', className, alt = '', ...props }) => (
|
|
33
|
+
<Root {...props} alt={alt} className={classNames('chip-img', className)} />
|
|
34
|
+
)
|
|
31
35
|
);
|
|
32
36
|
|
|
33
37
|
ChipImage.displayName = 'ChipImage';
|
|
34
38
|
|
|
35
|
-
export const ChipDismiss
|
|
36
|
-
className,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
>
|
|
47
|
-
{children ?? <Icon name="x-lg" aria-hidden="true" />}
|
|
48
|
-
</button>
|
|
39
|
+
export const ChipDismiss = polymorphic<ComponentPropsWithRef<'button'>>(
|
|
40
|
+
({ as: Root = 'button', className, children, 'aria-label': label = 'Remove', ...props }) => (
|
|
41
|
+
<Root
|
|
42
|
+
{...props}
|
|
43
|
+
type="button"
|
|
44
|
+
aria-label={label}
|
|
45
|
+
className={classNames('chip-dismiss', className)}
|
|
46
|
+
>
|
|
47
|
+
{children ?? <Icon name="x-lg" aria-hidden="true" />}
|
|
48
|
+
</Root>
|
|
49
|
+
)
|
|
49
50
|
);
|
|
50
|
-
|
|
51
51
|
ChipDismiss.displayName = 'ChipDismiss';
|
|
52
52
|
|
|
53
53
|
export type ChipTokenProps = ComponentPropsWithRef<'span'> & Pick<ChipProps, 'active' | 'theme'>;
|
|
54
54
|
|
|
55
|
-
export const ChipToken
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
export const ChipToken = polymorphic<ChipTokenProps>(
|
|
56
|
+
({ as: Root = 'span', className, active, theme, ...props }) => (
|
|
57
|
+
<Root
|
|
58
|
+
{...props}
|
|
59
|
+
tabIndex={props.tabIndex ?? 0}
|
|
60
|
+
className={classNames('chip', { active }, theme && `theme-${theme}`, className)}
|
|
61
|
+
/>
|
|
62
|
+
)
|
|
61
63
|
);
|
|
62
|
-
|
|
63
64
|
ChipToken.displayName = 'ChipToken';
|
|
64
65
|
|
|
65
|
-
export const ChipInputLabel
|
|
66
|
-
|
|
66
|
+
export const ChipInputLabel = polymorphic<ComponentPropsWithRef<'label'>>(
|
|
67
|
+
({ as: Root = 'label', className, ...props }) => (
|
|
68
|
+
<Root {...props} className={classNames('chip-input-label', className)} />
|
|
69
|
+
)
|
|
67
70
|
);
|
|
68
|
-
|
|
69
71
|
ChipInputLabel.displayName = 'ChipInputLabel';
|