@synerise/ds-editable-items-list 0.0.1

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Synerise
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ ---
2
+ id: editable-items-list
3
+ title: EditableItemsList
4
+ ---
5
+
6
+ EditableItemsList UI Component
7
+
8
+ ## Installation
9
+ ```
10
+ npm i @synerise/ds-editable-items-list
11
+ or
12
+ yarn add @synerise/ds-editable-items-list
13
+ ```
14
+
15
+ ## Usage
16
+ ```
17
+ import EditableItemsList from '@synerise/ds-editable-items-list'
18
+
19
+ <EditableItemsList />
20
+
21
+ ```
22
+
23
+ ## Demo
24
+
25
+ <iframe src="/storybook-static/iframe.html?id=components-editable-items-list--default"></iframe>
26
+
27
+ ## API
28
+
29
+ | Property | Description | Type | Default |
30
+ |----------------|--------------------------------------------------------------------------|-----------------------------|---------|
31
+ | renderRowElement | Function to render each row. Invoked with item index and item object. | (index: number, item: T) => ReactElement | - |
32
+ | items | Array of items to be rendered, each should have a unique id. | T[] | - |
33
+ | addButtonLabel | Text or custom component for the "Add" button. | string \| ReactNode | - |
34
+ | addButtonIcon | Custom icon for the "Add" button. | ReactElement | - |
35
+ | addButtonProps | Additional props for the "Add" button. It can override default style. | Partial<ButtonProps> | - |
36
+ | onAdd | Callback function called when the "Add" button is clicked. | () => void | - |
37
+ | minRowLength | The minimum number of rows to display. | number | 1 |
38
+ | maxRowLength | The maximum number of rows allowed. | number | - |
39
+ | deleteTooltip | Tooltip text for the delete button. | string | - |
40
+ | onDelete | Callback function called when a row's delete button is clicked. It receives the ID and index of the row to delete. | (id: string, index: number) => void | - |
41
+
@@ -0,0 +1,6 @@
1
+ import { ReactNode } from 'react';
2
+ import { EditableItemsListProps } from './EditableItemsList.types';
3
+ declare const EditableItemsList: <T extends {
4
+ id: string;
5
+ }>({ renderRowElement, items, addButtonLabel, addButtonIcon, addButtonProps, onAdd, minRowLength, maxRowLength, deleteTooltip, onDelete, }: EditableItemsListProps<T>) => ReactNode;
6
+ export default EditableItemsList;
@@ -0,0 +1,61 @@
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
+
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
4
+
5
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
+
7
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
+
9
+ import React from 'react';
10
+ import Button from '@synerise/ds-button';
11
+ import Icon, { Add3M } from '@synerise/ds-icon';
12
+ import Cruds from '@synerise/ds-cruds';
13
+ import { theme } from '@synerise/ds-core';
14
+ import * as S from './EditableItemsList.style';
15
+ var DEFAULT_ADD_BUTTON_PROPS = {
16
+ type: 'ghost-primary',
17
+ style: {
18
+ transition: 'none'
19
+ }
20
+ };
21
+
22
+ var EditableItemsList = function EditableItemsList(_ref) {
23
+ var renderRowElement = _ref.renderRowElement,
24
+ _ref$items = _ref.items,
25
+ items = _ref$items === void 0 ? [] : _ref$items,
26
+ addButtonLabel = _ref.addButtonLabel,
27
+ addButtonIcon = _ref.addButtonIcon,
28
+ addButtonProps = _ref.addButtonProps,
29
+ onAdd = _ref.onAdd,
30
+ _ref$minRowLength = _ref.minRowLength,
31
+ minRowLength = _ref$minRowLength === void 0 ? 1 : _ref$minRowLength,
32
+ maxRowLength = _ref.maxRowLength,
33
+ deleteTooltip = _ref.deleteTooltip,
34
+ onDelete = _ref.onDelete;
35
+
36
+ var mergedAddButtonProps = _objectSpread({}, DEFAULT_ADD_BUTTON_PROPS, {}, addButtonProps, {
37
+ style: _objectSpread({}, DEFAULT_ADD_BUTTON_PROPS.style, {}, addButtonProps == null ? void 0 : addButtonProps.style)
38
+ });
39
+
40
+ return /*#__PURE__*/React.createElement(React.Fragment, null, items.map(function (item, index) {
41
+ return /*#__PURE__*/React.createElement(S.RowWrapper, {
42
+ key: item.id,
43
+ "data-testid": "item-" + item.id
44
+ }, renderRowElement(index, item), items.length > minRowLength && /*#__PURE__*/React.createElement(S.CrudWrapper, null, /*#__PURE__*/React.createElement(Cruds, {
45
+ onRemove: onDelete ? function () {
46
+ return onDelete(item.id, index);
47
+ } : undefined,
48
+ removeTooltip: deleteTooltip,
49
+ "data-testid": "remove-button-" + item.id
50
+ })));
51
+ }), /*#__PURE__*/React.createElement(Button, _extends({}, mergedAddButtonProps, {
52
+ onClick: onAdd,
53
+ disabled: maxRowLength !== undefined && items.length >= maxRowLength
54
+ }), addButtonIcon || /*#__PURE__*/React.createElement(Icon, {
55
+ component: /*#__PURE__*/React.createElement(Add3M, null),
56
+ size: 24,
57
+ color: theme.palette['blue-600']
58
+ }), addButtonLabel));
59
+ };
60
+
61
+ export default EditableItemsList;
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export declare const CrudWrapper: import("styled-components").StyledComponent<"div", any, {
3
+ marginWithLabel?: boolean | React.ReactNode;
4
+ }, never>;
5
+ export declare const RowWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -0,0 +1,9 @@
1
+ import styled from 'styled-components';
2
+ export var CrudWrapper = styled.div.withConfig({
3
+ displayName: "EditableItemsListstyle__CrudWrapper",
4
+ componentId: "a71i6b-0"
5
+ })(["padding-left:4px;visibility:hidden;margin-top:0;"]);
6
+ export var RowWrapper = styled.div.withConfig({
7
+ displayName: "EditableItemsListstyle__RowWrapper",
8
+ componentId: "a71i6b-1"
9
+ })(["display:flex;justify-content:space-between;align-items:center;padding:0 0 16px 0;&:hover{", "{visibility:visible;}}& > *:not(:last-child){margin-right:12px;}"], CrudWrapper);
@@ -0,0 +1,16 @@
1
+ import React, { ReactElement, ReactNode } from 'react';
2
+ import { ButtonProps } from '@synerise/ds-button';
3
+ export type EditableItemsListProps<T extends {
4
+ id: string;
5
+ }> = {
6
+ renderRowElement: (index: number, data: T) => ReactElement | null;
7
+ items?: T[];
8
+ addButtonProps?: Partial<ButtonProps>;
9
+ addButtonLabel: string | ReactNode;
10
+ addButtonIcon?: ReactNode;
11
+ minRowLength?: number;
12
+ maxRowLength?: number;
13
+ deleteTooltip?: string;
14
+ onDelete: (id: string, index: number) => void;
15
+ onAdd: React.MouseEventHandler<HTMLElement>;
16
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export { default } from './EditableItemsList';
2
+ export type { EditableItemsListProps } from './EditableItemsList.types';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { default } from './EditableItemsList';
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom/extend-expect';
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@synerise/ds-editable-items-list",
3
+ "version": "0.0.1",
4
+ "description": "EditableItemsList UI Component for the Synerise Design System",
5
+ "license": "ISC",
6
+ "repository": "Synerise/synerise-design",
7
+ "main": "dist/index.js",
8
+ "files": [
9
+ "/dist",
10
+ "CHANGELOG.md",
11
+ "README.md",
12
+ "package.json",
13
+ "LICENSE.md"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "scripts": {
19
+ "build": "npm run build:js && npm run build:css && npm run defs",
20
+ "build:css": "node ../../../scripts/style/less.js",
21
+ "build:js": "babel --root-mode upward src --out-dir dist --extensions '.js,.ts,.tsx'",
22
+ "build:watch": "npm run build:js -- --watch",
23
+ "defs": "tsc --declaration --outDir dist/ --emitDeclarationOnly",
24
+ "pack:ci": "npm pack --pack-destination ../../portal/storybook-static/static",
25
+ "prepublish": "npm run build",
26
+ "test": "jest",
27
+ "test:watch": "npm run test -- --watchAll",
28
+ "types": "tsc --noEmit"
29
+ },
30
+ "sideEffects": [
31
+ "dist/style/*",
32
+ "*.less"
33
+ ],
34
+ "types": "dist/index.d.ts",
35
+ "dependencies": {
36
+ "@synerise/ds-button": "^0.18.7",
37
+ "@synerise/ds-cruds": "^0.3.40"
38
+ },
39
+ "peerDependencies": {
40
+ "@synerise/ds-core": "*",
41
+ "react": ">=16.9.0 < 17.0.0",
42
+ "styled-components": "5.0.1"
43
+ },
44
+ "gitHead": "212fee47706d5956bde989445e89ad46ef5c8867"
45
+ }