@lobehub/ui 5.19.3 → 5.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/Markdown/SyntaxMarkdown/CachedMarkdown.mjs +3 -2
- package/es/Markdown/SyntaxMarkdown/CachedMarkdown.mjs.map +1 -1
- package/es/Markdown/plugins/rehypeStreamAnimated.mjs.map +1 -1
- package/es/ThemeProvider/GlobalStyle/global.mjs +3 -2
- package/es/ThemeProvider/GlobalStyle/global.mjs.map +1 -1
- package/es/ThemeProvider/ThemeProvider.mjs +1 -1
- package/es/ThemeProvider/ThemeProvider.mjs.map +1 -1
- package/es/base-ui/AutoComplete/AutoComplete.d.mts +8 -0
- package/es/base-ui/AutoComplete/AutoComplete.mjs +91 -0
- package/es/base-ui/AutoComplete/AutoComplete.mjs.map +1 -0
- package/es/base-ui/AutoComplete/index.d.mts +3 -0
- package/es/base-ui/AutoComplete/style.d.mts +12 -0
- package/es/base-ui/AutoComplete/style.mjs +76 -0
- package/es/base-ui/AutoComplete/style.mjs.map +1 -0
- package/es/base-ui/AutoComplete/type.d.mts +40 -0
- package/es/base-ui/Button/style.mjs +6 -3
- package/es/base-ui/Button/style.mjs.map +1 -1
- package/es/base-ui/Checkbox/Checkbox.d.mts +8 -0
- package/es/base-ui/Checkbox/Checkbox.mjs +61 -0
- package/es/base-ui/Checkbox/Checkbox.mjs.map +1 -0
- package/es/base-ui/Checkbox/CheckboxGroup.d.mts +8 -0
- package/es/base-ui/Checkbox/CheckboxGroup.mjs +37 -0
- package/es/base-ui/Checkbox/CheckboxGroup.mjs.map +1 -0
- package/es/base-ui/Checkbox/index.d.mts +4 -0
- package/es/base-ui/Checkbox/style.d.mts +9 -0
- package/es/base-ui/Checkbox/style.mjs +70 -0
- package/es/base-ui/Checkbox/style.mjs.map +1 -0
- package/es/base-ui/Checkbox/type.d.mts +51 -0
- package/es/base-ui/Form/Form.mjs +155 -0
- package/es/base-ui/Form/Form.mjs.map +1 -0
- package/es/base-ui/Form/components/FormDivider.d.mts +8 -0
- package/es/base-ui/Form/components/FormDivider.mjs +19 -0
- package/es/base-ui/Form/components/FormDivider.mjs.map +1 -0
- package/es/base-ui/Form/components/FormField.d.mts +8 -0
- package/es/base-ui/Form/components/FormField.mjs +59 -0
- package/es/base-ui/Form/components/FormField.mjs.map +1 -0
- package/es/base-ui/Form/components/FormFlatGroup.d.mts +8 -0
- package/es/base-ui/Form/components/FormFlatGroup.mjs +20 -0
- package/es/base-ui/Form/components/FormFlatGroup.mjs.map +1 -0
- package/es/base-ui/Form/components/FormFooter.d.mts +8 -0
- package/es/base-ui/Form/components/FormFooter.mjs +20 -0
- package/es/base-ui/Form/components/FormFooter.mjs.map +1 -0
- package/es/base-ui/Form/components/FormGroup.d.mts +8 -0
- package/es/base-ui/Form/components/FormGroup.mjs +87 -0
- package/es/base-ui/Form/components/FormGroup.mjs.map +1 -0
- package/es/base-ui/Form/components/FormSubmitFooter.d.mts +8 -0
- package/es/base-ui/Form/components/FormSubmitFooter.mjs +118 -0
- package/es/base-ui/Form/components/FormSubmitFooter.mjs.map +1 -0
- package/es/base-ui/Form/components/FormTitle.d.mts +8 -0
- package/es/base-ui/Form/components/FormTitle.mjs +42 -0
- package/es/base-ui/Form/components/FormTitle.mjs.map +1 -0
- package/es/base-ui/Form/context.d.mts +6 -0
- package/es/base-ui/Form/context.mjs +15 -0
- package/es/base-ui/Form/context.mjs.map +1 -0
- package/es/base-ui/Form/index.d.mts +25 -0
- package/es/base-ui/Form/index.mjs +24 -0
- package/es/base-ui/Form/index.mjs.map +1 -0
- package/es/base-ui/Form/style.mjs +288 -0
- package/es/base-ui/Form/style.mjs.map +1 -0
- package/es/base-ui/Form/type.d.mts +139 -0
- package/es/base-ui/Input/Input.d.mts +8 -0
- package/es/base-ui/Input/Input.mjs +43 -0
- package/es/base-ui/Input/Input.mjs.map +1 -0
- package/es/base-ui/Input/InputNumber.d.mts +8 -0
- package/es/base-ui/Input/InputNumber.mjs +50 -0
- package/es/base-ui/Input/InputNumber.mjs.map +1 -0
- package/es/base-ui/Input/InputOTP.d.mts +8 -0
- package/es/base-ui/Input/InputOTP.mjs +31 -0
- package/es/base-ui/Input/InputOTP.mjs.map +1 -0
- package/es/base-ui/Input/InputPassword.d.mts +8 -0
- package/es/base-ui/Input/InputPassword.mjs +31 -0
- package/es/base-ui/Input/InputPassword.mjs.map +1 -0
- package/es/base-ui/Input/TextArea.d.mts +8 -0
- package/es/base-ui/Input/TextArea.mjs +43 -0
- package/es/base-ui/Input/TextArea.mjs.map +1 -0
- package/es/base-ui/Input/index.d.mts +7 -0
- package/es/base-ui/Input/style.d.mts +33 -0
- package/es/base-ui/Input/style.mjs +230 -0
- package/es/base-ui/Input/style.mjs.map +1 -0
- package/es/base-ui/Input/type.d.mts +122 -0
- package/es/base-ui/Select/style.mjs +4 -3
- package/es/base-ui/Select/style.mjs.map +1 -1
- package/es/base-ui/Slider/Slider.d.mts +8 -0
- package/es/base-ui/Slider/Slider.mjs +34 -0
- package/es/base-ui/Slider/Slider.mjs.map +1 -0
- package/es/base-ui/Slider/SliderWithInput.d.mts +8 -0
- package/es/base-ui/Slider/SliderWithInput.mjs +64 -0
- package/es/base-ui/Slider/SliderWithInput.mjs.map +1 -0
- package/es/base-ui/Slider/index.d.mts +4 -0
- package/es/base-ui/Slider/style.d.mts +11 -0
- package/es/base-ui/Slider/style.mjs +69 -0
- package/es/base-ui/Slider/style.mjs.map +1 -0
- package/es/base-ui/Slider/type.d.mts +47 -0
- package/es/base-ui/controlSize.d.mts +10 -0
- package/es/base-ui/controlSize.mjs +10 -0
- package/es/base-ui/controlSize.mjs.map +1 -0
- package/es/base-ui/index.d.mts +33 -4
- package/es/base-ui/index.mjs +28 -4
- package/es/eslint/index.mjs +25 -15
- package/es/eslint/index.mjs.map +1 -1
- package/es/node_modules/@types/hast/index.d.mts +642 -0
- package/package.json +4 -3
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import Checkbox from "./Checkbox.mjs";
|
|
3
|
+
import { memo, useMemo } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { CheckboxGroup } from "@base-ui/react/checkbox-group";
|
|
6
|
+
//#region src/base-ui/Checkbox/CheckboxGroup.tsx
|
|
7
|
+
const CheckboxGroup$1 = memo(({ options, onChange, gap = 12, horizontal = true, size, shape, textProps, style, ...rest }) => {
|
|
8
|
+
const items = useMemo(() => options.map((option) => typeof option === "string" ? {
|
|
9
|
+
label: option,
|
|
10
|
+
value: option
|
|
11
|
+
} : option), [options]);
|
|
12
|
+
return /* @__PURE__ */ jsx(CheckboxGroup, {
|
|
13
|
+
style: {
|
|
14
|
+
display: "flex",
|
|
15
|
+
flexDirection: horizontal ? "row" : "column",
|
|
16
|
+
flexWrap: "wrap",
|
|
17
|
+
gap,
|
|
18
|
+
...style
|
|
19
|
+
},
|
|
20
|
+
onValueChange: onChange,
|
|
21
|
+
...rest,
|
|
22
|
+
children: items.map((item) => /* @__PURE__ */ jsx(Checkbox, {
|
|
23
|
+
disabled: item.disabled,
|
|
24
|
+
name: item.value,
|
|
25
|
+
shape,
|
|
26
|
+
size,
|
|
27
|
+
textProps,
|
|
28
|
+
value: item.value,
|
|
29
|
+
children: item.label
|
|
30
|
+
}, item.value))
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
CheckboxGroup$1.displayName = "CheckboxGroup";
|
|
34
|
+
//#endregion
|
|
35
|
+
export { CheckboxGroup$1 as default };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=CheckboxGroup.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CheckboxGroup.mjs","names":["CheckboxGroup","BaseCheckboxGroup"],"sources":["../../../src/base-ui/Checkbox/CheckboxGroup.tsx"],"sourcesContent":["'use client';\n\nimport { CheckboxGroup as BaseCheckboxGroup } from '@base-ui/react/checkbox-group';\nimport { memo, useMemo } from 'react';\n\nimport Checkbox from './Checkbox';\nimport type { CheckboxGroupOption, CheckboxGroupProps } from './type';\n\nconst CheckboxGroup = memo<CheckboxGroupProps>(\n ({ options, onChange, gap = 12, horizontal = true, size, shape, textProps, style, ...rest }) => {\n const items = useMemo<CheckboxGroupOption[]>(\n () =>\n options.map((option) =>\n typeof option === 'string' ? { label: option, value: option } : option,\n ),\n [options],\n );\n\n return (\n <BaseCheckboxGroup\n style={{\n display: 'flex',\n flexDirection: horizontal ? 'row' : 'column',\n flexWrap: 'wrap',\n gap,\n ...style,\n }}\n onValueChange={onChange}\n {...rest}\n >\n {items.map((item) => (\n <Checkbox\n disabled={item.disabled}\n key={item.value}\n name={item.value}\n shape={shape}\n size={size}\n textProps={textProps}\n value={item.value}\n >\n {item.label}\n </Checkbox>\n ))}\n </BaseCheckboxGroup>\n );\n },\n);\n\nCheckboxGroup.displayName = 'CheckboxGroup';\n\nexport default CheckboxGroup;\n"],"mappings":";;;;;;AAQA,MAAMA,kBAAgB,MACnB,EAAE,SAAS,UAAU,MAAM,IAAI,aAAa,MAAM,MAAM,OAAO,WAAW,OAAO,GAAG,WAAW;CAC9F,MAAM,QAAQ,cAEV,QAAQ,KAAK,WACX,OAAO,WAAW,WAAW;EAAE,OAAO;EAAQ,OAAO;EAAQ,GAAG,OACjE,EACH,CAAC,QAAQ,CACV;AAED,QACE,oBAACC,eAAD;EACE,OAAO;GACL,SAAS;GACT,eAAe,aAAa,QAAQ;GACpC,UAAU;GACV;GACA,GAAG;GACJ;EACD,eAAe;EACf,GAAI;YAEH,MAAM,KAAK,SACV,oBAAC,UAAD;GACE,UAAU,KAAK;GAEf,MAAM,KAAK;GACJ;GACD;GACK;GACX,OAAO,KAAK;aAEX,KAAK;GACG,EARJ,KAAK,MAQD,CACX;EACgB,CAAA;EAGzB;AAED,gBAAc,cAAc"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createStaticStyles } from "antd-style";
|
|
2
|
+
//#region src/base-ui/Checkbox/style.ts
|
|
3
|
+
const styles = createStaticStyles(({ css, cssVar }) => ({
|
|
4
|
+
indicator: css`
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
justify-content: center;
|
|
8
|
+
`,
|
|
9
|
+
label: css`
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
user-select: none;
|
|
12
|
+
display: inline-flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
|
|
15
|
+
&:has([data-disabled]) {
|
|
16
|
+
cursor: not-allowed;
|
|
17
|
+
}
|
|
18
|
+
`,
|
|
19
|
+
root: css`
|
|
20
|
+
cursor: pointer;
|
|
21
|
+
|
|
22
|
+
display: inline-flex;
|
|
23
|
+
flex: none;
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: center;
|
|
26
|
+
|
|
27
|
+
margin: 0;
|
|
28
|
+
padding: 0;
|
|
29
|
+
border: 1px solid ${cssVar.colorBorderSecondary};
|
|
30
|
+
|
|
31
|
+
color: ${cssVar.colorBgLayout};
|
|
32
|
+
|
|
33
|
+
background: ${cssVar.colorBgContainer};
|
|
34
|
+
outline: none;
|
|
35
|
+
|
|
36
|
+
transition:
|
|
37
|
+
background 150ms ${cssVar.motionEaseOut},
|
|
38
|
+
border-color 150ms ${cssVar.motionEaseOut};
|
|
39
|
+
|
|
40
|
+
&:hover:not([data-disabled], [data-checked], [data-indeterminate]) {
|
|
41
|
+
border-color: ${cssVar.colorBorder};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&:focus-visible {
|
|
45
|
+
outline: 2px solid ${cssVar.colorPrimaryBorder};
|
|
46
|
+
outline-offset: 1px;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
&[data-checked],
|
|
50
|
+
&[data-indeterminate] {
|
|
51
|
+
border-color: var(--lobe-checkbox-bg, ${cssVar.colorPrimary});
|
|
52
|
+
background: var(--lobe-checkbox-bg, ${cssVar.colorPrimary});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
&[data-disabled] {
|
|
56
|
+
cursor: not-allowed;
|
|
57
|
+
|
|
58
|
+
border-color: ${cssVar.colorFill};
|
|
59
|
+
|
|
60
|
+
color: ${cssVar.colorText};
|
|
61
|
+
|
|
62
|
+
opacity: 0.25;
|
|
63
|
+
background: ${cssVar.colorFill};
|
|
64
|
+
}
|
|
65
|
+
`
|
|
66
|
+
}));
|
|
67
|
+
//#endregion
|
|
68
|
+
export { styles };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=style.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style.mjs","names":[],"sources":["../../../src/base-ui/Checkbox/style.ts"],"sourcesContent":["import { createStaticStyles } from 'antd-style';\n\nexport const styles = createStaticStyles(({ css, cssVar }) => ({\n indicator: css`\n display: flex;\n align-items: center;\n justify-content: center;\n `,\n label: css`\n cursor: pointer;\n user-select: none;\n display: inline-flex;\n align-items: center;\n\n &:has([data-disabled]) {\n cursor: not-allowed;\n }\n `,\n root: css`\n cursor: pointer;\n\n display: inline-flex;\n flex: none;\n align-items: center;\n justify-content: center;\n\n margin: 0;\n padding: 0;\n border: 1px solid ${cssVar.colorBorderSecondary};\n\n color: ${cssVar.colorBgLayout};\n\n background: ${cssVar.colorBgContainer};\n outline: none;\n\n transition:\n background 150ms ${cssVar.motionEaseOut},\n border-color 150ms ${cssVar.motionEaseOut};\n\n &:hover:not([data-disabled], [data-checked], [data-indeterminate]) {\n border-color: ${cssVar.colorBorder};\n }\n\n &:focus-visible {\n outline: 2px solid ${cssVar.colorPrimaryBorder};\n outline-offset: 1px;\n }\n\n &[data-checked],\n &[data-indeterminate] {\n border-color: var(--lobe-checkbox-bg, ${cssVar.colorPrimary});\n background: var(--lobe-checkbox-bg, ${cssVar.colorPrimary});\n }\n\n &[data-disabled] {\n cursor: not-allowed;\n\n border-color: ${cssVar.colorFill};\n\n color: ${cssVar.colorText};\n\n opacity: 0.25;\n background: ${cssVar.colorFill};\n }\n `,\n}));\n"],"mappings":";;AAEA,MAAa,SAAS,oBAAoB,EAAE,KAAK,cAAc;CAC7D,WAAW,GAAG;;;;;CAKd,OAAO,GAAG;;;;;;;;;;CAUV,MAAM,GAAG;;;;;;;;;;wBAUa,OAAO,qBAAqB;;aAEvC,OAAO,cAAc;;kBAEhB,OAAO,iBAAiB;;;;yBAIjB,OAAO,cAAc;2BACnB,OAAO,cAAc;;;sBAG1B,OAAO,YAAY;;;;2BAId,OAAO,mBAAmB;;;;;;8CAMP,OAAO,aAAa;4CACtB,OAAO,aAAa;;;;;;sBAM1C,OAAO,UAAU;;eAExB,OAAO,UAAU;;;oBAGZ,OAAO,UAAU;;;CAGpC,EAAE"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { FlexboxProps } from "../../Flex/type.mjs";
|
|
2
|
+
import { TextProps } from "../../Text/type.mjs";
|
|
3
|
+
import { CSSProperties, ComponentProps, ReactNode } from "react";
|
|
4
|
+
import { Checkbox } from "@base-ui/react/checkbox";
|
|
5
|
+
import { CheckboxGroup } from "@base-ui/react/checkbox-group";
|
|
6
|
+
|
|
7
|
+
//#region src/base-ui/Checkbox/type.d.ts
|
|
8
|
+
type CheckboxShape = 'square' | 'circle';
|
|
9
|
+
type BaseCheckboxProps = Omit<ComponentProps<typeof Checkbox.Root>, 'className' | 'style' | 'render' | 'children' | 'onCheckedChange'>;
|
|
10
|
+
interface CheckboxProps extends BaseCheckboxProps {
|
|
11
|
+
backgroundColor?: string;
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
className?: string;
|
|
14
|
+
classNames?: {
|
|
15
|
+
checkbox?: string;
|
|
16
|
+
text?: string;
|
|
17
|
+
wrapper?: string;
|
|
18
|
+
};
|
|
19
|
+
onChange?: (checked: boolean) => void;
|
|
20
|
+
shape?: CheckboxShape;
|
|
21
|
+
/**
|
|
22
|
+
* Box size in pixels
|
|
23
|
+
* @default 16
|
|
24
|
+
*/
|
|
25
|
+
size?: number;
|
|
26
|
+
style?: CSSProperties;
|
|
27
|
+
styles?: {
|
|
28
|
+
checkbox?: CSSProperties;
|
|
29
|
+
text?: CSSProperties;
|
|
30
|
+
wrapper?: CSSProperties;
|
|
31
|
+
};
|
|
32
|
+
textProps?: Omit<TextProps, 'children' | 'className' | 'style'>;
|
|
33
|
+
}
|
|
34
|
+
interface CheckboxGroupOption {
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
label: ReactNode;
|
|
37
|
+
value: string;
|
|
38
|
+
}
|
|
39
|
+
type BaseCheckboxGroupProps = Omit<ComponentProps<typeof CheckboxGroup>, 'className' | 'style' | 'render' | 'children' | 'onValueChange' | 'onChange'>;
|
|
40
|
+
interface CheckboxGroupProps extends BaseCheckboxGroupProps, Pick<FlexboxProps, 'gap' | 'horizontal'> {
|
|
41
|
+
className?: string;
|
|
42
|
+
onChange?: (value: string[]) => void;
|
|
43
|
+
options: (string | CheckboxGroupOption)[];
|
|
44
|
+
shape?: CheckboxShape;
|
|
45
|
+
size?: number;
|
|
46
|
+
style?: CSSProperties;
|
|
47
|
+
textProps?: CheckboxProps['textProps'];
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { CheckboxGroupOption, CheckboxGroupProps, CheckboxProps, CheckboxShape };
|
|
51
|
+
//# sourceMappingURL=type.d.mts.map
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { rootVariants } from "./style.mjs";
|
|
3
|
+
import { FormContext } from "./context.mjs";
|
|
4
|
+
import FormField from "./components/FormField.mjs";
|
|
5
|
+
import FormFlatGroup from "./components/FormFlatGroup.mjs";
|
|
6
|
+
import FormGroup from "./components/FormGroup.mjs";
|
|
7
|
+
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { cx, useResponsive } from "antd-style";
|
|
10
|
+
import { isUndefined } from "es-toolkit/compat";
|
|
11
|
+
import { Form } from "@base-ui/react/form";
|
|
12
|
+
//#region src/base-ui/Form/Form.tsx
|
|
13
|
+
const serializeForm = (form) => {
|
|
14
|
+
if (!form) return "";
|
|
15
|
+
const entries = [...new FormData(form).entries()].filter(([, value]) => typeof value === "string");
|
|
16
|
+
return JSON.stringify(entries.sort((a, b) => a[0].localeCompare(b[0])));
|
|
17
|
+
};
|
|
18
|
+
const Form$1 = memo(({ className, itemMinWidth, footer, items = [], children, itemsType = "group", variant = "borderless", classNames, styles: customStyles, gap, style, collapsible, defaultActiveKey, initialValues, activeKey, onCollapse, onFinish, onFormSubmit, layout, ref, ...rest }) => {
|
|
19
|
+
const { mobile } = useResponsive();
|
|
20
|
+
const formRef = useRef(null);
|
|
21
|
+
const [submitLoading, setSubmitLoading] = useState(false);
|
|
22
|
+
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);
|
|
23
|
+
const snapshotRef = useRef("");
|
|
24
|
+
const syncUnsaved = useCallback(() => {
|
|
25
|
+
setHasUnsavedChanges(serializeForm(formRef.current) !== snapshotRef.current);
|
|
26
|
+
}, []);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const form = formRef.current;
|
|
29
|
+
if (!form) return;
|
|
30
|
+
snapshotRef.current = serializeForm(form);
|
|
31
|
+
let resetTimer;
|
|
32
|
+
const handleMutation = () => syncUnsaved();
|
|
33
|
+
const handleReset = () => {
|
|
34
|
+
resetTimer = setTimeout(() => {
|
|
35
|
+
snapshotRef.current = serializeForm(formRef.current);
|
|
36
|
+
syncUnsaved();
|
|
37
|
+
}, 0);
|
|
38
|
+
};
|
|
39
|
+
form.addEventListener("input", handleMutation);
|
|
40
|
+
form.addEventListener("change", handleMutation);
|
|
41
|
+
form.addEventListener("reset", handleReset);
|
|
42
|
+
return () => {
|
|
43
|
+
clearTimeout(resetTimer);
|
|
44
|
+
form.removeEventListener("input", handleMutation);
|
|
45
|
+
form.removeEventListener("change", handleMutation);
|
|
46
|
+
form.removeEventListener("reset", handleReset);
|
|
47
|
+
};
|
|
48
|
+
}, [syncUnsaved]);
|
|
49
|
+
const requestReset = useCallback(() => {
|
|
50
|
+
formRef.current?.reset();
|
|
51
|
+
}, []);
|
|
52
|
+
const mergedRef = useCallback((node) => {
|
|
53
|
+
formRef.current = node;
|
|
54
|
+
if (typeof ref === "function") ref(node);
|
|
55
|
+
else if (ref) ref.current = node;
|
|
56
|
+
}, [ref]);
|
|
57
|
+
const context = useMemo(() => ({
|
|
58
|
+
hasUnsavedChanges,
|
|
59
|
+
initialValues,
|
|
60
|
+
itemMinWidth,
|
|
61
|
+
layout: layout || (mobile ? "vertical" : "horizontal"),
|
|
62
|
+
requestReset,
|
|
63
|
+
submitLoading,
|
|
64
|
+
variant
|
|
65
|
+
}), [
|
|
66
|
+
hasUnsavedChanges,
|
|
67
|
+
initialValues,
|
|
68
|
+
itemMinWidth,
|
|
69
|
+
layout,
|
|
70
|
+
mobile,
|
|
71
|
+
requestReset,
|
|
72
|
+
submitLoading,
|
|
73
|
+
variant
|
|
74
|
+
]);
|
|
75
|
+
const mapFlat = useCallback((item, itemIndex) => /* @__PURE__ */ jsx(FormField, {
|
|
76
|
+
className: classNames?.item,
|
|
77
|
+
divider: itemIndex !== 0,
|
|
78
|
+
style: customStyles?.item,
|
|
79
|
+
variant,
|
|
80
|
+
...item
|
|
81
|
+
}, itemIndex), [
|
|
82
|
+
variant,
|
|
83
|
+
classNames,
|
|
84
|
+
customStyles
|
|
85
|
+
]);
|
|
86
|
+
const mapTree = useCallback((group, groupIndex) => {
|
|
87
|
+
const key = group?.key || groupIndex;
|
|
88
|
+
return /* @__PURE__ */ jsx(FormGroup, {
|
|
89
|
+
active: activeKey && group?.key ? activeKey.includes(key) : void 0,
|
|
90
|
+
className: classNames?.group,
|
|
91
|
+
collapsible: isUndefined(group.collapsible) ? collapsible : group.collapsible,
|
|
92
|
+
desc: group?.desc,
|
|
93
|
+
extra: group?.extra,
|
|
94
|
+
icon: group?.icon,
|
|
95
|
+
style: customStyles?.group,
|
|
96
|
+
title: group.title,
|
|
97
|
+
variant: group?.variant || variant,
|
|
98
|
+
defaultActive: defaultActiveKey && group?.key ? defaultActiveKey.includes(key) : group?.defaultActive,
|
|
99
|
+
onCollapse: (active) => {
|
|
100
|
+
let keys = activeKey || defaultActiveKey || [];
|
|
101
|
+
keys = keys.filter((k) => k !== key);
|
|
102
|
+
onCollapse?.(active ? [...keys, key] : keys);
|
|
103
|
+
},
|
|
104
|
+
children: Array.isArray(group.children) ? group.children.filter((item) => !item.hidden).map((item, i) => mapFlat(item, i)) : group.children
|
|
105
|
+
}, key);
|
|
106
|
+
}, [
|
|
107
|
+
activeKey,
|
|
108
|
+
collapsible,
|
|
109
|
+
defaultActiveKey,
|
|
110
|
+
onCollapse,
|
|
111
|
+
variant,
|
|
112
|
+
classNames,
|
|
113
|
+
customStyles,
|
|
114
|
+
mapFlat
|
|
115
|
+
]);
|
|
116
|
+
return /* @__PURE__ */ jsx(FormContext, {
|
|
117
|
+
value: context,
|
|
118
|
+
children: /* @__PURE__ */ jsxs(Form, {
|
|
119
|
+
className: cx(rootVariants({ variant }), className),
|
|
120
|
+
ref: mergedRef,
|
|
121
|
+
style: {
|
|
122
|
+
gap,
|
|
123
|
+
...style
|
|
124
|
+
},
|
|
125
|
+
onFormSubmit: async (values, eventDetails) => {
|
|
126
|
+
onFormSubmit?.(values, eventDetails);
|
|
127
|
+
if (!onFinish) return;
|
|
128
|
+
setSubmitLoading(true);
|
|
129
|
+
try {
|
|
130
|
+
await onFinish(values, eventDetails);
|
|
131
|
+
snapshotRef.current = serializeForm(formRef.current);
|
|
132
|
+
syncUnsaved();
|
|
133
|
+
} finally {
|
|
134
|
+
setSubmitLoading(false);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
...rest,
|
|
138
|
+
children: [
|
|
139
|
+
items && items.length > 0 ? itemsType === "group" ? items.map((item, i) => mapTree(item, i)) : /* @__PURE__ */ jsx(FormFlatGroup, {
|
|
140
|
+
className: classNames?.group,
|
|
141
|
+
style: customStyles?.group,
|
|
142
|
+
variant,
|
|
143
|
+
children: items.filter((item) => !item.hidden).map((item, i) => mapFlat(item, i))
|
|
144
|
+
}) : void 0,
|
|
145
|
+
children,
|
|
146
|
+
footer
|
|
147
|
+
]
|
|
148
|
+
})
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
Form$1.displayName = "Form";
|
|
152
|
+
//#endregion
|
|
153
|
+
export { Form$1 as default };
|
|
154
|
+
|
|
155
|
+
//# sourceMappingURL=Form.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Form.mjs","names":["Form","BaseForm"],"sources":["../../../src/base-ui/Form/Form.tsx"],"sourcesContent":["'use client';\n\nimport { Form as BaseForm } from '@base-ui/react/form';\nimport { cx, useResponsive } from 'antd-style';\nimport { isUndefined } from 'es-toolkit/compat';\nimport { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nimport FormField from './components/FormField';\nimport FormFlatGroup from './components/FormFlatGroup';\nimport FormGroup from './components/FormGroup';\nimport { FormContext } from './context';\nimport { rootVariants } from './style';\nimport type { FormFieldProps, FormGroupItemType, FormProps } from './type';\n\nconst serializeForm = (form: HTMLFormElement | null) => {\n if (!form) return '';\n const entries = [...new FormData(form).entries()].filter(\n ([, value]) => typeof value === 'string',\n ) as [string, string][];\n return JSON.stringify(entries.sort((a, b) => a[0].localeCompare(b[0])));\n};\n\nconst Form = memo<FormProps>(\n ({\n className,\n itemMinWidth,\n footer,\n items = [],\n children,\n itemsType = 'group',\n variant = 'borderless',\n classNames,\n styles: customStyles,\n gap,\n style,\n collapsible,\n defaultActiveKey,\n initialValues,\n activeKey,\n onCollapse,\n onFinish,\n onFormSubmit,\n layout,\n ref,\n ...rest\n }) => {\n const { mobile } = useResponsive();\n const formRef = useRef<HTMLFormElement>(null);\n const [submitLoading, setSubmitLoading] = useState(false);\n const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);\n const snapshotRef = useRef('');\n\n const syncUnsaved = useCallback(() => {\n setHasUnsavedChanges(serializeForm(formRef.current) !== snapshotRef.current);\n }, []);\n\n useEffect(() => {\n const form = formRef.current;\n if (!form) return;\n snapshotRef.current = serializeForm(form);\n let resetTimer: ReturnType<typeof setTimeout>;\n const handleMutation = () => syncUnsaved();\n const handleReset = () => {\n resetTimer = setTimeout(() => {\n snapshotRef.current = serializeForm(formRef.current);\n syncUnsaved();\n }, 0);\n };\n form.addEventListener('input', handleMutation);\n form.addEventListener('change', handleMutation);\n form.addEventListener('reset', handleReset);\n return () => {\n clearTimeout(resetTimer);\n form.removeEventListener('input', handleMutation);\n form.removeEventListener('change', handleMutation);\n form.removeEventListener('reset', handleReset);\n };\n }, [syncUnsaved]);\n\n const requestReset = useCallback(() => {\n formRef.current?.reset();\n }, []);\n\n const mergedRef = useCallback(\n (node: HTMLFormElement | null) => {\n formRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n },\n [ref],\n );\n\n const context = useMemo(\n () => ({\n hasUnsavedChanges,\n initialValues,\n itemMinWidth,\n layout: layout || (mobile ? ('vertical' as const) : ('horizontal' as const)),\n requestReset,\n submitLoading,\n variant,\n }),\n [\n hasUnsavedChanges,\n initialValues,\n itemMinWidth,\n layout,\n mobile,\n requestReset,\n submitLoading,\n variant,\n ],\n );\n\n const mapFlat = useCallback(\n (item: FormFieldProps, itemIndex: number) => (\n <FormField\n className={classNames?.item}\n divider={itemIndex !== 0}\n key={itemIndex}\n style={customStyles?.item}\n variant={variant}\n {...item}\n />\n ),\n [variant, classNames, customStyles],\n );\n\n const mapTree = useCallback(\n (group: FormGroupItemType, groupIndex: number) => {\n const key = group?.key || groupIndex;\n return (\n <FormGroup\n active={activeKey && group?.key ? activeKey.includes(key) : undefined}\n className={classNames?.group}\n collapsible={isUndefined(group.collapsible) ? collapsible : group.collapsible}\n desc={group?.desc}\n extra={group?.extra}\n icon={group?.icon}\n key={key}\n style={customStyles?.group}\n title={group.title}\n variant={group?.variant || variant}\n defaultActive={\n defaultActiveKey && group?.key ? defaultActiveKey.includes(key) : group?.defaultActive\n }\n onCollapse={(active) => {\n let keys: (string | number)[] = activeKey || defaultActiveKey || [];\n keys = keys.filter((k) => k !== key);\n onCollapse?.(active ? [...keys, key] : keys);\n }}\n >\n {Array.isArray(group.children)\n ? group.children.filter((item) => !item.hidden).map((item, i) => mapFlat(item, i))\n : group.children}\n </FormGroup>\n );\n },\n [\n activeKey,\n collapsible,\n defaultActiveKey,\n onCollapse,\n variant,\n classNames,\n customStyles,\n mapFlat,\n ],\n );\n\n return (\n <FormContext value={context}>\n <BaseForm\n className={cx(rootVariants({ variant }), className)}\n ref={mergedRef}\n style={{ gap, ...style }}\n onFormSubmit={async (values, eventDetails) => {\n onFormSubmit?.(values, eventDetails);\n if (!onFinish) return;\n setSubmitLoading(true);\n try {\n await onFinish(values, eventDetails);\n snapshotRef.current = serializeForm(formRef.current);\n syncUnsaved();\n } finally {\n setSubmitLoading(false);\n }\n }}\n {...rest}\n >\n {items && items.length > 0 ? (\n itemsType === 'group' ? (\n (items as FormGroupItemType[]).map((item, i) => mapTree(item, i))\n ) : (\n <FormFlatGroup\n className={classNames?.group}\n style={customStyles?.group}\n variant={variant}\n >\n {(items as FormFieldProps[])\n .filter((item) => !item.hidden)\n .map((item, i) => mapFlat(item, i))}\n </FormFlatGroup>\n )\n ) : undefined}\n {children}\n {footer}\n </BaseForm>\n </FormContext>\n );\n },\n);\n\nForm.displayName = 'Form';\n\nexport default Form;\n"],"mappings":"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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FormDividerProps } from "../type.mjs";
|
|
2
|
+
import { FC } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/base-ui/Form/components/FormDivider.d.ts
|
|
5
|
+
declare const FormDivider: FC<FormDividerProps>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { FormDivider };
|
|
8
|
+
//# sourceMappingURL=FormDivider.d.mts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { dividerStyles } from "../style.mjs";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { cx } from "antd-style";
|
|
5
|
+
//#region src/base-ui/Form/components/FormDivider.tsx
|
|
6
|
+
const FormDivider = ({ visible = true, style, className, ...rest }) => /* @__PURE__ */ jsx("div", {
|
|
7
|
+
className: cx(dividerStyles.root, className),
|
|
8
|
+
role: "separator",
|
|
9
|
+
style: {
|
|
10
|
+
opacity: visible ? .66 : 0,
|
|
11
|
+
...style
|
|
12
|
+
},
|
|
13
|
+
...rest
|
|
14
|
+
});
|
|
15
|
+
FormDivider.displayName = "FormDivider";
|
|
16
|
+
//#endregion
|
|
17
|
+
export { FormDivider as default };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=FormDivider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormDivider.mjs","names":[],"sources":["../../../../src/base-ui/Form/components/FormDivider.tsx"],"sourcesContent":["'use client';\n\nimport { cx } from 'antd-style';\nimport { type FC } from 'react';\n\nimport { dividerStyles } from '../style';\nimport type { FormDividerProps } from '../type';\n\nconst FormDivider: FC<FormDividerProps> = ({ visible = true, style, className, ...rest }) => (\n <div\n className={cx(dividerStyles.root, className)}\n role={'separator'}\n style={{ opacity: visible ? 0.66 : 0, ...style }}\n {...rest}\n />\n);\n\nFormDivider.displayName = 'FormDivider';\n\nexport default FormDivider;\n"],"mappings":";;;;;AAQA,MAAM,eAAqC,EAAE,UAAU,MAAM,OAAO,WAAW,GAAG,WAChF,oBAAC,OAAD;CACE,WAAW,GAAG,cAAc,MAAM,UAAU;CAC5C,MAAM;CACN,OAAO;EAAE,SAAS,UAAU,MAAO;EAAG,GAAG;EAAO;CAChD,GAAI;CACJ,CAAA;AAGJ,YAAY,cAAc"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FormFieldProps } from "../type.mjs";
|
|
2
|
+
import * as _$react from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/base-ui/Form/components/FormField.d.ts
|
|
5
|
+
declare const FormField: _$react.NamedExoticComponent<FormFieldProps>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { FormField };
|
|
8
|
+
//# sourceMappingURL=FormField.d.mts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { fieldStyles, fieldVariants } from "../style.mjs";
|
|
3
|
+
import FormDivider from "./FormDivider.mjs";
|
|
4
|
+
import { useFormContext } from "../context.mjs";
|
|
5
|
+
import FormTitle from "./FormTitle.mjs";
|
|
6
|
+
import { cloneElement, isValidElement, memo, useMemo } from "react";
|
|
7
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { cx, useResponsive } from "antd-style";
|
|
9
|
+
import { Field } from "@base-ui/react/field";
|
|
10
|
+
//#region src/base-ui/Form/components/FormField.tsx
|
|
11
|
+
const FormField = memo(({ avatar, children, className, desc, divider, hidden, label, layout, minWidth, name, required, style, tag, variant, ...rest }) => {
|
|
12
|
+
const { mobile } = useResponsive();
|
|
13
|
+
const config = useFormContext();
|
|
14
|
+
const mergedLayout = layout || (mobile ? "vertical" : config.layout);
|
|
15
|
+
const mergedVariant = variant || config.variant;
|
|
16
|
+
const mergedMinWidth = minWidth ?? config.itemMinWidth;
|
|
17
|
+
const control = useMemo(() => {
|
|
18
|
+
if (!isValidElement(children)) return children;
|
|
19
|
+
const props = children.props;
|
|
20
|
+
const injected = {};
|
|
21
|
+
if (required && props.required === void 0) injected.required = true;
|
|
22
|
+
if (name) {
|
|
23
|
+
const initialValue = config.initialValues?.[name];
|
|
24
|
+
if (initialValue !== void 0 && props.value === void 0 && props.defaultValue === void 0) injected.defaultValue = initialValue;
|
|
25
|
+
}
|
|
26
|
+
if (Object.keys(injected).length === 0) return children;
|
|
27
|
+
return cloneElement(children, injected);
|
|
28
|
+
}, [
|
|
29
|
+
children,
|
|
30
|
+
name,
|
|
31
|
+
required,
|
|
32
|
+
config.initialValues
|
|
33
|
+
]);
|
|
34
|
+
if (hidden) return null;
|
|
35
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [divider && /* @__PURE__ */ jsx(FormDivider, { visible: mergedVariant !== "borderless" }), /* @__PURE__ */ jsxs(Field.Root, {
|
|
36
|
+
className: cx(fieldVariants({ layout: mergedLayout }), className),
|
|
37
|
+
name,
|
|
38
|
+
style,
|
|
39
|
+
...rest,
|
|
40
|
+
children: [/* @__PURE__ */ jsx(Field.Label, {
|
|
41
|
+
className: fieldStyles.label,
|
|
42
|
+
children: /* @__PURE__ */ jsx(FormTitle, {
|
|
43
|
+
avatar,
|
|
44
|
+
desc,
|
|
45
|
+
tag,
|
|
46
|
+
title: label
|
|
47
|
+
})
|
|
48
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
49
|
+
className: cx(fieldStyles.control, mergedLayout === "vertical" && fieldStyles.controlVertical),
|
|
50
|
+
style: mergedMinWidth === void 0 || mergedMinWidth === null || mergedMinWidth === "" ? void 0 : { minWidth: typeof mergedMinWidth === "number" ? `${mergedMinWidth}px` : mergedMinWidth },
|
|
51
|
+
children: [control, /* @__PURE__ */ jsx(Field.Error, { className: fieldStyles.error })]
|
|
52
|
+
})]
|
|
53
|
+
})] });
|
|
54
|
+
});
|
|
55
|
+
FormField.displayName = "FormField";
|
|
56
|
+
//#endregion
|
|
57
|
+
export { FormField as default };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=FormField.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormField.mjs","names":[],"sources":["../../../../src/base-ui/Form/components/FormField.tsx"],"sourcesContent":["'use client';\n\nimport { Field } from '@base-ui/react/field';\nimport { cx, useResponsive } from 'antd-style';\nimport { cloneElement, isValidElement, memo, useMemo } from 'react';\n\nimport { useFormContext } from '../context';\nimport { fieldStyles, fieldVariants } from '../style';\nimport type { FormFieldProps } from '../type';\nimport FormDivider from './FormDivider';\nimport FormTitle from './FormTitle';\n\nconst FormField = memo<FormFieldProps>(\n ({\n avatar,\n children,\n className,\n desc,\n divider,\n hidden,\n label,\n layout,\n minWidth,\n name,\n required,\n style,\n tag,\n variant,\n ...rest\n }) => {\n const { mobile } = useResponsive();\n const config = useFormContext();\n\n const mergedLayout = layout || (mobile ? 'vertical' : config.layout);\n const mergedVariant = variant || config.variant;\n const mergedMinWidth = minWidth ?? config.itemMinWidth;\n\n const control = useMemo(() => {\n if (!isValidElement(children)) return children;\n const props = children.props as Record<string, unknown>;\n const injected: Record<string, unknown> = {};\n if (required && props.required === undefined) injected.required = true;\n if (name) {\n const initialValue = config.initialValues?.[name];\n if (\n initialValue !== undefined &&\n props.value === undefined &&\n props.defaultValue === undefined\n )\n injected.defaultValue = initialValue;\n }\n if (Object.keys(injected).length === 0) return children;\n return cloneElement(children, injected as never);\n }, [children, name, required, config.initialValues]);\n\n if (hidden) return null;\n\n return (\n <>\n {divider && <FormDivider visible={mergedVariant !== 'borderless'} />}\n <Field.Root\n className={cx(fieldVariants({ layout: mergedLayout }), className)}\n name={name}\n style={style}\n {...rest}\n >\n <Field.Label className={fieldStyles.label}>\n <FormTitle avatar={avatar} desc={desc} tag={tag} title={label} />\n </Field.Label>\n <div\n className={cx(\n fieldStyles.control,\n mergedLayout === 'vertical' && fieldStyles.controlVertical,\n )}\n style={\n mergedMinWidth === undefined || mergedMinWidth === null || mergedMinWidth === ''\n ? undefined\n : {\n minWidth:\n typeof mergedMinWidth === 'number' ? `${mergedMinWidth}px` : mergedMinWidth,\n }\n }\n >\n {control}\n <Field.Error className={fieldStyles.error} />\n </div>\n </Field.Root>\n </>\n );\n },\n);\n\nFormField.displayName = 'FormField';\n\nexport default FormField;\n"],"mappings":";;;;;;;;;;AAYA,MAAM,YAAY,MACf,EACC,QACA,UACA,WACA,MACA,SACA,QACA,OACA,QACA,UACA,MACA,UACA,OACA,KACA,SACA,GAAG,WACC;CACJ,MAAM,EAAE,WAAW,eAAe;CAClC,MAAM,SAAS,gBAAgB;CAE/B,MAAM,eAAe,WAAW,SAAS,aAAa,OAAO;CAC7D,MAAM,gBAAgB,WAAW,OAAO;CACxC,MAAM,iBAAiB,YAAY,OAAO;CAE1C,MAAM,UAAU,cAAc;AAC5B,MAAI,CAAC,eAAe,SAAS,CAAE,QAAO;EACtC,MAAM,QAAQ,SAAS;EACvB,MAAM,WAAoC,EAAE;AAC5C,MAAI,YAAY,MAAM,aAAa,KAAA,EAAW,UAAS,WAAW;AAClE,MAAI,MAAM;GACR,MAAM,eAAe,OAAO,gBAAgB;AAC5C,OACE,iBAAiB,KAAA,KACjB,MAAM,UAAU,KAAA,KAChB,MAAM,iBAAiB,KAAA,EAEvB,UAAS,eAAe;;AAE5B,MAAI,OAAO,KAAK,SAAS,CAAC,WAAW,EAAG,QAAO;AAC/C,SAAO,aAAa,UAAU,SAAkB;IAC/C;EAAC;EAAU;EAAM;EAAU,OAAO;EAAc,CAAC;AAEpD,KAAI,OAAQ,QAAO;AAEnB,QACE,qBAAA,YAAA,EAAA,UAAA,CACG,WAAW,oBAAC,aAAD,EAAa,SAAS,kBAAkB,cAAgB,CAAA,EACpE,qBAAC,MAAM,MAAP;EACE,WAAW,GAAG,cAAc,EAAE,QAAQ,cAAc,CAAC,EAAE,UAAU;EAC3D;EACC;EACP,GAAI;YAJN,CAME,oBAAC,MAAM,OAAP;GAAa,WAAW,YAAY;aAClC,oBAAC,WAAD;IAAmB;IAAc;IAAW;IAAK,OAAO;IAAS,CAAA;GACrD,CAAA,EACd,qBAAC,OAAD;GACE,WAAW,GACT,YAAY,SACZ,iBAAiB,cAAc,YAAY,gBAC5C;GACD,OACE,mBAAmB,KAAA,KAAa,mBAAmB,QAAQ,mBAAmB,KAC1E,KAAA,IACA,EACE,UACE,OAAO,mBAAmB,WAAW,GAAG,eAAe,MAAM,gBAChE;aAXT,CAcG,SACD,oBAAC,MAAM,OAAP,EAAa,WAAW,YAAY,OAAS,CAAA,CACzC;KACK;IACZ,EAAA,CAAA;EAGR;AAED,UAAU,cAAc"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FormFlatGroupProps } from "../type.mjs";
|
|
2
|
+
import * as _$react from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/base-ui/Form/components/FormFlatGroup.d.ts
|
|
5
|
+
declare const FormFlatGroup: _$react.NamedExoticComponent<FormFlatGroupProps>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { FormFlatGroup };
|
|
8
|
+
//# sourceMappingURL=FormFlatGroup.d.mts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import FlexBasic_default from "../../../Flex/FlexBasic.mjs";
|
|
3
|
+
import { flatGroupStyles, flatGroupVariants } from "../style.mjs";
|
|
4
|
+
import { memo } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { cx, useResponsive } from "antd-style";
|
|
7
|
+
//#region src/base-ui/Form/components/FormFlatGroup.tsx
|
|
8
|
+
const FormFlatGroup = memo(({ className, children, variant = "borderless", ...rest }) => {
|
|
9
|
+
const { mobile } = useResponsive();
|
|
10
|
+
return /* @__PURE__ */ jsx(FlexBasic_default, {
|
|
11
|
+
className: cx(mobile ? flatGroupStyles.mobile : flatGroupVariants({ variant }), className),
|
|
12
|
+
...rest,
|
|
13
|
+
children
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
FormFlatGroup.displayName = "FormFlatGroup";
|
|
17
|
+
//#endregion
|
|
18
|
+
export { FormFlatGroup as default };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=FormFlatGroup.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormFlatGroup.mjs","names":["Flexbox"],"sources":["../../../../src/base-ui/Form/components/FormFlatGroup.tsx"],"sourcesContent":["'use client';\n\nimport { cx, useResponsive } from 'antd-style';\nimport { memo } from 'react';\n\nimport { Flexbox } from '@/Flex';\n\nimport { flatGroupStyles, flatGroupVariants } from '../style';\nimport type { FormFlatGroupProps } from '../type';\n\nconst FormFlatGroup = memo<FormFlatGroupProps>(\n ({ className, children, variant = 'borderless', ...rest }) => {\n const { mobile } = useResponsive();\n\n return (\n <Flexbox\n className={cx(mobile ? flatGroupStyles.mobile : flatGroupVariants({ variant }), className)}\n {...rest}\n >\n {children}\n </Flexbox>\n );\n },\n);\n\nFormFlatGroup.displayName = 'FormFlatGroup';\n\nexport default FormFlatGroup;\n"],"mappings":";;;;;;;AAUA,MAAM,gBAAgB,MACnB,EAAE,WAAW,UAAU,UAAU,cAAc,GAAG,WAAW;CAC5D,MAAM,EAAE,WAAW,eAAe;AAElC,QACE,oBAACA,mBAAD;EACE,WAAW,GAAG,SAAS,gBAAgB,SAAS,kBAAkB,EAAE,SAAS,CAAC,EAAE,UAAU;EAC1F,GAAI;EAEH;EACO,CAAA;EAGf;AAED,cAAc,cAAc"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FormFooterProps } from "../type.mjs";
|
|
2
|
+
import { FC } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/base-ui/Form/components/FormFooter.d.ts
|
|
5
|
+
declare const FormFooter: FC<FormFooterProps>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { FormFooter };
|
|
8
|
+
//# sourceMappingURL=FormFooter.d.mts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import FlexBasic_default from "../../../Flex/FlexBasic.mjs";
|
|
3
|
+
import { footerStyles } from "../style.mjs";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { cx } from "antd-style";
|
|
6
|
+
//#region src/base-ui/Form/components/FormFooter.tsx
|
|
7
|
+
const FormFooter = ({ className, children, ...rest }) => /* @__PURE__ */ jsx(FlexBasic_default, {
|
|
8
|
+
horizontal: true,
|
|
9
|
+
align: "center",
|
|
10
|
+
className: cx(footerStyles.root, className),
|
|
11
|
+
gap: 8,
|
|
12
|
+
justify: "flex-end",
|
|
13
|
+
...rest,
|
|
14
|
+
children
|
|
15
|
+
});
|
|
16
|
+
FormFooter.displayName = "FormFooter";
|
|
17
|
+
//#endregion
|
|
18
|
+
export { FormFooter as default };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=FormFooter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormFooter.mjs","names":["Flexbox"],"sources":["../../../../src/base-ui/Form/components/FormFooter.tsx"],"sourcesContent":["'use client';\n\nimport { cx } from 'antd-style';\nimport { type FC } from 'react';\n\nimport { Flexbox } from '@/Flex';\n\nimport { footerStyles } from '../style';\nimport type { FormFooterProps } from '../type';\n\nconst FormFooter: FC<FormFooterProps> = ({ className, children, ...rest }) => (\n <Flexbox\n horizontal\n align={'center'}\n className={cx(footerStyles.root, className)}\n gap={8}\n justify={'flex-end'}\n {...rest}\n >\n {children}\n </Flexbox>\n);\n\nFormFooter.displayName = 'FormFooter';\n\nexport default FormFooter;\n"],"mappings":";;;;;;AAUA,MAAM,cAAmC,EAAE,WAAW,UAAU,GAAG,WACjE,oBAACA,mBAAD;CACE,YAAA;CACA,OAAO;CACP,WAAW,GAAG,aAAa,MAAM,UAAU;CAC3C,KAAK;CACL,SAAS;CACT,GAAI;CAEH;CACO,CAAA;AAGZ,WAAW,cAAc"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FormGroupProps } from "../type.mjs";
|
|
2
|
+
import * as _$react from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/base-ui/Form/components/FormGroup.d.ts
|
|
5
|
+
declare const FormGroup: _$react.NamedExoticComponent<FormGroupProps>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { FormGroup };
|
|
8
|
+
//# sourceMappingURL=FormGroup.d.mts.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import Icon from "../../../Icon/Icon.mjs";
|
|
3
|
+
import { groupStyles, groupVariants } from "../style.mjs";
|
|
4
|
+
import { memo } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { cx, useResponsive } from "antd-style";
|
|
7
|
+
import { ChevronDown } from "lucide-react";
|
|
8
|
+
import { Collapsible } from "@base-ui/react/collapsible";
|
|
9
|
+
//#region src/base-ui/Form/components/FormGroup.tsx
|
|
10
|
+
const GroupTitle = memo(({ icon, title, desc, variant, mobile }) => /* @__PURE__ */ jsxs("div", {
|
|
11
|
+
className: cx(groupStyles.title, variant === "borderless" && !mobile && groupStyles.titleBorderless, mobile && groupStyles.mobileTitle),
|
|
12
|
+
children: [icon && /* @__PURE__ */ jsx(Icon, { icon }), /* @__PURE__ */ jsxs("div", { children: [title, desc && /* @__PURE__ */ jsx("div", {
|
|
13
|
+
className: groupStyles.desc,
|
|
14
|
+
children: desc
|
|
15
|
+
})] })]
|
|
16
|
+
}));
|
|
17
|
+
GroupTitle.displayName = "GroupTitle";
|
|
18
|
+
const FormGroup = memo(({ className, icon, title, children, extra, variant = "borderless", defaultActive = true, collapsible, active, onCollapse, desc, keyValue: _keyValue, ...rest }) => {
|
|
19
|
+
const { mobile } = useResponsive();
|
|
20
|
+
const isBorderless = variant === "borderless";
|
|
21
|
+
const isCollapsible = collapsible === void 0 ? !isBorderless : collapsible;
|
|
22
|
+
if (mobile) return /* @__PURE__ */ jsxs("div", {
|
|
23
|
+
className,
|
|
24
|
+
...rest,
|
|
25
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
26
|
+
className: cx(groupStyles.header, groupStyles.mobileHeader),
|
|
27
|
+
children: [/* @__PURE__ */ jsx(GroupTitle, {
|
|
28
|
+
mobile: true,
|
|
29
|
+
desc,
|
|
30
|
+
icon,
|
|
31
|
+
title
|
|
32
|
+
}), extra]
|
|
33
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
34
|
+
className: groupStyles.mobileBody,
|
|
35
|
+
children
|
|
36
|
+
})]
|
|
37
|
+
});
|
|
38
|
+
if (!isCollapsible) return /* @__PURE__ */ jsxs("div", {
|
|
39
|
+
className: cx(groupVariants({ variant }), className),
|
|
40
|
+
...rest,
|
|
41
|
+
children: [title && /* @__PURE__ */ jsxs("div", {
|
|
42
|
+
className: cx(groupStyles.header, isBorderless ? groupStyles.headerBorderless : groupStyles.headerBoxed),
|
|
43
|
+
children: [/* @__PURE__ */ jsx(GroupTitle, {
|
|
44
|
+
desc,
|
|
45
|
+
icon,
|
|
46
|
+
title,
|
|
47
|
+
variant
|
|
48
|
+
}), extra]
|
|
49
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
50
|
+
className: cx(groupStyles.body, !isBorderless && groupStyles.bodyBoxed),
|
|
51
|
+
children
|
|
52
|
+
})]
|
|
53
|
+
});
|
|
54
|
+
return /* @__PURE__ */ jsxs(Collapsible.Root, {
|
|
55
|
+
className: cx(groupVariants({ variant }), className),
|
|
56
|
+
defaultOpen: defaultActive,
|
|
57
|
+
open: active,
|
|
58
|
+
onOpenChange: onCollapse,
|
|
59
|
+
...rest,
|
|
60
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
61
|
+
className: cx(groupStyles.header, isBorderless ? groupStyles.headerBorderless : groupStyles.headerBoxed),
|
|
62
|
+
children: [/* @__PURE__ */ jsxs(Collapsible.Trigger, {
|
|
63
|
+
className: groupStyles.trigger,
|
|
64
|
+
children: [/* @__PURE__ */ jsx(GroupTitle, {
|
|
65
|
+
desc,
|
|
66
|
+
icon,
|
|
67
|
+
title,
|
|
68
|
+
variant
|
|
69
|
+
}), /* @__PURE__ */ jsx(Icon, {
|
|
70
|
+
className: groupStyles.chevron,
|
|
71
|
+
icon: ChevronDown
|
|
72
|
+
})]
|
|
73
|
+
}), extra]
|
|
74
|
+
}), /* @__PURE__ */ jsx(Collapsible.Panel, {
|
|
75
|
+
className: groupStyles.panel,
|
|
76
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
77
|
+
className: cx(groupStyles.body, !isBorderless && groupStyles.bodyBoxed),
|
|
78
|
+
children
|
|
79
|
+
})
|
|
80
|
+
})]
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
FormGroup.displayName = "FormGroup";
|
|
84
|
+
//#endregion
|
|
85
|
+
export { FormGroup as default };
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=FormGroup.mjs.map
|