How to use CenteredBlock method in storybook-root

Best JavaScript code snippet using storybook-root

index.js

Source:index.js Github

copy

Full Screen

1import View from '../View';2import GameManager from '../../../game/GameManager';3import Constants from '../../../utils/Constants';4import './style.scss';5import background_jpg from '../../images/background.jpg';6import game_lost_png from '../../images/game_over_splash_lost.png';7import game_won_png from '../../images/game_over_splash_won.png';8export default class GameView extends View {9 open(root, data = null) {10 this.root = root;11 if (data !== null && data.type === 'FullSwapScene') {12 this.addRestartButton = function() {/*placeholder func*/};13 }14 const {appWidth, appHeight} = this._findAppWidthHeight();15 const gameField = this._setupAppCanvas(appWidth, appHeight);16 this._setupGameManager(gameField, appWidth, appHeight);17 this.gameManager.initiateGame(data);18 this.fullScreenOpener = function(e) {19 if (e.keyCode === 70) {20 this.toggleFullScreen();21 e.preventDefault();22 }23 }.bind(this);24 this.gameCanvas = document.querySelector('canvas');25 this.endGameWrapper = document.createElement('div');26 this.endGameWrapper.classList.add('endgame-wrapper');27 this.root.appendChild(this.endGameWrapper);28 this.gameCanvas.style.display = 'block';29 this.gameCanvas.style.margin = 'auto';30 // document.body.style.overflow = 'hidden';31 document.addEventListener('keydown', this.fullScreenOpener, false);32 }33 close() {34 document.removeEventListener('keydown', this.fullScreenOpener, false);35 document.body.style.overflow = '';36 this.gameManager.destroy();37 this.gameManager = null;38 delete this;39 }40 _findAppWidthHeight() {41 let appWidth = window.innerWidth * Constants.WINDOW_SCALE;42 let appHeight = Math.round(appWidth * Constants.WINDOW_HD_RATIO_INVERSE);43 if (appHeight > window.innerHeight) {44 appHeight = window.innerHeight * Constants.WINDOW_SCALE;45 appWidth = Math.round(appHeight * Constants.WINDOW_HD_RATIO);46 }47 return {appWidth, appHeight};48 }49 _findAppWidthHeightInner() {50 return;51 }52 _setupAppCanvas(appWidth, appHeight) {53 this.root.innerHTML = '';54 // this.root.classList.add('fullscreen');55 const gameFieldWrapper = document.createElement('div');56 gameFieldWrapper.style.position = 'relative';57 gameFieldWrapper.style.width = '100%';58 gameFieldWrapper.style.height = '100%';59 this.root.appendChild(gameFieldWrapper);60 const background = document.createElement('div');61 background.classList.add('game-background');62 background.classList.add('fullscreen');63 background.style.position = 'absolute';64 background.style.top = '0';65 background.style.left = '0';66 background.style.background = `url(${background_jpg})`;67 background.style.width = '100%';68 background.style.height = '100%';69 this._background = background;70 this._moveBackgroundAngle = 1.2;71 this._moveBackground();72 gameFieldWrapper.appendChild(background);73 const versionNumber = 'v1.0.0'; //change this if you're not sure if your changes are passing through74 const versionDisplay = document.createElement('div');75 versionDisplay.style.position = 'fixed';76 versionDisplay.style.zIndex = '10';77 versionDisplay.style.left = '5px';78 versionDisplay.style.bottom = '0';79 versionDisplay.style.userSelect = 'none';80 versionDisplay.innerHTML = versionNumber;81 gameFieldWrapper.appendChild(versionDisplay);82 const gameField = document.createElement('div');83 gameField.style.height = '100vh';84 gameField.classList.add('fullscreen');85 gameFieldWrapper.appendChild(gameField);86 const glow = document.createElement('div');87 glow.classList.add('fullscreen');88 glow.style.position = 'absolute';89 glow.style.top = '0';90 glow.style.left = '0';91 glow.style.background = 'linear-gradient(90deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 50%)';92 glow.style.width = '100%';93 glow.style.height = '100%';94 this._glow = glow;95 this._glowProgress = -200;96 this._doGlow('0');97 this.serviceLocator.eventBus.subscribeOn('game_health_block_beat_player_left',98 () => this._startGlow('90'), this);99 this.serviceLocator.eventBus.subscribeOn('game_health_block_beat_player_right',100 () => this._startGlow('-90'), this);101 gameFieldWrapper.appendChild(glow);102 const scrollHolder = document.createElement('div');103 scrollHolder.style.width = '0';104 scrollHolder.style.height = '110%';105 gameFieldWrapper.appendChild(scrollHolder);106 setTimeout(function() { window.scrollTo(0, 1); }, 100);107 this.gameField = gameField;108 return gameField;109 }110 _displayWinMessage() {111 const centeredBlock = this._createCenteredImage();112 centeredBlock.style.background = `url(${game_won_png})`;113 centeredBlock.style.backgroundSize = 'contain';114 centeredBlock.style.backgroundRepeat = 'no-repeat';115 centeredBlock.style.backgroundPosition = 'center center';116 }117 _displayLoseMessage() {118 const centeredBlock = this._createCenteredImage();119 centeredBlock.style.background = `url(${game_lost_png})`;120 centeredBlock.style.backgroundSize = 'contain';121 centeredBlock.style.backgroundRepeat = 'no-repeat';122 centeredBlock.style.backgroundPosition = 'center center';123 }124 _createCenteredImage() {125 const centeredBlock = document.createElement('div');126 // centeredBlock.style.position = 'fixed';127 centeredBlock.style.width = '90%';128 centeredBlock.style.height = '30.515625%';129 centeredBlock.style.zIndex = '50';130 this.endGameWrapper.appendChild(centeredBlock);131 return centeredBlock;132 }133 _moveBackground() {134 clearTimeout(this._backgroundTimeout);135 this._backgroundTimeout = setTimeout(() => {136 this._fixResizeBackground();137 this._background.style.backgroundPositionX = `${Math.cos(this._moveBackgroundAngle) * 150 - 150}px`;138 this._background.style.backgroundPositionY = `${-Math.sin(this._moveBackgroundAngle) * 150 - 150}px`;139 this._moveBackgroundAngle += 0.005;140 if (this._moveBackgroundAngle > 6.28) {141 this._moveBackgroundAngle = 0;142 }143 this._moveBackground();144 }, 25);145 }146 _fixResizeBackground() {147 if (this._prevWindowWidth === window.innerWidth) {148 return;149 }150 if (this._prevWindowHeight === window.innerHeight) {151 return;152 }153 this._prevWindowWidth = window.innerWidth;154 this._prevWindowHeight = window.innerHeight;155 let backgroundWidth = window.innerWidth + 300;156 const backgroundHeight = window.innerHeight + 300;157 if (backgroundHeight > backgroundWidth) {158 backgroundWidth = backgroundHeight / 800 * 1280;159 }160 this._background.style.backgroundSize = `${backgroundWidth}px ${backgroundHeight}px`;161 }162 _startGlow(deg) {163 this._glowProgress = -150;164 this._doGlow(deg);165 }166 _doGlow(deg) {167 clearTimeout(this._glowTimeout);168 this._glowTimeout = setTimeout(() => {169 this._glow.style.background = `linear-gradient(${deg}deg,170 rgba(55, 255, 255, 0),171 rgba(55, 255, 255, 0) ${this._glowProgress}%,172 rgba(55, 255, 255, 0.3) ${this._glowProgress + 50}%,173 rgba(55, 255, 255, 0.3) ${this._glowProgress + 100}%,174 rgba(55, 255, 255, 0) ${this._glowProgress + 150}%)`;175 this._glowProgress += 10;176 if (this._glowProgress > 300) {177 this._glowProgress = -150;178 return;179 }180 this._doGlow(deg);181 }, 25);182 }183 toggleFullScreen() {184 if (!document.fullscreenElement && // alternative standard method185 !document.mozFullScreenElement && !document.webkitFullscreenElement) { // current working methods186 if (document.documentElement.requestFullscreen) {187 document.documentElement.requestFullscreen();188 } else if (document.documentElement.mozRequestFullScreen) {189 document.documentElement.mozRequestFullScreen();190 } else if (document.documentElement.webkitRequestFullscreen) {191 document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);192 }193 } else {194 if (document.cancelFullScreen) {195 document.cancelFullScreen();196 } else if (document.mozCancelFullScreen) {197 document.mozCancelFullScreen();198 } else if (document.webkitCancelFullScreen) {199 document.webkitCancelFullScreen();200 }201 }202 }203 _setupGameManager(gameField, appWidth, appHeight) {204 this.gameManager = new GameManager(this.serviceLocator, this.addEndGameButtons.bind(this),205 this._findAppWidthHeight, this._displayWinMessage.bind(this), this._displayLoseMessage.bind(this));206 this.gameManager.setGameField(gameField);207 this.gameManager.setResolution([appWidth, appHeight]);208 }209 refresh() {210 if (!this.serviceLocator.gameRefreshed) {211 const currentUrlPath = location.pathname;212 console.log(currentUrlPath);213 this.serviceLocator.router.changePage('/');214 this.serviceLocator.router.changePage(currentUrlPath);215 } else {216 location.reload();217 }218 this.serviceLocator.gameRefreshed = !this.serviceLocator.gameRefreshed;219 }220 addEndGameButtons() {221 this.addMenuButton();222 this.addRestartButton();223 }224 addMenuButton() {225 const backToMenuButton = document.createElement('button');226 backToMenuButton.innerHTML = 'Back to menu';227 backToMenuButton.classList.add('endgame-button');228 backToMenuButton.onclick = this.serviceLocator.router.changePage229 .bind(this.serviceLocator.router, '/');230 backToMenuButton.style.position = 'absolute';231 backToMenuButton.style.padding = '0.5em';232 backToMenuButton.style.top = '60%';233 this.endGameWrapper.appendChild(backToMenuButton);234 }235 addRestartButton() {236 const restartButton = document.createElement('button');237 restartButton.innerHTML = 'Restart the game';238 restartButton.classList.add('endgame-button');239 restartButton.onclick = this.refresh.bind(this);240 restartButton.style.position = 'absolute';241 restartButton.style.padding = '0.5em';242 restartButton.style.top = '70%';243 this.endGameWrapper.appendChild(restartButton);244 }...

Full Screen

Full Screen

centered_block.js

Source:centered_block.js Github

copy

Full Screen

1import React from 'react';2import PropTypes from 'prop-types';3import styled from 'styled-components';4export const CenteredBlockStyle = styled.div`5 height: 100%;6 background: #e1e1e1;7 justify-content: center;8 display: flex;9`;10export const CenteredBlockContentStyle = styled.div`11 width: ${props => props.width};12 display: flex;13 align-self: center;14 position: relative;15 top: -10%;16`;17class CenteredBlock extends React.Component {18 render () {19 return (20 <CenteredBlockStyle>21 <CenteredBlockContentStyle width={this.props.width}>22 {this.props.children}23 </CenteredBlockContentStyle>24 </CenteredBlockStyle>25 );26 }27}28CenteredBlock.propTypes = {29 width: PropTypes.string,30 children: PropTypes.object31};32CenteredBlock.defaultProps = {33 width: '60%'34};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import centered from 'storybook-root-decorator';2import { storiesOf } from '@storybook/react';3storiesOf('Test', module)4 .addDecorator(centered)5 .add('Test', () => <div>Test</div>);6import centered from 'storybook-root-decorator';7import { configure } from '@storybook/react';8function loadStories() {9 require('../test.js');10}11configure(loadStories, module);

Full Screen

Using AI Code Generation

copy

Full Screen

1import centered from '@storybook/addon-centered/react'2storiesOf('MyComponent', module)3 .addDecorator(centered)4 .add('with text', () => <MyComponent />)5 .add('with some emoji', () => <MyComponent />)6 .add('with centered block', () => (7import { configure } from '@storybook/react'8import { addDecorator } from '@storybook/react'9import centered from '@storybook/addon-centered/react'10addDecorator(centered)11configure(require.context('../src', true, /\.stories\.js$/), module)12const path = require('path')13module.exports = (baseConfig, env, defaultConfig) => {14 defaultConfig.module.rules.push({15 loaders: [require.resolve('@storybook/addon-storysource/loader')],16 include: [path.resolve(__dirname, '../src')],17 })18}19import '@storybook/addon-actions/register'20import '@storybook/addon-links/register'21import '@storybook/addon-knobs/register'22import '@storybook/addon-storysource/register'23import '@storybook/addon-options/register'24import '@storybook/addon-viewport/register'25import '@storybook/addon-notes/register'26import '@storybook/addon-centered/register'27import React from 'react'28import { addDecorator } from '@storybook/react'29import centered from '@storybook/addon-centered/react'30addDecorator(centered)31import { addons } from '@storybook/addons'32import theme from './theme'33addons.setConfig({34})35import { create } from '@storybook/theming'36export default create({37})38import { configure, addDecorator } from '@storybook/react'39import { withOptions } from '@storybook/addon-options'40addDecorator(41 withOptions({

Full Screen

Using AI Code Generation

copy

Full Screen

1import centered from 'storybook-root-decorator';2export default {3};4export const MyComponent = () => <MyComponent />;5import centered from 'storybook-root-decorator';6export default {7 decorators: [centered({ centeringMethod: 'CenteredBlock' })],8};

Full Screen

Using AI Code Generation

copy

Full Screen

1import centered from 'storybook-root-decorator';2export default centered(storyFn => <div style={{width: '50%'}}>{storyFn()}</div>);3import centered from './test.js';4storiesOf('MyComponent', module)5 .addDecorator(centered)6 .add('with text', () => (7 .add('with some emoji', () => (8 ));9import { addParameters, addDecorator } from '@storybook/react';10import { withKnobs } from '@storybook/addon-knobs';11addDecorator(withKnobs);12addParameters({13 options: {14 },15});16import { addParameters, addDecorator } from '@storybook/react';17import { withActions } from '@storybook/addon-actions';18addDecorator(withActions('click .btn'));19addParameters({20 options: {21 },22});

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful