Sha256: abcecc393137a90473d668d06099e6250bedbbfe18b84d96f30525af4ca3bf63

Contents?: true

Size: 1.83 KB

Versions: 44

Compression:

Stored size: 1.83 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.js'

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

44 entries across 44 versions & 1 rubygems

Version Path
playbook_ui-11.3.0.pre.alpha2 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.3.0.pre.alpha1 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.3.0 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.2.7 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.2.6 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.2.5 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.2.4 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.2.4.pre.alpha1 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.2.3 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.2.2 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.2.1 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.2.0 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.1.2 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.1.2.pre.alpha1 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.1.1 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.1.1.pre.alpha1 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.1.0 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.0.1 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.0.0 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx
playbook_ui-11.0.0.pre.alpha.2 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx