@stories-js/core
Version:
Stories web components to build stories
86 lines • 2.38 kB
JavaScript
/*!
* (C) StoriesJS https://storiesjs.org - GPL-2.0 License
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { Component, Host, h, Element, State, Method } from '@stencil/core';
import { api } from '../../api';
import { messages } from '../../types';
import { ACTION_EVENT } from './action';
export class AddonActions {
constructor() {
this.id = "ADDON_ACTIONS";
this.actions = [];
this.onActions = (actionDisplay) => {
this.actions = [...this.actions, actionDisplay];
};
}
title() {
return "Actions";
}
async storyContextChanged(story, context) {
console.log('AddonActions.storyContextChanged', story, context);
this.actions = [];
}
async componentDidLoad() {
// Register addon
api.registerAddon(this);
// Register event listeners
messages.on(ACTION_EVENT, this.onActions);
}
async disconnectedCallback() {
// Unregister event listener
messages.off(ACTION_EVENT, this.onActions);
// Unregster addon
api.unregisterAddon(this);
}
render() {
return (h(Host, null,
h("ul", null, this.actions.map(action => h("li", null, action.data.name)))));
}
static get is() { return "stories-addon-actions"; }
static get encapsulation() { return "shadow"; }
static get originalStyleUrls() { return {
"$": ["addon-actions.scss"]
}; }
static get styleUrls() { return {
"$": ["addon-actions.css"]
}; }
static get states() { return {
"actions": {}
}; }
static get methods() { return {
"storyContextChanged": {
"complexType": {
"signature": "(story: StoryComponent, context: StoryContext) => Promise<void>",
"parameters": [{
"tags": [],
"text": ""
}, {
"tags": [],
"text": ""
}],
"references": {
"Promise": {
"location": "global"
},
"StoryComponent": {
"location": "import",
"path": "../../types"
},
"StoryContext": {
"location": "import",
"path": "../../types"
}
},
"return": "Promise<void>"
},
"docs": {
"text": "",
"tags": []
}
}
}; }
static get elementRef() { return "el"; }
}
//# sourceMappingURL=addon-actions.js.map