Pen Settings



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


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


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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.




              $green: #B0DE6B
$blue: #76C9DE
$dark-gray: #948F8F
$light-gray: #ddd

  background: $light-gray

  box-sizing: border-box

  display: flex
  flex-wrap: wrap
  width: 740px
  padding: 30px
  margin: 100px auto 0
  background: white
  font-family: sans-serif
  font-size: 19px
  text-align: center

    border-radius: 10px
    user-select: none

  &.dragging *
    cursor: grabbing

  width: 100%
  font-weight: 300
  margin: 1em 0 0

  margin-right: 30px

  width: 240px
  line-height: 38px
  border-radius: 10px
  font-weight: bold
  font-size: 24px
  color: rgba(0,0,0,.2)
  cursor: grab

    margin: 0 0 10px

    background: $green

    background: $blue

  background: $dark-gray
  flex: 1
  padding: 15px

  position: relative
  background: white
  line-height: 50px
  font-weight: 300
  overflow: hidden

    margin: 0 0 10px

    content: ''
    position: absolute
    left: 0
    width: 20px
    height: 100%
    background: $green

    background: $blue

    left: 20px

      display: none

    box-shadow: 0 0 0 3px $dark-gray, 0 0 0 4px $green
      background: $green

    box-shadow: 0 0 0 3px $dark-gray, 0 0 0 4px $blue
      background: $blue

    opacity: .2
    cursor: no-drop

  z-index: 1
  pointer-events: none
  box-shadow: 0 2px 5px rgba(0,0,0,.8)


              {div, p} = React.DOM

DRAG_THRESHOLD = 3 # pixels

document.addEventListener 'DOMContentLoaded', ->
  React.renderComponent Example(), document.body

Example = React.createClass
  getInitialState: ->
    currentDragItem: null

  render: ->
      className: "dnd-example #{'dragging' if @state.currentDragItem}"
      children: [
          onDragStart: @onDragStart
          onDragStop: @onDragStop
          currentDragItem: @state.currentDragItem
          onDrop: @onDrop

  onDragStart: (details) ->
    @setState currentDragItem: details

  onDragStop: ->
    @setState currentDragItem: null

  onDrop: (target) ->
    @setState lastDrop:
      source: @state.currentDragItem
      target: target

  dropDescription: ->
    if drop = @state.lastDrop
        className: 'drop-description'
        children: "Dropped source #{drop.source.type}-#{drop.source.index} on target #{}"

SourceObjects = React.createClass
  render: ->
      className: 'dnd-source-objects'
      children: for object, i in @objects()
          type: object.type
          index: i + 1
          children: i + 1
          onDragStart: @props.onDragStart
          onDragStop: @props.onDragStop

  objects: ->
    _.flatten [
      { type: 'green' } for i in [0..2]
      { type: 'blue' } for i in [0..2]

SourceObject = React.createClass
  render: ->
      className: "dnd-source-object #{@props.type}"
      children: @props.children
      onDragStart: @props.onDragStart
      onDragStop: @props.onDragStop
      dragData: @dragData

  dragData: ->
    type: @props.type
    index: @props.index

Draggable = React.createClass
  getInitialState: ->
    mouseDown: false
    dragging: false

  render: ->
    @transferPropsTo div
      style: @style()
      className: "dnd-draggable #{'dragging' if @state.dragging}"
      children: @props.children
      onMouseDown: @onMouseDown

  style: ->
    if @state.dragging
      position: 'absolute'
      left: @state.left

  onMouseDown: (event) ->
    if event.button == LEFT_BUTTON
      pageOffset = @getDOMNode().getBoundingClientRect()
        mouseDown: true
        originX: event.pageX
        originY: event.pageY
        elementX: pageOffset.left

  onMouseMove: (event) ->
    deltaX = event.pageX - @state.originX
    deltaY = event.pageY - @state.originY
    distance = Math.abs(deltaX) + Math.abs(deltaY)

    if !@state.dragging and distance > DRAG_THRESHOLD
      @setState dragging: true
      @props.onDragStart? @props.dragData?()

    if @state.dragging
        left: @state.elementX + deltaX + document.body.scrollLeft
        top: @state.elementY + deltaY + document.body.scrollTop

  onMouseUp: ->
    if @state.dragging
      @setState dragging: false

  addEvents: ->
    document.addEventListener 'mousemove', @onMouseMove
    document.addEventListener 'mouseup', @onMouseUp

  removeEvents: ->
    document.removeEventListener 'mousemove', @onMouseMove
    document.removeEventListener 'mouseup', @onMouseUp

DropTargets = React.createClass
  render: ->
      className: 'dnd-drop-targets'
      children: for target, i in @targets()
          target: target
          index: i
          currentDragItem: @props.currentDragItem
          onDrop: @props.onDrop

  targets: ->
      { accepts: ['blue'] }
      { accepts: ['green'] }
      { accepts: ['blue', 'green'] }
      { accepts: [] }

DropTarget = React.createClass
  getInitialState: ->
    hover: false

  render: ->
      className: @classes()
      children: 'accepts ' + @acceptsDescription()
      onMouseEnter: => @setState hover: true
      onMouseLeave: => @setState hover: false
      onMouseUp: @onDrop

  classes: ->
      "#{ ' '}"
      'active' if @active()
      'active-green' if @active() and @props.currentDragItem.type == 'green'
      'active-blue' if @active() and @props.currentDragItem.type == 'blue'
      'disabled' if @disabled()
      'hover' if @state.hover
    ].join ' '

  active: ->
    item = @props.currentDragItem
    item and item.type in

  disabled: ->
    item = @props.currentDragItem 
    item and item.type not in

  acceptsDescription: ->
    if > 0 ' & '

  onDrop: ->
    if @active()
      @props.onDrop? index: @props.index + 1