musae 0.1.32 → 0.1.34

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.
Files changed (31) hide show
  1. package/dist/components/button/button.d.ts +1 -0
  2. package/dist/components/button/button.mjs +5 -2
  3. package/dist/components/config/hooks.d.ts +1 -0
  4. package/dist/components/form/field/error.d.ts +12 -0
  5. package/dist/components/form/field/error.mjs +38 -0
  6. package/dist/components/form/{field.d.ts → field/field.d.ts} +1 -1
  7. package/dist/components/form/{field.mjs → field/field.mjs} +35 -49
  8. package/dist/components/form/field/index.d.ts +3 -0
  9. package/dist/components/form/field/layout.d.ts +45 -0
  10. package/dist/components/form/{gridded.mjs → field/layout.mjs} +20 -17
  11. package/dist/components/form/form.mjs +10 -9
  12. package/dist/components/form/index.d.ts +2 -1
  13. package/dist/components/form/item.mjs +3 -3
  14. package/dist/components/form/types.d.ts +9 -4
  15. package/dist/components/grid/col.mjs +1 -1
  16. package/dist/components/grid/row.mjs +1 -1
  17. package/dist/components/input/hooks.d.ts +1 -1
  18. package/dist/components/input/input.mjs +1 -3
  19. package/dist/components/message/holder.mjs +1 -1
  20. package/dist/components/message/message.mjs +15 -8
  21. package/dist/components/picker/hooks.mjs +2 -2
  22. package/dist/components/popper/dropdown.mjs +10 -9
  23. package/dist/components/waterfall/hooks.d.ts +1 -2
  24. package/dist/components/waterfall/hooks.mjs +14 -16
  25. package/dist/components/waterfall/waterfall.mjs +2 -2
  26. package/dist/index.d.ts +1 -1
  27. package/dist/stylex.css +2 -4
  28. package/dist/utils/class-name.d.ts +6 -2
  29. package/dist/utils/class-name.mjs +6 -4
  30. package/package.json +2 -2
  31. package/dist/components/form/gridded.d.ts +0 -15
@@ -5,6 +5,7 @@ import React from "react";
5
5
  *
6
6
  * @description
7
7
  * button
8
+ * 1. diff from normal html button, this button is default type `button`, not `submit`
8
9
  */
9
10
  export declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
10
11
  export default Button;
@@ -16,7 +16,7 @@ const styles = {
16
16
  overflow: "musae-b3r6kr",
17
17
  overflowX: null,
18
18
  overflowY: null,
19
- display: "musae-78zum5",
19
+ display: "musae-3nfvp2",
20
20
  alignItems: "musae-6s0dn4",
21
21
  gap: "musae-vbka3v",
22
22
  rowGap: null,
@@ -219,6 +219,7 @@ const styles = {
219
219
  *
220
220
  * @description
221
221
  * button
222
+ * 1. diff from normal html button, this button is default type `button`, not `submit`
222
223
  */
223
224
  const Button = forwardRef(({
224
225
  children,
@@ -232,6 +233,7 @@ const Button = forwardRef(({
232
233
  ripple = true,
233
234
  onPointerEnter,
234
235
  onPointerLeave,
236
+ type = "button",
235
237
  ...props$1
236
238
  }, ref) => {
237
239
  const classNames = useClassNames(ComponentToken.Button);
@@ -278,7 +280,8 @@ const Button = forwardRef(({
278
280
  ...style
279
281
  },
280
282
  onPointerEnter: onPointerEnter,
281
- onPointerLeave: onPointerLeave
283
+ onPointerLeave: onPointerLeave,
284
+ type: type
282
285
  }, props$1.prefix, children, props$1.suffix, ripple && React.createElement(Ripple, {
283
286
  ripples: ripples,
284
287
  onClear: clear
@@ -26,6 +26,7 @@ export declare const useClassNames: <T extends ComponentToken>(token: T) => {
26
26
  0: string;
27
27
  1: string;
28
28
  2: string;
29
+ 3: string;
29
30
  };
30
31
  5: {
31
32
  0: string;
@@ -0,0 +1,12 @@
1
+ import { FieldError } from "react-hook-form";
2
+ import { ComponentProps } from "../../../types/element";
3
+ import React from "react";
4
+ type Props = ComponentProps & {
5
+ /**
6
+ * @description
7
+ * error
8
+ */
9
+ error?: FieldError;
10
+ };
11
+ declare const Error: ({ error, className, style }: Props) => React.JSX.Element;
12
+ export default Error;
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+ import { useClassNames } from '../../config/hooks.mjs';
3
+ import { ComponentToken, FormClassToken } from '../../../utils/class-name.mjs';
4
+ import clsx from 'clsx';
5
+ import { motion } from 'framer-motion';
6
+
7
+ const Error = ({
8
+ error,
9
+ className,
10
+ style
11
+ }) => {
12
+ const classNames = useClassNames(ComponentToken.Form);
13
+ const styled = {
14
+ className: "musae-1xkwav8 musae-1p848mt"
15
+ };
16
+ return React.createElement(motion.div, {
17
+ className: clsx(classNames[FormClassToken.FieldError], className, styled.className),
18
+ style: {
19
+ ...style,
20
+ ...styled.style
21
+ },
22
+ initial: {
23
+ height: 0
24
+ },
25
+ animate: {
26
+ height: "auto"
27
+ },
28
+ exit: {
29
+ height: 0
30
+ },
31
+ transition: {
32
+ duration: 0.1
33
+ }
34
+ }, error?.message);
35
+ };
36
+ var Error$1 = Error;
37
+
38
+ export { Error$1 as default };
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import type { FormItemProps } from "./types";
2
+ import type { FormItemProps } from "../types";
3
3
  import type { RequiredIn } from "@aiszlab/relax/types";
4
4
  /**
5
5
  * @description
@@ -1,34 +1,32 @@
1
1
  import React, { useMemo, isValidElement, cloneElement } from 'react';
2
2
  import { useController } from 'react-hook-form';
3
- import { isRefable } from '@aiszlab/relax';
4
- import { useClassNames } from '../config/hooks.mjs';
5
- import { ComponentToken, FormClassToken } from '../../utils/class-name.mjs';
6
- import { props } from '../../node_modules/@stylexjs/stylex/lib/es/stylex.mjs';
3
+ import { chain, isRefable } from '@aiszlab/relax';
4
+ import { useClassNames } from '../../config/hooks.mjs';
5
+ import { ComponentToken, FormClassToken } from '../../../utils/class-name.mjs';
6
+ import { props } from '../../../node_modules/@stylexjs/stylex/lib/es/stylex.mjs';
7
7
  import clsx from 'clsx';
8
- import { useTheme } from '../theme/hooks.mjs';
9
- import { ColorToken } from '../../utils/colors.mjs';
10
- import Gridded from './gridded.mjs';
11
- import { typography } from '../theme/theme.mjs';
8
+ import { useTheme } from '../../theme/hooks.mjs';
9
+ import { ColorToken } from '../../../utils/colors.mjs';
10
+ import Layout from './layout.mjs';
11
+ import Error from './error.mjs';
12
+ import { AnimatePresence } from 'framer-motion';
13
+ import { typography } from '../../theme/theme.mjs';
12
14
 
13
15
  const styles = {
14
- explain: {
15
- paddingInline: "musae-1xkwav8",
16
- paddingStart: null,
17
- paddingLeft: null,
18
- paddingEnd: null,
19
- paddingRight: null,
20
- paddingBlock: "musae-24n1ab",
21
- paddingTop: null,
22
- paddingBottom: null,
23
- marginBottom: "musae-uwzj2e",
24
- $$css: true
25
- },
26
16
  error: props => [{
27
17
  color: "musae-19dipnz",
18
+ overflow: "musae-b3r6kr",
19
+ overflowX: null,
20
+ overflowY: null,
28
21
  $$css: true
29
22
  }, {
30
23
  "--color": props.color != null ? props.color : "initial"
31
- }]
24
+ }],
25
+ supporting: {
26
+ minHeight: "musae-jbwyga",
27
+ paddingBottom: "musae-78w2x6",
28
+ $$css: true
29
+ }
32
30
  };
33
31
  /**
34
32
  * @description
@@ -40,6 +38,7 @@ const Field = ({
40
38
  ...props$1
41
39
  }) => {
42
40
  const classNames = useClassNames(ComponentToken.Form);
41
+ const theme = useTheme();
43
42
  const {
44
43
  field: {
45
44
  onBlur,
@@ -61,21 +60,14 @@ const Field = ({
61
60
  }
62
61
  }
63
62
  });
64
- const theme = useTheme();
65
63
  const children = useMemo(() => {
66
64
  const _isValidElement = isValidElement(props$1.children);
67
65
  if (!_isValidElement) return props$1.children;
68
66
  const _child = props$1.children;
69
67
  /// rewrite change and blur handler
70
68
  const handlers = {
71
- onChange: (...args) => {
72
- _child.props.onChange?.(...args);
73
- onChange(...args);
74
- },
75
- onBlur: (...args) => {
76
- _child.props.onBlur?.(...args);
77
- onBlur();
78
- }
69
+ onChange: chain(_child.props.onChange, onChange),
70
+ onBlur: chain(_child.props.onBlur, onBlur)
79
71
  };
80
72
  /// registe react hook form
81
73
  return cloneElement(props$1.children, {
@@ -89,30 +81,24 @@ const Field = ({
89
81
  });
90
82
  }, [props$1.children, name, value, invalid, ref, onChange, onBlur]);
91
83
  const styled = {
92
- explain: props(typography.body.medium, styles.explain)
93
- };
94
- const _error = useMemo(() => {
95
- if (!invalid) return null;
96
- const {
97
- className,
98
- style
99
- } = props(styles.error({
84
+ error: props(styles.error({
100
85
  color: theme.colors[ColorToken.Error]
101
- }));
102
- return React.createElement("span", {
103
- className: clsx(classNames[FormClassToken.ItemExplainError], className),
104
- style: style
105
- }, error?.message);
106
- }, [classNames, error?.message, invalid, theme.colors]);
86
+ })),
87
+ supporting: props(styles.supporting, typography.body.small)
88
+ };
107
89
  return React.createElement("div", {
108
90
  className: clsx(classNames[FormClassToken.Item])
109
- }, React.createElement(Gridded, {
91
+ }, React.createElement(Layout, {
110
92
  label: props$1.label,
111
93
  required: required
112
- }, React.createElement("div", null, children), _error && React.createElement("div", {
113
- className: clsx(classNames[FormClassToken.ItemExplain], styled.explain.className),
114
- style: styled.explain.style
115
- }, _error)));
94
+ }, React.createElement("div", null, children), React.createElement("div", {
95
+ className: clsx(classNames[FormClassToken.FieldSupporting], styled.supporting.className),
96
+ style: styled.supporting.style
97
+ }, React.createElement(AnimatePresence, null, invalid && React.createElement(Error, {
98
+ error: error,
99
+ className: styled.error.className,
100
+ style: styled.error.style
101
+ })))));
116
102
  };
117
103
  var Field$1 = Field;
118
104
 
@@ -0,0 +1,3 @@
1
+ import Field from "./field";
2
+ import Layout from "./layout";
3
+ export { Field, Layout };
@@ -0,0 +1,45 @@
1
+ import React from "react";
2
+ import { type ReactNode } from "react";
3
+ import type { ContextValue } from "../types";
4
+ /**
5
+ * @description
6
+ * layout props
7
+ */
8
+ type Props = {
9
+ /**
10
+ * @description
11
+ * children
12
+ */
13
+ children: ReactNode;
14
+ /**
15
+ * @description
16
+ * label for current input
17
+ */
18
+ label?: string;
19
+ /**
20
+ * @description
21
+ * how many columns should the label take
22
+ */
23
+ labelCol?: ContextValue["labelCol"];
24
+ /**
25
+ * @description
26
+ * how many columns should the input take
27
+ */
28
+ wrapperCol?: ContextValue["wrapperCol"];
29
+ /**
30
+ * @description
31
+ * display required
32
+ */
33
+ required: boolean;
34
+ /**
35
+ * @description
36
+ * if this item has margin space
37
+ */
38
+ space?: boolean;
39
+ };
40
+ /**
41
+ * @description
42
+ * item layout
43
+ */
44
+ declare const Layout: ({ required, space, ...props }: Props) => React.JSX.Element;
45
+ export default Layout;
@@ -1,13 +1,21 @@
1
1
  import React, { useContext } from 'react';
2
- import Context from './context.mjs';
3
- import { Grid } from '../grid/index.mjs';
4
- import { props } from '../../node_modules/@stylexjs/stylex/lib/es/stylex.mjs';
5
- import { typography } from '../theme/theme.mjs';
6
- import { useTheme } from '../theme/hooks.mjs';
7
- import { ColorToken } from '../../utils/colors.mjs';
2
+ import Context from '../context.mjs';
3
+ import { Grid } from '../../grid/index.mjs';
4
+ import { props } from '../../../node_modules/@stylexjs/stylex/lib/es/stylex.mjs';
5
+ import { typography } from '../../theme/theme.mjs';
6
+ import { useTheme } from '../../theme/hooks.mjs';
7
+ import { ColorToken } from '../../../utils/colors.mjs';
8
8
  import clsx from 'clsx';
9
9
 
10
+ const {
11
+ Row,
12
+ Col
13
+ } = Grid;
10
14
  const styles = {
15
+ space: {
16
+ marginBottom: "musae-a4cli4",
17
+ $$css: true
18
+ },
11
19
  required: props => [{
12
20
  "::before_content": "musae-ilz4u6",
13
21
  "::before_color": "musae-gyfpa5",
@@ -19,16 +27,13 @@ const styles = {
19
27
  "--1g451k2": props.color != null ? props.color : "initial"
20
28
  }]
21
29
  };
22
- const {
23
- Row,
24
- Col
25
- } = Grid;
26
30
  /**
27
31
  * @description
28
- * item grid
32
+ * item layout
29
33
  */
30
- const Gridded = ({
34
+ const Layout = ({
31
35
  required,
36
+ space,
32
37
  ...props$1
33
38
  }) => {
34
39
  const contextValue = useContext(Context);
@@ -36,9 +41,7 @@ const Gridded = ({
36
41
  const wrapperCol = props$1.wrapperCol ?? contextValue.wrapperCol;
37
42
  const theme = useTheme();
38
43
  const styled = {
39
- item: {
40
- className: "musae-a4cli4"
41
- },
44
+ item: props(!!space && styles.space),
42
45
  label: props(required && styles.required({
43
46
  color: theme.colors[ColorToken.Error]
44
47
  }), typography.label.small)
@@ -56,6 +59,6 @@ const Gridded = ({
56
59
  span: wrapperCol
57
60
  }, props$1.children));
58
61
  };
59
- var Gridded$1 = Gridded;
62
+ var Layout$1 = Layout;
60
63
 
61
- export { Gridded$1 as default };
64
+ export { Layout$1 as default };
@@ -1,6 +1,6 @@
1
- import React, { forwardRef, useImperativeHandle, useMemo, useEffect } from 'react';
1
+ import React, { forwardRef, useImperativeHandle, useMemo } from 'react';
2
2
  import { useForm, FormProvider } from 'react-hook-form';
3
- import { isUndefined } from '@aiszlab/relax';
3
+ import { useEvent, useMounted, isUndefined } from '@aiszlab/relax';
4
4
  import Context, { CONTEXT_VALUE } from './context.mjs';
5
5
 
6
6
  const Form = forwardRef(({ onSubmit, onChange, labelCol, wrapperCol, children }, ref) => {
@@ -27,21 +27,22 @@ const Form = forwardRef(({ onSubmit, onChange, labelCol, wrapperCol, children },
27
27
  getFieldsError,
28
28
  getFieldError,
29
29
  getValues: methods.getValues,
30
+ reset: methods.reset,
30
31
  };
31
32
  });
32
- const _submit = useMemo(() => {
33
+ const submit = useEvent(() => {
33
34
  return handleSubmit((values) => {
34
35
  onSubmit?.(values);
35
36
  });
36
- }, [onSubmit, handleSubmit]);
37
- useEffect(() => {
38
- const subscription = watch((values, { type }) => {
37
+ });
38
+ useMounted(() => {
39
+ const watched = watch((values, { type }) => {
39
40
  type === "change" && onChange?.(values);
40
41
  });
41
42
  return () => {
42
- subscription.unsubscribe();
43
+ watched.unsubscribe();
43
44
  };
44
- }, [onChange, watch]);
45
+ });
45
46
  /// context value
46
47
  const contextValue = useMemo(() => {
47
48
  return {
@@ -56,7 +57,7 @@ const Form = forwardRef(({ onSubmit, onChange, labelCol, wrapperCol, children },
56
57
  }, [labelCol, wrapperCol]);
57
58
  return (React.createElement(Context.Provider, { value: contextValue },
58
59
  React.createElement(FormProvider, { handleSubmit: handleSubmit, watch: watch, ...methods },
59
- React.createElement("form", { onSubmit: _submit }, children))));
60
+ React.createElement("form", { onSubmit: submit }, children))));
60
61
  });
61
62
  var _Form = Form;
62
63
 
@@ -1,2 +1,3 @@
1
- import type { TypedForm } from "./types";
1
+ import type { TypedForm, FormRef } from "./types";
2
2
  export declare const Form: TypedForm;
3
+ export { FormRef };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import Field from './field.mjs';
3
- import Gridded from './gridded.mjs';
2
+ import Field from './field/field.mjs';
3
+ import Layout from './field/layout.mjs';
4
4
 
5
5
  /**
6
6
  * @description
@@ -10,7 +10,7 @@ const Item = ({ required = false, ...props }) => {
10
10
  if (props.name) {
11
11
  return React.createElement(Field, { ...props, name: props.name, required: required });
12
12
  }
13
- return (React.createElement(Gridded, { label: props.label, labelCol: props.labelCol, wrapperCol: props.wrapperCol, required: required }, props.children));
13
+ return (React.createElement(Layout, { label: props.label, labelCol: props.labelCol, wrapperCol: props.wrapperCol, required: required, space: true }, props.children));
14
14
  };
15
15
  var Item$1 = Item;
16
16
 
@@ -1,12 +1,12 @@
1
- import type { ExoticComponent, ReactNode } from "react";
2
- import type { DeepPartial, FieldError, FieldErrors, FieldPath, FieldValues, UseFormGetValues, UseFormTrigger } from "react-hook-form";
1
+ import type { ForwardRefExoticComponent, PropsWithoutRef, ReactNode, RefAttributes } from "react";
2
+ import type { DeepPartial, FieldError, FieldErrors, FieldPath, FieldValues, UseFormGetValues, UseFormReset, UseFormTrigger } from "react-hook-form";
3
3
  import type { Nullable, Partialable } from "@aiszlab/relax/types";
4
4
  /**
5
5
  * @author murukal
6
6
  * @description
7
7
  * form ref
8
8
  */
9
- export interface FormRef<T extends FieldValues> {
9
+ export interface FormRef<T extends FieldValues = FieldValues> {
10
10
  /**
11
11
  * @description
12
12
  * validate
@@ -30,6 +30,11 @@ export interface FormRef<T extends FieldValues> {
30
30
  * get single field error
31
31
  */
32
32
  getValues: UseFormGetValues<T>;
33
+ /**
34
+ * @description
35
+ * reset form to default values, and clear all validation errors
36
+ */
37
+ reset: UseFormReset<T>;
33
38
  }
34
39
  /**
35
40
  * @author murukal
@@ -103,7 +108,7 @@ export interface FormItemProps extends Pick<FormProps<unknown>, "labelCol" | "wr
103
108
  * @description
104
109
  * typed form
105
110
  */
106
- export interface TypedForm<T extends FieldValues = FieldValues> extends ExoticComponent<FormProps<T>> {
111
+ export interface TypedForm<T extends FieldValues = FieldValues> extends ForwardRefExoticComponent<PropsWithoutRef<FormProps<T>> & RefAttributes<FormRef<T>>> {
107
112
  Item: (props: FormItemProps) => ReactNode;
108
113
  }
109
114
  /**
@@ -25,7 +25,7 @@ const Col = ({
25
25
  }));
26
26
  const classNames = useClassNames(ComponentToken.Grid);
27
27
  return React.createElement(As, {
28
- className: clsx(styled.className, classNames[GridClassToken.Col], className),
28
+ className: clsx(classNames[GridClassToken.Col], className, styled.className),
29
29
  style: {
30
30
  ...styled.style,
31
31
  ...props$1.style
@@ -41,7 +41,7 @@ const Row = ({
41
41
  align
42
42
  }));
43
43
  return React.createElement(As, {
44
- className: clsx(styled.className, classNames[GridClassToken.Row], className),
44
+ className: clsx(classNames[GridClassToken.Row], className, styled.className),
45
45
  style: {
46
46
  ...styled.style,
47
47
  ...props$1.style
@@ -13,7 +13,7 @@ export declare const useStyles: ([className, isFocused, isInvalid]: [className:
13
13
  * use events for input
14
14
  */
15
15
  export declare const useInputEvents: ({ setValue, onBlur, onChange, onClick, onFocus, }: Pick<InputProps, "onClick" | "onFocus" | "onBlur" | "onChange"> & {
16
- setValue: Dispatch<SetStateAction<Partialable<string>>>;
16
+ setValue: Dispatch<SetStateAction<string>>;
17
17
  }) => {
18
18
  focus: FocusEventHandler<HTMLInputElement>;
19
19
  blur: FocusEventHandler<HTMLInputElement>;
@@ -127,9 +127,7 @@ const Input = forwardRef((props$1, ref) => {
127
127
  }
128
128
  }), []);
129
129
  /// controlled value
130
- const [_value, _setValue] = useControlledState(props$1.value, {
131
- defaultState: ""
132
- });
130
+ const [_value, _setValue] = useControlledState(props$1.value ?? "");
133
131
  /// events
134
132
  const inputEvents = useInputEvents({
135
133
  setValue: _setValue,
@@ -19,7 +19,7 @@ const Holder = forwardRef((props, ref) => {
19
19
  if (messages.size === 0) return null;
20
20
  return React.createElement("div", {
21
21
  ...{
22
- className: "musae-ixxii4 musae-78zum5 musae-dt5ytf musae-6s0dn4 musae-n9wirt musae-47corl musae-11uqc5h musae-12vixxq musae-utp9vd"
22
+ className: "musae-ixxii4 musae-13vifvy musae-u96u03 musae-3m8u43 musae-11uqc5h musae-78zum5 musae-dt5ytf musae-6s0dn4 musae-47corl musae-12vixxq musae-utp9vd"
23
23
  }
24
24
  }, React.createElement(AnimatePresence, null, Array.from(messages.values()).map(({
25
25
  content,
@@ -1,4 +1,4 @@
1
- import React, { createElement } from 'react';
1
+ import React, { useMemo, createElement } from 'react';
2
2
  import { useTimeout } from '@aiszlab/relax';
3
3
  import { props } from '../../node_modules/@stylexjs/stylex/lib/es/stylex.mjs';
4
4
  import { useTheme } from '../theme/hooks.mjs';
@@ -22,7 +22,7 @@ const styles = {
22
22
  paddingLeft: null,
23
23
  paddingEnd: null,
24
24
  paddingRight: null,
25
- borderRadius: "musae-1kogg8i",
25
+ borderRadius: "musae-1gg5qfe",
26
26
  borderStartStartRadius: null,
27
27
  borderStartEndRadius: null,
28
28
  borderEndStartRadius: null,
@@ -31,16 +31,18 @@ const styles = {
31
31
  borderTopRightRadius: null,
32
32
  borderBottomLeftRadius: null,
33
33
  borderBottomRightRadius: null,
34
- backgroundColor: "musae-q1mx2j",
35
34
  boxShadow: "musae-jdr3co",
36
35
  display: "musae-78zum5",
37
36
  alignItems: "musae-1cy8zhl",
38
37
  columnGap: "musae-1om1yv4",
39
38
  maxWidth: "musae-kfv0gj",
40
39
  pointerEvents: "musae-67bb7w",
40
+ backgroundColor: "musae-q1mx2j",
41
+ color: "musae-19dipnz",
41
42
  $$css: true
42
43
  }, {
43
- "--backgroundColor": props.backgroundColor != null ? props.backgroundColor : "initial"
44
+ "--backgroundColor": props.backgroundColor != null ? props.backgroundColor : "initial",
45
+ "--color": props.color != null ? props.color : "initial"
44
46
  }],
45
47
  content: {
46
48
  display: "musae-1rg5ohu",
@@ -58,15 +60,20 @@ const Message = ({
58
60
  useTimeout(() => {
59
61
  onClose?.();
60
62
  }, duration);
61
- const color = type === "success" ? theme.colors[ColorToken.Primary] : theme.colors[ColorToken.Error] ;
63
+ const colors = useMemo(() => ({
64
+ success: theme.colors[ColorToken.Primary],
65
+ error: theme.colors[ColorToken.Error]
66
+ }), [theme]);
62
67
  const styled = {
63
68
  message: props(styles.message({
64
- backgroundColor: theme.colors[ColorToken.OnPrimary]
69
+ backgroundColor: theme.colors[ColorToken.OnPrimary],
70
+ color: theme.colors[ColorToken.OnPrimaryContainer]
65
71
  })),
66
72
  content: props(typography.body.medium, styles.content)
67
73
  };
68
74
  return React.createElement(motion.div, {
69
- ...styled.message,
75
+ className: styled.message.className,
76
+ style: styled.message.style,
70
77
  initial: {
71
78
  y: "-100%",
72
79
  opacity: 0
@@ -80,7 +87,7 @@ const Message = ({
80
87
  opacity: 0
81
88
  }
82
89
  }, SIGNALS.get(type) && createElement(SIGNALS.get(type), {
83
- color
90
+ color: colors[type]
84
91
  }), React.createElement("span", {
85
92
  ...styled.content
86
93
  }, children));
@@ -24,10 +24,10 @@ const useEvents = ({ onBlur, onClick, }) => {
24
24
  const useFadeAnimate = () => {
25
25
  const [scope, animate] = useAnimate();
26
26
  const fadeIn = useEvent(async () => {
27
- await animate(scope.current, { opacity: 1 }, { duration: 0.05 });
27
+ await animate(scope.current, { opacity: 1 }, { duration: 0.2 });
28
28
  });
29
29
  const fadeOut = useEvent(async () => {
30
- await animate(scope.current, { opacity: 0 }, { duration: 0.05 });
30
+ await animate(scope.current, { opacity: 0 }, { duration: 0.2 });
31
31
  });
32
32
  return {
33
33
  scope,
@@ -1,9 +1,10 @@
1
1
  import React, { forwardRef, useRef, useImperativeHandle, useEffect } from 'react';
2
2
  import { createPopper } from '@popperjs/core';
3
3
  import { ComponentToken, PopperClassToken } from '../../utils/class-name.mjs';
4
- import { useMounted } from '@aiszlab/relax';
4
+ import { useMount } from '@aiszlab/relax';
5
5
  import { useClassNames } from '../config/hooks.mjs';
6
6
  import clsx from 'clsx';
7
+ import { toClassList } from '../../utils/styles.mjs';
7
8
 
8
9
  const Dropdown = forwardRef(({
9
10
  open,
@@ -24,18 +25,20 @@ const Dropdown = forwardRef(({
24
25
  popper.current?.update();
25
26
  }
26
27
  }));
27
- useMounted(() => {
28
+ /// fix: why use mount instead of use mounted?
29
+ /// when mounted, this div display a normal block, must sync to popper.
30
+ useMount(() => {
28
31
  if (!trigger) return;
29
32
  if (!container.current) return;
30
- const popped = createPopper(trigger, container.current, {
33
+ const _popper = createPopper(trigger, container.current, {
31
34
  placement,
32
35
  modifiers: [{
33
36
  name: "flip"
34
37
  }]
35
38
  });
36
- popper.current = popped;
39
+ popper.current = _popper;
37
40
  return () => {
38
- popped.destroy();
41
+ _popper.destroy();
39
42
  };
40
43
  });
41
44
  const styled = {
@@ -48,14 +51,13 @@ const Dropdown = forwardRef(({
48
51
  };
49
52
  useEffect(() => {
50
53
  (async () => {
51
- const toggleBy = styled.hidden.className?.split(" ") ?? [];
52
54
  if (open) {
53
- container.current?.classList.remove(...toggleBy);
55
+ container.current?.classList.remove(...toClassList(styled.hidden.className));
54
56
  await onEntered?.();
55
57
  return;
56
58
  }
57
59
  await onExit?.();
58
- container.current?.classList.add(...toggleBy);
60
+ container.current?.classList.add(...toClassList(styled.hidden.className));
59
61
  })();
60
62
  // eslint-disable-next-line react-hooks/exhaustive-deps
61
63
  }, [open]);
@@ -65,7 +67,6 @@ const Dropdown = forwardRef(({
65
67
  className: clsx(classNames[PopperClassToken.Dropdown], className, styled.dropdown.className),
66
68
  style: {
67
69
  ...styled.dropdown.style,
68
- ...styled.hidden.style,
69
70
  ...style
70
71
  }
71
72
  }, children);
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  /**
3
2
  * @description
4
3
  * repaint child
@@ -7,7 +6,7 @@ export declare const useRepaint: ({ columns, rowGap }: {
7
6
  columns: number;
8
7
  rowGap: number;
9
8
  }) => {
10
- maxHeight: import("react").MutableRefObject<number>;
9
+ maxHeight: number;
11
10
  collect: (index: number, ref: HTMLDivElement | null) => void;
12
11
  getOrder: (index: number) => number | null;
13
12
  };
@@ -1,4 +1,4 @@
1
- import { useRef, useCallback, useEffect } from 'react';
1
+ import { useRef, useState, useCallback, useEffect } from 'react';
2
2
 
3
3
  /**
4
4
  * @description
@@ -6,32 +6,30 @@ import { useRef, useCallback, useEffect } from 'react';
6
6
  */
7
7
  const useRepaint = ({ columns, rowGap }) => {
8
8
  const items = useRef(new Map());
9
- const orders = useRef(new Map());
10
- const maxHeight = useRef(0);
9
+ const [maxHeight, setMaxHeight] = useState(0);
10
+ const [orders, setOrders] = useState(new Map());
11
11
  const collect = useCallback((index, ref) => {
12
12
  items.current.set(index, ref);
13
13
  }, []);
14
14
  useEffect(() => {
15
- const columnHeights = new Array(columns).fill(0);
16
- // reset
17
- orders.current.clear();
18
- maxHeight.current = 0;
19
- Array.from(items.current.entries()).forEach(([index, child]) => {
15
+ const [columnHeights, _orders] = Array.from(items.current.entries()).reduce((prev, [index, child]) => {
20
16
  if (!child)
21
- return;
17
+ return prev;
22
18
  const childHeight = child.getBoundingClientRect().height;
23
- const order = columnHeights.indexOf(Math.min(...columnHeights));
19
+ const order = prev[0].indexOf(Math.min(...prev[0]));
24
20
  // count
25
- columnHeights[order] = columnHeights[order] + (columnHeights[order] && rowGap) + childHeight;
21
+ prev[0][order] = prev[0][order] + (prev[0][order] && rowGap) + childHeight;
26
22
  // set order for render
27
- orders.current.set(index, order + 1);
28
- });
29
- maxHeight.current = Math.max(...columnHeights);
23
+ prev[1].set(index, order + 1);
24
+ return prev;
25
+ }, [new Array(columns).fill(0), new Map()]);
26
+ setMaxHeight(Math.max(...columnHeights));
27
+ setOrders(_orders);
30
28
  // eslint-disable-next-line react-hooks/exhaustive-deps
31
29
  }, [rowGap]);
32
30
  const getOrder = useCallback((index) => {
33
- return orders.current.get(index) ?? null;
34
- }, []);
31
+ return orders.get(index) ?? null;
32
+ }, [orders]);
35
33
  return {
36
34
  maxHeight,
37
35
  collect,
@@ -59,8 +59,8 @@ const Waterfall = ({
59
59
  const styled = props(styles.waterfall({
60
60
  rowGap,
61
61
  columnGap
62
- }), maxHeight.current > 0 && styles.repainted({
63
- maxHeight: maxHeight.current
62
+ }), maxHeight > 0 && styles.repainted({
63
+ maxHeight: maxHeight
64
64
  }));
65
65
  if (children.length === 0) return null;
66
66
  return React.createElement("div", {
package/dist/index.d.ts CHANGED
@@ -18,7 +18,7 @@ export { Breadcrumb } from "./components/breadcrumb";
18
18
  export { Tabs } from "./components/tabs";
19
19
  export { ThemeProvider } from "./components/theme";
20
20
  export { ConfigProvider } from "./components/config";
21
- export { Form } from "./components/form";
21
+ export { Form, FormRef } from "./components/form";
22
22
  export { Empty } from "./components/empty";
23
23
  export { Drawer } from "./components/drawer";
24
24
  export { Dialog } from "./components/dialog";
package/dist/stylex.css CHANGED
@@ -24,7 +24,6 @@
24
24
  .musae-9r1u3d:not(#\#):not(#\#){border-color:transparent}
25
25
  .musae-eqt46j:not(#\#):not(#\#){border-color:var(--borderColor,revert)}
26
26
  .musae-12oqio5:not(#\#):not(#\#){border-radius:4px}
27
- .musae-1kogg8i:not(#\#):not(#\#){border-radius:6px}
28
27
  .musae-ur7f20:not(#\#):not(#\#){border-radius:8px}
29
28
  .musae-1pjcqnp:not(#\#):not(#\#){border-radius:inherit}
30
29
  .musae-1gg5qfe:not(#\#):not(#\#){border-radius:var(--musae-1l9c3uf)}
@@ -53,7 +52,6 @@
53
52
  .musae-ohadnq:not(#\#):not(#\#){outline:var(--musae-1aj7t22)}
54
53
  .musae-ysyzu8:not(#\#):not(#\#){overflow:auto}
55
54
  .musae-b3r6kr:not(#\#):not(#\#){overflow:hidden}
56
- .musae-24n1ab:not(#\#):not(#\#){padding-block:var(--musae-1h5s2h0)}
57
55
  .musae-avjae4:not(#\#):not(#\#){padding-block:var(--musae-1ncxh3n)}
58
56
  .musae-1c9czsq:not(#\#):not(#\#){padding-block:var(--musae-1tzp6vk)}
59
57
  .musae-hwhe2e:not(#\#):not(#\#){padding-block:var(--musae-1wblvyz)}
@@ -219,7 +217,6 @@ html[dir='rtl'] .musae-1yc453h:not(#\#):not(#\#):not(#\#){text-align:right}
219
217
  .musae-12cinw4:not(#\#):not(#\#):not(#\#):not(#\#){height:var(--musae-wll1cf)}
220
218
  .musae-u96u03:not(#\#):not(#\#):not(#\#):not(#\#){left:0}
221
219
  .musae-101gtxs:not(#\#):not(#\#):not(#\#):not(#\#){left:var(--left,revert)}
222
- .musae-uwzj2e:not(#\#):not(#\#):not(#\#):not(#\#){margin-bottom:calc(var(--musae-1tzp6vk) * -1)}
223
220
  .musae-hq7bbv:not(#\#):not(#\#):not(#\#):not(#\#){margin-bottom:var(--musae-15cw4i4)}
224
221
  .musae-a4cli4:not(#\#):not(#\#):not(#\#):not(#\#){margin-bottom:var(--musae-1tzp6vk)}
225
222
  .musae-rsi211:not(#\#):not(#\#):not(#\#):not(#\#){margin-bottom:var(--musae-qk2ac7)}
@@ -247,11 +244,13 @@ html[dir='rtl'] .musae-1yc453h:not(#\#):not(#\#):not(#\#){text-align:right}
247
244
  .musae-6ikm8r:not(#\#):not(#\#):not(#\#):not(#\#){overflow-x:hidden}
248
245
  .musae-10wlt62:not(#\#):not(#\#):not(#\#):not(#\#){overflow-y:hidden}
249
246
  .musae-1244622:not(#\#):not(#\#):not(#\#):not(#\#){padding-bottom:var(--musae-1tzp6vk)}
247
+ .musae-78w2x6:not(#\#):not(#\#):not(#\#):not(#\#){padding-bottom:var(--musae-qk2ac7)}
250
248
  .musae-1k3zc6d:not(#\#):not(#\#):not(#\#):not(#\#){padding-left:var(--paddingLeft,revert)}
251
249
  .musae-sgdd5s:not(#\#):not(#\#):not(#\#):not(#\#){padding-right:var(--musae-1ncxh3n)}
252
250
  .musae-1y1aa1q:not(#\#):not(#\#):not(#\#):not(#\#){padding-right:var(--musae-oohzsl)}
253
251
  .musae-1teihh3:not(#\#):not(#\#):not(#\#):not(#\#){padding-right:var(--musae-vk5id6)}
254
252
  .musae-522f2k:not(#\#):not(#\#):not(#\#):not(#\#){padding-top:var(--musae-oohzsl)}
253
+ .musae-1p848mt:not(#\#):not(#\#):not(#\#):not(#\#){padding-top:var(--musae-qk2ac7)}
255
254
  .musae-utp9vd:not(#\#):not(#\#):not(#\#):not(#\#){padding-top:var(--musae-vk5id6)}
256
255
  .musae-3m8u43:not(#\#):not(#\#):not(#\#):not(#\#){right:0}
257
256
  .musae-6al1c1:not(#\#):not(#\#):not(#\#):not(#\#){right:var(--musae-oohzsl)}
@@ -260,7 +259,6 @@ html[dir='rtl'] .musae-1yc453h:not(#\#):not(#\#):not(#\#){text-align:right}
260
259
  .musae-9c655z:not(#\#):not(#\#):not(#\#):not(#\#){top:var(--musae-oohzsl)}
261
260
  .musae-rzbxsz:not(#\#):not(#\#):not(#\#):not(#\#){top:var(--top,revert)}
262
261
  .musae-h8yej3:not(#\#):not(#\#):not(#\#):not(#\#){width:100%}
263
- .musae-n9wirt:not(#\#):not(#\#):not(#\#):not(#\#){width:100vw}
264
262
  .musae-1i1rx1s:not(#\#):not(#\#):not(#\#):not(#\#){width:1px}
265
263
  .musae-afpxmx:not(#\#):not(#\#):not(#\#):not(#\#){width:240px}
266
264
  .musae-vy4d1p:not(#\#):not(#\#):not(#\#):not(#\#){width:24px}
@@ -64,8 +64,9 @@ export declare enum PopperClassToken {
64
64
  }
65
65
  export declare enum FormClassToken {
66
66
  Item = 0,
67
- ItemExplain = 1,
68
- ItemExplainError = 2
67
+ Field = 1,
68
+ FieldSupporting = 2,
69
+ FieldError = 3
69
70
  }
70
71
  export declare enum GridClassToken {
71
72
  Row = 0,
@@ -198,6 +199,7 @@ export declare const CLASS_NAMES: {
198
199
  0: string;
199
200
  1: string;
200
201
  2: string;
202
+ 3: string;
201
203
  };
202
204
  5: {
203
205
  0: string;
@@ -328,6 +330,7 @@ export declare const addPrefix: (classNames: ClassNames, prefix: string) => {
328
330
  0: string;
329
331
  1: string;
330
332
  2: string;
333
+ 3: string;
331
334
  };
332
335
  5: {
333
336
  0: string;
@@ -458,6 +461,7 @@ export declare const DEFAULT_CLASS_NAMES: {
458
461
  0: string;
459
462
  1: string;
460
463
  2: string;
464
+ 3: string;
461
465
  };
462
466
  5: {
463
467
  0: string;
@@ -79,8 +79,9 @@ var PopperClassToken;
79
79
  var FormClassToken;
80
80
  (function (FormClassToken) {
81
81
  FormClassToken[FormClassToken["Item"] = 0] = "Item";
82
- FormClassToken[FormClassToken["ItemExplain"] = 1] = "ItemExplain";
83
- FormClassToken[FormClassToken["ItemExplainError"] = 2] = "ItemExplainError";
82
+ FormClassToken[FormClassToken["Field"] = 1] = "Field";
83
+ FormClassToken[FormClassToken["FieldSupporting"] = 2] = "FieldSupporting";
84
+ FormClassToken[FormClassToken["FieldError"] = 3] = "FieldError";
84
85
  })(FormClassToken || (FormClassToken = {}));
85
86
  var GridClassToken;
86
87
  (function (GridClassToken) {
@@ -231,8 +232,9 @@ const CLASS_NAMES = {
231
232
  },
232
233
  [ComponentToken.Form]: {
233
234
  [FormClassToken.Item]: "form__item",
234
- [FormClassToken.ItemExplain]: "form__item-explain",
235
- [FormClassToken.ItemExplainError]: "form__item-explain--error",
235
+ [FormClassToken.Field]: "form__item-field",
236
+ [FormClassToken.FieldSupporting]: "form__item-supporting",
237
+ [FormClassToken.FieldError]: "form__item-field-error",
236
238
  },
237
239
  [ComponentToken.Grid]: {
238
240
  [GridClassToken.Row]: "grid__row",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musae",
3
- "version": "0.1.32",
3
+ "version": "0.1.34",
4
4
  "description": "musae-ui",
5
5
  "author": "tutu@fantufantu.com",
6
6
  "license": "MIT",
@@ -22,7 +22,7 @@
22
22
  }
23
23
  },
24
24
  "dependencies": {
25
- "@aiszlab/relax": "1.2.29",
25
+ "@aiszlab/relax": "^1.2.30",
26
26
  "@popperjs/core": "^2.11.8",
27
27
  "@tanstack/react-table": "^8.11.3",
28
28
  "clsx": "^2.1.0",
@@ -1,15 +0,0 @@
1
- import React from "react";
2
- import { type ReactNode } from "react";
3
- import type { ContextValue } from "./types";
4
- /**
5
- * @description
6
- * item grid
7
- */
8
- declare const Gridded: ({ required, ...props }: {
9
- children: ReactNode;
10
- label?: string | undefined;
11
- labelCol?: number | undefined;
12
- wrapperCol?: number | undefined;
13
- required: boolean;
14
- }) => React.JSX.Element;
15
- export default Gridded;