@stories-js/core
Version:
Stories web components to build stories
58 lines • 1.84 kB
JavaScript
/*!
* (C) StoriesJS https://storiesjs.org - GPL-2.0 License
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
import { state } from '../store';
export const layoutAPI = {
toggleFullscreen(toggled) {
const { showNav, singleStory, fullScreen } = state;
const value = typeof toggled === 'boolean' ? toggled : !fullScreen;
const shouldShowNav = showNav === false && value === false;
state.fullScreen = value;
state.showNav = !singleStory && shouldShowNav ? true : showNav;
},
togglePanel(toggled) {
const { showNav, fullScreen, showPanel } = state;
const value = typeof toggled !== 'undefined' ? toggled : !showPanel;
const shouldToggleFullScreen = showNav === false && value === false;
state.showPanel = value;
state.fullScreen = shouldToggleFullScreen ? true : fullScreen;
},
togglePanelPosition(position) {
if (typeof position !== 'undefined') {
state.panelPosition = position;
}
else {
state.panelPosition = state.panelPosition === 'right' ? 'bottom' : 'right';
}
},
toggleNav(toggled) {
if (state.singleStory) {
return;
}
;
const { showPanel, fullScreen, showNav } = state;
const value = typeof toggled !== 'undefined' ? toggled : !showNav;
const shouldToggleFullScreen = showPanel === false && value === false;
state.showNav = value;
state.fullScreen = shouldToggleFullScreen ? true : !value && fullScreen;
},
resetLayout() {
state.showNav = false;
state.showPanel = false;
state.fullScreen = false;
},
focusOnUIElement(elementId, select) {
if (!elementId) {
return;
}
const element = document.querySelector(`#${elementId}`);
if (element) {
element.focus();
if (select) {
element.select();
}
}
},
};
//# sourceMappingURL=layout.js.map