forked from forcedotcom/commerce-on-lightning-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommonLink.js
More file actions
87 lines (78 loc) · 2.01 KB
/
commonLink.js
File metadata and controls
87 lines (78 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* For full license text, see the LICENSE file in the repo
* root or https://opensource.org/licenses/apache-2-0/
*/
import { api, LightningElement } from 'lwc';
import {
generateButtonSizeClass,
generateButtonStretchClass,
generateButtonStyleClass,
generateElementAlignmentClass,
} from 'experience/styling';
export default class CommonLink extends LightningElement {
static renderMode = 'light';
@api
disabled = false;
/**
* Hyperlink URL.
* @type {?string}
*/
@api
href;
/**
* The assistive text for the anchor element (or button element in disabled state).
* @type {?string}
*/
@api
assistiveText;
/**
* The anchor/button variant.
* @type {?('primary' | 'secondary' | 'tertiary')}
*/
@api
variant;
/**
* The anchor/button size.
* @type {?('small' | 'large')}
*/
@api
size;
/**
* The anchor/button width.
* @type {?('stretch' | 'standard')}
*/
@api
width;
/**
* The alignment of the content inside the anchor/button.
* @type {?('center' | 'left' | 'right')}
*/
@api
alignment;
@api
focus() {
this.querySelector('a')?.focus();
}
get anchorClasses() {
return [
'slds-button',
generateButtonStyleClass(this.variant ?? null),
generateButtonSizeClass(this.size ?? null),
generateButtonStretchClass(this.width ?? null),
generateElementAlignmentClass(this.alignment ?? null),
].join(' ');
}
/**
* Makes sure that {@link Event.prototype.preventDefault} gets called when
* the `href` attribute is either `undefined` or blank.
* @param {Event} event The caught event
*/
handleClick(event) {
if (typeof this.href !== 'string' || this.href.trim().length === 0) {
event.preventDefault();
}
}
}