Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="root"></div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Architects+Daughter');
body{font-family:'Architects Daughter';}

/*@import url('https://fonts.googleapis.com/css?family=Cabin+Sketch');
body{font-family:'Cabin Sketch';}*/

/*@import url('https://fonts.googleapis.com/css?family=Fredericka+the+Great');
body{font-family:'Fredericka the Great';}*/

/*@import url('https://fonts.googleapis.com/css?family=Fredoka+One');
body{font-family:'Fredoka One';}*/

/*@import url('https://fonts.googleapis.com/css?family=Rock+Salt');
body{font-family:'Rock Salt';}*/

/*@import url('https://fonts.googleapis.com/css?family=Shadows+Into+Light+Two');
body{font-family:'Shadows Into Light Two';}*/

/*@import url('https://fonts.googleapis.com/css?family=Short+Stack');
body{font-family:'Short Stack';}*/

/*@import url('https://fonts.googleapis.com/css?family=Sue+Ellen+Francisco');
body{font-family:'Sue Ellen Francisco';}*/

/*@import url('https://fonts.googleapis.com/css?family=Swanky+and+Moo+Moo');
body{font-family:'Swanky and Moo Moo';}*/

/*@import url('https://fonts.googleapis.com/css?family=Waiting+for+the+Sunrise');
body{font-family:'Waiting for the Sunrise';}*/

/*@import url('https://fonts.googleapis.com/css?family=Bad+Script');
body{font-family:'Bad Script';}*/

html,body,#root {
  height: 100%;
}

.vh-100 {
  height: 100vh;
}

.pill {
  border-radius: 2.5rem;
}

pre {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.text-shadow {
  text-shadow: 0 0.25rem 0.75rem #2f4f4f;
}

.top-left {
  position: fixed;
  top: 25px;
  left: 25px;
}

.top-right {
  position: fixed;
  top: 25px;
  right: 25px;
}

.bottom-right {
  position: fixed;
  bottom: 25px;
  right: 25px;
}

.btn-dark {
  color: rgba(255,255,255,.75);
  background: rgba(34,58,40,.5);
  border-color: rgba(34,58,40,.5);
}

.btn-light {
  color: rgba(0,0,0,.75);
  background: rgba(248,249,250,.5);
  border-color: rgba(248,249,250,.5);
}

.center {
  margin-left: auto;
  margin-right: auto;
}

.transition {
  transition: all 0.5s ease;
}
              
            
!

JS

              
                console.clear()

const TITLE = 'ReactJS: FlexBox animated transition'
const LEAD = ''
const DEG = randInt(360)
const BG = [randColor(),randColor()]

function Box(props) {
  const {children,w,h,bg,className='',style={}} = props
  const classNames = ['transition p-3 text-center rounded shadow',className]
  if (typeof(w)==='number'&&w>0) style.width = w
  if (typeof(h)==='number'&&h>0) style.height = h
  if (typeof(bg)==='string'&&bg.length>0) style.background = bg
  return (
    <div className={classNames.join(' ')} style={style}>{children}</div>
  )
}

const W = 75
const H = W
const BOX = {w:W,h:H,bg:randColor()}

function App() {
  
  const [box,setBox] = React.useState(BOX)
  
  // k: key, m: multiplier
  function update(k,m) {
    setBox({...box,[k]:box[k]*m})
  }
  
  function inc() {
    setBox({...box,w:box.w*2,h:box.h*2})
  }
  
  function dec() {
    setBox({...box,w:box.w*.5,h:box.h*.5})
  }
  
  const incw = ()=>update('w',2)
  const decw = ()=>update('w',.5)
  const inch = ()=>update('h',2)
  const dech = ()=>update('h',.5)
  
  return (
    <FlexContainer deg={DEG} bg={BG}>
      <div className="container">
        <div className="h1 text-center text-white text-shadow">{TITLE}</div>
        <p className="lead text-center text-light text-shadow">{LEAD}</p>
        <div className="p-3 bg-white rounded shadow">
          
          <div className="text-center mb-3">
            <button className="center btn btn-success rounded-pill pl-3 pr-3 m-1 shadow" onClick={inc}>+</button>
            <button className="center btn btn-danger rounded-pill pl-3 pr-3 m-1 shadow" onClick={dec}>-</button>
            
            <button className="center btn btn-success rounded-pill pl-3 pr-3 m-1 shadow" onClick={incw}>+ width</button>
            <button className="center btn btn-danger rounded-pill pl-3 pr-3 m-1 shadow" onClick={decw}>- width</button>
            <button className="center btn btn-success rounded-pill pl-3 pr-3 m-1 shadow" onClick={inch}>+ height</button>
            <button className="center btn btn-danger rounded-pill pl-3 pr-3 m-1 shadow" onClick={dech}>- height</button>
          </div>
          
          <Box {...box} className="text-white text-shadow center">{`I'm a Box`}</Box>
        </div>
      </div>
    </FlexContainer>
  )
}

function FlexContainer(props) {
  const {children,deg=randInt(360),bg,style={}} = props
  if (Array.isArray(bg)&&bg.length>0) {
    style.background = `linear-gradient(${deg}deg,${bg.join(',')})`
  }
  return (
    <div className="d-flex align-content-center align-items-center justify-content-center flex-wrap w-100 v-100 vh-100" style={style}>{children}</div>
  )
}

function Details(props) {
  const {summary='details',children,className=''} = props
  return (
    <details className={className}><summary>{summary}</summary><div className="mt-3 animated faster slideInDown">{children}</div></details>
  )
}

function PreCode(props) {
  const {ugly,className='',children} = props
  
  if (typeof(children)==='object'&&children!==null) {
    if (ugly) {
      return (
        <PreCode {...props}>{JSON.stringify(children)}</PreCode>
      )
    }
    return (
      <PreCode {...props}>{JSON.stringify(children,null,2)}</PreCode>
    )
  }
  
  return (
    <pre className={`p-3 bg-dark text-white rounded shadow ${className}`}><code>{children}</code></pre>
  )
}

function randInt(n=10) {
  return Math.floor(Math.random()*n)
}

function randColor() {
  return `#${[...Array(3).keys()].map(e=>(randInt(238)+17).toString(16)).join('')}`
}

ReactDOM.render(
  <App/>,
  document.getElementById('root')
);
              
            
!
999px

Console