@pingux/astro 2.178.4-alpha.0 → 2.180.1-alpha.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/lib/cjs/components/Avatar/Avatar.js +8 -6
- package/lib/cjs/components/Avatar/Avatar.test.js +57 -0
- package/lib/cjs/components/Icon/Icon.stories.js +8 -8
- package/lib/cjs/libs/astro/src/types/avatar.d.ts +1 -1
- package/lib/cjs/libs/astro/tsconfig.lib.tsbuildinfo +1 -1
- package/lib/components/Avatar/Avatar.js +8 -6
- package/lib/components/Avatar/Avatar.test.js +57 -0
- package/lib/components/Icon/Icon.stories.js +8 -8
- package/package.json +6 -11
|
@@ -44,14 +44,16 @@ var Avatar = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
44
44
|
isSquare = props.isSquare,
|
|
45
45
|
isLogo = props.isLogo,
|
|
46
46
|
others = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
var safeColorId = colorId || '_INTERNAL_DEFAULT_ID_';
|
|
48
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
49
|
+
if (!src && !color && !colorId) {
|
|
50
|
+
console.warn("[Astro] Avatar: No 'src', 'color', or 'colorId' provided. " + 'The component is falling back to a default generated color.');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
50
53
|
var finalColor = (0, _react.useMemo)(function () {
|
|
51
54
|
if (color) return color;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}, [color, colorId, _constants.avatarColors]);
|
|
55
|
+
return (0, _getColorFromUuid["default"])(safeColorId, _constants.avatarColors);
|
|
56
|
+
}, [color, safeColorId]);
|
|
55
57
|
var _useStatusClasses = (0, _hooks.useStatusClasses)(className, (0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, "is-".concat(finalColor), finalColor), "size-".concat(size), size), "font-size-".concat(size), src ? false : size), 'is-square', isSquare), 'is-image', src), 'is-logo', isLogo)),
|
|
56
58
|
classNames = _useStatusClasses.classNames;
|
|
57
59
|
if (src) {
|
|
@@ -46,12 +46,14 @@ test('an avatar is rendered with custom alt', function () {
|
|
|
46
46
|
expect(img).toHaveAttribute('alt', 'Custom Alt');
|
|
47
47
|
});
|
|
48
48
|
test('an avatar is rendered with custom alt', function () {
|
|
49
|
+
var warnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
49
50
|
getComponent({
|
|
50
51
|
src: undefined,
|
|
51
52
|
defaultText: 'KL'
|
|
52
53
|
});
|
|
53
54
|
var avatar = _testWrapper.screen.getByText('KL');
|
|
54
55
|
expect(avatar).toBeInTheDocument();
|
|
56
|
+
warnSpy.mockRestore();
|
|
55
57
|
});
|
|
56
58
|
describe('getColorFromUUID', function () {
|
|
57
59
|
test('returns a consistent color for the same UUID', function () {
|
|
@@ -110,6 +112,61 @@ describe('getColorFromUUID', function () {
|
|
|
110
112
|
expect(avatar).toHaveClass('is-green');
|
|
111
113
|
});
|
|
112
114
|
});
|
|
115
|
+
describe('Avatar fallback behavior', function () {
|
|
116
|
+
test('warns in development when no src, color, or colorId is provided', function () {
|
|
117
|
+
var warnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
118
|
+
getComponent({
|
|
119
|
+
src: undefined
|
|
120
|
+
});
|
|
121
|
+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("No 'src', 'color', or 'colorId' provided"));
|
|
122
|
+
warnSpy.mockRestore();
|
|
123
|
+
});
|
|
124
|
+
test('does not crash when colorId is null', function () {
|
|
125
|
+
var warnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
126
|
+
getComponent({
|
|
127
|
+
src: undefined,
|
|
128
|
+
colorId: null
|
|
129
|
+
});
|
|
130
|
+
var avatar = _testWrapper.screen.getByTestId(datatestId);
|
|
131
|
+
var classList = (0, _from["default"])(avatar.classList);
|
|
132
|
+
var colorClass = (0, _find["default"])(classList).call(classList, function (cls) {
|
|
133
|
+
return (0, _startsWith["default"])(cls).call(cls, 'is-');
|
|
134
|
+
});
|
|
135
|
+
expect(colorClass).toBeDefined();
|
|
136
|
+
warnSpy.mockRestore();
|
|
137
|
+
});
|
|
138
|
+
test('two avatars with missing colorId get the same color class', function () {
|
|
139
|
+
var _context, _context2;
|
|
140
|
+
var warnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
141
|
+
var _render = (0, _testWrapper.render)((0, _react2.jsx)(_["default"], {
|
|
142
|
+
"data-testid": "avatar-1"
|
|
143
|
+
})),
|
|
144
|
+
unmount = _render.unmount;
|
|
145
|
+
var avatar1 = _testWrapper.screen.getByTestId('avatar-1');
|
|
146
|
+
var colorClass1 = (0, _find["default"])(_context = (0, _from["default"])(avatar1.classList)).call(_context, function (cls) {
|
|
147
|
+
return (0, _startsWith["default"])(cls).call(cls, 'is-');
|
|
148
|
+
});
|
|
149
|
+
unmount();
|
|
150
|
+
(0, _testWrapper.render)((0, _react2.jsx)(_["default"], {
|
|
151
|
+
"data-testid": "avatar-2"
|
|
152
|
+
}));
|
|
153
|
+
var avatar2 = _testWrapper.screen.getByTestId('avatar-2');
|
|
154
|
+
var colorClass2 = (0, _find["default"])(_context2 = (0, _from["default"])(avatar2.classList)).call(_context2, function (cls) {
|
|
155
|
+
return (0, _startsWith["default"])(cls).call(cls, 'is-');
|
|
156
|
+
});
|
|
157
|
+
expect(colorClass1).toBe(colorClass2);
|
|
158
|
+
warnSpy.mockRestore();
|
|
159
|
+
});
|
|
160
|
+
test('does not warn when color prop is provided', function () {
|
|
161
|
+
var warnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
162
|
+
getComponent({
|
|
163
|
+
src: undefined,
|
|
164
|
+
color: 'blue'
|
|
165
|
+
});
|
|
166
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
167
|
+
warnSpy.mockRestore();
|
|
168
|
+
});
|
|
169
|
+
});
|
|
113
170
|
describe('getColorFromUUID Distribution', function () {
|
|
114
171
|
test('distributes 10,000 UUIDs evenly across 10 colors', function () {
|
|
115
172
|
var iterations = 10000;
|
|
@@ -118,44 +118,44 @@ var Sizes = exports.Sizes = function Sizes() {
|
|
|
118
118
|
borderBottom: 'unset'
|
|
119
119
|
}
|
|
120
120
|
}, (0, _react2.jsx)(_index.TableRow, {
|
|
121
|
-
height: "
|
|
121
|
+
height: "auto",
|
|
122
122
|
bg: "transparent !important"
|
|
123
123
|
}, (0, _react2.jsx)(_index.TableCell, null, (0, _react2.jsx)(_index.Text, null, "XXS | 9px")), (0, _react2.jsx)(_index.TableCell, null, (0, _react2.jsx)(_index.Text, {
|
|
124
124
|
fontFamily: "monospace"
|
|
125
|
-
}, '<Icon icon={SearchIcon}
|
|
125
|
+
}, '<Icon icon={SearchIcon} size="xxs"/>')), (0, _react2.jsx)(_index.TableCell, null, (0, _react2.jsx)(_index.Icon, {
|
|
126
126
|
icon: _SearchIcon["default"],
|
|
127
127
|
size: "xxs",
|
|
128
128
|
title: {
|
|
129
129
|
name: 'Search Icon'
|
|
130
130
|
}
|
|
131
131
|
}))), (0, _react2.jsx)(_index.TableRow, {
|
|
132
|
-
height: "
|
|
132
|
+
height: "auto",
|
|
133
133
|
bg: "transparent !important"
|
|
134
134
|
}, (0, _react2.jsx)(_index.TableCell, null, (0, _react2.jsx)(_index.Text, null, "XS | 15px")), (0, _react2.jsx)(_index.TableCell, null, (0, _react2.jsx)(_index.Text, {
|
|
135
135
|
fontFamily: "monospace"
|
|
136
|
-
}, '<Icon icon={SearchIcon}
|
|
136
|
+
}, '<Icon icon={SearchIcon} size="xs"/>')), (0, _react2.jsx)(_index.TableCell, null, (0, _react2.jsx)(_index.Icon, {
|
|
137
137
|
icon: _SearchIcon["default"],
|
|
138
138
|
size: "xs",
|
|
139
139
|
title: {
|
|
140
140
|
name: 'Search Icon'
|
|
141
141
|
}
|
|
142
142
|
}))), (0, _react2.jsx)(_index.TableRow, {
|
|
143
|
-
height: "
|
|
143
|
+
height: "auto",
|
|
144
144
|
bg: "transparent !important"
|
|
145
145
|
}, (0, _react2.jsx)(_index.TableCell, null, (0, _react2.jsx)(_index.Text, null, "SM | 20px")), (0, _react2.jsx)(_index.TableCell, null, (0, _react2.jsx)(_index.Text, {
|
|
146
146
|
fontFamily: "monospace"
|
|
147
|
-
}, '<Icon icon={SearchIcon}
|
|
147
|
+
}, '<Icon icon={SearchIcon} size="sm"/>')), (0, _react2.jsx)(_index.TableCell, null, (0, _react2.jsx)(_index.Icon, {
|
|
148
148
|
icon: _SearchIcon["default"],
|
|
149
149
|
size: "sm",
|
|
150
150
|
title: {
|
|
151
151
|
name: 'Search Icon'
|
|
152
152
|
}
|
|
153
153
|
}))), (0, _react2.jsx)(_index.TableRow, {
|
|
154
|
-
height: "
|
|
154
|
+
height: "auto",
|
|
155
155
|
bg: "transparent !important"
|
|
156
156
|
}, (0, _react2.jsx)(_index.TableCell, null, (0, _react2.jsx)(_index.Text, null, "MD | 25px")), (0, _react2.jsx)(_index.TableCell, null, (0, _react2.jsx)(_index.Text, {
|
|
157
157
|
fontFamily: "monospace"
|
|
158
|
-
}, '<Icon icon={SearchIcon}
|
|
158
|
+
}, '<Icon icon={SearchIcon} size="md"/>')), (0, _react2.jsx)(_index.TableCell, null, (0, _react2.jsx)(_index.Icon, {
|
|
159
159
|
icon: _SearchIcon["default"],
|
|
160
160
|
size: "md",
|
|
161
161
|
title: {
|