Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NUX-638] - Date Kit Refactor/Design #1108

Merged
merged 16 commits into from Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 64 additions & 8 deletions app/pb_kits/playbook/pb_date/_date.html.erb
@@ -1,14 +1,70 @@
<%= 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 }) %>
class: object.classname,
aria: object.aria) do %>

<% if object.size == "md" %>
coleerikson marked this conversation as resolved.
Show resolved Hide resolved
<!-- 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 %>

<!-- 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: { text: object.xs_date, size: 4 }) %>
<%= pb_rails("title", props: { tag: "div", text: "#{object.month} #{object.day}, #{object.year}", size: 4 }) %>
<% end %>

<% else %>

<!-- 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("caption", props: { tag: "div", text: object.day_of_week }) %>
<%= pb_rails("caption", props: {
text: "•",
color: "light",
tag: "div",
}) %>
<% end %>

<!-- month day, year -->

<%# if not current year %>
<% if object.year.to_s == DateTime.now.year.to_s %>
<%= pb_rails("caption", props: { tag: "span", text: "#{object.month} #{object.day}" }) %>
<%# if is current year %>
<% else %>
<%= pb_rails("caption", props: { tag: "span", text: "#{object.month} #{object.day}, #{object.year}" }) %>
<% end %>
<% end %>
<% end %>

181 changes: 115 additions & 66 deletions app/pb_kits/playbook/pb_date/_date.jsx
Expand Up @@ -2,82 +2,131 @@

import React from 'react'
import DateTime from '../pb_kit/dateTime.js'
import { Icon } from '../'
import { Body, Caption, 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,
size?: string,
value: string | date,
}

const ExtraSmallDate = ({ value, ...props }: DateSubcomponent) => (
<h3 className={classnames('pb_title_kit_4', globalProps(props))}>
{defaultDateString(value)}
</h3>
)

const SmallDate = ({ value, ...props }: DateSubcomponent) => (
<h3 className={classnames('pb_title_kit_4', globalProps(props))}>
<Icon
fixedWidth
icon="calendar"
/>
{defaultDateString(value)}
</h3>
)
const PbDate = (props: PbDateProps) => {
const {
aria = {},
alignment = 'left',
className,
data = {},
id,
showDayOfWeek = false,
showIcon = false,
size = 'md',
value,
} = props

const LargeDate = ({ value, ...props }: DateSubcomponent) => (
<h3 className={classnames('pb_title_kit_3', globalProps(props))}>
{largeDateString(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()

type PbDateProps = {
size?: "xs" | "sm" | "lg",
value?: string,
className?: string
}
const ariaProps = buildAriaProps(aria)
const dataProps = buildDataProps(data)

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}
>
<If condition={size == 'md' || size == 'lg'}>

<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>
<Else />
<>
<If condition={showIcon}>
<Body
className="pb_icon_kit_container"
color="light"
tag="span"
>
<Icon
fixedWidth
icon="calendar-alt"
/>
</Body>
</If>
<If condition={showDayOfWeek}>
<Caption tag="div">
{weekday}
</Caption>
<Caption
color="light"
tag="div"
text=" • "
/>
</If>
<Caption tag="span">
{month}
{' '}
{day}
<If condition={currentYear != year}>
{`, ${year}`}
</If>
</Caption>
</>
</If>
</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;
}
}
}
30 changes: 21 additions & 9 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"
values: %w[lg md sm xs],
default: "md"
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"
}) %>