forstok-ui-lib 5.2.11 → 5.2.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forstok-ui-lib",
3
- "version": "5.2.11",
3
+ "version": "5.2.13",
4
4
  "description": "Forstok UI Components Library",
5
5
  "path": "dist",
6
6
  "main": "dist/index.js",
@@ -42,6 +42,7 @@
42
42
  "react-dom": "^19.0.0",
43
43
  "react-router-dom": "^7.1.1",
44
44
  "react-select": "^5.10.0",
45
+ "react-select-async-paginate": "^0.7.9",
45
46
  "rollup-plugin-dts": "^6.1.1",
46
47
  "rollup-plugin-peer-deps-external": "^2.2.4",
47
48
  "rollup-plugin-postcss": "^4.0.2",
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
2
+ <svg fill="#808080" width="100%" height="100%" viewBox="0 0 56 56" xmlns="http://www.w3.org/2000/svg"><path d="M 44.5235 48.6602 L 46.1407 14.3945 L 48.4844 14.3945 C 49.4454 14.3945 50.2187 13.5976 50.2187 12.6367 C 50.2187 11.6758 49.4454 10.8555 48.4844 10.8555 L 38.2422 10.8555 L 38.2422 7.3398 C 38.2422 3.9883 35.9688 1.8086 32.3595 1.8086 L 23.5938 1.8086 C 19.9844 1.8086 17.7344 3.9883 17.7344 7.3398 L 17.7344 10.8555 L 7.5391 10.8555 C 6.6016 10.8555 5.7813 11.6758 5.7813 12.6367 C 5.7813 13.5976 6.6016 14.3945 7.5391 14.3945 L 9.8829 14.3945 L 11.5000 48.6836 C 11.6641 52.0586 13.8907 54.1914 17.2657 54.1914 L 38.7579 54.1914 C 42.1095 54.1914 44.3595 52.0351 44.5235 48.6602 Z M 21.4844 7.5742 C 21.4844 6.2383 22.4688 5.3008 23.8751 5.3008 L 32.1016 5.3008 C 33.5313 5.3008 34.5157 6.2383 34.5157 7.5742 L 34.5157 10.8555 L 21.4844 10.8555 Z M 17.6173 50.6758 C 16.2579 50.6758 15.2500 49.6445 15.1797 48.2852 L 13.5391 14.3945 L 42.3907 14.3945 L 40.8438 48.2852 C 40.7735 49.6680 39.7891 50.6758 38.4063 50.6758 Z M 34.9610 46.5508 C 35.7344 46.5508 36.3204 45.9180 36.3438 45.0273 L 37.0469 20.2773 C 37.0704 19.3867 36.4610 18.7305 35.6641 18.7305 C 34.9376 18.7305 34.3282 19.4102 34.3048 20.2539 L 33.6016 45.0273 C 33.5782 45.8711 34.1641 46.5508 34.9610 46.5508 Z M 21.0626 46.5508 C 21.8595 46.5508 22.4454 45.8711 22.4219 45.0273 L 21.7188 20.2539 C 21.6954 19.4102 21.0626 18.7305 20.3360 18.7305 C 19.5391 18.7305 18.9532 19.3867 18.9766 20.2773 L 19.7032 45.0273 C 19.7266 45.9180 20.2891 46.5508 21.0626 46.5508 Z M 29.4298 45.0273 L 29.4298 20.2539 C 29.4298 19.4102 28.7969 18.7305 28.0235 18.7305 C 27.2500 18.7305 26.5938 19.4102 26.5938 20.2539 L 26.5938 45.0273 C 26.5938 45.8711 27.2500 46.5508 28.0235 46.5508 C 28.7735 46.5508 29.4298 45.8711 29.4298 45.0273 Z"/></svg>
@@ -21,6 +21,7 @@ import IconPrint from '../../assets/images/icons/print.svg';
21
21
  import IconWarning from '../../assets/images/icons/warning.svg';
22
22
  import IconAlert from '../../assets/images/icons/alert.svg';
23
23
  import IconBarcode from '../../assets/images/icons/barcode.svg';
24
+ import IconTrash from '../../assets/images/icons/trash.svg'
24
25
 
25
26
  const getIconContainerStyled = ({ $mode, $name, $width, onClick }:{ $mode?: string, $name: string, $width?: string | number, onClick?: (e: MouseEvent<HTMLElement>) => void }) => {
26
27
  let style = ``;
@@ -172,6 +173,13 @@ const getIconContainerStyled = ({ $mode, $name, $width, onClick }:{ $mode?: stri
172
173
  }
173
174
  `
174
175
  break;
176
+ case 'trash':
177
+ style += `
178
+ &:before {
179
+ content: url(${IconTrash});
180
+ }
181
+ `
182
+ break;
175
183
  default:
176
184
  break;
177
185
  }
@@ -0,0 +1,126 @@
1
+ import { useCallback, useEffect, useState } from 'react'
2
+ import type { OnChangeValue, OptionProps, GroupBase, ActionMeta, StylesConfig, CSSObjectWithLabel, ControlProps } from 'react-select'
3
+ import { AsyncPaginate } from 'react-select-async-paginate'
4
+ import type { LoadOptions } from 'react-select-async-paginate'
5
+ import { CSSObject } from '@emotion/serialize'
6
+ import type { TLoadOption, TOption } from './typed'
7
+ import { TState } from '../../typeds'
8
+
9
+ type TSelect = {
10
+ customOption?: (arg0: OptionProps) => void
11
+ MenuList?: any
12
+ evChange?: (newValue: OnChangeValue<TOption, false>, actionMeta?: ActionMeta<TOption>) => void
13
+ defaultValue?: OnChangeValue<TOption, boolean>
14
+ loadOptions: TLoadOption | LoadOptions<unknown, GroupBase<unknown>, unknown>
15
+ loadOptionsOnMenuOpen?: boolean
16
+ noOptionsMessage?: ((obj: {
17
+ inputValue: string;
18
+ }) => React.ReactNode)
19
+ isSearchable?: boolean
20
+ isClearable?: boolean
21
+ placeholder?: string
22
+ isMenuOpen?: boolean
23
+ setMenuIsOpen: TState<boolean|undefined>
24
+ isForceUpdate: boolean
25
+ setForceUpdate: TState<boolean>
26
+ }
27
+
28
+ const SelectAsyncPaginate = ({ loadOptions, isForceUpdate, setForceUpdate, ...props }:TSelect) => {
29
+ const { customOption, MenuList, defaultValue, evChange, loadOptionsOnMenuOpen, noOptionsMessage, isSearchable, placeholder, isMenuOpen, setMenuIsOpen } = props;
30
+ const [valueSelect, setValueSelect] = useState<typeof defaultValue>(defaultValue || null);
31
+
32
+ useEffect(() => {
33
+ if (isForceUpdate) {
34
+ setValueSelect(defaultValue || null);
35
+ setForceUpdate(false);
36
+ }
37
+ }, [defaultValue, isForceUpdate, setForceUpdate, setValueSelect]);
38
+
39
+ const handleChange = (value: OnChangeValue<TOption, boolean>, actionMeta?: ActionMeta<TOption>) => {
40
+ const newValue = value as OnChangeValue<TOption, false>;
41
+ setValueSelect(newValue ? { value: newValue.value, label : newValue.label } : newValue);
42
+ evChange && evChange(newValue, actionMeta);
43
+ }
44
+
45
+ const customStyles: StylesConfig<TOption, boolean> = {
46
+ container: (provided: CSSObject) => ({
47
+ ...provided,
48
+ display: 'inline-block',
49
+ width: '100%',
50
+ minHeight: '1px',
51
+ textAlign: 'left',
52
+ border: 'none',
53
+ } as CSSObjectWithLabel),
54
+ control: (provided: CSSObject, state:ControlProps<TOption, boolean>) => ({
55
+ ...provided,
56
+ borderRadius: '4px',
57
+ minHeight: '1px',
58
+ cursor: 'pointer',
59
+ borderWidth: '1px' ,
60
+ boxShadow: 'none',
61
+ } as CSSObjectWithLabel),
62
+ input: (provided: CSSObject) => ({
63
+ ...provided,
64
+ minHeight: '1px',
65
+ margin: '0 2px',
66
+ padding: '0',
67
+ 'input': {
68
+ boxShadow: 'none !important'
69
+ }
70
+ } as CSSObjectWithLabel),
71
+ singleValue: (provided: CSSObject) => ({
72
+ ...provided,
73
+ minHeight: '1px',
74
+ paddingBottom: '2px',
75
+ color: 'initial',
76
+ } as CSSObjectWithLabel),
77
+ option: (provided: CSSObject, state: OptionProps<TOption, boolean>) => ({
78
+ ...provided,
79
+ color: state.isSelected ? '#ffffff' : '#000000',
80
+ backgroundColor: state.isSelected || state.isFocused ? '#fc5c64' : 'transparent',
81
+ cursor: 'pointer',
82
+ '&:hover': {
83
+ backgroundColor: '#ec5b62',
84
+ color: '#ffffff'
85
+ }
86
+ } as CSSObjectWithLabel),
87
+ menuPortal: (provided: CSSObject) => ({
88
+ ...provided,
89
+ zIndex: 9999,
90
+ letterSpacing: 'normal',
91
+ lineHeight: 'normal',
92
+ } as CSSObjectWithLabel)
93
+ }
94
+
95
+ const onMenuOpen = useCallback(() => {
96
+ setMenuIsOpen(true);
97
+ }, [setMenuIsOpen]);
98
+
99
+ const onMenuClose = useCallback(() => {
100
+ setMenuIsOpen(false);
101
+ }, [setMenuIsOpen]);
102
+
103
+ return <div className='_refContainer'>
104
+ <AsyncPaginate
105
+ isSearchable={isSearchable}
106
+ placeholder={placeholder}
107
+ debounceTimeout={500}
108
+ styles={customStyles}
109
+ loadOptions={loadOptions}
110
+ menuPortalTarget={document.body}
111
+ menuPosition='fixed'
112
+ menuPlacement='auto'
113
+ value={valueSelect}
114
+ onChange={handleChange}
115
+ loadOptionsOnMenuOpen={loadOptionsOnMenuOpen}
116
+ noOptionsMessage={noOptionsMessage}
117
+ menuIsOpen={isMenuOpen}
118
+ onMenuOpen={onMenuOpen}
119
+ onMenuClose={onMenuClose}
120
+ {...customOption && { components: { Option: customOption } }}
121
+ {...MenuList && { components: { MenuList } }}
122
+ {...props} />
123
+ </div>
124
+ }
125
+
126
+ export default SelectAsyncPaginate
@@ -1,4 +1,4 @@
1
- import type { OnChangeValue } from 'react-select';
1
+ import type { ActionMeta, OnChangeValue } from 'react-select';
2
2
  import type { TChannel } from '../../typeds/shares.typed';
3
3
 
4
4
  export type TOption = {
@@ -17,4 +17,20 @@ export type TOption = {
17
17
  }[]
18
18
  }
19
19
 
20
- export type TOnChangeValue = OnChangeValue<TOption, boolean>
20
+ export type TLoadOption = (search: string, callback: () => void, { endCursor }: {
21
+ endCursor: string;
22
+ }) => Promise<{
23
+ options: any;
24
+ hasMore: any;
25
+ additional?: {
26
+ endCursor: any;
27
+ };
28
+ } | {
29
+ options: never[];
30
+ hasMore: boolean;
31
+ additional?: undefined;
32
+ } | undefined>
33
+
34
+ export type TOnChangeValue = OnChangeValue<TOption, boolean>
35
+
36
+ export type TActionMeta = ActionMeta<TOption>