Best JavaScript code snippet using storybook-root
index.ts
Source:index.ts
1/**2 * Huge shoutout to Storybook as the core architecture of our shortcuts3 * is based off of their source. Storybook is a development environment4 * for UI components. It allows you to browse a component library, view5 * the different states of each component, and interactively develop and6 * test components.7 *8 * https://github.com/storybooks/storybook9 */1011import { navigate } from 'gatsby'1213import settings from '../settings'14import store from '../store'15import shortcuts from './shortcuts'16import * as constants from './constants'17import { shortcutMatchesShortcut, eventToShortcut, keyToSymbol } from './utils'1819import { Feature } from './types'2021export { constants, keyToSymbol }2223export default (store => {24 const api = {25 getShortcuts() {26 return shortcuts27 },2829 // Used in Command Line to not show some options30 getShortcutsFiltered() {31 const blacklist = [constants.COMMAND_LINE_DEFAULT, constants.ESCAPE]3233 return shortcuts.filter(34 shortcut => !blacklist.some(item => item === shortcut.name)35 )36 },3738 // Listening to shortcut events39 handleKeydownEvent(event: KeyboardEvent) {40 const activeElement = document.activeElement41 const inputs = ['input', 'select', 'textarea']42 const noInputIsFocused =43 activeElement &&44 inputs.indexOf(activeElement.tagName.toLowerCase()) === -14546 const shortcut = eventToShortcut(event)4748 const matchedFeature = shortcuts.find((feature: Feature) => {49 return shortcutMatchesShortcut(shortcut, feature.keys)50 })5152 if (53 (matchedFeature && noInputIsFocused) ||54 (matchedFeature && matchedFeature.name === 'ESCAPE')55 ) {56 // Temp logging to make it clear what is matched57 console.log(58 `Pressed ${shortcut.join(' + ')} and matched ${matchedFeature.name}`59 )60 /**61 * If it's a Fey matched feature make sure we don't also invoke a62 * feature the browser or a different tool supports63 */64 event.preventDefault()6566 return api.handleShortcutFeature(matchedFeature)67 }6869 // Hook in and add a check for custom Backspace events70 api.handleBackToDefault(event)71 },7273 /**74 * handleShortcutFeature()75 *76 * If a feature is matched, we pass the matched key String so we can77 * act upon it. Here is wher we dispatch and custom action or process we78 * want based on the feature!79 *80 * @param feature String81 */82 handleShortcutFeature(feature: { name: string }) {83 switch (feature.name) {84 // Our different Command Line variants85 case constants.COMMAND_LINE_DEFAULT: {86 store.dispatch({ type: constants.SHORTCUT, payload: feature })87 break88 }89 case constants.COMMAND_LINE_READ: {90 store.dispatch({ type: constants.SHORTCUT, payload: feature })91 break92 }93 case constants.COMMAND_LINE_OPEN_SOURCE: {94 store.dispatch({ type: constants.SHORTCUT, payload: feature })95 break96 }9798 // Go to page in Gifting-Wild99 case constants.GO_TO_HOME: {100 navigate('/')101 store.dispatch({ type: constants.SHORTCUT, payload: feature })102 break103 }104 case constants.GO_TO_CAREERS: {105 navigate('/careers')106 store.dispatch({ type: constants.SHORTCUT, payload: feature })107 break108 }109 case constants.GO_TO_LABS: {110 navigate('/labs')111 store.dispatch({ type: constants.SHORTCUT, payload: feature })112 break113 }114 case constants.GO_TO_ARTICLES: {115 navigate('/articles')116 store.dispatch({ type: constants.SHORTCUT, payload: feature })117 break118 }119 case constants.GO_TO_ARTICLE: {120 navigate(`/articles/${feature.path}`)121 store.dispatch({ type: constants.SHORTCUT, payload: feature })122 break123 }124125 // Go to Fey126 case constants.GO_TO_FEY: {127 window.open('https://feyapp.com', '_blank')128 store.dispatch({ type: constants.SHORTCUT, payload: feature })129 break130 }131132 // Social133 case constants.GO_TO_TWITTER: {134 window.open(settings.urls.twitter, '_blank')135 store.dispatch({ type: constants.SHORTCUT, payload: feature })136 break137 }138 case constants.GO_TO_LINKEDIN: {139 window.open(settings.urls.linkedin, '_blank')140 store.dispatch({ type: constants.SHORTCUT, payload: feature })141 break142 }143 case constants.GO_TO_INSTAGRAM: {144 window.open(settings.urls.instagram, '_blank')145 store.dispatch({ type: constants.SHORTCUT, payload: feature })146 break147 }148149 // Open source150 case constants.GO_TO_GIFTINGWILD_GITHUB: {151 window.open('https://github.com/giftingwild/giftingwild.com', '_blank')152 store.dispatch({ type: constants.SHORTCUT, payload: feature })153 break154 }155 case constants.GO_TO_GIFTINGWILD: {156 window.open('https://www.giftingwild.com/design/open/giftingwild', '_blank')157 store.dispatch({ type: constants.SHORTCUT, payload: feature })158 break159 }160 case constants.GO_TO_FEY_LOGO: {161 window.open('https://www.giftingwild.com/design/open/fey', '_blank')162 store.dispatch({ type: constants.SHORTCUT, payload: feature })163 break164 }165 case constants.GO_TO_HOPPER_WWW: {166 window.open('https://www.giftingwild.com/design/open/hopper', '_blank')167 store.dispatch({ type: constants.SHORTCUT, payload: feature })168 break169 }170 // case constants.GO_TO_HOPPER_MEDIA: {171 // window.open('https://www.giftingwild.com/design/open/hopper', '_blank')172 // store.dispatch({ type: constants.SHORTCUT, payload: feature })173 // break174 // }175176 // Single key commands177 case constants.CONTACT: {178 store.dispatch({ type: constants.SHORTCUT, payload: feature })179 break180 }181 case constants.ESCAPE: {182 store.dispatch({ type: constants.ESCAPE })183 break184 }185186 default:187 console.log(`Found no matching shortcut features for ${feature.name}`)188 break189 }190 },191192 handleBackToDefault(event: KeyboardEvent) {193 if (event.key === 'Backspace') {194 const input = document.getElementById(195 'CommandLineInput'196 ) as HTMLInputElement197 const isInputEmpty = input.value === ''198199 if (isInputEmpty) {200 return api.handleShortcutFeature({201 name: constants.COMMAND_LINE_DEFAULT,202 })203 }204 }205 },206 }207208 return api
...
citysdk-geo-request.js
Source:citysdk-geo-request.js
1import Promise from 'promise';2import CitySdk from './citysdk';3import CitySdkSummaryRequest from './citysdk-summary-request';4import CitySdkTigerwebRequest from './citysdk-tigerweb-request';5export default class CitySdkGeoRequest {6 static supplementalRequest(req, res, featureIndex) {7 let i = featureIndex;8 let features = res.features;9 let variables = req.variables;10 // Sometimes cities span multiple counties. In this case,11 // we sometimes miss data due to the limited nature of12 // the Census API's geography hierarchy. This will issue13 // supplemental requests to ensure we have data for all of14 // our geojson entities15 let suppRequest = {16 state: features[i].properties['STATE'],17 tract: features[i].properties['TRACT'],18 county: features[i].properties['COUNTY'],19 blockGroup: features[i].properties['BLKGRP'],20 place: features[i].properties['PLACE'],21 lat: parseFloat(features[i].properties.CENTLAT),22 lng: parseFloat(features[i].properties.CENTLON),23 level: req.level,24 year: req.year,25 api: req.api,26 variables: variables,27 featuresIndex: i,28 apikey: req.apikey29 };30 let promiseHandler = (resolve, reject) => {31 let censusSummaryRequest = CitySdkSummaryRequest.request(suppRequest);32 censusSummaryRequest.then((response) => {33 for (let property in response.data[0]) {34 if (response.data[0].hasOwnProperty(property)) {35 features[response.featuresIndex].properties[property] = response.data[0][property];36 if (variables.indexOf(property) !== -1) {37 res.totals[property] = Number(res.totals[property]) >= 0 ? Number(response.data[0][property]) : 0;38 }39 }40 }41 resolve(response);42 });43 censusSummaryRequest.catch((reason) => {44 reject(reason);45 });46 };47 return new Promise(promiseHandler);48 }49 static handleTigerwebResponse(tigerwebResponse) {50 let request = tigerwebResponse.request;51 let response = tigerwebResponse.response;52 let supplementalRequests = [];53 // Reference dictionary of levels -> geocoder response variables54 let comparisonVariables = {55 'tract': 'TRACT',56 'place': 'PLACE',57 'county': 'COUNTY',58 'blockGroup': 'BLKGRP'59 };60 if (!response.totals) {61 response.totals = {};62 }63 if (request.data) {64 let data = request.data;65 let variables = request.variables;66 let totals = response.totals;67 let features = response.features;68 let matchedFeature;69 features.forEach((f, i) => {70 matchedFeature = data.filter((d) => {71 // Ensure we have a direct match for low level items by comparing the higher level items72 if (request.level === 'blockGroup' || request.level === 'tract') {73 let levelMatch = d[request.level] === f.properties[comparisonVariables[request.level]];74 let tractMatch = d['tract'] === f.properties.TRACT;75 let countyMatch = d['county'] === f.properties.COUNTY;76 return levelMatch && tractMatch && countyMatch;77 } else {78 return d[request.level] === f.properties[comparisonVariables[request.level]];79 }80 });81 if (matchedFeature.length === 0) {82 supplementalRequests.push(CitySdkGeoRequest.supplementalRequest(request, response, i))83 } else if (matchedFeature.length === 1) {84 // We have matched the feature's tract to a data tract, move the data over85 matchedFeature = matchedFeature[0];86 for (let property in matchedFeature) {87 if (matchedFeature.hasOwnProperty(property)) {88 f.properties[property] = matchedFeature[property];89 if (variables.indexOf(property) !== -1) {90 totals[property] = Number(totals[property]) >= 0 ? Number(matchedFeature[property]) : 0;91 }92 }93 }94 } else {95 // This usually occurs when a low-level geography entity isn't uniquely identified96 // by the grep. We'll need to add more comparisons to the grep to clear this issue up.97 console.log('Multiple matched features: ');98 console.log(f);99 console.log(matchedFeature);100 }101 });102 }103 let promiseHandler = (resolve, reject) => {104 // If supplemental requests were needed, wait for all105 // to finish.106 if (supplementalRequests.length) {107 Promise.all(supplementalRequests)108 .then(() => resolve(response))109 .catch((reason) => reject(reason))110 } else {111 setTimeout(() => resolve(response), 0);112 }113 };114 return new Promise(promiseHandler);115 }116 static request(request) {117 let promiseHandler = (resolve, reject) => {118 CitySdk.request(request)119 .then(CitySdkTigerwebRequest.request)120 .then(CitySdkGeoRequest.handleTigerwebResponse)121 .then((response) => resolve(response))122 .catch((reason) => reject(reason));123 };124 return new Promise(promiseHandler);125 }...
heatmap.js
Source:heatmap.js
1// import { getLongitudeFromCurb, getLatitudeFromCurb } from '../utils/heatmap';2// import {AsburyPark} from './constants/asbury-park';3import {AsburyParkSpaces} from '../constants/asbury-park-spaces';4//api => state5export const heatmapModelToState = (payload) => {6 // debugger;7 const unfilteredOutput = payload.map(obj => {8 if (!obj.space) {9 return;10 }11 const matchedFeature = AsburyParkSpaces.features.find((feature) => {12 return feature.properties.spacename === obj.space;13 });14 return [15 //latitude16 matchedFeature.geometry.coordinates[0][1],17 //longitude18 matchedFeature.geometry.coordinates[0][0],19 //intesity20 obj.value21 ];22 });23 return unfilteredOutput.filter(el => el !== undefined);24}25//state => api26export const heatmapModelFromState = (state) => {27 const {28 startDate,29 endDate,30 selectedParkingSpaces,31 selectedCurbs,32 showSpaces,33 geojsonData,34 } = state;35 let parkingSpaces = [];36 parkingSpaces = selectedParkingSpaces.map(space => {37 if (space) {38 return `${space}`;39 }40 });41 // TODO - fix42 // if (showSpaces) {43 // parkingSpaces = selectedParkingSpaces.map(space => {44 // if (space) {45 // return `${space}`;46 // }47 // });48 // } else {49 // geojsonData.features.map((feature) => {50 // if (selectedCurbs[feature.properties.curbline_id]) {51 // if (feature.properties.spaces) {52 // parkingSpaces.push(feature.properties.spaces);53 // }54 // }55 // });56 // }57 return {58 datetime_range: {59 start: startDate.utc().format(),60 end: endDate.utc().format(),61 },62 parking_spaces: parkingSpaces,63 }...
Using AI Code Generation
1import React from 'react';2import {storiesOf} from '@storybook/react';3import {action} from '@storybook/addon-actions';4import {linkTo} from '@storybook/addon-links';5import {Button, Welcome} from '@storybook/react/demo';6import {matchedFeature} from 'storybook-root';7import {withKnobs, text, boolean, number} from '@storybook/addon-knobs/react';8storiesOf('Button', module)9 .addDecorator(withKnobs)10 .add('with text', () => (11 <Button onClick={action('clicked')}>Hello Button</Button>12 .add('with some emoji', () => (13 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>14 .add('with knobs', () => (15 <Button onClick={action('clicked')}>{text('Label', 'Hello Button')}</Button>16 .add('with matching feature', () => (17 <Button onClick={action('clicked')}>{matchedFeature('feature1', 'Hello Button')}</Button>18 ));19storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')}/>);
Using AI Code Generation
1import { matchedFeature } from 'storybook-root';2import { matchedFeature } from 'storybook-root';3import { matchedFeature } from 'storybook-root';4import { matchedFeature } from 'storybook-root';5import { matchedFeature } from 'storybook-root';6import { matchedFeature } from 'storybook-root';7import { matchedFeature } from 'storybook-root';8import { matchedFeature } from 'storybook-root';9import { matchedFeature } from 'storybook-root';10import { matchedFeature } from 'storybook-root';11import { matchedFeature } from 'storybook-root';12import { matchedFeature } from 'storybook-root';13import { matchedFeature } from 'storybook-root';14import { matchedFeature } from 'storybook-root';15import { matchedFeature } from 'storybook-root';16import { matchedFeature } from 'storybook-root';17import { matchedFeature } from 'storybook-root';18import { matchedFeature } from 'storybook-root';19import { matchedFeature } from 'storybook-root';20import { matchedFeature } from 'storybook-root';
Using AI Code Generation
1const { matchedFeature } = require('storybook-root');2const matchedFeature = require('storybook-root').matchedFeature;3const { matchedFeature } = require('storybook-root/matchedFeature');4const matchedFeature = require('storybook-root/matchedFeature').default;5const matchedFeature = require('storybook-root/matchedFeature');6const matchedFeature = require('storybook-root/matchedFeature');7const matchedFeature = require('storybook-root/matchedFeature');8const { matchedFeature } = require('storybook-root/matchedFeature');9const matchedFeature = require('storybook-root/matchedFeature');10const matchedFeature = require('storybook-root/matchedFeature');11const matchedFeature = require('storybook-root/matchedFeature');12const matchedFeature = require('storybook-root/matchedFeature');
Using AI Code Generation
1var storybookRoot = document.querySelector('storybook-root');2var matchedFeature = storybookRoot.matchedFeature;3console.log(matchedFeature);4var storybookRoot = document.querySelector('storybook-root');5var matchedFeature = storybookRoot.matchedFeature;6console.log(matchedFeature);7var storybookRoot = document.querySelector('storybook-root');8var matchedFeature = storybookRoot.matchedFeature;9console.log(matchedFeature);10var storybookRoot = document.querySelector('storybook-root');11var matchedFeature = storybookRoot.matchedFeature;12console.log(matchedFeature);13var storybookRoot = document.querySelector('storybook-root');14var matchedFeature = storybookRoot.matchedFeature;15console.log(matchedFeature);16var storybookRoot = document.querySelector('storybook-root');17var matchedFeature = storybookRoot.matchedFeature;18console.log(matchedFeature);19var storybookRoot = document.querySelector('storybook-root');20var matchedFeature = storybookRoot.matchedFeature;21console.log(matchedFeature);22var storybookRoot = document.querySelector('storybook-root');23var matchedFeature = storybookRoot.matchedFeature;24console.log(matchedFeature);25var storybookRoot = document.querySelector('storybook-root');26var matchedFeature = storybookRoot.matchedFeature;27console.log(matchedFeature);28var storybookRoot = document.querySelector('storybook-root');29var matchedFeature = storybookRoot.matchedFeature;30console.log(matchedFeature);
Using AI Code Generation
1import {matchedFeature} from 'storybook-root';2matchedFeature('featureName', () => {3});4import {matchedFeature} from 'storybook-root';5matchedFeature('featureName', () => {6});7import {matchedFeature} from 'storybook-root';8matchedFeature('featureName', () => {9});10import {matchedFeature} from 'storybook-root';11matchedFeature('featureName', () => {12});13import {matchedFeature} from 'storybook-root';14matchedFeature('featureName', () => {15});16import {matchedFeature} from 'storybook-root';17matchedFeature('featureName', () => {18});19import {matchedFeature} from 'storybook-root';20matchedFeature('featureName', () => {21});22import {matchedFeature} from 'storybook-root';23matchedFeature('featureName', () => {24});25import {matchedFeature} from 'storybook-root';26matchedFeature('featureName', () => {27});
Using AI Code Generation
1import { matchedFeature } from "storybook-root";2import { Feature } from "storyboard";3const feature = new Feature("test");4feature.addScenario("test", () => {5 const matched = matchedFeature("test");6 console.log(matched);7});8export default feature;9import { matchedFeature } from "storybook-root";10import { Feature } from "storyboard";11const feature = new Feature("storybook-root");12feature.addScenario("storybook-root", () => {13 const matched = matchedFeature("storybook-root");14 console.log(matched);15});16export default feature;17import { matchedFeature } from "storybook-root";18import { Feature } from "storyboard";19const feature = new Feature("storybook-root");20feature.addScenario("storybook-root", () => {21 const matched = matchedFeature("storybook-root");22 console.log(matched);23});24export default feature;25I have tried to mock the matchedFeature method of storybook-root.js file in storybook-root.test.js file using jest.mock() method with the following options:26jest.mock("storybook-root", () => ({27 matchedFeature: jest.fn().mockImplementation(() => true),28}));29I have tried to mock the matchedFeature method of storybook-root.js file in storybook-root.test.js file using jest.mock() method with the following options:30jest.mock("storybook
Using AI Code Generation
1import { matchedFeature } from 'storybook-root'2import { getFeature } from 'storybook-root'3const feature = getFeature('test')4const feature = matchedFeature('test')5import { matchedFeature } from 'storybook-root'6import { getFeature } from 'storybook-root'7const feature = getFeature('test')8const feature = matchedFeature('test')9import { matchedFeature } from 'storybook-root'10import { getFeature } from 'storybook-root'11const feature = getFeature('test')12const feature = matchedFeature('test')13import { matchedFeature } from 'storybook-root'14import { getFeature } from 'storybook-root'15const feature = getFeature('test')16const feature = matchedFeature('test')17import { matchedFeature } from 'storybook-root'18import { getFeature } from 'storybook-root'19const feature = getFeature('test')20const feature = matchedFeature('test')21import { matchedFeature } from 'storybook-root'22import { getFeature } from 'storybook-root'23const feature = getFeature('test')24const feature = matchedFeature('test')25import { matchedFeature } from 'storybook-root'26import { getFeature } from 'storybook-root'27const feature = getFeature('test')28const feature = matchedFeature('test')29import { matchedFeature } from 'storybook-root'30import { getFeature } from 'storybook-root'
Using AI Code Generation
1import { matchedFeature } from 'storybook-root';2const feature = matchedFeature();3console.log(feature);4import { storiesOf, addDecorator } from '@storybook/react';5import { withFeature } from 'storybook-root';6import MyFeature from './index.js';7storiesOf('My Feature', module)8 .addDecorator(withFeature('my-feature'))9 .add('default', () => <MyFeature />);10import React from 'react';11import { feature } from 'storybook-root';12const MyFeature = () => {13 const { name, description } = feature();14 return (15 <h1>{name}</h1>16 <p>{description}</p>17 );18};19export default MyFeature;20toggle(): void21enable(): void22disable(): void23hide(): void24show(): void25lock(): void26unlock(): void27addTag(tag: string): void28removeTag(tag: string): void29toggleTag(tag: string): void30setLockMessage(message: string): void31setUnlockMessage(message: string): void32setUnlockCode(code: string): void33setUnlockCodeTries(tries: number): void34resetUnlockCodeTriesRemaining(): void35setDisableMessage(message: string): void36setEnableMessage(message: string): void
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!!