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
package/source/Card.tsx
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
|
+
|
|
4
|
+
export const Card: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
|
|
5
|
+
<div {...props} className={classNames('card', className)} />
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
export const CardGroup: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
|
|
9
|
+
<div {...props} className={classNames('card-group', className)} />
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export const CardImageOverlay: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
|
|
13
|
+
<div {...props} className={classNames('card-img-overlay', className)} />
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export const CardHeader: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
|
|
17
|
+
<div {...props} className={classNames('card-header', className)} />
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export const CardBody: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
|
|
21
|
+
<div {...props} className={classNames('card-body', className)} />
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export const CardFooter: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
|
|
25
|
+
<div {...props} className={classNames('card-footer', className)} />
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export const CardTitle: FC<ComponentPropsWithRef<'h3'>> = ({ className, ...props }) => (
|
|
29
|
+
<h3 {...props} className={classNames('card-title', className)} />
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export const CardText: FC<ComponentPropsWithRef<'p'>> = ({ className, ...props }) => (
|
|
33
|
+
<p {...props} className={classNames('card-text', className)} />
|
|
34
|
+
);
|
package/source/ClickBoundary.tsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
createRef,
|
|
3
5
|
DetailedHTMLProps,
|
|
@@ -8,8 +10,8 @@ import {
|
|
|
8
10
|
|
|
9
11
|
export type ClickBoundaryProps = PropsWithChildren<
|
|
10
12
|
{
|
|
11
|
-
onInnerClick?: (event: MouseEvent) =>
|
|
12
|
-
onOuterClick?: (event: MouseEvent) =>
|
|
13
|
+
onInnerClick?: (event: MouseEvent) => unknown;
|
|
14
|
+
onOuterClick?: (event: MouseEvent) => unknown;
|
|
13
15
|
} & DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
|
|
14
16
|
>;
|
|
15
17
|
|
|
@@ -19,8 +21,7 @@ export class ClickBoundary extends PureComponent<ClickBoundaryProps> {
|
|
|
19
21
|
switchClick = (event: MouseEvent) => {
|
|
20
22
|
const { onInnerClick, onOuterClick } = this.props;
|
|
21
23
|
|
|
22
|
-
if (this.root.current?.contains(event.target as Node))
|
|
23
|
-
onInnerClick?.(event);
|
|
24
|
+
if (this.root.current?.contains(event.target as Node)) onInnerClick?.(event);
|
|
24
25
|
else onOuterClick?.(event);
|
|
25
26
|
};
|
|
26
27
|
|
|
@@ -33,7 +34,7 @@ export class ClickBoundary extends PureComponent<ClickBoundaryProps> {
|
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
render() {
|
|
36
|
-
const { children, onInnerClick, onOuterClick, ...props } = this.props;
|
|
37
|
+
const { children, onInnerClick: _, onOuterClick: __, ...props } = this.props;
|
|
37
38
|
|
|
38
39
|
return (
|
|
39
40
|
<div ref={this.root} {...props}>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
|
+
|
|
4
|
+
export interface CloseButtonProps extends ComponentPropsWithRef<'button'> {
|
|
5
|
+
dismiss?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const CloseButton: FC<CloseButtonProps> = ({
|
|
9
|
+
dismiss,
|
|
10
|
+
className,
|
|
11
|
+
type = 'button',
|
|
12
|
+
'aria-label': ariaLabel = 'Close',
|
|
13
|
+
...props
|
|
14
|
+
}) => (
|
|
15
|
+
<button
|
|
16
|
+
{...props}
|
|
17
|
+
type={type}
|
|
18
|
+
className={classNames('btn-close', className)}
|
|
19
|
+
data-bs-dismiss={dismiss}
|
|
20
|
+
aria-label={ariaLabel}
|
|
21
|
+
/>
|
|
22
|
+
);
|
|
23
|
+
CloseButton.displayName = 'CloseButton';
|
package/source/CodeBlock.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import js from '@shikijs/langs/javascript';
|
|
|
2
2
|
import jsx from '@shikijs/langs/jsx';
|
|
3
3
|
import tsx from '@shikijs/langs/tsx';
|
|
4
4
|
import ts from '@shikijs/langs/typescript';
|
|
5
|
+
import githubDark from '@shikijs/themes/github-dark';
|
|
5
6
|
import githubLight from '@shikijs/themes/github-light';
|
|
6
7
|
import { FC, HTMLAttributes, isValidElement } from 'react';
|
|
7
8
|
import reactElementToJSXString from 'react-element-to-jsx-string';
|
|
@@ -9,7 +10,7 @@ import { createHighlighterCoreSync } from 'shiki/core';
|
|
|
9
10
|
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
|
|
10
11
|
|
|
11
12
|
const highlighter = createHighlighterCoreSync({
|
|
12
|
-
themes: [githubLight],
|
|
13
|
+
themes: [githubLight, githubDark],
|
|
13
14
|
langs: [js, jsx, ts, tsx],
|
|
14
15
|
engine: createJavaScriptRegexEngine()
|
|
15
16
|
});
|
|
@@ -26,12 +27,13 @@ export const CodeBlock: FC<CodeBlockProps> = ({ className = '', language, childr
|
|
|
26
27
|
|
|
27
28
|
const __html = highlighter.codeToHtml(sourceCode, {
|
|
28
29
|
lang: language,
|
|
29
|
-
|
|
30
|
+
themes: { light: 'github-light', dark: 'github-dark' },
|
|
31
|
+
defaultColor: 'light',
|
|
30
32
|
structure: 'inline'
|
|
31
33
|
});
|
|
32
34
|
|
|
33
35
|
return (
|
|
34
|
-
<pre className={`m-0 language-${language} ${className}`} {...props}>
|
|
36
|
+
<pre className={`m-0 shiki language-${language} ${className}`} {...props}>
|
|
35
37
|
<code dangerouslySetInnerHTML={{ __html }} className={`language-${language}`} />
|
|
36
38
|
</pre>
|
|
37
39
|
);
|
package/source/Countdown.tsx
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { ComponentPropsWithRef, FC, ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
import { CloseButton } from './CloseButton';
|
|
7
|
+
import { NativeDialog, NativeDialogProps } from './NativeDialog';
|
|
8
|
+
|
|
9
|
+
export type DrawerPlacement = 'start' | 'end' | 'top' | 'bottom';
|
|
10
|
+
|
|
11
|
+
export const DrawerHeader: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
|
|
12
|
+
<div {...props} className={classNames('drawer-header', className)} />
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const DrawerTitle: FC<ComponentPropsWithRef<'h5'>> = ({ className, ...props }) => (
|
|
16
|
+
<h5 {...props} className={classNames('drawer-title', className)} />
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export const DrawerBody: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
|
|
20
|
+
<div {...props} className={classNames('drawer-body', className)} />
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export const DrawerFooter: FC<ComponentPropsWithRef<'div'>> = ({ className, ...props }) => (
|
|
24
|
+
<div {...props} className={classNames('drawer-footer', className)} />
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export interface DrawerProps extends Omit<NativeDialogProps, 'dialog' | 'onClose' | 'title'> {
|
|
28
|
+
title?: ReactNode;
|
|
29
|
+
placement?: DrawerPlacement;
|
|
30
|
+
footer?: ReactNode;
|
|
31
|
+
bodyClassName?: string;
|
|
32
|
+
onDismiss?: () => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const Drawer: FC<DrawerProps> = ({
|
|
36
|
+
title,
|
|
37
|
+
placement = 'end',
|
|
38
|
+
footer,
|
|
39
|
+
bodyClassName,
|
|
40
|
+
onDismiss,
|
|
41
|
+
className,
|
|
42
|
+
children,
|
|
43
|
+
...props
|
|
44
|
+
}) => (
|
|
45
|
+
<NativeDialog
|
|
46
|
+
{...props}
|
|
47
|
+
dialog={false}
|
|
48
|
+
tabIndex={-1}
|
|
49
|
+
aria-label={typeof title === 'string' ? title : props['aria-label']}
|
|
50
|
+
className={classNames('drawer', `drawer-${placement}`, className)}
|
|
51
|
+
onClose={onDismiss}
|
|
52
|
+
>
|
|
53
|
+
<DrawerHeader>
|
|
54
|
+
<DrawerTitle>{title}</DrawerTitle>
|
|
55
|
+
<CloseButton onClick={onDismiss} />
|
|
56
|
+
</DrawerHeader>
|
|
57
|
+
<DrawerBody className={bodyClassName}>{children}</DrawerBody>
|
|
58
|
+
{footer && <DrawerFooter>{footer}</DrawerFooter>}
|
|
59
|
+
</NativeDialog>
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
Drawer.displayName = 'Drawer';
|
package/source/Editor.tsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
1
3
|
import { EditorCore, WrapperProps } from '@react-editor-js/core';
|
|
2
4
|
import { observable } from 'mobx';
|
|
3
5
|
import { observer } from 'mobx-react';
|
|
@@ -7,8 +9,7 @@ import { createReactEditorJS } from 'react-editor-js';
|
|
|
7
9
|
const ReactEditorJS = createReactEditorJS();
|
|
8
10
|
|
|
9
11
|
export type EditorProps = PropsWithoutRef<
|
|
10
|
-
WrapperProps &
|
|
11
|
-
Pick<InputHTMLAttributes<HTMLInputElement>, 'name' | 'required'>
|
|
12
|
+
WrapperProps & Pick<InputHTMLAttributes<HTMLInputElement>, 'name' | 'required'>
|
|
12
13
|
>;
|
|
13
14
|
|
|
14
15
|
@observer
|
|
@@ -23,16 +24,12 @@ export class Editor extends Component<EditorProps> {
|
|
|
23
24
|
save = async () => this.core && (this.innerValue = await this.core.save());
|
|
24
25
|
|
|
25
26
|
render() {
|
|
26
|
-
const { name, required, children, ...editorProps } = this.props,
|
|
27
|
+
const { name, required, children: _children, ...editorProps } = this.props,
|
|
27
28
|
{ innerValue } = this;
|
|
28
29
|
|
|
29
30
|
return (
|
|
30
31
|
<div className="form-control" tabIndex={-1} onBlur={this.save}>
|
|
31
|
-
<input
|
|
32
|
-
hidden
|
|
33
|
-
{...{ name, required }}
|
|
34
|
-
value={JSON.stringify(innerValue)}
|
|
35
|
-
/>
|
|
32
|
+
<input hidden {...{ name, required }} value={JSON.stringify(innerValue)} />
|
|
36
33
|
<ReactEditorJS
|
|
37
34
|
{...editorProps}
|
|
38
35
|
onInitialize={core => {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
|
+
|
|
4
|
+
export type FormAdornmentProps = Omit<ComponentPropsWithRef<'label'>, 'htmlFor'> & {
|
|
5
|
+
end?: boolean;
|
|
6
|
+
size?: 'sm' | 'lg';
|
|
7
|
+
htmlFor?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const FormAdornment: FC<FormAdornmentProps> = ({ className, end, size, ...props }) => (
|
|
11
|
+
<label
|
|
12
|
+
{...props}
|
|
13
|
+
className={classNames(
|
|
14
|
+
'form-control form-adorn',
|
|
15
|
+
end && 'form-adorn-end',
|
|
16
|
+
size && `form-adorn-${size}`,
|
|
17
|
+
className
|
|
18
|
+
)}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
FormAdornment.displayName = 'FormAdornment';
|
|
23
|
+
|
|
24
|
+
export type FormAdornmentTextProps = ComponentPropsWithRef<'span'>;
|
|
25
|
+
|
|
26
|
+
export const FormAdornmentText: FC<FormAdornmentTextProps> = ({ className, ...props }) => (
|
|
27
|
+
<span {...props} className={classNames('form-adorn-text', className)} />
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
FormAdornmentText.displayName = 'FormAdornmentText';
|
|
31
|
+
|
|
32
|
+
export type FormGhostProps = ComponentPropsWithRef<'input'>;
|
|
33
|
+
|
|
34
|
+
export const FormGhost: FC<FormGhostProps> = ({ className, ...props }) => (
|
|
35
|
+
<input {...props} className={classNames('form-ghost', className)} />
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
FormGhost.displayName = 'FormGhost';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { Component, ComponentPropsWithoutRef, forwardRef, Ref } from 'react';
|
|
5
|
+
|
|
6
|
+
import type { ComponentTheme } from '../Button';
|
|
7
|
+
|
|
8
|
+
export type CheckboxProps = Omit<ComponentPropsWithoutRef<'input'>, 'type' | 'size'> & {
|
|
9
|
+
size?: 'sm' | 'lg';
|
|
10
|
+
theme?: ComponentTheme;
|
|
11
|
+
indeterminate?: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
interface CheckboxComponentProps extends CheckboxProps {
|
|
15
|
+
forwardedRef?: Ref<HTMLInputElement>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class CheckboxComponent extends Component<CheckboxComponentProps> {
|
|
19
|
+
private input?: HTMLInputElement;
|
|
20
|
+
|
|
21
|
+
componentDidMount() {
|
|
22
|
+
this.setIndeterminate();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
componentDidUpdate() {
|
|
26
|
+
this.setIndeterminate();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private setIndeterminate = () => {
|
|
30
|
+
if (this.input) this.input.indeterminate = this.props.indeterminate || false;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
private setInputRef = (input: HTMLInputElement | null) => {
|
|
34
|
+
this.input = input || undefined;
|
|
35
|
+
|
|
36
|
+
const { forwardedRef } = this.props;
|
|
37
|
+
|
|
38
|
+
if (typeof forwardedRef === 'function') forwardedRef(input);
|
|
39
|
+
else if (forwardedRef) forwardedRef.current = input;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
render() {
|
|
43
|
+
const {
|
|
44
|
+
className,
|
|
45
|
+
size,
|
|
46
|
+
theme,
|
|
47
|
+
indeterminate,
|
|
48
|
+
forwardedRef: _forwardedRef,
|
|
49
|
+
...props
|
|
50
|
+
} = this.props;
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<input
|
|
54
|
+
{...props}
|
|
55
|
+
ref={this.setInputRef}
|
|
56
|
+
type="checkbox"
|
|
57
|
+
aria-checked={indeterminate ? 'mixed' : undefined}
|
|
58
|
+
className={classNames(
|
|
59
|
+
'check',
|
|
60
|
+
size && `check-${size}`,
|
|
61
|
+
theme && `theme-${theme}`,
|
|
62
|
+
className
|
|
63
|
+
)}
|
|
64
|
+
/>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>((props, forwardedRef) => (
|
|
70
|
+
<CheckboxComponent {...props} forwardedRef={forwardedRef} />
|
|
71
|
+
));
|
|
72
|
+
|
|
73
|
+
Checkbox.displayName = 'Checkbox';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
|
+
|
|
4
|
+
import type { ComponentTheme } from '../Button';
|
|
5
|
+
|
|
6
|
+
export type ChipProps = ComponentPropsWithRef<'button'> & {
|
|
7
|
+
active?: boolean;
|
|
8
|
+
theme?: ComponentTheme;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const Chip: FC<ChipProps> = ({ className, active, disabled, theme, ...props }) => (
|
|
12
|
+
<button
|
|
13
|
+
{...props}
|
|
14
|
+
className={classNames('chip', active && 'active', theme && `theme-${theme}`, className)}
|
|
15
|
+
type="button"
|
|
16
|
+
aria-pressed={active}
|
|
17
|
+
disabled={disabled}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
Chip.displayName = 'Chip';
|
|
22
|
+
|
|
23
|
+
export type ChipInputProps = ComponentPropsWithRef<'div'> & {
|
|
24
|
+
theme?: ComponentTheme;
|
|
25
|
+
separator?: string;
|
|
26
|
+
allowDuplicates?: boolean;
|
|
27
|
+
maxChips?: number;
|
|
28
|
+
createOnBlur?: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const ChipInput: FC<ChipInputProps> = ({
|
|
32
|
+
className,
|
|
33
|
+
theme,
|
|
34
|
+
separator,
|
|
35
|
+
allowDuplicates,
|
|
36
|
+
maxChips,
|
|
37
|
+
createOnBlur,
|
|
38
|
+
...props
|
|
39
|
+
}) => (
|
|
40
|
+
<div
|
|
41
|
+
{...props}
|
|
42
|
+
className={classNames('chip-input', theme && `theme-${theme}`, className)}
|
|
43
|
+
data-bs-chips=""
|
|
44
|
+
data-bs-separator={separator}
|
|
45
|
+
data-bs-allow-duplicates={allowDuplicates}
|
|
46
|
+
data-bs-max-chips={maxChips}
|
|
47
|
+
data-bs-create-on-blur={createOnBlur}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
ChipInput.displayName = 'ChipInput';
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { Children, cloneElement, ComponentPropsWithRef, FC, isValidElement } from 'react';
|
|
5
|
+
|
|
6
|
+
import { Menu } from '../Menu';
|
|
7
|
+
|
|
8
|
+
export interface ComboboxOptionProps extends ComponentPropsWithRef<'button'> {
|
|
9
|
+
value: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const ComboboxOption: FC<ComboboxOptionProps> = ({ className, value, ...props }) => (
|
|
13
|
+
<button
|
|
14
|
+
{...props}
|
|
15
|
+
type="button"
|
|
16
|
+
className={classNames('menu-item', className)}
|
|
17
|
+
data-bs-value={value}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
ComboboxOption.displayName = 'ComboboxOption';
|
|
22
|
+
|
|
23
|
+
export interface ComboboxProps extends Omit<ComponentPropsWithRef<'div'>, 'onChange'> {
|
|
24
|
+
name: string;
|
|
25
|
+
value: string | string[];
|
|
26
|
+
placeholder?: string;
|
|
27
|
+
multiple?: boolean;
|
|
28
|
+
menuClassName?: string;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
onChange?: (value: string | string[]) => unknown;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const Combobox: FC<ComboboxProps> = ({
|
|
34
|
+
className,
|
|
35
|
+
name,
|
|
36
|
+
value,
|
|
37
|
+
placeholder = 'Select an item…',
|
|
38
|
+
disabled,
|
|
39
|
+
multiple,
|
|
40
|
+
onChange,
|
|
41
|
+
menuClassName,
|
|
42
|
+
children,
|
|
43
|
+
...props
|
|
44
|
+
}) => {
|
|
45
|
+
const values = Array.isArray(value) ? value : value ? [value] : [];
|
|
46
|
+
const options = Children.toArray(children).filter(
|
|
47
|
+
(option): option is React.ReactElement<ComboboxOptionProps> =>
|
|
48
|
+
isValidElement<ComboboxOptionProps>(option)
|
|
49
|
+
);
|
|
50
|
+
const selected = options.filter(option => values.includes(option.props.value));
|
|
51
|
+
const hasSelection = selected.length > 0;
|
|
52
|
+
|
|
53
|
+
const handleClick: ComponentPropsWithRef<'div'>['onClick'] = ({ target }) => {
|
|
54
|
+
if (!(target instanceof Element)) return;
|
|
55
|
+
|
|
56
|
+
const option = target.closest<HTMLButtonElement>('[data-bs-value]');
|
|
57
|
+
if (!option || !onChange) return;
|
|
58
|
+
|
|
59
|
+
const next = option.dataset.bsValue || '';
|
|
60
|
+
const value = multiple
|
|
61
|
+
? values.includes(next)
|
|
62
|
+
? values.filter(item => item !== next)
|
|
63
|
+
: [...values, next]
|
|
64
|
+
: next;
|
|
65
|
+
|
|
66
|
+
onChange(value);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div {...props} className={classNames('combobox', className)}>
|
|
71
|
+
<Menu
|
|
72
|
+
label={
|
|
73
|
+
<span
|
|
74
|
+
className={classNames(
|
|
75
|
+
'combobox-value',
|
|
76
|
+
!hasSelection && 'combobox-placeholder'
|
|
77
|
+
)}
|
|
78
|
+
>
|
|
79
|
+
{hasSelection ? selected.map(option => option.props.children) : placeholder}
|
|
80
|
+
</span>
|
|
81
|
+
}
|
|
82
|
+
toggleProps={{
|
|
83
|
+
className: 'form-control combobox-toggle',
|
|
84
|
+
variant: 'text',
|
|
85
|
+
disabled,
|
|
86
|
+
'aria-haspopup': 'listbox',
|
|
87
|
+
'aria-label': placeholder
|
|
88
|
+
}}
|
|
89
|
+
autoClose={!multiple}
|
|
90
|
+
menuClassName={classNames(menuClassName, 'combobox-menu')}
|
|
91
|
+
onClick={handleClick}
|
|
92
|
+
>
|
|
93
|
+
{options.map(option => {
|
|
94
|
+
const selected = values.includes(option.props.value);
|
|
95
|
+
|
|
96
|
+
return cloneElement(option, {
|
|
97
|
+
className: classNames(option.props.className, selected && 'selected'),
|
|
98
|
+
'aria-selected': selected
|
|
99
|
+
});
|
|
100
|
+
})}
|
|
101
|
+
</Menu>
|
|
102
|
+
{values.map(item => (
|
|
103
|
+
<input key={item} type="hidden" name={name} value={item} />
|
|
104
|
+
))}
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
Combobox.displayName = 'Combobox';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
|
+
|
|
4
|
+
const CONTROL_SIZES = {
|
|
5
|
+
sm: 'form-control-sm',
|
|
6
|
+
lg: 'form-control-lg'
|
|
7
|
+
} as const;
|
|
8
|
+
|
|
9
|
+
export type FormControlProps = ComponentPropsWithRef<'input'> & {
|
|
10
|
+
plaintext?: boolean;
|
|
11
|
+
ghost?: boolean;
|
|
12
|
+
caret?: boolean;
|
|
13
|
+
color?: boolean;
|
|
14
|
+
controlSize?: 'sm' | 'lg';
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const FormControl: FC<FormControlProps> = ({
|
|
18
|
+
className,
|
|
19
|
+
plaintext,
|
|
20
|
+
ghost,
|
|
21
|
+
caret,
|
|
22
|
+
color,
|
|
23
|
+
controlSize,
|
|
24
|
+
...props
|
|
25
|
+
}) => (
|
|
26
|
+
<input
|
|
27
|
+
{...props}
|
|
28
|
+
className={classNames(
|
|
29
|
+
ghost ? 'form-ghost' : plaintext ? 'form-control-plaintext' : 'form-control',
|
|
30
|
+
!ghost && caret && 'form-control-caret',
|
|
31
|
+
!ghost && !plaintext && color && 'form-control-color',
|
|
32
|
+
!ghost && !plaintext && controlSize && CONTROL_SIZES[controlSize],
|
|
33
|
+
className
|
|
34
|
+
)}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
FormControl.displayName = 'FormControl';
|
|
39
|
+
|
|
40
|
+
export type FormTextAreaProps = ComponentPropsWithRef<'textarea'>;
|
|
41
|
+
|
|
42
|
+
export const FormTextArea: FC<FormTextAreaProps> = ({ className, ...props }) => (
|
|
43
|
+
<textarea {...props} className={classNames('form-control', className)} />
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
FormTextArea.displayName = 'FormTextArea';
|
|
47
|
+
|
|
48
|
+
export type FormSelectProps = ComponentPropsWithRef<'select'> & {
|
|
49
|
+
controlSize?: 'sm' | 'lg';
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const FormSelect: FC<FormSelectProps> = ({ className, controlSize, ...props }) => (
|
|
53
|
+
<select
|
|
54
|
+
{...props}
|
|
55
|
+
className={classNames('form-control', controlSize && CONTROL_SIZES[controlSize], className)}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
FormSelect.displayName = 'FormSelect';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { Component, ComponentPropsWithoutRef, forwardRef, Ref } from 'react';
|
|
5
|
+
|
|
6
|
+
export type DatePickerProps = Omit<ComponentPropsWithoutRef<'input'>, 'type'> & {
|
|
7
|
+
enhanced?: boolean;
|
|
8
|
+
inline?: boolean;
|
|
9
|
+
selectionMode?: 'single' | 'multiple' | 'multiple-ranged';
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
interface DatePickerComponentProps extends DatePickerProps {
|
|
13
|
+
forwardedRef?: Ref<HTMLInputElement>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface DatepickerInstance {
|
|
17
|
+
dispose(): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class DatePickerComponent extends Component<DatePickerComponentProps> {
|
|
21
|
+
private input?: HTMLInputElement;
|
|
22
|
+
private instance?: DatepickerInstance;
|
|
23
|
+
private mounted = false;
|
|
24
|
+
|
|
25
|
+
componentDidMount() {
|
|
26
|
+
this.mounted = true;
|
|
27
|
+
this.initialize();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
componentWillUnmount() {
|
|
31
|
+
this.mounted = false;
|
|
32
|
+
const { instance } = this;
|
|
33
|
+
this.instance = undefined;
|
|
34
|
+
|
|
35
|
+
queueMicrotask(() => instance?.dispose());
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private initialize = async () => {
|
|
39
|
+
if (!this.props.enhanced) return;
|
|
40
|
+
|
|
41
|
+
const { default: Datepicker } = await import('bootstrap/js/src/datepicker.js');
|
|
42
|
+
|
|
43
|
+
if (this.mounted && this.input) this.instance = Datepicker.getOrCreateInstance(this.input);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
private setInputRef = (input: HTMLInputElement | null) => {
|
|
47
|
+
this.input = input || undefined;
|
|
48
|
+
|
|
49
|
+
const { forwardedRef } = this.props;
|
|
50
|
+
|
|
51
|
+
if (typeof forwardedRef === 'function') forwardedRef(input);
|
|
52
|
+
else if (forwardedRef) forwardedRef.current = input;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
render() {
|
|
56
|
+
const {
|
|
57
|
+
className,
|
|
58
|
+
enhanced,
|
|
59
|
+
inline,
|
|
60
|
+
selectionMode,
|
|
61
|
+
min,
|
|
62
|
+
max,
|
|
63
|
+
forwardedRef: _forwardedRef,
|
|
64
|
+
...props
|
|
65
|
+
} = this.props;
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<input
|
|
69
|
+
{...props}
|
|
70
|
+
ref={this.setInputRef}
|
|
71
|
+
className={classNames('form-control', className)}
|
|
72
|
+
type={enhanced ? 'text' : 'date'}
|
|
73
|
+
min={min}
|
|
74
|
+
max={max}
|
|
75
|
+
data-bs-toggle={enhanced ? 'datepicker' : undefined}
|
|
76
|
+
data-bs-date-min={enhanced ? min : undefined}
|
|
77
|
+
data-bs-date-max={enhanced ? max : undefined}
|
|
78
|
+
data-bs-inline={enhanced ? inline || undefined : undefined}
|
|
79
|
+
data-bs-selection-mode={enhanced ? selectionMode : undefined}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const DatePicker = forwardRef<HTMLInputElement, DatePickerProps>((props, forwardedRef) => (
|
|
86
|
+
<DatePickerComponent {...props} forwardedRef={forwardedRef} />
|
|
87
|
+
));
|
|
88
|
+
|
|
89
|
+
DatePicker.displayName = 'DatePicker';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef, FC } from 'react';
|
|
3
|
+
|
|
4
|
+
export type FormTextProps = ComponentPropsWithRef<'small'>;
|
|
5
|
+
|
|
6
|
+
export const FormText: FC<FormTextProps> = ({ className, ...props }) => (
|
|
7
|
+
<small {...props} className={classNames('form-text', className)} />
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
FormText.displayName = 'FormText';
|
|
11
|
+
|
|
12
|
+
export type FormFeedbackProps = Omit<ComponentPropsWithRef<'div'>, 'type'> & {
|
|
13
|
+
type?: 'valid' | 'invalid';
|
|
14
|
+
tooltip?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const FormFeedback: FC<FormFeedbackProps> = ({
|
|
18
|
+
className,
|
|
19
|
+
type = 'invalid',
|
|
20
|
+
tooltip,
|
|
21
|
+
...props
|
|
22
|
+
}) => (
|
|
23
|
+
<div
|
|
24
|
+
{...props}
|
|
25
|
+
className={classNames(tooltip ? `${type}-tooltip` : `${type}-feedback`, className)}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
FormFeedback.displayName = 'FormFeedback';
|