@via-profit/ui-kit 0.1.0-rc.44 → 0.1.0-rc.45

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.
Files changed (41) hide show
  1. package/Autocomplete/AutocompleteContainer.d.ts +34 -6
  2. package/Autocomplete/AutocompleteContainer.js +24 -29
  3. package/Badge/BadgeBase.d.ts +54 -0
  4. package/Badge/BadgeBase.js +33 -0
  5. package/Badge/BadgeContainer.d.ts +14 -0
  6. package/Badge/BadgeContainer.js +42 -0
  7. package/Badge/BadgeDeleteButton.d.ts +10 -0
  8. package/Badge/BadgeDeleteButton.js +92 -0
  9. package/Badge/BadgeIconWrapper.d.ts +4 -0
  10. package/Badge/BadgeIconWrapper.js +29 -0
  11. package/Badge/BadgeOutlined.d.ts +5 -0
  12. package/Badge/BadgeOutlined.js +69 -0
  13. package/Badge/BadgeStandard.d.ts +5 -0
  14. package/Badge/BadgeStandard.js +89 -0
  15. package/Badge/BadgeTextWrapper.d.ts +4 -0
  16. package/Badge/BadgeTextWrapper.js +30 -0
  17. package/Badge/index.d.ts +22 -0
  18. package/Badge/index.js +27 -0
  19. package/Button/ButtonContainer.js +0 -1
  20. package/Button/ButtonPlain.js +2 -0
  21. package/Button/ButtonStandard.js +2 -0
  22. package/ClickOutside/index.d.ts +22 -0
  23. package/ClickOutside/index.js +41 -0
  24. package/Menu/MenuContainer.d.ts +48 -14
  25. package/Menu/MenuContainer.js +47 -115
  26. package/Menu/MenuList.js +4 -1
  27. package/Menu/context.d.ts +0 -1
  28. package/Menu/context.js +1 -2
  29. package/Menu/index.d.ts +2 -0
  30. package/Menu/index.js +2 -34
  31. package/PhoneField/templates.d.ts +2 -2
  32. package/PhoneField/templates.js +0 -1
  33. package/PhoneField/usePhoneUtils.js +1 -1
  34. package/Popper/PopperContainer.d.ts +7 -0
  35. package/Popper/PopperContainer.js +30 -0
  36. package/Popper/index.d.ts +22 -0
  37. package/Popper/index.js +267 -0
  38. package/Table/Table.js +0 -1
  39. package/ThemeProvider/createTheme.js +1 -1
  40. package/ThemeProvider/index.d.ts +0 -1
  41. package/package.json +1 -1
@@ -1,12 +1,14 @@
1
1
  import React from 'react';
2
2
  import { Value, OnRequestClose, GetOptionSelected } from '../Menu';
3
+ import { TextFieldProps } from '../TextField';
4
+ import type { AnchorPos } from '../Popper';
3
5
  import type { MenuItemCommonProps } from '../Menu/MenuItem';
4
- export type AutocompleteProps<T, Multiple extends boolean | undefined = undefined> = {
5
- readonly value: Value<T, Multiple> | null;
6
+ export interface AutocompleteProps<T, Multiple extends boolean | undefined = undefined> {
7
+ readonly items: readonly T[];
8
+ readonly value: Value<T, Multiple>;
6
9
  /**
7
10
  * Array of items. If will be array of objects or array of strings
8
11
  */
9
- readonly items: T[];
10
12
  readonly multiple?: Multiple;
11
13
  /**
12
14
  * Menu open state\
@@ -17,9 +19,35 @@ export type AutocompleteProps<T, Multiple extends boolean | undefined = undefine
17
19
  * Loading indicator visiblility\
18
20
  * If `true` then visible, otherwise - hidden
19
21
  */
22
+ /**
23
+ * Anchor position\
24
+ * \
25
+ * Default: `auto-start-end`
26
+ */
27
+ readonly anchorPos?: AnchorPos;
28
+ /**
29
+ * Text field loading state\
30
+ * If `true` then text field has been contained the loading indicator, otherwise - nop
31
+ */
20
32
  readonly isLoading?: boolean;
33
+ /**
34
+ * Should the autocomplete element be cleared when blur and if no element is selected
35
+ */
21
36
  readonly clearIfNotSelected?: boolean;
37
+ /**
38
+ * items render function
39
+ */
22
40
  readonly children: Children<T>;
41
+ /**
42
+ * Field placeholder
43
+ */
44
+ readonly placeholder?: string;
45
+ /**
46
+ * Field label text or element
47
+ */
48
+ readonly label?: TextFieldProps['label'];
49
+ readonly error?: TextFieldProps['error'];
50
+ readonly errorText?: TextFieldProps['errorText'];
23
51
  readonly filterItems?: FilterItems<T>;
24
52
  readonly onChange?: OnChange<T, Multiple>;
25
53
  readonly selectedItemToString: ItemToString<T, Multiple>;
@@ -27,14 +55,14 @@ export type AutocompleteProps<T, Multiple extends boolean | undefined = undefine
27
55
  readonly onRequestClose?: OnRequestClose;
28
56
  readonly onInputChange?: React.ChangeEventHandler<HTMLInputElement>;
29
57
  readonly onRequestOpen?: (event: React.KeyboardEvent<HTMLInputElement> | React.MouseEvent<HTMLInputElement> | React.FocusEvent<HTMLInputElement, Element>) => void;
30
- };
58
+ }
31
59
  export type Children<T> = (data: {
32
60
  item: T;
33
61
  index: number;
34
62
  inputValue: string;
35
63
  }, itemProps: MenuItemCommonProps) => React.ReactNode;
36
- export type ItemToString<T, Multiple extends boolean | undefined = undefined> = (item: Value<T, Multiple>) => string;
37
- export type OnChange<T, Multiple extends boolean | undefined = undefined> = (item: Value<T, Multiple> | null) => void;
64
+ export type ItemToString<T, Multiple extends boolean | undefined = undefined> = (item: Multiple extends undefined ? T : readonly T[]) => string;
65
+ export type OnChange<T, Multiple extends boolean | undefined = undefined> = (item: Value<T, Multiple>) => void;
38
66
  export type FilterItems<T> = (items: readonly T[], data: {
39
67
  readonly query: string;
40
68
  readonly inputValue: string;
@@ -34,7 +34,7 @@ const Spinner_1 = __importDefault(require("../LoadingIndicator/Spinner"));
34
34
  const IconClear_1 = __importDefault(require("./IconClear"));
35
35
  const context_1 = __importStar(require("./context"));
36
36
  const Autocomplete = react_1.default.forwardRef((props, ref) => {
37
- const { items, value, multiple, isOpen = false, isLoading = false, clearIfNotSelected = true, filterItems, children, onChange, selectedItemToString, onInputChange, getOptionSelected, onRequestOpen = () => undefined, onRequestClose = () => undefined, } = props;
37
+ const { items, value, multiple, isOpen = false, isLoading = false, clearIfNotSelected = true, anchorPos = 'auto-start-end', placeholder, label, error, errorText, filterItems, children, onChange, selectedItemToString, onInputChange, getOptionSelected, onRequestOpen = () => undefined, onRequestClose = () => undefined, } = props;
38
38
  const menuRef = react_1.default.useRef(null);
39
39
  const inputRef = react_1.default.useRef(null);
40
40
  const isFocusedRef = react_1.default.useRef(false);
@@ -42,7 +42,7 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
42
42
  const { currentOpen, filteredItems, inputValue, currentValue, anchorElement, currentLoading } = state;
43
43
  const clear = react_1.default.useCallback(() => {
44
44
  if (onChange) {
45
- onChange(null);
45
+ onChange((multiple ? [] : null));
46
46
  }
47
47
  dispatch((0, context_1.actionSetPartial)({
48
48
  filteredItems: items,
@@ -53,7 +53,7 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
53
53
  var _a;
54
54
  (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
55
55
  }, 15);
56
- }, [dispatch, onChange, items]);
56
+ }, [dispatch, onChange, items, multiple]);
57
57
  /**
58
58
  * API
59
59
  */
@@ -120,22 +120,14 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
120
120
  if (value === currentValue) {
121
121
  return;
122
122
  }
123
- if (multiple) {
124
- if (Array.isArray(value)) {
125
- dispatch((0, context_1.actionSetPartial)({
126
- currentValue: value,
127
- inputValue: value === null ? inputValue : selectedItemToString(value),
128
- }));
129
- }
130
- }
131
- if (!multiple) {
132
- if (!Array.isArray(value)) {
133
- dispatch((0, context_1.actionSetPartial)({
134
- currentValue: value,
135
- inputValue: value === null ? inputValue : selectedItemToString(value),
136
- }));
137
- }
138
- }
123
+ dispatch((0, context_1.actionSetPartial)({
124
+ currentValue: value,
125
+ inputValue: multiple
126
+ ? ''
127
+ : value === null
128
+ ? inputValue
129
+ : selectedItemToString(value),
130
+ }));
139
131
  }, [value, multiple, currentValue, inputValue, dispatch, selectedItemToString]);
140
132
  react_1.default.useEffect(() => {
141
133
  if (currentOpen && menuRef.current) {
@@ -152,7 +144,7 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
152
144
  dispatch((0, context_1.actionSetPartial)({ currentOpen: isOpen, currentLoading: isLoading, filteredItems: items }));
153
145
  }, [isOpen, isLoading, items, dispatch]);
154
146
  return (react_1.default.createElement("div", null,
155
- react_1.default.useMemo(() => (react_1.default.createElement(TextField_1.default, { endIcon: react_1.default.createElement(Button_1.default, { iconOnly: true, onClick: () => (currentLoading ? 'undefined' : clear()) }, currentLoading ? react_1.default.createElement(Spinner_1.default, null) : react_1.default.createElement(IconClear_1.default, null)), onKeyDown: inputKeydownEvent, ref: el => {
147
+ react_1.default.useMemo(() => (react_1.default.createElement(TextField_1.default, { placeholder: placeholder, label: label, error: error, errorText: errorText, endIcon: react_1.default.createElement(Button_1.default, { iconOnly: true, onClick: () => (currentLoading ? 'undefined' : clear()) }, currentLoading ? react_1.default.createElement(Spinner_1.default, null) : react_1.default.createElement(IconClear_1.default, null)), onKeyDown: inputKeydownEvent, ref: el => {
156
148
  if (anchorElement !== el) {
157
149
  dispatch((0, context_1.actionSetPartial)({ anchorElement: el }));
158
150
  }
@@ -160,7 +152,11 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
160
152
  isFocusedRef.current = false;
161
153
  if (clearIfNotSelected) {
162
154
  dispatch((0, context_1.actionSetPartial)({
163
- inputValue: value !== null ? selectedItemToString(value) : '',
155
+ inputValue: multiple
156
+ ? ''
157
+ : value !== null
158
+ ? selectedItemToString(value)
159
+ : '',
164
160
  }));
165
161
  }
166
162
  }, onFocus: event => {
@@ -184,6 +180,11 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
184
180
  filteredItems: newItems,
185
181
  }));
186
182
  } })), [
183
+ placeholder,
184
+ label,
185
+ multiple,
186
+ error,
187
+ errorText,
187
188
  currentLoading,
188
189
  inputKeydownEvent,
189
190
  inputValue,
@@ -198,15 +199,10 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
198
199
  filterItems,
199
200
  items,
200
201
  ]),
201
- react_1.default.useMemo(() => (react_1.default.createElement(Menu_1.default, { ref: menuRef, anchorPos: "left-bottom-right", multiple: multiple, items: filteredItems, value: currentValue, isOpen: currentOpen && filteredItems.length > 0, autofocus: false, anchorElement: anchorElement, closeOutsideClick: true, getOptionSelected: getOptionSelected, onSelectItem: item => {
202
+ react_1.default.useMemo(() => (react_1.default.createElement(Menu_1.default, { ref: menuRef, anchorPos: anchorPos, multiple: multiple, items: filteredItems, value: currentValue, isOpen: currentOpen && filteredItems.length > 0, autofocus: false, anchorElement: anchorElement, closeOutsideClick: true, getOptionSelected: getOptionSelected, onSelectItem: item => {
202
203
  if (typeof onChange === 'function') {
203
204
  onChange(item);
204
205
  }
205
- if (!multiple) {
206
- dispatch((0, context_1.actionSetPartial)({
207
- inputValue: selectedItemToString(item),
208
- }));
209
- }
210
206
  }, closeOnSelect: multiple ? false : true, onRequestClose: evt => {
211
207
  if ((evt === null || evt === void 0 ? void 0 : evt.target) !== anchorElement) {
212
208
  onRequestClose(evt);
@@ -218,12 +214,11 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
218
214
  filteredItems,
219
215
  inputValue,
220
216
  multiple,
217
+ anchorPos,
221
218
  children,
222
- dispatch,
223
219
  onRequestClose,
224
220
  onChange,
225
221
  getOptionSelected,
226
- selectedItemToString,
227
222
  ])));
228
223
  });
229
224
  Autocomplete.displayName = 'Autocomplete';
@@ -0,0 +1,54 @@
1
+ import React from 'react';
2
+ import { BadgeIconWrapperProps } from './BadgeIconWrapper';
3
+ import { BadgeTextWrapperProps } from './BadgeTextWrapper';
4
+ import { BadgeContainerProps } from './BadgeContainer';
5
+ import { BadgeDeleteButtonProps } from './BadgeDeleteButton';
6
+ type BadgeNativeProps = React.HTMLAttributes<HTMLSpanElement>;
7
+ export interface BadgeBaseProps extends Omit<BadgeNativeProps, 'color'> {
8
+ /**
9
+ * Icon or another JSX element placed before Badge label\
10
+ * Example:
11
+ * ```tsx
12
+ * <Badge startIcon={<MyIconElement />}>
13
+ * Label
14
+ * </Badge>
15
+ * ```
16
+ */
17
+ readonly startIcon?: JSX.Element;
18
+ /**
19
+ * Badge style variant\
20
+ * Allowed variants: `standard` or `outlined`\
21
+ * \
22
+ * **Default**: `standard`
23
+ */
24
+ readonly variant?: 'standard' | 'outlined';
25
+ /**
26
+ * You can pass the primary, default, secondary name of the colors or your specified color value
27
+ */
28
+ readonly color?: BadgeContainerProps['color'];
29
+ readonly onDelete?: React.MouseEventHandler<HTMLButtonElement>;
30
+ /**
31
+ * Overridable components map
32
+ */
33
+ readonly overrides?: BadgeBaseOverrides;
34
+ }
35
+ export interface BadgeBaseOverrides {
36
+ /**
37
+ * Element container
38
+ */
39
+ readonly Container?: React.ForwardRefExoticComponent<BadgeContainerProps & React.RefAttributes<HTMLSpanElement>>;
40
+ /**
41
+ * icon wrapper
42
+ */
43
+ readonly IconWrapper?: React.ForwardRefExoticComponent<BadgeIconWrapperProps & React.RefAttributes<HTMLSpanElement>>;
44
+ /**
45
+ * text wrapper
46
+ */
47
+ readonly TextWrapper?: React.ForwardRefExoticComponent<BadgeTextWrapperProps & React.RefAttributes<HTMLSpanElement>>;
48
+ /**
49
+ * Icon delete
50
+ */
51
+ readonly ButtonDelete?: React.ForwardRefExoticComponent<BadgeDeleteButtonProps & React.RefAttributes<HTMLButtonElement>>;
52
+ }
53
+ declare const _default: React.ForwardRefExoticComponent<BadgeBaseProps & React.RefAttributes<HTMLSpanElement>>;
54
+ export default _default;
@@ -0,0 +1,33 @@
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 BadgeIconWrapper_1 = __importDefault(require("./BadgeIconWrapper"));
19
+ const BadgeTextWrapper_1 = __importDefault(require("./BadgeTextWrapper"));
20
+ const BadgeContainer_1 = __importDefault(require("./BadgeContainer"));
21
+ const BadgeDeleteButton_1 = __importDefault(require("./BadgeDeleteButton"));
22
+ const BadgeBase = (props, ref) => {
23
+ const { children, startIcon, color, variant, overrides, onDelete } = props, nativeProps = __rest(props, ["children", "startIcon", "color", "variant", "overrides", "onDelete"]);
24
+ const overridesMap = react_1.default.useMemo(() => (Object.assign({ TextWrapper: BadgeTextWrapper_1.default,
25
+ IconWrapper: BadgeIconWrapper_1.default,
26
+ Container: BadgeContainer_1.default,
27
+ ButtonDelete: BadgeDeleteButton_1.default }, overrides)), [overrides]);
28
+ return (react_1.default.createElement(overridesMap.Container, Object.assign({}, nativeProps, { color: color, ref: ref }),
29
+ typeof startIcon !== 'undefined' && startIcon !== null && (react_1.default.createElement(overridesMap.IconWrapper, null, startIcon)),
30
+ react_1.default.createElement(overridesMap.TextWrapper, null, children),
31
+ typeof onDelete === 'function' && (react_1.default.createElement(overridesMap.ButtonDelete, { variant: variant, onClick: onDelete, color: color }))));
32
+ };
33
+ exports.default = react_1.default.forwardRef(BadgeBase);
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ export type BadgeContainerProps = React.HTMLAttributes<HTMLSpanElement> & {
3
+ /**
4
+ * You can pass the primary, default, secondary name of the colors or your specified color value
5
+ */
6
+ readonly color?: 'default' | 'primary' | 'secondary' | string;
7
+ };
8
+ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLSpanElement> & {
9
+ /**
10
+ * You can pass the primary, default, secondary name of the colors or your specified color value
11
+ */
12
+ readonly color?: string | undefined;
13
+ } & React.RefAttributes<HTMLSpanElement>>;
14
+ export default _default;
@@ -0,0 +1,42 @@
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 StyledBadge = styled_1.default.span `
20
+ border-radius: ${({ theme }) => theme.shape.radiusFactor * 2.5}em;
21
+ font-size: 1em;
22
+ border-width: 0;
23
+ outline-style: solid;
24
+ outline-color: transparent;
25
+ outline-width: 0.14em;
26
+ transition: all 180ms ease-out 0s;
27
+ background: none;
28
+ display: inline-flex;
29
+ align-items: center;
30
+ color: ${({ color, theme }) => {
31
+ switch (true) {
32
+ case typeof color === 'undefined':
33
+ default:
34
+ return theme.color.textPrimary.toString();
35
+ }
36
+ }};
37
+ `;
38
+ const BadgeContainer = (props, ref) => {
39
+ const { children } = props, nativeProps = __rest(props, ["children"]);
40
+ return (react_1.default.createElement(StyledBadge, Object.assign({}, nativeProps, { ref: ref }), children));
41
+ };
42
+ exports.default = react_1.default.forwardRef(BadgeContainer);
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ export type BadgeDeleteButtonProps = Omit<React.HTMLAttributes<HTMLButtonElement>, 'children'> & {
3
+ readonly color?: 'primary' | 'secondaary' | 'default' | string;
4
+ readonly variant?: 'standard' | 'outlined';
5
+ };
6
+ declare const _default: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLButtonElement>, "children"> & {
7
+ readonly color?: string | undefined;
8
+ readonly variant?: "standard" | "outlined" | undefined;
9
+ } & React.RefAttributes<HTMLButtonElement>>;
10
+ export default _default;
@@ -0,0 +1,92 @@
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 ButtonBase_1 = __importDefault(require("../Button/ButtonBase"));
21
+ const Color_1 = __importDefault(require("../Color"));
22
+ const StyledButton = (0, styled_1.default)(ButtonBase_1.default) `
23
+ display: flex;
24
+ padding: 0.3em;
25
+ font-size: 1em;
26
+ align-items: center;
27
+ justify-content: center;
28
+ margin-left: 0.1em;
29
+ margin-right: 0.14em;
30
+ background-color: ${({ $background }) => $background.toString()};
31
+ color: ${({ $color }) => $color.toString()};
32
+ position: relative;
33
+ `;
34
+ const BadgeDeleteButton = (props, ref) => {
35
+ const { color = 'default', variant = 'standard' } = props, nativeProps = __rest(props, ["color", "variant"]);
36
+ const theme = (0, react_2.useTheme)();
37
+ const { $color, $background } = react_1.default.useMemo(() => {
38
+ switch (true) {
39
+ case variant === 'standard' && color === 'default':
40
+ return {
41
+ $color: theme.color.textPrimary,
42
+ $background: theme.color.surface.darken(20),
43
+ };
44
+ case variant === 'standard' && color === 'primary':
45
+ return {
46
+ $color: theme.color.accentPrimaryContrast,
47
+ $background: theme.color.accentPrimary,
48
+ };
49
+ case variant === 'standard' && color === 'secondary':
50
+ return {
51
+ $color: theme.color.accentSecondaryContrast,
52
+ $background: theme.color.accentSecondary,
53
+ };
54
+ case variant === 'outlined' && color === 'default':
55
+ return {
56
+ $color: theme.color.textPrimary,
57
+ $background: theme.color.surface,
58
+ };
59
+ case variant === 'outlined' && color === 'primary':
60
+ return {
61
+ $color: theme.color.accentPrimary.darken(10),
62
+ $background: new Color_1.default('rgba(0,0,0,0)'),
63
+ };
64
+ case variant === 'outlined' && color === 'secondary':
65
+ return {
66
+ $color: theme.color.accentSecondary.darken(10),
67
+ $background: new Color_1.default('rgba(0,0,0,0)'),
68
+ };
69
+ case variant === 'outlined' && typeof color === 'string':
70
+ return {
71
+ $color: new Color_1.default(color),
72
+ $background: new Color_1.default(color).alpha(0),
73
+ };
74
+ case variant === 'standard' && typeof color === 'string':
75
+ return {
76
+ $color: new Color_1.default(color).contrast(theme.color.textPrimary) > 5
77
+ ? theme.color.textPrimary
78
+ : theme.color.surface,
79
+ $background: new Color_1.default(color),
80
+ };
81
+ default:
82
+ return {
83
+ $color: theme.color.textPrimary,
84
+ $background: theme.color.textPrimary,
85
+ };
86
+ }
87
+ }, [color, variant, theme.color]);
88
+ return (react_1.default.createElement(StyledButton, Object.assign({}, nativeProps, { "$color": $color, "$background": $background, ref: ref }),
89
+ react_1.default.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "1em", height: "1em", viewBox: "0 0 512 512" },
90
+ react_1.default.createElement("path", { d: "m256 0c-141.11 0-256 114.89-256 256s114.89 256 256 256 256-114.89 256-256-114.89-256-256-256zm0 39.385c119.81 0 216.62 96.805 216.62 216.62s-96.805 216.62-216.62 216.62-216.62-96.805-216.62-216.62 96.805-216.62 216.62-216.62zm-78.769 118.15a19.692 19.692 0 0 0-5.0961 0.67068 19.692 19.692 0 0 0-8.8293 5.0961 19.692 19.692 0 0 0 0 27.851l64.844 64.844-64.844 64.844a19.692 19.692 0 0 0 0 27.851 19.692 19.692 0 0 0 27.851 0l64.844-64.844 64.844 64.844a19.692 19.692 0 0 0 27.851 0 19.692 19.692 0 0 0 0-27.851l-64.844-64.844 64.844-64.844a19.692 19.692 0 0 0 0-27.851 19.692 19.692 0 0 0-27.851 0l-64.844 64.844-64.844-64.844a19.692 19.692 0 0 0-13.925-5.7669z", fill: "currentColor" }))));
91
+ };
92
+ exports.default = react_1.default.forwardRef(BadgeDeleteButton);
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export type BadgeIconWrapperProps = React.HTMLAttributes<HTMLSpanElement>;
3
+ declare const _default: React.ForwardRefExoticComponent<BadgeIconWrapperProps & React.RefAttributes<HTMLSpanElement>>;
4
+ export default _default;
@@ -0,0 +1,29 @@
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 Wrapper = styled_1.default.span `
20
+ display: flex;
21
+ padding: 0.3em 0 0.3em 0.3em;
22
+ align-items: center;
23
+ justify-content: center;
24
+ `;
25
+ const BadgeIconWrapper = (props, ref) => {
26
+ const { children } = props, nativeProps = __rest(props, ["children"]);
27
+ return (react_1.default.createElement(Wrapper, Object.assign({}, nativeProps, { ref: ref }), children));
28
+ };
29
+ exports.default = react_1.default.forwardRef(BadgeIconWrapper);
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { BadgeBaseProps } from './BadgeBase';
3
+ export type BadgeOutlinedProps = BadgeBaseProps;
4
+ declare const _default: React.ForwardRefExoticComponent<BadgeBaseProps & React.RefAttributes<HTMLSpanElement>>;
5
+ export default _default;
@@ -0,0 +1,69 @@
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 Color_1 = __importDefault(require("../Color"));
21
+ const BadgeBase_1 = __importDefault(require("./BadgeBase"));
22
+ const StyledOutlinedBadge = (0, styled_1.default)(BadgeBase_1.default) `
23
+ color: ${({ $color }) => $color.darken(30).toString()};
24
+ border-color: ${({ $color }) => $color.toString()};
25
+ background-color: transparent;
26
+ border-style: solid;
27
+ border-width: 0.14em;
28
+ &:hover {
29
+ background-color: ${({ $color }) => $color.darken(20).alpha(0.1).toString()};
30
+ }
31
+ &:focus-visible {
32
+ outline-style: solid;
33
+ outline-width: 0.14em;
34
+ outline-color: ${({ $color, theme }) => $color.rgbString() === theme.color.accentPrimary.rgbString()
35
+ ? theme.color.textPrimary.toString()
36
+ : theme.color.accentPrimary.toString()};
37
+ }
38
+ `;
39
+ const BadgeOutlined = (props, ref) => {
40
+ const { children, color } = props, restProps = __rest(props, ["children", "color"]);
41
+ const theme = (0, react_2.useTheme)();
42
+ const $color = react_1.default.useMemo(() => {
43
+ switch (true) {
44
+ case color === 'primary':
45
+ return theme.color.accentPrimary;
46
+ case color === 'secondary':
47
+ return theme.color.accentSecondary;
48
+ case typeof color === 'undefined':
49
+ case color === 'default':
50
+ return theme.color.textPrimary.lighten(30);
51
+ case typeof color === 'string': {
52
+ let c = theme.color.textPrimary;
53
+ try {
54
+ if (color) {
55
+ c = new Color_1.default(color);
56
+ }
57
+ }
58
+ catch (err) {
59
+ console.error(`invalid color value «${color}»`);
60
+ }
61
+ return c;
62
+ }
63
+ default:
64
+ return theme.color.textPrimary;
65
+ }
66
+ }, [color, theme.color]);
67
+ return (react_1.default.createElement(StyledOutlinedBadge, Object.assign({ "$color": $color, color: color, variant: "outlined" }, restProps, { ref: ref }), children));
68
+ };
69
+ exports.default = react_1.default.forwardRef(BadgeOutlined);
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { BadgeBaseProps } from './BadgeBase';
3
+ export type BadgeStandardProps = BadgeBaseProps;
4
+ declare const _default: React.ForwardRefExoticComponent<BadgeBaseProps & React.RefAttributes<HTMLSpanElement>>;
5
+ export default _default;
@@ -0,0 +1,89 @@
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 Color_1 = __importDefault(require("../Color"));
21
+ const BadgeBase_1 = __importDefault(require("./BadgeBase"));
22
+ const StyledStandardBadge = (0, styled_1.default)(BadgeBase_1.default) `
23
+ color: ${({ $color }) => $color.toString()};
24
+ background-color: ${({ $background }) => $background.toString()};
25
+ ${({ $background }) => {
26
+ switch (true) {
27
+ case $background.luminance() > 0.49:
28
+ return $background.darken(40).alpha(0.8).toString();
29
+ default:
30
+ return $background.darken(20).alpha(0.5).toString();
31
+ }
32
+ }};
33
+ &:hover {
34
+ background-color: ${({ $background }) => $background.darken(30).toString()};
35
+ }
36
+ &:focus-visible {
37
+ outline-color: ${({ theme, $background }) => $background.rgbString() === theme.color.accentPrimary.rgbString()
38
+ ? theme.color.textPrimary.toString()
39
+ : theme.color.accentPrimary.toString()};
40
+ }
41
+ `;
42
+ const BadgeStandard = (props, ref) => {
43
+ const { children, color } = props, restProps = __rest(props, ["children", "color"]);
44
+ const theme = (0, react_2.useTheme)();
45
+ const { $background, $color } = react_1.default.useMemo(() => {
46
+ switch (true) {
47
+ case color === 'primary':
48
+ return {
49
+ $color: theme.color.accentPrimaryContrast,
50
+ $background: theme.color.accentPrimary,
51
+ };
52
+ case color === 'secondary':
53
+ return {
54
+ $color: theme.color.accentSecondaryContrast,
55
+ $background: theme.color.accentSecondary,
56
+ };
57
+ case typeof color === 'undefined':
58
+ case color === 'default':
59
+ return {
60
+ $background: theme.color.surface.darken(10),
61
+ $color: theme.color.textPrimary,
62
+ };
63
+ case typeof color === 'string': {
64
+ let $background = theme.color.surface;
65
+ try {
66
+ if (color) {
67
+ $background = new Color_1.default(color);
68
+ }
69
+ }
70
+ catch (err) {
71
+ console.error(`invalid color value «${color}»`);
72
+ }
73
+ return {
74
+ $background,
75
+ $color: $background.contrast(theme.color.textPrimary) > 5
76
+ ? theme.color.textPrimary
77
+ : theme.color.surface,
78
+ };
79
+ }
80
+ default:
81
+ return {
82
+ $background: theme.color.surface,
83
+ $color: theme.color.textPrimary,
84
+ };
85
+ }
86
+ }, [color, theme.color]);
87
+ return (react_1.default.createElement(StyledStandardBadge, Object.assign({ variant: "standard", "$color": $color, "$background": $background, color: color }, restProps, { ref: ref }), children));
88
+ };
89
+ exports.default = react_1.default.forwardRef(BadgeStandard);
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export type BadgeTextWrapperProps = React.HTMLAttributes<HTMLSpanElement>;
3
+ declare const _default: React.ForwardRefExoticComponent<BadgeTextWrapperProps & React.RefAttributes<HTMLSpanElement>>;
4
+ export default _default;