idea-react 3.0.0-beta.0 → 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 +19 -2
- package/ReadMe.md +95 -54
- package/dist/DatePickerPlugin-CpGuQRsi.js +1 -0
- package/dist/DatePickerPlugin-DB3nnslN.mjs +1 -0
- package/dist/index.d.mts +1232 -474
- package/dist/index.d.ts +1232 -474
- package/dist/index.js +16 -16
- package/dist/index.mjs +15 -15
- package/dist/rolldown-runtime-5iZMYShA.js +1 -0
- package/dist/style.css +66 -66
- package/package.json +1 -1
- package/source/Accordion.tsx +161 -0
- package/source/Alert.tsx +153 -0
- package/source/Avatar.tsx +57 -46
- package/source/Badge.tsx +17 -15
- package/source/Breadcrumb.tsx +50 -0
- package/source/Button.tsx +69 -40
- package/source/ButtonGroup.tsx +23 -18
- package/source/Card.tsx +86 -17
- package/source/Carousel/index.tsx +392 -0
- package/source/Carousel/model.ts +113 -0
- package/source/Carousel/scroll.ts +79 -0
- package/source/CloseButton.tsx +20 -15
- package/source/Collapse.tsx +233 -0
- package/source/Drawer.tsx +158 -38
- package/source/{ClickBoundary.tsx → Extension/ClickBoundary.tsx} +24 -5
- package/source/Extension/CodeBlock.tsx +64 -0
- package/source/{Countdown.tsx → Extension/Countdown.tsx} +21 -9
- package/source/{Dialog.tsx → Extension/Dialog.tsx} +10 -6
- package/source/Extension/Editor.tsx +78 -0
- package/source/Extension/EditorHTML.tsx +20 -0
- package/source/{HorizontalMarquee → Extension/HorizontalMarquee}/index.module.less +1 -3
- package/source/Extension/HorizontalMarquee/index.tsx +85 -0
- package/source/Extension/Icon.tsx +19 -0
- package/source/Extension/Loading.tsx +30 -0
- package/source/{MonthCalendar.tsx → Extension/MonthCalendar.tsx} +29 -13
- package/source/{Nameplate.tsx → Extension/Nameplate.tsx} +1 -1
- package/source/Extension/OverlayBox.tsx +293 -0
- package/source/{PageNav.tsx → Extension/PageNav.tsx} +43 -16
- package/source/{ScrollNav → Extension/ScrollNav}/Scroller.tsx +21 -5
- package/source/Extension/ScrollNav/index.tsx +47 -0
- package/source/Extension/Select.tsx +128 -0
- package/source/{ShareBox.tsx → Extension/ShareBox.tsx} +1 -1
- package/source/Extension/SpinnerButton.tsx +30 -0
- package/source/Extension/TableSpinner.tsx +22 -0
- package/source/Extension/TextTruncate/index.tsx +29 -0
- package/source/Extension/Time.tsx +17 -0
- package/source/Extension/TimeDistance.tsx +45 -0
- package/source/Extension/Timeline/index.tsx +63 -0
- package/source/Extension/TypeEcho/Content.tsx +123 -0
- package/source/Extension/TypeEcho/index.tsx +22 -0
- package/source/Extension/UserRank/Address.tsx +22 -0
- package/source/Extension/UserRank/index.tsx +106 -0
- package/source/Extension/VerticalMarquee/index.tsx +23 -0
- package/source/Extension/ZodiacBar.tsx +59 -0
- package/source/Extension/index.ts +27 -0
- package/source/Form/Adorn.tsx +45 -26
- package/source/Form/Checkbox.tsx +20 -11
- package/source/Form/ChipInput.tsx +129 -0
- package/source/Form/Chips.tsx +57 -37
- package/source/Form/Combobox.tsx +362 -78
- package/source/Form/Control.tsx +72 -42
- package/source/Form/DatePicker.tsx +245 -45
- package/source/Form/DatePickerPlugin.ts +37 -0
- package/source/Form/Feedback.tsx +21 -16
- package/source/Form/FloatingLabel.tsx +21 -7
- package/source/Form/InputGroup.tsx +162 -11
- package/source/Form/OTP.tsx +156 -45
- package/source/Form/PasswordStrength.tsx +43 -17
- package/source/Form/Plugin.tsx +53 -0
- package/source/Form/Primitives.tsx +70 -20
- package/source/Form/Radio.tsx +35 -40
- package/source/Form/Range.tsx +125 -56
- package/source/Form/Switch.tsx +53 -27
- package/source/Form/index.ts +1 -0
- package/source/Grid.tsx +68 -56
- package/source/Image.tsx +10 -6
- package/source/ListGroup.tsx +59 -58
- package/source/Menu.tsx +317 -46
- package/source/NativeDialog/index.tsx +148 -22
- package/source/Nav.tsx +49 -33
- package/source/NavOverflow/index.tsx +323 -0
- package/source/NavOverflow/model.ts +21 -0
- package/source/Navbar.tsx +65 -45
- package/source/Overlay.ts +163 -1
- package/source/Pagination.tsx +86 -0
- package/source/Placeholder.tsx +70 -0
- package/source/Polymorphic.ts +57 -0
- package/source/Popover.tsx +34 -26
- package/source/Progress/index.tsx +81 -0
- package/source/Progress/style.module.css +15 -0
- package/source/ScrollSpy/index.tsx +380 -0
- package/source/ScrollSpy/model.ts +17 -0
- package/source/Spinner.tsx +31 -17
- package/source/Stack.tsx +25 -0
- package/source/Stepper.tsx +91 -0
- package/source/Tab.tsx +261 -0
- package/source/Table.tsx +53 -42
- package/source/Toast.tsx +93 -46
- package/source/ToggleButton.tsx +47 -30
- package/source/Toggler.tsx +117 -0
- package/source/Tooltip.tsx +31 -24
- package/source/index.ts +17 -27
- package/source/CodeBlock.tsx +0 -40
- package/source/Editor.tsx +0 -43
- package/source/EditorHTML.tsx +0 -16
- package/source/HorizontalMarquee/index.tsx +0 -61
- package/source/Icon.tsx +0 -24
- package/source/Loading.tsx +0 -22
- package/source/OverlayBox.tsx +0 -208
- package/source/ScrollNav/index.tsx +0 -22
- package/source/Select.tsx +0 -95
- package/source/SpinnerButton.tsx +0 -35
- package/source/TableSpinner.tsx +0 -26
- package/source/TextTruncate/index.tsx +0 -25
- package/source/Time.tsx +0 -15
- package/source/TimeDistance.tsx +0 -41
- package/source/Timeline/index.tsx +0 -60
- package/source/TypeEcho/Content.tsx +0 -58
- package/source/TypeEcho/index.tsx +0 -14
- package/source/UserRank/Address.tsx +0 -20
- package/source/UserRank/index.tsx +0 -111
- package/source/VerticalMarquee/index.tsx +0 -25
- package/source/ZodiacBar.tsx +0 -51
- /package/source/{LiveTSX.tsx → Extension/LiveTSX.tsx} +0 -0
- /package/source/{ScrollNav → Extension/ScrollNav}/index.module.less +0 -0
- /package/source/{TextTruncate → Extension/TextTruncate}/Content.tsx +0 -0
- /package/source/{Timeline → Extension/Timeline}/index.module.less +0 -0
- /package/source/{UserRank → Extension/UserRank}/index.module.less +0 -0
- /package/source/{VerticalMarquee → Extension/VerticalMarquee}/index.module.less +0 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import css from '@shikijs/langs/css';
|
|
2
|
+
import html from '@shikijs/langs/html';
|
|
3
|
+
import js from '@shikijs/langs/javascript';
|
|
4
|
+
import json from '@shikijs/langs/json';
|
|
5
|
+
import jsx from '@shikijs/langs/jsx';
|
|
6
|
+
import sh from '@shikijs/langs/sh';
|
|
7
|
+
import tsx from '@shikijs/langs/tsx';
|
|
8
|
+
import ts from '@shikijs/langs/typescript';
|
|
9
|
+
import githubDark from '@shikijs/themes/github-dark';
|
|
10
|
+
import githubLight from '@shikijs/themes/github-light';
|
|
11
|
+
import { HTMLAttributes, isValidElement, ReactNode } from 'react';
|
|
12
|
+
import reactElementToJSXString from 'react-element-to-jsx-string';
|
|
13
|
+
import { createHighlighterCoreSync, ShikiTransformer } from 'shiki/core';
|
|
14
|
+
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
|
|
15
|
+
|
|
16
|
+
import { polymorphic } from '../Polymorphic';
|
|
17
|
+
|
|
18
|
+
const highlighter = createHighlighterCoreSync({
|
|
19
|
+
themes: [githubLight, githubDark],
|
|
20
|
+
langs: [css, html, js, json, jsx, sh, ts, tsx],
|
|
21
|
+
engine: createJavaScriptRegexEngine()
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export interface CodeBlockProps extends HTMLAttributes<HTMLPreElement> {
|
|
25
|
+
language: string;
|
|
26
|
+
header?: ReactNode;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const CodeBlock = polymorphic<CodeBlockProps>(
|
|
30
|
+
({ as: Root = 'pre', className = '', language, header, children, ...props }) => {
|
|
31
|
+
const sourceCode =
|
|
32
|
+
typeof children === 'string'
|
|
33
|
+
? children
|
|
34
|
+
: reactElementToJSXString(isValidElement(children) ? children : <>{children}</>);
|
|
35
|
+
|
|
36
|
+
const span: ShikiTransformer['span'] = ({ properties }) => {
|
|
37
|
+
properties.style = `${properties.style};color:light-dark(var(--shiki-light),var(--shiki-dark))`;
|
|
38
|
+
};
|
|
39
|
+
const __html = highlighter.codeToHtml(sourceCode, {
|
|
40
|
+
lang: language,
|
|
41
|
+
themes: { light: 'github-light', dark: 'github-dark' },
|
|
42
|
+
defaultColor: false,
|
|
43
|
+
structure: 'inline',
|
|
44
|
+
transformers: [{ span }]
|
|
45
|
+
});
|
|
46
|
+
const code = (
|
|
47
|
+
<Root className={`m-0 shiki language-${language} ${className}`} {...props}>
|
|
48
|
+
<code dangerouslySetInnerHTML={{ __html }} className={`language-${language}`} />
|
|
49
|
+
</Root>
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
return header ? (
|
|
53
|
+
<figure className="m-0">
|
|
54
|
+
<figcaption className="px-3 pb-6 mb-6 bg-body-tertiary border-bottom">
|
|
55
|
+
{header}
|
|
56
|
+
</figcaption>
|
|
57
|
+
{code}
|
|
58
|
+
</figure>
|
|
59
|
+
) : (
|
|
60
|
+
code
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
CodeBlock.displayName = 'CodeBlock';
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
import { computed, observable } from 'mobx';
|
|
4
4
|
import { observer } from 'mobx-react';
|
|
5
5
|
import { ObservedComponent, reaction } from 'mobx-react-helper';
|
|
6
|
-
import { HTMLAttributes } from 'react';
|
|
6
|
+
import { ElementType, HTMLAttributes } from 'react';
|
|
7
7
|
import { Second, TimeData } from 'web-utility';
|
|
8
8
|
|
|
9
|
+
import { AsProps, PolymorphicClassProps } from '../Polymorphic';
|
|
10
|
+
|
|
9
11
|
export interface TimeUnit {
|
|
10
12
|
scale: number;
|
|
11
13
|
label: string;
|
|
@@ -27,7 +29,15 @@ export interface CountdownProps extends HTMLAttributes<HTMLOListElement> {
|
|
|
27
29
|
* Migrate from https://bootstrap.web-cell.dev/#Calendar/CountDown
|
|
28
30
|
*/
|
|
29
31
|
@observer
|
|
30
|
-
export class Countdown extends ObservedComponent<
|
|
32
|
+
export class Countdown<T extends ElementType | undefined = 'ol'> extends ObservedComponent<
|
|
33
|
+
PolymorphicClassProps<T, CountdownProps>
|
|
34
|
+
> {
|
|
35
|
+
declare readonly props: PolymorphicClassProps<T, CountdownProps>;
|
|
36
|
+
|
|
37
|
+
protected get componentProps(): CountdownProps & AsProps {
|
|
38
|
+
return this.observedProps;
|
|
39
|
+
}
|
|
40
|
+
|
|
31
41
|
static displayName = 'Countdown';
|
|
32
42
|
|
|
33
43
|
@observable
|
|
@@ -36,12 +46,12 @@ export class Countdown extends ObservedComponent<CountdownProps> {
|
|
|
36
46
|
private timer = 0;
|
|
37
47
|
|
|
38
48
|
get endTimestamp() {
|
|
39
|
-
return +new Date(this.
|
|
49
|
+
return +new Date(this.componentProps.endTime || Date.now());
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
@computed
|
|
43
53
|
get timeSections(): TimeSection[] {
|
|
44
|
-
const { units } = this.
|
|
54
|
+
const { units } = this.componentProps;
|
|
45
55
|
let { rest } = this;
|
|
46
56
|
|
|
47
57
|
return units.reduce((list, { label }, index) => {
|
|
@@ -59,7 +69,7 @@ export class Countdown extends ObservedComponent<CountdownProps> {
|
|
|
59
69
|
}
|
|
60
70
|
|
|
61
71
|
tick = () => {
|
|
62
|
-
const { onEnd, endTime } = this.
|
|
72
|
+
const { onEnd, endTime } = this.componentProps,
|
|
63
73
|
rest = this.endTimestamp - Date.now();
|
|
64
74
|
|
|
65
75
|
if (rest > 0) {
|
|
@@ -83,7 +93,7 @@ export class Countdown extends ObservedComponent<CountdownProps> {
|
|
|
83
93
|
this.initTimer();
|
|
84
94
|
}
|
|
85
95
|
|
|
86
|
-
@reaction(_this => _this.
|
|
96
|
+
@reaction(_this => _this.componentProps.endTime)
|
|
87
97
|
initTimer() {
|
|
88
98
|
this.stop();
|
|
89
99
|
this.tick();
|
|
@@ -97,24 +107,26 @@ export class Countdown extends ObservedComponent<CountdownProps> {
|
|
|
97
107
|
|
|
98
108
|
render() {
|
|
99
109
|
const {
|
|
110
|
+
as,
|
|
100
111
|
className = '',
|
|
101
112
|
itemClassName = 'border rounded px-4 py-3 d-flex flex-column justify-content-center align-items-center',
|
|
102
113
|
units: _u,
|
|
103
114
|
endTime: _e,
|
|
104
115
|
onEnd: _o,
|
|
105
116
|
...props
|
|
106
|
-
} = this.
|
|
117
|
+
} = this.componentProps;
|
|
118
|
+
const Root: ElementType = as ?? 'ol';
|
|
107
119
|
const { timeSections } = this;
|
|
108
120
|
|
|
109
121
|
return (
|
|
110
|
-
<
|
|
122
|
+
<Root className={`list-unstyled m-0 ${className}`} {...props}>
|
|
111
123
|
{timeSections.map(({ value, label }) => (
|
|
112
124
|
<li key={label} className={itemClassName}>
|
|
113
125
|
<strong>{(value + '').padStart(2, '0')}</strong>
|
|
114
126
|
<span>{label}</span>
|
|
115
127
|
</li>
|
|
116
128
|
))}
|
|
117
|
-
</
|
|
129
|
+
</Root>
|
|
118
130
|
);
|
|
119
131
|
}
|
|
120
132
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Defer } from 'iterable-observer';
|
|
2
|
-
import { observable } from 'mobx';
|
|
2
|
+
import { action, observable } from 'mobx';
|
|
3
3
|
import { observer } from 'mobx-react';
|
|
4
4
|
import { FC } from 'react';
|
|
5
5
|
|
|
@@ -9,11 +9,11 @@ export class DialogClose extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export interface DialogProps<T =
|
|
12
|
+
export interface DialogProps<T = unknown> {
|
|
13
13
|
defer?: Defer<T>;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export class Dialog<I extends object = {}, O =
|
|
16
|
+
export class Dialog<I extends object = {}, O = unknown> {
|
|
17
17
|
@observable
|
|
18
18
|
accessor input = {} as I;
|
|
19
19
|
|
|
@@ -29,13 +29,17 @@ export class Dialog<I extends object = {}, O = any> {
|
|
|
29
29
|
this.Component.displayName = 'DialogComponent';
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
@action
|
|
32
33
|
open(input?: I) {
|
|
33
34
|
if (input) this.input = input;
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
const defer = new Defer<O>();
|
|
37
|
+
this.defer = defer;
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
const clear = action(() => this.defer === defer && (this.defer = undefined));
|
|
38
40
|
|
|
39
|
-
|
|
41
|
+
defer.promise.then(clear, clear);
|
|
42
|
+
|
|
43
|
+
return defer.promise;
|
|
40
44
|
}
|
|
41
45
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { EditorCore, WrapperProps } from '@react-editor-js/core';
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
import { action, observable } from 'mobx';
|
|
6
|
+
import { observer } from 'mobx-react';
|
|
7
|
+
import { Component, ComponentPropsWithRef, ElementType, FocusEvent } from 'react';
|
|
8
|
+
import { createReactEditorJS } from 'react-editor-js';
|
|
9
|
+
|
|
10
|
+
import { AsProps, PolymorphicClassProps } from '../Polymorphic';
|
|
11
|
+
|
|
12
|
+
const ReactEditorJS = createReactEditorJS();
|
|
13
|
+
|
|
14
|
+
export type EditorProps = WrapperProps &
|
|
15
|
+
Pick<ComponentPropsWithRef<'input'>, 'name' | 'required'> &
|
|
16
|
+
Pick<ComponentPropsWithRef<'div'>, 'className' | 'style' | 'tabIndex' | 'onBlur'>;
|
|
17
|
+
|
|
18
|
+
@observer
|
|
19
|
+
export class Editor<T extends ElementType | undefined = 'div'> extends Component<
|
|
20
|
+
PolymorphicClassProps<T, EditorProps>
|
|
21
|
+
> {
|
|
22
|
+
declare readonly props: PolymorphicClassProps<T, EditorProps>;
|
|
23
|
+
|
|
24
|
+
protected get componentProps(): Readonly<EditorProps & AsProps> {
|
|
25
|
+
return this.props;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static displayName = 'Editor';
|
|
29
|
+
|
|
30
|
+
private core?: EditorCore;
|
|
31
|
+
|
|
32
|
+
@observable
|
|
33
|
+
accessor innerValue = this.componentProps.defaultValue;
|
|
34
|
+
|
|
35
|
+
setInnerValue = action((value: typeof this.innerValue) => (this.innerValue = value));
|
|
36
|
+
|
|
37
|
+
handleBlur = async (event: FocusEvent<HTMLDivElement>) => {
|
|
38
|
+
this.componentProps.onBlur?.(event);
|
|
39
|
+
|
|
40
|
+
if (this.core) this.setInnerValue(await this.core.save());
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
initialize = (core: EditorCore) => {
|
|
44
|
+
this.componentProps.onInitialize?.(core);
|
|
45
|
+
|
|
46
|
+
this.core = core;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
render() {
|
|
50
|
+
const Root: ElementType = this.componentProps.as ?? 'div';
|
|
51
|
+
|
|
52
|
+
const {
|
|
53
|
+
as: _as,
|
|
54
|
+
name,
|
|
55
|
+
required,
|
|
56
|
+
className,
|
|
57
|
+
style,
|
|
58
|
+
tabIndex = -1,
|
|
59
|
+
onBlur: _onBlur,
|
|
60
|
+
children: _children,
|
|
61
|
+
...editorProps
|
|
62
|
+
} = this.componentProps,
|
|
63
|
+
{ innerValue } = this;
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<Root
|
|
67
|
+
{...(this.componentProps.as ? editorProps : {})}
|
|
68
|
+
className={classNames('form-control', className)}
|
|
69
|
+
style={style}
|
|
70
|
+
tabIndex={tabIndex}
|
|
71
|
+
onBlur={this.handleBlur}
|
|
72
|
+
>
|
|
73
|
+
<input hidden {...{ name, required }} value={JSON.stringify(innerValue)} />
|
|
74
|
+
<ReactEditorJS {...editorProps} onInitialize={this.initialize} />
|
|
75
|
+
</Root>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { OutputData } from '@editorjs/editorjs';
|
|
2
|
+
import createParser from 'editorjs-html';
|
|
3
|
+
import { HTMLAttributes } from 'react';
|
|
4
|
+
|
|
5
|
+
import { polymorphic } from '../Polymorphic';
|
|
6
|
+
|
|
7
|
+
export const parser = createParser({
|
|
8
|
+
link: ({ data: { link } }) => `<a href="${link}">${link}</a>`
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export interface EditorHTMLProps extends HTMLAttributes<HTMLDivElement> {
|
|
12
|
+
data: OutputData;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const EditorHTML = polymorphic<EditorHTMLProps>(
|
|
16
|
+
({ as: Root = 'article', data, ...props }) => (
|
|
17
|
+
<Root {...props} dangerouslySetInnerHTML={{ __html: parser.parse(data) }} />
|
|
18
|
+
)
|
|
19
|
+
);
|
|
20
|
+
EditorHTML.displayName = 'EditorHTML';
|
|
@@ -36,9 +36,7 @@
|
|
|
36
36
|
--scroll-height: 20px;
|
|
37
37
|
height: var(--scroll-height);
|
|
38
38
|
.scrollContainer {
|
|
39
|
-
transform: translateY(
|
|
40
|
-
calc(calc(-100% + var(--scroll-height) + var(--scroll-height)) * 2)
|
|
41
|
-
);
|
|
39
|
+
transform: translateY(calc(calc(-100% + var(--scroll-height) + var(--scroll-height)) * 2));
|
|
42
40
|
max-height: calc(var(--scroll-height) * 3);
|
|
43
41
|
.unScrollItem {
|
|
44
42
|
max-height: calc(var(--scroll-height) * 2);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
import { polymorphic } from '../../Polymorphic';
|
|
4
|
+
import * as style from './index.module.less';
|
|
5
|
+
|
|
6
|
+
export type HorizontalMarqueeProps = HTMLAttributes<HTMLDivElement> &
|
|
7
|
+
Partial<Record<'maxWidth' | 'duration' | 'height', string>>;
|
|
8
|
+
|
|
9
|
+
export const HorizontalMarquee = polymorphic<HorizontalMarqueeProps>(
|
|
10
|
+
({
|
|
11
|
+
as: Root = 'div',
|
|
12
|
+
className = '',
|
|
13
|
+
children,
|
|
14
|
+
maxWidth = '100%',
|
|
15
|
+
duration,
|
|
16
|
+
height,
|
|
17
|
+
...props
|
|
18
|
+
}) => (
|
|
19
|
+
<Root className={`overflow-hidden max-w-100 ${className}`} {...props}>
|
|
20
|
+
<div
|
|
21
|
+
className={`d-inline-block align-top text-nowrap ${style.scrollWrap}`}
|
|
22
|
+
style={{
|
|
23
|
+
maxWidth,
|
|
24
|
+
animationDuration: duration,
|
|
25
|
+
height,
|
|
26
|
+
lineHeight: height
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
<div
|
|
30
|
+
className={`d-inline-block ${style.scrollItem}`}
|
|
31
|
+
style={{ animationDuration: duration }}
|
|
32
|
+
>
|
|
33
|
+
{children}
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
</Root>
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const HorizontalMarqueeBox = polymorphic<HorizontalMarqueeProps>(
|
|
41
|
+
({
|
|
42
|
+
as: RootAs,
|
|
43
|
+
children,
|
|
44
|
+
className = '',
|
|
45
|
+
style: rootStyle,
|
|
46
|
+
maxWidth,
|
|
47
|
+
duration,
|
|
48
|
+
height,
|
|
49
|
+
...props
|
|
50
|
+
}) => {
|
|
51
|
+
const Root = RootAs ?? 'div';
|
|
52
|
+
return height ? (
|
|
53
|
+
<Root
|
|
54
|
+
{...props}
|
|
55
|
+
className={`overflow-hidden ${style.scrollHeightWrap} ${className}`}
|
|
56
|
+
style={{ maxWidth, '--scroll-height': height, ...rootStyle }}
|
|
57
|
+
>
|
|
58
|
+
<div
|
|
59
|
+
className={`d-inline-block overflow-hidden max-w-100 ${style.scrollContainer}`}
|
|
60
|
+
>
|
|
61
|
+
<div
|
|
62
|
+
className={`d-block overflow-hidden text-wrap text-break ${style.unScrollItem}`}
|
|
63
|
+
>
|
|
64
|
+
{children}
|
|
65
|
+
</div>
|
|
66
|
+
<HorizontalMarquee duration={duration}>{children}</HorizontalMarquee>
|
|
67
|
+
</div>
|
|
68
|
+
</Root>
|
|
69
|
+
) : (
|
|
70
|
+
<HorizontalMarquee
|
|
71
|
+
as={RootAs}
|
|
72
|
+
{...props}
|
|
73
|
+
className={className}
|
|
74
|
+
style={rootStyle}
|
|
75
|
+
{...{ maxWidth, duration, height }}
|
|
76
|
+
>
|
|
77
|
+
{children}
|
|
78
|
+
</HorizontalMarquee>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
HorizontalMarquee.displayName = 'HorizontalMarquee';
|
|
84
|
+
|
|
85
|
+
HorizontalMarqueeBox.displayName = 'HorizontalMarqueeBox';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ComponentPropsWithRef } from 'react';
|
|
3
|
+
|
|
4
|
+
import { polymorphic } from '../Polymorphic';
|
|
5
|
+
|
|
6
|
+
export type IconProps = ComponentPropsWithRef<'span'> & {
|
|
7
|
+
name: string;
|
|
8
|
+
size?: number;
|
|
9
|
+
};
|
|
10
|
+
export const Icon = polymorphic<IconProps>(
|
|
11
|
+
({ as: Root = 'span', className, style, name, size, ...props }) => (
|
|
12
|
+
<Root
|
|
13
|
+
className={classNames(`bi-${name}`, className)}
|
|
14
|
+
style={{ fontSize: size && `${size}rem`, ...style }}
|
|
15
|
+
{...props}
|
|
16
|
+
/>
|
|
17
|
+
)
|
|
18
|
+
);
|
|
19
|
+
Icon.displayName = 'Icon';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
import { polymorphic } from '../Polymorphic';
|
|
4
|
+
import { Spinner } from '../Spinner';
|
|
5
|
+
|
|
6
|
+
export interface LoadingProps extends HTMLAttributes<HTMLDivElement> {
|
|
7
|
+
opacity?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const Loading = polymorphic<LoadingProps>(
|
|
11
|
+
({
|
|
12
|
+
as: Root = 'div',
|
|
13
|
+
className = '',
|
|
14
|
+
children = 'Loading...',
|
|
15
|
+
opacity = 25,
|
|
16
|
+
style,
|
|
17
|
+
...props
|
|
18
|
+
}) => (
|
|
19
|
+
<Root
|
|
20
|
+
className={`fixed-top h-100 w-100 d-flex justify-content-center align-items-center bg-black ${className}`}
|
|
21
|
+
style={{ ...style, opacity: opacity / 100 }}
|
|
22
|
+
{...props}
|
|
23
|
+
>
|
|
24
|
+
<Spinner theme="success" />
|
|
25
|
+
|
|
26
|
+
<span className="ms-3 fg-white">{children}</span>
|
|
27
|
+
</Root>
|
|
28
|
+
)
|
|
29
|
+
);
|
|
30
|
+
Loading.displayName = 'Loading';
|
|
@@ -4,12 +4,13 @@ import classNames from 'classnames';
|
|
|
4
4
|
import { action, computed, observable } from 'mobx';
|
|
5
5
|
import { observer } from 'mobx-react';
|
|
6
6
|
import { ObservedComponent } from 'mobx-react-helper';
|
|
7
|
-
import { HTMLAttributes, MouseEvent, ReactNode } from 'react';
|
|
7
|
+
import { ElementType, HTMLAttributes, MouseEvent, ReactNode } from 'react';
|
|
8
8
|
import { changeMonth, Day, formatDate, splitArray, TimeData } from 'web-utility';
|
|
9
9
|
|
|
10
|
-
import { Badge } from '
|
|
11
|
-
import { Button, type ComponentTheme } from '
|
|
12
|
-
import { text2color } from '
|
|
10
|
+
import { Badge } from '../Badge';
|
|
11
|
+
import { Button, type ComponentTheme } from '../Button';
|
|
12
|
+
import { text2color } from '../color';
|
|
13
|
+
import { AsProps, PolymorphicClassProps } from '../Polymorphic';
|
|
13
14
|
import { OverlayBox } from './OverlayBox';
|
|
14
15
|
|
|
15
16
|
export interface DateData {
|
|
@@ -33,12 +34,24 @@ export interface MonthCalendarProps extends Omit<
|
|
|
33
34
|
* Re-implement from https://github.com/EasyWebApp/BootCell/blob/3d30027a97fe0a8c4ab8fabc8dfef22aede04de7/source/Calendar/MonthCalendar.tsx
|
|
34
35
|
*/
|
|
35
36
|
@observer
|
|
36
|
-
export class MonthCalendar extends ObservedComponent<
|
|
37
|
+
export class MonthCalendar<T extends ElementType | undefined = 'table'> extends ObservedComponent<
|
|
38
|
+
PolymorphicClassProps<T, MonthCalendarProps>
|
|
39
|
+
> {
|
|
40
|
+
declare readonly props: PolymorphicClassProps<T, MonthCalendarProps>;
|
|
41
|
+
|
|
42
|
+
protected get componentProps(): Readonly<MonthCalendarProps & AsProps> {
|
|
43
|
+
return this.props;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected get observedComponentProps(): MonthCalendarProps & AsProps {
|
|
47
|
+
return this.observedProps;
|
|
48
|
+
}
|
|
49
|
+
|
|
37
50
|
static displayName = 'MonthCalendar';
|
|
38
51
|
|
|
39
52
|
@computed
|
|
40
53
|
get weekFormatter() {
|
|
41
|
-
const { locale = globalThis.navigator?.language } = this.
|
|
54
|
+
const { locale = globalThis.navigator?.language } = this.observedComponentProps;
|
|
42
55
|
|
|
43
56
|
return new Intl.DateTimeFormat(locale, { weekday: 'long' });
|
|
44
57
|
}
|
|
@@ -63,7 +76,7 @@ export class MonthCalendar extends ObservedComponent<MonthCalendarProps> {
|
|
|
63
76
|
changeMonth(delta: number) {
|
|
64
77
|
this.currentDate = changeMonth(this.currentDate, delta);
|
|
65
78
|
|
|
66
|
-
this.
|
|
79
|
+
this.componentProps.onChange?.(this.currentDate);
|
|
67
80
|
}
|
|
68
81
|
|
|
69
82
|
changePreviousMonth = () => this.changeMonth(-1);
|
|
@@ -77,16 +90,16 @@ export class MonthCalendar extends ObservedComponent<MonthCalendarProps> {
|
|
|
77
90
|
|
|
78
91
|
const date = targetItem.dataset.calendarDate;
|
|
79
92
|
const index = Number(targetItem.dataset.calendarIndex);
|
|
80
|
-
const items = this.
|
|
93
|
+
const items = this.componentProps.value?.filter(
|
|
81
94
|
({ date: itemDate }) => formatDate(itemDate, 'YYYY-MM-DD') === date
|
|
82
95
|
);
|
|
83
96
|
const item = items?.[index];
|
|
84
97
|
|
|
85
|
-
if (item) this.
|
|
98
|
+
if (item) this.componentProps.onSelect?.(item);
|
|
86
99
|
};
|
|
87
100
|
|
|
88
101
|
renderDate = (date: Date) => {
|
|
89
|
-
const { value } = this.
|
|
102
|
+
const { value } = this.observedComponentProps,
|
|
90
103
|
dateText = formatDate(date, 'YYYY-MM-DD');
|
|
91
104
|
const list = value?.filter(({ date }) => formatDate(date, 'YYYY-MM-DD') === dateText);
|
|
92
105
|
|
|
@@ -125,18 +138,21 @@ export class MonthCalendar extends ObservedComponent<MonthCalendarProps> {
|
|
|
125
138
|
};
|
|
126
139
|
|
|
127
140
|
render() {
|
|
141
|
+
const Root: ElementType = this.componentProps.as ?? 'table';
|
|
142
|
+
|
|
128
143
|
const { weekFormatter, currentDate, dateGrid } = this,
|
|
129
144
|
{
|
|
145
|
+
as: _as,
|
|
130
146
|
className = '',
|
|
131
147
|
style,
|
|
132
148
|
theme = 'primary',
|
|
133
149
|
onChange: _onChange,
|
|
134
150
|
onSelect: _onSelect,
|
|
135
151
|
...props
|
|
136
|
-
} = this.
|
|
152
|
+
} = this.observedComponentProps;
|
|
137
153
|
|
|
138
154
|
return (
|
|
139
|
-
<
|
|
155
|
+
<Root
|
|
140
156
|
{...props}
|
|
141
157
|
className={`table ${className}`}
|
|
142
158
|
style={{ tableLayout: 'fixed', ...style }}
|
|
@@ -173,7 +189,7 @@ export class MonthCalendar extends ObservedComponent<MonthCalendarProps> {
|
|
|
173
189
|
<tr key={days[0] + ''}>{days.map(this.renderDate)}</tr>
|
|
174
190
|
))}
|
|
175
191
|
</tbody>
|
|
176
|
-
</
|
|
192
|
+
</Root>
|
|
177
193
|
);
|
|
178
194
|
}
|
|
179
195
|
}
|