@synerise/ds-inline-edit 0.7.13 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.8.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-inline-edit@0.7.13...@synerise/ds-inline-edit@0.8.0) (2024-07-05)
7
+
8
+
9
+ ### Features
10
+
11
+ * **inline-edit:** swapped Menu.Item for ListItem ([94c79a3](https://github.com/Synerise/synerise-design/commit/94c79a3eb3c731952c11418bcbd49b4af8c916d9))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [0.7.13](https://github.com/Synerise/synerise-design/compare/@synerise/ds-inline-edit@0.7.12...@synerise/ds-inline-edit@0.7.13) (2024-07-02)
7
18
 
8
19
  **Note:** Version bump only for package @synerise/ds-inline-edit
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { InlineSelectProps } from './InlineSelect.types';
3
- declare const InlineSelect: ({ className, style, expanded, dropdownProps, dropdownOverlayStyle, inputStyle, size, disabled, autoFocus, hideIcon, error, input, placeholder, dataSource, initialValue, }: InlineSelectProps) => React.JSX.Element;
3
+ declare const InlineSelect: ({ className, style, expanded, dropdownProps, dropdownOverlayStyle, inputStyle, size, disabled, autoFocus, hideIcon, error, input, placeholder, dataSource, initialValue, onValueChange, }: InlineSelectProps) => React.JSX.Element;
4
4
  export default InlineSelect;
@@ -1,5 +1,9 @@
1
+ var _excluded = ["value", "onChange"];
2
+
1
3
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
4
 
5
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
6
+
3
7
  import React, { useRef, useState, useEffect } from 'react';
4
8
  import { toCamelCase } from '@synerise/ds-utils';
5
9
  import Icon, { AngleDownS } from '@synerise/ds-icon';
@@ -27,7 +31,8 @@ var InlineSelect = function InlineSelect(_ref) {
27
31
  input = _ref.input,
28
32
  placeholder = _ref.placeholder,
29
33
  dataSource = _ref.dataSource,
30
- initialValue = _ref.initialValue;
34
+ initialValue = _ref.initialValue,
35
+ onValueChange = _ref.onValueChange;
31
36
  var inputRef = useRef(null);
32
37
 
33
38
  var _useState = useState(initialValue || placeholder || 'option'),
@@ -42,11 +47,21 @@ var InlineSelect = function InlineSelect(_ref) {
42
47
  isPressed = _useState3[0],
43
48
  setIsPressed = _useState3[1];
44
49
 
50
+ var value = input.value,
51
+ onChange = input.onChange,
52
+ inputProps = _objectWithoutPropertiesLoose(input, _excluded);
53
+
54
+ var handleSelect = function handleSelect(item) {
55
+ // eslint-disable-next-line no-unused-expressions
56
+ onValueChange == null || onValueChange(item);
57
+ setSelectedValue(item.text);
58
+ };
59
+
45
60
  useEffect(function () {
46
- if (input != null && input.value && input.value !== selectedValue) {
47
- setSelectedValue(input == null ? void 0 : input.value);
61
+ if (value && value !== selectedValue) {
62
+ setSelectedValue("" + value);
48
63
  }
49
- }, [input == null ? void 0 : input.value, selectedValue]);
64
+ }, [value, selectedValue]);
50
65
  useEffect(function () {
51
66
  autoFocus && inputRef.current && inputRef.current.focus();
52
67
  }, [autoFocus, inputRef]);
@@ -57,9 +72,7 @@ var InlineSelect = function InlineSelect(_ref) {
57
72
  disabled: disabled,
58
73
  overlay: /*#__PURE__*/React.createElement(SelectDropdown, {
59
74
  dataSource: dataSource,
60
- onSelect: function onSelect(item) {
61
- return setSelectedValue(item.text);
62
- },
75
+ onSelect: handleSelect,
63
76
  closeDropdown: function closeDropdown() {
64
77
  return setIsOpened(false);
65
78
  },
@@ -86,20 +99,17 @@ var InlineSelect = function InlineSelect(_ref) {
86
99
  placeholderIsMinWidth: false,
87
100
  extraWidth: 2,
88
101
  wrapperClassName: "autosize-input"
89
- }, /*#__PURE__*/React.createElement("input", {
102
+ }, /*#__PURE__*/React.createElement("input", _extends({}, inputProps, {
90
103
  ref: inputRef,
91
104
  style: inputStyle,
92
105
  id: input.name ? toCamelCase(input.name) : 'id',
93
106
  className: "autosize-input",
94
107
  "data-testid": "inline-select-autosize-input",
95
- placeholder: placeholder,
96
- maxLength: input.maxLength,
97
- disabled: disabled,
98
- name: input.name,
99
- readOnly: input.readOnly,
100
108
  value: selectedValue || placeholder,
101
- autoComplete: "off"
102
- })), !hideIcon && /*#__PURE__*/React.createElement(S.IconWrapper, {
109
+ autoComplete: "off",
110
+ placeholder: placeholder,
111
+ disabled: disabled
112
+ }))), !hideIcon && /*#__PURE__*/React.createElement(S.IconWrapper, {
103
113
  size: size,
104
114
  expanded: isOpened
105
115
  }, /*#__PURE__*/React.createElement(Icon, {
@@ -1,8 +1,8 @@
1
1
  import type { CSSProperties } from 'react';
2
- import { MenuItemProps } from '@synerise/ds-menu/dist/Elements/Item/MenuItem.types';
3
- import { DropdownProps } from '@synerise/ds-dropdown/dist/Dropdown';
4
- import { InputProps } from '../InlineEdit.types';
5
- export type InlineSelectProps = {
2
+ import type { ListItemProps } from '@synerise/ds-list-item';
3
+ import type { DropdownProps } from '@synerise/ds-dropdown/dist/Dropdown';
4
+ import type { InputProps } from '../InlineEdit.types';
5
+ export type InlineSelectProps<ItemType extends ListItemProps = ListItemProps> = {
6
6
  size?: 'normal' | 'small';
7
7
  tooltipTitle?: string;
8
8
  className?: string;
@@ -17,6 +17,7 @@ export type InlineSelectProps = {
17
17
  hideIcon?: boolean;
18
18
  expanded?: boolean;
19
19
  initialValue?: string;
20
+ onValueChange?: (item: ItemType) => void;
20
21
  placeholder?: string;
21
- dataSource: MenuItemProps[];
22
+ dataSource: ItemType[];
22
23
  };
@@ -1,4 +1,5 @@
1
- import * as React from 'react';
2
- import { Props } from './SelectDropdown.types';
3
- declare const SelectDropdown: React.FC<Props>;
1
+ import React from 'react';
2
+ import type { ListItemProps } from '@synerise/ds-list-item';
3
+ import { SelectDropdownProps } from './SelectDropdown.types';
4
+ declare const SelectDropdown: <ItemType extends ListItemProps>({ dataSource, dropdownVisibleRows, dropdownRowHeight, onSelect, closeDropdown, style, }: SelectDropdownProps<ItemType>) => React.JSX.Element;
4
5
  export default SelectDropdown;
@@ -1,7 +1,7 @@
1
1
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
- import * as React from 'react';
4
- import Menu from '@synerise/ds-menu';
3
+ import React, { useState, useCallback } from 'react';
4
+ import ListItem from '@synerise/ds-list-item';
5
5
  import { SearchItems } from '@synerise/ds-search/dist/Elements';
6
6
  import * as S from './SelectDropdown.style';
7
7
  var DEFAULT_ROW_HEIGHT = 32;
@@ -17,40 +17,41 @@ var SelectDropdown = function SelectDropdown(_ref) {
17
17
  var rowCount = dropdownVisibleRows || DEFAULT_VISIBLE_ROWS;
18
18
  var rowHeight = dropdownRowHeight || DEFAULT_ROW_HEIGHT;
19
19
 
20
- var _React$useState = React.useState(0),
21
- scrollTop = _React$useState[0],
22
- setScrollTop = _React$useState[1];
20
+ var _useState = useState(0),
21
+ scrollTop = _useState[0],
22
+ setScrollTop = _useState[1];
23
23
 
24
- var handleChange = React.useCallback(function (item) {
25
- onSelect(item);
24
+ var handleItemClick = useCallback(function (item) {
25
+ onSelect(item); // eslint-disable-next-line no-unused-expressions
26
+
27
+ item.onClick == null || item.onClick(item);
26
28
  closeDropdown();
27
29
  }, [onSelect, closeDropdown]);
28
30
  return /*#__PURE__*/React.createElement(S.DropdownWrapper, {
29
31
  style: style
30
- }, /*#__PURE__*/React.createElement(S.DSMenu, null, /*#__PURE__*/React.createElement(S.StyledScrollbar, {
32
+ }, /*#__PURE__*/React.createElement(S.ListWrapper, null, /*#__PURE__*/React.createElement(S.StyledScrollbar, {
31
33
  maxHeight: rowCount * rowHeight,
32
34
  absolute: true,
33
- onScroll: function onScroll(e) {
34
- return setScrollTop(e.currentTarget.scrollTop);
35
+ onScroll: function onScroll(event) {
36
+ return setScrollTop(event.currentTarget.scrollTop);
35
37
  }
36
38
  }, /*#__PURE__*/React.createElement(SearchItems, {
37
- data: dataSource,
39
+ data: dataSource // eslint-disable-next-line react/jsx-handler-names
40
+ ,
38
41
  itemRender: function itemRender(item) {
39
- return /*#__PURE__*/React.createElement(Menu.Item, _extends({
42
+ return /*#__PURE__*/React.createElement(ListItem, _extends({
40
43
  key: item == null ? void 0 : item.text
41
44
  }, item));
42
45
  },
43
- onItemClick: function onItemClick(i) {
44
- return handleChange(i);
45
- },
46
+ onItemClick: handleItemClick,
46
47
  rowHeight: rowHeight,
47
48
  height: rowCount * rowHeight,
48
49
  visibleRows: rowCount,
49
50
  listProps: {
50
51
  scrollTop: scrollTop
51
- } // @ts-ignore
52
- ,
53
- width: "100%"
52
+ },
53
+ width: "100%",
54
+ renderInMenu: false
54
55
  }))));
55
56
  };
56
57
 
@@ -1,8 +1,7 @@
1
1
  /// <reference types="react" />
2
- import Menu from '@synerise/ds-menu';
3
2
  import { ScrollbarProps } from '@synerise/ds-scrollbar/dist/Scrollbar.types';
4
3
  export declare const DropdownWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
5
- export declare const DSMenu: import("styled-components").StyledComponent<typeof Menu, any, {}, never>;
4
+ export declare const ListWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
6
5
  export declare const StyledScrollbar: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<(ScrollbarProps | import("@synerise/ds-scrollbar").VirtualScrollbarProps) & import("react").RefAttributes<HTMLElement>>, any, import("@synerise/ds-scrollbar").ScrollbarAdditionalProps & {
7
6
  children?: import("react").ReactNode;
8
7
  }, never>;
@@ -1,14 +1,16 @@
1
1
  import styled from 'styled-components';
2
- import Menu from '@synerise/ds-menu';
3
2
  import Scrollbar from '@synerise/ds-scrollbar';
4
3
  export var DropdownWrapper = styled.div.withConfig({
5
4
  displayName: "SelectDropdownstyle__DropdownWrapper",
6
5
  componentId: "sc-1c17xkc-0"
7
6
  })(["display:flex;flex-direction:column;align-items:stretch;justify-content:flex-start;min-width:200px;"]);
8
- export var DSMenu = styled(Menu).withConfig({
9
- displayName: "SelectDropdownstyle__DSMenu",
7
+ export var ListWrapper = styled.div.withConfig({
8
+ displayName: "SelectDropdownstyle__ListWrapper",
10
9
  componentId: "sc-1c17xkc-1"
11
- })(["display:flex;flex-direction:column;align-items:stretch;justify-content:flex-start;padding:8px;"]);
10
+ })(["display:flex;flex-direction:column;align-items:stretch;justify-content:flex-start;padding:8px;background:", ";"], function (_ref) {
11
+ var theme = _ref.theme;
12
+ return theme.palette.white;
13
+ });
12
14
  export var StyledScrollbar = styled(Scrollbar).withConfig({
13
15
  displayName: "SelectDropdownstyle__StyledScrollbar",
14
16
  componentId: "sc-1c17xkc-2"
@@ -1,10 +1,11 @@
1
- import * as React from 'react';
2
- import { MenuItemProps } from '@synerise/ds-menu/dist/Elements/Item/MenuItem.types';
3
- export interface Props {
4
- dataSource: MenuItemProps[];
1
+ import type { CSSProperties } from 'react';
2
+ import type { ListItemProps } from '@synerise/ds-list-item';
3
+ import type { InlineSelectProps } from '../InlineSelect.types';
4
+ export type SelectDropdownProps<ItemType extends ListItemProps = ListItemProps> = Pick<InlineSelectProps<ItemType>, 'dataSource'> & {
5
5
  dropdownVisibleRows?: number;
6
6
  dropdownRowHeight?: number;
7
- onSelect: (item: MenuItemProps) => void;
7
+ onSelect: (item: ItemType) => void;
8
8
  closeDropdown: () => void;
9
- style?: React.CSSProperties;
10
- }
9
+ style?: CSSProperties;
10
+ };
11
+ export type Props = SelectDropdownProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-inline-edit",
3
- "version": "0.7.13",
3
+ "version": "0.8.0",
4
4
  "description": "InlineEdit UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -33,24 +33,20 @@
33
33
  ],
34
34
  "types": "dist/index.d.ts",
35
35
  "dependencies": {
36
- "@synerise/ds-dropdown": "^0.18.3",
37
- "@synerise/ds-icon": "^0.63.0",
38
- "@synerise/ds-input": "^0.23.0",
39
- "@synerise/ds-menu": "^0.19.3",
40
- "@synerise/ds-scrollbar": "^0.11.2",
41
- "@synerise/ds-search": "^0.8.95",
42
- "@synerise/ds-tooltip": "^0.14.31",
43
- "@synerise/ds-typography": "^0.15.0",
44
- "@synerise/ds-utils": "^0.27.0"
36
+ "@synerise/ds-dropdown": "^0.18.4",
37
+ "@synerise/ds-icon": "^0.64.0",
38
+ "@synerise/ds-input": "^0.23.1",
39
+ "@synerise/ds-list-item": "^0.4.0",
40
+ "@synerise/ds-scrollbar": "^0.11.3",
41
+ "@synerise/ds-search": "^0.9.0",
42
+ "@synerise/ds-tooltip": "^0.14.32",
43
+ "@synerise/ds-typography": "^0.15.1",
44
+ "@synerise/ds-utils": "^0.28.0"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@synerise/ds-core": "*",
48
- "react": ">=16.9.0 < 17.0.0",
48
+ "react": ">=16.9.0 <= 17.0.2",
49
49
  "styled-components": "5.0.1"
50
50
  },
51
- "devDependencies": {
52
- "@testing-library/jest-dom": "5.1.1",
53
- "@testing-library/react": "10.0.1"
54
- },
55
- "gitHead": "0692552b018dc9c8042f18c773f88890c9ad3270"
51
+ "gitHead": "6e5e5202d6c6f1c2caf6bfef799009813b437b3d"
56
52
  }
@@ -1,6 +0,0 @@
1
- export type WatcherParent = HTMLElement & {
2
- sizeWatcher?: HTMLIFrameElement;
3
- };
4
- export type ResizeCallback = (width: number, height: number) => void;
5
- declare const _default: (element: WatcherParent, resizeCallback: ResizeCallback, width?: boolean, height?: boolean) => number[] | false;
6
- export default _default;
@@ -1,43 +0,0 @@
1
- export default (function (element, resizeCallback, width, height) {
2
- if (width === void 0) {
3
- width = true;
4
- }
5
-
6
- if (height === void 0) {
7
- height = true;
8
- }
9
-
10
- var customElement = element;
11
- if (customElement.sizeWatcher) return false;
12
-
13
- if (!customElement.style.position || customElement.style.position !== 'absolute' && customElement.style.position !== 'relative') {
14
- throw new Error('Element needs to have explicit absolute or relative positioning to support size watcher');
15
- }
16
-
17
- var watcher = document.createElement('iframe');
18
- document.body.appendChild(watcher);
19
- Object.assign(watcher.style, {
20
- position: 'absolute',
21
- top: '0',
22
- left: '0',
23
- width: width ? '100%' : '0',
24
- height: height ? '100%' : '0',
25
- pointerEvents: 'none',
26
- visibility: 'hidden',
27
- border: 'none',
28
- margin: '0',
29
- padding: '0'
30
- });
31
- customElement.appendChild(watcher);
32
- customElement.sizeWatcher = watcher;
33
- var content = watcher.contentWindow;
34
-
35
- if (content) {
36
- content.addEventListener('resize', function (event) {
37
- return resizeCallback(event.target.innerWidth, event.target.innerHeight);
38
- });
39
- return [content.innerWidth, content.innerHeight];
40
- }
41
-
42
- return false;
43
- });
@@ -1 +0,0 @@
1
- export { default as attachWidthWatcher } from './attachWidthWatcher/attachWidthWatcher';
@@ -1,2 +0,0 @@
1
- // eslint-disable-next-line import/prefer-default-export
2
- export { default as attachWidthWatcher } from './attachWidthWatcher/attachWidthWatcher';