@salesforcedevs/docs-components
Advanced tools
Comparing version 0.28.0 to 0.28.1
@@ -12,4 +12,5 @@ { | ||
"doc/heading", | ||
"doc/headingAnchor", | ||
"doc/phase" | ||
] | ||
} |
{ | ||
"name": "@salesforcedevs/docs-components", | ||
"version": "0.28.0", | ||
"version": "0.28.1", | ||
"description": "Docs Lightning web components for DSC", | ||
@@ -13,3 +13,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "e7bf549e93170dd173ff7419b302674d0faa0b7a" | ||
"gitHead": "01dbc1fb1d21c1b83ec997821bb33e8343732ec8" | ||
} |
import { LightningElement, api } from "lwc"; | ||
import { IconSprite, IconSize, IconSymbol } from "typings/custom"; | ||
export default class HeadingAnchor extends LightningElement { | ||
@api ariaLabel: string = "copy"; | ||
@api iconSize?: IconSize = "override"; | ||
@api iconSprite?: IconSprite = "utility"; | ||
@api iconSymbol?: IconSymbol; | ||
@api title: string = ""; | ||
@api hash: string | null = null; | ||
@api urlText: string = ""; | ||
label: string = "Copy link to clipboard"; | ||
timeout: number | null = null; | ||
private get titleToWrap() { | ||
return this.title.substring(0, this.title.lastIndexOf(" ")); | ||
private async onIconClick() { | ||
await this.iconClickHandler(); | ||
} | ||
private get needsSpace() { | ||
return this.titleToWrap.length > 0; | ||
} | ||
private get titleNoWrap() { | ||
return this.title.substring(this.title.lastIndexOf(" ") + 1); | ||
} | ||
private async copy() { | ||
if (this.timeout) { | ||
window.clearTimeout(this.timeout); | ||
} | ||
private async iconClickHandler() { | ||
this.label = "Copied"; | ||
this.timeout = window.setTimeout(() => { | ||
setTimeout(() => { | ||
this.label = "Copy link to clipboard"; | ||
@@ -33,5 +25,5 @@ }, 2000); | ||
try { | ||
if (this.title && this.hash) { | ||
if (this.title && this.urlText) { | ||
const [hostUrl] = window.location.href.split("#"); | ||
const url = `${hostUrl}#${this.hash}`; | ||
const url = `${hostUrl}#${this.urlText}`; | ||
await navigator.clipboard.writeText(url); | ||
@@ -43,2 +35,11 @@ } | ||
} | ||
private async onKeyDown(e: KeyboardEvent) { | ||
switch (e.key) { | ||
case "Enter": | ||
await this.iconClickHandler(); | ||
break; | ||
default: | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66958
37
1540