@salesforcedevs/docs-components 0.28.0 → 0.46.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/lwc.config.json +2 -0
- package/package.json +2 -2
- package/src/modules/doc/breadcrumbItem/breadcrumbItem.css +50 -0
- package/src/modules/doc/breadcrumbItem/breadcrumbItem.html +5 -0
- package/src/modules/doc/breadcrumbItem/breadcrumbItem.ts +49 -0
- package/src/modules/doc/breadcrumbs/breadcrumbs.css +19 -0
- package/src/modules/doc/breadcrumbs/breadcrumbs.html +48 -0
- package/src/modules/doc/breadcrumbs/breadcrumbs.ts +144 -0
- package/src/modules/doc/heading/heading.css +4 -4
- package/src/modules/doc/heading/heading.html +4 -4
- package/src/modules/doc/headingAnchor/headingAnchor.css +17 -39
- package/src/modules/doc/headingAnchor/headingAnchor.html +17 -17
- package/src/modules/doc/headingAnchor/headingAnchor.ts +21 -20
- package/src/modules/doc/headingContent/headingContent.css +55 -0
- package/src/modules/doc/headingContent/headingContent.html +19 -0
- package/src/modules/doc/headingContent/headingContent.ts +42 -0
package/lwc.config.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/docs-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"description": "Docs Lightning web components for DSC",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.js",
|
|
@@ -10,5 +10,5 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"gitHead": "
|
|
13
|
+
"gitHead": "78a4e68343ce579334b49d3dd6c474e1f71b4fd6"
|
|
14
14
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
@import "helpers/reset";
|
|
2
|
+
@import "helpers/text";
|
|
3
|
+
|
|
4
|
+
:host {
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
width: fit-content;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
:host(.breadcrumb_long) {
|
|
11
|
+
/* ensure 30 character min-width */
|
|
12
|
+
min-width: 245px;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
:host(.breadcrumb_back-arrow) {
|
|
16
|
+
gap: var(--dx-g-spacing-sm);
|
|
17
|
+
padding: var(--dx-g-spacing-sm);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
:host(.breadcrumb_back-arrow:hover) {
|
|
21
|
+
background-color: var(--dx-g-cloud-blue-vibrant-90);
|
|
22
|
+
border-radius: var(--dx-g-spacing-xs);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
:host(.breadcrumb_back-arrow) :is(a, dx-icon) {
|
|
26
|
+
color: var(--dx-g-blue-vibrant-50);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
a {
|
|
30
|
+
font-weight: var(--dx-g-font-bold);
|
|
31
|
+
text-decoration: none;
|
|
32
|
+
transition: var(--dx-g-transition-hue-1x);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
a,
|
|
36
|
+
span {
|
|
37
|
+
color: var(
|
|
38
|
+
--dx-c-breadcrumbs-breadcrumb-color,
|
|
39
|
+
var(--dx-g-blue-vibrant-20)
|
|
40
|
+
);
|
|
41
|
+
font-family: var(--dx-g-font-sans);
|
|
42
|
+
font-size: var(--dx-g-text-sm);
|
|
43
|
+
overflow: hidden;
|
|
44
|
+
text-overflow: ellipsis;
|
|
45
|
+
white-space: nowrap;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
a:hover {
|
|
49
|
+
color: var(--dx-g-blue-vibrant-40);
|
|
50
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { LightningElement, api } from "lwc";
|
|
2
|
+
import { BreadcrumbItemVariant } from "typings/custom";
|
|
3
|
+
|
|
4
|
+
const BREADCRUMB_LONG = "breadcrumb_long";
|
|
5
|
+
const BREADCRUMB_BACK_ARROW = "breadcrumb_back-arrow";
|
|
6
|
+
|
|
7
|
+
const LONG_LABEL_NUMBER = 30;
|
|
8
|
+
export default class BreadcrumbItem extends LightningElement {
|
|
9
|
+
@api href?: string;
|
|
10
|
+
|
|
11
|
+
@api
|
|
12
|
+
get label() {
|
|
13
|
+
return this._label;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
set label(value) {
|
|
17
|
+
this._label = value;
|
|
18
|
+
this.calculateClass();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@api
|
|
22
|
+
get variant() {
|
|
23
|
+
return this._variant;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
set variant(value) {
|
|
27
|
+
this._variant = value;
|
|
28
|
+
this.calculateClass();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
_label: string = "";
|
|
32
|
+
_variant: BreadcrumbItemVariant = "default";
|
|
33
|
+
|
|
34
|
+
private calculateClass(): void {
|
|
35
|
+
this.classList.remove(BREADCRUMB_LONG, BREADCRUMB_BACK_ARROW);
|
|
36
|
+
|
|
37
|
+
if (this.label?.length >= LONG_LABEL_NUMBER) {
|
|
38
|
+
this.classList.add(BREADCRUMB_LONG);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (this._variant === "back-arrow") {
|
|
42
|
+
this.classList.add(BREADCRUMB_BACK_ARROW);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private get isBackArrowVariant(): boolean {
|
|
47
|
+
return this._variant === "back-arrow";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
@import "helpers/reset";
|
|
2
|
+
@import "helpers/text";
|
|
3
|
+
|
|
4
|
+
:host {
|
|
5
|
+
--dx-c-breadcrumbs-title-color: var(--dx-g-blue-vibrant-20);
|
|
6
|
+
--dx-c-breadcrumbs-breadcrumb-color: var(--dx-g-blue-vibrant-20);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
nav {
|
|
10
|
+
display: flex;
|
|
11
|
+
align-items: center;
|
|
12
|
+
height: 100%;
|
|
13
|
+
position: relative;
|
|
14
|
+
gap: var(--dx-g-spacing-sm);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.breadcrumb-item_slash {
|
|
18
|
+
min-width: fit-content;
|
|
19
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<nav role="navigation" aria-label={ariaLabel}>
|
|
3
|
+
<template if:false={renderSmallVariant}>
|
|
4
|
+
<template if:true={renderFirstCrumb}>
|
|
5
|
+
<doc-breadcrumb-item
|
|
6
|
+
href={firstCrumb.href}
|
|
7
|
+
label={firstCrumb.label}
|
|
8
|
+
></doc-breadcrumb-item>
|
|
9
|
+
<span class="breadcrumb-item_slash">/</span>
|
|
10
|
+
</template>
|
|
11
|
+
<template if:true={renderDropdown}>
|
|
12
|
+
<dx-dropdown
|
|
13
|
+
if:true={renderDropdown}
|
|
14
|
+
options={dropdownOptions}
|
|
15
|
+
open-on-hover
|
|
16
|
+
placement="bottom"
|
|
17
|
+
width="200px"
|
|
18
|
+
>
|
|
19
|
+
<dx-button
|
|
20
|
+
aria-label="Open Breadcrumbs Dropdown"
|
|
21
|
+
icon-size="large"
|
|
22
|
+
icon-symbol="threedots"
|
|
23
|
+
variant="tertiary"
|
|
24
|
+
></dx-button>
|
|
25
|
+
</dx-dropdown>
|
|
26
|
+
<span class="breadcrumb-item_slash">/</span>
|
|
27
|
+
</template>
|
|
28
|
+
<template for:each={breadcrumbItems} for:item="breadcrumb">
|
|
29
|
+
<doc-breadcrumb-item
|
|
30
|
+
href={breadcrumb.href}
|
|
31
|
+
key={breadcrumb.label}
|
|
32
|
+
label={breadcrumb.label}
|
|
33
|
+
></doc-breadcrumb-item>
|
|
34
|
+
<span class="breadcrumb-item_slash" key={breadcrumb.label}>
|
|
35
|
+
/
|
|
36
|
+
</span>
|
|
37
|
+
</template>
|
|
38
|
+
<doc-breadcrumb-item label={lastCrumb.label}></doc-breadcrumb-item>
|
|
39
|
+
</template>
|
|
40
|
+
<template if:true={renderSmallVariant}>
|
|
41
|
+
<doc-breadcrumb-item
|
|
42
|
+
href={lastLinkCrump.href}
|
|
43
|
+
label={lastLinkCrump.label}
|
|
44
|
+
variant="back-arrow"
|
|
45
|
+
></doc-breadcrumb-item>
|
|
46
|
+
</template>
|
|
47
|
+
</nav>
|
|
48
|
+
</template>
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { LightningElement, api } from "lwc";
|
|
2
|
+
import { Breadcrumb, Option } from "typings/custom";
|
|
3
|
+
import { toJson } from "utils/normalizers";
|
|
4
|
+
|
|
5
|
+
type BreadcrumbConfig = {
|
|
6
|
+
minWidth: number;
|
|
7
|
+
crumbsInDropdown: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const GAP = 8;
|
|
11
|
+
const CONSTANTS = {
|
|
12
|
+
pixelPerCharacter: 7.2,
|
|
13
|
+
pixelPerCrumbSpace: GAP * 2 + 4.6,
|
|
14
|
+
minWidthPerCrumb: 245,
|
|
15
|
+
dropdownWidth: 32
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default class Breadcrumbs extends LightningElement {
|
|
19
|
+
@api ariaLabel: string = "Documentation Breadcrumbs";
|
|
20
|
+
|
|
21
|
+
@api
|
|
22
|
+
get breadcrumbs(): Breadcrumb[] {
|
|
23
|
+
return this._breadcrumbs;
|
|
24
|
+
}
|
|
25
|
+
set breadcrumbs(value) {
|
|
26
|
+
this._breadcrumbs = toJson(value) || [];
|
|
27
|
+
this.calculateBreadcrumbsConfigs();
|
|
28
|
+
if (this.observer) {
|
|
29
|
+
this.updateDropdownOptionAmount();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private _breadcrumbs: Breadcrumb[] = [];
|
|
34
|
+
private navWidth = 0;
|
|
35
|
+
private observer: ResizeObserver | null = null;
|
|
36
|
+
private breadcrumbConfigs: BreadcrumbConfig[] = [];
|
|
37
|
+
private dropdownOptionAmount? = 0;
|
|
38
|
+
|
|
39
|
+
private get renderSmallVariant(): boolean {
|
|
40
|
+
return (
|
|
41
|
+
!this.dropdownOptionAmount &&
|
|
42
|
+
this.dropdownOptionAmount !== 0 &&
|
|
43
|
+
!!this.lastLinkCrump
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private get lastLinkCrump(): Breadcrumb {
|
|
48
|
+
return this.breadcrumbs[this.breadcrumbs.length - 2];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private get hasInternalBreadcrumbs(): boolean {
|
|
52
|
+
return this.breadcrumbs.length > 2;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private get breadcrumbItems(): Breadcrumb[] {
|
|
56
|
+
return this.breadcrumbs!.slice(
|
|
57
|
+
this.dropdownOptionAmount! + 1,
|
|
58
|
+
this._breadcrumbs.length - 1
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private get renderDropdown(): boolean {
|
|
63
|
+
return this.hasInternalBreadcrumbs && !!this.dropdownOptionAmount;
|
|
64
|
+
}
|
|
65
|
+
private get dropdownOptions(): Option[] {
|
|
66
|
+
return this.breadcrumbs!.slice(1, this.dropdownOptionAmount! + 1).map(
|
|
67
|
+
(link) => ({
|
|
68
|
+
id: link.href!,
|
|
69
|
+
label: link.label,
|
|
70
|
+
link: { href: link.href! }
|
|
71
|
+
})
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private get renderFirstCrumb(): boolean {
|
|
76
|
+
return this.breadcrumbs.length > 1;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private get firstCrumb(): Breadcrumb {
|
|
80
|
+
return this.breadcrumbs[0];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private get lastCrumb(): Breadcrumb {
|
|
84
|
+
return this.breadcrumbs[this.breadcrumbs.length - 1];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
renderedCallback(): void {
|
|
88
|
+
if (!this.observer) {
|
|
89
|
+
this.observer = new ResizeObserver((entries) => {
|
|
90
|
+
const [nav] = entries;
|
|
91
|
+
if (this.navWidth === nav.contentRect.width) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
this.navWidth = nav.contentRect.width;
|
|
95
|
+
this.updateDropdownOptionAmount();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
this.observer.observe(this.template.querySelector("nav")!);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
disconnectedCallback(): void {
|
|
103
|
+
this.observer?.disconnect();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private updateDropdownOptionAmount(): void {
|
|
107
|
+
this.dropdownOptionAmount = this.breadcrumbConfigs.find(
|
|
108
|
+
({ minWidth }) => minWidth <= this.navWidth
|
|
109
|
+
)?.crumbsInDropdown;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private calculateBreadcrumbsConfigs(): void {
|
|
113
|
+
this.breadcrumbConfigs = [
|
|
114
|
+
...Array(this._breadcrumbs.length - 1).keys()
|
|
115
|
+
].map((optionsAmount) => {
|
|
116
|
+
const breadcrumbs = [...this._breadcrumbs];
|
|
117
|
+
breadcrumbs.splice(1, optionsAmount);
|
|
118
|
+
return {
|
|
119
|
+
crumbsInDropdown: optionsAmount,
|
|
120
|
+
minWidth: this.reduceBreadcrumbs(
|
|
121
|
+
breadcrumbs,
|
|
122
|
+
optionsAmount
|
|
123
|
+
? CONSTANTS.dropdownWidth + CONSTANTS.pixelPerCrumbSpace
|
|
124
|
+
: 0
|
|
125
|
+
)
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private reduceBreadcrumbs(
|
|
131
|
+
breadcrumbs: Breadcrumb[],
|
|
132
|
+
offset: number = 0
|
|
133
|
+
): number {
|
|
134
|
+
return breadcrumbs.reduce(
|
|
135
|
+
(previousValue, element) =>
|
|
136
|
+
previousValue +
|
|
137
|
+
Math.min(
|
|
138
|
+
element.label.length * CONSTANTS.pixelPerCharacter,
|
|
139
|
+
CONSTANTS.minWidthPerCrumb
|
|
140
|
+
),
|
|
141
|
+
(breadcrumbs.length - 1) * CONSTANTS.pixelPerCrumbSpace + offset
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -16,7 +16,7 @@ h6 {
|
|
|
16
16
|
line-height: var(--dx-g-text-4xl);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
.display-3 doc-heading-
|
|
19
|
+
.display-3 doc-heading-content {
|
|
20
20
|
--doc-c-heading-anchor-button-bottom: 8px;
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -27,7 +27,7 @@ h6 {
|
|
|
27
27
|
line-height: var(--dx-g-spacing-lg);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
.display-4 doc-heading-
|
|
30
|
+
.display-4 doc-heading-content {
|
|
31
31
|
--doc-c-heading-anchor-button-bottom: -3px;
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -38,7 +38,7 @@ h6 {
|
|
|
38
38
|
line-height: var(--dx-g-spacing-lg);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
.display-5 doc-heading-
|
|
41
|
+
.display-5 doc-heading-content {
|
|
42
42
|
--doc-c-heading-anchor-button-bottom: -4px;
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -49,6 +49,6 @@ h6 {
|
|
|
49
49
|
line-height: var(--dx-g-spacing-mlg);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
.display-6 doc-heading-
|
|
52
|
+
.display-6 doc-heading-content {
|
|
53
53
|
--doc-c-heading-anchor-button-bottom: -6px;
|
|
54
54
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<h1 class={className} if:true={isAriaLevelOne}>
|
|
3
|
-
<doc-heading-
|
|
3
|
+
<doc-heading-content title={title} hash={hash}></doc-heading-content>
|
|
4
4
|
</h1>
|
|
5
5
|
<h2 class={className} if:true={isAriaLevelTwo}>
|
|
6
|
-
<doc-heading-
|
|
6
|
+
<doc-heading-content title={title} hash={hash}></doc-heading-content>
|
|
7
7
|
</h2>
|
|
8
8
|
<h3 class={className} if:true={isAriaLevelThree}>
|
|
9
|
-
<doc-heading-
|
|
9
|
+
<doc-heading-content title={title} hash={hash}></doc-heading-content>
|
|
10
10
|
</h3>
|
|
11
11
|
<h4 class={className} if:true={isAriaLevelFour}>
|
|
12
|
-
<doc-heading-
|
|
12
|
+
<doc-heading-content title={title} hash={hash}></doc-heading-content>
|
|
13
13
|
</h4>
|
|
14
14
|
</template>
|
|
@@ -1,55 +1,33 @@
|
|
|
1
1
|
@import "helpers/reset";
|
|
2
2
|
|
|
3
|
-
:host {
|
|
4
|
-
--doc-c-heading-anchor-button-bottom: 0;
|
|
5
|
-
--doc-c-heading-anchor-icon-size: 18px;
|
|
6
|
-
--button-size: var(--dx-g-spacing-xl);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
dx-tooltip {
|
|
10
|
-
line-height: var(--button-size);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.button-container {
|
|
14
|
-
height: 100%;
|
|
15
|
-
margin-right: calc(var(--dx-g-spacing-xl) - 4px);
|
|
16
|
-
position: relative;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
3
|
button {
|
|
20
|
-
position: absolute;
|
|
21
|
-
bottom: var(--doc-c-heading-anchor-button-bottom);
|
|
22
|
-
left: 0;
|
|
23
4
|
opacity: 0;
|
|
24
5
|
color: rgb(11, 92, 171);
|
|
25
|
-
display: flex;
|
|
26
|
-
justify-content: center;
|
|
27
|
-
align-items: center;
|
|
28
|
-
height: var(--button-size);
|
|
29
|
-
width: var(--button-size);
|
|
30
|
-
border-radius: 4px;
|
|
31
6
|
}
|
|
32
7
|
|
|
33
|
-
|
|
34
|
-
|
|
8
|
+
button:hover {
|
|
9
|
+
opacity: 1;
|
|
10
|
+
outline: none;
|
|
35
11
|
}
|
|
36
12
|
|
|
37
|
-
|
|
38
|
-
|
|
13
|
+
button:focus {
|
|
14
|
+
opacity: 1;
|
|
15
|
+
outline: none;
|
|
39
16
|
}
|
|
40
17
|
|
|
41
|
-
|
|
42
|
-
|
|
18
|
+
button:focus-visible {
|
|
19
|
+
border-radius: 4px;
|
|
20
|
+
border: 2px solid rgb(11, 92, 171);
|
|
43
21
|
}
|
|
44
22
|
|
|
45
|
-
|
|
46
|
-
|
|
23
|
+
.icon-wrapper {
|
|
24
|
+
height: 32px;
|
|
25
|
+
width: 32px;
|
|
26
|
+
display: flex;
|
|
27
|
+
justify-content: center;
|
|
28
|
+
align-items: center;
|
|
47
29
|
}
|
|
48
30
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
span:hover dx-tooltip button,
|
|
52
|
-
span:hover ~ span dx-tooltip button {
|
|
53
|
-
opacity: 1;
|
|
54
|
-
outline: none;
|
|
31
|
+
.icon-container {
|
|
32
|
+
--dx-c-icon-size: 18px;
|
|
55
33
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
</
|
|
17
|
-
</
|
|
18
|
-
</
|
|
2
|
+
<dx-tooltip placement="top" label={label}>
|
|
3
|
+
<button
|
|
4
|
+
onclick={onIconClick}
|
|
5
|
+
aria-label={ariaLabel}
|
|
6
|
+
onkeydown={onKeyDown}
|
|
7
|
+
part="headingAnchorIcon"
|
|
8
|
+
>
|
|
9
|
+
<div class="icon-wrapper">
|
|
10
|
+
<dx-icon
|
|
11
|
+
sprite={iconSprite}
|
|
12
|
+
size={iconSize}
|
|
13
|
+
symbol={iconSymbol}
|
|
14
|
+
class="icon-container"
|
|
15
|
+
></dx-icon>
|
|
16
|
+
</div>
|
|
17
|
+
</button>
|
|
18
|
+
</dx-tooltip>
|
|
19
19
|
</template>
|
|
@@ -1,42 +1,43 @@
|
|
|
1
1
|
import { LightningElement, api } from "lwc";
|
|
2
|
+
import { IconSprite, IconSize, IconSymbol } from "typings/custom";
|
|
2
3
|
|
|
3
4
|
export default class HeadingAnchor extends LightningElement {
|
|
5
|
+
@api ariaLabel: string = "copy";
|
|
6
|
+
@api iconSize?: IconSize = "override";
|
|
7
|
+
@api iconSprite?: IconSprite = "utility";
|
|
8
|
+
@api iconSymbol?: IconSymbol;
|
|
4
9
|
@api title: string = "";
|
|
5
|
-
@api
|
|
10
|
+
@api urlText: string = "";
|
|
6
11
|
|
|
7
12
|
label: string = "Copy link to clipboard";
|
|
8
|
-
timeout: number | null = null;
|
|
9
13
|
|
|
10
|
-
private
|
|
11
|
-
|
|
14
|
+
private async onIconClick() {
|
|
15
|
+
await this.iconClickHandler();
|
|
12
16
|
}
|
|
13
17
|
|
|
14
|
-
private
|
|
15
|
-
return this.titleToWrap.length > 0;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
private get titleNoWrap() {
|
|
19
|
-
return this.title.substring(this.title.lastIndexOf(" ") + 1);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
private async copy() {
|
|
23
|
-
if (this.timeout) {
|
|
24
|
-
window.clearTimeout(this.timeout);
|
|
25
|
-
}
|
|
26
|
-
|
|
18
|
+
private async iconClickHandler() {
|
|
27
19
|
this.label = "Copied";
|
|
28
|
-
|
|
20
|
+
setTimeout(() => {
|
|
29
21
|
this.label = "Copy link to clipboard";
|
|
30
22
|
}, 2000);
|
|
31
23
|
|
|
32
24
|
try {
|
|
33
|
-
if (this.title && this.
|
|
25
|
+
if (this.title && this.urlText) {
|
|
34
26
|
const [hostUrl] = window.location.href.split("#");
|
|
35
|
-
const url = `${hostUrl}#${this.
|
|
27
|
+
const url = `${hostUrl}#${this.urlText}`;
|
|
36
28
|
await navigator.clipboard.writeText(url);
|
|
37
29
|
}
|
|
38
30
|
} catch (error) {
|
|
39
31
|
console.error(error);
|
|
40
32
|
}
|
|
41
33
|
}
|
|
34
|
+
|
|
35
|
+
private async onKeyDown(e: KeyboardEvent) {
|
|
36
|
+
switch (e.key) {
|
|
37
|
+
case "Enter":
|
|
38
|
+
await this.iconClickHandler();
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
}
|
|
42
|
+
}
|
|
42
43
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
@import "helpers/reset";
|
|
2
|
+
|
|
3
|
+
:host {
|
|
4
|
+
--doc-c-heading-anchor-button-bottom: 0;
|
|
5
|
+
--doc-c-heading-anchor-icon-size: 18px;
|
|
6
|
+
--button-size: var(--dx-g-spacing-xl);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
dx-tooltip {
|
|
10
|
+
line-height: var(--button-size);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.button-container {
|
|
14
|
+
height: 100%;
|
|
15
|
+
margin-right: calc(var(--dx-g-spacing-xl) - 4px);
|
|
16
|
+
position: relative;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
button {
|
|
20
|
+
position: absolute;
|
|
21
|
+
bottom: var(--doc-c-heading-anchor-button-bottom);
|
|
22
|
+
left: 0;
|
|
23
|
+
opacity: 0;
|
|
24
|
+
color: rgb(11, 92, 171);
|
|
25
|
+
display: flex;
|
|
26
|
+
justify-content: center;
|
|
27
|
+
align-items: center;
|
|
28
|
+
height: var(--button-size);
|
|
29
|
+
width: var(--button-size);
|
|
30
|
+
border-radius: 4px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
dx-icon {
|
|
34
|
+
--dx-c-icon-size: var(--doc-c-heading-anchor-icon-size);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
span:last-of-type {
|
|
38
|
+
padding-right: var(--dx-g-spacing-xs);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.nowrap {
|
|
42
|
+
white-space: nowrap;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
button:focus {
|
|
46
|
+
box-shadow: 0 0 0 2px rgb(11 92 171);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
button:focus,
|
|
50
|
+
button:hover,
|
|
51
|
+
span:hover dx-tooltip button,
|
|
52
|
+
span:hover ~ span dx-tooltip button {
|
|
53
|
+
opacity: 1;
|
|
54
|
+
outline: none;
|
|
55
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<template if:false={hash}>{title}</template>
|
|
3
|
+
<template if:true={hash}>
|
|
4
|
+
<template if:true={needsSpace}>
|
|
5
|
+
<span>{titleToWrap}</span>
|
|
6
|
+
<span> </span>
|
|
7
|
+
</template>
|
|
8
|
+
<span class="nowrap">
|
|
9
|
+
{titleNoWrap}
|
|
10
|
+
<dx-tooltip placement="top" label={label}>
|
|
11
|
+
<span class="button-container">
|
|
12
|
+
<button onclick={copy} aria-label="copy">
|
|
13
|
+
<dx-icon size="override" symbol="link"></dx-icon>
|
|
14
|
+
</button>
|
|
15
|
+
</span>
|
|
16
|
+
</dx-tooltip>
|
|
17
|
+
</span>
|
|
18
|
+
</template>
|
|
19
|
+
</template>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { LightningElement, api } from "lwc";
|
|
2
|
+
|
|
3
|
+
export default class HeadingContent extends LightningElement {
|
|
4
|
+
@api title: string = "";
|
|
5
|
+
@api hash: string | null = null;
|
|
6
|
+
|
|
7
|
+
label: string = "Copy link to clipboard";
|
|
8
|
+
timeout: number | null = null;
|
|
9
|
+
|
|
10
|
+
private get titleToWrap(): string {
|
|
11
|
+
return this.title.substring(0, this.title.lastIndexOf(" "));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
private get needsSpace(): boolean {
|
|
15
|
+
return this.titleToWrap.length > 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private get titleNoWrap(): string {
|
|
19
|
+
return this.title.substring(this.title.lastIndexOf(" ") + 1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private async copy() {
|
|
23
|
+
if (this.timeout) {
|
|
24
|
+
window.clearTimeout(this.timeout);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
this.label = "Copied";
|
|
28
|
+
this.timeout = window.setTimeout(() => {
|
|
29
|
+
this.label = "Copy link to clipboard";
|
|
30
|
+
}, 2000);
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
if (this.title && this.hash) {
|
|
34
|
+
const [hostUrl] = window.location.href.split("#");
|
|
35
|
+
const url = `${hostUrl}#${this.hash}`;
|
|
36
|
+
await navigator.clipboard.writeText(url);
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error(error);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|