@spaced-out/ui-design-system 0.0.57 → 0.0.58
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/CHANGELOG.md +7 -0
- package/lib/components/Toast/Toast.js +23 -13
- package/lib/components/Toast/Toast.js.flow +32 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.0.58](https://github.com/spaced-out/ui-design-system/compare/v0.0.57...v0.0.58) (2023-03-25)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* custom icon support in toast ([#83](https://github.com/spaced-out/ui-design-system/issues/83)) ([e6deaf8](https://github.com/spaced-out/ui-design-system/commit/e6deaf82ac3fc284beafb61003efc448bcd5c992))
|
|
11
|
+
|
|
5
12
|
### [0.0.57](https://github.com/spaced-out/ui-design-system/compare/v0.0.56...v0.0.57) (2023-03-24)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -13,19 +13,21 @@ var _ToastModule = _interopRequireDefault(require("./Toast.module.css"));
|
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
14
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
15
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
16
|
-
|
|
16
|
+
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); }
|
|
17
17
|
const TOAST_SEMANTIC = Object.freeze({
|
|
18
18
|
success: 'success',
|
|
19
19
|
information: 'information',
|
|
20
20
|
warning: 'warning',
|
|
21
|
-
danger: 'danger'
|
|
21
|
+
danger: 'danger',
|
|
22
|
+
primary: 'primary'
|
|
22
23
|
});
|
|
23
24
|
exports.TOAST_SEMANTIC = TOAST_SEMANTIC;
|
|
24
25
|
const TOAST_TITLE_COLOR = {
|
|
25
26
|
success: _Text.TEXT_COLORS.success,
|
|
26
27
|
information: _Text.TEXT_COLORS.information,
|
|
27
28
|
warning: _Text.TEXT_COLORS.warning,
|
|
28
|
-
danger: _Text.TEXT_COLORS.danger
|
|
29
|
+
danger: _Text.TEXT_COLORS.danger,
|
|
30
|
+
primary: _Text.TEXT_COLORS.primary
|
|
29
31
|
};
|
|
30
32
|
const ToastIcon = _ref => {
|
|
31
33
|
let {
|
|
@@ -71,17 +73,22 @@ const ToastIcon = _ref => {
|
|
|
71
73
|
};
|
|
72
74
|
const ToastTitle = _ref2 => {
|
|
73
75
|
let {
|
|
74
|
-
children
|
|
76
|
+
children,
|
|
77
|
+
semantic = '',
|
|
78
|
+
...props
|
|
75
79
|
} = _ref2;
|
|
76
|
-
return
|
|
80
|
+
return /*#__PURE__*/React.createElement(_Text.SubTitleSmall, _extends({
|
|
81
|
+
color: TOAST_TITLE_COLOR[semantic]
|
|
82
|
+
}, props), children);
|
|
77
83
|
};
|
|
78
84
|
exports.ToastTitle = ToastTitle;
|
|
79
85
|
ToastTitle.displayName = 'ToastTitle';
|
|
80
86
|
const ToastBody = _ref3 => {
|
|
81
87
|
let {
|
|
82
|
-
children
|
|
88
|
+
children,
|
|
89
|
+
...props
|
|
83
90
|
} = _ref3;
|
|
84
|
-
return children;
|
|
91
|
+
return /*#__PURE__*/React.createElement(_Text.BodyMedium, props, children);
|
|
85
92
|
};
|
|
86
93
|
exports.ToastBody = ToastBody;
|
|
87
94
|
ToastBody.displayName = 'ToastBody';
|
|
@@ -132,7 +139,8 @@ const Toast = _ref5 => {
|
|
|
132
139
|
time,
|
|
133
140
|
semantic = TOAST_SEMANTIC.success,
|
|
134
141
|
onClose,
|
|
135
|
-
initialFocus = -1
|
|
142
|
+
initialFocus = -1,
|
|
143
|
+
customIcon
|
|
136
144
|
} = _ref5;
|
|
137
145
|
const {
|
|
138
146
|
floating,
|
|
@@ -144,7 +152,9 @@ const Toast = _ref5 => {
|
|
|
144
152
|
const nodes = [];
|
|
145
153
|
for (const child of childrenArray) {
|
|
146
154
|
if (child?.type?.displayName === comp) {
|
|
147
|
-
nodes.push(child
|
|
155
|
+
nodes.push( /*#__PURE__*/React.cloneElement(child, {
|
|
156
|
+
semantic
|
|
157
|
+
}));
|
|
148
158
|
}
|
|
149
159
|
}
|
|
150
160
|
return nodes.length > 1 ? nodes : nodes[0];
|
|
@@ -162,7 +172,7 @@ const Toast = _ref5 => {
|
|
|
162
172
|
}, /*#__PURE__*/React.createElement("div", {
|
|
163
173
|
className: (0, _classify.default)(_ToastModule.default.toastContainer, classNames?.wrapper),
|
|
164
174
|
ref: floating
|
|
165
|
-
}, /*#__PURE__*/React.createElement(ToastIcon, {
|
|
175
|
+
}, customIcon || /*#__PURE__*/React.createElement(ToastIcon, {
|
|
166
176
|
semantic: semantic
|
|
167
177
|
}), /*#__PURE__*/React.createElement("div", {
|
|
168
178
|
className: _ToastModule.default.toastMidSection
|
|
@@ -170,9 +180,9 @@ const Toast = _ref5 => {
|
|
|
170
180
|
className: _ToastModule.default.contentWrap
|
|
171
181
|
}, /*#__PURE__*/React.createElement("div", {
|
|
172
182
|
className: _ToastModule.default.titleBodyWrap
|
|
173
|
-
}, /*#__PURE__*/React.createElement(_Text.
|
|
174
|
-
|
|
175
|
-
},
|
|
183
|
+
}, getComp('ToastTitle'), getComp('ToastBody')), time && /*#__PURE__*/React.createElement(_Text.SubTitleExtraSmall, {
|
|
184
|
+
className: classNames?.time
|
|
185
|
+
}, time)), footerWithClose), /*#__PURE__*/React.createElement(_Icon.CloseIcon, {
|
|
176
186
|
className: _ToastModule.default.closeIcon,
|
|
177
187
|
onClick: onClose,
|
|
178
188
|
ariaLabel: "Close Button"
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
useFloating,
|
|
9
9
|
} from '@floating-ui/react-dom-interactions';
|
|
10
10
|
|
|
11
|
+
import type {ColorTypes} from '../../types/typography';
|
|
11
12
|
import classify from '../../utils/classify';
|
|
12
13
|
import {CloseIcon, Icon} from '../Icon';
|
|
13
14
|
import {
|
|
@@ -20,13 +21,14 @@ import {
|
|
|
20
21
|
import css from './Toast.module.css';
|
|
21
22
|
|
|
22
23
|
|
|
23
|
-
type ClassNames = $ReadOnly<{wrapper?: string}>;
|
|
24
|
+
type ClassNames = $ReadOnly<{wrapper?: string, time?: string}>;
|
|
24
25
|
|
|
25
26
|
export const TOAST_SEMANTIC = Object.freeze({
|
|
26
27
|
success: 'success',
|
|
27
28
|
information: 'information',
|
|
28
29
|
warning: 'warning',
|
|
29
30
|
danger: 'danger',
|
|
31
|
+
primary: 'primary',
|
|
30
32
|
});
|
|
31
33
|
|
|
32
34
|
const TOAST_TITLE_COLOR = {
|
|
@@ -34,6 +36,7 @@ const TOAST_TITLE_COLOR = {
|
|
|
34
36
|
information: TEXT_COLORS.information,
|
|
35
37
|
warning: TEXT_COLORS.warning,
|
|
36
38
|
danger: TEXT_COLORS.danger,
|
|
39
|
+
primary: TEXT_COLORS.primary,
|
|
37
40
|
};
|
|
38
41
|
|
|
39
42
|
export type ToastSemanticType = $Values<typeof TOAST_SEMANTIC>;
|
|
@@ -45,6 +48,7 @@ export type ToastProps = {
|
|
|
45
48
|
semantic?: ToastSemanticType,
|
|
46
49
|
onClose?: () => void,
|
|
47
50
|
initialFocus?: number,
|
|
51
|
+
customIcon?: React.Node,
|
|
48
52
|
};
|
|
49
53
|
|
|
50
54
|
const ToastIcon = ({semantic}: {semantic: ToastSemanticType}) => {
|
|
@@ -103,17 +107,32 @@ const ToastIcon = ({semantic}: {semantic: ToastSemanticType}) => {
|
|
|
103
107
|
|
|
104
108
|
export type ToastTitleProps = {
|
|
105
109
|
children?: React.Node,
|
|
110
|
+
className?: string,
|
|
111
|
+
semantic?: ToastSemanticType,
|
|
112
|
+
color?: ColorTypes,
|
|
106
113
|
};
|
|
107
114
|
|
|
108
|
-
export const ToastTitle = ({
|
|
115
|
+
export const ToastTitle = ({
|
|
116
|
+
children,
|
|
117
|
+
semantic = '',
|
|
118
|
+
...props
|
|
119
|
+
}: ToastTitleProps): React.Node => (
|
|
120
|
+
<SubTitleSmall color={TOAST_TITLE_COLOR[semantic]} {...props}>
|
|
121
|
+
{children}
|
|
122
|
+
</SubTitleSmall>
|
|
123
|
+
);
|
|
109
124
|
|
|
110
125
|
ToastTitle.displayName = 'ToastTitle';
|
|
111
126
|
|
|
112
127
|
export type ToastBodyProps = {
|
|
113
128
|
children?: React.Node,
|
|
129
|
+
className?: string,
|
|
130
|
+
color?: ColorTypes,
|
|
114
131
|
};
|
|
115
132
|
|
|
116
|
-
export const ToastBody = ({children}: ToastBodyProps): React.Node =>
|
|
133
|
+
export const ToastBody = ({children, ...props}: ToastBodyProps): React.Node => (
|
|
134
|
+
<BodyMedium {...props}>{children}</BodyMedium>
|
|
135
|
+
);
|
|
117
136
|
|
|
118
137
|
ToastBody.displayName = 'ToastBody';
|
|
119
138
|
|
|
@@ -170,6 +189,7 @@ export const Toast = ({
|
|
|
170
189
|
semantic = TOAST_SEMANTIC.success,
|
|
171
190
|
onClose,
|
|
172
191
|
initialFocus = -1,
|
|
192
|
+
customIcon,
|
|
173
193
|
}: ToastProps): React.Node => {
|
|
174
194
|
const {floating, context} = useFloating();
|
|
175
195
|
|
|
@@ -179,7 +199,7 @@ export const Toast = ({
|
|
|
179
199
|
const nodes: React.Node[] = [];
|
|
180
200
|
for (const child of childrenArray) {
|
|
181
201
|
if (child?.type?.displayName === comp) {
|
|
182
|
-
nodes.push(child);
|
|
202
|
+
nodes.push(React.cloneElement(child, {semantic}));
|
|
183
203
|
}
|
|
184
204
|
}
|
|
185
205
|
return nodes.length > 1 ? nodes : nodes[0];
|
|
@@ -197,16 +217,18 @@ export const Toast = ({
|
|
|
197
217
|
className={classify(css.toastContainer, classNames?.wrapper)}
|
|
198
218
|
ref={floating}
|
|
199
219
|
>
|
|
200
|
-
<ToastIcon semantic={semantic} />
|
|
220
|
+
{customIcon || <ToastIcon semantic={semantic} />}
|
|
201
221
|
<div className={css.toastMidSection}>
|
|
202
222
|
<div className={css.contentWrap}>
|
|
203
223
|
<div className={css.titleBodyWrap}>
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
</SubTitleSmall>
|
|
207
|
-
<BodyMedium>{getComp('ToastBody')}</BodyMedium>
|
|
224
|
+
{getComp('ToastTitle')}
|
|
225
|
+
{getComp('ToastBody')}
|
|
208
226
|
</div>
|
|
209
|
-
{time &&
|
|
227
|
+
{time && (
|
|
228
|
+
<SubTitleExtraSmall className={classNames?.time}>
|
|
229
|
+
{time}
|
|
230
|
+
</SubTitleExtraSmall>
|
|
231
|
+
)}
|
|
210
232
|
</div>
|
|
211
233
|
{footerWithClose}
|
|
212
234
|
</div>
|