onekijs-ui 0.18.0 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/components/table/typings.d.ts +1 -0
  2. package/dist/components/tooltip/typings.d.ts +2 -0
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +72 -39
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.module.js +72 -40
  7. package/dist/index.module.js.map +1 -1
  8. package/dist/styles/border.d.ts +1 -1
  9. package/dist/styles/size.d.ts +6 -6
  10. package/dist/styles/typography.d.ts +2 -2
  11. package/package.json +3 -3
  12. package/src/components/dashboard/components/DashboardBody.tsx +2 -1
  13. package/src/components/dropdown/components/DropdownComponent.tsx +1 -1
  14. package/src/components/icon/HelpIcon.tsx +2 -1
  15. package/src/components/input/components/InputComponent.tsx +18 -2
  16. package/src/components/list/components/ListBodyComponent.tsx +10 -11
  17. package/src/components/list/hooks/useListView.tsx +6 -1
  18. package/src/components/select/FormSelect.tsx +1 -0
  19. package/src/components/select/components/ControlledSelectComponent.tsx +12 -4
  20. package/src/components/select/components/SelectInputComponent.tsx +1 -0
  21. package/src/components/select/components/SelectOptionComponent.tsx +1 -1
  22. package/src/components/select/style.ts +1 -0
  23. package/src/components/table/columns/selectColumn.ts +3 -5
  24. package/src/components/table/components/FormTableComponent.tsx +2 -1
  25. package/src/components/table/components/TableBodyComponent.tsx +2 -1
  26. package/src/components/table/typings.ts +1 -0
  27. package/src/components/tooltip/components/TooltipComponent.tsx +25 -11
  28. package/src/components/tooltip/style.ts +1 -1
  29. package/src/components/tooltip/typings.ts +2 -0
  30. package/src/index.ts +1 -0
@@ -29,6 +29,7 @@ export type FormTableProps<T = any, I extends TableItem<T> = TableItem<T>, S ext
29
29
  onChange?: (value: T[]) => void;
30
30
  status?: ValidationStatus;
31
31
  size?: TshirtSize;
32
+ showAddButton?: boolean;
32
33
  };
33
34
  export type FormTableContext<T = any> = {
34
35
  tableName: string;
@@ -7,4 +7,6 @@ export interface TooltipProps extends Config {
7
7
  popperOptions?: PopperOptions;
8
8
  kind?: ColorPropertyTheme;
9
9
  delayHide?: number;
10
+ delayShow?: number;
11
+ attachToBody?: boolean;
10
12
  }
package/dist/index.d.ts CHANGED
@@ -52,6 +52,7 @@ export { default as Row } from './components/grid/Row';
52
52
  export { colStyle, rowStyle } from './components/grid/style';
53
53
  export { ColProps, GridSize, RowProps } from './components/grid/typings';
54
54
  export { default as CloseAllIcon } from './components/icon/CloseAllIcon';
55
+ export { default as HelpIcon } from './components/icon/HelpIcon';
55
56
  export { default as CrossIcon } from './components/icon/CrossIcon';
56
57
  export { default as ErrorIcon } from './components/icon/ErrorIcon';
57
58
  export { default as FileIcon } from './components/icon/FileIcon';
package/dist/index.js CHANGED
@@ -1187,9 +1187,7 @@ const DropdownComponent = ({ animationTimeout = 0, attachToBody = false, classNa
1187
1187
  React.createElement(reactTransitionGroup.CSSTransition, { in: open, classNames: "o-dropdown", timeout: animationTimeout, mountOnEnter: true, appear: false, unmountOnExit: true, onEnter: onEnter, onEntering: onEntering, onEntered: onEntered, onExit: onExit, onExited: onExited, onExiting: onExiting },
1188
1188
  React.createElement("div", { className: "o-dropdown" }, children))));
1189
1189
  if (attachToBody) {
1190
- return React.createElement(React.Fragment, null,
1191
- " ",
1192
- ReactDOM.createPortal(element, document.body));
1190
+ return React.createElement(React.Fragment, null, ReactDOM.createPortal(element, document.body));
1193
1191
  }
1194
1192
  else {
1195
1193
  return React.createElement(React.Fragment, null, element);
@@ -1246,11 +1244,12 @@ const DropdownButton = styled(DropdownButtonComponent) `
1246
1244
  `;
1247
1245
 
1248
1246
  const TooltipComponent = (props) => {
1249
- const { content, className, popperOptions, children, delayHide = 300, ...tooltipConfig } = props;
1247
+ const { content, className, popperOptions, children, delayHide = 300, delayShow = 200, attachToBody, ...tooltipConfig } = props;
1250
1248
  const [show, setShow] = React.useState(true);
1251
1249
  const tooltipOptions = Object.assign({
1252
1250
  interactive: true,
1253
1251
  delayHide,
1252
+ delayShow,
1254
1253
  }, tooltipConfig);
1255
1254
  const { getArrowProps, getTooltipProps, setTooltipRef, setTriggerRef, visible } = reactPopperTooltip.usePopperTooltip(tooltipOptions, popperOptions);
1256
1255
  const { style: containerStyle, ...containerProps } = getTooltipProps({ className: 'o-tooltip-container' });
@@ -1274,11 +1273,19 @@ const TooltipComponent = (props) => {
1274
1273
  document.removeEventListener('tooltipVisible', listener);
1275
1274
  };
1276
1275
  }, [uid]);
1277
- return (React.createElement("div", { className: classNames, ref: setTriggerRef },
1278
- children,
1279
- show && visible && content && (React.createElement("div", { ref: setTooltipRef, style: containerStyle, ...containerProps },
1280
- React.createElement("div", { style: arrowStyle, ...arrowProps }),
1281
- content))));
1276
+ const element = (React.createElement("div", { ref: setTooltipRef, style: containerStyle, ...containerProps },
1277
+ React.createElement("div", { style: arrowStyle, ...arrowProps }),
1278
+ content));
1279
+ if (attachToBody) {
1280
+ return (React.createElement("div", { ref: setTriggerRef },
1281
+ children,
1282
+ show && visible && content && ReactDOM.createPortal(React.createElement("div", { className: classNames, style: { position: 'absolute', width: '100%' } }, element), document.body)));
1283
+ }
1284
+ else {
1285
+ return (React.createElement("div", { className: classNames, ref: setTriggerRef },
1286
+ children,
1287
+ show && visible && content && element));
1288
+ }
1282
1289
  };
1283
1290
 
1284
1291
  const sizeFormatter = (type, value, theme) => {
@@ -1426,7 +1433,7 @@ const tooltipStyle = ({ kind = 'secondary', theme }) => {
1426
1433
  }
1427
1434
  }
1428
1435
  }
1429
- .o-tooltip-arrow {
1436
+ &.o-tooltip-arrow, .o-tooltip-arrow {
1430
1437
  ${height('1rem')}
1431
1438
  ${width('1rem')}
1432
1439
  ${position('absolute')}
@@ -1833,7 +1840,7 @@ const Row = styled(RowComponent) `
1833
1840
  `;
1834
1841
 
1835
1842
  const IconComponent$6 = ({ className, onClick, style }) => {
1836
- return (React.createElement("div", { className: className, onClick: onClick, style: style },
1843
+ return (React.createElement("div", { className: addClassname('o-icon-help', className), onClick: onClick, style: style },
1837
1844
  React.createElement("svg", { className: "o-icon-help-svg", viewBox: "0 0 512 512" },
1838
1845
  React.createElement("path", { d: "M256 90c44.3 0 86 17.3 117.4 48.6C404.7 170 422 211.7 422 256s-17.3 86-48.6 117.4C342 404.7 300.3 422 256 422s-86-17.3-117.4-48.6C107.3 342 90 300.3 90 256s17.3-86 48.6-117.4C170 107.3 211.7 90 256 90m0-42C141.1 48 48 141.1 48 256s93.1 208 208 208 208-93.1 208-208S370.9 48 256 48z" }),
1839
1846
  React.createElement("path", { d: "M235 339h42v42h-42zM276.8 318h-41.6c0-67 62.4-62.2 62.4-103.8 0-22.9-18.7-41.7-41.6-41.7S214.4 192 214.4 214h-41.6c0-46 37.2-83 83.2-83s83.2 37.1 83.2 83.1c0 52-62.4 57.9-62.4 103.9z" }))));
@@ -2834,7 +2841,8 @@ const style$3 = (props) => {
2834
2841
  grid-area: body;
2835
2842
  width: ${() => getBodyLength('width', 'small', props)};
2836
2843
  height: ${() => getBodyLength('height', 'small', props)};
2837
- overflow: auto;
2844
+ overflow-x: auto;
2845
+ overflow-y: scroll;
2838
2846
  transition: ${() => (props.panel ? 'transform 0.3s, width 0.3s, height 0.3s' : 'none')};
2839
2847
  transform: translate(${() => getTranslateX$2('small', props)}, ${() => getTranslateY$2('small', props)});
2840
2848
  @media only screen and (min-width: 768px) {
@@ -3706,7 +3714,7 @@ var SuccessIcon = styled(SuccessIconComponent) `
3706
3714
  `;
3707
3715
 
3708
3716
  const InputComponent = (props) => {
3709
- const { className, size = 'medium', status, PrefixComponent, SuffixComponent, onFocus: forwardFocus, onBlur: forwardBlur, ...inputProps } = props;
3717
+ const { className, size = 'medium', status, PrefixComponent, SuffixComponent, onFocus: forwardFocus, onBlur: forwardBlur, onChange: forwardChange, value, ...inputProps } = props;
3710
3718
  const [focus, setFocus] = React.useState(false);
3711
3719
  const classNames = addClassname(`o-input o-input-size-${size}${focus ? ' o-input-focus' : ''}${status ? ' o-input-status-' + status.toLowerCase() : ''}`, className);
3712
3720
  const onFocus = (e) => {
@@ -3717,9 +3725,21 @@ const InputComponent = (props) => {
3717
3725
  setFocus(false);
3718
3726
  forwardBlur && forwardBlur(e);
3719
3727
  };
3728
+ const ref = React.useRef(null);
3729
+ const selectorRef = React.useRef();
3730
+ const onChange = (e) => {
3731
+ selectorRef.current = e.target.selectionStart;
3732
+ forwardChange && forwardChange(e);
3733
+ };
3734
+ React.useEffect(() => {
3735
+ if (selectorRef.current !== undefined && selectorRef.current !== null && ref.current) {
3736
+ ref.current.setSelectionRange(selectorRef.current, selectorRef.current);
3737
+ selectorRef.current = undefined;
3738
+ }
3739
+ }, [value]);
3720
3740
  return (React.createElement("div", { className: classNames },
3721
3741
  PrefixComponent && React.createElement(PrefixComponent, { ...props, className: "o-input-prefix" }),
3722
- React.createElement("input", { className: "o-input-field", ...inputProps, onFocus: onFocus, onBlur: onBlur }),
3742
+ React.createElement("input", { className: "o-input-field", ...inputProps, ref: ref, onFocus: onFocus, onBlur: onBlur, onChange: value === undefined ? undefined : onChange, value: value }),
3723
3743
  SuffixComponent && React.createElement(SuffixComponent, { ...props, className: "o-input-suffix" })));
3724
3744
  };
3725
3745
  InputComponent.displayName = 'InputComponent';
@@ -4460,7 +4480,7 @@ const useListView = ({ controller, height, itemHeight = defaultItemHeight, overs
4460
4480
  let to;
4461
4481
  const first = Math.max(0, lastVirtualItemIndex - increment);
4462
4482
  if (lastVirtualItemIndex > 0) {
4463
- let slice = state.items.slice(Math.max(0, lastVirtualItemIndex - increment), lastVirtualItemIndex);
4483
+ let slice = state.items.slice(first, lastVirtualItemIndex);
4464
4484
  if (slice.length < lastVirtualItemIndex - first) {
4465
4485
  const arr = new Array(lastVirtualItemIndex - first);
4466
4486
  arr.splice(arr.length - slice.length, slice.length, ...slice);
@@ -4506,6 +4526,10 @@ const useListView = ({ controller, height, itemHeight = defaultItemHeight, overs
4506
4526
  to = offset + increment;
4507
4527
  }
4508
4528
  if (from !== undefined && to !== undefined && to > from) {
4529
+ from = Math.max(0, from);
4530
+ if (state.total !== undefined) {
4531
+ to = Math.min(state.total, to);
4532
+ }
4509
4533
  controller.load(to - from, from, true);
4510
4534
  }
4511
4535
  }
@@ -4746,6 +4770,7 @@ const ListBodyComponent = ({ autoRefresh, bodyRef, className, follow, height, it
4746
4770
  nextItem = onekijsFramework.get(state.items, activeIndex.toString());
4747
4771
  onItemClick(nextItem, activeIndex);
4748
4772
  }
4773
+ e.preventDefault();
4749
4774
  break;
4750
4775
  case 'Escape':
4751
4776
  if (onItemDeactivate && activeItem !== undefined) {
@@ -4771,26 +4796,26 @@ const ListBodyComponent = ({ autoRefresh, bodyRef, className, follow, height, it
4771
4796
  });
4772
4797
  React.useEffect(() => {
4773
4798
  const atBottom = () => {
4774
- if (bodyRef && bodyRef.current) {
4775
- const sh = bodyRef.current.scrollHeight;
4776
- const st = bodyRef.current.scrollTop;
4777
- const oh = bodyRef.current.offsetHeight;
4799
+ const ref = parentRef ? parentRef : bodyRef;
4800
+ if (ref && ref.current) {
4801
+ const sh = ref.current.scrollHeight;
4802
+ const st = ref.current.scrollTop;
4803
+ const oh = ref.current.offsetHeight;
4778
4804
  if (oh === 0 || st === sh - oh)
4779
4805
  return true;
4780
4806
  }
4781
4807
  return false;
4782
4808
  };
4783
4809
  if (tail && scrollToIndex && totalSize && bodyRef && bodyRef.current) {
4784
- const lastScrollTop = tailRef.current.lastScrollTop;
4785
4810
  tailRef.current.lastScrollTop = bodyRef.current.scrollTop;
4786
- if (tailRef.current.applyTail === true &&
4787
- lastScrollTop > bodyRef.current.scrollTop &&
4788
- (mouseRef.current || wheelRef.current)) {
4811
+ if (mouseRef.current || wheelRef.current) {
4789
4812
  tailRef.current.applyTail = false;
4790
4813
  }
4791
4814
  else if (tailRef.current.applyTail === true || atBottom()) {
4792
4815
  tailRef.current.applyTail = true;
4793
- scrollToIndex(state.total ? state.total - 1 : state.items ? state.items.length - 1 : 0);
4816
+ scrollToIndex(state.total ? state.total - 1 : state.items ? state.items.length - 1 : 0, {
4817
+ align: 'start',
4818
+ });
4794
4819
  }
4795
4820
  wheelRef.current = false;
4796
4821
  }
@@ -6262,7 +6287,7 @@ const SelectOptionComponent = (props) => {
6262
6287
  return (React.createElement(React.Fragment, null,
6263
6288
  displayGroup && React.createElement(OptionGroupComponent, { ...props }),
6264
6289
  React.createElement("div", { className: classNames, onClick: () => onItemClick(item, index), onMouseEnter: () => hoverable && onMouseEnter && item && onMouseEnter(item, index), onMouseLeave: () => hoverable && onMouseLeave && item && onMouseLeave(item, index) },
6265
- React.createElement("div", { ref: ref },
6290
+ React.createElement("div", { style: { display: 'flex' }, ref: ref },
6266
6291
  service.config?.multiple && (React.createElement(Checkbox, { value: item?.selected ? true : false, onChange: () => onItemClick(item, index), color: "currentColor", className: "o-select-option-multiple-checkbox" })),
6267
6292
  React.createElement(OptionContentComponent, { ...props, onClick: () => onItemClick(item, index) })))));
6268
6293
  };
@@ -6380,8 +6405,13 @@ const ControlledSelectComponent = ({ attachDropdownToBody = false, className = '
6380
6405
  const showActiveRef = React.useRef(false);
6381
6406
  const proxyItem = React.useMemo(() => {
6382
6407
  const search = controller.getSearch();
6383
- if (showActiveRef.current && controller.state.active && controller.state.active.length > 0) {
6384
- return controller.getItem(controller.state.active[0]);
6408
+ const active = controller.state.active;
6409
+ const selected = controller.state.selected;
6410
+ if (showActiveRef.current && active && active.length > 0) {
6411
+ if (multiple && selected && selected.find((i) => i === active[0])) {
6412
+ return undefined;
6413
+ }
6414
+ return controller.getItem(active[0]);
6385
6415
  }
6386
6416
  else if (focus && search) {
6387
6417
  const item = autoCompleteSearch ? findSelectItem(controller, search.toString()) : controller.items[0];
@@ -6390,8 +6420,11 @@ const ControlledSelectComponent = ({ attachDropdownToBody = false, className = '
6390
6420
  }
6391
6421
  return item;
6392
6422
  }
6393
- else if (controller.state.active && controller.state.active.length > 0) {
6394
- return controller.getItem(controller.state.active[0]);
6423
+ else if (active && active.length > 0) {
6424
+ if (multiple && selected && selected.find((i) => i === active[0])) {
6425
+ return undefined;
6426
+ }
6427
+ return controller.getItem(active[0]);
6395
6428
  }
6396
6429
  if (!multiple) {
6397
6430
  return controller.adapt(value);
@@ -7112,6 +7145,7 @@ const selectStyle = ({ theme, clickable = true, searchable = true }) => {
7112
7145
 
7113
7146
  .o-select-option-data {
7114
7147
  ${flexGrow(1)}
7148
+ ${whiteSpace('nowrap')}
7115
7149
  }
7116
7150
 
7117
7151
  .o-select-option-multiple-checkbox {
@@ -8962,7 +8996,7 @@ const TableBodyComponent = ({ className, tableRef, contentRef }) => {
8962
8996
  const itemHeight = React.useCallback(() => {
8963
8997
  return 20;
8964
8998
  }, []);
8965
- const { items, isVirtual, totalSize, virtualItems, measure } = useListView({
8999
+ const { items, isVirtual, totalSize, virtualItems, measure, scrollToIndex } = useListView({
8966
9000
  controller: service,
8967
9001
  height: height,
8968
9002
  ref: parentRef || tableRef,
@@ -8988,7 +9022,7 @@ const TableBodyComponent = ({ className, tableRef, contentRef }) => {
8988
9022
  if (service.status === onekijsFramework.LoadingStatus.Loaded && items.length === 0 && NotFoundComponent) {
8989
9023
  return React.createElement(NotFoundComponent, null);
8990
9024
  }
8991
- return (React.createElement(ListBodyComponent, { autoRefresh: autoRefresh, className: addClassname('o-table-body', className), follow: follow, height: height, ItemComponent: ItemComponentRef.current, items: items, onItemSelect: onRowClick, onItemHighlight: onRowEnter, onItemUnhighlight: onRowLeave, parentRef: parentRef || tableRef, bodyRef: contentRef, service: service, state: state, totalSize: totalSize, tail: tail, virtualItems: isVirtual ? virtualItems : undefined }));
9025
+ return (React.createElement(ListBodyComponent, { autoRefresh: autoRefresh, className: addClassname('o-table-body', className), follow: follow, height: height, ItemComponent: ItemComponentRef.current, items: items, onItemSelect: onRowClick, onItemHighlight: onRowEnter, onItemUnhighlight: onRowLeave, parentRef: parentRef || tableRef, bodyRef: contentRef, service: service, state: state, totalSize: totalSize, tail: tail, virtualItems: isVirtual ? virtualItems : undefined, scrollToIndex: scrollToIndex }));
8992
9026
  };
8993
9027
  TableBodyComponent.displayName = 'TableBody';
8994
9028
 
@@ -9756,7 +9790,7 @@ const FooterComponent = () => {
9756
9790
  React.createElement(TogglerIcon, { open: false, model: "plus", color: "currentColor" }),
9757
9791
  React.createElement("span", null, addLabel)));
9758
9792
  };
9759
- const FormTableComponent = React.memo(({ addLabel = 'add', controller, value, onChange, className, name, format = 'auto', required, minLength, maxLength, ...props }) => {
9793
+ const FormTableComponent = React.memo(({ addLabel = 'add', controller, value, onChange, className, name, format = 'auto', required, minLength, maxLength, showAddButton = true, ...props }) => {
9760
9794
  const form = onekijsFramework.useForm();
9761
9795
  const field = form.fields[name];
9762
9796
  if (field) {
@@ -9840,7 +9874,7 @@ const FormTableComponent = React.memo(({ addLabel = 'add', controller, value, on
9840
9874
  if (!mounted)
9841
9875
  return null;
9842
9876
  return (React.createElement(DefaultFormTableContext.Provider, { value: formTableContext.current },
9843
- React.createElement(ControllerTableComponent, { controller: controller, className: addClassname('o-form-table', className), FooterComponent: tableService.dataSource ? undefined : FooterComponent, footer: tableService.dataSource ? false : true, NotFoundComponent: null, ...props })));
9877
+ React.createElement(ControllerTableComponent, { controller: controller, className: addClassname('o-form-table', className), FooterComponent: tableService.dataSource ? undefined : FooterComponent, footer: tableService.dataSource || !showAddButton ? false : true, NotFoundComponent: null, ...props })));
9844
9878
  });
9845
9879
  FormTableComponent.displayName = 'FormTable';
9846
9880
 
@@ -10048,12 +10082,10 @@ const selectColumn = (id, options) => {
10048
10082
  if (Array.isArray(opts.dataSource) && Array.isArray(opts.dataSource[0])) {
10049
10083
  dataSource = opts.dataSource.map((entry) => entry[0]);
10050
10084
  const adapter = (data) => {
10051
- const item = opts.adapter ? opts.adapter(data) : {};
10052
- if (!item.text) {
10053
- const entry = opts.dataSource.find((entry) => entry[0] === data);
10054
- item.text = entry ? entry[1] : '';
10055
- }
10056
- return item;
10085
+ const entry = opts.dataSource.find((entry) => entry[0] === data);
10086
+ return {
10087
+ text: entry ? entry[1] : ''
10088
+ };
10057
10089
  };
10058
10090
  opts.adapter = adapter;
10059
10091
  }
@@ -11704,6 +11736,7 @@ exports.FormSelect = FormSelect$1;
11704
11736
  exports.FormStep = FormCard;
11705
11737
  exports.FormTable = FormTable;
11706
11738
  exports.FormTextarea = FormTextarea;
11739
+ exports.HelpIcon = HelpIcon;
11707
11740
  exports.Input = Input;
11708
11741
  exports.InputCellComponent = InputCellComponent;
11709
11742
  exports.InputComponent = InputComponent;