Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
ui-component-library / src / playground / Button / BaseButtonAtom.tsx
Size: Mime:
import React from 'react'
import toClassName from 'classnames'
import { observer } from 'xmobx/mobx-react'
import { styled } from 'uxui-modules/view-container'
import { toIdentifier } from 'uxui-modules/identifier'
import { DotLoader } from 'features/Animations'
import { makeCommonState } from '../../../state'
import { toAttributes } from './deps'
import {
  renderSnackbar as defaultRenderSnackbar,
  renderIconAndText as defaultRenderIconAndText,
  renderButtonOrLink as defaultRenderButtonOrLink,
} from './renderProps'
import BaseButtonAtomStateful from './BaseButtonAtomStateful'
import { baseButtonPropTypes } from './typings'

@observer
class Button extends BaseButtonAtomStateful {
  state = makeCommonState(this.props)
  static propTypes = baseButtonPropTypes
  static defaultProps = {
    // element: 'button',
    className: 'button-atom',
    defaultClassName: '',
    timeout: 60,
    shouldAnimate: false,
    isActive: false,
    renderSnackbar: defaultRenderSnackbar,
    renderIconAndText: defaultRenderIconAndText,
    renderButtonOrLink: defaultRenderButtonOrLink,
  }

  get eventHandlers() {
    return {
      onFocus: this.state.handleFocus,
      onBlur: this.state.handleBlur,
      onKeyDown: this.handleKeyDown,
      onClick: this.handleClick,
    }
  }

  render() {
    const attributes = toAttributes(this.props, this.state)
    const eventHandlers = this.eventHandlers

    // @tdo
    // need to pass textview to render
    const textView = this.props.renderIconAndText(attributes, this.state)
    const view = this.props.renderButtonOrLink(attributes, this.state)

    if (attributes.hasSnackbar) {
      return this.props.renderSnackbar(attributes, this.state, view)
    } else {
      return view
    }
  }
}

export default Button
export { Button }