musae 0.3.8 → 0.3.9

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 (32) hide show
  1. package/dist/components/avatar/group.cjs +4 -5
  2. package/dist/components/avatar/group.mjs +5 -6
  3. package/dist/components/countdown/countdown.cjs +25 -6
  4. package/dist/components/countdown/countdown.d.ts +1 -1
  5. package/dist/components/countdown/countdown.mjs +25 -6
  6. package/dist/components/form/field/field.cjs +8 -3
  7. package/dist/components/form/field/field.mjs +9 -4
  8. package/dist/components/form/item.cjs +16 -5
  9. package/dist/components/form/item.d.ts +2 -2
  10. package/dist/components/form/item.mjs +16 -5
  11. package/dist/components/otp-input/hooks.cjs +1 -4
  12. package/dist/components/otp-input/hooks.mjs +2 -5
  13. package/dist/components/otp-input/otp-input.cjs +5 -3
  14. package/dist/components/otp-input/otp-input.d.ts +1 -1
  15. package/dist/components/otp-input/otp-input.mjs +6 -4
  16. package/dist/components/popconfirm/popconfirm.cjs +26 -19
  17. package/dist/components/popconfirm/popconfirm.mjs +28 -21
  18. package/dist/components/popover/hooks.cjs +28 -0
  19. package/dist/components/popover/hooks.d.ts +11 -0
  20. package/dist/components/popover/hooks.mjs +30 -3
  21. package/dist/components/popover/popover.cjs +54 -26
  22. package/dist/components/popover/popover.d.ts +2 -2
  23. package/dist/components/popover/popover.mjs +57 -29
  24. package/dist/locale/locales/en_US.cjs +8 -3
  25. package/dist/locale/locales/en_US.mjs +8 -3
  26. package/dist/locale/locales/zh_CN.cjs +8 -3
  27. package/dist/locale/locales/zh_CN.mjs +8 -3
  28. package/dist/types/countdown.d.ts +1 -1
  29. package/dist/types/locale.d.ts +3 -0
  30. package/dist/types/otp-input.d.ts +2 -1
  31. package/dist/types/popover.d.ts +2 -3
  32. package/package.json +1 -1
@@ -24,15 +24,14 @@ var _Group = function Group(_ref) {
24
24
  };
25
25
  var children = React.useMemo(function () {
26
26
  var _Children$toArray$red = React.Children.toArray(_children).reduce(function (prev, child, index) {
27
- // @ts-ignore
28
- var element = /*#__PURE__*/React.cloneElement(child, {
27
+ var _child = /*#__PURE__*/ /*#__PURE__*/React.isValidElement(child) ? /*#__PURE__*/React.cloneElement(child, {
29
28
  key: "avatars-".concat(index)
30
- });
29
+ }) : child;
31
30
  // great than max, hide current node
32
31
  if (index >= max) {
33
- prev[1].push(element);
32
+ prev[1].push(_child);
34
33
  } else {
35
- prev[0].push(element);
34
+ prev[0].push(_child);
36
35
  }
37
36
  return prev;
38
37
  }, [[], []]),
@@ -1,5 +1,5 @@
1
1
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
- import React, { useMemo, Children, cloneElement } from 'react';
2
+ import React, { useMemo, Children, isValidElement, cloneElement } from 'react';
3
3
  import { Context } from './context.mjs';
4
4
  import { useClassNames } from '../../hooks/use-class-names.mjs';
5
5
  import { AvatarClassToken } from '../../utils/class-name.mjs';
@@ -22,15 +22,14 @@ var _Group = function Group(_ref) {
22
22
  };
23
23
  var children = useMemo(function () {
24
24
  var _Children$toArray$red = Children.toArray(_children).reduce(function (prev, child, index) {
25
- // @ts-ignore
26
- var element = /*#__PURE__*/cloneElement(child, {
25
+ var _child = /*#__PURE__*/ /*#__PURE__*/isValidElement(child) ? /*#__PURE__*/cloneElement(child, {
27
26
  key: "avatars-".concat(index)
28
- });
27
+ }) : child;
29
28
  // great than max, hide current node
30
29
  if (index >= max) {
31
- prev[1].push(element);
30
+ prev[1].push(_child);
32
31
  } else {
33
- prev[0].push(element);
32
+ prev[0].push(_child);
34
33
  }
35
34
  return prev;
36
35
  }, [[], []]),
@@ -1,5 +1,7 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
 
3
+ var _regeneratorRuntime = require('@babel/runtime/helpers/regeneratorRuntime');
4
+ var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
3
5
  var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
6
  var React = require('react');
5
7
  var button = require('../button/button.cjs');
@@ -25,7 +27,8 @@ var Countdown = function Countdown(_ref) {
25
27
  _ref$ripple = _ref.ripple,
26
28
  ripple = _ref$ripple === void 0 ? true : _ref$ripple,
27
29
  className = _ref.className,
28
- style = _ref.style;
30
+ style = _ref.style,
31
+ onClick = _ref.onClick;
29
32
  var trigger = React.useRef(null);
30
33
  var counter = React.useRef(null);
31
34
  var stopper = React.useRef(null);
@@ -64,11 +67,27 @@ var Countdown = function Countdown(_ref) {
64
67
  }
65
68
  })) !== null && _counter$current$subs !== void 0 ? _counter$current$subs : null;
66
69
  });
67
- var start = relax.useEvent(function (e) {
68
- var _trigger$current2;
69
- countdown();
70
- (_trigger$current2 = trigger.current) === null || _trigger$current2 === void 0 || _trigger$current2.next(e);
71
- });
70
+ var start = relax.useEvent(/*#__PURE__*/function () {
71
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(e) {
72
+ var _trigger$current2;
73
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
74
+ while (1) switch (_context.prev = _context.next) {
75
+ case 0:
76
+ _context.next = 2;
77
+ return Promise.resolve(onClick === null || onClick === void 0 ? void 0 : onClick(e));
78
+ case 2:
79
+ countdown();
80
+ (_trigger$current2 = trigger.current) === null || _trigger$current2 === void 0 || _trigger$current2.next(e);
81
+ case 4:
82
+ case "end":
83
+ return _context.stop();
84
+ }
85
+ }, _callee);
86
+ }));
87
+ return function (_x) {
88
+ return _ref2.apply(this, arguments);
89
+ };
90
+ }());
72
91
  return /*#__PURE__*/React.createElement(button.Button, {
73
92
  onClick: start,
74
93
  disabled: disabled || isCounting,
@@ -1,4 +1,4 @@
1
1
  import React from "react";
2
2
  import type { CountdownProps } from "musae/types/countdown";
3
- declare const Countdown: ({ count, children, interval: _interval, disabled, variant, color, shape, size, ripple, className, style, }: CountdownProps) => React.JSX.Element;
3
+ declare const Countdown: ({ count, children, interval: _interval, disabled, variant, color, shape, size, ripple, className, style, onClick, }: CountdownProps) => React.JSX.Element;
4
4
  export default Countdown;
@@ -1,3 +1,5 @@
1
+ import _regeneratorRuntime from '@babel/runtime/helpers/regeneratorRuntime';
2
+ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
1
3
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
4
  import React, { useRef, useState } from 'react';
3
5
  import { Button } from '../button/button.mjs';
@@ -23,7 +25,8 @@ var Countdown = function Countdown(_ref) {
23
25
  _ref$ripple = _ref.ripple,
24
26
  ripple = _ref$ripple === void 0 ? true : _ref$ripple,
25
27
  className = _ref.className,
26
- style = _ref.style;
28
+ style = _ref.style,
29
+ onClick = _ref.onClick;
27
30
  var trigger = useRef(null);
28
31
  var counter = useRef(null);
29
32
  var stopper = useRef(null);
@@ -62,11 +65,27 @@ var Countdown = function Countdown(_ref) {
62
65
  }
63
66
  })) !== null && _counter$current$subs !== void 0 ? _counter$current$subs : null;
64
67
  });
65
- var start = useEvent(function (e) {
66
- var _trigger$current2;
67
- countdown();
68
- (_trigger$current2 = trigger.current) === null || _trigger$current2 === void 0 || _trigger$current2.next(e);
69
- });
68
+ var start = useEvent(/*#__PURE__*/function () {
69
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(e) {
70
+ var _trigger$current2;
71
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
72
+ while (1) switch (_context.prev = _context.next) {
73
+ case 0:
74
+ _context.next = 2;
75
+ return Promise.resolve(onClick === null || onClick === void 0 ? void 0 : onClick(e));
76
+ case 2:
77
+ countdown();
78
+ (_trigger$current2 = trigger.current) === null || _trigger$current2 === void 0 || _trigger$current2.next(e);
79
+ case 4:
80
+ case "end":
81
+ return _context.stop();
82
+ }
83
+ }, _callee);
84
+ }));
85
+ return function (_x) {
86
+ return _ref2.apply(this, arguments);
87
+ };
88
+ }());
70
89
  return /*#__PURE__*/React.createElement(Button, {
71
90
  onClick: start,
72
91
  disabled: disabled || isCounting,
@@ -14,6 +14,7 @@ var framerMotion = require('framer-motion');
14
14
  var theme = require('../../theme/theme.cjs');
15
15
  var useClassNames = require('../../../hooks/use-class-names.cjs');
16
16
  var componentToken = require('../../../utils/component-token.cjs');
17
+ var useLocale = require('../../../locale/use-locale.cjs');
17
18
 
18
19
  var _excluded = ["required", "children", "className", "style"];
19
20
  var styles = {
@@ -29,18 +30,22 @@ var styles = {
29
30
  * if there is name prop, it will render
30
31
  */
31
32
  var Field = function Field(_ref) {
33
+ var _props$label;
32
34
  var required = _ref.required,
33
35
  _children = _ref.children,
34
36
  className$1 = _ref.className,
35
37
  style = _ref.style,
36
38
  props = _objectWithoutProperties(_ref, _excluded);
37
39
  var classNames = useClassNames.useClassNames(componentToken.ComponentToken.Form);
40
+ var _useLocale = useLocale.useLocale(componentToken.ComponentToken.Form),
41
+ _useLocale2 = _slicedToArray(_useLocale, 1),
42
+ locale = _useLocale2[0];
38
43
  var _useController = reactHookForm.useController({
39
44
  name: props.name,
40
45
  rules: {
41
46
  required: {
42
47
  value: required,
43
- message: "".concat(props.name, " is required")
48
+ message: relax.toFunction(locale.required)((_props$label = props.label) !== null && _props$label !== void 0 ? _props$label : props.name)
44
49
  }
45
50
  }
46
51
  }),
@@ -71,7 +76,7 @@ var Field = function Field(_ref) {
71
76
  }, relax.isRefable(_child) && {
72
77
  ref: ref
73
78
  }))), true];
74
- }, [[], false]);
79
+ }, [[], false]).at(0);
75
80
  }, [_children, name, value, invalid, ref, onChange, onBlur]);
76
81
  var styled = {
77
82
  supporting: stylex.default.props(styles.supporting, theme.typography.body.small)
@@ -81,7 +86,7 @@ var Field = function Field(_ref) {
81
86
  required: required,
82
87
  className: classNames[className.FormClassToken.Item]
83
88
  }, /*#__PURE__*/React.createElement("div", {
84
- className: className$1,
89
+ className: relax.clsx(classNames[className.FormClassToken.Field], className$1),
85
90
  style: style
86
91
  }, children), /*#__PURE__*/React.createElement("div", {
87
92
  className: relax.clsx(classNames[className.FormClassToken.FieldSupporting], styled.supporting.className),
@@ -3,7 +3,7 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
3
3
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
4
4
  import React, { useMemo, Children, isValidElement, cloneElement } from 'react';
5
5
  import { useController } from 'react-hook-form';
6
- import { chain, isRefable, clsx } from '@aiszlab/relax';
6
+ import { toFunction, chain, isRefable, clsx } from '@aiszlab/relax';
7
7
  import { FormClassToken } from '../../../utils/class-name.mjs';
8
8
  import _stylex from '../../../node_modules/.pnpm/@stylexjs_stylex@0.7.5/node_modules/@stylexjs/stylex/lib/es/stylex.mjs';
9
9
  import Layout from './layout.mjs';
@@ -12,6 +12,7 @@ import { AnimatePresence } from 'framer-motion';
12
12
  import { typography } from '../../theme/theme.mjs';
13
13
  import { useClassNames } from '../../../hooks/use-class-names.mjs';
14
14
  import { ComponentToken } from '../../../utils/component-token.mjs';
15
+ import { useLocale } from '../../../locale/use-locale.mjs';
15
16
 
16
17
  var _excluded = ["required", "children", "className", "style"];
17
18
  var styles = {
@@ -27,18 +28,22 @@ var styles = {
27
28
  * if there is name prop, it will render
28
29
  */
29
30
  var Field = function Field(_ref) {
31
+ var _props$label;
30
32
  var required = _ref.required,
31
33
  _children = _ref.children,
32
34
  className = _ref.className,
33
35
  style = _ref.style,
34
36
  props = _objectWithoutProperties(_ref, _excluded);
35
37
  var classNames = useClassNames(ComponentToken.Form);
38
+ var _useLocale = useLocale(ComponentToken.Form),
39
+ _useLocale2 = _slicedToArray(_useLocale, 1),
40
+ locale = _useLocale2[0];
36
41
  var _useController = useController({
37
42
  name: props.name,
38
43
  rules: {
39
44
  required: {
40
45
  value: required,
41
- message: "".concat(props.name, " is required")
46
+ message: toFunction(locale.required)((_props$label = props.label) !== null && _props$label !== void 0 ? _props$label : props.name)
42
47
  }
43
48
  }
44
49
  }),
@@ -69,7 +74,7 @@ var Field = function Field(_ref) {
69
74
  }, isRefable(_child) && {
70
75
  ref: ref
71
76
  }))), true];
72
- }, [[], false]);
77
+ }, [[], false]).at(0);
73
78
  }, [_children, name, value, invalid, ref, onChange, onBlur]);
74
79
  var styled = {
75
80
  supporting: _stylex.props(styles.supporting, typography.body.small)
@@ -79,7 +84,7 @@ var Field = function Field(_ref) {
79
84
  required: required,
80
85
  className: classNames[FormClassToken.Item]
81
86
  }, /*#__PURE__*/React.createElement("div", {
82
- className: className,
87
+ className: clsx(classNames[FormClassToken.Field], className),
83
88
  style: style
84
89
  }, children), /*#__PURE__*/React.createElement("div", {
85
90
  className: clsx(classNames[FormClassToken.FieldSupporting], styled.supporting.className),
@@ -5,8 +5,12 @@ var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProp
5
5
  var React = require('react');
6
6
  var field = require('./field/field.cjs');
7
7
  var layout = require('./field/layout.cjs');
8
+ var useClassNames = require('../../hooks/use-class-names.cjs');
9
+ var componentToken = require('../../utils/component-token.cjs');
10
+ var relax = require('@aiszlab/relax');
11
+ var className = require('../../utils/class-name.cjs');
8
12
 
9
- var _excluded = ["required"];
13
+ var _excluded = ["required", "className", "style"];
10
14
  /**
11
15
  * @description
12
16
  * item render
@@ -14,9 +18,14 @@ var _excluded = ["required"];
14
18
  var Item = function Item(_ref) {
15
19
  var _ref$required = _ref.required,
16
20
  required = _ref$required === void 0 ? false : _ref$required,
21
+ className$1 = _ref.className,
22
+ style = _ref.style,
17
23
  props = _objectWithoutProperties(_ref, _excluded);
24
+ var classNames = useClassNames.useClassNames(componentToken.ComponentToken.Form);
18
25
  if (props.name) {
19
26
  return /*#__PURE__*/React.createElement(field.default, _objectSpread(_objectSpread({}, props), {}, {
27
+ className: className$1,
28
+ style: style,
20
29
  name: props.name,
21
30
  required: required
22
31
  }));
@@ -26,10 +35,12 @@ var Item = function Item(_ref) {
26
35
  labelCol: props.labelCol,
27
36
  wrapperCol: props.wrapperCol,
28
37
  required: required,
29
- className: props.className,
30
- style: props.style,
31
- space: true
32
- }, props.children);
38
+ space: true,
39
+ className: classNames[className.FormClassToken.Item]
40
+ }, /*#__PURE__*/React.createElement("div", {
41
+ className: relax.clsx(classNames[className.FormClassToken.Field], className$1),
42
+ style: style
43
+ }, props.children));
33
44
  };
34
45
 
35
46
  exports.default = Item;
@@ -1,9 +1,9 @@
1
- import { FormItemProps } from "musae/types/form";
1
+ import type { FormItemProps } from "musae/types/form";
2
2
  import React from "react";
3
3
  import type { FieldValues } from "react-hook-form";
4
4
  /**
5
5
  * @description
6
6
  * item render
7
7
  */
8
- declare const Item: <T extends FieldValues = FieldValues>({ required, ...props }: FormItemProps<T>) => React.JSX.Element;
8
+ declare const Item: <T extends FieldValues = FieldValues>({ required, className, style, ...props }: FormItemProps<T>) => React.JSX.Element;
9
9
  export default Item;
@@ -3,8 +3,12 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
3
3
  import React from 'react';
4
4
  import Field from './field/field.mjs';
5
5
  import Layout from './field/layout.mjs';
6
+ import { useClassNames } from '../../hooks/use-class-names.mjs';
7
+ import { ComponentToken } from '../../utils/component-token.mjs';
8
+ import { clsx } from '@aiszlab/relax';
9
+ import { FormClassToken } from '../../utils/class-name.mjs';
6
10
 
7
- var _excluded = ["required"];
11
+ var _excluded = ["required", "className", "style"];
8
12
  /**
9
13
  * @description
10
14
  * item render
@@ -12,9 +16,14 @@ var _excluded = ["required"];
12
16
  var Item = function Item(_ref) {
13
17
  var _ref$required = _ref.required,
14
18
  required = _ref$required === void 0 ? false : _ref$required,
19
+ className = _ref.className,
20
+ style = _ref.style,
15
21
  props = _objectWithoutProperties(_ref, _excluded);
22
+ var classNames = useClassNames(ComponentToken.Form);
16
23
  if (props.name) {
17
24
  return /*#__PURE__*/React.createElement(Field, _objectSpread(_objectSpread({}, props), {}, {
25
+ className: className,
26
+ style: style,
18
27
  name: props.name,
19
28
  required: required
20
29
  }));
@@ -24,10 +33,12 @@ var Item = function Item(_ref) {
24
33
  labelCol: props.labelCol,
25
34
  wrapperCol: props.wrapperCol,
26
35
  required: required,
27
- className: props.className,
28
- style: props.style,
29
- space: true
30
- }, props.children);
36
+ space: true,
37
+ className: classNames[FormClassToken.Item]
38
+ }, /*#__PURE__*/React.createElement("div", {
39
+ className: clsx(classNames[FormClassToken.Field], className),
40
+ style: style
41
+ }, props.children));
31
42
  };
32
43
 
33
44
  export { Item as default };
@@ -28,10 +28,7 @@ var useValue = function useValue(_ref) {
28
28
  var changed = Array.from(values);
29
29
  changed[index] = otp;
30
30
  var changedValue = changed.join("");
31
- if (relax.isUndefined(_value)) {
32
- setValue(changedValue);
33
- return;
34
- }
31
+ setValue(changedValue);
35
32
  onChange === null || onChange === void 0 || onChange(changedValue);
36
33
  });
37
34
  return {
@@ -1,5 +1,5 @@
1
1
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
- import { useControlledState, useEvent, isUndefined } from '@aiszlab/relax';
2
+ import { useControlledState, useEvent } from '@aiszlab/relax';
3
3
  import { useMemo } from 'react';
4
4
  import { Keyboard } from '../../utils/keyboard.mjs';
5
5
 
@@ -28,10 +28,7 @@ var useValue = function useValue(_ref) {
28
28
  var changed = Array.from(values);
29
29
  changed[index] = otp;
30
30
  var changedValue = changed.join("");
31
- if (isUndefined(_value)) {
32
- setValue(changedValue);
33
- return;
34
- }
31
+ setValue(changedValue);
35
32
  onChange === null || onChange === void 0 || onChange(changedValue);
36
33
  });
37
34
  return {
@@ -11,7 +11,9 @@ var OtpInput = function OtpInput(_ref) {
11
11
  var _ref$length = _ref.length,
12
12
  length = _ref$length === void 0 ? 6 : _ref$length,
13
13
  onChange = _ref.onChange,
14
- _value = _ref.value;
14
+ _value = _ref.value,
15
+ className = _ref.className,
16
+ style = _ref.style;
15
17
  var _useValue = hooks.useValue({
16
18
  length: length,
17
19
  onChange: onChange,
@@ -63,8 +65,8 @@ var OtpInput = function OtpInput(_ref) {
63
65
  }
64
66
  };
65
67
  return /*#__PURE__*/React.createElement("div", {
66
- className: styled.otp.className,
67
- style: styled.otp.style
68
+ className: relax.clsx(styled.otp.className, className),
69
+ style: _objectSpread(_objectSpread({}, styled.otp.style), style)
68
70
  }, value.map(function (item, index) {
69
71
  return /*#__PURE__*/React.createElement(input.default, {
70
72
  key: index,
@@ -1,4 +1,4 @@
1
1
  import React from "react";
2
2
  import type { OtpInputProps } from "musae/types/otp-input";
3
- declare const OtpInput: ({ length, onChange, value: _value }: OtpInputProps) => React.JSX.Element;
3
+ declare const OtpInput: ({ length, onChange, value: _value, className, style }: OtpInputProps) => React.JSX.Element;
4
4
  export default OtpInput;
@@ -3,13 +3,15 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
3
3
  import React, { useRef, useState } from 'react';
4
4
  import { useValue, useInputEvents } from './hooks.mjs';
5
5
  import Input from '../input/input.mjs';
6
- import { useEvent, clamp } from '@aiszlab/relax';
6
+ import { useEvent, clamp, clsx } from '@aiszlab/relax';
7
7
 
8
8
  var OtpInput = function OtpInput(_ref) {
9
9
  var _ref$length = _ref.length,
10
10
  length = _ref$length === void 0 ? 6 : _ref$length,
11
11
  onChange = _ref.onChange,
12
- _value = _ref.value;
12
+ _value = _ref.value,
13
+ className = _ref.className,
14
+ style = _ref.style;
13
15
  var _useValue = useValue({
14
16
  length: length,
15
17
  onChange: onChange,
@@ -61,8 +63,8 @@ var OtpInput = function OtpInput(_ref) {
61
63
  }
62
64
  };
63
65
  return /*#__PURE__*/React.createElement("div", {
64
- className: styled.otp.className,
65
- style: styled.otp.style
66
+ className: clsx(styled.otp.className, className),
67
+ style: _objectSpread(_objectSpread({}, styled.otp.style), style)
66
68
  }, value.map(function (item, index) {
67
69
  return /*#__PURE__*/React.createElement(Input, {
68
70
  key: index,
@@ -56,17 +56,17 @@ var styles = {
56
56
  $$css: true
57
57
  }
58
58
  };
59
- var Popconfirm = function Popconfirm(_ref2) {
60
- var content = _ref2.content,
61
- title = _ref2.title,
62
- onConfirm = _ref2.onConfirm,
63
- onCancel = _ref2.onCancel,
64
- className$1 = _ref2.className,
65
- _ref2$placement = _ref2.placement,
66
- placement = _ref2$placement === void 0 ? "top" : _ref2$placement,
67
- _children = _ref2.children,
68
- style = _ref2.style;
69
- var _ref = React.useRef(null);
59
+ var Popconfirm = function Popconfirm(_ref) {
60
+ var content = _ref.content,
61
+ title = _ref.title,
62
+ onConfirm = _ref.onConfirm,
63
+ onCancel = _ref.onCancel,
64
+ className$1 = _ref.className,
65
+ _ref$placement = _ref.placement,
66
+ placement = _ref$placement === void 0 ? "top" : _ref$placement,
67
+ _children = _ref.children,
68
+ style = _ref.style;
69
+ var ref = React.useRef(null);
70
70
  var _useBoolean = relax.useBoolean(),
71
71
  _useBoolean2 = _slicedToArray(_useBoolean, 2),
72
72
  isOpen = _useBoolean2[0],
@@ -74,7 +74,6 @@ var Popconfirm = function Popconfirm(_ref2) {
74
74
  turnOff = _useBoolean2$.turnOff,
75
75
  toggle = _useBoolean2$.toggle;
76
76
  var classNames = useClassNames.useClassNames(componentToken.ComponentToken.Popconfirm);
77
- var childRef = relax.useRefs(_ref, _children.props.ref);
78
77
  var popperRef = React.useRef(null);
79
78
  var theme$1 = hooks.useTheme();
80
79
  var _useLocale = useLocale.useLocale(componentToken.ComponentToken.Popconfirm),
@@ -92,14 +91,22 @@ var Popconfirm = function Popconfirm(_ref2) {
92
91
  onCancel === null || onCancel === void 0 || onCancel();
93
92
  turnOff();
94
93
  });
95
- // @ts-ignore
96
- var children = /*#__PURE__*/React.cloneElement(_children, {
97
- ref: childRef,
98
- onClick: onClick
99
- });
94
+ var children = React.useMemo(function () {
95
+ var props = {
96
+ ref: ref,
97
+ onClick: onClick
98
+ };
99
+ if (/*#__PURE__*/React.isValidElement(_children)) {
100
+ return /*#__PURE__*/React.cloneElement(_children, props);
101
+ }
102
+ return /*#__PURE__*/React.createElement("div", {
103
+ ref: ref,
104
+ onClick: onClick
105
+ }, _children);
106
+ }, [ref, onClick, _children]);
100
107
  relax.useClickAway(function () {
101
108
  turnOff();
102
- }, [popperRef, _ref]);
109
+ }, [popperRef, ref]);
103
110
  var styled = {
104
111
  popconfirm: {
105
112
  className: "musaex-2wmp0v musaex-16xn7b0 musaex-rvj5dj musaex-183ukxf musaex-1lsrmdg"
@@ -114,7 +121,7 @@ var Popconfirm = function Popconfirm(_ref2) {
114
121
  }
115
122
  };
116
123
  return /*#__PURE__*/React.createElement(React.Fragment, null, children, /*#__PURE__*/React.createElement(popper.default, {
117
- trigger: _ref.current,
124
+ trigger: ref.current,
118
125
  open: isOpen,
119
126
  arrow: true,
120
127
  placement: placement,
@@ -1,12 +1,12 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
3
- import React, { useRef, cloneElement } from 'react';
3
+ import React, { useRef, useMemo, isValidElement, cloneElement } from 'react';
4
4
  import _stylex from '../../node_modules/.pnpm/@stylexjs_stylex@0.7.5/node_modules/@stylexjs/stylex/lib/es/stylex.mjs';
5
5
  import { useClassNames } from '../../hooks/use-class-names.mjs';
6
6
  import { PopconfirmClassToken } from '../../utils/class-name.mjs';
7
7
  import Space from '../space/space.mjs';
8
8
  import { Button } from '../button/button.mjs';
9
- import { useBoolean, useRefs, useEvent, useClickAway, clsx } from '@aiszlab/relax';
9
+ import { useBoolean, useEvent, useClickAway, clsx } from '@aiszlab/relax';
10
10
  import Popper from '../popper/popper.mjs';
11
11
  import { typography } from '../theme/theme.mjs';
12
12
  import { useTheme } from '../theme/hooks.mjs';
@@ -54,17 +54,17 @@ var styles = {
54
54
  $$css: true
55
55
  }
56
56
  };
57
- var Popconfirm = function Popconfirm(_ref2) {
58
- var content = _ref2.content,
59
- title = _ref2.title,
60
- onConfirm = _ref2.onConfirm,
61
- onCancel = _ref2.onCancel,
62
- className = _ref2.className,
63
- _ref2$placement = _ref2.placement,
64
- placement = _ref2$placement === void 0 ? "top" : _ref2$placement,
65
- _children = _ref2.children,
66
- style = _ref2.style;
67
- var _ref = useRef(null);
57
+ var Popconfirm = function Popconfirm(_ref) {
58
+ var content = _ref.content,
59
+ title = _ref.title,
60
+ onConfirm = _ref.onConfirm,
61
+ onCancel = _ref.onCancel,
62
+ className = _ref.className,
63
+ _ref$placement = _ref.placement,
64
+ placement = _ref$placement === void 0 ? "top" : _ref$placement,
65
+ _children = _ref.children,
66
+ style = _ref.style;
67
+ var ref = useRef(null);
68
68
  var _useBoolean = useBoolean(),
69
69
  _useBoolean2 = _slicedToArray(_useBoolean, 2),
70
70
  isOpen = _useBoolean2[0],
@@ -72,7 +72,6 @@ var Popconfirm = function Popconfirm(_ref2) {
72
72
  turnOff = _useBoolean2$.turnOff,
73
73
  toggle = _useBoolean2$.toggle;
74
74
  var classNames = useClassNames(ComponentToken.Popconfirm);
75
- var childRef = useRefs(_ref, _children.props.ref);
76
75
  var popperRef = useRef(null);
77
76
  var theme = useTheme();
78
77
  var _useLocale = useLocale(ComponentToken.Popconfirm),
@@ -90,14 +89,22 @@ var Popconfirm = function Popconfirm(_ref2) {
90
89
  onCancel === null || onCancel === void 0 || onCancel();
91
90
  turnOff();
92
91
  });
93
- // @ts-ignore
94
- var children = /*#__PURE__*/cloneElement(_children, {
95
- ref: childRef,
96
- onClick: onClick
97
- });
92
+ var children = useMemo(function () {
93
+ var props = {
94
+ ref: ref,
95
+ onClick: onClick
96
+ };
97
+ if (/*#__PURE__*/isValidElement(_children)) {
98
+ return /*#__PURE__*/cloneElement(_children, props);
99
+ }
100
+ return /*#__PURE__*/React.createElement("div", {
101
+ ref: ref,
102
+ onClick: onClick
103
+ }, _children);
104
+ }, [ref, onClick, _children]);
98
105
  useClickAway(function () {
99
106
  turnOff();
100
- }, [popperRef, _ref]);
107
+ }, [popperRef, ref]);
101
108
  var styled = {
102
109
  popconfirm: {
103
110
  className: "musaex-2wmp0v musaex-16xn7b0 musaex-rvj5dj musaex-183ukxf musaex-1lsrmdg"
@@ -112,7 +119,7 @@ var Popconfirm = function Popconfirm(_ref2) {
112
119
  }
113
120
  };
114
121
  return /*#__PURE__*/React.createElement(React.Fragment, null, children, /*#__PURE__*/React.createElement(Popper, {
115
- trigger: _ref.current,
122
+ trigger: ref.current,
116
123
  open: isOpen,
117
124
  arrow: true,
118
125
  placement: placement,
@@ -60,5 +60,33 @@ var useIsOpen = function useIsOpen(popperRef) {
60
60
  disappear: disappear
61
61
  }];
62
62
  };
63
+ /**
64
+ * @description
65
+ * used triggers
66
+ */
67
+ var useTriggerBy = function useTriggerBy(triggerBy) {
68
+ var _triggerBy = React.useMemo(function () {
69
+ return new Set(relax.toArray(triggerBy));
70
+ }, [triggerBy]);
71
+ var isHoverable = React.useMemo(function () {
72
+ return _triggerBy.has("hover");
73
+ }, [_triggerBy]);
74
+ var isFocusable = React.useMemo(function () {
75
+ return _triggerBy.has("focus");
76
+ }, [_triggerBy]);
77
+ var isClickable = React.useMemo(function () {
78
+ return _triggerBy.has("click");
79
+ }, [_triggerBy]);
80
+ var isContextMenuable = React.useMemo(function () {
81
+ return _triggerBy.has("contextMenu");
82
+ }, [_triggerBy]);
83
+ return {
84
+ isHoverable: isHoverable,
85
+ isFocusable: isFocusable,
86
+ isClickable: isClickable,
87
+ isContextMenuable: isContextMenuable
88
+ };
89
+ };
63
90
 
64
91
  exports.useIsOpen = useIsOpen;
92
+ exports.useTriggerBy = useTriggerBy;
@@ -1,4 +1,5 @@
1
1
  import type { PopperRef } from "musae/types/popper";
2
+ import { TriggerBy } from "../../types/popover";
2
3
  type UsedIsOpen = [
3
4
  boolean,
4
5
  {
@@ -13,4 +14,14 @@ type UsedIsOpen = [
13
14
  * open state
14
15
  */
15
16
  export declare const useIsOpen: (popperRef: React.RefObject<PopperRef>) => UsedIsOpen;
17
+ /**
18
+ * @description
19
+ * used triggers
20
+ */
21
+ export declare const useTriggerBy: (triggerBy: TriggerBy | TriggerBy[]) => {
22
+ isHoverable: boolean;
23
+ isFocusable: boolean;
24
+ isClickable: boolean;
25
+ isContextMenuable: boolean;
26
+ };
16
27
  export {};
@@ -1,9 +1,9 @@
1
1
  import _regeneratorRuntime from '@babel/runtime/helpers/regeneratorRuntime';
2
2
  import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
3
3
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
- import { useEvent } from '@aiszlab/relax';
4
+ import { useEvent, toArray } from '@aiszlab/relax';
5
5
  import { useLazyBoolean } from '../../hooks/use-lazy-boolean.mjs';
6
- import { useCallback } from 'react';
6
+ import { useCallback, useMemo } from 'react';
7
7
 
8
8
  /**
9
9
  * @description
@@ -60,5 +60,32 @@ var useIsOpen = function useIsOpen(popperRef) {
60
60
  disappear: disappear
61
61
  }];
62
62
  };
63
+ /**
64
+ * @description
65
+ * used triggers
66
+ */
67
+ var useTriggerBy = function useTriggerBy(triggerBy) {
68
+ var _triggerBy = useMemo(function () {
69
+ return new Set(toArray(triggerBy));
70
+ }, [triggerBy]);
71
+ var isHoverable = useMemo(function () {
72
+ return _triggerBy.has("hover");
73
+ }, [_triggerBy]);
74
+ var isFocusable = useMemo(function () {
75
+ return _triggerBy.has("focus");
76
+ }, [_triggerBy]);
77
+ var isClickable = useMemo(function () {
78
+ return _triggerBy.has("click");
79
+ }, [_triggerBy]);
80
+ var isContextMenuable = useMemo(function () {
81
+ return _triggerBy.has("contextMenu");
82
+ }, [_triggerBy]);
83
+ return {
84
+ isHoverable: isHoverable,
85
+ isFocusable: isFocusable,
86
+ isClickable: isClickable,
87
+ isContextMenuable: isContextMenuable
88
+ };
89
+ };
63
90
 
64
- export { useIsOpen };
91
+ export { useIsOpen, useTriggerBy };
@@ -68,11 +68,12 @@ var Popover = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
68
68
  turnOff = _useIsOpen2$.turnOff,
69
69
  toggle = _useIsOpen2$.toggle,
70
70
  disappear = _useIsOpen2$.disappear;
71
- var triggerBy = React.useMemo(function () {
72
- return new Set(relax.toArray(_triggerBy));
73
- }, [_triggerBy]);
74
71
  var classNames = useClassNames.useClassNames(componentToken.ComponentToken.Popover);
75
- var childRef = relax.useRefs(_ref, _children.props.ref);
72
+ var _useTriggerBy = hooks.useTriggerBy(_triggerBy),
73
+ isClickable = _useTriggerBy.isClickable,
74
+ isContextMenuable = _useTriggerBy.isContextMenuable,
75
+ isFocusable = _useTriggerBy.isFocusable,
76
+ isHoverable = _useTriggerBy.isHoverable;
76
77
  var onClick = relax.useEvent(function (event) {
77
78
  event.stopPropagation();
78
79
  toggle();
@@ -81,34 +82,61 @@ var Popover = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
81
82
  event.preventDefault();
82
83
  toggle();
83
84
  });
85
+ // hover enter callback
86
+ var onHoverEnter = React.useCallback(function (event) {
87
+ var _children$props$onMou, _children$props, _children$props$onPoi, _children$props2;
88
+ turnOn();
89
+ if (! /*#__PURE__*/React.isValidElement(_children)) return;
90
+ (_children$props$onMou = (_children$props = _children.props).onMouseEnter) === null || _children$props$onMou === void 0 || _children$props$onMou.call(_children$props, event);
91
+ (_children$props$onPoi = (_children$props2 = _children.props).onPointerEnter) === null || _children$props$onPoi === void 0 || _children$props$onPoi.call(_children$props2, event);
92
+ }, [_children, turnOn]);
93
+ // hover leave callback
94
+ var onHoverLeave = React.useCallback(function (event) {
95
+ var _children$props$onMou2, _children$props3, _children$props$onPoi2, _children$props4;
96
+ turnOff();
97
+ if (! /*#__PURE__*/React.isValidElement(_children)) return;
98
+ (_children$props$onMou2 = (_children$props3 = _children.props).onMouseLeave) === null || _children$props$onMou2 === void 0 || _children$props$onMou2.call(_children$props3, event);
99
+ (_children$props$onPoi2 = (_children$props4 = _children.props).onPointerLeave) === null || _children$props$onPoi2 === void 0 || _children$props$onPoi2.call(_children$props4, event);
100
+ }, [_children, turnOff]);
84
101
  var _useHover = relax.useHover({
85
- onEnter: function onEnter(event) {
86
- return relax.chain(_children.props.onMouseEnter, _children.props.onPointerEnter, turnOn)(event);
87
- },
88
- onLeave: function onLeave(event) {
89
- return relax.chain(_children.props.onMouseLeave, _children.props.onPointerLeave, disappear)(event);
90
- }
102
+ onEnter: onHoverEnter,
103
+ onLeave: onHoverLeave
91
104
  }),
92
105
  _useHover2 = _slicedToArray(_useHover, 2),
93
106
  hoverProps = _useHover2[1];
107
+ var onFocus = React.useCallback(function (event) {
108
+ var _children$props$onFoc, _children$props5;
109
+ turnOn();
110
+ if (! /*#__PURE__*/React.isValidElement(_children)) return;
111
+ (_children$props$onFoc = (_children$props5 = _children.props).onFocus) === null || _children$props$onFoc === void 0 || _children$props$onFoc.call(_children$props5, event);
112
+ }, [_children, turnOn]);
113
+ var onBlur = React.useCallback(function (event) {
114
+ var _children$props$onBlu, _children$props6;
115
+ turnOff();
116
+ if (! /*#__PURE__*/React.isValidElement(_children)) return;
117
+ (_children$props$onBlu = (_children$props6 = _children.props).onBlur) === null || _children$props$onBlu === void 0 || _children$props$onBlu.call(_children$props6, event);
118
+ }, [_children, turnOff]);
94
119
  var _useFocus = relax.useFocus({
95
- onFocus: function onFocus(event) {
96
- return relax.chain(_children.props.onFocus, turnOn)(event);
97
- },
98
- onBlur: function onBlur(event) {
99
- return relax.chain(_children.props.onBlur, disappear)(event);
100
- }
120
+ onFocus: onFocus,
121
+ onBlur: onBlur
101
122
  }),
102
123
  _useFocus2 = _slicedToArray(_useFocus, 2),
103
124
  focusProps = _useFocus2[1];
104
- // @ts-ignore
105
- var children = /*#__PURE__*/React.cloneElement(_children, _objectSpread(_objectSpread(_objectSpread(_objectSpread({
106
- ref: childRef
107
- }, triggerBy.has("hover") && hoverProps), triggerBy.has("focus") && focusProps), triggerBy.has("click") && {
108
- onClick: onClick
109
- }), triggerBy.has("contextMenu") && {
110
- onContextMenu: onContextMenu
111
- }));
125
+ // valid elment, inject handlers
126
+ // else add `div` wrapper
127
+ var children = React.useMemo(function () {
128
+ var props = _objectSpread(_objectSpread(_objectSpread(_objectSpread({
129
+ ref: _ref
130
+ }, isHoverable && hoverProps), isFocusable && focusProps), isClickable && {
131
+ onClick: onClick
132
+ }), isContextMenuable && {
133
+ onContextMenu: onContextMenu
134
+ });
135
+ if (/*#__PURE__*/React.isValidElement(_children)) {
136
+ return /*#__PURE__*/React.cloneElement(_children, props);
137
+ }
138
+ return /*#__PURE__*/React.createElement("div", _objectSpread({}, props), _children);
139
+ }, [_children, focusProps, hoverProps, isClickable, isContextMenuable, isFocusable, isHoverable, onClick, onContextMenu]);
112
140
  var enterPopper = React.useCallback(function () {
113
141
  turnOn();
114
142
  }, [turnOn]);
@@ -117,7 +145,7 @@ var Popover = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
117
145
  }, [disappear]);
118
146
  relax.useClickAway(function () {
119
147
  turnOff();
120
- }, [popperRef, triggerBy.has("click") && _ref]);
148
+ }, [popperRef, isClickable && _ref]);
121
149
  React.useImperativeHandle(ref, function () {
122
150
  return {
123
151
  close: turnOff
@@ -132,7 +160,7 @@ var Popover = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
132
160
  trigger: _ref.current,
133
161
  open: isOpen,
134
162
  arrow: arrow
135
- }, triggerBy.has("hover") && {
163
+ }, isHoverable && {
136
164
  onPointerEnter: enterPopper,
137
165
  onPointerLeave: leavePopper
138
166
  }), {}, {
@@ -1,10 +1,10 @@
1
1
  import React from "react";
2
2
  import type { ChildProps, PopoverRef } from "musae/types/popover";
3
3
  declare const Popover: React.ForwardRefExoticComponent<import("../../types/element").ComponentProps & {
4
- children: React.ReactElement<ChildProps<HTMLElement>, string | React.JSXElementConstructor<any>>;
4
+ children: number | boolean | React.ReactElement<ChildProps<HTMLElement>, string | React.JSXElementConstructor<any>> | null | undefined;
5
5
  title?: React.ReactNode;
6
6
  content: React.ReactNode;
7
- triggerBy?: ("hover" | "focus" | "click" | "contextMenu") | ("hover" | "focus" | "click" | "contextMenu")[];
7
+ triggerBy?: import("musae/types/popover").TriggerBy | import("musae/types/popover").TriggerBy[];
8
8
  placement?: import("@floating-ui/dom").Placement;
9
9
  padding?: boolean | number;
10
10
  arrow?: boolean;
@@ -1,7 +1,7 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
3
- import { toArray, useRefs, useEvent, useHover, chain, useFocus, useClickAway, clsx } from '@aiszlab/relax';
4
- import React, { forwardRef, useRef, useMemo, cloneElement, useCallback, useImperativeHandle } from 'react';
3
+ import { useEvent, useHover, useFocus, useClickAway, clsx } from '@aiszlab/relax';
4
+ import React, { forwardRef, useRef, useCallback, isValidElement, useMemo, cloneElement, useImperativeHandle } from 'react';
5
5
  import Popper from '../popper/popper.mjs';
6
6
  import _stylex from '../../node_modules/.pnpm/@stylexjs_stylex@0.7.5/node_modules/@stylexjs/stylex/lib/es/stylex.mjs';
7
7
  import { spacing } from '../theme/tokens.stylex.mjs';
@@ -9,7 +9,7 @@ import { typography } from '../theme/theme.mjs';
9
9
  import { useClassNames } from '../../hooks/use-class-names.mjs';
10
10
  import { PopoverClassToken } from '../../utils/class-name.mjs';
11
11
  import { ComponentToken } from '../../utils/component-token.mjs';
12
- import { useIsOpen } from './hooks.mjs';
12
+ import { useIsOpen, useTriggerBy } from './hooks.mjs';
13
13
 
14
14
  var styles = {
15
15
  popover: {
@@ -66,11 +66,12 @@ var Popover = /*#__PURE__*/forwardRef(function (_ref2, ref) {
66
66
  turnOff = _useIsOpen2$.turnOff,
67
67
  toggle = _useIsOpen2$.toggle,
68
68
  disappear = _useIsOpen2$.disappear;
69
- var triggerBy = useMemo(function () {
70
- return new Set(toArray(_triggerBy));
71
- }, [_triggerBy]);
72
69
  var classNames = useClassNames(ComponentToken.Popover);
73
- var childRef = useRefs(_ref, _children.props.ref);
70
+ var _useTriggerBy = useTriggerBy(_triggerBy),
71
+ isClickable = _useTriggerBy.isClickable,
72
+ isContextMenuable = _useTriggerBy.isContextMenuable,
73
+ isFocusable = _useTriggerBy.isFocusable,
74
+ isHoverable = _useTriggerBy.isHoverable;
74
75
  var onClick = useEvent(function (event) {
75
76
  event.stopPropagation();
76
77
  toggle();
@@ -79,34 +80,61 @@ var Popover = /*#__PURE__*/forwardRef(function (_ref2, ref) {
79
80
  event.preventDefault();
80
81
  toggle();
81
82
  });
83
+ // hover enter callback
84
+ var onHoverEnter = useCallback(function (event) {
85
+ var _children$props$onMou, _children$props, _children$props$onPoi, _children$props2;
86
+ turnOn();
87
+ if (! /*#__PURE__*/isValidElement(_children)) return;
88
+ (_children$props$onMou = (_children$props = _children.props).onMouseEnter) === null || _children$props$onMou === void 0 || _children$props$onMou.call(_children$props, event);
89
+ (_children$props$onPoi = (_children$props2 = _children.props).onPointerEnter) === null || _children$props$onPoi === void 0 || _children$props$onPoi.call(_children$props2, event);
90
+ }, [_children, turnOn]);
91
+ // hover leave callback
92
+ var onHoverLeave = useCallback(function (event) {
93
+ var _children$props$onMou2, _children$props3, _children$props$onPoi2, _children$props4;
94
+ turnOff();
95
+ if (! /*#__PURE__*/isValidElement(_children)) return;
96
+ (_children$props$onMou2 = (_children$props3 = _children.props).onMouseLeave) === null || _children$props$onMou2 === void 0 || _children$props$onMou2.call(_children$props3, event);
97
+ (_children$props$onPoi2 = (_children$props4 = _children.props).onPointerLeave) === null || _children$props$onPoi2 === void 0 || _children$props$onPoi2.call(_children$props4, event);
98
+ }, [_children, turnOff]);
82
99
  var _useHover = useHover({
83
- onEnter: function onEnter(event) {
84
- return chain(_children.props.onMouseEnter, _children.props.onPointerEnter, turnOn)(event);
85
- },
86
- onLeave: function onLeave(event) {
87
- return chain(_children.props.onMouseLeave, _children.props.onPointerLeave, disappear)(event);
88
- }
100
+ onEnter: onHoverEnter,
101
+ onLeave: onHoverLeave
89
102
  }),
90
103
  _useHover2 = _slicedToArray(_useHover, 2),
91
104
  hoverProps = _useHover2[1];
105
+ var onFocus = useCallback(function (event) {
106
+ var _children$props$onFoc, _children$props5;
107
+ turnOn();
108
+ if (! /*#__PURE__*/isValidElement(_children)) return;
109
+ (_children$props$onFoc = (_children$props5 = _children.props).onFocus) === null || _children$props$onFoc === void 0 || _children$props$onFoc.call(_children$props5, event);
110
+ }, [_children, turnOn]);
111
+ var onBlur = useCallback(function (event) {
112
+ var _children$props$onBlu, _children$props6;
113
+ turnOff();
114
+ if (! /*#__PURE__*/isValidElement(_children)) return;
115
+ (_children$props$onBlu = (_children$props6 = _children.props).onBlur) === null || _children$props$onBlu === void 0 || _children$props$onBlu.call(_children$props6, event);
116
+ }, [_children, turnOff]);
92
117
  var _useFocus = useFocus({
93
- onFocus: function onFocus(event) {
94
- return chain(_children.props.onFocus, turnOn)(event);
95
- },
96
- onBlur: function onBlur(event) {
97
- return chain(_children.props.onBlur, disappear)(event);
98
- }
118
+ onFocus: onFocus,
119
+ onBlur: onBlur
99
120
  }),
100
121
  _useFocus2 = _slicedToArray(_useFocus, 2),
101
122
  focusProps = _useFocus2[1];
102
- // @ts-ignore
103
- var children = /*#__PURE__*/cloneElement(_children, _objectSpread(_objectSpread(_objectSpread(_objectSpread({
104
- ref: childRef
105
- }, triggerBy.has("hover") && hoverProps), triggerBy.has("focus") && focusProps), triggerBy.has("click") && {
106
- onClick: onClick
107
- }), triggerBy.has("contextMenu") && {
108
- onContextMenu: onContextMenu
109
- }));
123
+ // valid elment, inject handlers
124
+ // else add `div` wrapper
125
+ var children = useMemo(function () {
126
+ var props = _objectSpread(_objectSpread(_objectSpread(_objectSpread({
127
+ ref: _ref
128
+ }, isHoverable && hoverProps), isFocusable && focusProps), isClickable && {
129
+ onClick: onClick
130
+ }), isContextMenuable && {
131
+ onContextMenu: onContextMenu
132
+ });
133
+ if (/*#__PURE__*/isValidElement(_children)) {
134
+ return /*#__PURE__*/cloneElement(_children, props);
135
+ }
136
+ return /*#__PURE__*/React.createElement("div", _objectSpread({}, props), _children);
137
+ }, [_children, focusProps, hoverProps, isClickable, isContextMenuable, isFocusable, isHoverable, onClick, onContextMenu]);
110
138
  var enterPopper = useCallback(function () {
111
139
  turnOn();
112
140
  }, [turnOn]);
@@ -115,7 +143,7 @@ var Popover = /*#__PURE__*/forwardRef(function (_ref2, ref) {
115
143
  }, [disappear]);
116
144
  useClickAway(function () {
117
145
  turnOff();
118
- }, [popperRef, triggerBy.has("click") && _ref]);
146
+ }, [popperRef, isClickable && _ref]);
119
147
  useImperativeHandle(ref, function () {
120
148
  return {
121
149
  close: turnOff
@@ -130,7 +158,7 @@ var Popover = /*#__PURE__*/forwardRef(function (_ref2, ref) {
130
158
  trigger: _ref.current,
131
159
  open: isOpen,
132
160
  arrow: arrow
133
- }, triggerBy.has("hover") && {
161
+ }, isHoverable && {
134
162
  onPointerEnter: enterPopper,
135
163
  onPointerLeave: leavePopper
136
164
  }), {}, {
@@ -3,9 +3,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
3
3
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
4
  var componentToken = require('../../utils/component-token.cjs');
5
5
 
6
- var en_US = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
6
+ var _en_US;
7
+ var en_US = (_en_US = {
7
8
  locale: "en_US"
8
- }, componentToken.ComponentToken.Dialog, {
9
+ }, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_en_US, componentToken.ComponentToken.Dialog, {
9
10
  confirm: "Confirm",
10
11
  cancel: "Cancel"
11
12
  }), componentToken.ComponentToken.Empty, {
@@ -33,6 +34,10 @@ var en_US = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_def
33
34
  confirm: "Confirm"
34
35
  }), componentToken.ComponentToken.Upload, {
35
36
  upload: "Upload"
36
- });
37
+ }), _defineProperty(_en_US, componentToken.ComponentToken.Form, {
38
+ required: function required(name) {
39
+ return "".concat(name, " is required");
40
+ }
41
+ }));
37
42
 
38
43
  exports.default = en_US;
@@ -1,9 +1,10 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import { ComponentToken } from '../../utils/component-token.mjs';
3
3
 
4
- var en_US = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
4
+ var _en_US;
5
+ var en_US = (_en_US = {
5
6
  locale: "en_US"
6
- }, ComponentToken.Dialog, {
7
+ }, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_en_US, ComponentToken.Dialog, {
7
8
  confirm: "Confirm",
8
9
  cancel: "Cancel"
9
10
  }), ComponentToken.Empty, {
@@ -31,6 +32,10 @@ var en_US = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_def
31
32
  confirm: "Confirm"
32
33
  }), ComponentToken.Upload, {
33
34
  upload: "Upload"
34
- });
35
+ }), _defineProperty(_en_US, ComponentToken.Form, {
36
+ required: function required(name) {
37
+ return "".concat(name, " is required");
38
+ }
39
+ }));
35
40
 
36
41
  export { en_US as default };
@@ -3,9 +3,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
3
3
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
4
  var componentToken = require('../../utils/component-token.cjs');
5
5
 
6
- var zh_CN = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
6
+ var _zh_CN;
7
+ var zh_CN = (_zh_CN = {
7
8
  locale: "zh_CN"
8
- }, componentToken.ComponentToken.Dialog, {
9
+ }, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_zh_CN, componentToken.ComponentToken.Dialog, {
9
10
  confirm: "确认",
10
11
  cancel: "取消"
11
12
  }), componentToken.ComponentToken.Empty, {
@@ -33,6 +34,10 @@ var zh_CN = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_def
33
34
  confirm: "确认"
34
35
  }), componentToken.ComponentToken.Upload, {
35
36
  upload: "上传"
36
- });
37
+ }), _defineProperty(_zh_CN, componentToken.ComponentToken.Form, {
38
+ required: function required(name) {
39
+ return "".concat(name, " \u662F\u5FC5\u586B\u9879");
40
+ }
41
+ }));
37
42
 
38
43
  exports.default = zh_CN;
@@ -1,9 +1,10 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import { ComponentToken } from '../../utils/component-token.mjs';
3
3
 
4
- var zh_CN = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
4
+ var _zh_CN;
5
+ var zh_CN = (_zh_CN = {
5
6
  locale: "zh_CN"
6
- }, ComponentToken.Dialog, {
7
+ }, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_zh_CN, ComponentToken.Dialog, {
7
8
  confirm: "确认",
8
9
  cancel: "取消"
9
10
  }), ComponentToken.Empty, {
@@ -31,6 +32,10 @@ var zh_CN = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_def
31
32
  confirm: "确认"
32
33
  }), ComponentToken.Upload, {
33
34
  upload: "上传"
34
- });
35
+ }), _defineProperty(_zh_CN, ComponentToken.Form, {
36
+ required: function required(name) {
37
+ return "".concat(name, " \u662F\u5FC5\u586B\u9879");
38
+ }
39
+ }));
35
40
 
36
41
  export { zh_CN as default };
@@ -4,7 +4,7 @@ import { ButtonProps } from "./button";
4
4
  * @description
5
5
  * countdown props
6
6
  */
7
- export type CountdownProps = Pick<ButtonProps, "children" | "disabled" | "variant" | "color" | "size" | "shape" | "ripple"> & ComponentProps & {
7
+ export type CountdownProps = Pick<ButtonProps, "children" | "disabled" | "variant" | "color" | "size" | "shape" | "ripple" | "onClick"> & ComponentProps & {
8
8
  /**
9
9
  * @description
10
10
  * count total after every trigger
@@ -35,4 +35,7 @@ export interface Locale {
35
35
  [ComponentToken.Upload]: {
36
36
  upload: string;
37
37
  };
38
+ [ComponentToken.Form]: {
39
+ required: ((name: string) => string) | string;
40
+ };
38
41
  }
@@ -1,8 +1,9 @@
1
+ import { ComponentProps } from "./element";
1
2
  /**
2
3
  * @description
3
4
  * otp input props
4
5
  */
5
- export type OtpInputProps = {
6
+ export type OtpInputProps = ComponentProps & {
6
7
  /**
7
8
  * @description
8
9
  * length
@@ -2,7 +2,7 @@ import type { DOMAttributes, ReactElement, ReactNode, RefAttributes } from "reac
2
2
  import type { ComponentProps } from "musae/types/element";
3
3
  import type { Placement } from "@floating-ui/dom";
4
4
  export type ChildProps<T> = Pick<DOMAttributes<T>, "onMouseEnter" | "onMouseLeave" | "onPointerEnter" | "onPointerLeave" | "onClick" | "onContextMenu" | "onFocus" | "onBlur"> & RefAttributes<T>;
5
- type TriggerBy = "hover" | "focus" | "click" | "contextMenu";
5
+ export type TriggerBy = "hover" | "focus" | "click" | "contextMenu";
6
6
  /**
7
7
  * @description
8
8
  * popover props
@@ -13,7 +13,7 @@ export type PopoverProps<P extends ChildProps<T>, T extends HTMLElement> = Compo
13
13
  * a trigger element.
14
14
  * @requires
15
15
  */
16
- children: ReactElement<P>;
16
+ children: ReactElement<P> | Exclude<ReactNode, ReactElement | Iterable<ReactNode>>;
17
17
  /**
18
18
  * @description
19
19
  * title
@@ -65,4 +65,3 @@ export type PopoverRef = {
65
65
  */
66
66
  close: () => Promise<void>;
67
67
  };
68
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musae",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "musae-ui",
5
5
  "author": "tutu@fantufantu.com",
6
6
  "license": "MIT",