@ioca/react 1.5.29 → 1.5.31

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 (35) hide show
  1. package/lib/css/index.css +1 -1
  2. package/lib/es/components/checkbox/checkbox.js +1 -1
  3. package/lib/es/components/divider/divider.js +12 -0
  4. package/lib/es/components/divider/index.js +5 -0
  5. package/lib/es/components/dropdown/dropdown.js +8 -12
  6. package/lib/es/components/dropdown/item.js +15 -9
  7. package/lib/es/components/form/useForm.js +3 -4
  8. package/lib/es/components/input/input.js +2 -2
  9. package/lib/es/components/input/number.js +3 -5
  10. package/lib/es/components/input/range.js +2 -2
  11. package/lib/es/components/input/textarea.js +1 -1
  12. package/lib/es/components/list/item.js +5 -1
  13. package/lib/es/components/list/list.js +11 -4
  14. package/lib/es/components/modal/hookModal.js +11 -1
  15. package/lib/es/components/modal/modal.js +24 -16
  16. package/lib/es/components/pill/pill.js +2 -2
  17. package/lib/es/components/select/options.js +5 -7
  18. package/lib/es/components/select/select.js +4 -8
  19. package/lib/es/index.js +2 -2
  20. package/lib/index.js +319 -297
  21. package/lib/types/components/divider/divider.d.ts +6 -0
  22. package/lib/types/components/divider/index.d.ts +5 -0
  23. package/lib/types/components/divider/type.d.ts +9 -0
  24. package/lib/types/components/dropdown/type.d.ts +3 -1
  25. package/lib/types/components/form/useForm.d.ts +1 -1
  26. package/lib/types/components/list/type.d.ts +1 -0
  27. package/lib/types/components/modal/type.d.ts +1 -1
  28. package/lib/types/components/pill/type.d.ts +1 -0
  29. package/lib/types/index.d.ts +2 -2
  30. package/package.json +1 -1
  31. package/lib/es/components/card/card.js +0 -12
  32. package/lib/es/components/card/index.js +0 -5
  33. package/lib/types/components/card/card.d.ts +0 -6
  34. package/lib/types/components/card/index.d.ts +0 -5
  35. package/lib/types/components/card/type.d.ts +0 -13
@@ -4,11 +4,18 @@ import { forwardRef, Children, cloneElement } from 'react';
4
4
  import Item from './item.js';
5
5
 
6
6
  const List = forwardRef((props, ref) => {
7
- const { label, type, border, className, children, ...restProps } = props;
8
- return (jsx("ul", { ref: ref, className: classNames("i-list", className), ...restProps, children: Children.map(children, (node, i) => {
7
+ const { label, type, border, padding, className, style, children, ...restProps } = props;
8
+ return (jsx("ul", { ref: ref, className: classNames("i-list", className, {
9
+ "i-list-option-type": type === "option",
10
+ }), style: {
11
+ ...(padding !== undefined
12
+ ? { "--option-gap": typeof padding === "number" ? `${padding}px` : padding }
13
+ : undefined),
14
+ ...style,
15
+ }, ...restProps, children: Children.map(children, (node, i) => {
9
16
  const renderLabel = typeof label === "function" ? label(i) : label;
10
- const { type, props: nodeProps } = node;
11
- if (type === Item) {
17
+ const { type: elementType, props: nodeProps } = node;
18
+ if (elementType === Item) {
12
19
  return cloneElement(node, {
13
20
  label: renderLabel,
14
21
  ...nodeProps,
@@ -13,7 +13,17 @@ const HookModal = (props) => {
13
13
  },
14
14
  close: () => {
15
15
  state.visible = false;
16
- if (mergedProps.closable ?? true)
16
+ const canClose = typeof mergedProps.closable === 'function'
17
+ ? mergedProps.closable()
18
+ : (mergedProps.closable ?? true);
19
+ if (canClose instanceof Promise) {
20
+ canClose.then((result) => {
21
+ if (!result)
22
+ state.visible = true;
23
+ });
24
+ return;
25
+ }
26
+ if (canClose)
17
27
  return;
18
28
  Promise.resolve().then(() => {
19
29
  state.visible = true;
@@ -46,25 +46,33 @@ function Modal(props) {
46
46
  if (!toggable.current)
47
47
  return;
48
48
  toggable.current = false;
49
- if (!closable) {
50
- setBounced(true);
49
+ const canClose = typeof closable === 'function' ? closable() : closable;
50
+ const exec = (result) => {
51
+ if (!result) {
52
+ setBounced(true);
53
+ const timer = setTimeout(() => {
54
+ setBounced(false);
55
+ toggable.current = true;
56
+ }, 400);
57
+ return () => clearTimeout(timer);
58
+ }
59
+ setActive(false);
60
+ updateVisible(mid, false);
51
61
  const timer = setTimeout(() => {
52
- setBounced(false);
62
+ if (!keepDOM)
63
+ setShow(false);
53
64
  toggable.current = true;
54
- }, 400);
65
+ onVisibleChange?.(false);
66
+ onClose?.();
67
+ }, 240);
55
68
  return () => clearTimeout(timer);
69
+ };
70
+ if (canClose instanceof Promise) {
71
+ canClose.then(exec);
72
+ return;
56
73
  }
57
- setActive(false);
58
- updateVisible(mid, false);
59
- const timer = setTimeout(() => {
60
- if (!keepDOM)
61
- setShow(false);
62
- toggable.current = true;
63
- onVisibleChange?.(false);
64
- onClose?.();
65
- }, 240);
66
- return () => clearTimeout(timer);
67
- }, [closable, keepDOM, onClose, onVisibleChange]);
74
+ return exec(canClose);
75
+ }, [closable, keepDOM, mid, onClose, onVisibleChange]);
68
76
  const handleBackdropClick = () => {
69
77
  backdropClosable && handleHide();
70
78
  };
@@ -124,7 +132,7 @@ function Modal(props) {
124
132
  e.stopPropagation();
125
133
  handleClick();
126
134
  onClick?.(e);
127
- }, role: "dialog", "aria-modal": top, "data-mid": mid, ...restProps, children: jsxs(ModalContext.Provider, { value: true, children: [customized && children, !customized && (jsx(Content, { title: title, hideCloseButton: hideCloseButton, footer: footer, okButtonProps: okButtonProps, cancelButtonProps: cancelButtonProps, children: children, footerLeft: footerLeft, onOk: onOk, onClose: handleHide }))] }) }) }), getContainer());
135
+ }, role: "dialog", "aria-modal": top, "data-mid": mid, ...restProps, children: jsxs(ModalContext.Provider, { value: true, children: [customized && children, !customized && jsx(Content, { title: title, hideCloseButton: hideCloseButton, footer: footer, okButtonProps: okButtonProps, cancelButtonProps: cancelButtonProps, children: children, footerLeft: footerLeft, onOk: onOk, onClose: handleHide })] }) }) }), getContainer());
128
136
  }
129
137
  Modal.useModal = useModal;
130
138
 
@@ -6,7 +6,7 @@ import CreateTag from './create.js';
6
6
  import TagItem from './item.js';
7
7
 
8
8
  function Pill(props) {
9
- const { value = [], tagProps, max, icon = jsx(AddRound, {}), className, label, labelInline, readonly, editable, onChange, onUpdate, validator, format, renderItem, ...restProps } = props;
9
+ const { value = [], tagProps, max, icon = jsx(AddRound, {}), className, label, labelInline, readonly, editable, onChange, onUpdate, validator, format, renderItem, hideCreate, ...restProps } = props;
10
10
  const [editingIndex, setEditingIndex] = useState(null);
11
11
  const [loadingSet, setLoadingSet] = useState(new Set());
12
12
  const instRef = useRef({
@@ -185,7 +185,7 @@ function Pill(props) {
185
185
  return;
186
186
  inst.setEditingIndex(-1);
187
187
  }, []);
188
- const canCreate = !readonly && (max === undefined || value.length < max);
188
+ const canCreate = !hideCreate && !readonly && (max === undefined || value.length < max);
189
189
  return (jsxs("div", { className: classNames("i-pills i-input-label", { "i-input-inline": labelInline }, className), ...restProps, children: [label && jsx("span", { className: "i-input-label-text", children: label }), jsxs("div", { className: "i-pill-list", children: [value.map((item, i) => (jsx(TagItem, { item: item, index: i, isEditing: editingIndex === i, isLoading: loadingSet.has(i), tagProps: tagProps, editable: editable, readonly: readonly, renderItem: renderItem, onClose: handleClose, onClick: handleItemClick, onBlur: handleBlur, onKeyDown: handleKeyDown }, i))), canCreate && jsx(CreateTag, { isEditing: editingIndex === -1, isLoading: loadingSet.has(-1), createTagProps: cleanTagProps, tagProps: tagProps, onBlur: handleBlur, onKeyDown: handleKeyDown, onStartCreate: handleStartCreate })] })] }));
190
190
  }
191
191
 
@@ -7,19 +7,17 @@ import Tag from '../tag/tag.js';
7
7
  import Empty from '../utils/empty/index.js';
8
8
 
9
9
  const Options = (props) => {
10
- const { value: val, options, filter, filterPlaceholder, multiple, empty = jsx(Empty, {}), onSelect, onFilter, } = props;
10
+ const { value: val, options, filter, filterPlaceholder, multiple, empty = jsx(Empty, {}), onSelect, onFilter } = props;
11
11
  return (jsxs("div", { className: classNames("i-select-options", {
12
12
  "i-select-options-multiple": multiple,
13
- }), children: [filter && multiple && (jsxs("div", { className: 'i-select-filter', children: [jsx(Icon, { icon: jsx(SearchRound, {}), className: 'color-8 ml-8 my-auto', size: '1.2em' }), jsx("input", { type: 'text', className: 'i-input', placeholder: filterPlaceholder, onChange: onFilter })] })), options.length === 0 && empty, options.map((option, i) => {
13
+ }), children: [filter && multiple && (jsxs("div", { className: "i-select-filter", children: [jsx(Icon, { icon: jsx(SearchRound, {}), className: "color-8 ml-8 my-auto", size: "1.2em" }), jsx("input", { type: "text", className: "i-input", placeholder: filterPlaceholder, onChange: onFilter })] })), options.length === 0 && empty, options.map((option, i) => {
14
14
  const { label, value, disabled } = option;
15
- const isActive = multiple
16
- ? val?.includes(value)
17
- : val === value;
18
- return (jsxs(List.Item, { active: isActive, type: 'option', onClick: () => onSelect?.(value, option), disabled: disabled, children: [multiple && (jsx(Icon, { icon: jsx(CheckRound, {}), className: 'i-select-option-check', size: '1em' })), label] }, value || i));
15
+ const isActive = multiple ? val?.includes(value) : val === value;
16
+ return (jsxs(List.Item, { active: isActive, type: "option", onClick: () => onSelect?.(value, option), disabled: disabled, children: [multiple && jsx(Icon, { icon: jsx(CheckRound, {}), className: "i-select-option-check", size: "1em" }), label] }, value || i));
19
17
  })] }));
20
18
  };
21
19
  const activeOptions = (options = [], value = [], max = 3) => {
22
- const total = options.flatMap((opt) => value.includes(opt.value) ? [opt] : []);
20
+ const total = options.flatMap((opt) => (value.includes(opt.value) ? [opt] : []));
23
21
  if (max >= total.length)
24
22
  return total;
25
23
  const rest = total.length - max;
@@ -9,7 +9,7 @@ import Helpericon from '../utils/helpericon/helpericon.js';
9
9
  import { displayValue, Options } from './options.js';
10
10
 
11
11
  const Select = (props) => {
12
- const { ref, type = "text", name, label, value = "", placeholder, required, options = [], multiple, prepend, append, labelInline, style, className, message, status = "normal", hideClear, hideArrow, maxDisplay, border, filter, tip, filterPlaceholder = "...", popupProps, onSelect, onChange, ...restProps } = props;
12
+ const { ref, type = "text", name, label, value = "", placeholder, required, options = [], multiple, prepend, append, labelInline, style, className, message, status = "normal", hideClear, hideArrow, maxDisplay, border = true, filter, tip, filterPlaceholder = "...", popupProps, onSelect, onChange, ...restProps } = props;
13
13
  const [filterValue, setFilterValue] = useState("");
14
14
  const [selectedValue, setSelectedValue] = useState(value);
15
15
  const [active, setActive] = useState(false);
@@ -24,9 +24,7 @@ const Select = (props) => {
24
24
  if (!fv || !filter)
25
25
  return formattedOptions;
26
26
  const lowerFv = fv.toLowerCase();
27
- const filterFn = typeof filter === "function"
28
- ? filter
29
- : (opt) => opt._value.includes(lowerFv) || opt._label.includes(lowerFv);
27
+ const filterFn = typeof filter === "function" ? filter : (opt) => opt._value.includes(lowerFv) || opt._label.includes(lowerFv);
30
28
  return formattedOptions.filter(filterFn);
31
29
  }, [formattedOptions, filter, filterValue]);
32
30
  const changeValue = (v) => {
@@ -75,9 +73,7 @@ const Select = (props) => {
75
73
  useEffect(() => {
76
74
  setSelectedValue(value);
77
75
  }, [value]);
78
- const hasValue = multiple
79
- ? selectedValue.length > 0
80
- : !!selectedValue;
76
+ const hasValue = multiple ? selectedValue.length > 0 : !!selectedValue;
81
77
  const clearable = !hideClear && active && hasValue;
82
78
  const text = message ?? tip;
83
79
  return (jsxs("label", { className: classNames("i-input-label", className, {
@@ -94,7 +90,7 @@ const Select = (props) => {
94
90
  multiple,
95
91
  maxDisplay,
96
92
  onSelect: handleSelect,
97
- }) })) : (jsx("input", { className: "i-input i-select", placeholder: placeholder, readOnly: true }))) : null, !multiple && (jsx("input", { value: active ? filterValue : displayLabel, className: "i-input i-select", placeholder: displayLabel || placeholder, onChange: handleInputChange, readOnly: !filter })), jsx(Helpericon, { active: !hideArrow, icon: clearable ? undefined : jsx(UnfoldMoreRound, {}), onClick: handleHelperClick }), append] }) }), text && jsx("span", { className: "i-input-message", children: text })] }));
93
+ }) })) : (jsx("input", { className: "i-input i-select", placeholder: placeholder, readOnly: true }))) : null, !multiple && jsx("input", { value: active ? filterValue : displayLabel, className: "i-input i-select", placeholder: displayLabel || placeholder, onChange: handleInputChange, readOnly: !filter }), jsx(Helpericon, { active: !hideArrow, icon: clearable ? undefined : jsx(UnfoldMoreRound, {}), onClick: handleHelperClick }), append] }) }), text && jsx("span", { className: "i-input-message", children: text })] }));
98
94
  };
99
95
 
100
96
  export { Select as default };
package/lib/es/index.js CHANGED
@@ -1,10 +1,8 @@
1
1
  export { default as Affix } from './components/affix/affix.js';
2
2
  export { default as Badge } from './components/badge/badge.js';
3
3
  export { default as Button } from './components/button/button.js';
4
- export { default as Card } from './components/card/card.js';
5
4
  export { default as Checkbox } from './components/checkbox/checkbox.js';
6
5
  export { default as Collapse } from './components/collapse/collapse.js';
7
- export { default as Pill } from './components/pill/pill.js';
8
6
  export { default as Datagrid } from './components/datagrid/datagrid.js';
9
7
  export { default as Description } from './components/description/description.js';
10
8
  export { default as Drawer } from './components/drawer/drawer.js';
@@ -15,6 +13,7 @@ export { default as Form } from './components/form/form.js';
15
13
  export { default as Icon } from './components/icon/icon.js';
16
14
  export { default as Image } from './components/image/image.js';
17
15
  export { default as Input } from './components/input/input.js';
16
+ export { default as Divider } from './components/divider/divider.js';
18
17
  export { default as List } from './components/list/list.js';
19
18
  export { default as Loading } from './components/loading/loading.js';
20
19
  export { default as Message } from './components/message/index.js';
@@ -24,6 +23,7 @@ export { default as ColorPicker } from './components/picker/colors/index.js';
24
23
  export { default as DatePicker } from './components/picker/dates/index.js';
25
24
  export { default as TimePicker } from './components/picker/time/index.js';
26
25
  export { default as DateRange } from './components/picker/daterange/daterange.js';
26
+ export { default as Pill } from './components/pill/pill.js';
27
27
  export { default as Popconfirm } from './components/popconfirm/popconfirm.js';
28
28
  export { default as Popup } from './components/popup/popup.js';
29
29
  export { default as Progress } from './components/progress/progress.js';