react-restyle-components 0.1.83 → 0.1.84
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/lib/package.json +1 -1
- package/lib/src/core-components/index.d.ts +2 -1
- package/lib/src/core-components/index.js +2 -1
- package/lib/src/core-components/molecules/multi-select/multi-select.component.d.ts +9 -0
- package/lib/src/core-components/molecules/{mutiple-select → multi-select}/multi-select.component.js +1 -1
- package/lib/src/core-components/molecules/multi-select/multi-select.stories.d.ts +6 -0
- package/lib/src/core-components/molecules/{mutiple-select → multi-select}/multi-select.stories.js +4 -4
- package/lib/src/core-components/molecules/multi-select/multi-select.test.d.ts +1 -0
- package/lib/src/core-components/molecules/{mutiple-select → multi-select}/multi-select.test.js +3 -3
- package/lib/src/core-components/molecules/multi-select-with-field/multi-select-with-field.component.d.ts +10 -0
- package/lib/src/core-components/molecules/multi-select-with-field/multi-select-with-field.component.js +58 -0
- package/lib/src/core-components/molecules/multi-select-with-field/multi-select-with-field.stories.d.ts +6 -0
- package/lib/src/core-components/molecules/multi-select-with-field/multi-select-with-field.stories.js +20 -0
- package/lib/src/core-components/molecules/multi-select-with-field/multi-select-with-field.test.js +12 -0
- package/package.json +1 -1
- package/lib/src/core-components/molecules/mutiple-select/multi-select.component.d.ts +0 -9
- package/lib/src/core-components/molecules/mutiple-select/multi-select.stories.d.ts +0 -6
- /package/lib/src/core-components/molecules/{mutiple-select/multi-select.test.d.ts → multi-select-with-field/multi-select-with-field.test.d.ts} +0 -0
package/lib/package.json
CHANGED
|
@@ -17,6 +17,7 @@ export * from './atoms/tabs/tabs.component';
|
|
|
17
17
|
export * from './molecules/css-multiline-input/css-multiline-input.component';
|
|
18
18
|
export * from './molecules/auto-complete-filter-multiple-select-multiple-fields-display/auto-complete-filter-multiple-select-multiple-fields-display.component';
|
|
19
19
|
export * from './molecules/auto-complete-filter-single-select-multiple-fields-display/auto-complete-filter-single-select-multiple-fields-display.component';
|
|
20
|
-
export * from './molecules/
|
|
20
|
+
export * from './molecules/multi-select/multi-select.component';
|
|
21
|
+
export * from './molecules/multi-select-with-field/multi-select-with-field.component';
|
|
21
22
|
export * from './molecules/modal-confirm/modal-confirm.component';
|
|
22
23
|
export { Form };
|
|
@@ -17,6 +17,7 @@ export * from './atoms/tabs/tabs.component';
|
|
|
17
17
|
export * from './molecules/css-multiline-input/css-multiline-input.component';
|
|
18
18
|
export * from './molecules/auto-complete-filter-multiple-select-multiple-fields-display/auto-complete-filter-multiple-select-multiple-fields-display.component';
|
|
19
19
|
export * from './molecules/auto-complete-filter-single-select-multiple-fields-display/auto-complete-filter-single-select-multiple-fields-display.component';
|
|
20
|
-
export * from './molecules/
|
|
20
|
+
export * from './molecules/multi-select/multi-select.component';
|
|
21
|
+
export * from './molecules/multi-select-with-field/multi-select-with-field.component';
|
|
21
22
|
export * from './molecules/modal-confirm/modal-confirm.component';
|
|
22
23
|
export { Form };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface MultiSelectProps {
|
|
3
|
+
options: Array<string>;
|
|
4
|
+
selectedItems?: Array<string>;
|
|
5
|
+
hasError?: boolean;
|
|
6
|
+
onSelect: (item: any) => any;
|
|
7
|
+
}
|
|
8
|
+
export declare const MultiSelect: ({ options, selectedItems, hasError, onSelect, }: MultiSelectProps) => React.JSX.Element;
|
|
9
|
+
export {};
|
package/lib/src/core-components/molecules/{mutiple-select → multi-select}/multi-select.component.js
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
import React, { useState, useEffect, useRef } from 'react';
|
|
3
|
-
export const
|
|
3
|
+
export const MultiSelect = ({ options = [], selectedItems = [], hasError = false, onSelect, }) => {
|
|
4
4
|
const [selectedOptions, setSelectedOptions] = useState([]);
|
|
5
5
|
const [isListOpen, setIsListOpen] = useState(false);
|
|
6
6
|
const useOutsideAlerter = (ref) => {
|
package/lib/src/core-components/molecules/{mutiple-select → multi-select}/multi-select.stories.js
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MultiSelect } from './multi-select.component';
|
|
2
2
|
const meta = {
|
|
3
|
-
title: 'Design System/Molecules/
|
|
4
|
-
component:
|
|
3
|
+
title: 'Design System/Molecules/MultiSelect',
|
|
4
|
+
component: MultiSelect,
|
|
5
5
|
tags: ['autodocs'],
|
|
6
6
|
parameters: {
|
|
7
|
-
componentSubtitle: `import {
|
|
7
|
+
componentSubtitle: `import { MultiSelect } from 'react-restyle-components'`,
|
|
8
8
|
},
|
|
9
9
|
};
|
|
10
10
|
export default meta;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/src/core-components/molecules/{mutiple-select → multi-select}/multi-select.test.js
RENAMED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
/* eslint-disable testing-library/render-result-naming-convention */
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { render } from '@core-utils';
|
|
6
|
-
import {
|
|
7
|
-
it('render
|
|
8
|
-
const result = render(React.createElement(
|
|
6
|
+
import { MultiSelect } from './multi-select.component';
|
|
7
|
+
it('render MultiSelect correctly', () => {
|
|
8
|
+
const result = render(React.createElement(MultiSelect, { options: ['UPI', 'CASH'], selectedItems: ['CASH'], onSelect: () => { } }));
|
|
9
9
|
expect(result).toMatchSnapshot();
|
|
10
10
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface MultiSelectWithFieldProps {
|
|
3
|
+
displayField: string;
|
|
4
|
+
options: Array<any>;
|
|
5
|
+
selectedItems?: Array<any>;
|
|
6
|
+
hasError?: boolean;
|
|
7
|
+
onSelect: (item: any) => any;
|
|
8
|
+
}
|
|
9
|
+
export declare const MultiSelectWithField: ({ displayField, options, selectedItems, hasError, onSelect, }: MultiSelectWithFieldProps) => React.JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import React, { useState, useEffect, useRef } from 'react';
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
export const MultiSelectWithField = ({ displayField = '', options = [], selectedItems = [], hasError = false, onSelect, }) => {
|
|
5
|
+
const [selectedOptions, setSelectedOptions] = useState([]);
|
|
6
|
+
const [isListOpen, setIsListOpen] = useState(false);
|
|
7
|
+
const useOutsideAlerter = ref => {
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
function handleClickOutside(event) {
|
|
10
|
+
if (ref.current && !ref.current.contains(event.target) && isListOpen) {
|
|
11
|
+
setIsListOpen(false);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
15
|
+
return () => {
|
|
16
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
17
|
+
};
|
|
18
|
+
}, [ref, isListOpen]);
|
|
19
|
+
};
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
setSelectedOptions(selectedItems);
|
|
22
|
+
}, [selectedItems]);
|
|
23
|
+
const wrapperRef = useRef(null);
|
|
24
|
+
useOutsideAlerter(wrapperRef);
|
|
25
|
+
return (React.createElement(React.Fragment, null,
|
|
26
|
+
React.createElement("div", { className: `flex dark:bg-boxdark dark:text-white flex-col w-full rounded-md border-2 ${hasError ? 'border-red ' : 'border-gray-300'}`, ref: wrapperRef },
|
|
27
|
+
React.createElement("span", { className: 'p-2 mt-1 shadow-sm', onClick: () => {
|
|
28
|
+
setIsListOpen(!isListOpen);
|
|
29
|
+
} }, selectedOptions?.length > 0
|
|
30
|
+
? `${selectedOptions?.length} Items`
|
|
31
|
+
: 'Select'),
|
|
32
|
+
React.createElement("div", { className: `flex mx-2 ${isListOpen ? `show` : `hidden`}` }, options
|
|
33
|
+
? options?.length > 0 && (React.createElement("ul", { className: 'flex flex-col gap-1 p-2' }, options?.map((item, index) => (React.createElement("li", { key: index, className: 'flex items-center' },
|
|
34
|
+
React.createElement("input", { className: 'flex bg-black', type: 'checkbox', checked: !_.isEmpty(selectedOptions?.find(e => e[displayField]?.toUpperCase() ==
|
|
35
|
+
item[displayField]?.toUpperCase()))
|
|
36
|
+
? true
|
|
37
|
+
: false, onChange: () => {
|
|
38
|
+
if (!_.isEmpty(selectedOptions?.find(e => e[displayField]?.toUpperCase() ==
|
|
39
|
+
item[displayField]?.toUpperCase()))) {
|
|
40
|
+
setSelectedOptions(selectedOptions?.filter(e => e[displayField]?.toUpperCase() !=
|
|
41
|
+
item[displayField]?.toUpperCase()));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
if (selectedOptions?.length > 0) {
|
|
45
|
+
setSelectedOptions(selectedOptions?.concat([item]));
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
setSelectedOptions([item]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}, onBlur: () => {
|
|
52
|
+
if (!isListOpen)
|
|
53
|
+
onSelect(selectedOptions);
|
|
54
|
+
} }),
|
|
55
|
+
' ',
|
|
56
|
+
React.createElement("span", { className: 'flex ml-2 dark:text-white text-center' }, item[displayField]))))))
|
|
57
|
+
: null))));
|
|
58
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { MultiSelectWithField } from './multi-select-with-field.component';
|
|
3
|
+
declare const meta: Meta<typeof MultiSelectWithField>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof MultiSelectWithField>;
|
|
6
|
+
export declare const Primary: Story;
|
package/lib/src/core-components/molecules/multi-select-with-field/multi-select-with-field.stories.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MultiSelectWithField } from './multi-select-with-field.component';
|
|
2
|
+
const meta = {
|
|
3
|
+
title: 'Design System/Molecules/MultiSelectWithField',
|
|
4
|
+
component: MultiSelectWithField,
|
|
5
|
+
tags: ['autodocs'],
|
|
6
|
+
parameters: {
|
|
7
|
+
componentSubtitle: `import { MultiSelectWithField } from 'react-restyle-components'`,
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
export default meta;
|
|
11
|
+
export const Primary = {
|
|
12
|
+
args: {
|
|
13
|
+
displayField: 'code',
|
|
14
|
+
options: [{ code: 'UPI' }, { code: 'CARD' }, { code: 'CASH' }],
|
|
15
|
+
selectedItems: [{ code: 'CASH' }],
|
|
16
|
+
onSelect: (item) => {
|
|
17
|
+
console.log({ item });
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
package/lib/src/core-components/molecules/multi-select-with-field/multi-select-with-field.test.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* eslint-disable testing-library/await-async-query */
|
|
2
|
+
/* eslint-disable testing-library/prefer-screen-queries */
|
|
3
|
+
/* eslint-disable testing-library/render-result-naming-convention */
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { render } from '@core-utils';
|
|
6
|
+
import { MultiSelectWithField } from './multi-select-with-field.component';
|
|
7
|
+
it('render MultiSelectWithField correctly', () => {
|
|
8
|
+
const result = render(React.createElement(MultiSelectWithField, { displayField: 'code', options: [{ code: 'UPI' }, { code: 'CARD' }, { code: 'CASH' }], selectedItems: [{ code: 'CASH' }], onSelect: (item) => {
|
|
9
|
+
console.log({ item });
|
|
10
|
+
} }));
|
|
11
|
+
expect(result).toMatchSnapshot();
|
|
12
|
+
});
|
package/package.json
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
interface MultipleSelectProps {
|
|
3
|
-
options: Array<string>;
|
|
4
|
-
selectedItems?: Array<string>;
|
|
5
|
-
hasError?: boolean;
|
|
6
|
-
onSelect: (item: any) => any;
|
|
7
|
-
}
|
|
8
|
-
export declare const MultipleSelect: ({ options, selectedItems, hasError, onSelect, }: MultipleSelectProps) => React.JSX.Element;
|
|
9
|
-
export {};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { MultipleSelect } from './multi-select.component';
|
|
3
|
-
declare const meta: Meta<typeof MultipleSelect>;
|
|
4
|
-
export default meta;
|
|
5
|
-
type Story = StoryObj<typeof MultipleSelect>;
|
|
6
|
-
export declare const Primary: Story;
|