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 11 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
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
playbook_ui (7.1.0)
playbook_ui (7.1.1)
actionpack (>= 5.1.6, < 6.0)
actionview (>= 5.1.6, < 7.0)
activesupport (>= 5.1.6, < 7.0)
Expand Down
2 changes: 1 addition & 1 deletion app/pb_kits/playbook/pb_body/body.rb
Expand Up @@ -5,7 +5,7 @@ module PbBody
class Body
include Playbook::Props
include ActionView::Helpers

partial "pb_body/body"

prop :color, type: Playbook::Props::Enum,
Expand Down
12 changes: 7 additions & 5 deletions app/pb_kits/playbook/pb_caption/_caption.html.erb
@@ -1,5 +1,7 @@
<%= content_tag(object.tag, object.text,
id: object.id,
data: object.data,
class: object.classname,
aria: object.aria) %>
<%= content_tag(object.tag,
aria: object.aria,
id: object.id,
data: object.data,
class: object.classname) do %>
<%= object.children.present? ? capture(&object.children) : object.text %>
<% end %>
11 changes: 11 additions & 0 deletions app/pb_kits/playbook/pb_caption/docs/_caption_block.html.erb
@@ -0,0 +1,11 @@
<%= pb_rails("caption") do %>
Block
<% end %>

<%= pb_rails("caption", props: { size: 'lg' }) do %>
Large Block
<% end %>

<%= pb_rails("caption", props: { size: 'xs' }) do %>
Subcaption Block
<% end %>
28 changes: 28 additions & 0 deletions app/pb_kits/playbook/pb_caption/docs/_caption_block.jsx
@@ -0,0 +1,28 @@
import React from 'react'
import { Caption } from '../../'

const CaptionBlock = (props) => {
return (
<div>
<Caption {...props}>
{'Block'}
</Caption>

<Caption
{...props}
size="lg"
>
{'Large Block'}
</Caption>

<Caption
{...props}
size="xs"
>
{'Subcaption Block'}
</Caption>
</div>
)
}

export default CaptionBlock
2 changes: 2 additions & 0 deletions app/pb_kits/playbook/pb_caption/docs/example.yml
@@ -1,5 +1,7 @@
examples:
rails:
- caption_light: Default
- caption_block: Block
react:
- caption_light: Default
- caption_block: Block
1 change: 1 addition & 0 deletions app/pb_kits/playbook/pb_caption/docs/index.js
@@ -1,2 +1,3 @@
export { default as CaptionLight } from './_caption_light.jsx'
export { default as CaptionVariants } from './_caption_variants.jsx'
export { default as CaptionBlock } from './_caption_block.jsx'
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;
}
}
}