-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(esl-anchornav): create esl-anchor mixin
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[esl-anchor] { | ||
margin-block-end: -2px; | ||
height: 2px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {ESLMixinElement} from '../../esl-mixin-element/core'; | ||
import {ExportNs} from '../../esl-utils/environment/export-ns'; | ||
import {prop} from '../../esl-utils/decorators'; | ||
import {ESLEventUtils} from '../../esl-event-listener/core'; | ||
|
||
/** | ||
* ESLAnchor - custom mixin element for setting up anchor for {@link ESLAnchornav} attaching | ||
* | ||
* Use example: | ||
* `<div esl-anchor id="my-anchor-id" title="My anchor title"></div>` | ||
*/ | ||
@ExportNs('Anchor') | ||
export class ESLAnchor extends ESLMixinElement { | ||
static override is = 'esl-anchor'; | ||
|
||
@prop('esl:anchornav:request') public ANCHORNAV_REQUEST_EVENT: string; | ||
|
||
protected override connectedCallback(): void { | ||
super.connectedCallback(); | ||
this.sendRequestEvent(); | ||
} | ||
|
||
protected override disconnectedCallback(): void { | ||
this.sendRequestEvent(); | ||
super.disconnectedCallback(); | ||
} | ||
|
||
/** Sends a broadcast event to Anchornav components to refresh the list of anchors */ | ||
protected sendRequestEvent(): void { | ||
ESLEventUtils.dispatch(document.body, this.ANCHORNAV_REQUEST_EVENT); | ||
} | ||
} | ||
|
||
declare global { | ||
export interface ESLLibrary { | ||
Anchor: typeof ESLAnchor; | ||
} | ||
} |