forstok-ui-lib 5.2.12 → 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/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
3
  import { HTMLAttributes, ReactNode, AnchorHTMLAttributes, MouseEvent, Dispatch, SetStateAction, KeyboardEvent, FocusEvent, ChangeEvent, DragEvent, InputHTMLAttributes, PropsWithChildren, ButtonHTMLAttributes, RefObject, ImgHTMLAttributes } from 'react';
4
- import { OnChangeValue, OptionProps, SingleValueProps, ActionMeta } from 'react-select';
4
+ import { OnChangeValue, ActionMeta, OptionProps, SingleValueProps } from 'react-select';
5
5
  import * as styled_components from 'styled-components';
6
6
  import * as styled_components_dist_types from 'styled-components/dist/types';
7
7
 
@@ -306,7 +306,21 @@ type TOption = {
306
306
  localId?: string;
307
307
  }[];
308
308
  };
309
+ type TLoadOption = (search: string, callback: () => void, { endCursor }: {
310
+ endCursor: string;
311
+ }) => Promise<{
312
+ options: any;
313
+ hasMore: any;
314
+ additional?: {
315
+ endCursor: any;
316
+ };
317
+ } | {
318
+ options: never[];
319
+ hasMore: boolean;
320
+ additional?: undefined;
321
+ } | undefined>;
309
322
  type TOnChangeValue = OnChangeValue<TOption, boolean>;
323
+ type TActionMeta = ActionMeta<TOption>;
310
324
 
311
325
  type TSelect = {
312
326
  type?: string;
@@ -412,4 +426,4 @@ declare const generateMessage: (type: string, value: string | ReactNode, callbac
412
426
  declare const generateMessageQuestion: (type: string, title: string, subtitle: string, callback?: () => void, buttonSubmit?: string, cancelCallback?: () => void) => TMessageQuestion;
413
427
  declare const currencyNumber: (value: number) => string;
414
428
 
415
- export { ButtonComponent, CheckboxComponent, DropDownComponent as DropdownComponent, ErrorComponent, FoContainer, FormContainer, HeaderContainer, IconComponent, ImageComponent, InfoGroup, InputComponent, InputGroup, InputWithRefComponent as InputRefComponent, type KeysToSnakeCase, LabelComponent, LinkComponent, ListContainer, LoadingComponent, MessageComponent, MessageQuestionComponent, MuteLabel, PanelContainer, PanelWrapper, type PartialBy, PopupComponent, ReactPortalComponent, SelectComponent, SingleFormContainer, type TChangeEvent, type TChannel, type TCloseDropdownFunction, type TDragEvent, type TDropdown, type TEnterEvent, type TFile, type TFileImage, type THierarchy, type TIdNum, type TIdStr, type TKeyboadEvent, type TMessage, type TMessageFunction, type TMessageQuestion, type TMessageQuestionFunction, type TMouseEvent, type TObject, type TOnChangeValue, type TOption, type TPage, type TPopup, type TPopupContainer, type TPopupFunction, type TPopupFunctionGroup, type TPopupFunctionParam, type TPopupOpenFunction, type TState, type TUser, TabsContainer, TabsContent, TextComponent, Title, UploadComponent, UploadDragDropComponent, type WithRequired, boxBase, capitalize, clearList, currencyNumber, debounce, dropBase, elipsis, formLabel, formatNumber, generateMessage, generateMessageQuestion, getStorage, headTable, multiElipsis, removeStorage, responseWidth, setStorage, thirdElipsis };
429
+ export { ButtonComponent, CheckboxComponent, DropDownComponent as DropdownComponent, ErrorComponent, FoContainer, FormContainer, HeaderContainer, IconComponent, ImageComponent, InfoGroup, InputComponent, InputGroup, InputWithRefComponent as InputRefComponent, type KeysToSnakeCase, LabelComponent, LinkComponent, ListContainer, LoadingComponent, MessageComponent, MessageQuestionComponent, MuteLabel, PanelContainer, PanelWrapper, type PartialBy, PopupComponent, ReactPortalComponent, SelectComponent, SingleFormContainer, type TActionMeta, type TChangeEvent, type TChannel, type TCloseDropdownFunction, type TDragEvent, type TDropdown, type TEnterEvent, type TFile, type TFileImage, type THierarchy, type TIdNum, type TIdStr, type TKeyboadEvent, type TLoadOption, type TMessage, type TMessageFunction, type TMessageQuestion, type TMessageQuestionFunction, type TMouseEvent, type TObject, type TOnChangeValue, type TOption, type TPage, type TPopup, type TPopupContainer, type TPopupFunction, type TPopupFunctionGroup, type TPopupFunctionParam, type TPopupOpenFunction, type TState, type TUser, TabsContainer, TabsContent, TextComponent, Title, UploadComponent, UploadDragDropComponent, type WithRequired, boxBase, capitalize, clearList, currencyNumber, debounce, dropBase, elipsis, formLabel, formatNumber, generateMessage, generateMessageQuestion, getStorage, headTable, multiElipsis, removeStorage, responseWidth, setStorage, thirdElipsis };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forstok-ui-lib",
3
- "version": "5.2.12",
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,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>