@decisiv/ui-components 2.0.1-alpha.154 → 2.0.1-alpha.156
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/lib/components/Select/index.d.ts.map +1 -1
- package/lib/components/Select/index.js +3 -1
- package/lib/components/Select/index.test.js +43 -19
- package/lib/components/Select/schema.d.ts.map +1 -1
- package/lib/components/Select/schema.js +1 -0
- package/lib/components/Select/types.d.ts +1 -0
- package/lib/components/Select/types.d.ts.map +1 -1
- package/lib/components/Tag/Action.d.ts +4 -0
- package/lib/components/Tag/Action.d.ts.map +1 -0
- package/lib/components/Tag/Action.js +39 -0
- package/lib/components/Tag/constants.d.ts +1 -1
- package/lib/components/Tag/constants.d.ts.map +1 -1
- package/lib/components/Tag/constants.js +3 -3
- package/lib/components/Tag/index.d.ts +1 -1
- package/lib/components/Tag/index.d.ts.map +1 -1
- package/lib/components/Tag/index.js +114 -37
- package/lib/components/Tag/index.test.js +183 -2
- package/lib/components/Tag/propTypes.d.ts +2 -0
- package/lib/components/Tag/propTypes.d.ts.map +1 -1
- package/lib/components/Tag/propTypes.js +4 -2
- package/lib/components/Tag/schema.d.ts.map +1 -1
- package/lib/components/Tag/schema.js +1 -0
- package/lib/components/Tag/types.d.ts +8 -10
- package/lib/components/Tag/types.d.ts.map +1 -1
- package/lib/utils/commonUIColors.d.ts +349 -1
- package/lib/utils/commonUIColors.d.ts.map +1 -1
- package/lib/utils/commonUIColors.js +6 -2
- package/package.json +2 -2
- package/lib/components/Tag/ActionButton.d.ts +0 -5
- package/lib/components/Tag/ActionButton.d.ts.map +0 -1
- package/lib/components/Tag/ActionButton.js +0 -56
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Select/index.tsx"],"names":[],"mappings":"AAGA,OAAc,EAEZ,sBAAsB,EAMvB,MAAM,OAAO,CAAC;AAoBf,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Select/index.tsx"],"names":[],"mappings":"AAGA,OAAc,EAEZ,sBAAsB,EAMvB,MAAM,OAAO,CAAC;AAoBf,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AA8PjD,QAAA,MAAM,aAAa,EAAE,sBAAsB,CACzC,SAAS,EACT,WAAW,CACS,CAAC;AAgCvB,eAAe,aAAa,CAAC"}
|
|
@@ -72,6 +72,8 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
72
72
|
function Select(props, ref) {
|
|
73
73
|
var actions = props.actions,
|
|
74
74
|
clearButtonLabel = props.clearButtonLabel,
|
|
75
|
+
_props$hideClearButto = props.hideClearButton,
|
|
76
|
+
hideClearButton = _props$hideClearButto === void 0 ? false : _props$hideClearButto,
|
|
75
77
|
defaultValue = props.defaultValue,
|
|
76
78
|
id = props.id,
|
|
77
79
|
inputContainerRef = props.inputContainerRef,
|
|
@@ -246,7 +248,7 @@ function Select(props, ref) {
|
|
|
246
248
|
"aria-owns": dropdownListId,
|
|
247
249
|
clearButtonLabel: clearButtonLabel,
|
|
248
250
|
disabled: disabled,
|
|
249
|
-
hasClearButton: Boolean(selectedValue),
|
|
251
|
+
hasClearButton: hideClearButton ? false : Boolean(selectedValue),
|
|
250
252
|
id: targetId,
|
|
251
253
|
inputFieldLabel: label,
|
|
252
254
|
isPopoverVisible: isPopoverVisible,
|
|
@@ -187,16 +187,40 @@ describe('Select', function () {
|
|
|
187
187
|
|
|
188
188
|
expect(getByText(cat0Opt0.label)).toBeTruthy();
|
|
189
189
|
});
|
|
190
|
+
describe('when "hideClearButton" is false', function () {
|
|
191
|
+
it('shows the clear button', function () {
|
|
192
|
+
var _render7 = render(_react.default.createElement(_.default, _extends({}, defaultProps, {
|
|
193
|
+
defaultValue: cat0Opt0.id,
|
|
194
|
+
hideClearButton: false,
|
|
195
|
+
clearButtonLabel: "clear selection"
|
|
196
|
+
}))),
|
|
197
|
+
getByLabelText = _render7.getByLabelText;
|
|
198
|
+
|
|
199
|
+
expect(getByLabelText(/clear selection/i)).toBeInTheDocument();
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
describe('when "hideClearButton" is true', function () {
|
|
203
|
+
it('does not show the clear button', function () {
|
|
204
|
+
var _render8 = render(_react.default.createElement(_.default, _extends({}, defaultProps, {
|
|
205
|
+
defaultValue: cat0Opt0.id,
|
|
206
|
+
hideClearButton: true,
|
|
207
|
+
clearButtonLabel: "clear selection"
|
|
208
|
+
}))),
|
|
209
|
+
queryByLabelText = _render8.queryByLabelText;
|
|
210
|
+
|
|
211
|
+
expect(queryByLabelText(/clear selection/i)).not.toBeInTheDocument();
|
|
212
|
+
});
|
|
213
|
+
});
|
|
190
214
|
describe('clicking an option', function () {
|
|
191
215
|
it('calls the onchange handler with the new value', function () {
|
|
192
216
|
var onChange = jest.fn();
|
|
193
217
|
|
|
194
|
-
var
|
|
218
|
+
var _render9 = render(_react.default.createElement(_.default, _extends({}, defaultProps, {
|
|
195
219
|
onChange: onChange,
|
|
196
220
|
defaultValue: opt1.id
|
|
197
221
|
}))),
|
|
198
|
-
baseElement =
|
|
199
|
-
getByText =
|
|
222
|
+
baseElement = _render9.baseElement,
|
|
223
|
+
getByText = _render9.getByText;
|
|
200
224
|
|
|
201
225
|
_react2.fireEvent.click(getByText(defaultProps.label));
|
|
202
226
|
|
|
@@ -205,11 +229,11 @@ describe('Select', function () {
|
|
|
205
229
|
expect(onChange).toHaveBeenCalledWith(cat0Opt0.id);
|
|
206
230
|
});
|
|
207
231
|
it('automatically updates the option label inside the input field', function () {
|
|
208
|
-
var
|
|
232
|
+
var _render10 = render(_react.default.createElement(_.default, _extends({}, defaultProps, {
|
|
209
233
|
defaultValue: opt1.id
|
|
210
234
|
}))),
|
|
211
|
-
baseElement =
|
|
212
|
-
getByText =
|
|
235
|
+
baseElement = _render10.baseElement,
|
|
236
|
+
getByText = _render10.getByText;
|
|
213
237
|
|
|
214
238
|
_react2.fireEvent.click(getByText(defaultProps.label));
|
|
215
239
|
|
|
@@ -222,32 +246,32 @@ describe('Select', function () {
|
|
|
222
246
|
});
|
|
223
247
|
describe('when label hidden', function () {
|
|
224
248
|
it('does not display the label element', function () {
|
|
225
|
-
var
|
|
249
|
+
var _render11 = render(_react.default.createElement(_.default, _extends({}, defaultProps, {
|
|
226
250
|
defaultvalue: opt1.id,
|
|
227
251
|
hideLabel: true
|
|
228
252
|
}))),
|
|
229
|
-
getByText =
|
|
253
|
+
getByText = _render11.getByText;
|
|
230
254
|
|
|
231
255
|
expect(getByText(defaultProps.label, {
|
|
232
256
|
selector: 'span'
|
|
233
257
|
})).not.toBeVisible();
|
|
234
258
|
});
|
|
235
259
|
it('does display the input related to the label', function () {
|
|
236
|
-
var
|
|
260
|
+
var _render12 = render(_react.default.createElement(_.default, _extends({}, defaultProps, {
|
|
237
261
|
defaultValue: opt1.id,
|
|
238
262
|
hideLabel: true
|
|
239
263
|
}))),
|
|
240
|
-
getByLabelText =
|
|
264
|
+
getByLabelText = _render12.getByLabelText;
|
|
241
265
|
|
|
242
266
|
expect(getByLabelText(defaultProps.label)).toBeVisible();
|
|
243
267
|
});
|
|
244
268
|
});
|
|
245
269
|
describe('when component is controlled', function () {
|
|
246
270
|
it('displays the option label matching the value inside the input field', function () {
|
|
247
|
-
var
|
|
271
|
+
var _render13 = render(_react.default.createElement(_.default, _extends({}, defaultProps, {
|
|
248
272
|
value: cat0Opt0.id
|
|
249
273
|
}))),
|
|
250
|
-
getByText =
|
|
274
|
+
getByText = _render13.getByText;
|
|
251
275
|
|
|
252
276
|
expect(getByText(cat0Opt0.label)).toBeTruthy();
|
|
253
277
|
});
|
|
@@ -255,12 +279,12 @@ describe('Select', function () {
|
|
|
255
279
|
it('calls the onchange handler with the new value', function () {
|
|
256
280
|
var onChange = jest.fn();
|
|
257
281
|
|
|
258
|
-
var
|
|
282
|
+
var _render14 = render(_react.default.createElement(_.default, _extends({}, defaultProps, {
|
|
259
283
|
onChange: onChange,
|
|
260
284
|
value: opt1.id
|
|
261
285
|
}))),
|
|
262
|
-
baseElement =
|
|
263
|
-
getByText =
|
|
286
|
+
baseElement = _render14.baseElement,
|
|
287
|
+
getByText = _render14.getByText;
|
|
264
288
|
|
|
265
289
|
_react2.fireEvent.click(getByText(defaultProps.label));
|
|
266
290
|
|
|
@@ -269,12 +293,12 @@ describe('Select', function () {
|
|
|
269
293
|
expect(onChange).toHaveBeenCalledWith(cat0Opt0.id);
|
|
270
294
|
});
|
|
271
295
|
it('does NOT automatically update the option label inside the input field', function () {
|
|
272
|
-
var
|
|
296
|
+
var _render15 = render(_react.default.createElement(_.default, _extends({}, defaultProps, {
|
|
273
297
|
value: opt1.id
|
|
274
298
|
}))),
|
|
275
|
-
baseElement =
|
|
276
|
-
getByText =
|
|
277
|
-
queryByText =
|
|
299
|
+
baseElement = _render15.baseElement,
|
|
300
|
+
getByText = _render15.getByText,
|
|
301
|
+
queryByText = _render15.queryByText;
|
|
278
302
|
|
|
279
303
|
_react2.fireEvent.click(getByText(defaultProps.label));
|
|
280
304
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/components/Select/schema.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,MAAM,KAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/components/Select/schema.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,MAAM,KAAsC,CAAC;AAwEnD,eAAe,MAAM,CAAC"}
|
|
@@ -23,6 +23,7 @@ var schema = (0, _reactDesc.describe)({
|
|
|
23
23
|
displayName: 'Select'
|
|
24
24
|
});
|
|
25
25
|
schema.propTypes = _objectSpread({}, (0, _omit.default)(_InputField.schema.makePropTypes(), ['children', 'maxLength', 'onChange', 'showCharacterCount']), {
|
|
26
|
+
hideClearButton: _reactDesc.PropTypes.bool.description('Whether or not to hide the clear button after selecting an item').defaultValue('false'),
|
|
26
27
|
clearButtonLabel: _reactDesc.PropTypes.string.description("A hidden label value for the clear button. The select component's label is available within the string for clarity.").defaultValue('Clear {label} value'),
|
|
27
28
|
containerSelector: _reactDesc.PropTypes.string.description("A CSS selector to the element where the Select should be rendered in, or \"parent\" to render the Select in-place.").defaultValue('body'),
|
|
28
29
|
defaultValue: _reactDesc.PropTypes.string.description('The ID of the option that should be selected by default.'),
|
|
@@ -11,6 +11,7 @@ interface BaseSelectProps extends ButtonHTMLAttributes<SelectRef>, Omit<BaseInpu
|
|
|
11
11
|
onKeyDown?: KeyboardEventHandler;
|
|
12
12
|
}
|
|
13
13
|
export declare type SelectProps = BaseSelectProps & {
|
|
14
|
+
hideClearButton?: boolean;
|
|
14
15
|
clearButtonLabel?: string;
|
|
15
16
|
defaultValue?: string;
|
|
16
17
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/Select/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,oBAAY,SAAS,GAAG,iBAAiB,CAAC;AAE1C,UAAU,eACR,SAAQ,oBAAoB,CAAC,SAAS,CAAC,EACrC,IAAI,CACF,mBAAmB,EACnB,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,oBAAoB,GAAG,OAAO,CACvE,EACD,IAAI,CAAC,gBAAgB,EAAE,SAAS,GAAG,mBAAmB,CAAC;IACzD,M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BAAoB,CAAC,SAAS,CAAC,EACrC,IAAI,CACF,mBAAmB,EACnB,UAAU,GAAG,IAAI,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,KAAK,GAAG,OAAO,CACxE;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,MAAM,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IACtC,OAAO,CAAC,EAAE,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC3C,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;CACzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Action.d.ts","sourceRoot":"","sources":["../../../src/components/Tag/Action.tsx"],"names":[],"mappings":"AAgBA,QAAA,MAAM,MAAM,oEAcX,CAAC;AAEF,eAAO,MAAM,eAAe,oEAO3B,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.ActionContainer = void 0;
|
|
7
|
+
|
|
8
|
+
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
9
|
+
|
|
10
|
+
var _toColorString = _interopRequireDefault(require("polished/lib/color/toColorString"));
|
|
11
|
+
|
|
12
|
+
var _rem = _interopRequireDefault(require("polished/lib/helpers/rem"));
|
|
13
|
+
|
|
14
|
+
var _designTokens = _interopRequireDefault(require("@decisiv/design-tokens"));
|
|
15
|
+
|
|
16
|
+
var _constants = require("./constants");
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
|
21
|
+
|
|
22
|
+
var _designTokens$color = _designTokens.default.color,
|
|
23
|
+
baseColors = _designTokens$color.base,
|
|
24
|
+
interactionColors = _designTokens$color.interaction;
|
|
25
|
+
var borderRadius = (0, _styledComponents.css)(["border-radius:0 ", " ", " 0;"], (0, _rem.default)(10), (0, _rem.default)(10));
|
|
26
|
+
|
|
27
|
+
var Action = _styledComponents.default.div.withConfig({
|
|
28
|
+
displayName: "Action",
|
|
29
|
+
componentId: "sc-53eucd-0"
|
|
30
|
+
})(["align-items:center;appearance:none;background-color:", ";border:0;color:", ";display:flex;height:100%;justify-content:flex-start;padding:0 0 0 ", ";width:", ";outline:none;", ""], (0, _toColorString.default)(baseColors.snowWhite), (0, _toColorString.default)(interactionColors.pacificOcean), (0, _rem.default)(4), (0, _rem.default)(_constants.ACTION_WIDTH), borderRadius);
|
|
31
|
+
|
|
32
|
+
var ActionContainer = _styledComponents.default.div.withConfig({
|
|
33
|
+
displayName: "Action__ActionContainer",
|
|
34
|
+
componentId: "sc-53eucd-1"
|
|
35
|
+
})(["height:", ";margin-right:2px;background-color:", ";box-shadow:", " 0 0 0 ", ";", ";"], (0, _rem.default)(18), (0, _toColorString.default)(baseColors.snowWhite), (0, _rem.default)(2), (0, _toColorString.default)(baseColors.snowWhite), borderRadius);
|
|
36
|
+
|
|
37
|
+
exports.ActionContainer = ActionContainer;
|
|
38
|
+
var _default = Action;
|
|
39
|
+
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/components/Tag/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/components/Tag/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,mBAAmB,KAAK,CAAC;AACtC,eAAO,MAAM,mBAAmB,IAAI,CAAC;AACrC,eAAO,MAAM,mBAAmB,MAAM,CAAC"}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.MAX_CONTAINER_WIDTH = exports.ICON_CONTENT_MARGIN = exports.CONTAINER_X_PADDING = exports.
|
|
7
|
-
var
|
|
8
|
-
exports.
|
|
6
|
+
exports.MAX_CONTAINER_WIDTH = exports.ICON_CONTENT_MARGIN = exports.CONTAINER_X_PADDING = exports.ACTION_WIDTH = void 0;
|
|
7
|
+
var ACTION_WIDTH = 20;
|
|
8
|
+
exports.ACTION_WIDTH = ACTION_WIDTH;
|
|
9
9
|
var CONTAINER_X_PADDING = 14;
|
|
10
10
|
exports.CONTAINER_X_PADDING = CONTAINER_X_PADDING;
|
|
11
11
|
var ICON_CONTENT_MARGIN = 5;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RefForwardingComponent } from 'react';
|
|
2
2
|
import { CommonUIColors } from '../../utils/commonUIColors';
|
|
3
3
|
import { TagProps, TagRef } from './types';
|
|
4
|
-
export { TagProps, TagRef, TagActionButtonRef } from './types';
|
|
4
|
+
export { TagProps, TagRef, TagActionRef as TagActionButtonRef } from './types';
|
|
5
5
|
export declare type ColorKeys = keyof CommonUIColors;
|
|
6
6
|
declare const TagWithRef: RefForwardingComponent<TagRef, TagProps>;
|
|
7
7
|
export default TagWithRef;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Tag/index.tsx"],"names":[],"mappings":"AAEA,OAAc,EAIZ,sBAAsB,EAIvB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Tag/index.tsx"],"names":[],"mappings":"AAEA,OAAc,EAIZ,sBAAsB,EAIvB,MAAM,OAAO,CAAC;AAQf,OAAO,EAGL,cAAc,EACf,MAAM,4BAA4B,CAAC;AAapC,OAAO,EAGL,QAAQ,EACR,MAAM,EAEP,MAAM,SAAS,CAAC;AAQjB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,IAAI,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE/E,oBAAY,SAAS,GAAG,MAAM,cAAc,CAAC;AAkT7C,QAAA,MAAM,UAAU,EAAE,sBAAsB,CAAC,MAAM,EAAE,QAAQ,CAAmB,CAAC;AAS7E,eAAe,UAAU,CAAC"}
|
|
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "TagRef", {
|
|
|
18
18
|
Object.defineProperty(exports, "TagActionButtonRef", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
get: function get() {
|
|
21
|
-
return _types.
|
|
21
|
+
return _types.TagActionRef;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
exports.default = void 0;
|
|
@@ -31,15 +31,17 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
31
31
|
|
|
32
32
|
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
33
33
|
|
|
34
|
-
var _designTokens = require("@decisiv/design-tokens");
|
|
34
|
+
var _designTokens = _interopRequireWildcard(require("@decisiv/design-tokens"));
|
|
35
35
|
|
|
36
36
|
var _color = _interopRequireDefault(require("../../modifiers/color"));
|
|
37
37
|
|
|
38
|
+
var _focusRingWithColor = _interopRequireDefault(require("../../utils/focusRingWithColor"));
|
|
39
|
+
|
|
38
40
|
var _commonUIColors = require("../../utils/commonUIColors");
|
|
39
41
|
|
|
40
42
|
var _Typography = require("../Typography");
|
|
41
43
|
|
|
42
|
-
var
|
|
44
|
+
var _Action = _interopRequireWildcard(require("./Action"));
|
|
43
45
|
|
|
44
46
|
var _constants = require("./constants");
|
|
45
47
|
|
|
@@ -47,6 +49,10 @@ var _propTypes = require("./propTypes");
|
|
|
47
49
|
|
|
48
50
|
var _types = require("./types");
|
|
49
51
|
|
|
52
|
+
var _BaseButton = _interopRequireDefault(require("../../atoms/BaseButton"));
|
|
53
|
+
|
|
54
|
+
var _styleModifiers = require("../../utils/styleModifiers");
|
|
55
|
+
|
|
50
56
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
|
51
57
|
|
|
52
58
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -71,7 +77,9 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
71
77
|
|
|
72
78
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
73
79
|
|
|
74
|
-
var
|
|
80
|
+
var _designTokens$color = _designTokens.default.color,
|
|
81
|
+
interactionColors = _designTokens$color.interaction,
|
|
82
|
+
statusColors = _designTokens$color.status;
|
|
75
83
|
|
|
76
84
|
var getContentMaxWidth = function getContentMaxWidth(props) {
|
|
77
85
|
var isSingleChild = props.isSingleChild,
|
|
@@ -81,27 +89,43 @@ var getContentMaxWidth = function getContentMaxWidth(props) {
|
|
|
81
89
|
var containerBorder = 2;
|
|
82
90
|
var baseWidth = _constants.MAX_CONTAINER_WIDTH - _constants.CONTAINER_X_PADDING - containerBorder;
|
|
83
91
|
var valuesToSubtract = [];
|
|
84
|
-
!isSingleChild && valuesToSubtract.push(_constants.
|
|
92
|
+
!isSingleChild && valuesToSubtract.push(_constants.ACTION_WIDTH, actionBorder);
|
|
85
93
|
hasIcon && valuesToSubtract.push(iconWidth, _constants.ICON_CONTENT_MARGIN);
|
|
86
94
|
return (0, _rem.default)(valuesToSubtract.reduce(function (r, v) {
|
|
87
95
|
return r - v;
|
|
88
96
|
}, baseWidth));
|
|
89
97
|
};
|
|
90
98
|
|
|
91
|
-
var
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
var PALETTE_MAPPER = {
|
|
100
|
+
pastel: 'light',
|
|
101
|
+
bright: 'medium',
|
|
102
|
+
dark: 'dark'
|
|
103
|
+
};
|
|
104
|
+
var FG_COLOR = {
|
|
105
|
+
pastel: _objectSpread({}, _designTokens.color.base.charcoal, {
|
|
106
|
+
alpha: 0.8
|
|
107
|
+
}),
|
|
108
|
+
bright: _designTokens.color.base.snowWhite,
|
|
109
|
+
dark: _designTokens.color.base.snowWhite
|
|
110
|
+
};
|
|
111
|
+
var BORDER_OPACITY = {
|
|
112
|
+
pastel: 0.1,
|
|
113
|
+
bright: 0.15,
|
|
114
|
+
dark: 0.3
|
|
97
115
|
};
|
|
98
116
|
|
|
99
117
|
var Content = _styledComponents.default.div.withConfig({
|
|
100
118
|
displayName: "Tag__Content",
|
|
101
119
|
componentId: "nifm8a-0"
|
|
102
|
-
})(["align-items:center;border:0;display:flex;padding:0 ", ";", ";> svg{flex:1 0 auto;}* + *{margin-left:", ";}span{max-width:", ";}"], (0, _rem.default)(_constants.CONTAINER_X_PADDING / 2), function (
|
|
120
|
+
})(["color:inherit;align-items:center;border:0;display:flex;padding:0 ", ";border-right:1px solid ", ";", ";> svg{flex:1 0 auto;}* + *{margin-left:", ";}span{max-width:", ";}"], (0, _rem.default)(_constants.CONTAINER_X_PADDING / 2), function (_ref) {
|
|
121
|
+
var _ref$palette = _ref.palette,
|
|
122
|
+
palette = _ref$palette === void 0 ? 'bright' : _ref$palette;
|
|
123
|
+
return (0, _toColorString.default)(_objectSpread({}, _designTokens.color.base.charcoal, {
|
|
124
|
+
alpha: BORDER_OPACITY[palette]
|
|
125
|
+
}));
|
|
126
|
+
}, function (_ref2) {
|
|
103
127
|
var isSingleChild = _ref2.isSingleChild;
|
|
104
|
-
return (0, _styledComponents.css)(["max-width:", ";"], isSingleChild ? '100%' : "calc(100% - ".concat(_constants.
|
|
128
|
+
return (0, _styledComponents.css)(["max-width:", ";border-width:", ";"], isSingleChild ? '100%' : "calc(100% - ".concat(_constants.ACTION_WIDTH, "px)"), isSingleChild ? '0' : '1px');
|
|
105
129
|
}, (0, _rem.default)(_constants.ICON_CONTENT_MARGIN), getContentMaxWidth);
|
|
106
130
|
|
|
107
131
|
var contentSVGColor = function contentSVGColor(_ref3) {
|
|
@@ -115,10 +139,61 @@ var contentSVGColor = function contentSVGColor(_ref3) {
|
|
|
115
139
|
return null;
|
|
116
140
|
};
|
|
117
141
|
|
|
118
|
-
var
|
|
142
|
+
var getColorByProps = function getColorByProps(_ref4) {
|
|
143
|
+
var variant = _ref4.variant,
|
|
144
|
+
colorProp = _ref4.color,
|
|
145
|
+
_ref4$palette = _ref4.palette,
|
|
146
|
+
palette = _ref4$palette === void 0 ? 'bright' : _ref4$palette;
|
|
147
|
+
if (variant === 'outline') return _objectSpread({}, _designTokens.color.base.snowWhite, {
|
|
148
|
+
fg: _designTokens.color.base.alaskanHusky
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
if (colorProp && colorProp in _commonUIColors.commonUIThreeShadeColors) {
|
|
152
|
+
var baseColor = _commonUIColors.commonUIThreeShadeColors[colorProp];
|
|
153
|
+
var fgColor = FG_COLOR[palette];
|
|
154
|
+
var bgColor = baseColor[PALETTE_MAPPER[palette]];
|
|
155
|
+
return palette === 'bright' ? bgColor : _objectSpread({}, bgColor, {
|
|
156
|
+
fg: fgColor
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return _commonUIColors.commonUIColors.licoriceMousse;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
var colorModifiers = function colorModifiers(props) {
|
|
164
|
+
var _props$palette = props.palette,
|
|
165
|
+
palette = _props$palette === void 0 ? 'bright' : _props$palette;
|
|
166
|
+
|
|
167
|
+
var borderColor = _objectSpread({}, _designTokens.color.base.charcoal, {
|
|
168
|
+
alpha: BORDER_OPACITY[palette]
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
return (0, _styledComponents.css)(["", ";border:1px solid ", ";", ""], (0, _color.default)(getColorByProps(props)), (0, _toColorString.default)(borderColor), (0, _styleModifiers.when)('isSingleChild', false, (0, _styledComponents.css)(["&:hover{box-shadow:inset 0 0 0 ", " ", ";", "{border-color:transparent;}}"], (0, _rem.default)(100), (0, _toColorString.default)(borderColor), Content)));
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
var variantModifiers = function variantModifiers(props) {
|
|
175
|
+
var _props$variant = props.variant,
|
|
176
|
+
variant = _props$variant === void 0 ? 'normal' : _props$variant;
|
|
177
|
+
if (variant === 'normal') return undefined;
|
|
178
|
+
return (0, _styledComponents.css)(["border:1px solid ", ";", " &:focus{border:1px solid ", ";", ";}"], (0, _toColorString.default)(_designTokens.color.opacity.charcoal15), (0, _styleModifiers.when)('isSingleChild', false, (0, _styledComponents.css)(["&:hover{box-shadow:none;background-color:", ";}"], (0, _toColorString.default)(_objectSpread({}, _designTokens.color.base.charcoal, {
|
|
179
|
+
alpha: 0.07
|
|
180
|
+
})))), (0, _toColorString.default)(_designTokens.color.interaction.pacificOcean), (0, _focusRingWithColor.default)(_designTokens.color.interaction.pacificOcean40));
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
var actionColors = {
|
|
184
|
+
normal: (0, _toColorString.default)(interactionColors.indianOcean),
|
|
185
|
+
danger: (0, _toColorString.default)(statusColors.danger.medium)
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
var actionColor = function actionColor(_ref5) {
|
|
189
|
+
var actionIntent = _ref5.actionIntent;
|
|
190
|
+
return actionColors[actionIntent !== 'danger' ? 'normal' : 'danger'];
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
var Container = (0, _styledComponents.default)(_BaseButton.default).withConfig({
|
|
119
194
|
displayName: "Tag__Container",
|
|
120
195
|
componentId: "nifm8a-1"
|
|
121
|
-
})(["font-family:", ";font-size:", ";font-weight:", ";align-items:center;border-radius:", ";
|
|
196
|
+
})(["font-family:", ";font-size:", ";font-weight:", ";align-items:center;border-radius:", ";display:inline-flex;height:", ";max-width:100%;min-width:", ";padding:0;background-color:transparent;&:focus{border:1px solid ", ";", ";", "{height:", ";box-shadow:none;}}&:focus-visible{outline:none;}&:hover{", "{color:", ";}}", ";", ";", ";"], _designTokens.typography.typeface.default, (0, _rem.default)(_designTokens.typography.size.alias.default), _designTokens.typography.weight.alias.default, (0, _rem.default)(10), (0, _rem.default)(20), (0, _rem.default)(26), (0, _toColorString.default)(_designTokens.color.base.blackSheep), (0, _focusRingWithColor.default)(_designTokens.color.opacity.charcoal40), _Action.ActionContainer, (0, _rem.default)(14), _Action.default, actionColor, colorModifiers, variantModifiers, contentSVGColor);
|
|
122
197
|
|
|
123
198
|
function Tag(props, containerRef) {
|
|
124
199
|
var action = props.action,
|
|
@@ -128,50 +203,44 @@ function Tag(props, containerRef) {
|
|
|
128
203
|
actionRef = props.actionRef,
|
|
129
204
|
Icon = props.icon,
|
|
130
205
|
text = props.text,
|
|
131
|
-
|
|
206
|
+
palette = props.palette,
|
|
207
|
+
rest = _objectWithoutProperties(props, ["action", "actionAttributes", "actionIcon", "actionIntent", "actionRef", "icon", "text", "palette"]);
|
|
132
208
|
|
|
133
209
|
var _useState = (0, _react.useState)(false),
|
|
134
210
|
_useState2 = _slicedToArray(_useState, 2),
|
|
135
211
|
isFocused = _useState2[0],
|
|
136
212
|
setIsFocused = _useState2[1];
|
|
137
213
|
|
|
138
|
-
var
|
|
139
|
-
var
|
|
214
|
+
var onTagFocus = (0, _react.useCallback)(function (e) {
|
|
215
|
+
var _ref6 = actionAttributes || {
|
|
140
216
|
onFocus: undefined
|
|
141
217
|
},
|
|
142
|
-
onFocus =
|
|
218
|
+
onFocus = _ref6.onFocus;
|
|
143
219
|
|
|
144
220
|
setIsFocused(true);
|
|
145
221
|
onFocus && onFocus(e);
|
|
146
222
|
}, [actionAttributes]);
|
|
147
|
-
var
|
|
148
|
-
var
|
|
223
|
+
var onTagBlur = (0, _react.useCallback)(function (e) {
|
|
224
|
+
var _ref7 = actionAttributes || {
|
|
149
225
|
onBlur: undefined
|
|
150
226
|
},
|
|
151
|
-
onBlur =
|
|
227
|
+
onBlur = _ref7.onBlur;
|
|
152
228
|
|
|
153
229
|
setIsFocused(false);
|
|
154
230
|
onBlur && onBlur(e);
|
|
155
231
|
}, [actionAttributes]);
|
|
156
|
-
var
|
|
232
|
+
var ActionElement = (0, _react.useMemo)(function () {
|
|
157
233
|
if (!text || !action || !actionIcon) {
|
|
158
234
|
return null;
|
|
159
235
|
}
|
|
160
236
|
|
|
161
237
|
var ActionIcon = actionIcon;
|
|
162
|
-
return _react.default.createElement(
|
|
163
|
-
|
|
164
|
-
}, _react.default.createElement(
|
|
165
|
-
ref: actionRef,
|
|
166
|
-
type: "button",
|
|
167
|
-
onBlur: onActionBlur,
|
|
168
|
-
onClick: action,
|
|
169
|
-
onFocus: onActionFocus,
|
|
170
|
-
actionIntent: actionIntent
|
|
171
|
-
}), _react.default.createElement(ActionIcon, {
|
|
238
|
+
return _react.default.createElement(_Action.ActionContainer, null, _react.default.createElement(_Action.default, {
|
|
239
|
+
ref: actionRef
|
|
240
|
+
}, _react.default.createElement(ActionIcon, {
|
|
172
241
|
size: "small"
|
|
173
242
|
})));
|
|
174
|
-
}, [text, action, actionRef,
|
|
243
|
+
}, [text, action, actionRef, actionIcon]);
|
|
175
244
|
var contentIsSingleChild = !action || !!action && !text;
|
|
176
245
|
/**
|
|
177
246
|
* We render the "content" twice below. The first one is visible to the user
|
|
@@ -182,9 +251,17 @@ function Tag(props, containerRef) {
|
|
|
182
251
|
* seconds content component, and calculate the max width of the container.
|
|
183
252
|
*/
|
|
184
253
|
|
|
185
|
-
return _react.default.createElement(Container, _extends({}, rest, {
|
|
186
|
-
|
|
254
|
+
return _react.default.createElement(Container, _extends({}, rest, actionAttributes, {
|
|
255
|
+
isSingleChild: contentIsSingleChild,
|
|
256
|
+
palette: palette,
|
|
257
|
+
ref: containerRef,
|
|
258
|
+
onBlur: onTagBlur,
|
|
259
|
+
onClick: action,
|
|
260
|
+
onFocus: onTagFocus,
|
|
261
|
+
isFocused: isFocused,
|
|
262
|
+
actionIntent: actionIntent
|
|
187
263
|
}), _react.default.createElement(Content, {
|
|
264
|
+
palette: palette,
|
|
188
265
|
hasIcon: !!Icon,
|
|
189
266
|
isSingleChild: contentIsSingleChild
|
|
190
267
|
}, Icon && _react.default.createElement(Icon, {
|
|
@@ -194,7 +271,7 @@ function Tag(props, containerRef) {
|
|
|
194
271
|
color: "inherit",
|
|
195
272
|
size: "small",
|
|
196
273
|
truncate: true
|
|
197
|
-
}, text)),
|
|
274
|
+
}, text)), ActionElement);
|
|
198
275
|
}
|
|
199
276
|
|
|
200
277
|
var TagWithRef = (0, _react.forwardRef)(Tag); // @ts-ignore
|