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 { isFunction } from 'exotic'
import { formatPhoneNumber } from '@skava/modules/___dist/utils/formatPhoneNumber'
import { TelephoneProps as Props, TelephoneAttributes as Attributes } from './typings'
import { renderIcon, renderValue } from './renderProps'
import { classes } from './fixture'

// alias
export function toTelephoneNumber(props: Props): string | Number {
  return props.phoneNo || props.phoneno || props.telephone || props.value || props.number
}

export function toAttributes(props: Props): Attributes {
  const { shouldFormat, shouldUseIcon } = props
  const telephoneNumber = toTelephoneNumber(props)

  const attributes = {
    className: classes.telephoneNumberButton,
    isLink: true,
    to: `tel:${telephoneNumber}`,
    shouldUseIcon: shouldUseIcon
  }

  const telephone = shouldFormat ? formatPhoneNumber(telephoneNumber) : telephoneNumber
  const render = toRender(props)

  return {
    renderIcon: props.renderIcon || renderIcon,
    render,
    shouldUseIcon,
    attributes,
    telephone,
  }
}

/**
 * @todo generic toRender functon...
 */
export function toRender(props: Props) {
  return isFunction(props.children)
    ? props.children
    : props.render || props.renderValue || renderValue
}