Sha256: c3ec1b8576894200098618210f3871e7f7ce0f619c7e138bc244ba009e3706c4

Contents?: true

Size: 1.9 KB

Versions: 101

Compression:

Stored size: 1.9 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?: {[key:string]:string },
  className?: string,
  dark?: boolean,
  data?: object,
  date: Date,
  id?: string,
  variant?: "day_only" | "month_day" | "expanded",
  compact?: boolean,
}

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

const getFormattedDate = (value: Date | string, variant: "day_only" | "month_day" | "expanded") => {
  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

101 entries across 101 versions & 1 rubygems

Version Path
playbook_ui-12.24.0.pre.alpha.play824751 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.24.0.pre.alpha.railsmultilevelimprovements749 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.24.0.pre.alpha.play824745 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.24.0.pre.alpha.railsmultilevelimprovements742 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.24.0.pre.alpha.railsmultilevelimprovements741 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.24.0.pre.alpha.railsmultilevelimprovements739 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.24.0.pre.alpha.play824733 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.24.0.pre.alpha.play833boldoptionfortitle2and3721 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.24.0.pre.alpha.alphatestforselfhostfak720 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.24.0.pre.alpha.play833boldoptionfortitle2and3719 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.24.0.pre.alpha.play833boldoptionfortitle2and3717 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.24.0 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.23.0.pre.alpha.movemarkdown712 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.23.0.pre.alpha.movemarkdown708 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.23.0.pre.alpha.play698responsivespacingglobalprop703 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.23.0.pre.alpha.play698responsivespacingglobalprop701 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.23.0 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.22.0.pre.alpha.PLAY603datepickerquickpickinputpresetdropdown696 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.22.0.pre.alpha.play698responsivespacingglobalprop690 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
playbook_ui-12.22.0.pre.alpha.PBNTR12checkingemptyfilters686 app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx