Best JavaScript code snippet using storybook-root
shortcuts.ts
Source:shortcuts.ts
...17 getShortcutKeys(): Shortcuts;18 getDefaultShortcuts(): Shortcuts | AddonShortcutDefaults;19 getAddonsShortcuts(): AddonShortcuts;20 getAddonsShortcutLabels(): AddonShortcutLabels;21 getAddonsShortcutDefaults(): AddonShortcutDefaults;22 setShortcuts(shortcuts: Shortcuts): Promise<Shortcuts>;23 setShortcut(action: Action, value: KeyCollection): Promise<KeyCollection>;24 setAddonShortcut(addon: string, shortcut: AddonShortcut): Promise<AddonShortcut>;25 restoreAllDefaultShortcuts(): Promise<Shortcuts>;26 restoreDefaultShortcut(action: Action): Promise<KeyCollection>;27 handleKeydownEvent(event: Event): void;28 handleShortcutFeature(feature: Action): void;29}30export type KeyCollection = string[];31export interface Shortcuts {32 fullScreen: KeyCollection;33 togglePanel: KeyCollection;34 panelPosition: KeyCollection;35 toggleNav: KeyCollection;36 toolbar: KeyCollection;37 search: KeyCollection;38 focusNav: KeyCollection;39 focusIframe: KeyCollection;40 focusPanel: KeyCollection;41 prevComponent: KeyCollection;42 nextComponent: KeyCollection;43 prevStory: KeyCollection;44 nextStory: KeyCollection;45 shortcutsPage: KeyCollection;46 aboutPage: KeyCollection;47 escape: KeyCollection;48 collapseAll: KeyCollection;49 expandAll: KeyCollection;50}51export type Action = keyof Shortcuts;52interface AddonShortcut {53 label: string;54 defaultShortcut: KeyCollection;55 actionName: string;56 showInMenu?: boolean;57 action: (...args: any[]) => any;58}59type AddonShortcuts = Record<string, AddonShortcut>;60type AddonShortcutLabels = Record<string, string>;61type AddonShortcutDefaults = Record<string, KeyCollection>;62export const defaultShortcuts: Shortcuts = Object.freeze({63 fullScreen: ['F'],64 togglePanel: ['A'],65 panelPosition: ['D'],66 toggleNav: ['S'],67 toolbar: ['T'],68 search: ['/'],69 focusNav: ['1'],70 focusIframe: ['2'],71 focusPanel: ['3'],72 prevComponent: ['alt', 'ArrowUp'],73 nextComponent: ['alt', 'ArrowDown'],74 prevStory: ['alt', 'ArrowLeft'],75 nextStory: ['alt', 'ArrowRight'],76 shortcutsPage: [controlOrMetaKey(), 'shift', ','],77 aboutPage: [','],78 escape: ['escape'], // This one is not customizable79 collapseAll: [controlOrMetaKey(), 'shift', 'ArrowUp'],80 expandAll: [controlOrMetaKey(), 'shift', 'ArrowDown'],81});82const addonsShortcuts: AddonShortcuts = {};83export interface Event extends KeyboardEvent {84 target: {85 tagName: string;86 addEventListener(): void;87 removeEventListener(): boolean;88 dispatchEvent(event: Event): boolean;89 getAttribute(attr: string): string | null;90 };91}92function focusInInput(event: Event) {93 return (94 /input|textarea/i.test(event.target.tagName) ||95 event.target.getAttribute('contenteditable') !== null96 );97}98export const init: ModuleFn = ({ store, fullAPI }) => {99 const api: SubAPI = {100 // Getting and setting shortcuts101 getShortcutKeys(): Shortcuts {102 return store.getState().shortcuts;103 },104 getDefaultShortcuts(): Shortcuts | AddonShortcutDefaults {105 return {106 ...defaultShortcuts,107 ...api.getAddonsShortcutDefaults(),108 };109 },110 getAddonsShortcuts(): AddonShortcuts {111 return addonsShortcuts;112 },113 getAddonsShortcutLabels(): AddonShortcutLabels {114 const labels: AddonShortcutLabels = {};115 Object.entries(api.getAddonsShortcuts()).forEach(([actionName, { label }]) => {116 labels[actionName] = label;117 });118 return labels;119 },120 getAddonsShortcutDefaults(): AddonShortcutDefaults {121 const defaults: AddonShortcutDefaults = {};122 Object.entries(api.getAddonsShortcuts()).forEach(([actionName, { defaultShortcut }]) => {123 defaults[actionName] = defaultShortcut;124 });125 return defaults;126 },127 async setShortcuts(shortcuts: Shortcuts) {128 await store.setState({ shortcuts }, { persistence: 'permanent' });129 return shortcuts;130 },131 async restoreAllDefaultShortcuts() {132 return api.setShortcuts(api.getDefaultShortcuts() as Shortcuts);133 },134 async setShortcut(action, value) {...
Using AI Code Generation
1import { getAddonsShortcutDefaults } from 'storybook-root';2const shortcutDefaults = getAddonsShortcutDefaults();3import { getAddonsShortcutDefaults } from 'storybook-root';4const shortcutDefaults = getAddonsShortcutDefaults();5import { getAddonsShortcutDefaults } from 'storybook-root';6const shortcutDefaults = getAddonsShortcutDefaults();7import { getAddonsShortcutDefaults } from 'storybook-root';8const shortcutDefaults = getAddonsShortcutDefaults();9import { getAddonsShortcutDefaults } from 'storybook-root';10const shortcutDefaults = getAddonsShortcutDefaults();11import { getAddonsShortcutDefaults } from 'storybook-root';12const shortcutDefaults = getAddonsShortcutDefaults();13import { getAddonsShortcutDefaults } from 'storybook-root';14const shortcutDefaults = getAddonsShortcutDefaults();15import { getAddonsShortcutDefaults } from 'storybook-root';16const shortcutDefaults = getAddonsShortcutDefaults();17import { getAddonsShortcutDefaults } from 'storybook-root';18const shortcutDefaults = getAddonsShortcutDefaults();19import { getAddonsShortcutDefaults } from 'storybook-root';20const shortcutDefaults = getAddonsShortcutDefaults();21import { getAddonsShortcutDefaults } from 'storybook-root';22const shortcutDefaults = getAddonsShortcutDefaults();23import { getAddonsShortcutDefaults } from 'storybook-root';24const shortcutDefaults = getAddonsShortcutDefaults();25import { getAddonsShortcutDefaults } from 'storybook-root';26const shortcutDefaults = getAddonsShortcutDefaults();27import { getAddons
Using AI Code Generation
1const storybookRoot = require('./storybook-root');2const addonsShortcutDefaults = storybookRoot.getAddonsShortcutDefaults();3console.log(addonsShortcutDefaults);4const storybookRoot = require('./storybook-root');5const addonsShortcutDefaults = storybookRoot.getAddonsShortcutDefaults();6console.log(addonsShortcutDefaults);7const storybookRoot = require('./storybook-root');8const addonsShortcutDefaults = storybookRoot.getAddonsShortcutDefaults();9console.log(addonsShortcutDefaults);10const storybookRoot = require('./storybook-root');11const addonsShortcutDefaults = storybookRoot.getAddonsShortcutDefaults();12console.log(addonsShortcutDefaults);13const storybookRoot = require('./storybook-root');14const addonsShortcutDefaults = storybookRoot.getAddonsShortcutDefaults();15console.log(addonsShortcutDefaults);16const storybookRoot = require('./storybook-root');17const addonsShortcutDefaults = storybookRoot.getAddonsShortcutDefaults();18console.log(addonsShortcutDefaults);19const storybookRoot = require('./storybook-root');20const addonsShortcutDefaults = storybookRoot.getAddonsShortcutDefaults();21console.log(addonsShortcutDefaults);22const storybookRoot = require('./storybook-root');23const addonsShortcutDefaults = storybookRoot.getAddonsShortcutDefaults();24console.log(addonsShortcutDefaults);25const storybookRoot = require('./storybook-root');26const addonsShortcutDefaults = storybookRoot.getAddonsShortcutDefaults();27console.log(addonsShortcutDefaults);28const storybookRoot = require('./storybook-root');29const addonsShortcutDefaults = storybookRoot.getAddonsShortcutDefaults();30console.log(addonsShortcutDefaults);31const storybookRoot = require('./storybook-root');32const addonsShortcutDefaults = storybookRoot.getAddonsShortcutDefaults();33console.log(addonsShortcutDefaults);
Using AI Code Generation
1import { getAddonsShortcutDefaults } from 'storybook-root-addons';2import addons from '@storybook/addons';3addons.setConfig({4 shortcuts: getAddonsShortcutDefaults(),5});6import { getAddonsShortcutDefaults } from 'storybook-root-addons';7import addons from '@storybook/addons';8addons.setConfig({9 shortcuts: getAddonsShortcutDefaults({10 }),11});12import addons from '@storybook/addons';13addons.setConfig({14 shortcuts: {15 },16});17import addons from '@storybook/addons';18addons.setConfig({19 shortcuts: {20 },21});
Using AI Code Generation
1import { getAddonsShortcutDefaults } from 'storybook-root';2const shortcuts = getAddonsShortcutDefaults();3console.log(shortcuts);4import { useShortcut } from 'storybook-addon-shortcuts';5const MyComponent = () => {6 const showSearch = useShortcut('storybook/shortcuts/show-search');7 const toggleShortcutsHelp = useShortcut('storybook/shortcuts/toggle-shortcuts-help');8 const nextStory = useShortcut('storybook/shortcuts/next-story');9 const previousStory = useShortcut('storybook/shortcuts/previous-story');10 const nextComponent = useShortcut('storybook/shortcuts/next-component');11 const previousComponent = useShortcut('storybook/shortcuts/previous-component');12 const togglePanel = useShortcut('storybook/shortcuts/toggle-panel');13 const togglePanel1 = useShortcut('storybook
Using AI Code Generation
1const { getAddonsShortcutDefaults } = require('storybook-root');2const addonsShortcutDefaults = getAddonsShortcutDefaults();3console.log(addonsShortcutDefaults);4{5 'addon-actions/register': {6 },7 'addon-backgrounds/register': {8 },9 'addon-centered/register': {10 },11 'addon-contexts/register': {12 },13 'addon-docs/register': {14 },15 'addon-events/register': {16 },17 'addon-google-analytics/register': {18 },19 'addon-info/register': {20 },21 'addon-jest/register': {22 },23 'addon-knobs/register': {24 },25 'addon-links/register': {26 },27 'addon-notes/register': {28 },29 'addon-options/register': {
Using AI Code Generation
1import { getAddonsShortcutDefaults } from 'storybook-root';2const defaultShortcuts = getAddonsShortcutDefaults();3const { shortcuts } = defaultShortcuts;4if (shortcuts) {5 const { actions, backgrounds, viewport } = shortcuts;6 if (actions) {7 actions.currentShortcut = 'ctrl+alt+a';8 }9 if (backgrounds) {10 backgrounds.currentShortcut = 'ctrl+alt+b';11 }12 if (viewport) {13 viewport.currentShortcut = 'ctrl+alt+v';14 }15}16export default defaultShortcuts;17import defaultShortcuts from '../test.js';18import { addons } from '@storybook/addons';19import { SET_SHORTCUTS } from '@storybook/api';20addons.getChannel().emit(SET_SHORTCUTS, defaultShortcuts);21.react-select__option--is-selected {22 background-color: #00ff00;23}24.react-select__option--is-selected {25 background-color: #00ff00 !important;26}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!