Best JavaScript code snippet using storybook-root
preset-loader.ts
Source:preset-loader.ts
1// LICENSE : MIT2import { moduleInterop } from "@textlint/module-interop";3import { TextLintModuleResolver } from "./textlint-module-resolver";4import { normalizeTextlintPresetSubRuleKey } from "@textlint/utils";5import { isPresetRuleKey } from "./config-util";6import { TextlintConfigDescriptor } from "./TextlintConfigDescriptor";7/**8 * Convert config of preset to rawRulesConfig flat path format.9 *10 * This function convert Preset nesting rule to flat path11 * ```12 * {13 * "x" : true14 * "preset-a" : { "rule-name": "value" }15 * }16 * ```17 * =>18 * ```19 * { "x": true }20 * { "a/rule-name": "value" }21 * ```22 *23 * @param rawRulesConfig24 * @returns {{string: string}}25 */26export function createFlatRulesConfigFromRawRulesConfig(rawRulesConfig: any) {27 if (!rawRulesConfig) {28 return {};29 }30 const rulesConfig: { [index: string]: any } = {};31 Object.keys(rawRulesConfig).forEach((key) => {32 if (isPresetRuleKey(key)) {33 // <preset>/<rule>34 const presetName = key;35 const presetRuleConfig = rawRulesConfig[key];36 Object.assign(37 rulesConfig,38 createFlatPresetRulesConfigFromRawPresetRuleConfig(presetRuleConfig, presetName)39 );40 return;41 }42 rulesConfig[key] = rawRulesConfig[key];43 });44 return rulesConfig;45}46/**47 * create flat `<plugin>/<rule>` option48 * @param {Object} [rulesConfig]49 * @param {string} presetName50 * @returns {Object}51 */52export function createFlatPresetRulesConfigFromRawPresetRuleConfig(53 rulesConfig: { [index: string]: string },54 presetName: string55): object {56 const mapped: { [index: string]: string } = {};57 // missing "rulesConfig"58 if (rulesConfig === undefined || typeof rulesConfig !== "object") {59 return mapped;60 }61 Object.keys(rulesConfig).forEach((ruleName) => {62 const normalizedKey = normalizeTextlintPresetSubRuleKey({ preset: presetName, rule: ruleName });63 mapped[normalizedKey] = rulesConfig[ruleName];64 });65 return mapped;66}67// load rulesConfig from plugins68/**69 *70 * @param presetNames71 * @param {TextLintModuleResolver} moduleResolver72 * @returns {{}}73 */74export function loadRulesConfigFromPresets(75 presetNames: string[] = [],76 moduleResolver: TextLintModuleResolver77): {78 [index: string]: boolean | {};79} {80 const presetRulesConfig: {81 [index: string]: boolean | {};82 } = {};83 presetNames.forEach((presetName) => {84 const presetPackageName = moduleResolver.resolvePresetPackageName(presetName);85 const preset = moduleInterop(require(presetPackageName.filePath));86 if (!preset.hasOwnProperty("rules")) {87 throw new Error(`${presetName} has not rules`);88 }89 if (!preset.hasOwnProperty("rulesConfig")) {90 throw new Error(`${presetName} has not rulesConfig`);91 }92 // set config of <rule> to "<preset>/<rule>"93 Object.assign(94 presetRulesConfig,95 createFlatPresetRulesConfigFromRawPresetRuleConfig(preset.rulesConfig, presetName)96 );97 });98 return presetRulesConfig;99}100export function loadPreset({101 presetName,102 userDefinedRuleOptions,103 moduleResolver104}: {105 presetName: string;106 userDefinedRuleOptions:107 | boolean108 | {109 [index: string]: boolean | {};110 };111 moduleResolver: TextLintModuleResolver;112}): TextlintConfigDescriptor["rules"] {113 const presetPackageName = moduleResolver.resolvePresetPackageName(presetName);114 const preset = moduleInterop(require(presetPackageName.filePath));115 if (!preset.hasOwnProperty("rules")) {116 throw new Error(`${presetName} has not rules`);117 }118 if (!preset.hasOwnProperty("rulesConfig")) {119 throw new Error(`${presetName} has not rulesConfig`);120 }121 // we should use preset.rules â some preset use different name actual rule122 return Object.keys(preset.rules).map((ruleId) => {123 const userDefinedOptions = typeof userDefinedRuleOptions !== "boolean" ? userDefinedRuleOptions?.[ruleId] : {};124 const normalizedKey = normalizeTextlintPresetSubRuleKey({ preset: presetName, rule: ruleId });125 return {126 ruleId: normalizedKey,127 rule: preset.rules[ruleId],128 // prefer textlintrc content than default value of preset129 options: userDefinedOptions ?? preset.rulesConfig[ruleId],130 filePath: "",131 moduleName: ""132 };133 });...
PresetButtons.js
Source:PresetButtons.js
1import { connect } from 'react-redux'2import OnScreenPresetButtonsBody from '../Templates/Shared/PresetButtonsBody'3import uiController from '../Controllers/UIController'4const staticPresetNames = [5 "PRESET_0",6 "PRESET_1",7 "PRESET_2",8 "PRESET_3",9 "PRESET_4",10 "PRESET_5"11];12const mapStateToProps = (state) => {13 var activeApp = state.activeApp;14 var appUI = {};15 var subscribedButtons = [];16 var presetStrings = [];17 var presets = [];18 if (activeApp) {19 appUI = state.ui[activeApp];20 subscribedButtons = appUI.subscribedButtons;21 presetStrings = appUI.customPresets;22 }23 for (var i=0; i<staticPresetNames.length; i++) {24 var name = staticPresetNames[i];25 if (!subscribedButtons[name]) {26 // Preset button is not subscribed to, skip27 continue;28 }29 var label = "";30 if (presetStrings[i]) {31 label = presetStrings[i];32 } else {33 label = "Preset " + i.toString();34 }35 presets.push({36 label: label,37 name: name38 })39 }40 //Assign color scheme to props41 var theme = state.theme42 var colorScheme = null;43 if (theme === true) { //Dark theme44 if(appUI.nightColorScheme) {45 colorScheme = {}46 if(appUI.nightColorScheme.primaryColor) {47 colorScheme["primary"] = appUI.nightColorScheme.primaryColor48 }49 if(appUI.nightColorScheme.secondaryColor) {50 colorScheme["secondary"] = appUI.nightColorScheme.secondaryColor51 }52 }53 } else {54 if(appUI.dayColorScheme) { //Light theme55 colorScheme = {}56 if(appUI.dayColorScheme.primaryColor) {57 colorScheme["primary"] = appUI.dayColorScheme.primaryColor58 }59 if(appUI.dayColorScheme.secondaryColor) {60 colorScheme["secondary"] = appUI.dayColorScheme.secondaryColor61 }62 }63 }64 return {65 presets: presets,66 appID: activeApp,67 theme: state.theme,68 colorScheme: colorScheme69 }70}71var presetsTimeoutMap = {};72const onLongButtonPress = (appID, presetName) => {73 // int cast to string to index json object74 var appIDStr = appID.toString();75 if (presetsTimeoutMap[appIDStr].hasOwnProperty(presetName) 76 && presetsTimeoutMap[appIDStr][presetName]) {77 presetsTimeoutMap[appIDStr][presetName] = null;78 uiController.onLongButtonPress(appID, undefined, presetName);79 } 80}81const mapDispatchToProps = (dispatch) => {82 return {83 onButtonDown: (appID, presetName) => {84 // int cast to string to index json object85 var appIDStr = appID.toString();86 presetsTimeoutMap[appIDStr] = presetsTimeoutMap[appIDStr] ? presetsTimeoutMap[appIDStr] : {};87 // Save timeout to clear later88 presetsTimeoutMap[appIDStr][presetName] = setTimeout(onLongButtonPress, 3000, appID, presetName);89 uiController.onButtonEventDown(appID, undefined, presetName);90 },91 onButtonUp: (appID, presetName) => {92 // int cast to string to index json object93 var appIDStr = appID.toString();94 if (presetsTimeoutMap[appIDStr][presetName]) {95 // Short press, clear long press timeout96 clearTimeout(presetsTimeoutMap[appIDStr][presetName]);97 presetsTimeoutMap[appIDStr][presetName] = null;98 uiController.onShortButtonPress(appID, undefined, presetName)99 }100 uiController.onButtonEventUp(appID, undefined, presetName);101 delete presetsTimeoutMap[appIDStr][presetName];102 103 },104 onButtonPress: (appID, presetName) => {105 uiController.onButtonPress(appID, undefined, presetName)106 }107 }108}109export const PresetButtons = connect(110 mapStateToProps,111 mapDispatchToProps...
index.ts
Source:index.ts
1import { GenerateConfiguration } from "./Configuration/GenerateConfiguration";2import { PresetName } from "./PresetName";3export { ESLintPlugin } from "./ESLintPlugin";4export { ESLintRule } from "./ESLintRule";5export { PresetName } from "./PresetName";6export { TSLintRule } from "./TSLintRule";7export { GenerateConfiguration as GenerateESLintConfiguration } from "./Configuration/GenerateConfiguration";8export { GenerateConfiguration as GenerateTSLintConfiguration } from "./Configuration/TSLint/GenerateConfiguration";9/**10 * The name of the plugin.11 */12export const PluginName = "@manuth/typescript";13let cache: Map<PresetName, any> = new Map();14/**15 * Loads the preset with the specified {@link presetName `presetName`}.16 *17 * @param presetName18 * The name of the preset to load.19 *20 * @returns21 * The preset with the specified {@link presetName `presetName`}.22 */23function LoadPreset(presetName: PresetName): any24{25 if (!cache.has(presetName))26 {27 let weak: boolean;28 let typeChecking: boolean;29 switch (presetName)30 {31 case PresetName.Recommended:32 case PresetName.RecommendedWithTypeChecking:33 weak = false;34 break;35 default:36 weak = true;37 break;38 }39 switch (presetName)40 {41 case PresetName.RecommendedWithTypeChecking:42 case PresetName.WeakWithTypeChecking:43 typeChecking = true;44 break;45 default:46 typeChecking = false;47 break;48 }49 cache.set(presetName, GenerateConfiguration(weak, typeChecking));50 }51 return cache.get(presetName);52}53/**54 * Provides configurations for `eslint`.55 */56export const configs = {57 get [PresetName.Recommended]()58 {59 return LoadPreset(PresetName.Recommended);60 },61 get [PresetName.RecommendedWithTypeChecking]()62 {63 return LoadPreset(PresetName.RecommendedWithTypeChecking);64 },65 get [PresetName.Weak]()66 {67 return LoadPreset(PresetName.Weak);68 },69 get [PresetName.WeakWithTypeChecking]()70 {71 return LoadPreset(PresetName.WeakWithTypeChecking);72 }...
Using AI Code Generation
1const { presetName } = require('storybook-root');2module.exports = presetName('react');3{4 "scripts": {5 },6 "dependencies": {7 }8}9module.exports = {10 presets: [require.resolve('./test.js')],11};12export const parameters = {13 actions: { argTypesRegex: "^on[A-Z].*" },14};15import { addons } from '@storybook/addons';16import { themes } from '@storybook/theming';17addons.setConfig({18});19 console.log('This is manager-head.html');20 console.log('This is preview-head.html');21 console.log('This is preview-body.html');22 console.log('This is iframe.html');23import { configure } from '@storybook/react';24import { addParameters } from '@storybook/react';25import { themes } from '@storybook/theming';26addParameters({27 options: {28 },29});30configure(require.context('../src', true, /\.stories\.js$/), module);31import '@storybook/addon-actions/register';32import '@storybook/addon-links/register';33import '@storybook/addon-knobs/register';34import '@storybook/addon-viewport/register';35import '@storybook/addon-docs/register';36import '@storybook/addon-a11y/register';37import '@storybook/addon-background
Using AI Code Generation
1const { presetName } = require('@storybook/addon-docs/preset');2module.exports = {3 stories: ['../src/**/*.stories.(js|mdx)'],4};5import { addDecorator } from '@storybook/react';6import { withA11y } from '@storybook/addon-a11y';7import { withKnobs } from '@storybook/addon-knobs';8import { withInfo } from '@storybook/addon-info';9import { setDefaults } from '@storybook/addon-info';10setDefaults({11});12addDecorator(withA11y);13addDecorator(withKnobs);14addDecorator(withInfo);15const path = require('path');16module.exports = async ({ config, mode }) => {17 config.module.rules.push({18 test: /\.(ts|tsx)$/,19 {20 loader: require.resolve('awesome-typescript-loader'),21 },22 {23 loader: require.resolve('react-docgen-typescript-loader'),24 },25 });26 config.resolve.extensions.push('.ts', '.tsx');27 return config;28};29module.exports = {30 stories: ['../src/**/*.stories.(js|mdx)'],31 webpackFinal: async config => {32 config.module.rules.push({33 test: /\.(ts|tsx)$/,34 {35 loader: require.resolve('awesome-typescript-loader'),36 },37 {38 loader: require.resolve('react-docgen-typescript-loader'),39 },40 });41 config.resolve.extensions.push('.ts', '.tsx');42 return config;43 },44};45import { addons } from '@storybook/addons';46addons.setConfig({47 theme: {48 },49});50{51 "compilerOptions": {
Using AI Code Generation
1import { presetName } from 'storybook-root';2console.log(presetName);3import { presetName } from 'storybook-root/lib/preset';4console.log(presetName);5import { presetName } from 'storybook-root/lib/preset/preset.js';6console.log(presetName);7import { presetName } from 'storybook-root/lib/preset/preset.js';8console.log(presetName);9import { presetName } from 'storybook-root/lib/preset/preset.js';10console.log(presetName);11import { presetName } from 'storybook-root/lib/preset/preset.js';12console.log(presetName);13import { presetName } from 'storybook-root/lib/preset/preset.js';14console.log(presetName);15import { presetName } from 'storybook-root/lib/preset/preset.js';16console.log(presetName);17import { presetName } from 'storybook-root/lib/preset/preset.js';18console.log(presetName);19import { presetName } from 'storybook-root/lib/preset/preset.js';20console.log(presetName);21import { presetName } from 'storybook-root/lib/preset/preset.js';22console.log(presetName);23import { presetName } from 'storybook-root/lib/preset/preset.js';24console.log(presetName);25import { presetName } from 'storybook-root/lib/preset/preset.js';26console.log(presetName);27import { presetName } from 'storybook-root/lib/preset/preset.js';28console.log(presetName);29import { presetName } from 'storybook-root/lib/preset/preset.js';30console.log(presetName);
Using AI Code Generation
1import { presetName } from 'storybook-root-decorator';2export default {3 decorators: [presetName('PresetName')],4};5export const presetName = () => <div>hello world</div>;6import { addDecorator } from '@storybook/react';7import rootDecorator from 'storybook-root-decorator';8addDecorator(rootDecorator);9import { configure } from '@storybook/react';10import requireContext from 'require-context.macro';11const req = requireContext('../', true, /.stories.js$/);12function loadStories() {13 req.keys().forEach(filename => req(filename));14}15configure(loadStories, module);16import 'storybook-root-decorator/register';17const path = require('path');18module.exports = async ({ config }) => {19 config.resolve.alias = {20 'storybook-root-decorator': path.resolve(__dirname, '../'),21 };22 return config;23};24{25 "compilerOptions": {26 "paths": {27 }28 }29}
Using AI Code Generation
1import { presetName } from 'storybook-root-decorator';2import { presetName } from 'storybook-root-decorator';3presetName('presetName');4import { presetName } from 'storybook-root-decorator';5presetName('presetName');6import { presetName } from 'storybook-root-decorator';7presetName('presetName');8import { presetName } from 'storybook-root-decorator';9presetName('presetName');10import { presetName } from 'storybook-root-decorator';11presetName('presetName');
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!!