@primer/components 0.0.0-2021816151443 → 0.0.0-2021816212749

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 (112) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/dist/browser.esm.js +667 -621
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +301 -255
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList/Item.js +3 -3
  7. package/lib/AnchoredOverlay/AnchoredOverlay.js +2 -2
  8. package/lib/Avatar.d.ts +4 -0
  9. package/lib/Dialog/Dialog.js +4 -4
  10. package/lib/FilteredActionList/FilteredActionList.js +3 -3
  11. package/lib/Overlay.d.ts +0 -1
  12. package/lib/Overlay.js +5 -10
  13. package/lib/SelectMenu/SelectMenu.d.ts +11 -327
  14. package/lib/SelectMenu/SelectMenuFilter.d.ts +1 -1
  15. package/lib/TextInput.d.ts +6 -6
  16. package/lib/TextInput.js +21 -16
  17. package/lib/Timeline.js +12 -15
  18. package/lib/hooks/useOverlay.d.ts +1 -2
  19. package/lib/hooks/useOverlay.js +6 -11
  20. package/lib/index.d.ts +1 -0
  21. package/lib/index.js +14 -0
  22. package/lib/theme-preval.js +1705 -1957
  23. package/lib/utils/ssr.d.ts +1 -0
  24. package/lib/utils/ssr.js +19 -0
  25. package/lib/utils/testing.d.ts +2431 -2929
  26. package/lib/utils/uniqueId.js +1 -0
  27. package/lib-esm/ActionList/Item.js +4 -4
  28. package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +3 -3
  29. package/lib-esm/Avatar.d.ts +4 -0
  30. package/lib-esm/Dialog/Dialog.js +3 -3
  31. package/lib-esm/FilteredActionList/FilteredActionList.js +3 -3
  32. package/lib-esm/Overlay.d.ts +0 -1
  33. package/lib-esm/Overlay.js +5 -8
  34. package/lib-esm/SelectMenu/SelectMenu.d.ts +11 -327
  35. package/lib-esm/SelectMenu/SelectMenuFilter.d.ts +1 -1
  36. package/lib-esm/TextInput.d.ts +6 -6
  37. package/lib-esm/TextInput.js +22 -16
  38. package/lib-esm/Timeline.js +8 -13
  39. package/lib-esm/hooks/useOverlay.d.ts +1 -2
  40. package/lib-esm/hooks/useOverlay.js +6 -11
  41. package/lib-esm/index.d.ts +1 -0
  42. package/lib-esm/index.js +2 -1
  43. package/lib-esm/theme-preval.js +1705 -1957
  44. package/lib-esm/utils/ssr.d.ts +1 -0
  45. package/lib-esm/utils/ssr.js +1 -0
  46. package/lib-esm/utils/testing.d.ts +2431 -2929
  47. package/lib-esm/utils/uniqueId.js +1 -0
  48. package/package.json +5 -7
  49. package/lib/Autocomplete/Autocomplete.d.ts +0 -8
  50. package/lib/Autocomplete/Autocomplete.js +0 -49
  51. package/lib/Autocomplete/AutocompleteContext.d.ts +0 -13
  52. package/lib/Autocomplete/AutocompleteContext.js +0 -11
  53. package/lib/Autocomplete/AutocompleteInput.d.ts +0 -7
  54. package/lib/Autocomplete/AutocompleteInput.js +0 -78
  55. package/lib/Autocomplete/AutocompleteMenu.d.ts +0 -19
  56. package/lib/Autocomplete/AutocompleteMenu.js +0 -226
  57. package/lib/Badge/Badge.d.ts +0 -8
  58. package/lib/Badge/Badge.js +0 -59
  59. package/lib/Badge/BadgeState.d.ts +0 -13
  60. package/lib/Badge/BadgeState.js +0 -51
  61. package/lib/Badge/_badgeStyleUtils.d.ts +0 -3
  62. package/lib/Badge/_badgeStyleUtils.js +0 -39
  63. package/lib/TextInputTokens.d.ts +0 -32
  64. package/lib/TextInputTokens.js +0 -225
  65. package/lib/TextInputWithTokens.d.ts +0 -41
  66. package/lib/TextInputWithTokens.js +0 -396
  67. package/lib/Token/Token.d.ts +0 -7
  68. package/lib/Token/Token.js +0 -66
  69. package/lib/Token/TokenBase.d.ts +0 -16
  70. package/lib/Token/TokenBase.js +0 -76
  71. package/lib/Token/TokenLabel.d.ts +0 -8
  72. package/lib/Token/TokenLabel.js +0 -116
  73. package/lib/Token/TokenProfile.d.ts +0 -7
  74. package/lib/Token/TokenProfile.js +0 -45
  75. package/lib/Token/_AddTokenButton.d.ts +0 -3
  76. package/lib/Token/_AddTokenButton.js +0 -42
  77. package/lib/Token/_RemoveTokenButton.d.ts +0 -3
  78. package/lib/Token/_RemoveTokenButton.js +0 -42
  79. package/lib/Token/_tokenButtonUtils.d.ts +0 -8
  80. package/lib/Token/_tokenButtonUtils.js +0 -42
  81. package/lib-esm/Autocomplete/Autocomplete.d.ts +0 -8
  82. package/lib-esm/Autocomplete/Autocomplete.js +0 -36
  83. package/lib-esm/Autocomplete/AutocompleteContext.d.ts +0 -13
  84. package/lib-esm/Autocomplete/AutocompleteContext.js +0 -2
  85. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +0 -7
  86. package/lib-esm/Autocomplete/AutocompleteInput.js +0 -59
  87. package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +0 -19
  88. package/lib-esm/Autocomplete/AutocompleteMenu.js +0 -203
  89. package/lib-esm/Badge/Badge.d.ts +0 -8
  90. package/lib-esm/Badge/Badge.js +0 -44
  91. package/lib-esm/Badge/BadgeState.d.ts +0 -13
  92. package/lib-esm/Badge/BadgeState.js +0 -40
  93. package/lib-esm/Badge/_badgeStyleUtils.d.ts +0 -3
  94. package/lib-esm/Badge/_badgeStyleUtils.js +0 -29
  95. package/lib-esm/TextInputTokens.d.ts +0 -32
  96. package/lib-esm/TextInputTokens.js +0 -195
  97. package/lib-esm/TextInputWithTokens.d.ts +0 -41
  98. package/lib-esm/TextInputWithTokens.js +0 -361
  99. package/lib-esm/Token/Token.d.ts +0 -7
  100. package/lib-esm/Token/Token.js +0 -46
  101. package/lib-esm/Token/TokenBase.d.ts +0 -16
  102. package/lib-esm/Token/TokenBase.js +0 -56
  103. package/lib-esm/Token/TokenLabel.d.ts +0 -8
  104. package/lib-esm/Token/TokenLabel.js +0 -100
  105. package/lib-esm/Token/TokenProfile.d.ts +0 -7
  106. package/lib-esm/Token/TokenProfile.js +0 -28
  107. package/lib-esm/Token/_AddTokenButton.d.ts +0 -3
  108. package/lib-esm/Token/_AddTokenButton.js +0 -27
  109. package/lib-esm/Token/_RemoveTokenButton.d.ts +0 -3
  110. package/lib-esm/Token/_RemoveTokenButton.js +0 -27
  111. package/lib-esm/Token/_tokenButtonUtils.d.ts +0 -8
  112. package/lib-esm/Token/_tokenButtonUtils.js +0 -26
@@ -1,13 +0,0 @@
1
- /// <reference types="react" />
2
- import { ItemInput } from '../ActionList/List';
3
- export declare const AutocompleteContext: import("react").Context<{
4
- activeDescendantRef?: import("react").MutableRefObject<HTMLElement | null> | undefined;
5
- autocompleteSuggestion?: string | undefined;
6
- filterFn?: ((item: ItemInput, i: number) => boolean) | undefined;
7
- inputRef?: import("react").MutableRefObject<HTMLInputElement | null> | undefined;
8
- inputValue?: string | undefined;
9
- showMenu?: boolean | undefined;
10
- setAutocompleteSuggestion?: import("react").Dispatch<import("react").SetStateAction<string>> | undefined;
11
- setShowMenu?: import("react").Dispatch<import("react").SetStateAction<boolean>> | undefined;
12
- setInputValue?: import("react").Dispatch<import("react").SetStateAction<string>> | undefined;
13
- }>;
@@ -1,2 +0,0 @@
1
- import { createContext } from 'react';
2
- export const AutocompleteContext = /*#__PURE__*/createContext({});
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- import type * as Polymorphic from "@radix-ui/react-polymorphic";
3
- interface Props {
4
- as?: React.ComponentType<any>;
5
- }
6
- declare const AutocompleteInput: Polymorphic.ForwardRefComponent<"input", Props>;
7
- export default AutocompleteInput;
@@ -1,59 +0,0 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- import React, { useCallback, useContext } from 'react';
4
- import { AutocompleteContext } from './AutocompleteContext';
5
- import TextInput from '../TextInput';
6
- import { useCombinedRefs } from '../hooks/useCombinedRefs';
7
- const AutocompleteInput = /*#__PURE__*/React.forwardRef(({
8
- as: Component = TextInput,
9
- onFocus,
10
- onChange,
11
- onKeyDown,
12
- onKeyPress,
13
- ...props
14
- }, forwardedRef) => {
15
- const {
16
- activeDescendantRef,
17
- autocompleteSuggestion,
18
- inputRef,
19
- setInputValue,
20
- setShowMenu
21
- } = useContext(AutocompleteContext);
22
- const combinedInputRef = useCombinedRefs(inputRef, forwardedRef);
23
-
24
- const handleInputFocus = () => {
25
- if (setShowMenu) {
26
- setShowMenu(true);
27
- }
28
- };
29
-
30
- const handleInputChange = e => {
31
- if (setInputValue) {
32
- setInputValue(e.currentTarget.value);
33
- }
34
- };
35
-
36
- const handleInputKeyDown = e => {
37
- if (setInputValue && e.key === 'ArrowRight' && autocompleteSuggestion) {
38
- setInputValue(autocompleteSuggestion);
39
- }
40
- };
41
-
42
- const onInputKeyPress = useCallback(event => {
43
- if (activeDescendantRef && event.key === 'Enter' && activeDescendantRef.current) {
44
- event.preventDefault();
45
- event.nativeEvent.stopImmediatePropagation(); // Forward Enter key press to active descendant so that item gets activated
46
-
47
- const activeDescendantEvent = new KeyboardEvent(event.type, event.nativeEvent);
48
- activeDescendantRef.current.dispatchEvent(activeDescendantEvent);
49
- }
50
- }, [activeDescendantRef]);
51
- return /*#__PURE__*/React.createElement(Component, _extends({
52
- onFocus: handleInputFocus,
53
- onChange: handleInputChange,
54
- onKeyDown: handleInputKeyDown,
55
- onKeyPress: onInputKeyPress,
56
- ref: combinedInputRef
57
- }, props));
58
- });
59
- export default AutocompleteInput;
@@ -1,19 +0,0 @@
1
- import React from 'react';
2
- import { ItemProps } from '../ActionList';
3
- import { ItemInput } from '../ActionList/List';
4
- import { ComponentProps } from '../utils/types';
5
- declare type AutocompleteMenuInternalProps = {
6
- selectableItems: ItemInput[];
7
- selectedItemIds: Array<string | number>;
8
- selectedSortFn?: (itemIdA: string | number, itemIdB: string | number) => number;
9
- onItemSelect: NonNullable<ItemProps['onAction']>;
10
- onItemDeselect: NonNullable<ItemProps['onAction']>;
11
- emptyStateText?: React.ReactNode | false;
12
- addNewItem?: Omit<ItemInput, 'onAction'>;
13
- onCloseOptionsList?: () => void;
14
- maxHeight?: React.CSSProperties['maxHeight'];
15
- loading?: boolean;
16
- };
17
- declare const AutocompleteMenu: React.ForwardRefExoticComponent<AutocompleteMenuInternalProps & React.RefAttributes<HTMLInputElement>>;
18
- export declare type AutocompleteMenuProps = ComponentProps<typeof AutocompleteMenu>;
19
- export default AutocompleteMenu;
@@ -1,203 +0,0 @@
1
- import React, { useContext, useEffect, useRef, useState } from 'react';
2
- import { ActionList } from '../ActionList';
3
- import { useAnchoredPosition } from '../hooks';
4
- import { useFocusZone } from '../hooks/useFocusZone';
5
- import Overlay from '../Overlay';
6
- import { Box, Spinner } from '../';
7
- import { registerPortalRoot } from '../Portal';
8
- import { AutocompleteContext } from './AutocompleteContext';
9
- const DROPDOWN_PORTAL_CONTAINER_NAME = '__listcontainerportal__';
10
-
11
- const getDefaultSortFn = isItemSelectedFn => (itemIdA, itemIdB) => isItemSelectedFn(itemIdA) === isItemSelectedFn(itemIdB) ? 0 : isItemSelectedFn(itemIdA) ? -1 : 1;
12
-
13
- function scrollIntoViewingArea(child, container, margin = 8, behavior = 'smooth') {
14
- const {
15
- top: childTop,
16
- bottom: childBottom
17
- } = child.getBoundingClientRect();
18
- const {
19
- top: containerTop,
20
- bottom: containerBottom
21
- } = container.getBoundingClientRect();
22
- const isChildTopAboveViewingArea = childTop < containerTop + margin;
23
- const isChildBottomBelowViewingArea = childBottom > containerBottom - margin;
24
-
25
- if (isChildTopAboveViewingArea) {
26
- const scrollHeightToChildTop = childTop - containerTop + container.scrollTop;
27
- container.scrollTo({
28
- behavior,
29
- top: scrollHeightToChildTop - margin
30
- });
31
- } else if (isChildBottomBelowViewingArea) {
32
- const scrollHeightToChildBottom = childBottom - containerBottom + container.scrollTop;
33
- container.scrollTo({
34
- behavior,
35
- top: scrollHeightToChildBottom + margin
36
- });
37
- } // either completely in view or outside viewing area on both ends, don't scroll
38
-
39
- }
40
-
41
- // TODO:
42
- // insteaad of using `forwardRef`, just use a regular Functional Component
43
- // get rid of unused props
44
- const AutocompleteMenu = /*#__PURE__*/React.forwardRef(({
45
- selectableItems,
46
- selectedItemIds,
47
- selectedSortFn,
48
- onItemSelect,
49
- onItemDeselect,
50
- emptyStateText,
51
- addNewItem,
52
- onCloseOptionsList,
53
- loading
54
- }, ref) => {
55
- const {
56
- activeDescendantRef,
57
- filterFn,
58
- inputRef,
59
- inputValue,
60
- showMenu,
61
- setAutocompleteSuggestion,
62
- setShowMenu,
63
- setInputValue
64
- } = useContext(AutocompleteContext);
65
- const listContainerRef = useRef(null);
66
- const scrollContainerRef = useRef(null);
67
- const [highlightedItem, setHighlightedItem] = useState(); // TODO: clean up this mess by making id required on ItemProps
68
-
69
- const [sortedItemIds, setSortedItemIds] = useState(selectableItems.map(({
70
- id
71
- }) => id || id === 0 ? id : ''));
72
- const {
73
- floatingElementRef,
74
- position
75
- } = useAnchoredPosition({
76
- side: 'outside-bottom',
77
- align: 'start',
78
- anchorElementRef: inputRef
79
- }, [showMenu, selectedItemIds]); // TODO: replace this with the fn from the AutocompleteContext
80
-
81
- const closeOptionList = () => {
82
- if (setShowMenu) {
83
- setShowMenu(false);
84
- }
85
-
86
- if (onCloseOptionsList) {
87
- onCloseOptionsList();
88
- }
89
- };
90
-
91
- const isItemSelected = itemId => {
92
- var _selectableItems$find;
93
-
94
- return ((_selectableItems$find = selectableItems.find(selectableItem => selectableItem.id === itemId)) === null || _selectableItems$find === void 0 ? void 0 : _selectableItems$find.selected) || selectedItemIds.includes(itemId);
95
- };
96
-
97
- const itemsToRender = [// selectable tokens
98
- ...selectableItems.map(selectableItem => {
99
- return { ...selectableItem,
100
- //TODO: just make `id` required
101
- selected: isItemSelected(selectableItem.id),
102
- onAction: (item, e) => {
103
- if (!item.selected) {
104
- onItemSelect(item, e);
105
-
106
- if (setInputValue) {
107
- setInputValue('');
108
- }
109
-
110
- if (setAutocompleteSuggestion) {
111
- setAutocompleteSuggestion('');
112
- }
113
- } else {
114
- onItemDeselect(item, e);
115
- }
116
- }
117
- };
118
- }), // menu item used for creating a token from whatever is in the text input
119
- ...(addNewItem ? [{ ...addNewItem,
120
- onAction: (_item, e) => {
121
- onItemSelect({
122
- text: inputValue,
123
- id: `randomlyGeneratedId-${inputValue}`
124
- }, e);
125
- }
126
- }] : [])];
127
- useFocusZone({
128
- containerRef: listContainerRef,
129
- focusOutBehavior: 'wrap',
130
- focusableElementFilter: element => {
131
- return !(element instanceof HTMLInputElement);
132
- },
133
- activeDescendantFocus: inputRef,
134
- onActiveDescendantChanged: (current, _previous, directlyActivated) => {
135
- if (activeDescendantRef && current) {
136
- activeDescendantRef.current = current;
137
- }
138
-
139
- const selectedItem = itemsToRender.find(item => {
140
- var _item$id;
141
-
142
- return ((_item$id = item.id) === null || _item$id === void 0 ? void 0 : _item$id.toString()) === (current === null || current === void 0 ? void 0 : current.dataset.id);
143
- });
144
- setHighlightedItem(selectedItem);
145
-
146
- if (current && scrollContainerRef.current && directlyActivated) {
147
- scrollIntoViewingArea(current, scrollContainerRef.current);
148
- }
149
- }
150
- });
151
- useEffect(() => {
152
- var _highlightedItem$text;
153
-
154
- if (!setAutocompleteSuggestion) {
155
- return;
156
- }
157
-
158
- if (inputValue && highlightedItem !== null && highlightedItem !== void 0 && (_highlightedItem$text = highlightedItem.text) !== null && _highlightedItem$text !== void 0 && _highlightedItem$text.startsWith(inputValue)) {
159
- setAutocompleteSuggestion(highlightedItem.text);
160
- } else {
161
- setAutocompleteSuggestion('');
162
- }
163
- }, [highlightedItem, inputValue]);
164
- useEffect(() => {
165
- setSortedItemIds([...sortedItemIds].sort(selectedSortFn ? selectedSortFn : getDefaultSortFn(isItemSelected)));
166
- }, [showMenu]);
167
-
168
- if (listContainerRef.current) {
169
- registerPortalRoot(listContainerRef.current, DROPDOWN_PORTAL_CONTAINER_NAME);
170
- }
171
-
172
- const itemSortOrderData = sortedItemIds.reduce((acc, curr, i) => {
173
- acc[curr] = i;
174
- return acc;
175
- }, {});
176
- return /*#__PURE__*/React.createElement("div", {
177
- ref: listContainerRef
178
- }, showMenu && emptyStateText ? /*#__PURE__*/React.createElement(Overlay, {
179
- returnFocusRef: inputRef,
180
- portalContainerName: DROPDOWN_PORTAL_CONTAINER_NAME,
181
- preventFocusOnOpen: true,
182
- onClickOutside: closeOptionList,
183
- onEscape: closeOptionList,
184
- ref: floatingElementRef,
185
- top: position === null || position === void 0 ? void 0 : position.top,
186
- left: position === null || position === void 0 ? void 0 : position.left
187
- }, loading ? /*#__PURE__*/React.createElement(Box, {
188
- p: 3,
189
- display: "flex",
190
- justifyContent: "center"
191
- }, /*#__PURE__*/React.createElement(Spinner, null)) : /*#__PURE__*/React.createElement(React.Fragment, null, itemsToRender.length ? /*#__PURE__*/React.createElement(ActionList, {
192
- selectionVariant: "multiple",
193
- items: [...(filterFn ? itemsToRender.filter(filterFn) : itemsToRender)].sort((a, b) => itemSortOrderData[a.id] - itemSortOrderData[b.id]),
194
- role: "listbox"
195
- }) : /*#__PURE__*/React.createElement(Box, {
196
- p: 3
197
- }, emptyStateText))) : null);
198
- });
199
- AutocompleteMenu.defaultProps = {
200
- emptyStateText: 'No selectable options'
201
- };
202
- AutocompleteMenu.displayName = 'AutocompleteMenu';
203
- export default AutocompleteMenu;
@@ -1,8 +0,0 @@
1
- import { BadgeSizeKeys } from './_badgeStyleUtils';
2
- declare type BadgeColorOptions = 'default' | 'primary' | 'secondary' | 'info' | 'success' | 'warning' | 'danger';
3
- interface Props {
4
- color?: BadgeColorOptions;
5
- variant?: BadgeSizeKeys;
6
- }
7
- declare const Badge: import("styled-components").StyledComponent<"span", any, Props, never>;
8
- export default Badge;
@@ -1,44 +0,0 @@
1
- import styled from 'styled-components';
2
- import { get } from '../constants';
3
- import { badgeVariants } from './_badgeStyleUtils';
4
- const badgeColorMap = {
5
- default: {
6
- borderColor: get('colors.border.default')
7
- },
8
- primary: {
9
- borderColor: get('colors.fg.default')
10
- },
11
- secondary: {
12
- borderColor: get('colors.border.muted'),
13
- textColor: get('colors.fg.muted')
14
- },
15
- info: {
16
- borderColor: get('colors.accent.fg'),
17
- textColor: get('colors.accent.fg')
18
- },
19
- success: {
20
- borderColor: get('colors.success.fg'),
21
- textColor: get('colors.success.emphasis')
22
- },
23
- warning: {
24
- borderColor: get('colors.attention.fg'),
25
- textColor: get('colors.attention.emphasis')
26
- },
27
- danger: {
28
- borderColor: get('colors.danger.fg'),
29
- textColor: get('colors.danger.emphasis')
30
- }
31
- };
32
- const Badge = styled.span.withConfig({
33
- displayName: "Badge",
34
- componentId: "sc-15t9m5z-0"
35
- })(["align-items:center;background-color:transparent;border-width:1px;border-radius:999px;border-style:solid;border-color:", ";color:", ";display:inline-flex;font-weight:", ";line-height:1;white-space:nowrap;", ";"], ({
36
- color = 'default'
37
- }) => badgeColorMap[color].borderColor, ({
38
- color = 'default'
39
- }) => badgeColorMap[color].textColor, get('fontWeights.bold'), badgeVariants);
40
- Badge.defaultProps = {
41
- variant: 'sm',
42
- color: 'default'
43
- };
44
- export default Badge;
@@ -1,13 +0,0 @@
1
- /// <reference types="react" />
2
- import { IconProps } from '@primer/octicons-react';
3
- import { BadgeSizeKeys } from './_badgeStyleUtils';
4
- declare type BadgeStateColorOptions = 'default' | 'open' | 'merged' | 'closed';
5
- interface Props {
6
- color?: BadgeStateColorOptions;
7
- icon?: React.ComponentType<{
8
- size?: IconProps['size'];
9
- }>;
10
- variant?: BadgeSizeKeys;
11
- }
12
- declare const BadgeState: React.FC<Props>;
13
- export default BadgeState;
@@ -1,40 +0,0 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- import styled from 'styled-components';
4
- import { get } from '../constants';
5
- import { badgeVariants } from './_badgeStyleUtils'; // TODO: consider making these a little less specific by using:
6
- // 'default' | 'success' | 'done' | 'danger'
7
-
8
- const badgeStateColorMap = {
9
- default: get('colors.neutral.emphasis'),
10
- open: get('colors.success.emphasis'),
11
- merged: get('colors.done.emphasis'),
12
- closed: get('colors.danger.emphasis')
13
- }; // const badgeStateIconSizeMap: Record<BadgeSizeKeys, number> = {
14
- // 'sm':
15
- // };
16
-
17
- const StyledBadgeState = styled.span.withConfig({
18
- displayName: "BadgeState__StyledBadgeState",
19
- componentId: "sc-5hwzjt-0"
20
- })(["align-items:center;background-color:", ";border-radius:999px;color:", ";display:inline-flex;font-weight:", ";gap:", ";line-height:1;white-space:nowrap;", ";"], ({
21
- color = 'default'
22
- }) => badgeStateColorMap[color], get('colors.fg.onEmphasis'), get('fontWeights.bold'), get('space.1'), badgeVariants);
23
-
24
- const BadgeState = ({
25
- children,
26
- icon: IconComponent,
27
- variant,
28
- ...rest
29
- }) => /*#__PURE__*/React.createElement(StyledBadgeState, _extends({
30
- variant: variant
31
- }, rest), IconComponent ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(IconComponent, {
32
- size: variant === 'sm' ? 12 : 'small'
33
- }), children) : children);
34
-
35
- BadgeState.displayName = "BadgeState";
36
- BadgeState.defaultProps = {
37
- variant: 'lg',
38
- color: 'default'
39
- };
40
- export default BadgeState;
@@ -1,3 +0,0 @@
1
- export declare type BadgeSizeKeys = 'sm' | 'md' | 'lg';
2
- export declare const badgeSizes: Record<BadgeSizeKeys, number>;
3
- export declare const badgeVariants: (...args: any[]) => any;
@@ -1,29 +0,0 @@
1
- import { variant } from 'styled-system';
2
- // TODO: consider moving to Primitives
3
- export const badgeSizes = {
4
- sm: 20,
5
- md: 24,
6
- lg: 32
7
- };
8
- export const badgeVariants = variant({
9
- variants: {
10
- sm: {
11
- fontSize: 0,
12
- height: `${badgeSizes.sm}px`,
13
- paddingLeft: 2,
14
- paddingRight: 2
15
- },
16
- md: {
17
- fontSize: 0,
18
- height: `${badgeSizes.md}px`,
19
- paddingLeft: 2,
20
- paddingRight: 2
21
- },
22
- lg: {
23
- fontSize: 1,
24
- height: `${badgeSizes.lg}px`,
25
- paddingLeft: 3,
26
- paddingRight: 3
27
- }
28
- }
29
- });