Skip to content

Commit 1e44ea3

Browse files
committed
uui-badge sizing
1 parent 872a8ad commit 1e44ea3

File tree

2 files changed

+83
-24
lines changed

2 files changed

+83
-24
lines changed

packages/uui-badge/lib/uui-badge.element.ts

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,27 @@ export class UUIBadgeElement extends LitElement {
1313
css`
1414
:host {
1515
position: absolute;
16+
display: flex;
17+
justify-content: center;
18+
align-items: center;
1619
1720
/* top: -8px;
1821
right: -8px; */
19-
padding: 3px 5px;
22+
padding: var(--uui-size-1) var(--uui-size-2);
2023
--uui-badge-inset: -8px -8px auto auto;
2124
/* 4 different ones */
2225
inset: var(--uui-badge-inset);
2326
2427
text-align: center;
25-
font-size: 12px;
26-
line-height: 16px;
28+
font-size: var(--uui-badge-font-size, var(--uui-type-small-size));
2729
font-weight: 900;
30+
line-height: 1;
2831
2932
margin-right: 0 !important;
3033
31-
min-width: var(--uui-size-4);
32-
min-height: var(--uui-size-4);
34+
min-width: var(--uui-size-8);
35+
min-height: var(--uui-size-8);
36+
box-sizing: border-box;
3337
3438
border-width: var(--uui-badge-border-width, 1px);
3539
border-style: solid;
@@ -44,9 +48,44 @@ export class UUIBadgeElement extends LitElement {
4448
var(--uui-interface-surface)
4549
);
4650
color: var(--uui-badge-contrast, var(--uui-interface-contrast));
47-
display: flex;
48-
justify-content: center;
49-
align-items: center;
51+
}
52+
53+
/** TODO: we didn't want to target elements by name, but what else can we do? */
54+
::slotted(uui-icon) {
55+
margin-left: -0.2em;
56+
margin-right: -0.2em;
57+
}
58+
59+
@keyframes --uui-badge-bounce {
60+
0% {
61+
transform: translateY(0);
62+
}
63+
20% {
64+
transform: translateY(-6px);
65+
}
66+
40% {
67+
transform: translateY(0);
68+
}
69+
55% {
70+
transform: translateY(-3px);
71+
}
72+
70% {
73+
transform: translateY(0);
74+
}
75+
100% {
76+
transform: translateY(0);
77+
}
78+
}
79+
:host([attention]) {
80+
animation-duration: 1.4s;
81+
animation-iteration-count: infinite;
82+
animation-name: --uui-badge-bounce;
83+
animation-timing-function: ease;
84+
}
85+
@media (prefers-reduced-motion) {
86+
:host([attention]) {
87+
animation: none;
88+
}
5089
}
5190
5291
:host([look='primary']) {
@@ -130,6 +169,15 @@ export class UUIBadgeElement extends LitElement {
130169
@property({ type: String, reflect: true })
131170
look: InterfaceLookType = 'danger';
132171

172+
/**
173+
* Bring attention to this badge by applying a bounce animation.
174+
* @type Boolean
175+
* @attr
176+
* @default false
177+
*/
178+
@property({ type: Boolean, reflect: true })
179+
attention = false;
180+
133181
render() {
134182
return html` <slot></slot> `;
135183
}

packages/uui-badge/lib/uui-badge.story.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export default {
1010
title: 'Displays/Badge',
1111
component: 'uui-badge',
1212
id: 'uui-badge',
13+
args: {
14+
look: 'primary',
15+
slot: '1',
16+
attention: false,
17+
},
1318
argTypes: {
1419
look: {
1520
options: [
@@ -28,27 +33,37 @@ export default {
2833

2934
const Template: Story = props => html` <div
3035
style="position:relative; width:80px; height:80px; border: 2px dashed black;">
31-
<uui-badge .look=${props.look}>${props.slot}</uui-badge>
36+
<uui-badge .look=${props.look} ?attention=${props.attention}
37+
>${props.slot}</uui-badge
38+
>
3239
</div>`;
3340

3441
export const AAAOverview = Template.bind({});
3542
AAAOverview.args = {
36-
look: 'danger',
37-
slot: '!',
43+
look: 'primary',
44+
slot: '1',
45+
attention: false,
3846
};
3947
AAAOverview.storyName = 'Overview';
4048
AAAOverview.parameters = {
4149
docs: {
4250
source: {
4351
code: `
4452
<div style="position:relative;">
45-
<uui-badge>!</uui-badge>
53+
<uui-badge>1</uui-badge>
4654
</div>
4755
`,
4856
},
4957
},
5058
};
5159

60+
export const WithAttention = Template.bind({});
61+
WithAttention.args = {
62+
look: 'danger',
63+
slot: '!',
64+
attention: true,
65+
};
66+
5267
export const WithText = Template.bind({});
5368
WithText.args = {
5469
look: 'positive',
@@ -58,19 +73,17 @@ WithText.parameters = {
5873
docs: {
5974
source: {
6075
code: `
61-
<div style="position:relative;">
6276
<uui-badge look="positive">Published</uui-badge>
63-
</div>
6477
`,
6578
},
6679
},
6780
};
6881

69-
// TODO: Uncomment when we fix the icon package.
70-
// export const WithIcon = () => html` <div
71-
// style="position:relative; width:20px; height:10px;">
72-
// <uui-badge look="secondary"><uui-icon name="info"></uui-icon></uui-badge>
73-
// </div>`;
82+
export const WithIcon = Template.bind({});
83+
WithIcon.args = {
84+
look: 'positive',
85+
slot: html`<uui-icon name="info"></uui-icon>`,
86+
};
7487

7588
export const OnButton: Story = props => html` <uui-button look="outline">
7689
Button label
@@ -94,15 +107,13 @@ OnButton.parameters = {
94107
};
95108

96109
export const Looks: Story = props => html`
97-
<div
98-
style="position:relative; width:80px; height:80px; border: 2px dashed black; margin-bottom: 16px">
99-
<uui-badge .look=${props.look}>${props.slot}</uui-badge>
100-
</div>
101110
${InterfaceLookNames.map(
102111
(lookName: InterfaceLookType) =>
103112
html`<div
104113
style="position:relative; display:inline-block; width:10px; height:10px; margin-right: 16px;">
105-
<uui-badge .look=${lookName}> 1 </uui-badge>
114+
<uui-badge .look=${lookName} ?attention=${props.attention}
115+
>${props.slot}</uui-badge
116+
>
106117
</div>`
107118
)}
108119
`;

0 commit comments

Comments
 (0)