@@ -11,6 +11,7 @@ import {
11
11
} from '@umbraco-ui/uui-icon-registry-essential/lib/svgs' ;
12
12
import { css , html , LitElement } from 'lit' ;
13
13
import { property , query } from 'lit/decorators.js' ;
14
+ import { ifDefined } from 'lit/directives/if-defined.js' ;
14
15
15
16
export type UUIButtonState = undefined | 'waiting' | 'success' | 'failed' ;
16
17
@@ -76,6 +77,7 @@ export class UUIButtonElement extends FormControlMixin(
76
77
}
77
78
78
79
.label {
80
+ line-height: normal; /** needed to reset 'a > span' */
79
81
display: block;
80
82
transition: opacity 120ms;
81
83
}
@@ -95,7 +97,7 @@ export class UUIButtonElement extends FormControlMixin(
95
97
animation-fill-mode: forwards;
96
98
}
97
99
98
- button {
100
+ # button {
99
101
height: 100%;
100
102
width: 100%;
101
103
background-color: transparent;
@@ -107,6 +109,12 @@ export class UUIButtonElement extends FormControlMixin(
107
109
text-align: inherit;
108
110
border: none;
109
111
cursor: inherit;
112
+ display: block;
113
+
114
+ /* for anchor tag: */
115
+ text-decoration: none;
116
+ color: currentColor;
117
+ line-height: normal;
110
118
111
119
border-width: var(--uui-button-border-width, 1px);
112
120
border-style: solid;
@@ -123,7 +131,8 @@ export class UUIButtonElement extends FormControlMixin(
123
131
vertical-align: middle;
124
132
box-shadow: none;
125
133
}
126
- button[disabled]:active {
134
+ button[disabled]:active,
135
+ a:not([href]):active {
127
136
animation: ${ UUIHorizontalShakeAnimationValue } ;
128
137
}
129
138
#icon-check,
@@ -161,43 +170,43 @@ export class UUIButtonElement extends FormControlMixin(
161
170
}
162
171
163
172
/* edge case for default color */
164
- :host(:not([color]):not([look='primary'])) button,
165
- :host([color='']:not([look='primary'])) button,
166
- :host([color='default']:not([look='primary'])) button {
173
+ :host(:not([color]):not([look='primary'])) # button,
174
+ :host([color='']:not([look='primary'])) # button,
175
+ :host([color='default']:not([look='primary'])) # button {
167
176
--uui-button-contrast-hover: var(--uui-color-default-emphasis);
168
177
}
169
178
170
- :host([color='warning'][look='outline']) button,
171
- :host([color='warning'][look='placeholder']) button {
179
+ :host([color='warning'][look='outline']) # button,
180
+ :host([color='warning'][look='placeholder']) # button {
172
181
--uui-button-contrast-hover: var(--color-standalone);
173
182
}
174
183
175
184
/** Button color attribute: */
176
- button {
185
+ # button {
177
186
--color: var(--uui-color-default);
178
187
--color-standalone: var(--uui-color-default-standalone);
179
188
--color-emphasis: var(--uui-color-default-emphasis);
180
189
--color-contrast: var(--uui-color-default-contrast);
181
190
}
182
- :host([color='positive']) button {
191
+ :host([color='positive']) # button {
183
192
--color: var(--uui-color-positive);
184
193
--color-standalone: var(--uui-color-positive-standalone);
185
194
--color-emphasis: var(--uui-color-positive-emphasis);
186
195
--color-contrast: var(--uui-color-positive-contrast);
187
196
}
188
- :host([color='warning']) button {
197
+ :host([color='warning']) # button {
189
198
--color: var(--uui-color-warning);
190
199
--color-standalone: var(--uui-color-warning-standalone);
191
200
--color-emphasis: var(--uui-color-warning-emphasis);
192
201
--color-contrast: var(--uui-color-warning-contrast);
193
202
}
194
- :host([color='danger']) button {
203
+ :host([color='danger']) # button {
195
204
--color: var(--uui-color-danger);
196
205
--color-standalone: var(--uui-color-danger-standalone);
197
206
--color-emphasis: var(--uui-color-danger-emphasis);
198
207
--color-contrast: var(--uui-color-danger-contrast);
199
208
}
200
- :host([disabled]) button {
209
+ :host([disabled]) # button {
201
210
--color: var(--uui-color-disabled);
202
211
--color-standalone: var(--uui-color-disabled-contrast);
203
212
--color-emphasis: var(--uui-color-disabled);
@@ -208,20 +217,20 @@ export class UUIButtonElement extends FormControlMixin(
208
217
209
218
/** Button look attribute: */
210
219
/* DEFAULT */
211
- button {
220
+ # button {
212
221
background-color: var(--uui-button-background-color, transparent);
213
222
color: var(--uui-button-contrast, var(--color-standalone));
214
223
border-color: var(--uui-button-border-color, transparent);
215
224
}
216
- :host(:not([disabled]):hover) button {
225
+ :host(:not([disabled]):hover) # button {
217
226
background-color: var(
218
227
--uui-button-background-color-hover,
219
228
var(--uui-color-surface-emphasis)
220
229
);
221
230
color: var(--uui-button-contrast-hover, var(--color-standalone));
222
231
border-color: var(--uui-button-border-color-hover, transparent);
223
232
}
224
- :host([disabled]) button {
233
+ :host([disabled]) # button {
225
234
background-color: var(
226
235
--uui-button-background-color-disabled,
227
236
transparent
@@ -231,23 +240,23 @@ export class UUIButtonElement extends FormControlMixin(
231
240
}
232
241
233
242
/* PRIMARY */
234
- :host([look='primary']) button {
243
+ :host([look='primary']) # button {
235
244
background-color: var(--uui-button-background-color, var(--color));
236
245
color: var(--uui-button-contrast, var(--color-contrast));
237
246
border-color: var(--uui-button-border-color, transparent);
238
247
239
248
/* special for primary: */
240
249
font-weight: var(--uui-button-font-weight, 700);
241
250
}
242
- :host([look='primary']:hover) button {
251
+ :host([look='primary']:hover) # button {
243
252
background-color: var(
244
253
--uui-button-background-color-hover,
245
254
var(--color-emphasis)
246
255
);
247
256
color: var(--uui-button-contrast-hover, var(--color-contrast));
248
257
border-color: var(--uui-button-border-color-hover, transparent);
249
258
}
250
- :host([look='primary'][disabled]) button {
259
+ :host([look='primary'][disabled]) # button {
251
260
background-color: var(
252
261
--uui-button-background-color-disabled,
253
262
var(--color)
@@ -256,7 +265,7 @@ export class UUIButtonElement extends FormControlMixin(
256
265
border-color: var(--uui-button-border-color-disabled, var(--color));
257
266
}
258
267
/* SECONDARY */
259
- :host([look='secondary']) button {
268
+ :host([look='secondary']) # button {
260
269
background-color: var(
261
270
--uui-button-background-color,
262
271
var(--uui-color-surface-alt)
@@ -267,15 +276,15 @@ export class UUIButtonElement extends FormControlMixin(
267
276
/* special for secondary: */
268
277
font-weight: var(--uui-button-font-weight, 700);
269
278
}
270
- :host([look='secondary']:hover) button {
279
+ :host([look='secondary']:hover) # button {
271
280
background-color: var(
272
281
--uui-button-background-color-hover,
273
282
var(--uui-color-surface-emphasis)
274
283
);
275
284
color: var(--uui-button-contrast-hover, var(--color-standalone));
276
285
border-color: var(--uui-button-border-color-hover, transparent);
277
286
}
278
- :host([look='secondary'][disabled]) button {
287
+ :host([look='secondary'][disabled]) # button {
279
288
background-color: var(
280
289
--uui-button-background-color-disabled,
281
290
var(--color)
@@ -285,23 +294,23 @@ export class UUIButtonElement extends FormControlMixin(
285
294
}
286
295
287
296
/* OUTLINE */
288
- :host([look='outline']) button {
297
+ :host([look='outline']) # button {
289
298
background-color: var(--uui-button-background-color, transparent);
290
299
color: var(--uui-button-contrast, var(--color-standalone));
291
300
border-color: var(--uui-button-border-color, --color-standalone);
292
301
293
302
/* special for outline: */
294
303
font-weight: var(--uui-button-font-weight, 700);
295
304
}
296
- :host([look='outline']:not([disabled]):hover) button {
305
+ :host([look='outline']:not([disabled]):hover) # button {
297
306
background-color: var(--uui-button-background-color-hover, transparent);
298
307
color: var(--uui-button-contrast-hover, var(--color-emphasis));
299
308
border-color: var(
300
309
--uui-button-border-color-hover,
301
310
var(--color-emphasis)
302
311
);
303
312
}
304
- :host([look='outline'][disabled]) button {
313
+ :host([look='outline'][disabled]) # button {
305
314
background-color: var(
306
315
--uui-button-background-color-disabled,
307
316
transparent
@@ -314,7 +323,7 @@ export class UUIButtonElement extends FormControlMixin(
314
323
}
315
324
316
325
/* PLACEHOLDER */
317
- :host([look='placeholder']) button {
326
+ :host([look='placeholder']) # button {
318
327
border-style: dashed;
319
328
background-color: var(--uui-button-background-color, transparent);
320
329
color: var(--uui-button-contrast, var(--color-standalone));
@@ -323,12 +332,12 @@ export class UUIButtonElement extends FormControlMixin(
323
332
var(--uui-color-border-standalone)
324
333
);
325
334
}
326
- :host([look='placeholder']:not([disabled]):hover) button {
335
+ :host([look='placeholder']:not([disabled]):hover) # button {
327
336
background-color: var(--uui-button-background-color-hover, transparent);
328
337
color: var(--uui-button-contrast-hover, var(--color-standalone));
329
338
border-color: var(--uui-button-border-color-hover, --color-standalone);
330
339
}
331
- :host([look='placeholder'][disabled]) button {
340
+ :host([look='placeholder'][disabled]) # button {
332
341
background-color: var(
333
342
--uui-button-background-color-disabled,
334
343
var(--color)
@@ -395,6 +404,24 @@ export class UUIButtonElement extends FormControlMixin(
395
404
@property ( { type : String , reflect : true } )
396
405
state : UUIButtonState = undefined ;
397
406
407
+ /**
408
+ * Set an href, this will turns the button into a anchor tag.
409
+ * @type {string }
410
+ * @attr
411
+ * @default undefined
412
+ */
413
+ @property ( { type : String } )
414
+ public href ?: string ;
415
+
416
+ /**
417
+ * Set an anchor tag target, only used when using href.
418
+ * @type {string }
419
+ * @attr
420
+ * @default undefined
421
+ */
422
+ @property ( { type : String } )
423
+ public target ?: '_blank' | '_parent' | '_self' | '_top' ;
424
+
398
425
@query ( '#button' )
399
426
protected _button ! : HTMLInputElement ;
400
427
@@ -475,12 +502,29 @@ export class UUIButtonElement extends FormControlMixin(
475
502
}
476
503
477
504
render ( ) {
478
- return html `
479
- < button id ="button " ?disabled =${ this . disabled } aria-label ="${ this . label } ">
480
- ${ this . renderState ( ) } ${ this . renderLabel ( ) }
481
- < slot name ="extra "> </ slot >
482
- </ button >
483
- ` ;
505
+ return this . href
506
+ ? html `
507
+ < a
508
+ id ="button "
509
+ aria-label =${ this . label }
510
+ href =${ ifDefined ( ! this . disabled ? this . href : undefined ) }
511
+ target=${ ifDefined ( this . target || undefined ) }
512
+ rel=${ ifDefined (
513
+ this . target === '_blank' ? 'noopener noreferrer' : undefined
514
+ ) } >
515
+ ${ this . renderState ( ) } ${ this . renderLabel ( ) }
516
+ < slot name ="extra "> </ slot >
517
+ </ a >
518
+ `
519
+ : html `
520
+ < button
521
+ id ="button "
522
+ ?disabled =${ this . disabled }
523
+ aria-label =${ this . label } >
524
+ ${ this . renderState ( ) } ${ this . renderLabel ( ) }
525
+ < slot name ="extra "> </ slot >
526
+ </ button >
527
+ ` ;
484
528
}
485
529
}
486
530
0 commit comments