1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
6 |
|
7 | require('./slicedToArray-0711941d.js');
|
8 | require('./unsupportedIterableToArray-68db1d3b.js');
|
9 | var React = require('react');
|
10 | var React__default = _interopDefault(React);
|
11 | require('./_commonjsHelpers-72d386ba.js');
|
12 | var index = require('./index-b0606964.js');
|
13 | require('./defineProperty-0921a47c.js');
|
14 | require('./toConsumableArray-d8a4a2c3.js');
|
15 | var _styled = require('styled-components');
|
16 | var _styled__default = _interopDefault(_styled);
|
17 | require('./getPrototypeOf-2a661a20.js');
|
18 | require('./color.js');
|
19 | require('./components.js');
|
20 | require('./contains-component.js');
|
21 | var css = require('./css.js');
|
22 | require('./dayjs.min-e07657bf.js');
|
23 | require('./date.js');
|
24 | require('./miscellaneous.js');
|
25 | require('./environment.js');
|
26 | require('./font.js');
|
27 | require('./math-f4029164.js');
|
28 | require('./characters.js');
|
29 | require('./format.js');
|
30 | require('./keycodes.js');
|
31 | require('./url.js');
|
32 | require('./web3.js');
|
33 | var constants = require('./constants.js');
|
34 | require('./breakpoints.js');
|
35 | require('./springs.js');
|
36 | var textStyles = require('./text-styles.js');
|
37 | require('./theme-dark.js');
|
38 | require('./theme-light.js');
|
39 | var Theme = require('./Theme.js');
|
40 | var _extends = require('./extends-40571110.js');
|
41 | var objectWithoutProperties = require('./objectWithoutProperties-35db8ab0.js');
|
42 |
|
43 | var MODE_INDICATOR = 'indicator';
|
44 | var MODE_IDENTIFIER = 'identifier';
|
45 | var MODE_NEW = 'new';
|
46 | var MODE_ACTIVITY = 'activity';
|
47 | var SIZE_NORMAL = 'normal';
|
48 | var SIZE_SMALL = 'small';
|
49 | var COUNT_DEFAULT = 2;
|
50 |
|
51 | function useMode(mode) {
|
52 | var theme = Theme.useTheme();
|
53 |
|
54 | if (mode === MODE_IDENTIFIER) {
|
55 | return {
|
56 | background: theme.tagIdentifier,
|
57 | color: theme.tagIdentifierContent,
|
58 | size: SIZE_NORMAL
|
59 | };
|
60 | }
|
61 |
|
62 | if (mode === MODE_NEW) {
|
63 | return {
|
64 | background: theme.tagNew,
|
65 | color: theme.tagNewContent,
|
66 | size: SIZE_NORMAL
|
67 | };
|
68 | }
|
69 |
|
70 | if (mode === MODE_ACTIVITY) {
|
71 | return {
|
72 | background: theme.tagActivity,
|
73 | color: theme.tagActivityContent,
|
74 | size: SIZE_SMALL
|
75 | };
|
76 | }
|
77 |
|
78 |
|
79 | return {
|
80 | background: theme.tagIndicator,
|
81 | color: theme.tagIndicatorContent,
|
82 | size: SIZE_NORMAL
|
83 | };
|
84 | }
|
85 |
|
86 | function getSize(size, _ref) {
|
87 | var uppercase = _ref.uppercase,
|
88 | discMode = _ref.discMode,
|
89 | iconAndLabel = _ref.iconAndLabel;
|
90 |
|
91 | if (size === SIZE_SMALL) {
|
92 | return "\n min-width: ".concat(2 * constants.GU, "px;\n width: ").concat(discMode ? "".concat(2 * constants.GU, "px") : 'auto', ";\n height: ").concat(2 * constants.GU, "px;\n padding: ").concat(discMode ? '0' : "0 ".concat(0.5 * constants.GU, "px"), ";\n padding-top: ").concat(uppercase ? '0.5px' : 0, ";\n border-radius: ").concat(2 * constants.GU, "px;\n ").concat(textStyles.textStyle('label3'), ";\n font-weight: 600;\n ");
|
93 | }
|
94 |
|
95 |
|
96 | return "\n min-width: ".concat(2.5 * constants.GU, "px;\n width: ").concat(discMode ? "".concat(3 * constants.GU, "px") : 'auto', ";\n height: ").concat(2.5 * constants.GU, "px;\n padding: ").concat(discMode ? '0' : "0 ".concat(1.5 * constants.GU, "px"), " ;\n padding-top: ").concat(uppercase ? '1px' : 0, ";\n ").concat(iconAndLabel ? "padding-left: ".concat(1.25 * constants.GU, "px") : '', ";\n border-radius: ").concat(2.5 * constants.GU, "px;\n ").concat(textStyles.textStyle('label2'), ";\n font-weight: 600;\n ");
|
97 | }
|
98 |
|
99 | function useLabel(_ref2) {
|
100 | var _ref2$label = _ref2.label,
|
101 | label = _ref2$label === void 0 ? '' : _ref2$label,
|
102 | limitDigits = _ref2.limitDigits;
|
103 | var finalLabel = React.useMemo(function () {
|
104 | if (limitDigits === false) {
|
105 | return typeof label === 'number' ? String(label) : label || '';
|
106 | }
|
107 |
|
108 | var digits = typeof limitDigits === 'number' ? limitDigits : COUNT_DEFAULT;
|
109 | var parsed = parseInt(label, 10);
|
110 |
|
111 | if (isNaN(parsed)) {
|
112 | return label || '';
|
113 | }
|
114 |
|
115 | var max = Math.pow(10, digits) - 1;
|
116 | var formattedValue = parsed > max ? "".concat(max, "+") : parsed;
|
117 | return String(formattedValue);
|
118 | }, [label, limitDigits]);
|
119 | return finalLabel;
|
120 | }
|
121 |
|
122 | var _StyledSpan = _styled__default("span").withConfig({
|
123 | displayName: "Tag___StyledSpan",
|
124 | componentId: "sc-875dmt-0"
|
125 | })(["display:inline-flex;align-items:center;justify-content:center;white-space:nowrap;", ";", ";color:", ";background:", ";", ";"], function (p) {
|
126 | return p._css;
|
127 | }, function (p) {
|
128 | return p._css2;
|
129 | }, function (p) {
|
130 | return p._css3;
|
131 | }, function (p) {
|
132 | return p._css4;
|
133 | }, css.unselectable);
|
134 |
|
135 | var _StyledSpan2 = _styled__default("span").withConfig({
|
136 | displayName: "Tag___StyledSpan2",
|
137 | componentId: "sc-875dmt-1"
|
138 | })(["display:flex;align-items:center;margin-right:", "px;"], function (p) {
|
139 | return p._css5;
|
140 | });
|
141 |
|
142 | var _StyledSpan3 = _styled__default("span").withConfig({
|
143 | displayName: "Tag___StyledSpan3",
|
144 | componentId: "sc-875dmt-2"
|
145 | })(["overflow:hidden;text-overflow:ellipsis;margin-top:", ";"], function (p) {
|
146 | return p._css6;
|
147 | });
|
148 |
|
149 | function Tag(_ref3) {
|
150 | var background = _ref3.background,
|
151 | children = _ref3.children,
|
152 | color = _ref3.color,
|
153 | limitDigits = _ref3.limitDigits,
|
154 | icon = _ref3.icon,
|
155 | label = _ref3.label,
|
156 | mode = _ref3.mode,
|
157 | size = _ref3.size,
|
158 | uppercase = _ref3.uppercase,
|
159 | props = objectWithoutProperties._objectWithoutProperties(_ref3, ["background", "children", "color", "limitDigits", "icon", "label", "mode", "size", "uppercase"]);
|
160 |
|
161 | if ((icon || label !== undefined) && children !== undefined) {
|
162 | throw new Error('Tag: you cannot use icon or label with children.');
|
163 | }
|
164 |
|
165 | var modeProps = useMode(mode);
|
166 | var finalSize = size || modeProps.size;
|
167 | var finalLabel = useLabel({
|
168 | label: label !== undefined ? label : children,
|
169 | limitDigits: limitDigits
|
170 | });
|
171 | var sizeStyles = getSize(finalSize, {
|
172 | uppercase: uppercase,
|
173 | discMode:
|
174 | icon && !finalLabel ||
|
175 | !icon && typeof finalLabel === 'string' && finalLabel.length < 2,
|
176 | iconAndLabel: icon && finalLabel
|
177 | });
|
178 |
|
179 |
|
180 | var alignmentCorrection = finalSize === SIZE_NORMAL && (uppercase || typeof label === 'number' || limitDigits !== false);
|
181 | return React__default.createElement(_StyledSpan, _extends._extends({}, props, {
|
182 | _css: sizeStyles,
|
183 | _css2: !uppercase ? 'text-transform: unset' : '',
|
184 | _css3: color || modeProps.color,
|
185 | _css4: background || modeProps.background
|
186 | }), icon && React__default.createElement(_StyledSpan2, {
|
187 | _css5: finalLabel ? 0.25 * constants.GU : 0
|
188 | }, icon), React__default.createElement(_StyledSpan3, {
|
189 | _css6: alignmentCorrection ? '1px' : '0'
|
190 | }, finalLabel));
|
191 | }
|
192 |
|
193 | Tag.propTypes = {
|
194 | background: index.PropTypes.string,
|
195 | children: index.PropTypes.node,
|
196 | color: index.PropTypes.string,
|
197 | limitDigits: index.PropTypes.oneOfType([index.PropTypes.bool, index.PropTypes.number]),
|
198 | icon: index.PropTypes.node,
|
199 | label: index.PropTypes.oneOfType([index.PropTypes.node, index.PropTypes.number]),
|
200 | mode: index.PropTypes.oneOf([MODE_IDENTIFIER, MODE_NEW, MODE_INDICATOR, MODE_ACTIVITY]),
|
201 | size: index.PropTypes.oneOf([SIZE_NORMAL, SIZE_SMALL]),
|
202 | uppercase: index.PropTypes.bool
|
203 | };
|
204 | Tag.defaultProps = {
|
205 | uppercase: true,
|
206 | limitDigits: false
|
207 | };
|
208 |
|
209 | exports.default = Tag;
|
210 |
|