Skip to content

Commit

Permalink
Refactor and redesign Date Kit
Browse files Browse the repository at this point in the history
  • Loading branch information
Cole Erikson committed Sep 17, 2020
1 parent cd2b4a6 commit 6d0b32e
Show file tree
Hide file tree
Showing 15 changed files with 404 additions and 132 deletions.
41 changes: 32 additions & 9 deletions app/pb_kits/playbook/pb_date/_date.html.erb
@@ -1,14 +1,37 @@
<%= content_tag(:div,
id: object.id,
data: object.data,
class: object.classname) do %>
<% if object.size == "lg" %>
<%= pb_rails("title", props: { text: object.lg_date, size: 3 }) %>
<% elsif object.size == "sm" %>
<%= pb_rails("icon", props: { icon: "calendar", fixed_width: true }) %>
<%= pb_rails("title", props: { tag: "span", text: object.sm_date, size: 4 }) %>
<% else %>
<%= pb_rails("title", props: { text: object.xs_date, size: 4 }) %>
class: object.classname,
aria: object.aria) do %>

<!-- icon -->
<% if object.show_icon %>
<%= pb_rails("body", props: {
color: "light",
tag: "div",
}) do %>
<%= pb_rails("icon", props: { icon: "calendar-alt", fixed_width: true }) %>
<% end %>
<% end %>

<!-- day_of_week -->
<% if object.show_day_of_week %>
<%= pb_rails("title", props: { tag: "div", text: object.day_of_week, size: 4 }) %>
<%= pb_rails("body", props: {
text: "•",
color: "light",
tag: "div",
}) %>
<% end %>
<% end %>

<!-- month day, year -->

<%# if not current year %>
<% if object.year.to_s == DateTime.now.year.to_s %>
<%= pb_rails("title", props: { tag: "div", text: "#{object.month} #{object.day}", size: 4 }) %>
<%# if is current year %>
<% else %>
<%= pb_rails("title", props: { tag: "div", text: "#{object.month} #{object.day}, #{object.year}", size: 4 }) %>
<% end %>
<% end %>
143 changes: 77 additions & 66 deletions app/pb_kits/playbook/pb_date/_date.jsx
Expand Up @@ -2,82 +2,93 @@

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

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,
type PbDateProps = {
alignment?: "left" | "center" | "right",
aria: Object,
className?: string,
data?: Object,
id?: string,
showDayOfWeek?: boolean,
showIcon?: boolean,
value: string | date,
}

const ExtraSmallDate = ({ value, ...props }: DateSubcomponent) => (
<h3 className={classnames('pb_title_kit_4', globalProps(props))}>
{defaultDateString(value)}
</h3>
)
const PbDate = (props: PbDateProps) => {
const {
aria = {},
alignment = 'left',
className,
data = {},
id,
showDayOfWeek = false,
showIcon = false,
value,
} = props

const SmallDate = ({ value, ...props }: DateSubcomponent) => (
<h3 className={classnames('pb_title_kit_4', globalProps(props))}>
<Icon
fixedWidth
icon="calendar"
/>
{defaultDateString(value)}
</h3>
)
const dateTimestamp = new DateTime({ value: value })
const weekday = dateTimestamp.toWeekday()
const month = dateTimestamp.toMonth()
const day = dateTimestamp.toDay()
const year = dateTimestamp.toYear()
const currentYear = new Date().getFullYear().toString()

const LargeDate = ({ value, ...props }: DateSubcomponent) => (
<h3 className={classnames('pb_title_kit_3', globalProps(props))}>
{largeDateString(value)}
</h3>
)
const ariaProps = buildAriaProps(aria)
const dataProps = buildDataProps(data)

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

const PbDate = ({ size, value, className, ...props }: PbDateProps) => {
const date = new DateTime({ value: value })
const classes = classnames(
buildCss('pb_date_kit', alignment),
globalProps(props),
className
)

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}
/>
<div
{...ariaProps}
{...dataProps}
className={classes}
id={id}
>
<Title
size={4}
tag="h4"
>
<If condition={showIcon}>
<Body
className="pb_icon_kit_container"
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>
)
}

Expand Down
30 changes: 30 additions & 0 deletions app/pb_kits/playbook/pb_date/_date.scss
@@ -1,2 +1,32 @@
@import "../pb_icon/icon";
@import "../pb_title/title";

[class^=pb_date_kit] {
display: flex;
flex-direction: row;
align-items: center;
> div, .pb_icon_kit_container {
margin-right: 4px !important;
}

&[class*=_center] {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
margin-right: 4px !important;
}

&[class*=_right] {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-end;
margin-left: 4px !important;
}
&.dark {
[class^=pb_title_kit] {
color: $text_dk_default !important;
}
}
}
26 changes: 19 additions & 7 deletions app/pb_kits/playbook/pb_date/date.rb
Expand Up @@ -10,25 +10,37 @@ class Date
partial "pb_date/date"

prop :date, required: true
prop :alignment, type: Playbook::Props::Enum,
values: %w[left center right],
default: "left"
prop :show_icon, type: Playbook::Props::Boolean,
default: false
prop :show_day_of_week, type: Playbook::Props::Boolean,
default: false
# Size to be deprecated.
prop :size, type: Playbook::Props::Enum,
values: %w[lg sm xs],
default: "sm"
prop :timezone, default: "America/New_York"

def classname
generate_classname("pb_date_kit")
generate_classname("pb_date_kit", alignment)
end

def xs_date
"#{pb_date_time.to_day_of_week.upcase} &middot; #{pb_date_time.to_month.upcase} #{pb_date_time.to_day}".html_safe
def day_of_week
pb_date_time.to_day_of_week
end

def lg_date
"#{pb_date_time.to_month.upcase} #{pb_date_time.to_day}"
def day
pb_date_time.to_day
end

def sm_date
"#{pb_date_time.to_day_of_week.upcase} &middot; #{pb_date_time.to_month.upcase} #{pb_date_time.to_day}".html_safe
def month
pb_date_time.to_month.capitalize
end

def year
pb_date_time.to_year
end

private
Expand Down
24 changes: 24 additions & 0 deletions app/pb_kits/playbook/pb_date/docs/_date_alignment.html.erb
@@ -0,0 +1,24 @@
<%= pb_rails("date", props: {
date: DateTime.now,
show_icon: true,
show_day_of_week: true
}) %>

<br><br>

<%= pb_rails("date", props: {
date: DateTime.now,
show_icon: true,
show_day_of_week: true,
alignment: "center"
}) %>

<br><br>

<%= pb_rails("date", props: {
date: DateTime.now,
show_icon: true,
show_day_of_week: true,
alignment: "right"
}) %>

32 changes: 32 additions & 0 deletions app/pb_kits/playbook/pb_date/docs/_date_alignment.jsx
@@ -0,0 +1,32 @@
import React from 'react'
import { Date as FormattedDate } from '../..'

const DateAlignment = () => {
return (
<div>
<FormattedDate
dayOfWeek
icon
value="1995-12-25"
/>

<br />

<FormattedDate
alignment="center"
dayOfWeek
icon
value="2020-12-25"
/>

<br />

<FormattedDate
alignment="right"
value={new Date()}
/>
</div>
)
}

export default DateAlignment
22 changes: 22 additions & 0 deletions app/pb_kits/playbook/pb_date/docs/_date_dark.html.erb
@@ -0,0 +1,22 @@
<%= pb_rails("date", props: {
dark: true,
date: Date.today,
show_icon: true,
}) %>

<br>

<%= pb_rails("date", props: {
dark: true,
date: "2012-08-02T15:49:29Z",
show_icon: true,
}) %>

<br>

<%= pb_rails("date", props: {
dark: true,
date: "2017-12-02T15:49:29Z",
show_day_of_week: true,
show_icon: true,
}) %>

0 comments on commit 6d0b32e

Please sign in to comment.