@via-profit/ui-kit 0.1.0-rc.79 → 0.1.0-rc.80

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.
@@ -49,12 +49,57 @@ export interface AutocompleteProps<T, Multiple extends boolean | undefined = und
49
49
  * items render function
50
50
  */
51
51
  readonly children: Children<T>;
52
+ /**
53
+ * A function that returns a filtered array of values. which correspond to the entered query
54
+ * Example:
55
+ * ```tsx
56
+ * <Autocomplete
57
+ * filterItems={(items, { query }) =>
58
+ * items.filter(item => item.name.toLocaleLowerCase().indexOf(query) !== -1)
59
+ * }
60
+ * ...
61
+ * >
62
+ * ```
63
+ * </Autocomplete>
64
+ */
52
65
  readonly filterItems?: FilterItems<T>;
66
+ /**
67
+ * The function that will be called when an item is selected from the list
68
+ */
53
69
  readonly onChange?: OnChange<T, Multiple>;
70
+ /**
71
+ * A function that transforms the selected item into a string
72
+ * Example:
73
+ * ```tsx
74
+ * <Autocomplete
75
+ * selectedItemToString={item => item.name} // item is {id: 1, name: 'Oleg'}
76
+ * ...
77
+ * >
78
+ * ...
79
+ * </Autocomplete>
80
+ * ```
81
+ */
54
82
  readonly selectedItemToString: ItemToString<T, Multiple>;
83
+ /**
84
+ * A function that determines which of the elements is currently selected\
85
+ * Example:
86
+ * ```tsx
87
+ * <Menu
88
+ * ...
89
+ * getOptionSelected={({ item, value }) => item.id === value.id}
90
+ */
55
91
  readonly getOptionSelected?: GetOptionSelected<T>;
92
+ /**
93
+ * The function that will be called at the moment when you want to close the autocomplete
94
+ */
56
95
  readonly onRequestClose?: OnRequestClose;
96
+ /**
97
+ * The function that will be called at the moment when you change the input value of input element
98
+ */
57
99
  readonly onInputChange?: React.ChangeEventHandler<HTMLInputElement>;
100
+ /**
101
+ * The function that will be called at the moment when you want to open the selectbox
102
+ */
58
103
  readonly onRequestOpen?: (event: React.KeyboardEvent<HTMLElement> | React.MouseEvent<HTMLElement> | React.FocusEvent<HTMLInputElement, Element> | React.ChangeEvent<HTMLInputElement>) => void;
59
104
  /**
60
105
  * Overridable components map
@@ -128,11 +128,6 @@ export interface MenuProps<T, Multiple extends boolean | undefined = undefined>
128
128
  * Called when item selected
129
129
  */
130
130
  readonly onSelectItem?: OnSelectItem<T, Multiple>;
131
- /**
132
- * A function that renders each list item as string\
133
- * \
134
- * **Default**: `JSON.stringify(...)`
135
- */
136
131
  /**
137
132
  * The function that will be called at the moment when you want to close the menu
138
133
  */
@@ -10,6 +10,7 @@ const TabManager_1 = __importDefault(require("../../utils/TabManager"));
10
10
  const ModalWrapper = props => {
11
11
  const { children, isOpen: isOpenProp, autofocus = true } = props;
12
12
  const { state, dispatch } = (0, context_1.useContext)();
13
+ const initialOpenStateRef = react_1.default.useRef(isOpenProp);
13
14
  const [alreadyMounted, setMountState] = react_1.default.useState(true);
14
15
  const { closeOnEscape, isMounted, isOpen, destroyTimeout, onRequestClose } = state;
15
16
  const containerRef = react_1.default.useRef(null);
@@ -98,7 +99,7 @@ const ModalWrapper = props => {
98
99
  */
99
100
  react_1.default.useEffect(() => {
100
101
  var _a;
101
- if (isOpen !== isOpenProp) {
102
+ if (isOpen !== isOpenProp || initialOpenStateRef.current) {
102
103
  /**
103
104
  * Mark as mounted and wait minimum loop of event (15ms) then mark as open
104
105
  */
@@ -12,6 +12,9 @@ import { SelectboxButtonWrapperProps } from './SelectboxButtonWrapper';
12
12
  import { SelectboxContainerProps } from './SelectboxContainer';
13
13
  export { SelectboxItem };
14
14
  export interface SelectboxProps<T, Multiple extends boolean | undefined = undefined> extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'value' | 'onChange' | 'children'> {
15
+ /**
16
+ * Array of values
17
+ */
15
18
  readonly items: readonly T[];
16
19
  readonly value: Value<T, Multiple>;
17
20
  /**
@@ -72,12 +75,47 @@ export interface SelectboxProps<T, Multiple extends boolean | undefined = undefi
72
75
  * items render function
73
76
  */
74
77
  readonly children: Children<T>;
78
+ /**
79
+ * The function that will be called when an item is selected from the list
80
+ */
75
81
  readonly onChange?: OnChange<T, Multiple>;
82
+ /**
83
+ * A function that transforms the selected item into a string
84
+ * Example:
85
+ * ```tsx
86
+ * <Selectbox
87
+ * selectedItemToString={item => item.name} // item is {id: 1, name: 'Oleg'}
88
+ * ...
89
+ * >
90
+ * ...
91
+ * </Selectbox>
92
+ * ```
93
+ */
76
94
  readonly selectedItemToString: ItemToString<T, Multiple>;
95
+ /**
96
+ * A function that determines which of the elements is currently selected\
97
+ * Example:
98
+ * ```tsx
99
+ * <Selectbox
100
+ * getOptionSelected={({ item, value }) => item.id === value.id}
101
+ * >
102
+ * ...
103
+ * </Selectbox>
104
+ * ```
105
+ */
77
106
  readonly getOptionSelected?: GetOptionSelected<T>;
107
+ /**
108
+ * The function that will be called at the moment when you want to close the selectbox
109
+ */
78
110
  readonly onRequestClose?: OnRequestClose;
79
- readonly onInputChange?: React.ChangeEventHandler<HTMLInputElement>;
111
+ /**
112
+ * The function that will be called at the moment when you want to open the selectbox
113
+ */
80
114
  readonly onRequestOpen?: (event: React.KeyboardEvent<HTMLElement> | React.MouseEvent<HTMLElement> | React.FocusEvent<HTMLInputElement, Element> | React.ChangeEvent<HTMLInputElement>) => void;
115
+ /**
116
+ * Еhe label that will be shown if there are no selected items
117
+ */
118
+ readonly notSetLabel?: string;
81
119
  /**
82
120
  * Overridable components map
83
121
  */
@@ -29,7 +29,7 @@ const TextFieldErrorText_1 = __importDefault(require("../TextField/TextFieldErro
29
29
  const SelectboxButtonWrapper_1 = __importDefault(require("./SelectboxButtonWrapper"));
30
30
  const SelectboxContainer_1 = __importDefault(require("./SelectboxContainer"));
31
31
  const Selectbox = react_1.default.forwardRef((props, ref) => {
32
- const { items, value, multiple, isOpen = false, isLoading = false, anchorPos = 'auto-start-end', fullWidth = false, children, onChange, selectedItemToString, getOptionSelected, onRequestOpen = () => undefined, onRequestClose = () => undefined, overrides, id, label, onFocus, requiredAsterisk, error, errorText } = props, nativeButtonProps = __rest(props, ["items", "value", "multiple", "isOpen", "isLoading", "anchorPos", "fullWidth", "children", "onChange", "selectedItemToString", "getOptionSelected", "onRequestOpen", "onRequestClose", "overrides", "id", "label", "onFocus", "requiredAsterisk", "error", "errorText"]);
32
+ const { items, value, multiple, isOpen = false, isLoading = false, anchorPos = 'auto-start-end', fullWidth = false, children, onChange, selectedItemToString, getOptionSelected, onRequestOpen = () => undefined, onRequestClose = () => undefined, overrides, id, label, onFocus, requiredAsterisk, error, errorText, notSetLabel = 'Not set' } = props, nativeButtonProps = __rest(props, ["items", "value", "multiple", "isOpen", "isLoading", "anchorPos", "fullWidth", "children", "onChange", "selectedItemToString", "getOptionSelected", "onRequestOpen", "onRequestClose", "overrides", "id", "label", "onFocus", "requiredAsterisk", "error", "errorText", "notSetLabel"]);
33
33
  const menuRef = react_1.default.useRef(null);
34
34
  const overridesMap = react_1.default.useMemo(() => ({
35
35
  Button: (overrides === null || overrides === void 0 ? void 0 : overrides.Button) || SelectboxButton_1.default,
@@ -69,10 +69,10 @@ const Selectbox = react_1.default.forwardRef((props, ref) => {
69
69
  }, [onRequestClose, anchorElement]);
70
70
  const renderValueAsString = react_1.default.useCallback(() => {
71
71
  if ((!multiple && !value) || (multiple && value.length === 0)) {
72
- return 'Not set label';
72
+ return notSetLabel;
73
73
  }
74
74
  return selectedItemToString(value);
75
- }, [multiple, selectedItemToString, value]);
75
+ }, [multiple, selectedItemToString, value, notSetLabel]);
76
76
  const inputID = react_1.default.useMemo(() => {
77
77
  if (typeof id === 'string') {
78
78
  return id;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@via-profit/ui-kit",
3
- "version": "0.1.0-rc.79",
3
+ "version": "0.1.0-rc.80",
4
4
  "description": "UI Kit",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,4 +0,0 @@
1
- import React from 'react';
2
- export type CalendarBottomBarProps = React.HTMLAttributes<HTMLDivElement>;
3
- declare const _default: React.ForwardRefExoticComponent<CalendarBottomBarProps & React.RefAttributes<HTMLDivElement>>;
4
- export default _default;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- const react_1 = __importDefault(require("react"));
18
- const styled_1 = __importDefault(require("@emotion/styled"));
19
- const Container = styled_1.default.div `
20
- display: flex;
21
- justify-content: space-between;
22
- align-items: center;
23
- `;
24
- const CalendarBottomBar = (props, ref) => {
25
- const { children } = props, restProps = __rest(props, ["children"]);
26
- return (react_1.default.createElement(Container, Object.assign({}, restProps, { ref: ref }), children));
27
- };
28
- exports.default = react_1.default.forwardRef(CalendarBottomBar);
@@ -1,6 +0,0 @@
1
- import React from 'react';
2
- export interface CalendarMonthControlProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
- readonly displayIcon: 'prev' | 'next';
4
- }
5
- declare const _default: React.ForwardRefExoticComponent<CalendarMonthControlProps & React.RefAttributes<HTMLButtonElement>>;
6
- export default _default;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- const react_1 = __importDefault(require("react"));
18
- const styled_1 = __importDefault(require("@emotion/styled"));
19
- const react_2 = require("@emotion/react");
20
- const Button_1 = __importDefault(require("../Button"));
21
- const IconChevronLeft_1 = __importDefault(require("./IconChevronLeft"));
22
- const IconChevronRight_1 = __importDefault(require("./IconChevronRight"));
23
- const StyledButton = (0, styled_1.default)(Button_1.default) `
24
- color: ${({ theme }) => theme.color.accentSecondaryContrast.toString()};
25
- &:hover {
26
- color: ${({ theme }) => theme.color.accentSecondaryContrast.alpha(0.5).toString()};
27
- background-color: ${({ theme }) => theme.color.accentSecondary.lighten(10).toString()};
28
- }
29
- &:active {
30
- color: ${({ theme }) => theme.color.accentSecondaryContrast.alpha(0.9).toString()};
31
- }
32
- ${({ disabled }) => disabled &&
33
- (0, react_2.css) `
34
- opacity: 0.5;
35
- `};
36
- `;
37
- const CalendarMonthControl = (props, ref) => {
38
- const { displayIcon } = props, restProps = __rest(props, ["displayIcon"]);
39
- return (react_1.default.createElement(StyledButton, Object.assign({ variant: "plain", iconOnly: true, type: "button" }, restProps, { ref: ref }), displayIcon === 'next' ? react_1.default.createElement(IconChevronRight_1.default, null) : react_1.default.createElement(IconChevronLeft_1.default, null)));
40
- };
41
- exports.default = react_1.default.forwardRef(CalendarMonthControl);
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- declare const _default: React.ForwardRefExoticComponent<Omit<React.SVGProps<SVGSVGElement>, "ref"> & React.RefAttributes<SVGSVGElement>>;
3
- export default _default;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const react_1 = __importDefault(require("react"));
7
- const IconChevronLeft = (props, ref) => (react_1.default.createElement("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 512 512", width: "1em", height: "1em", ref: ref }, props),
8
- react_1.default.createElement("path", { fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 48, d: "M328 112 184 256l144 144" })));
9
- exports.default = react_1.default.forwardRef(IconChevronLeft);
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- declare const _default: React.ForwardRefExoticComponent<Omit<React.SVGProps<SVGSVGElement>, "ref"> & React.RefAttributes<SVGSVGElement>>;
3
- export default _default;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const react_1 = __importDefault(require("react"));
7
- const IconShow = (props, ref) => (react_1.default.createElement("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "1em", height: "1em", viewBox: "0 0 512 512" }, props, { ref: ref }),
8
- react_1.default.createElement("path", { d: "m105.79 160.82a24 24 0 0 0-10.76 6.2109 24 24 0 0 0 0 33.941l144 144a24.002 24.002 0 0 0 33.941 0l144-144a24 24 0 0 0 0-33.941 24 24 0 0 0-33.941 0l-127.03 127.03-127.03-127.03a24 24 0 0 0-23.182-6.2109z", fill: "currentColor" })));
9
- exports.default = react_1.default.forwardRef(IconShow);