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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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,.25);
  border-color: rgba(248,249,250,.25);
}

.blur {
	filter: blur(.1rem);
}

.blur:hover {
  filter: none;
}

pre {
  font-size: x-small;
}
              
            
!

JS

              
                console.clear()

const TITLE = 'ReactJS: Iframe component'
const LEAD = 'With maximise to full dimension button'
const DEG = randInt(360)
const BG = [randColor(),randColor()]
const FLEX = false

function Iframe(props) {
  const {src,className='',style={}} = props
  const {width,height} = useDimension()
  const [max,setMax] = React.useState(false)
  
  if (!src) {
    return null
  }
  
  function toggle(e) {
    e.preventDefault()
    setMax(!max)
  }
  
  const classNames = [className,max?'position-fixed':'position-relative']
  const cStyle = max?{
    ...style,
    width,
    height,
    left:0,
    top:0,
    zIndex:99,
  }:style
  
  return (
    <div className={classNames.join(' ')} style={cStyle}>
      <div className="position-absolute" style={{right:0}} data-tootik={max?'Minimize':'Maximize'} data-tootik-conf={`${max?'left':'top'} delay`}>
        <button className="btn btn-light" onClick={toggle}>{max?'\u2926':'\u2922'}</button>
      </div>
      <iframe className="w-100" src={src} style={{border:'none',...cStyle}}></iframe>
    </div>
  )
}

const YOUTUBE_EMBED_URL = 'https://www.youtube.com/embed/'

const LIST = [
  {id:'xDMP3i36naA',name:'Wildlife'},
  {id:'LXb3EKWsInQ',name:'Cost Rica'},
  {id:'1La4QzGeaaQ',name:'Peru'},
  {id:'tO01J-M3g0U',name:'The World'},
  {id:'hVvEISFw9w0',name:'Morocco'},
  {id:'N1-Jmq7BLFE',name:'Bulgaria'},
  {id:'mHUOCxVT5ro',name:'Yellowstone National Park'},
]

function App() {
  const {width,height} = useDimension()
  
  const [src,setSrc] = React.useState()
  
  React.useEffect(()=>{
    const {id} = LIST[0]
    const src = `${YOUTUBE_EMBED_URL}${id}`
    setSrc(src)
  }, [])
  
  return (
    <FlexContainer deg={DEG} bg={BG} flex={FLEX}>
      <div className="container">
        <div className="h1 pt-3 text-center text-white text-shadow">{TITLE}</div>
        <p className="lead text-center text-light text-shadow">{LEAD}</p>
        
        <Details summary="The Code" className="mb-3"><PreCode>{`${Iframe}`}</PreCode></Details>
        
        <h5 className="text-center text-white text-shadow">Usage</h5>
        
        <PreCode>{`<Iframe src="https://www.mjunaidi.com" />`}</PreCode>
        <Iframe src="https://www.mjunaidi.com" className="w-100 rounded mb-3" />
        
        <PreCode>{`<Iframe src="https://mjunaidi.github.io" />`}</PreCode>
        <Iframe src="https://mjunaidi.github.io" className="w-100 rounded mb-3" />
        
        <h5 className="text-center text-white text-shadow">Example</h5>
        
        <Iframe src={src} className="w-100 rounded mb-2" />
        
        <Section center mb="3">
          <PreCode className="text-left">{`<Iframe src="${src}" />`}</PreCode>
          {LIST.map((e,i)=>{
            const {id,name} = e
            const url = `${YOUTUBE_EMBED_URL}${id}`
            const classNames = ['m-1 btn rounded-pill shadow-sm text-truncate overflow-hidden']
            if (src===url) {
              classNames.push('btn-primary')
            } else {
              classNames.push('btn-light border')
            }
            return (
              <button key={i} className={classNames.join(' ')} style={{maxWidth:240,fontSize:10}} onClick={e=>setSrc(url)}>{name}</button>
            )
          })}
        </Section>
        
      </div>
    </FlexContainer>
  )
}

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

function TableEditor(props) {
  const {value,onChange,className=''} = props
  const classNames = ['table-sm',className]
  function handleChange(e,i,j) {
    let v = e.target.value
    if (typeof(v)==='string'&&v.length>0&&v.charAt(v.length-1)!=='.') {
      const n = Number(v)
      if (typeof(n)==='number'&&!isNaN(n)) {
        v = n
      }
    }
    onChange([...value.slice(0,i),[...value[i].slice(0,j),v,...value[i].slice(j+1)],...value.slice(i+1)],i,j)
  }
  function render(e,i,j) {
    return (
      <input value={e} className="form-control" onChange={e=>handleChange(e,i,j)} />
    )
  }
  return (
    <Table value={value} render={render} className={classNames.join(' ')} />
  )
}

function Table(props) {
  const {value,className='',render} = props
  if (Array.isArray(value)&&value.length>0) {
    const classNames = ['table',className]
    return (
      <table className={classNames.join(' ')}>
        <tbody>
          {value.map((e,i)=>{
            if (typeof(e)==='object'&&e!==null) {
              return (
                <tr key={i}>
                  {Object.keys(e).map((k,j)=>{
                    const v = e[k]
                    function renderValue() {
                      if (typeof(render)==='function') return render(v,i,j)
                      return v
                    }
                    return (
                      <td key={j}>{renderValue()}</td>
                    )
                  })}
                </tr>
              )
            }
            return null
          })}
        </tbody>
      </table>
    )
  }
  return null
}

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('')}`
}

function toNumber(n,d=-1) {
  if (typeof(n)==='number'&&!isNaN(n)) return n
  if (typeof(n)==='string'&&n.length>0) {
    if (n.indexOf('.')>=0) return toNumber(parseFloat(n),d)
    else return toNumber(parseInt(n),d)
  }
  if (Array.isArray(n)&&n.length>0) return toNumber(n[0],d)
  if (typeof(n)==='object'&&n!==null) {
    const keys = Object.keys(n)
    if (Array.isArray(keys)&&keys.length>0) return toNumber(n[keys[0]],d)
  }
  if (typeof(d)==='number'&&!isNaN(d)) return d
  return -1
}

function lipsum(n=10,dot=false) {
  if (typeof(n)!=='number'||(typeof(n)==='number'&&n<1)) n=10
  const words = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit', 'vivamus', 'et', 'accumsan', 'augue', 'duis', 'eget', 'nunc', 'id', 'sodales', 'finibus', 'vestibulum', 'sagittis', 'magna', 'nec', 'rutrum', 'volutpat', 'risus', 'tincidunt', 'justo', 'non', 'gravida', 'tortor', 'enim', 'in', 'urna', 'ut', 'vel', 'metus', 'pellentesque', 'porttitor', 'vitae', 'nisi', 'nullam', 'faucibus', 'condimentum', 'quam', 'imperdiet', 'class', 'aptent', 'taciti', 'sociosqu', 'ad', 'litora', 'torquent', 'per', 'conubia', 'nostra', 'inceptos', 'himenaeos', 'interdum', 'malesuada', 'fames', 'ac', 'ante', 'primis', 'curabitur', 'nibh', 'quis', 'iaculis', 'cras', 'mollis', 'eu', 'congue', 'leo']
  const count = n
  const sentence = []
  const indexes = (new Array(count)).fill(0).map(index=>Math.floor(Math.random()*words.length))
  indexes.forEach((index,i)=>{
    const word = words[index]
    if (i===0)
      sentence.push(word.charAt(0).toUpperCase()+word.substr(1))
    else
      sentence.push(word)
  })
  if (dot) return sentence.join(' ').concat('.')
  return sentence.join(' ')
}

function getDimension() {
  if (typeof(window)==='object') {
    const {innerWidth,innerHeight} = window
    return {width:innerWidth,height:innerHeight}
  }
  return {}
}

function useDimension() {
  const [dimension,setDimension] = React.useState(getDimension())
  React.useEffect(()=>{
    function handleResize() {
      setDimension(getDimension())
    }
    window.addEventListener('resize', handleResize)
    return ()=>window.removeEventListener('resize', handleResize)
  }, [])
  return dimension
}

// usage <Row noGutters>...</Row>
// <Row noGutters><Col></Col><Col></Col></Row>
function Row(props) {
  const {className='',noGutters=false,children} = props
  const classNames = [className,'row']
  if (noGutters) classNames.push('no-gutters')
  return (
    <div className={classNames.join(' ')}>{children}</div>
  )
}

// usage <Col>...</Col>
// <Col n={12} sm={8} md={6} lg={4} xl={2} />
function Col(props) {
  const {className='',children,n,sm,md,lg,xl} = props
  const classNames = [className]
  
  if (typeof(n)==='number'&&n>0&&n<=12) classNames.push(`col-${n}`)
  
  // Extra small <576px	Small ≥576px	Medium ≥768px	Large ≥992px	Extra large ≥1200px
  // Max container width	None (auto)	540px	720px	960px	1140px
  // Class prefix	.col-	.col-sm-	.col-md-	.col-lg-	.col-xl-
  
  if (typeof(sm)==='number'&&sm>0&&sm<=12) classNames.push(`col-sm-${sm}`)
  if (typeof(md)==='number'&&md>0&&md<=12) classNames.push(`col-md-${md}`)
  if (typeof(lg)==='number'&&lg>0&&lg<=12) classNames.push(`col-lg-${lg}`)
  if (typeof(xl)==='number'&&xl>0&&xl<=12) classNames.push(`col-xl-${xl}`)
  
  if (classNames.length<2) classNames.push('col')
  
  return (
    <div className={classNames.join(' ')}>{children}</div>
  )
}

// usage <Box random />
// <Box backgroundColor={randColor()} />
function Box(props) {
  const {className='',children,style={minHeight:50},backgroundColor,random=false} = props
  
  const classNames = [className, 'w-100 d-flex justify-content-center align-items-center']
  
  if (typeof(backgroundColor)==='string'&&backgroundColor.length>0) style.backgroundColor = backgroundColor
  
  if (random) style.backgroundColor = randColor()
  
  return (
    <div className={classNames.join(' ')} style={style}>{children}</div>
  )
}

function Section(props) {
  const {children,className='',center=false} = props
  const classNames = ['p-3 bg-white rounded shadow',className]
  if (center) classNames.push('text-center')
  
  const mb = toNumber(props.mb,3)
  if (typeof(mb)==='number'&&mb>=0&&mb<=5) classNames.push(`mb-${mb}`)
  
  return (
    <div className={classNames.join(' ')}>{children}</div>
  )
}

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

Console