Skip to content

Commit

Permalink
feat(esl-anchornav): create esl-anchor mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
dshovchko committed Aug 8, 2024
1 parent 63d869b commit db5fb32
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions .commitlintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ rules:
-
- esl-a11y-group
- esl-alert
- esl-anchornav
- esl-animate
- esl-base-element
- esl-carousel
Expand Down
4 changes: 4 additions & 0 deletions src/modules/esl-anchornav/core/esl-anchor.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[esl-anchor] {
margin-block-end: -2px;
height: 2px;
}
38 changes: 38 additions & 0 deletions src/modules/esl-anchornav/core/esl-anchor.ts
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;
}
}

0 comments on commit db5fb32

Please sign in to comment.