Best JavaScript code snippet using storybook-root
preset.js
Source:preset.js
1'use strict';2(function () {3 var KeyCode = {4 LEFT: 37,5 UP: 38,6 RIGHT: 39,7 DOWN: 408 };9 var MAX_BLUR = 3;10 var MAX_BRIGHTNESS = 3;11 var BRIGHTNESS_CORRECTION = 1;12 var MIN_PIN_POSITION = 0;13 var PIN_KEYPRESS_STEP = 10;14 var PIN_POSITION_MIN_CORRECTION = 20;15 var PIN_POSITION_MAX_CORRECTION = 474;16 var picturePreview = document.querySelector('.img-upload__preview img');17 var sliderBlock = document.querySelector('.effect-level');18 var sliderPresetLevel = sliderBlock.querySelector('.effect-level__value');19 var sliderPin = sliderBlock.querySelector('.effect-level__pin');20 var sliderLine = sliderBlock.querySelector('.effect-level__line');21 var sliderDepthLine = sliderBlock.querySelector('.effect-level__depth');22 var sliderLineWidth;23 // reset filter after filter selection from filter list ----------------------24 var resetPreset = function () {25 picturePreview.style.filter = '';26 sliderPresetLevel.value = 0;27 picturePreview.className = '';28 sliderPin.style.left = sliderLineWidth + 'px';29 sliderDepthLine.style.width = sliderLineWidth + 'px';30 };31 // get values for presets -----------------------------------------------------32 var getSaturation = function () {33 var value = (sliderPin.offsetLeft34 / sliderLineWidth).toFixed(2);35 return value;36 };37 var getBlur = function () {38 var value = (sliderPin.offsetLeft * MAX_BLUR39 / sliderLineWidth).toFixed(2);40 return value;41 };42 var getBrightness = function () {43 var value = (((sliderPin.offsetLeft44 * (MAX_BRIGHTNESS - BRIGHTNESS_CORRECTION))45 / sliderLineWidth) + BRIGHTNESS_CORRECTION).toFixed(2);46 return value;47 };48 // change filter saturation --------------------------------------------------49 var setPresetValue = function () {50 var filter = document.querySelector('#upload-select-image input[name="effect"]:checked');51 var presetResult;52 switch (filter.value) {53 case 'chrome':54 presetResult = getSaturation();55 picturePreview.style.filter = 'grayscale(' + presetResult + ')';56 break;57 case 'sepia':58 presetResult = getSaturation();59 picturePreview.style.filter = 'sepia(' + presetResult + ')';60 break;61 case 'marvin':62 presetResult = getSaturation() * 100;63 picturePreview.style.filter = 'invert(' + presetResult + '%' + ')';64 break;65 case 'phobos':66 presetResult = getBlur();67 picturePreview.style.filter = 'blur(' + presetResult + 'px' + ')';68 break;69 case 'heat':70 presetResult = getBrightness();71 picturePreview.style.filter = 'brightness(' + presetResult + ')';72 break;73 }74 sliderPresetLevel.value = presetResult;75 };76 // filter select from filter list ---------------------------------------------77 var toggleSlider = function (isVisible) {78 sliderBlock.classList.toggle('hidden', isVisible);79 };80 var onSampleClick = function (evt) {81 var target = evt.target;82 toggleSlider(target.value === 'none');83 sliderLineWidth = sliderLine.offsetWidth;84 resetPreset();85 setPresetValue();86 picturePreview.classList.add('effects__preview--' + target.value);87 };88 // change slider pin position on line click or by arrows key press -----------89 var setLinePosition = function (value) {90 sliderPin.style.left = value + 'px';91 sliderDepthLine.style.width = value + 'px';92 };93 var onSliderLineClick = function (evt) {94 var sliderLineClickPoint;95 var target = evt.target;96 if (target === sliderDepthLine || target === sliderLine) {97 sliderLineClickPoint = evt.offsetX;98 }99 if (target === sliderBlock) {100 if (evt.offsetX < PIN_POSITION_MIN_CORRECTION) {101 sliderLineClickPoint = MIN_PIN_POSITION;102 } else if (evt.offsetX > PIN_POSITION_MAX_CORRECTION) {103 sliderLineClickPoint = sliderLineWidth;104 } else {105 sliderLineClickPoint = evt.offsetX - PIN_POSITION_MIN_CORRECTION;106 }107 }108 setLinePosition(sliderLineClickPoint);109 setPresetValue();110 };111 var onSliderPinArrowPress = function (evt) {112 evt.preventDefault();113 if (evt.keyCode === KeyCode.LEFT || evt.keyCode === KeyCode.DOWN) {114 if (sliderPin.offsetLeft <= MIN_PIN_POSITION + PIN_KEYPRESS_STEP) {115 sliderPin.style.left = MIN_PIN_POSITION + PIN_KEYPRESS_STEP + 'px';116 }117 var posXminus = sliderPin.offsetLeft - PIN_KEYPRESS_STEP;118 setLinePosition(posXminus);119 setPresetValue();120 }121 if (evt.keyCode === KeyCode.RIGHT || evt.keyCode === KeyCode.UP) {122 evt.preventDefault();123 if (sliderPin.offsetLeft >= sliderLineWidth - PIN_KEYPRESS_STEP) {124 sliderPin.style.left = sliderLineWidth - PIN_KEYPRESS_STEP + 'px';125 }126 var posXplus = sliderPin.offsetLeft + PIN_KEYPRESS_STEP;127 setLinePosition(posXplus);128 setPresetValue();129 }130 };131 // change slider pin position -----------------------------------------------132 var setPinPosition = function (shift) {133 var shiftedLeft = sliderPin.offsetLeft - shift;134 var maxPinPosition = sliderLineWidth;135 if (shiftedLeft >= MIN_PIN_POSITION && shiftedLeft <= maxPinPosition) {136 sliderPin.style.left = shiftedLeft + 'px';137 sliderDepthLine.style.width = shiftedLeft + 'px';138 }139 };140 // slider listener ----------------------------------------------------------141 sliderPin.addEventListener('mousedown', function (evt) {142 evt.preventDefault();143 var startCoords = {144 x: evt.clientX,145 };146 var onMouseMove = function (moveEvt) {147 moveEvt.preventDefault();148 var shift = {149 x: startCoords.x - moveEvt.clientX150 };151 startCoords = {152 x: moveEvt.clientX153 };154 setPinPosition(shift.x);155 setPresetValue();156 };157 var onMouseUp = function (upEvt) {158 upEvt.preventDefault();159 document.removeEventListener('mousemove', onMouseMove);160 document.removeEventListener('mouseup', onMouseUp);161 };162 document.addEventListener('mousemove', onMouseMove);163 document.addEventListener('mouseup', onMouseUp);164 });165 window.preset = {166 reset: resetPreset,167 onSampleClick: onSampleClick,168 onSliderLineClick: onSliderLineClick,169 onSliderPinArrowPress: onSliderPinArrowPress,170 toggleSlider: toggleSlider171 };...
BBText.js
Source:BBText.js
1import React from 'react';2import BBCode from '@bbob/react/es/Component'3import reactPreset from '@bbob/preset-react/es'4import SpringyImage from './SpringyImage';5import SafeLink from './SafeLink';6import Streamable from './Streamable';7const getClassName = (attrs) => attrs && attrs.className ? attrs.className : '';8const hClasses = {9 h1: 'text-6xl',10 h2: 'text-5xl',11 h3: 'text-4xl',12 h4: 'text-3xl',13 h5: 'text-2xl',14 h6: 'text-xl'15};16const preset = reactPreset.extend(presetTags => {17 const tags = ({18 ...presetTags,19 p: (node) => ({20 tag: 'p',21 attrs: {22 className: `my-4 ${getClassName(node.attrs)}`23 },24 content: node.content25 }),26 b: (...args) => ({27 ...presetTags.b(...args),28 attrs: {29 style: {fontWeight: 500 }30 },31 content: args[0].content32 }),33 br: () => ({ tag: 'br' }),34 url: (node, ctx) => {35 const isInternal = !!node.attrs.internal;36 delete node.attrs.internal;37 const presetResult = presetTags.url(node, ctx);38 return ({39 ...presetResult,40 tag: isInternal ? 'a' : SafeLink41 });42 },43 purple: node => ({44 tag: 'span',45 attrs: {46 className: 'text-accent-purple'47 },48 content: node.content49 }),50 flex: node => {51 const wrap = node.attrs.wrap ? 'flex-wrap' : '';52 const direction = node.attrs.col ? 'flex-column' : 'flex-row';53 const justify = node.attrs.justify ? `justify-${node.attrs.justify}` : '';54 return ({55 tag: 'div',56 attrs: {57 className: `flex ${direction} ${wrap} ${justify}`.trim()58 },59 content: node.content60 });61 },62 ul: node => ({63 tag: 'ul',64 attrs: {65 className: 'pl-10 list-disc'66 },67 content: node.content68 }),69 li: node => ({70 tag: 'li',71 content: node.content72 }),73 img: (...args) => {74 const presetResult = presetTags.img(...args);75 return ({76 ...presetResult,77 tag: args[0].attrs.inline ? 'img' : SpringyImage,78 attrs: {79 ...presetResult.attrs,80 className: `h-full shadow-md ${81 getClassName(args[0].attrs)82 } ${83 args[0].attrs.inline ? 'inline' : ''84 } ${85 args[0].attrs.center ? '' : 'mx-auto'86 }`,87 alt: args[0].attrs.alt || '',88 width: args[0].attrs.width,89 height: args[0].attrs.height90 }91 });;92 },93 streamable: node => ({94 tag: Streamable,95 attrs: {96 src: node.attrs.src,97 className: getClassName(node.attrs) || 'relative mx-auto h-streamable shadow-md'98 }99 }),100 quote: node => ({101 tag: 'blockquote',102 attrs: {103 cite: node.attrs.cite || '',104 className: 'bg-gray-300 mx-10 my-3 p-3'105 },106 content: node.content107 })108 });109 Object.keys(hClasses).forEach((hClassKey) => {110 tags[hClassKey] = node => ({111 tag: hClassKey,112 attrs: {113 className: `${hClasses[hClassKey]} ${getClassName(node.attrs)}`114 },115 content: node.content116 });117 });118 return tags;119});120const BBText = ({ children }) => (121 <BBCode122 plugins={[preset()]}123 >124 {children}125 </BBCode>126);...
presets.js
Source:presets.js
1import { logger } from '@storybook/node-logger';2function interopRequireDefault(filePath) {3 // eslint-disable-next-line global-require,import/no-dynamic-require4 const result = require(`${filePath}`);5 const isES6DefaultExported =6 typeof result === 'object' && result !== null && typeof result.default !== 'undefined';7 return isES6DefaultExported ? result.default : result;8}9function loadPreset(preset) {10 try {11 if (typeof preset === 'string') {12 return {13 preset: interopRequireDefault(preset),14 options: {},15 };16 }17 const { name, options } = preset;18 return {19 preset: interopRequireDefault(name),20 options,21 };22 } catch (e) {23 logger.warn(` Failed to load preset: ${JSON.stringify(preset)}`);24 logger.error(e);25 return false;26 }27}28function loadPresets(presets) {29 if (!presets || !Array.isArray(presets) || !presets.length) {30 return [];31 }32 logger.info('=> Loading presets');33 const result = presets.map(loadPreset).filter(preset => preset);34 return result;35}36function applyPresets(presets, config, args = {}, extension) {37 const presetResult = new Promise(resolve => resolve(config));38 if (!presets.length) {39 return presetResult;40 }41 return presets.reduce((accumulationPromise, { preset, options }) => {42 const extensionFn = preset[extension];43 if (extensionFn && typeof extensionFn === 'function') {44 const context = {45 extensionFn,46 preset,47 combinedOptions: { ...args, ...options },48 };49 return accumulationPromise.then(newConfig =>50 context.extensionFn.call(context.preset, newConfig, context.combinedOptions)51 );52 }53 return accumulationPromise;54 }, presetResult);55}56function getPresets(presets) {57 const loadedPresets = loadPresets(presets);58 return {59 apply: async (extension, config, args) => applyPresets(loadedPresets, config, args, extension),60 };61}...
Using AI Code Generation
1import { presetResult } from 'storybook-root-decorator';2import { withKnobs } from '@storybook/addon-knobs';3export default {4};5export const test = () => {6 return 'Hello World';7};8import { withRootDecorator } from 'storybook-root-decorator';9import { addDecorator } from '@storybook/react';10addDecorator(withRootDecorator);11import { addons } from '@storybook/addons';12import { create } from '@storybook/theming';13addons.setConfig({14 theme: create({
Using AI Code Generation
1import { presetResult } from 'storybook-root';2import { presetResult } from 'storybook-root';3import { presetResult } from 'storybook-root';4import { presetResult } from 'storybook-root';5import { presetResult } from 'storybook-root';6import { presetResult } from 'storybook-root';7import { presetResult } from 'storybook-root';8import { presetResult } from 'storybook-root';9import { presetResult } from 'storybook-root';10import { presetResult } from 'storybook-root';11import { presetResult } from 'storybook-root';12import { presetResult } from 'storybook-root';13import { presetResult } from 'storybook-root';
Using AI Code Generation
1import { presetResult } from 'storybook-root';2import { presetResult } from 'storybook-root';3import { presetResult } from 'storybook-root';4import { presetResult } from 'storybook-root';5import { presetResult } from 'storybook-root';6import { presetResult } from 'storybook-root';7import { presetResult } from 'storybook-root';8import { presetResult } from 'storybook-root';9import { presetResult } from 'storybook-root';10import { presetResult } from 'storybook-root';
Using AI Code Generation
1import { presetResult } from 'storybook-root';2import { shallow } from 'enzyme';3import { expect } from 'chai';4describe('test', () => {5 it('should test', () => {6 const wrapper = shallow(<TestComponent />);7 expect(wrapper.find('div')).to.have.length(1);8 });9});
Using AI Code Generation
1import { presetResult } from 'storybook-root-decorator';2presetResult({3});4presetResult({5});6presetResult({7});8presetResult({9});10presetResult({
Using AI Code Generation
1import { presetResult } from 'storybook-root';2describe('Test', () => {3 it('should work', () => {4 const result = presetResult();5 expect(result).toBe(true);6 });7});8import { presetResult } from 'storybook-root';9describe('Test', () => {10 it('should work', () => {11 const result = presetResult();12 expect(result).toBe(true);13 });14});15import { presetResult } from 'storybook-root';16describe('Test', () => {17 it('should work', () => {18 const result = presetResult();19 expect(result).toBe(true);20 });21});22import { presetResult } from 'storybook-root';23describe('Test', () => {24 it('should work', () => {25 const result = presetResult();26 expect(result).toBe(true);27 });28});29import { presetResult } from 'storybook-root';30describe('Test', () => {31 it('should work', () => {32 const result = presetResult();33 expect(result).toBe(true);34 });35});
Using AI Code Generation
1import { presetResult } from "storybook-root";2presetResult("some story", "some result");3import { getResult } from "storybook-root";4getResult("some story");5import { getResult } from "storybook-root";6getResult("some story");7import { getResult } from "storybook-root";8getResult("some story");9import { getResult } from "storybook-root";10getResult("some story");11import { getResult } from "storybook-root";12getResult("some story");13import { getResult } from "storybook-root";14getResult("some story");15import { getResult } from "storybook-root";16getResult("some story");17import { getResult } from "storybook-root";18getResult("some story");19import { getResult } from "storybook-root";20getResult("some story");21import { getResult } from "storybook-root";22getResult("some story");23import { getResult } from "storybook-root";24getResult("some story");25import { getResult } from "storybook-root";26getResult("some story");27import { getResult } from "storybook-root";28getResult("some story");29import { getResult } from "storybook-root";30getResult("some story");31import { getResult } from "storybook-root";32getResult("some story");
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!!