foxit-component 0.0.1-alpha.1 → 0.0.1-alpha.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/es/Button/Button.d.ts +8 -11
- package/es/Button/Button.js +4 -6
- package/es/Button/button.css.js +1 -1
- package/es/Checkbox/Checkbox.d.ts +10 -0
- package/es/Checkbox/Checkbox.js +19 -0
- package/es/Checkbox/checkbox.css.js +6 -0
- package/es/Empty/Empty.d.ts +7 -0
- package/es/Empty/Empty.js +11 -0
- package/es/Empty/empty.css.js +6 -0
- package/es/Form/Form.d.ts +14 -0
- package/es/Form/Form.js +38 -0
- package/es/Form/Form.types.d.ts +39 -0
- package/es/Form/FormContext.d.ts +3 -0
- package/es/Form/FormContext.js +5 -0
- package/es/Form/FormItem.d.ts +16 -0
- package/es/Form/FormItem.js +35 -0
- package/es/Form/FormProvider.d.ts +10 -0
- package/es/Form/FormProvider.js +227 -0
- package/es/Form/form.css.js +6 -0
- package/es/Icon/index.d.ts +7 -0
- package/es/Icon/index.js +9 -0
- package/es/Input/Input.d.ts +13 -0
- package/es/Input/Input.js +28 -0
- package/es/Input/input.css.js +6 -0
- package/es/Menu/Menu.d.ts +22 -0
- package/es/Menu/Menu.js +50 -0
- package/es/Menu/menu.css.js +6 -0
- package/es/Modal/Modal.d.ts +20 -0
- package/es/Modal/Modal.js +39 -0
- package/es/Modal/ModalTemp.d.ts +11 -0
- package/es/Modal/ModalTemp.js +72 -0
- package/es/Modal/modal.css.js +6 -0
- package/es/Pagination/Pagination.d.ts +10 -0
- package/es/Pagination/Pagination.js +82 -0
- package/es/Pagination/pagination.css.js +6 -0
- package/es/Radio/Radio.d.ts +18 -0
- package/es/Radio/Radio.js +45 -0
- package/es/Radio/radio.css.js +6 -0
- package/es/Select/Select.d.ts +17 -0
- package/es/Select/Select.js +42 -0
- package/es/Table/Table.d.ts +15 -0
- package/es/Table/Table.js +15 -0
- package/es/Table/table.css.js +6 -0
- package/es/Tabs/Tabs.d.ts +14 -0
- package/es/Tabs/Tabs.js +22 -0
- package/es/Tabs/tabs.css.js +6 -0
- package/es/Tag/Tag.d.ts +8 -0
- package/es/Tag/Tag.js +11 -0
- package/es/Tag/tag.css.js +6 -0
- package/es/Toast/Toast.d.ts +5 -0
- package/es/Toast/Toast.js +44 -0
- package/es/Toast/Toast.types.d.ts +5 -0
- package/es/Toast/ToastContainer.d.ts +3 -0
- package/es/Toast/ToastContainer.js +47 -0
- package/es/Toast/ToastManager.d.ts +8 -0
- package/es/Toast/ToastManager.js +19 -0
- package/es/Toast/index.d.ts +8 -0
- package/es/Toast/index.js +39 -0
- package/es/Toast/toast.css.js +6 -0
- package/es/Tooltip/Tooltip.d.ts +8 -0
- package/es/Tooltip/Tooltip.js +31 -0
- package/es/Tooltip/tooltip.css.js +6 -0
- package/es/constants/icons.d.ts +24 -0
- package/es/constants/icons.js +29 -0
- package/es/index.d.ts +33 -0
- package/es/index.js +16 -0
- package/es/node_modules/style-inject/dist/style-inject.es.js +1 -1
- package/es/node_modules/tslib/tslib.es6.js +11 -1
- package/package.json +1 -1
package/es/Button/Button.d.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import './button.css';
|
|
2
|
+
import React from 'react';
|
|
2
3
|
export interface ButtonProps {
|
|
3
|
-
/** Is this the principal call to action on the page? */
|
|
4
4
|
primary?: boolean;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/** How large should the button be? */
|
|
8
|
-
size?: "small" | "medium" | "large";
|
|
9
|
-
/** Button contents */
|
|
10
|
-
label: string;
|
|
11
|
-
/** Optional click handler */
|
|
5
|
+
size?: 'small' | 'medium' | 'large';
|
|
6
|
+
children?: React.ReactNode;
|
|
12
7
|
onClick?: () => void;
|
|
8
|
+
className?: string;
|
|
9
|
+
style?: React.CSSProperties;
|
|
10
|
+
[key: string]: unknown;
|
|
13
11
|
}
|
|
14
|
-
|
|
15
|
-
export declare const Button: ({ primary, size, backgroundColor, label, ...props }: ButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export declare const Button: ({ primary, size, children, ...props }: ButtonProps) => import("react/jsx-runtime").JSX.Element;
|
package/es/Button/Button.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { __rest, __assign } from '../node_modules/tslib/tslib.es6.js';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import classNames from 'classnames';
|
|
3
4
|
import './button.css.js';
|
|
4
5
|
|
|
5
|
-
/** Primary UI component for user interaction */
|
|
6
6
|
var Button = function (_a) {
|
|
7
|
-
var _b = _a.primary, primary = _b === void 0 ? false : _b, _c = _a.size, size = _c === void 0 ?
|
|
8
|
-
var mode = primary
|
|
9
|
-
|
|
10
|
-
: "storybook-button--secondary";
|
|
11
|
-
return (jsx("button", __assign({ type: "button", className: ["storybook-button", "storybook-button--".concat(size), mode].join(" "), style: { backgroundColor: backgroundColor } }, props, { children: label })));
|
|
7
|
+
var _b = _a.primary, primary = _b === void 0 ? false : _b, _c = _a.size, size = _c === void 0 ? 'large' : _c, _d = _a.children, children = _d === void 0 ? '' : _d, props = __rest(_a, ["primary", "size", "children"]);
|
|
8
|
+
var mode = primary ? 'foxit-button-primary' : 'foxit-button-secondary';
|
|
9
|
+
return (jsx("button", __assign({ type: "button", className: classNames('foxit-button', "foxit-button-".concat(size), mode, props.className), style: props.style }, props, { children: children })));
|
|
12
10
|
};
|
|
13
11
|
|
|
14
12
|
export { Button };
|
package/es/Button/button.css.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import styleInject from '../node_modules/style-inject/dist/style-inject.es.js';
|
|
2
2
|
|
|
3
|
-
var css_248z = ".
|
|
3
|
+
var css_248z = ".foxit-button {\n display: flex;\n justify-content: center;\n align-items: center;\n cursor: pointer;\n border: 0;\n border-radius: 10px;\n font-weight: 600;\n font-size: 14px;\n line-height: 18px;\n padding: 19px 32px;\n letter-spacing: 0.42px;\n}\n.foxit-button-primary {\n background-color: #ff5f00;\n color: white;\n}\n.foxit-button-secondary {\n border: 2px solid #ff5f00;\n background-color: white;\n color: #ff5f00;\n}\n.foxit-button-small {\n padding: 10px 24px;\n border-radius: 5px;\n}\n.foxit-button-medium {\n padding: 13px 32px;\n border-radius: 5px;\n}\n.foxit-button-large {\n padding: 19px 32px;\n}\n";
|
|
4
4
|
styleInject(css_248z);
|
|
5
5
|
|
|
6
6
|
export { css_248z as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './checkbox.css';
|
|
3
|
+
interface CheckboxProps {
|
|
4
|
+
onChange?: (checked: boolean) => void;
|
|
5
|
+
checked?: boolean;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
declare const Checkbox: React.FC<CheckboxProps>;
|
|
10
|
+
export default Checkbox;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { __assign } from '../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import './checkbox.css.js';
|
|
5
|
+
|
|
6
|
+
var Checkbox = function (_a) {
|
|
7
|
+
var onChange = _a.onChange, checked = _a.checked, _b = _a.disabled, disabled = _b === void 0 ? false : _b, children = _a.children;
|
|
8
|
+
var _c = useState(checked || false), internalChecked = _c[0], setInternalChecked = _c[1];
|
|
9
|
+
var handleChange = function (e) {
|
|
10
|
+
var newChecked = e.target.checked;
|
|
11
|
+
setInternalChecked(newChecked);
|
|
12
|
+
if (onChange) {
|
|
13
|
+
onChange(newChecked);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
return (jsxs("label", __assign({ className: "foxit-checkbox-container ".concat(disabled ? 'disabled' : '') }, { children: [jsx("input", { type: "checkbox", checked: checked !== undefined ? checked : internalChecked, disabled: disabled, onChange: handleChange }), jsx("span", { className: "foxit-checkbox-checkmark ".concat(disabled ? 'disabled' : '') }), jsx("span", __assign({ className: "foxit-checkbox-content" }, { children: children }))] })));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { Checkbox as default };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import styleInject from '../node_modules/style-inject/dist/style-inject.es.js';
|
|
2
|
+
|
|
3
|
+
var css_248z = ".foxit-checkbox-container {\n display: inline-block;\n position: relative;\n padding-left: 25px;\n cursor: pointer;\n -webkit-user-select: none;\n user-select: none;\n}\n\n.foxit-checkbox-container input {\n position: absolute;\n opacity: 0;\n cursor: pointer;\n}\n\n.foxit-checkbox-checkmark {\n position: absolute;\n top: 0;\n left: 0;\n height: 20px;\n width: 20px;\n background-color: #fff;\n border: 1px solid #b3b3b3;\n border-radius: 4px;\n}\n\n.foxit-checkbox-content {\n line-height: 20px;\n}\n\n.foxit-checkbox-container input:checked ~ .foxit-checkbox-checkmark {\n background-color: #ff5f00;\n border: none;\n}\n\n.foxit-checkbox-checkmark:after {\n content: '';\n position: absolute;\n display: none;\n}\n\n.foxit-checkbox-container input:checked ~ .foxit-checkbox-checkmark:after {\n display: block;\n}\n\n.foxit-checkbox-container .foxit-checkbox-checkmark:after {\n left: 7px;\n top: 4px;\n width: 6px;\n height: 10px;\n border: solid white;\n border-width: 0 2px 2px 0;\n transform: rotate(45deg);\n}\n\n.foxit-checkbox-container.disabled {\n cursor: not-allowed;\n opacity: 0.6;\n color: #00000040;\n}\n\n.foxit-checkbox-checkmark.disabled {\n background-color: #f5f5f5;\n border: 1px solid #d9d9d9;\n}\n";
|
|
4
|
+
styleInject(css_248z);
|
|
5
|
+
|
|
6
|
+
export { css_248z as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { __assign } from '../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { Icon } from '../Icon/index.js';
|
|
4
|
+
import './empty.css.js';
|
|
5
|
+
|
|
6
|
+
var Empty = function (_a) {
|
|
7
|
+
var description = _a.description;
|
|
8
|
+
return (jsxs("div", __assign({ className: "foxit-empty" }, { children: [jsx("div", __assign({ className: "foxit-empty-image" }, { children: jsx(Icon, { name: "EmptyColoursOutlined" }) })), jsx("div", __assign({ className: "foxit-empty-description" }, { children: description }))] })));
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { Empty as default };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import styleInject from '../node_modules/style-inject/dist/style-inject.es.js';
|
|
2
|
+
|
|
3
|
+
var css_248z = ".foxit-empty {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n text-align: center;\n padding: 20px;\n}\n\n.foxit-empty-image {\n margin-bottom: 16px;\n}\n\n.foxit-empty-description {\n font-size: 14px;\n color: #757575;\n}\n";
|
|
4
|
+
styleInject(css_248z);
|
|
5
|
+
|
|
6
|
+
export { css_248z as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { FormRefInstance } from './Form.types';
|
|
3
|
+
import FormItem from './FormItem';
|
|
4
|
+
export type { FormRefInstance } from './Form.types';
|
|
5
|
+
interface FormProps {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
onFinish?: (values: unknown) => void;
|
|
8
|
+
initialValues?: {
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export { FormItem };
|
|
13
|
+
declare const _default: React.ForwardRefExoticComponent<FormProps & React.RefAttributes<FormRefInstance>>;
|
|
14
|
+
export default _default;
|
package/es/Form/Form.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { __assign } from '../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { forwardRef, useRef, useCallback, useImperativeHandle } from 'react';
|
|
4
|
+
import FormProvider from './FormProvider.js';
|
|
5
|
+
import './FormContext.js';
|
|
6
|
+
import './form.css.js';
|
|
7
|
+
|
|
8
|
+
var Form = function (_a, ref) {
|
|
9
|
+
var children = _a.children, onFinish = _a.onFinish, initialValues = _a.initialValues;
|
|
10
|
+
var formRef = useRef(null);
|
|
11
|
+
var handleSubmit = useCallback(function (e) {
|
|
12
|
+
var _a;
|
|
13
|
+
e.preventDefault();
|
|
14
|
+
if (onFinish) {
|
|
15
|
+
if (onFinish && formRef.current) {
|
|
16
|
+
(_a = formRef === null || formRef === void 0 ? void 0 : formRef.current) === null || _a === void 0 ? void 0 : _a.validateFields().then(function (values) {
|
|
17
|
+
onFinish(values);
|
|
18
|
+
}).catch(function (errors) {
|
|
19
|
+
console.error('Validation errors:', errors);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}, [onFinish]);
|
|
24
|
+
useImperativeHandle(ref, function () {
|
|
25
|
+
var _a, _b, _c, _d, _e;
|
|
26
|
+
return ({
|
|
27
|
+
setFieldsValue: (_a = formRef.current) === null || _a === void 0 ? void 0 : _a.setFieldsValue,
|
|
28
|
+
getFieldsValue: (_b = formRef.current) === null || _b === void 0 ? void 0 : _b.getFieldsValue,
|
|
29
|
+
resetFields: (_c = formRef.current) === null || _c === void 0 ? void 0 : _c.resetFields,
|
|
30
|
+
validateFields: (_d = formRef.current) === null || _d === void 0 ? void 0 : _d.validateFields,
|
|
31
|
+
setFieldsStatus: (_e = formRef.current) === null || _e === void 0 ? void 0 : _e.setFieldsStatus
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
return (jsx(FormProvider, __assign({ initialValues: initialValues, ref: formRef }, { children: jsx("form", __assign({ onSubmit: handleSubmit }, { children: children })) })));
|
|
35
|
+
};
|
|
36
|
+
var Form$1 = forwardRef(Form);
|
|
37
|
+
|
|
38
|
+
export { Form$1 as default };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface FormField {
|
|
2
|
+
value: unknown;
|
|
3
|
+
error?: string;
|
|
4
|
+
warning?: string;
|
|
5
|
+
rules?: ValidationRule[];
|
|
6
|
+
}
|
|
7
|
+
export interface ValidationRule {
|
|
8
|
+
required?: boolean;
|
|
9
|
+
message?: string;
|
|
10
|
+
type?: 'email' | 'number' | 'string' | 'min' | 'max';
|
|
11
|
+
min?: number;
|
|
12
|
+
max?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface FormInstance {
|
|
15
|
+
setFieldsValue: (values: {
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}) => void;
|
|
18
|
+
getFieldsValue: (names?: string[]) => {
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
};
|
|
21
|
+
resetFields: (names?: string[]) => void;
|
|
22
|
+
validateFields: (names?: string[]) => Promise<{
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}>;
|
|
25
|
+
setFieldsStatus: (status: {
|
|
26
|
+
type: 'error' | 'warning';
|
|
27
|
+
name: string | string[];
|
|
28
|
+
message: string;
|
|
29
|
+
}[]) => void;
|
|
30
|
+
registerField: (name: string, rules: ValidationRule[]) => void;
|
|
31
|
+
unregisterField: (name: string) => void;
|
|
32
|
+
}
|
|
33
|
+
export type FormRefInstance = Omit<FormInstance, 'registerField' | 'unregisterField'>;
|
|
34
|
+
export interface FormContextProps {
|
|
35
|
+
form: FormInstance;
|
|
36
|
+
formFields: {
|
|
37
|
+
[key: string]: FormField;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import './form.css';
|
|
3
|
+
interface FormItemProps {
|
|
4
|
+
name: string;
|
|
5
|
+
label?: string;
|
|
6
|
+
rules?: {
|
|
7
|
+
required?: boolean;
|
|
8
|
+
message?: string;
|
|
9
|
+
type?: 'email' | 'number' | 'string' | 'min' | 'max';
|
|
10
|
+
min?: number;
|
|
11
|
+
max?: number;
|
|
12
|
+
}[];
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
declare const FormItem: React.FC<FormItemProps>;
|
|
16
|
+
export default FormItem;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { __assign } from '../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import React, { useContext, useEffect, useCallback } from 'react';
|
|
4
|
+
import { FormContext } from './FormContext.js';
|
|
5
|
+
import './form.css.js';
|
|
6
|
+
|
|
7
|
+
var FormItem = function (_a) {
|
|
8
|
+
var _b, _c, _d;
|
|
9
|
+
var name = _a.name, label = _a.label, _e = _a.rules, rules = _e === void 0 ? [] : _e, children = _a.children;
|
|
10
|
+
var _f = useContext(FormContext), form = _f.form, formFields = _f.formFields;
|
|
11
|
+
// Register field when component mounts
|
|
12
|
+
useEffect(function () {
|
|
13
|
+
form.registerField(name, rules);
|
|
14
|
+
return function () {
|
|
15
|
+
form.unregisterField(name);
|
|
16
|
+
};
|
|
17
|
+
}, []);
|
|
18
|
+
var error = (_b = formFields[name]) === null || _b === void 0 ? void 0 : _b.error;
|
|
19
|
+
var warning = (_c = formFields[name]) === null || _c === void 0 ? void 0 : _c.warning;
|
|
20
|
+
var value = (_d = formFields[name]) === null || _d === void 0 ? void 0 : _d.value;
|
|
21
|
+
var handleChange = useCallback(function (e) {
|
|
22
|
+
var _a;
|
|
23
|
+
var _b;
|
|
24
|
+
var newValue = ((_b = e === null || e === void 0 ? void 0 : e.target) === null || _b === void 0 ? void 0 : _b.value) !== undefined ? e.target.value : e;
|
|
25
|
+
form.setFieldsValue((_a = {}, _a[name] = newValue, _a));
|
|
26
|
+
}, [form, name]);
|
|
27
|
+
return (jsxs("div", __assign({ className: "foxit-form-item" }, { children: [label && jsx("label", { children: label }), jsx("span", __assign({ className: "".concat(error ? 'foxit-form-error-component' : warning ? 'foxit-form-warning-component' : '') }, { children: React.Children.map(children, function (child) {
|
|
28
|
+
return React.cloneElement(child, {
|
|
29
|
+
value: value,
|
|
30
|
+
onChange: handleChange
|
|
31
|
+
});
|
|
32
|
+
}) })), error && jsx("div", __assign({ className: "foxit-form-error-text" }, { children: error })), warning && jsx("div", __assign({ className: "foxit-form-warning-text" }, { children: warning }))] })));
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { FormItem as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FormInstance } from './Form.types';
|
|
3
|
+
interface FormProviderProps {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
initialValues?: {
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
declare const _default: React.ForwardRefExoticComponent<FormProviderProps & React.RefAttributes<FormInstance>>;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { __assign } from '../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { forwardRef, useState, useRef, useEffect, useCallback, useImperativeHandle } from 'react';
|
|
4
|
+
import { FormContext } from './FormContext.js';
|
|
5
|
+
|
|
6
|
+
var FormProvider = function (_a, ref) {
|
|
7
|
+
var children = _a.children, _b = _a.initialValues, initialValues = _b === void 0 ? {} : _b;
|
|
8
|
+
var _c = useState({}), formFields = _c[0], setFormFields = _c[1];
|
|
9
|
+
var formInstanceRef = useRef({});
|
|
10
|
+
// 初始值的设置
|
|
11
|
+
useEffect(function () {
|
|
12
|
+
if (Object.keys(initialValues).length > 0) {
|
|
13
|
+
setFormFields(function (prevFields) {
|
|
14
|
+
var newFields = __assign({}, prevFields);
|
|
15
|
+
for (var key in initialValues) {
|
|
16
|
+
if (!newFields[key]) {
|
|
17
|
+
newFields[key] = { value: initialValues[key], rules: [] };
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
newFields[key] = __assign(__assign({}, newFields[key]), { value: initialValues[key] });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return newFields;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}, [initialValues]);
|
|
27
|
+
// 注册字段
|
|
28
|
+
var registerField = useCallback(function (name, rules) {
|
|
29
|
+
setFormFields(function (prevFields) {
|
|
30
|
+
var _a;
|
|
31
|
+
return (__assign(__assign({}, prevFields), (_a = {}, _a[name] = __assign(__assign({}, prevFields[name]), { rules: rules || [] }), _a)));
|
|
32
|
+
});
|
|
33
|
+
}, []);
|
|
34
|
+
// 销毁字段
|
|
35
|
+
var unregisterField = useCallback(function (name) {
|
|
36
|
+
setFormFields(function (prevFields) {
|
|
37
|
+
var newFields = __assign({}, prevFields);
|
|
38
|
+
delete newFields[name];
|
|
39
|
+
return newFields;
|
|
40
|
+
});
|
|
41
|
+
}, []);
|
|
42
|
+
// 验证字段
|
|
43
|
+
var validateField = useCallback(function (name, value, rules) {
|
|
44
|
+
for (var _i = 0, rules_1 = rules; _i < rules_1.length; _i++) {
|
|
45
|
+
var rule = rules_1[_i];
|
|
46
|
+
if (rule.required &&
|
|
47
|
+
(value === undefined ||
|
|
48
|
+
value === '' ||
|
|
49
|
+
value === null ||
|
|
50
|
+
(Array.isArray(value) && value.length === 0) ||
|
|
51
|
+
(typeof value === 'object' && Object.keys(value).length === 0))) {
|
|
52
|
+
return { type: 'error', message: rule.message || 'This field is required' };
|
|
53
|
+
}
|
|
54
|
+
if (rule.type === 'email' && value && !/\S+@\S+\.\S+/.test(value)) {
|
|
55
|
+
return { type: 'error', message: rule.message || 'The input is not valid E-mail' };
|
|
56
|
+
}
|
|
57
|
+
if (rule.type === 'number' && value && isNaN(Number(value))) {
|
|
58
|
+
return { type: 'error', message: rule.message || 'The input is not a number' };
|
|
59
|
+
}
|
|
60
|
+
if (rule.type === 'string' && typeof value !== 'string') {
|
|
61
|
+
return { type: 'error', message: rule.message || 'The input is not a string' };
|
|
62
|
+
}
|
|
63
|
+
if (rule.min !== undefined && typeof value === 'string' && value.length < rule.min) {
|
|
64
|
+
return {
|
|
65
|
+
type: 'error',
|
|
66
|
+
message: rule.message || "The input is less than ".concat(rule.min, " characters")
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (rule.max !== undefined && typeof value === 'string' && value.length > rule.max) {
|
|
70
|
+
return {
|
|
71
|
+
type: 'error',
|
|
72
|
+
message: rule.message || "The input is more than ".concat(rule.max, " characters")
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}, []);
|
|
78
|
+
// 设置字段值
|
|
79
|
+
var setFieldsValue = useCallback(function (values) {
|
|
80
|
+
setFormFields(function (prevFields) {
|
|
81
|
+
var _a;
|
|
82
|
+
var newFields = __assign({}, prevFields);
|
|
83
|
+
for (var key in values) {
|
|
84
|
+
if (Object.prototype.hasOwnProperty.call(values, key)) {
|
|
85
|
+
var newValue = values[key];
|
|
86
|
+
newFields[key] = __assign(__assign({}, newFields[key]), { value: newValue });
|
|
87
|
+
// 验证字段
|
|
88
|
+
var validation = validateField(key, newValue, ((_a = newFields[key]) === null || _a === void 0 ? void 0 : _a.rules) || []);
|
|
89
|
+
if (validation) {
|
|
90
|
+
if (validation.type === 'error') {
|
|
91
|
+
newFields[key] = __assign(__assign({}, newFields[key]), { error: validation.message, warning: undefined // Clear any previous warnings
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else if (validation.type === 'warning') {
|
|
95
|
+
newFields[key] = __assign(__assign({}, newFields[key]), { warning: validation.message, error: undefined // Clear any previous errors
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
newFields[key] = __assign(__assign({}, newFields[key]), { error: undefined, warning: undefined });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return newFields;
|
|
105
|
+
});
|
|
106
|
+
}, [formFields, validateField]);
|
|
107
|
+
// 获取字段值
|
|
108
|
+
var getFieldsValue = useCallback(function (names) {
|
|
109
|
+
if (!names) {
|
|
110
|
+
return Object.keys(formFields).reduce(function (acc, key) {
|
|
111
|
+
acc[key] = formFields[key].value;
|
|
112
|
+
return acc;
|
|
113
|
+
}, {});
|
|
114
|
+
}
|
|
115
|
+
return names.reduce(function (acc, key) {
|
|
116
|
+
var _a;
|
|
117
|
+
acc[key] = (_a = formFields[key]) === null || _a === void 0 ? void 0 : _a.value;
|
|
118
|
+
return acc;
|
|
119
|
+
}, {});
|
|
120
|
+
}, [formFields]);
|
|
121
|
+
// 重置字段
|
|
122
|
+
var resetFields = useCallback(function (names) {
|
|
123
|
+
setFormFields(function (prevFields) {
|
|
124
|
+
var newFields = __assign({}, prevFields);
|
|
125
|
+
if (names) {
|
|
126
|
+
names.forEach(function (name) {
|
|
127
|
+
if (newFields[name]) {
|
|
128
|
+
newFields[name].value = initialValues[name] || '';
|
|
129
|
+
newFields[name].error = undefined;
|
|
130
|
+
newFields[name].warning = undefined;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
Object.keys(newFields).forEach(function (key) {
|
|
136
|
+
newFields[key].value = initialValues[key] || '';
|
|
137
|
+
newFields[key].error = undefined;
|
|
138
|
+
newFields[key].warning = undefined;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return newFields;
|
|
142
|
+
});
|
|
143
|
+
}, [formFields, initialValues]);
|
|
144
|
+
var validateFields = useCallback(function (names) {
|
|
145
|
+
return new Promise(function (resolve, reject) {
|
|
146
|
+
var fieldsToValidate = names || Object.keys(formFields);
|
|
147
|
+
var values = getFieldsValue(fieldsToValidate);
|
|
148
|
+
var errors = {};
|
|
149
|
+
for (var _i = 0, fieldsToValidate_1 = fieldsToValidate; _i < fieldsToValidate_1.length; _i++) {
|
|
150
|
+
var key = fieldsToValidate_1[_i];
|
|
151
|
+
var field = formFields[key];
|
|
152
|
+
if (!field)
|
|
153
|
+
continue; // Skip if field is not registered
|
|
154
|
+
var validation = validateField(key, values[key], field.rules || []);
|
|
155
|
+
if (validation) {
|
|
156
|
+
if (validation.type === 'error') {
|
|
157
|
+
errors[key] = validation.message;
|
|
158
|
+
}
|
|
159
|
+
else if (validation.type === 'warning') {
|
|
160
|
+
validation.message;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (Object.keys(errors).length > 0) {
|
|
165
|
+
setFormFields(function (prevFields) {
|
|
166
|
+
var newFields = __assign({}, prevFields);
|
|
167
|
+
for (var key in errors) {
|
|
168
|
+
newFields[key] = __assign(__assign({}, newFields[key]), { error: errors[key] });
|
|
169
|
+
}
|
|
170
|
+
return newFields;
|
|
171
|
+
});
|
|
172
|
+
reject(errors);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
resolve(values);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}, [formFields, getFieldsValue, validateField]);
|
|
179
|
+
var setFieldsStatus = useCallback(function (status) {
|
|
180
|
+
setFormFields(function (prevFields) {
|
|
181
|
+
var newFields = __assign({}, prevFields);
|
|
182
|
+
status.forEach(function (_a) {
|
|
183
|
+
var type = _a.type, name = _a.name, message = _a.message;
|
|
184
|
+
if (Array.isArray(name)) {
|
|
185
|
+
name.forEach(function (n) {
|
|
186
|
+
if (newFields[n]) {
|
|
187
|
+
// Only update if field exists
|
|
188
|
+
if (type === 'error') {
|
|
189
|
+
newFields[n] = __assign(__assign({}, newFields[n]), { error: message });
|
|
190
|
+
}
|
|
191
|
+
else if (type === 'warning') {
|
|
192
|
+
newFields[n] = __assign(__assign({}, newFields[n]), { warning: message });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
if (newFields[name]) {
|
|
199
|
+
// Only update if field exists
|
|
200
|
+
if (type === 'error') {
|
|
201
|
+
newFields[name] = __assign(__assign({}, newFields[name]), { error: message });
|
|
202
|
+
}
|
|
203
|
+
else if (type === 'warning') {
|
|
204
|
+
newFields[name] = __assign(__assign({}, newFields[name]), { warning: message });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
return newFields;
|
|
210
|
+
});
|
|
211
|
+
}, [formFields]);
|
|
212
|
+
// 暴露给外部的方法
|
|
213
|
+
useImperativeHandle(ref, function () { return (__assign({}, formInstanceRef.current)); });
|
|
214
|
+
formInstanceRef.current = {
|
|
215
|
+
setFieldsValue: setFieldsValue,
|
|
216
|
+
getFieldsValue: getFieldsValue,
|
|
217
|
+
resetFields: resetFields,
|
|
218
|
+
validateFields: validateFields,
|
|
219
|
+
setFieldsStatus: setFieldsStatus,
|
|
220
|
+
registerField: registerField,
|
|
221
|
+
unregisterField: unregisterField
|
|
222
|
+
};
|
|
223
|
+
return (jsx(FormContext.Provider, __assign({ value: { form: formInstanceRef.current, formFields: formFields } }, { children: children })));
|
|
224
|
+
};
|
|
225
|
+
var FormProvider$1 = forwardRef(FormProvider);
|
|
226
|
+
|
|
227
|
+
export { FormProvider$1 as default };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import styleInject from '../node_modules/style-inject/dist/style-inject.es.js';
|
|
2
|
+
|
|
3
|
+
var css_248z = ".foxit-form-item {\n margin-bottom: 16px;\n}\n\n.foxit-form-item label {\n display: block;\n margin-bottom: 8px;\n font-weight: 500;\n font-size: 14px;\n color: #525252;\n}\n\n.foxit-form-error-text {\n margin-top: 8px;\n color: red;\n}\n\n.foxit-form-warning-text {\n margin-top: 8px;\n color: orange;\n}\n\n.foxit-form-item > .foxit-form-error-component .foxit-input-wrapper,\n.foxit-form-item > .foxit-form-error-component .foxit-select-wrapper > :nth-child(3),\n.foxit-form-item > .foxit-form-error-component .foxit-checkbox-container,\n.foxit-form-item > .foxit-form-error-component .foxit-radio-container {\n border: 1px solid red !important;\n}\n\n.foxit-form-item > .foxit-form-warning-component .foxit-input-wrapper,\n.foxit-form-item > .foxit-form-warning-component .foxit-select-wrapper > :nth-child(3),\n.foxit-form-item > .foxit-form-warning-component .foxit-checkbox-container,\n.foxit-form-item > .foxit-form-warning-component .foxit-radio-container {\n border-color: orange !important;\n}\n";
|
|
4
|
+
styleInject(css_248z);
|
|
5
|
+
|
|
6
|
+
export { css_248z as default };
|
package/es/Icon/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './input.css';
|
|
3
|
+
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
4
|
+
addonAfter?: React.ReactNode;
|
|
5
|
+
}
|
|
6
|
+
declare const Input: React.FC<InputProps>;
|
|
7
|
+
interface SearchInputProps extends InputProps {
|
|
8
|
+
onSearch?: (value: string) => void;
|
|
9
|
+
}
|
|
10
|
+
declare const SearchInput: React.FC<SearchInputProps>;
|
|
11
|
+
declare const PasswordInput: React.FC<InputProps>;
|
|
12
|
+
export default Input;
|
|
13
|
+
export { SearchInput, PasswordInput };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { __rest, __assign } from '../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import './input.css.js';
|
|
5
|
+
import { Icon } from '../Icon/index.js';
|
|
6
|
+
|
|
7
|
+
var Input = function (_a) {
|
|
8
|
+
var addonAfter = _a.addonAfter, rest = __rest(_a, ["addonAfter"]);
|
|
9
|
+
return (jsxs("div", __assign({ className: "foxit-input-wrapper" }, { children: [jsx("input", __assign({}, rest, { className: "foxit-input-element" })), addonAfter && jsx("div", __assign({ className: "foxit-input-addon" }, { children: addonAfter }))] })));
|
|
10
|
+
};
|
|
11
|
+
var SearchInput = function (_a) {
|
|
12
|
+
var onSearch = _a.onSearch, rest = __rest(_a, ["onSearch"]);
|
|
13
|
+
var handleSearch = function () {
|
|
14
|
+
if (onSearch) {
|
|
15
|
+
onSearch(rest.value);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
return (jsx(Input, __assign({}, rest, { addonAfter: jsx("div", __assign({ style: { display: 'flex' }, onClick: handleSearch }, { children: jsx(Icon, { name: "SearchOutlined" }) })) })));
|
|
19
|
+
};
|
|
20
|
+
var PasswordInput = function (props) {
|
|
21
|
+
var _a = useState(false), visible = _a[0], setVisible = _a[1];
|
|
22
|
+
var toggleVisibility = function () {
|
|
23
|
+
setVisible(!visible);
|
|
24
|
+
};
|
|
25
|
+
return (jsx(Input, __assign({}, props, { type: visible ? 'text' : 'password', addonAfter: jsx("div", __assign({ style: { display: 'flex' }, onClick: toggleVisibility }, { children: jsx(Icon, { name: visible ? 'EyeOutlined' : 'EyeInvisibleOutlined' }) })) })));
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { PasswordInput, SearchInput, Input as default };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import styleInject from '../node_modules/style-inject/dist/style-inject.es.js';
|
|
2
|
+
|
|
3
|
+
var css_248z = ".foxit-input-wrapper {\n display: flex;\n align-items: center;\n border: 1px solid #d9d9d9;\n border-radius: 10px;\n padding: 11px 16px;\n transition: border-color 0.3s;\n font-size: 14px;\n font-weight: 400;\n}\n\n.foxit-input-wrapper:focus-within {\n border-color: #ff5f00 !important;\n}\n.foxit-input-wrapper:hover {\n border-color: #757575;\n}\n\n.foxit-input-element {\n flex: 1;\n border: none;\n outline: none;\n color: #525252;\n line-height: 24px;\n}\n\n.foxit-input-element::placeholder {\n color: #b3b3b3;\n}\n\n.foxit-input-addon {\n display: flex;\n align-items: center;\n padding: 0 8px;\n cursor: pointer;\n color: #b3b3b3;\n transition: color 0.3s;\n}\n\n.foxit-input-wrapper:focus-within .foxit-input-addon {\n color: #ff5f00 !important;\n}\n.foxit-input-wrapper:hover .foxit-input-addon {\n color: #757575;\n}\n";
|
|
4
|
+
styleInject(css_248z);
|
|
5
|
+
|
|
6
|
+
export { css_248z as default };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ReactNode, Key } from 'react';
|
|
3
|
+
import './menu.css';
|
|
4
|
+
export interface MenuItem {
|
|
5
|
+
key: Key;
|
|
6
|
+
icon?: ReactNode;
|
|
7
|
+
children?: MenuItem[];
|
|
8
|
+
label: ReactNode;
|
|
9
|
+
type?: 'group';
|
|
10
|
+
}
|
|
11
|
+
interface MenuProps {
|
|
12
|
+
items: MenuItem[];
|
|
13
|
+
onClick?: (e: {
|
|
14
|
+
key: string;
|
|
15
|
+
}) => void;
|
|
16
|
+
defaultSelectedKeys?: string[];
|
|
17
|
+
defaultOpenKeys?: string[];
|
|
18
|
+
style?: React.CSSProperties;
|
|
19
|
+
}
|
|
20
|
+
export declare const getItem: (label: ReactNode, key: Key, icon?: ReactNode, children?: MenuItem[], type?: 'group') => MenuItem;
|
|
21
|
+
declare const Menu: React.FC<MenuProps>;
|
|
22
|
+
export default Menu;
|