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    
Size: Mime:
import React from 'react'
import { isFunction, isArray, isObj } from 'exotic'
import { CommonState } from '@skava/ui/dist/state'
import { StyledLinkButton, StyledButton } from './styled'
import { OrderItemProps, ButtonProps } from './typings'

const handleDynamicClick = (buttonClickProps: OrderItemProps) => {
  const { onActionButtonClick, item, buttonProps } = buttonClickProps
  if (isObj(buttonProps) && !buttonProps.navigationURL) {
    if (isFunction(onActionButtonClick)) {
      onActionButtonClick({ label: buttonProps.value, item })
    }
  }
}

function defaultRenderButton(
  props: OrderItemProps,
  index: number,
  state: CommonState
) {
  const handleClick = () => handleDynamicClick(props)
  const { buttonProps } = props
  const label = isObj(buttonProps) && buttonProps.label
  const color = isObj(buttonProps) && buttonProps.color
  const dataQa = isObj(buttonProps) && buttonProps['data-qa']
  return (
    <StyledButton
      key={index}
      text={label}
      onClick={
        label === 'return' || label === 'cancel'
          ? state.handleShow
          : handleClick
      }
      color={color}
      data-qa={dataQa}
    />
  )
}

function defaultRenderLinkButton(item: ButtonProps, index: number) {
  return (
    <StyledLinkButton
      href={item.navigationURL}
      color={item.color}
      data-qa={item['data-qa']}
      key={index}
    >
      {item.label}
    </StyledLinkButton>
  )
}

function defaultRenderActionButtons(props: OrderItemProps, state: CommonState) {
  const { renderLinkButton, renderButton, ...remainingProps } = props
  return (
    isArray(props.item.actionButtonList) &&
    props.item.actionButtonList.map((buttonProps, index) => {
      const buttonView = buttonProps.navigationURL
        ? isFunction(renderLinkButton) && renderLinkButton(buttonProps, index)
        : isFunction(renderButton) &&
          renderButton({ buttonProps, ...remainingProps }, index, state)
      return buttonView
    })
  )
}

export {
  defaultRenderLinkButton,
  defaultRenderButton,
  defaultRenderActionButtons,
}