<commit_before>{div, i, span, ul, li} = React.DOM

DropdownItem = React.createFactory React.createClass

  displayName: 'DropdownItem'

  clicked: ->
    @props.select @props.item

  render: ->
    className = "menuItem #{if @props.isActionMenu and not @props.item.action then 'disabled' else ''}"
    (li {key: @props.name, className: className, onClick: @clicked }, @props.name)

module.exports = DropDown = React.createClass

  displayName: 'Dropdown'

  getDefaultProps: ->
    isActionMenu: true              # Whether each item contains its own action
    onSelect: (item) ->             # If not, @props.onSelect is called
      log.info "Selected #{item}"

  getInitialState: ->
    showingMenu: false
    timeout: null

  blur: ->
    @unblur()
    timeout = setTimeout ( => @setState {showingMenu: false} ), 500
    @setState {timeout: timeout}

  unblur: ->
    if @state.timeout
      clearTimeout(@state.timeout)
    @setState {timeout: null}

  select: (item) ->
    nextState = (not @state.showingMenu)
    @setState {showingMenu: nextState}
    return unless item
    if @props.isActionMenu and item.action
      item.action()
    else
      @props.onSelect item

  render: ->
    menuClass = if @state.showingMenu then 'menu-showing' else 'menu-hidden'
    select = (item) =>
      ( => @select(item))
    (div {className: 'menu'},
      (span {className: 'menu-anchor', onClick: => @select(null)},
        @props.anchor
        (i {className: 'ivy-icon-arrow-expand'})
      )
      (div {className: menuClass, onMouseLeave: @blur, onMouseEnter: @unblur},
        (ul {},
          (DropdownItem {name: item.name or item, item: item, select: @select, isActionMenu: @props.isActionMenu}) for item in @props.items
        )
      )
    )


DemoDropDown = React.createFactory DropDown
Demo = React.createClass
  getInitialState: ->
    nonActionMenuSelection: "Selection menu"
  onNonActionMenuSelect: (item) -><commit_msg>Fix Dropdown's item keys<commit_after>{div, i, span, ul, li} = React.DOM

DropdownItem = React.createFactory React.createClass

  displayName: 'DropdownItem'

  clicked: ->
    @props.select @props.item

  render: ->
    className = "menuItem #{if @props.isActionMenu and not @props.item.action then 'disabled' else ''}"
    name = @props.item.name or @props.item
    (li {className: className, onClick: @clicked }, name)

module.exports = DropDown = React.createClass

  displayName: 'Dropdown'

  getDefaultProps: ->
    isActionMenu: true              # Whether each item contains its own action
    onSelect: (item) ->             # If not, @props.onSelect is called
      log.info "Selected #{item}"

  getInitialState: ->
    showingMenu: false
    timeout: null

  blur: ->
    @unblur()
    timeout = setTimeout ( => @setState {showingMenu: false} ), 500
    @setState {timeout: timeout}

  unblur: ->
    if @state.timeout
      clearTimeout(@state.timeout)
    @setState {timeout: null}

  select: (item) ->
    nextState = (not @state.showingMenu)
    @setState {showingMenu: nextState}
    return unless item
    if @props.isActionMenu and item.action
      item.action()
    else
      @props.onSelect item

  render: ->
    menuClass = if @state.showingMenu then 'menu-showing' else 'menu-hidden'
    select = (item) =>
      ( => @select(item))
    (div {className: 'menu'},
      (span {className: 'menu-anchor', onClick: => @select(null)},
        @props.anchor
        (i {className: 'ivy-icon-arrow-expand'})
      )
      (div {className: menuClass, onMouseLeave: @blur, onMouseEnter: @unblur},
        (ul {},
          (DropdownItem {key: item.name or item, item: item, select: @select, isActionMenu: @props.isActionMenu}) for item in @props.items
        )
      )
    )


DemoDropDown = React.createFactory DropDown
Demo = React.createClass
  getInitialState: ->
    nonActionMenuSelection: "Selection menu"
  onNonActionMenuSelect: (item) ->
{'fraction_non_alphanumeric': 0.12986680327868852, 'fraction_numerical': 0.0015368852459016393, 'mean_word_length': 2.9684959349593494, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2214502', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1202, 'n_words': 319}