@canonical/react-components 2.11.0 → 2.12.0
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/dist/components/Chip/Chip.d.ts +26 -2
- package/dist/components/Chip/Chip.js +18 -4
- package/dist/components/Chip/Chip.stories.d.ts +5 -0
- package/dist/components/Chip/Chip.stories.js +43 -1
- package/dist/components/StatusLabel/StatusLabel.d.ts +1 -1
- package/dist/components/StatusLabel/StatusLabel.js +1 -1
- package/dist/esm/components/Chip/Chip.d.ts +26 -2
- package/dist/esm/components/Chip/Chip.js +19 -5
- package/dist/esm/components/Chip/Chip.stories.d.ts +5 -0
- package/dist/esm/components/Chip/Chip.stories.js +42 -0
- package/dist/esm/components/StatusLabel/StatusLabel.d.ts +1 -1
- package/dist/esm/components/StatusLabel/StatusLabel.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { type ReactNode } from "react";
|
|
2
2
|
import type { MouseEvent, HTMLProps } from "react";
|
|
3
3
|
import { ValueOf, PropsWithSpread } from "../../types";
|
|
4
|
+
import { ICONS } from "../Icon";
|
|
4
5
|
export declare enum Label {
|
|
5
6
|
Dismiss = "Dismiss"
|
|
6
7
|
}
|
|
@@ -15,6 +16,29 @@ export type Props = PropsWithSpread<{
|
|
|
15
16
|
* The appearance of the chip.
|
|
16
17
|
*/
|
|
17
18
|
appearance?: ValueOf<typeof ChipType>;
|
|
19
|
+
/**
|
|
20
|
+
* Whether the chip is read-only.
|
|
21
|
+
* If true, the chip will not be interactive.
|
|
22
|
+
*/
|
|
23
|
+
isReadOnly?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* A badge to display on the chip.
|
|
26
|
+
*/
|
|
27
|
+
badge?: ReactNode;
|
|
28
|
+
/**
|
|
29
|
+
* The name of an icon to display on the chip.
|
|
30
|
+
*/
|
|
31
|
+
iconName?: ValueOf<typeof ICONS> | string;
|
|
32
|
+
/**
|
|
33
|
+
* Whether the chip is dense.
|
|
34
|
+
* Reduces the height of the chip by removing padding.
|
|
35
|
+
*/
|
|
36
|
+
isDense?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Whether the chip is inline.
|
|
39
|
+
* If true, the chip will be displayed inline with other content (such as text).
|
|
40
|
+
*/
|
|
41
|
+
isInline?: boolean;
|
|
18
42
|
/**
|
|
19
43
|
* The lead for the chip.
|
|
20
44
|
*/
|
|
@@ -53,5 +77,5 @@ export type Props = PropsWithSpread<{
|
|
|
53
77
|
*
|
|
54
78
|
* It can be used to display a small value attached to a component.
|
|
55
79
|
*/
|
|
56
|
-
declare const Chip: ({ appearance, lead, onClick, onDismiss, quoteValue, selected, subString, value, ...props }: Props) => React.JSX.Element;
|
|
80
|
+
declare const Chip: ({ appearance, lead, onClick, onDismiss, quoteValue, selected, subString, isReadOnly, isDense, isInline, iconName, badge, value, ...props }: Props) => React.JSX.Element;
|
|
57
81
|
export default Chip;
|
|
@@ -33,6 +33,11 @@ const Chip = _ref => {
|
|
|
33
33
|
quoteValue,
|
|
34
34
|
selected,
|
|
35
35
|
subString = "",
|
|
36
|
+
isReadOnly = false,
|
|
37
|
+
isDense = false,
|
|
38
|
+
isInline = false,
|
|
39
|
+
iconName,
|
|
40
|
+
badge,
|
|
36
41
|
value,
|
|
37
42
|
...props
|
|
38
43
|
} = _ref;
|
|
@@ -50,19 +55,28 @@ const Chip = _ref => {
|
|
|
50
55
|
}
|
|
51
56
|
};
|
|
52
57
|
const chipValue = (0, _utils.highlightSubString)(value, subString).text;
|
|
53
|
-
const chipContent = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null,
|
|
58
|
+
const chipContent = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, iconName && /*#__PURE__*/_react.default.createElement("i", {
|
|
59
|
+
className: "p-icon--".concat(iconName)
|
|
60
|
+
}), lead && /*#__PURE__*/_react.default.createElement("span", {
|
|
54
61
|
className: "p-chip__lead"
|
|
55
62
|
}, lead.toUpperCase()), /*#__PURE__*/_react.default.createElement("span", {
|
|
56
63
|
className: "p-chip__value",
|
|
57
64
|
dangerouslySetInnerHTML: {
|
|
58
65
|
__html: quoteValue ? "'".concat(chipValue, "'") : chipValue
|
|
59
66
|
}
|
|
60
|
-
}));
|
|
67
|
+
}), badge && badge);
|
|
61
68
|
const chipClassName = (0, _classnames.default)({
|
|
62
69
|
["p-chip--".concat(appearance)]: !!appearance,
|
|
63
|
-
"p-chip": !appearance
|
|
70
|
+
"p-chip": !appearance,
|
|
71
|
+
"is-dense": isDense,
|
|
72
|
+
"is-readonly": isReadOnly,
|
|
73
|
+
"is-inline": isInline
|
|
64
74
|
}, props.className);
|
|
65
|
-
if (
|
|
75
|
+
if (isReadOnly) {
|
|
76
|
+
return /*#__PURE__*/_react.default.createElement("span", _extends({}, props, {
|
|
77
|
+
className: chipClassName
|
|
78
|
+
}), chipContent);
|
|
79
|
+
} else if (onDismiss) {
|
|
66
80
|
return /*#__PURE__*/_react.default.createElement("span", _extends({}, props, {
|
|
67
81
|
className: chipClassName
|
|
68
82
|
}), chipContent, /*#__PURE__*/_react.default.createElement("button", {
|
|
@@ -7,3 +7,8 @@ export declare const Default: Story;
|
|
|
7
7
|
export declare const LeadValue: Story;
|
|
8
8
|
export declare const Appearance: Story;
|
|
9
9
|
export declare const Dismissible: Story;
|
|
10
|
+
export declare const Dense: Story;
|
|
11
|
+
export declare const Inline: Story;
|
|
12
|
+
export declare const ReadOnly: Story;
|
|
13
|
+
export declare const WithIcon: Story;
|
|
14
|
+
export declare const WithBadge: Story;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.LeadValue = exports.Dismissible = exports.Default = exports.Appearance = void 0;
|
|
6
|
+
exports.default = exports.WithIcon = exports.WithBadge = exports.ReadOnly = exports.LeadValue = exports.Inline = exports.Dismissible = exports.Dense = exports.Default = exports.Appearance = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _Chip = _interopRequireDefault(require("./Chip"));
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -42,4 +42,46 @@ const Dismissible = exports.Dismissible = {
|
|
|
42
42
|
}
|
|
43
43
|
}),
|
|
44
44
|
name: "Dismissible"
|
|
45
|
+
};
|
|
46
|
+
const Dense = exports.Dense = {
|
|
47
|
+
render: () => /*#__PURE__*/_react.default.createElement(_Chip.default, {
|
|
48
|
+
lead: "Owner",
|
|
49
|
+
value: "Bob",
|
|
50
|
+
isDense: true
|
|
51
|
+
}),
|
|
52
|
+
name: "Dense"
|
|
53
|
+
};
|
|
54
|
+
const Inline = exports.Inline = {
|
|
55
|
+
render: () => /*#__PURE__*/_react.default.createElement("p", null, "This is text with an inline", " ", /*#__PURE__*/_react.default.createElement(_Chip.default, {
|
|
56
|
+
value: "chip",
|
|
57
|
+
isDense: true,
|
|
58
|
+
isInline: true
|
|
59
|
+
})),
|
|
60
|
+
name: "Inline"
|
|
61
|
+
};
|
|
62
|
+
const ReadOnly = exports.ReadOnly = {
|
|
63
|
+
render: () => /*#__PURE__*/_react.default.createElement(_Chip.default, {
|
|
64
|
+
lead: "Owner",
|
|
65
|
+
value: "Bob",
|
|
66
|
+
isReadOnly: true
|
|
67
|
+
}),
|
|
68
|
+
name: "Read-only"
|
|
69
|
+
};
|
|
70
|
+
const WithIcon = exports.WithIcon = {
|
|
71
|
+
render: () => /*#__PURE__*/_react.default.createElement(_Chip.default, {
|
|
72
|
+
value: "Users",
|
|
73
|
+
iconName: "user"
|
|
74
|
+
}),
|
|
75
|
+
name: "With Icon"
|
|
76
|
+
};
|
|
77
|
+
const WithBadge = exports.WithBadge = {
|
|
78
|
+
render: () => /*#__PURE__*/_react.default.createElement(_Chip.default, {
|
|
79
|
+
lead: "Owner",
|
|
80
|
+
value: "Bob",
|
|
81
|
+
badge: /*#__PURE__*/_react.default.createElement("span", {
|
|
82
|
+
className: "p-badge",
|
|
83
|
+
"aria-label": "More than 2.5 billion items"
|
|
84
|
+
}, "2.5B")
|
|
85
|
+
}),
|
|
86
|
+
name: "With Badge"
|
|
45
87
|
};
|
|
@@ -27,8 +27,8 @@ export type Props = PropsWithSpread<{
|
|
|
27
27
|
}, HTMLProps<HTMLDivElement>>;
|
|
28
28
|
/**
|
|
29
29
|
* This is a [React](https://reactjs.org/) component for the Vanilla [Label](https://vanillaframework.io/docs/patterns/labels).
|
|
30
|
-
*
|
|
31
30
|
* Labels are static elements which you can apply to signify status, tags or any other information you find useful.
|
|
31
|
+
* @deprecated StatusLabel is deprecated. Use Read-only Chip instead.
|
|
32
32
|
*/
|
|
33
33
|
declare const StatusLabel: ({ appearance, children, className, ...labelProps }: Props) => React.JSX.Element;
|
|
34
34
|
export default StatusLabel;
|
|
@@ -22,8 +22,8 @@ const StatusLabelAppearance = exports.StatusLabelAppearance = {
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* This is a [React](https://reactjs.org/) component for the Vanilla [Label](https://vanillaframework.io/docs/patterns/labels).
|
|
25
|
-
*
|
|
26
25
|
* Labels are static elements which you can apply to signify status, tags or any other information you find useful.
|
|
26
|
+
* @deprecated StatusLabel is deprecated. Use Read-only Chip instead.
|
|
27
27
|
*/
|
|
28
28
|
const StatusLabel = _ref => {
|
|
29
29
|
let {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { type ReactNode } from "react";
|
|
2
2
|
import type { MouseEvent, HTMLProps } from "react";
|
|
3
3
|
import { ValueOf, PropsWithSpread } from "../../types";
|
|
4
|
+
import { ICONS } from "../Icon";
|
|
4
5
|
export declare enum Label {
|
|
5
6
|
Dismiss = "Dismiss"
|
|
6
7
|
}
|
|
@@ -15,6 +16,29 @@ export type Props = PropsWithSpread<{
|
|
|
15
16
|
* The appearance of the chip.
|
|
16
17
|
*/
|
|
17
18
|
appearance?: ValueOf<typeof ChipType>;
|
|
19
|
+
/**
|
|
20
|
+
* Whether the chip is read-only.
|
|
21
|
+
* If true, the chip will not be interactive.
|
|
22
|
+
*/
|
|
23
|
+
isReadOnly?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* A badge to display on the chip.
|
|
26
|
+
*/
|
|
27
|
+
badge?: ReactNode;
|
|
28
|
+
/**
|
|
29
|
+
* The name of an icon to display on the chip.
|
|
30
|
+
*/
|
|
31
|
+
iconName?: ValueOf<typeof ICONS> | string;
|
|
32
|
+
/**
|
|
33
|
+
* Whether the chip is dense.
|
|
34
|
+
* Reduces the height of the chip by removing padding.
|
|
35
|
+
*/
|
|
36
|
+
isDense?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Whether the chip is inline.
|
|
39
|
+
* If true, the chip will be displayed inline with other content (such as text).
|
|
40
|
+
*/
|
|
41
|
+
isInline?: boolean;
|
|
18
42
|
/**
|
|
19
43
|
* The lead for the chip.
|
|
20
44
|
*/
|
|
@@ -53,5 +77,5 @@ export type Props = PropsWithSpread<{
|
|
|
53
77
|
*
|
|
54
78
|
* It can be used to display a small value attached to a component.
|
|
55
79
|
*/
|
|
56
|
-
declare const Chip: ({ appearance, lead, onClick, onDismiss, quoteValue, selected, subString, value, ...props }: Props) => React.JSX.Element;
|
|
80
|
+
declare const Chip: ({ appearance, lead, onClick, onDismiss, quoteValue, selected, subString, isReadOnly, isDense, isInline, iconName, badge, value, ...props }: Props) => React.JSX.Element;
|
|
57
81
|
export default Chip;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["appearance", "lead", "onClick", "onDismiss", "quoteValue", "selected", "subString", "value"];
|
|
1
|
+
var _excluded = ["appearance", "lead", "onClick", "onDismiss", "quoteValue", "selected", "subString", "isReadOnly", "isDense", "isInline", "iconName", "badge", "value"];
|
|
2
2
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
|
|
3
3
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
4
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
@@ -29,6 +29,11 @@ var Chip = _ref => {
|
|
|
29
29
|
quoteValue,
|
|
30
30
|
selected,
|
|
31
31
|
subString = "",
|
|
32
|
+
isReadOnly = false,
|
|
33
|
+
isDense = false,
|
|
34
|
+
isInline = false,
|
|
35
|
+
iconName,
|
|
36
|
+
badge,
|
|
32
37
|
value
|
|
33
38
|
} = _ref,
|
|
34
39
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
@@ -46,19 +51,28 @@ var Chip = _ref => {
|
|
|
46
51
|
}
|
|
47
52
|
};
|
|
48
53
|
var chipValue = highlightSubString(value, subString).text;
|
|
49
|
-
var chipContent = /*#__PURE__*/React.createElement(React.Fragment, null,
|
|
54
|
+
var chipContent = /*#__PURE__*/React.createElement(React.Fragment, null, iconName && /*#__PURE__*/React.createElement("i", {
|
|
55
|
+
className: "p-icon--".concat(iconName)
|
|
56
|
+
}), lead && /*#__PURE__*/React.createElement("span", {
|
|
50
57
|
className: "p-chip__lead"
|
|
51
58
|
}, lead.toUpperCase()), /*#__PURE__*/React.createElement("span", {
|
|
52
59
|
className: "p-chip__value",
|
|
53
60
|
dangerouslySetInnerHTML: {
|
|
54
61
|
__html: quoteValue ? "'".concat(chipValue, "'") : chipValue
|
|
55
62
|
}
|
|
56
|
-
}));
|
|
63
|
+
}), badge && badge);
|
|
57
64
|
var chipClassName = classNames({
|
|
58
65
|
["p-chip--".concat(appearance)]: !!appearance,
|
|
59
|
-
"p-chip": !appearance
|
|
66
|
+
"p-chip": !appearance,
|
|
67
|
+
"is-dense": isDense,
|
|
68
|
+
"is-readonly": isReadOnly,
|
|
69
|
+
"is-inline": isInline
|
|
60
70
|
}, props.className);
|
|
61
|
-
if (
|
|
71
|
+
if (isReadOnly) {
|
|
72
|
+
return /*#__PURE__*/React.createElement("span", _extends({}, props, {
|
|
73
|
+
className: chipClassName
|
|
74
|
+
}), chipContent);
|
|
75
|
+
} else if (onDismiss) {
|
|
62
76
|
return /*#__PURE__*/React.createElement("span", _extends({}, props, {
|
|
63
77
|
className: chipClassName
|
|
64
78
|
}), chipContent, /*#__PURE__*/React.createElement("button", {
|
|
@@ -7,3 +7,8 @@ export declare const Default: Story;
|
|
|
7
7
|
export declare const LeadValue: Story;
|
|
8
8
|
export declare const Appearance: Story;
|
|
9
9
|
export declare const Dismissible: Story;
|
|
10
|
+
export declare const Dense: Story;
|
|
11
|
+
export declare const Inline: Story;
|
|
12
|
+
export declare const ReadOnly: Story;
|
|
13
|
+
export declare const WithIcon: Story;
|
|
14
|
+
export declare const WithBadge: Story;
|
|
@@ -35,4 +35,46 @@ export var Dismissible = {
|
|
|
35
35
|
}
|
|
36
36
|
}),
|
|
37
37
|
name: "Dismissible"
|
|
38
|
+
};
|
|
39
|
+
export var Dense = {
|
|
40
|
+
render: () => /*#__PURE__*/React.createElement(Chip, {
|
|
41
|
+
lead: "Owner",
|
|
42
|
+
value: "Bob",
|
|
43
|
+
isDense: true
|
|
44
|
+
}),
|
|
45
|
+
name: "Dense"
|
|
46
|
+
};
|
|
47
|
+
export var Inline = {
|
|
48
|
+
render: () => /*#__PURE__*/React.createElement("p", null, "This is text with an inline", " ", /*#__PURE__*/React.createElement(Chip, {
|
|
49
|
+
value: "chip",
|
|
50
|
+
isDense: true,
|
|
51
|
+
isInline: true
|
|
52
|
+
})),
|
|
53
|
+
name: "Inline"
|
|
54
|
+
};
|
|
55
|
+
export var ReadOnly = {
|
|
56
|
+
render: () => /*#__PURE__*/React.createElement(Chip, {
|
|
57
|
+
lead: "Owner",
|
|
58
|
+
value: "Bob",
|
|
59
|
+
isReadOnly: true
|
|
60
|
+
}),
|
|
61
|
+
name: "Read-only"
|
|
62
|
+
};
|
|
63
|
+
export var WithIcon = {
|
|
64
|
+
render: () => /*#__PURE__*/React.createElement(Chip, {
|
|
65
|
+
value: "Users",
|
|
66
|
+
iconName: "user"
|
|
67
|
+
}),
|
|
68
|
+
name: "With Icon"
|
|
69
|
+
};
|
|
70
|
+
export var WithBadge = {
|
|
71
|
+
render: () => /*#__PURE__*/React.createElement(Chip, {
|
|
72
|
+
lead: "Owner",
|
|
73
|
+
value: "Bob",
|
|
74
|
+
badge: /*#__PURE__*/React.createElement("span", {
|
|
75
|
+
className: "p-badge",
|
|
76
|
+
"aria-label": "More than 2.5 billion items"
|
|
77
|
+
}, "2.5B")
|
|
78
|
+
}),
|
|
79
|
+
name: "With Badge"
|
|
38
80
|
};
|
|
@@ -27,8 +27,8 @@ export type Props = PropsWithSpread<{
|
|
|
27
27
|
}, HTMLProps<HTMLDivElement>>;
|
|
28
28
|
/**
|
|
29
29
|
* This is a [React](https://reactjs.org/) component for the Vanilla [Label](https://vanillaframework.io/docs/patterns/labels).
|
|
30
|
-
*
|
|
31
30
|
* Labels are static elements which you can apply to signify status, tags or any other information you find useful.
|
|
31
|
+
* @deprecated StatusLabel is deprecated. Use Read-only Chip instead.
|
|
32
32
|
*/
|
|
33
33
|
declare const StatusLabel: ({ appearance, children, className, ...labelProps }: Props) => React.JSX.Element;
|
|
34
34
|
export default StatusLabel;
|
|
@@ -18,8 +18,8 @@ export var StatusLabelAppearance = {
|
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* This is a [React](https://reactjs.org/) component for the Vanilla [Label](https://vanillaframework.io/docs/patterns/labels).
|
|
21
|
-
*
|
|
22
21
|
* Labels are static elements which you can apply to signify status, tags or any other information you find useful.
|
|
22
|
+
* @deprecated StatusLabel is deprecated. Use Read-only Chip instead.
|
|
23
23
|
*/
|
|
24
24
|
var StatusLabel = _ref => {
|
|
25
25
|
var {
|