Sha256: 6416e2c500fd5d4177b7e58c113ed9386c521455d75969cb1788b31cf685d25e

Contents?: true

Size: 1.82 KB

Versions: 145

Compression:

Stored size: 1.82 KB

Contents

/* @flow */

import React from 'react'
import classnames from 'classnames'
import { globalProps } from '../utilities/globalProps'
import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'

import Caption from '../pb_caption/_caption'
import Title from '../pb_title/_title'

import DateTime from '../pb_kit/dateTime'

type WeekdayStackedProps = {
  align?: "left" | "center" | "right",
  aria?: object,
  className?: string,
  dark?: boolean,
  data?: object,
  date: date,
  id?: string,
  variant?: "day_only" | "month_day" | "expanded",
  compact?: boolean,
  id?: string,
}

const getDayOfWeek = (value, compact) => {
  const dateTime = new DateTime({ value })
  if (compact) {
    return dateTime.toDayAbbr()
  } else {
    return dateTime.toWeekday()
  }
}

const getFormattedDate = (value, variant) => {
  const dateTime = new DateTime({ value })
  if (variant === 'day_only') {
    return dateTime.toDay()
  } else {
    const format = variant === 'expanded' ? '%b %-d' : '%-m/%-d'
    return dateTime.toCustomFormat(format)
  }
}

const WeekdayStacked = (props: WeekdayStackedProps) => {
  const {
    align = 'left',
    aria = {},
    className,
    dark = false,
    data = {},
    date = new Date(),
    id,
    variant = 'month_day',
    compact = false,
  } = props

  const ariaProps = buildAriaProps(aria)
  const dataProps = buildDataProps(data)
  const classes = classnames(
    buildCss('pb_weekday_stacked_kit', align),
    globalProps(props),
    className
  )

  return (
    <div
        {...ariaProps}
        {...dataProps}
        className={classes}
        id={id}
    >
      <Caption dark={dark}>{getDayOfWeek(date, compact)}</Caption>
      <Title
          dark={dark}
          size={4}
          tag="span"
          text={getFormattedDate(date, variant)}
      />
    </div>
  )
}

export default WeekdayStacked

Version data entries

145 entries across 145 versions & 1 rubygems

Version Path
playbook_ui-11.6.0.pre.alpha.momenttz1 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.5.0 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.4.0.pre.alpha.rubytheme2 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.4.0.pre.alpha.rubytheme1 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.4.0 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx