Sha256: 83046603d8065a8efd0877b69126c03c89e7592312cee852bb6c573340537bdb

Contents?: true

Size: 1.79 KB

Versions: 60

Compression:

Stored size: 1.79 KB

Contents

/* @flow */

import React from 'react'
import DateTime from '../pb_kit/dateTime.js'
import { Icon } from '../'
import classnames from 'classnames'
import { globalProps } from '../utilities/globalProps.js'

const defaultDateString = (value: DateTime) => {
  const weekday = value.toWeekday().toUpperCase()
  const month = value.toMonth().toUpperCase()
  const day = value.toDay()

  return `${weekday} ยท ${month} ${day}`
}

const largeDateString = (value: DateTime) => {
  const month = value.toMonth().toUpperCase()
  const day = value.toDay()

  return `${month} ${day}`
}

type DateSubcomponent = {
  value: DateTime,
}

const ExtraSmallDate = ({ value, ...props }: DateSubcomponent) => (
  <h3 className={classnames('pb_title_kit_4', globalProps(props))}>
    {defaultDateString(value)}
  </h3>
)

const SmallDate = ({ value, ...props }: DateSubcomponent) => (
  <h3 className={classnames('pb_title_kit_4', globalProps(props))}>
    <Icon
        fixedWidth
        icon="calendar"
    />
    {defaultDateString(value)}
  </h3>
)

const LargeDate = ({ value, ...props }: DateSubcomponent) => (
  <h3 className={classnames('pb_title_kit_3', globalProps(props))}>
    {largeDateString(value)}
  </h3>
)

type PbDateProps = {
  size?: "xs" | "sm" | "lg",
  value?: string,
  className?: string
}

const PbDate = ({ size, value, className, ...props }: PbDateProps) => {
  const date = new DateTime({ value: value })

  if (size == 'xs')
    return (
      <ExtraSmallDate
          {...props}
          className={className}
          value={date}
      />
    )
  if (size == 'lg')
    return (
      <LargeDate
          {...props}
          className={className}
          value={date}
      />
    )
  return (
    <SmallDate
        {...props}
        className={className}
        value={date}
    />
  )
}

export default PbDate

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
playbook_ui-7.4.0.pre.alpha6 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.4.0.pre.alpha4 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.4.0.pre.alpha2 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.4.0.pre.alpha1 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.3.0.pre.alpha12 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.3.0.pre.alpha11 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.3.0.pre.alpha10 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.3.0.pre.alpha9 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.3.0.pre.alpha8 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.3.0.pre.alpha7 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.3.0.pre.alpha6 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.3.0.pre.alpha5 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.3.0.pre.alpha4 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.3.0.pre.alpha3 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.3.0.pre.alpha2 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.2.0 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.1.2 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.1.0.pre.alpha2 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.1.1.pre.alpha1 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.0.1 app/pb_kits/playbook/pb_date/_date.jsx