@tecsinapse/react-web-kit 1.17.10 → 1.17.11
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,14 @@
|
|
|
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
|
+
## [1.17.11](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-web-kit@1.17.10...@tecsinapse/react-web-kit@1.17.11) (2022-07-14)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @tecsinapse/react-web-kit
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [1.17.10](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-web-kit@1.17.9...@tecsinapse/react-web-kit@1.17.10) (2022-07-14)
|
|
7
15
|
|
|
8
16
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { TextProps } from '@tecsinapse/react-core';
|
|
2
|
+
import React from 'react';
|
|
3
3
|
export interface SelectProps<Data, Type extends 'single' | 'multi'> extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onSelect'> {
|
|
4
4
|
options: Data[];
|
|
5
5
|
onSelect: (option: Type extends 'single' ? Data | undefined : Data[]) => never | void;
|
|
@@ -5,21 +5,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.Select = void 0;
|
|
7
7
|
|
|
8
|
+
var _reactCore = require("@tecsinapse/react-core");
|
|
9
|
+
|
|
8
10
|
var _react = _interopRequireDefault(require("react"));
|
|
9
11
|
|
|
10
|
-
var
|
|
12
|
+
var _reactTransitionGroup = require("react-transition-group");
|
|
11
13
|
|
|
12
14
|
var _hooks = require("../../../hooks");
|
|
13
15
|
|
|
14
|
-
var
|
|
16
|
+
var _animations = require("./animations");
|
|
15
17
|
|
|
16
18
|
var _Dropdown = require("./Dropdown");
|
|
17
19
|
|
|
18
20
|
var _functions = require("./functions");
|
|
19
21
|
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
var _animations = require("./animations");
|
|
22
|
+
var _styled = require("./styled");
|
|
23
23
|
|
|
24
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
25
|
|
|
@@ -48,14 +48,21 @@ const Select = ({
|
|
|
48
48
|
const refDropDown = _react.default.useRef(null);
|
|
49
49
|
|
|
50
50
|
(0, _hooks.useClickAwayListener)(refDropDown, setDropDownVisible);
|
|
51
|
-
const
|
|
51
|
+
const onlyLabel = label && !placeholder;
|
|
52
|
+
const hasValue = type === 'single' ? !!value : (value || []).length > 0;
|
|
53
|
+
|
|
54
|
+
const _placeholder = onlyLabel ? label : placeholder;
|
|
55
|
+
|
|
56
|
+
const _label = hasValue ? label : undefined;
|
|
57
|
+
|
|
58
|
+
const displayValue = (0, _functions.getDisplayValue)(type, value, options, _placeholder, keyExtractor, labelExtractor);
|
|
52
59
|
|
|
53
60
|
const onPress = _react.default.useCallback(() => setDropDownVisible(prev => !prev), [setDropDownVisible]);
|
|
54
61
|
|
|
55
62
|
return _react.default.createElement(_styled.StyledContainer, _extends({
|
|
56
63
|
ref: refDropDown
|
|
57
64
|
}, rest), _react.default.createElement(_styled.StyledInputContainer, null, _react.default.createElement(_reactCore.PressableInputContainer, {
|
|
58
|
-
label:
|
|
65
|
+
label: _label,
|
|
59
66
|
onPress: onPress,
|
|
60
67
|
disabled: disabled,
|
|
61
68
|
rightComponent: _styled.RightComponent
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/molecules/Select/Select.tsx"],"names":["Select","value","options","keyExtractor","onSelect","type","labelExtractor","placeholder","onSearch","searchBarPlaceholder","hideSearchBar","label","disabled","anchor","displayTextProps","selectAllLabel","rest","dropDownVisible","setDropDownVisible","React","useState","refDropDown","useRef","displayValue","onPress","useCallback","prev","RightComponent","state","defaultStyles","transition"],"mappings":";;;;;;;AAAA;;
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/molecules/Select/Select.tsx"],"names":["Select","value","options","keyExtractor","onSelect","type","labelExtractor","placeholder","onSearch","searchBarPlaceholder","hideSearchBar","label","disabled","anchor","displayTextProps","selectAllLabel","rest","dropDownVisible","setDropDownVisible","React","useState","refDropDown","useRef","onlyLabel","hasValue","length","_placeholder","_label","undefined","displayValue","onPress","useCallback","prev","RightComponent","state","defaultStyles","transition"],"mappings":";;;;;;;AAAA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AA4BO,MAAMA,MAAM,GAAG,CAAwC;AAC5DC,EAAAA,KAD4D;AAE5DC,EAAAA,OAF4D;AAG5DC,EAAAA,YAH4D;AAI5DC,EAAAA,QAJ4D;AAK5DC,EAAAA,IAL4D;AAM5DC,EAAAA,cAN4D;AAO5DC,EAAAA,WAP4D;AAQ5DC,EAAAA,QAR4D;AAS5DC,EAAAA,oBAAoB,GAAG,yBATqC;AAU5DC,EAAAA,aAAa,GAAG,IAV4C;AAW5DC,EAAAA,KAX4D;AAY5DC,EAAAA,QAAQ,GAAG,KAZiD;AAa5DC,EAAAA,MAAM,GAAG,QAbmD;AAc5DC,EAAAA,gBAd4D;AAe5DC,EAAAA,cAAc,GAAG,kBAf2C;AAgB5D,KAAGC;AAhByD,CAAxC,KAiBsB;AAC1C,QAAM,CAACC,eAAD,EAAkBC,kBAAlB,IAAwCC,eAAMC,QAAN,CAAwB,KAAxB,CAA9C;;AACA,QAAMC,WAAW,GAAGF,eAAMG,MAAN,CAAa,IAAb,CAApB;;AACA,mCAAqBD,WAArB,EAAkCH,kBAAlC;AAEA,QAAMK,SAAS,GAAGZ,KAAK,IAAI,CAACJ,WAA5B;AACA,QAAMiB,QAAQ,GAAGnB,IAAI,KAAK,QAAT,GAAoB,CAAC,CAACJ,KAAtB,GAA8B,CAAEA,K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EAAE,GAAG2B,yBAAL;AAAoB,SAAGC,uBAAWvB,MAAX,EAAmBqB,KAAnB;AAAvB,KAVT;AAWE,IAAA,kBAAkB,EAAEhB,kBAXtB;AAYE,IAAA,MAAM,EAAEL,MAZV;AAaE,IAAA,cAAc,EAAEE;AAblB,IAFJ,CAbF,CADF;AAmCD,CA3EM;;;eA6EQf,M","sourcesContent":["import {\n PressableInputContainer,\n Text,\n TextProps\n} from '@tecsinapse/react-core';\nimport React from 'react';\nimport { Transition } from 'react-transition-group';\nimport { useClickAwayListener } from '../../../hooks';\nimport { defaultStyles, transition } from './animations';\nimport { Dropdown } from './Dropdown';\nimport { getDisplayValue } from './functions';\nimport {\n RightComponent,\n StyledContainer,\n StyledInputContainer\n} from './styled';\n\nexport interface SelectProps<Data, Type extends 'single' | 'multi'>\n extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onSelect'> {\n options: Data[];\n onSelect: (\n option: Type extends 'single' ? Data | undefined : Data[]\n ) => never | void;\n value: Type extends 'single' ? Data | undefined : Data[];\n type: Type;\n keyExtractor: (t: Data, index?: number) => string;\n labelExtractor: (t: Data) => string;\n placeholder?: string;\n onSearch?: (searchArg: string) => void | never;\n searchBarPlaceholder?: string;\n hideSearchBar?: boolean;\n selectAllLabel?: string;\n disabled?: boolean;\n label?: string;\n anchor?: 'top' | 'bottom';\n displayTextProps?: TextProps;\n}\n\n/** NOTE: For better performance, you should memoize options and handlers */\nexport const Select = <Data, Type extends 'single' | 'multi'>({\n value,\n options,\n keyExtractor,\n onSelect,\n type,\n labelExtractor,\n placeholder,\n onSearch,\n searchBarPlaceholder = 'Busque a opção desejada',\n hideSearchBar = true,\n label,\n disabled = false,\n anchor = 'bottom',\n displayTextProps,\n selectAllLabel = 'Selecionar todos',\n ...rest\n}: SelectProps<Data, Type>): JSX.Element => {\n const [dropDownVisible, setDropDownVisible] = React.useState<boolean>(false);\n const refDropDown = React.useRef(null);\n useClickAwayListener(refDropDown, setDropDownVisible);\n\n const onlyLabel = label && !placeholder;\n const hasValue = type === 'single' ? !!value : ((value || []) as []).length > 0\n const _placeholder = onlyLabel ? label : placeholder\n const _label = hasValue ? label : undefined\n\n const displayValue = getDisplayValue<Data>(\n type,\n value,\n options,\n _placeholder,\n keyExtractor,\n labelExtractor\n );\n\n const onPress = React.useCallback(() => setDropDownVisible(prev => !prev), [\n setDropDownVisible,\n ]);\n\n return (\n <StyledContainer ref={refDropDown} {...rest}>\n <StyledInputContainer>\n <PressableInputContainer\n label={_label}\n onPress={onPress}\n disabled={disabled}\n rightComponent={RightComponent}\n >\n <Text {...displayTextProps} ellipsizeMode=\"tail\" numberOfLines={1}>\n {displayValue}\n </Text>\n </PressableInputContainer>\n </StyledInputContainer>\n <Transition in={dropDownVisible} timeout={300}>\n {state => (\n <Dropdown\n options={options}\n onSelect={onSelect}\n value={value}\n type={type}\n keyExtractor={keyExtractor}\n labelExtractor={labelExtractor}\n hideSearchBar={hideSearchBar}\n searchBarPlaceholder={searchBarPlaceholder}\n onSearch={onSearch}\n style={{ ...defaultStyles, ...transition[anchor][state] }}\n setDropDownVisible={setDropDownVisible}\n anchor={anchor}\n selectAllLabel={selectAllLabel}\n />\n )}\n </Transition>\n </StyledContainer>\n );\n};\n\nexport default Select;\n"],"file":"Select.js"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tecsinapse/react-web-kit",
|
|
3
3
|
"description": "TecSinapse React components",
|
|
4
|
-
"version": "1.17.
|
|
4
|
+
"version": "1.17.11",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
37
37
|
"react-native-web": "^0.17.1"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "5b6adbc48490edb759d8f7d1a8519d5c7043360a"
|
|
40
40
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import {
|
|
3
2
|
PressableInputContainer,
|
|
4
3
|
Text,
|
|
5
|
-
TextProps
|
|
4
|
+
TextProps
|
|
6
5
|
} from '@tecsinapse/react-core';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { Transition } from 'react-transition-group';
|
|
7
8
|
import { useClickAwayListener } from '../../../hooks';
|
|
9
|
+
import { defaultStyles, transition } from './animations';
|
|
10
|
+
import { Dropdown } from './Dropdown';
|
|
11
|
+
import { getDisplayValue } from './functions';
|
|
8
12
|
import {
|
|
9
13
|
RightComponent,
|
|
10
14
|
StyledContainer,
|
|
11
|
-
StyledInputContainer
|
|
15
|
+
StyledInputContainer
|
|
12
16
|
} from './styled';
|
|
13
|
-
import { Dropdown } from './Dropdown';
|
|
14
|
-
import { getDisplayValue } from './functions';
|
|
15
|
-
import { Transition } from 'react-transition-group';
|
|
16
|
-
import { defaultStyles, transition } from './animations';
|
|
17
17
|
|
|
18
18
|
export interface SelectProps<Data, Type extends 'single' | 'multi'>
|
|
19
19
|
extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onSelect'> {
|
|
@@ -59,11 +59,16 @@ export const Select = <Data, Type extends 'single' | 'multi'>({
|
|
|
59
59
|
const refDropDown = React.useRef(null);
|
|
60
60
|
useClickAwayListener(refDropDown, setDropDownVisible);
|
|
61
61
|
|
|
62
|
+
const onlyLabel = label && !placeholder;
|
|
63
|
+
const hasValue = type === 'single' ? !!value : ((value || []) as []).length > 0
|
|
64
|
+
const _placeholder = onlyLabel ? label : placeholder
|
|
65
|
+
const _label = hasValue ? label : undefined
|
|
66
|
+
|
|
62
67
|
const displayValue = getDisplayValue<Data>(
|
|
63
68
|
type,
|
|
64
69
|
value,
|
|
65
70
|
options,
|
|
66
|
-
|
|
71
|
+
_placeholder,
|
|
67
72
|
keyExtractor,
|
|
68
73
|
labelExtractor
|
|
69
74
|
);
|
|
@@ -76,7 +81,7 @@ export const Select = <Data, Type extends 'single' | 'multi'>({
|
|
|
76
81
|
<StyledContainer ref={refDropDown} {...rest}>
|
|
77
82
|
<StyledInputContainer>
|
|
78
83
|
<PressableInputContainer
|
|
79
|
-
label={
|
|
84
|
+
label={_label}
|
|
80
85
|
onPress={onPress}
|
|
81
86
|
disabled={disabled}
|
|
82
87
|
rightComponent={RightComponent}
|