Sha256: b1bafd633b00fb2532cf522a9ac92cd6cde74f36c230b8904e0cb4be35ae4585

Contents?: true

Size: 1.98 KB

Versions: 10

Compression:

Stored size: 1.98 KB

Contents

/* @flow */

import React from 'react'
import DateTime from '../pb_kit/dateTime.js'
import { Body, Icon, Title } from '../'
import classnames from 'classnames'
import { globalProps } from '../utilities/globalProps.js'
import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'

type PbDateProps = {
  aria: Object,
  date: string | date,
  className?: string,
  data?: Object,
  id?: string,
  showIcon?: boolean,
  showDayOfWeek?: boolean,
  alignment?: "left" | "center" | "right"
}

const PbDate = (props: PbDateProps) => {
  const {
    aria = {},
    alignment = 'left',
    className,
    date,
    data = {},
    id,
    showDayOfWeek = false,
    showIcon = false,
  } = props

  const dateTimestamp = new DateTime({ value: date })
  const weekday = dateTimestamp.toWeekday()
  const month = dateTimestamp.toMonth()
  const day = dateTimestamp.toDay()
  const year = dateTimestamp.toYear()
  const currentYear = new Date().getFullYear().toString()

  const ariaProps = buildAriaProps(aria)
  const dataProps = buildDataProps(data)

  const classes = classnames(
    className,
    buildCss('pb_date_kit', alignment),
    globalProps(props)
  )
  return (
    <div
        {...ariaProps}
        {...dataProps}
        className={classes}
        id={id}
    >
      <Title
          size={4}
          tag="h4"
      >
        <If condition={showIcon}>
          <Body
              color="light"
              tag="span"
          >
            <Icon
                fixedWidth
                icon="calendar-alt"
            />
          </Body>
        </If>
        <If condition={showDayOfWeek}>
          {weekday}
          <Body
              color="light"
              tag="span"
              text=" • "
          />
        </If>
        <span>
          {month}
          {' '}
          {day}
        </span>
        <If condition={currentYear != year}>
          <span>
            {` , ${year}`}
          </span>
        </If>
      </Title>
    </div>
  )
}

export default PbDate

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
playbook_ui-7.0.0.pre.alpha9 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.0.0.pre.alpha8 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.0.0.pre.alpha7 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-6.4.1 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.0.0.pre.alpha6 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.0.0.pre.alpha5 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-6.4.0 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.0.0.pre.alpha4 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.0.0.pre.alpha3 app/pb_kits/playbook/pb_date/_date.jsx
playbook_ui-7.0.0.pre.alpha2 app/pb_kits/playbook/pb_date/_date.jsx