-
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-share): create esl-share-list component
- Loading branch information
Showing
6 changed files
with
121 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
@import './core/esl-share-button.less'; | ||
@import './core/esl-share-list.less'; | ||
@import './core/esl-share-popup-trigger.less'; | ||
@import './core/esl-share.less'; |
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
2 changes: 1 addition & 1 deletion
2
src/modules/esl-share/core/esl-share.less → ...odules/esl-share/core/esl-share-list.less
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
esl-share[mode='list'] { | ||
esl-share-list { | ||
display: inline-flex; | ||
flex-wrap: wrap; | ||
} |
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,27 @@ | ||
import type {ESLBaseElementShape} from '../../esl-base-element/core/esl-base-element.shape'; | ||
import type {ESLShareList} from './esl-share-list'; | ||
|
||
/** | ||
* Tag declaration interface of ESLShareList element | ||
* Used for TSX declaration | ||
*/ | ||
export interface ESLShareListTagShape extends ESLBaseElementShape<ESLShareList> { | ||
/** Define the list of social networks or groups of them to display (all by default) */ | ||
list?: string; | ||
/** Define URL to share (current page URL by default) */ | ||
'share-url'?: string; | ||
/** Define title to share (current document title by default) */ | ||
'share-title'?: string; | ||
|
||
/** Children are not allowed for ESLShareList */ | ||
children?: never[]; | ||
} | ||
|
||
declare global { | ||
namespace JSX { | ||
export interface IntrinsicElements { | ||
/** {@link ESLShareList} custom tag */ | ||
'esl-share-list': ESLShareListTagShape; | ||
} | ||
} | ||
} |
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,78 @@ | ||
import {ESLBaseElement} from '../../esl-base-element/core'; | ||
import {isEqual} from '../../esl-utils/misc/object/compare'; | ||
import {attr, boolAttr, listen, memoize, prop} from '../../esl-utils/decorators'; | ||
import {ESLShareButton} from './esl-share-button'; | ||
import {ESLShareConfig} from './esl-share-config'; | ||
|
||
import type {ESLShareButtonConfig} from './esl-share-config'; | ||
|
||
/** | ||
* ESLShare | ||
* @author Dmytro Shovchko | ||
* | ||
* ESLShare is a custom element to dynamically draw {@link ESLShareButton}s using simplified shared config | ||
*/ | ||
export class ESLShareList extends ESLBaseElement { | ||
public static override is = 'esl-share-list'; | ||
|
||
/** Register {@link ESLShareList} component and dependent {@link ESLShareButton} */ | ||
public static override register(): void { | ||
ESLShareButton.register(); | ||
super.register(); | ||
} | ||
|
||
/** Event to dispatch on change of {@link ESLShareList} */ | ||
@prop('esl:share:changed') public SHARE_CHANGED_EVENT: string; | ||
|
||
/** | ||
* List of social networks or groups of them to display (all by default). | ||
* The value - a string containing the names of the buttons or groups (specified with | ||
* the prefix group:) separated by spaces. | ||
* @example "facebook reddit group:default" | ||
* */ | ||
@attr({defaultValue: 'all'}) public list: string; | ||
|
||
/** @readonly Ready state marker */ | ||
@boolAttr({readonly: true}) public ready: boolean; | ||
|
||
/** @returns config of buttons specified by the list attribute */ | ||
@memoize() | ||
public get buttonsConfig(): ESLShareButtonConfig[] { | ||
return ESLShareConfig.getList(this.list); | ||
} | ||
|
||
public override connectedCallback(): void { | ||
super.connectedCallback(); | ||
this.init(); | ||
} | ||
|
||
/** Initializes the component */ | ||
protected init(force?: boolean): void { | ||
if (this.ready && !force) return; | ||
this.buildContent(); | ||
this.onReady(); | ||
} | ||
|
||
/** Appends buttons to the component. */ | ||
protected buildContent(): void { | ||
this.innerHTML = ''; | ||
this.buttonsConfig.forEach((cfg) => { | ||
const btn = ESLShareButton.create(cfg.name); | ||
btn && this.appendChild(btn); | ||
}); | ||
} | ||
|
||
/** Actions on complete init and ready component. */ | ||
private onReady(): void { | ||
this.$$attr('ready', true); | ||
this.$$fire(this.SHARE_CHANGED_EVENT, {bubbles: false}); | ||
} | ||
|
||
@listen({event: 'change', target: ESLShareConfig.instance}) | ||
protected _onConfigChange(): void { | ||
const {buttonsConfig} = this; | ||
memoize.clear(this, 'buttonsConfig'); | ||
if (isEqual(this.buttonsConfig, buttonsConfig)) return; | ||
this.init(true); | ||
} | ||
} |
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