Skip to content

Commit 94206b4

Browse files
authored
Feat: Adds looks and reworks colors on badge and tag (#243)
1 parent 8c7d962 commit 94206b4

File tree

8 files changed

+228
-124
lines changed

8 files changed

+228
-124
lines changed

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

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
22
import { css, html, LitElement } from 'lit';
33
import { property } from 'lit/decorators.js';
4+
import { InterfaceColor, InterfaceLook } from '@umbraco-ui/uui-base/lib/types';
45

56
/**
67
* A badge to notify that there is something that requires attention of the user. The badge is positioned with `position: absolute`. It will determine its position against the first ancestor with `position: relative`.
78
* @element uui-badge
89
* @slot - The slot for badge contents
910
*/
11+
1012
@defineElement('uui-badge')
1113
export class UUIBadgeElement extends LitElement {
1214
static styles = [
@@ -32,26 +34,55 @@ export class UUIBadgeElement extends LitElement {
3234
box-sizing: border-box;
3335
3436
border-radius: var(--uui-size-4);
35-
36-
/** default color: */
37-
background-color: var(--uui-color-default);
38-
color: var(--uui-color-default-contrast);
37+
border: 1px solid transparent;
3938
}
40-
:host([color='secondary']) {
41-
background-color: var(--uui-color-surface-alt);
42-
color: var(--uui-color-default);
39+
40+
:host {
41+
--color: var(--uui-color-default);
42+
--color-standalone: var(--uui-color-default-standalone);
43+
--color-contrast: var(--uui-color-default-contrast);
4344
}
4445
:host([color='positive']) {
45-
background-color: var(--uui-color-positive);
46-
color: var(--uui-color-positive-contrast);
46+
--color: var(--uui-color-positive);
47+
--color-standalone: var(--uui-color-positive-standalone);
48+
--color-contrast: var(--uui-color-positive-contrast);
4749
}
4850
:host([color='warning']) {
49-
background-color: var(--uui-color-warning);
50-
color: var(--uui-color-warning-contrast);
51+
--color: var(--uui-color-warning);
52+
--color-standalone: var(--uui-color-warning-standalone);
53+
--color-contrast: var(--uui-color-warning-contrast);
5154
}
5255
:host([color='danger']) {
53-
background-color: var(--uui-color-danger);
54-
color: var(--uui-color-danger-contrast);
56+
--color: var(--uui-color-danger);
57+
--color-standalone: var(--uui-color-danger-standalone);
58+
--color-contrast: var(--uui-color-danger-contrast);
59+
}
60+
61+
:host {
62+
background-color: var(--uui-color-surface);
63+
color: var(--color-standalone);
64+
border-color: transparent;
65+
}
66+
:host([look='primary']) {
67+
background-color: var(--color);
68+
color: var(--color-contrast);
69+
border-color: transparent;
70+
}
71+
:host([look='secondary']) {
72+
background-color: var(--uui-color-surface-alt);
73+
color: var(--color-standalone);
74+
border-color: transparent;
75+
}
76+
:host([look='outline']) {
77+
background-color: var(--uui-color-surface);
78+
color: var(--color-standalone);
79+
border-color: var(--color-standalone);
80+
}
81+
:host([look='placeholder']) {
82+
border-style: dashed;
83+
background-color: var(--uui-color-surface);
84+
color: var(--color-standalone);
85+
border-color: var(--uui-color-border-standalone);
5586
}
5687
5788
/** TODO: we didn't want to target elements by name, but what else can we do? */
@@ -95,13 +126,22 @@ export class UUIBadgeElement extends LitElement {
95126
];
96127

97128
/**
98-
* Changes the look of the badge to one of the predefined, symbolic looks. For example - set this to positive if you want nice, green "confirm" badge.
99-
* @type {"" | "default"|"positive"|"warning"|"danger"}
129+
* Changes the look of the button to one of the predefined, symbolic looks. For example - set this to positive if you want nice, green "confirm" button.
130+
* @type {"default" | "positive" | "warning" | "danger"}
131+
* @attr
132+
* @default "default"
133+
*/
134+
@property({ reflect: true })
135+
color: InterfaceColor = 'default';
136+
137+
/**
138+
* Changes the look of the button to one of the predefined, symbolic looks. For example - set this to positive if you want nice, green "confirm" button.
139+
* @type {"default" | "primary" | "secondary" | "outline" | "placeholder"}
100140
* @attr
101-
* @default default
141+
* @default "default"
102142
*/
103-
@property({ type: String, reflect: true })
104-
color = '';
143+
@property({ reflect: true })
144+
look: InterfaceLook = 'primary';
105145

106146
/**
107147
* Bring attention to this badge by applying a bounce animation.

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

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@ export default {
99
id: 'uui-badge',
1010
args: {
1111
color: 'default',
12+
look: 'primary',
1213
slot: '1',
1314
attention: false,
1415
},
1516
argTypes: {
17+
look: {
18+
control: {
19+
type: 'select',
20+
},
21+
options: ['default', 'primary', 'secondary', 'outline', 'placeholder'],
22+
},
1623
color: {
17-
options: ['default', 'secondary', 'positive', 'warning', 'danger'],
18-
control: { type: 'select' },
24+
control: {
25+
type: 'select',
26+
},
27+
options: ['default', 'positive', 'warning', 'danger'],
1928
},
2029
slot: {
2130
control: { type: 'text' },
@@ -25,8 +34,11 @@ export default {
2534

2635
const Template: Story = props => html` <uui-icon-registry-essential>
2736
<div
28-
style="position:relative; width:80px; height:80px; border: 2px dashed black;">
29-
<uui-badge .color=${props.color} ?attention=${props.attention}
37+
style="position:relative; width:80px; height:80px; border: 1px dashed rgba(0,0,0,0.1)">
38+
<uui-badge
39+
.color=${props.color}
40+
.look=${props.look}
41+
?attention=${props.attention}
3042
>${props.slot}</uui-badge
3143
>
3244
</div>
@@ -43,7 +55,7 @@ AAAOverview.parameters = {
4355
docs: {
4456
source: {
4557
code: `
46-
<div style="position:relative; width:80px; height:80px; border: 2px dashed black;">
58+
<div style="position:relative; width:80px; height:80px; border: 1px dashed rgba(0,0,0,0.1)">
4759
<uui-badge>1</uui-badge>
4860
</div>
4961
`,
@@ -61,7 +73,7 @@ WithAttention.parameters = {
6173
docs: {
6274
source: {
6375
code: `
64-
<div style="position:relative; width:80px; height:80px; border: 2px dashed black;">
76+
<div style="position:relative; width:80px; height:80px; border: 1px dashed rgba(0,0,0,0.1)">
6577
<uui-badge color="danger" attention>!</uui-badge>
6678
</div>
6779
`,
@@ -78,7 +90,7 @@ WithText.parameters = {
7890
docs: {
7991
source: {
8092
code: `
81-
<div style="position:relative; width:80px; height:80px; border: 2px dashed black;">
93+
<div style="position:relative; width:80px; height:80px; border: 1px dashed rgba(0,0,0,0.1)">
8294
<uui-badge color="positive">Published</uui-badge>
8395
</div>
8496
`,
@@ -98,7 +110,7 @@ WithIcon.parameters = {
98110
docs: {
99111
source: {
100112
code: `
101-
<div style="position:relative; width:80px; height:80px; border: 2px dashed black;">
113+
<div style="position:relative; width:80px; height:80px; border: 1px dashed rgba(0,0,0,0.1)">
102114
<uui-icon-registry-essential>
103115
<uui-badge ="positive">
104116
<uui-icon name="favorite"></uui-icon>
@@ -131,26 +143,34 @@ OnButton.parameters = {
131143
},
132144
};
133145

134-
export const Colors: Story = () => html`
135-
<div
136-
style="position:relative; width:80px; height:80px; border: 2px dashed black">
137-
<uui-badge>Default</uui-badge>
138-
</div>
139-
<div
140-
style="position:relative; width:80px; height:80px; border: 2px dashed black; margin-top: 16px">
141-
<uui-badge color="secondary">secondary</uui-badge>
142-
</div>
143-
</div>
144-
<div
145-
style="position:relative; width:80px; height:80px; border: 2px dashed black; margin-top: 16px">
146-
<uui-badge color="positive">positive</uui-badge>
147-
</div>
148-
<div
149-
style="position:relative; width:80px; height:80px; border: 2px dashed black; margin-top: 16px">
150-
<uui-badge color="warning">warning</uui-badge>
151-
</div>
152-
<div
153-
style="position:relative; width:80px; height:80px; border: 2px dashed black; margin-top: 16px">
154-
<uui-badge color="danger">danger</uui-badge>
155-
</div>
156-
`;
146+
const looks = ['default', 'primary', 'secondary', 'outline', 'placeholder'];
147+
const colors = ['default', 'positive', 'warning', 'danger'];
148+
149+
function uppercaseFirstLetter(s: string) {
150+
return s.charAt(0).toUpperCase() + s.slice(1);
151+
}
152+
153+
export const LooksAndColors: Story = () =>
154+
html`
155+
${colors.map(
156+
color =>
157+
html`
158+
<h5>${uppercaseFirstLetter(color)}</h5>
159+
<div style="margin-bottom: 32px; display: flex; gap: 16px;">
160+
${looks.map(
161+
look => html`
162+
<div
163+
style="position:relative; width:100px; height:80px; border: 1px dashed rgba(0,0,0,0.1); margin-top: 16px">
164+
<uui-badge
165+
.look=${look as any}
166+
.color=${color as any}
167+
style="margin-right:12px;"
168+
>${uppercaseFirstLetter(look)}</uui-badge
169+
>
170+
</div>
171+
`
172+
)}
173+
</div>
174+
`
175+
)}
176+
`;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const InterfaceColorValues: Readonly<InterfaceColor[]> = [
2+
'default',
3+
'positive',
4+
'warning',
5+
'danger',
6+
] as const;
7+
8+
export type InterfaceColor = '' | 'default' | 'positive' | 'warning' | 'danger';
Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,15 @@
1-
import { CSSResult, CSSResultArray, CSSResultGroup, unsafeCSS } from 'lit';
2-
3-
export const InterfaceLookNames: Readonly<InterfaceLookType[]> = [
1+
export const InterfaceLookValues: Readonly<InterfaceLook[]> = [
2+
'default',
43
'primary',
54
'secondary',
65
'outline',
76
'placeholder',
8-
'positive',
9-
'warning',
10-
'danger',
117
] as const;
128

13-
export type InterfaceLookType =
9+
export type InterfaceLook =
1410
| ''
11+
| 'default'
1512
| 'primary'
1613
| 'secondary'
1714
| 'outline'
18-
| 'placeholder'
19-
| 'positive'
20-
| 'warning'
21-
| 'danger';
22-
23-
export const InterfaceLookDefaultValue = '';
24-
25-
//TODO implement that in next released, so it can print out fallback values
26-
export function InterfaceLookCSSCreator(
27-
loopMethod: (lookName: CSSResult) => CSSResultGroup
28-
): CSSResultArray {
29-
return InterfaceLookNames.map((lookName: InterfaceLookType) => {
30-
return loopMethod(unsafeCSS(lookName));
31-
});
32-
}
15+
| 'placeholder';

packages/uui-base/lib/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './InterfaceLook';
2+
export * from './InterfaceColor';

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,12 @@ import {
1212
import { css, html, LitElement } from 'lit';
1313
import { property, query } from 'lit/decorators.js';
1414
import { ifDefined } from 'lit/directives/if-defined.js';
15+
import { InterfaceColor, InterfaceLook } from '@umbraco-ui/uui-base/lib/types';
1516

1617
export type UUIButtonState = undefined | 'waiting' | 'success' | 'failed';
1718

1819
export type UUIButtonType = 'submit' | 'button' | 'reset';
1920

20-
export type Look =
21-
| 'default'
22-
| 'primary'
23-
| 'secondary'
24-
| 'outline'
25-
| 'placeholder';
26-
export type Color = 'default' | 'positive' | 'warning' | 'danger';
27-
2821
/**
2922
* @element uui-button
3023
* @fires {UUIButtonEvent} click - fires when the element is clicked
@@ -373,7 +366,7 @@ export class UUIButtonElement extends FormControlMixin(
373366
* @default "default"
374367
*/
375368
@property({ reflect: true })
376-
look: Look = 'default';
369+
look: InterfaceLook = 'default';
377370

378371
/**
379372
* Changes the look of the button to one of the predefined, symbolic looks. For example - set this to positive if you want nice, green "confirm" button.
@@ -382,7 +375,7 @@ export class UUIButtonElement extends FormControlMixin(
382375
* @default "default"
383376
*/
384377
@property({ reflect: true })
385-
color: Color = 'default';
378+
color: InterfaceColor = 'default';
386379

387380
/**
388381
* Makes the left and right padding of the button narrower.

0 commit comments

Comments
 (0)