playbook_ui 13.34.0.pre.alpha.PLAY14143372 → 13.34.0.pre.alpha.PLAY14143373

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d7c06af6de4de1eca3eb2fc8730a1aef14bed8bcd201956301854e34cfbddd5
4
- data.tar.gz: a40334453ef2464508a473895cf2109743b2990e8e852ac842d19c43b1fb7a31
3
+ metadata.gz: 36b22bcec044ccc2dc38617892d16d11d3315798c45ba1c6eb4eb917859c4a11
4
+ data.tar.gz: 812f6f8cc2ec0fb4d270fee84a70fd9462dc7aea2ced21591f4592db402e0576
5
5
  SHA512:
6
- metadata.gz: 998396f1c63377bf30146be040990dc0125c407bfd185889091289092b59d7ba3fa813e3eca730d588268bb164ec2ef3fed0e30a8b321b3b208ebc402542f3a0
7
- data.tar.gz: 0ab76bd090f5b1873b76f7841c34dfadf48edfe3928e78e9f17f2db76fc21b71158f8f448edf47ed7e1fbb8ff13eb47c678311a857634c33fbe414539e9cb300
6
+ metadata.gz: b34badff8320ee92ed636ca67bd3744933624f58f20811be0e8cc4a575dbc7b9e07fd34a7108675deb87fd126341e5f12e450806e806d5b93dc545b7942b1b8c
7
+ data.tar.gz: b6e00cfb7a261f9c9539a9ef976100f22771f00a5a34d483320f24bf445213ae936b5edeb12478f545a0dbf5b841448daceb7fac06ab3107f4dfb1a794650469
@@ -0,0 +1,11 @@
1
+ [class^='pb_weekday_stacked'] {
2
+ &[class*='_left'] {
3
+ text-align: left;
4
+ }
5
+ &[class*='_center'] {
6
+ text-align: center;
7
+ }
8
+ &[class*='_right'] {
9
+ text-align: right;
10
+ }
11
+ }
@@ -0,0 +1,83 @@
1
+ import React from 'react'
2
+ import classnames from 'classnames'
3
+ import { globalProps } from '../utilities/globalProps'
4
+ import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
5
+
6
+ import Caption from '../pb_caption/_caption'
7
+ import Title from '../pb_title/_title'
8
+ import DateTime from '../pb_kit/dateTime';
9
+ import { GenericObject } from '../types'
10
+
11
+ type WeekdayStackedProps = {
12
+ align?: "left" | "center" | "right",
13
+ aria?: {[key:string]:string },
14
+ className?: string,
15
+ dark?: boolean,
16
+ data?: GenericObject,
17
+ date: Date,
18
+ htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
19
+ id?: string,
20
+ variant?: "day_only" | "month_day" | "expanded",
21
+ compact?: boolean,
22
+ }
23
+
24
+ const getDayOfWeek = (value: Date, compact: boolean) => {
25
+ if (compact) {
26
+ return DateTime.toDayAbbr(value)
27
+ } else {
28
+ return DateTime.toWeekday(value)
29
+ }
30
+ }
31
+
32
+ const getFormattedDate = (value: Date, variant: "day_only" | "month_day" | "expanded") => {
33
+ if (variant === 'day_only') {
34
+ return DateTime.toDay(value).toString()
35
+ } else {
36
+ const format = variant === 'expanded' ? 'expanded' : 'month_day'
37
+ return DateTime.toCustomFormat(value, format)
38
+ }
39
+ }
40
+
41
+ const WeekdayStacked = (props: WeekdayStackedProps) => {
42
+ const {
43
+ align = 'left',
44
+ aria = {},
45
+ className,
46
+ dark = false,
47
+ data = {},
48
+ date = new Date(),
49
+ htmlOptions = {},
50
+ id,
51
+ variant = 'month_day',
52
+ compact = false,
53
+ } = props
54
+
55
+ const ariaProps = buildAriaProps(aria)
56
+ const dataProps = buildDataProps(data)
57
+ const htmlProps = buildHtmlProps(htmlOptions)
58
+ const classes = classnames(
59
+ buildCss('pb_weekday_stacked_kit', align),
60
+ globalProps(props),
61
+ className
62
+ )
63
+
64
+ return (
65
+ <div
66
+ {...ariaProps}
67
+ {...dataProps}
68
+ {...htmlProps}
69
+ className={classes}
70
+ id={id}
71
+ >
72
+ <Caption dark={dark}>{getDayOfWeek(date, compact)}</Caption>
73
+ <Title
74
+ dark={dark}
75
+ size={4}
76
+ tag="span"
77
+ text={getFormattedDate(date, variant)}
78
+ />
79
+ </div>
80
+ )
81
+ }
82
+
83
+ export default WeekdayStacked
@@ -0,0 +1,3 @@
1
+ <%= pb_rails("weekday_stacked", props: {variant: "expanded", compact: true}) %>
2
+ <%= pb_rails("weekday_stacked", props: { variant: "day_only" , compact: true, align: "center"}) %>
3
+ <%= pb_rails("weekday_stacked", props: { variant: "month_day", compact: true, align: "right" }) %>
@@ -0,0 +1,27 @@
1
+ import React from 'react'
2
+
3
+ import WeekdayStacked from '../_weekday_stacked'
4
+
5
+ const WeekdayStackedCompact = (props) => (
6
+ <div>
7
+ <WeekdayStacked
8
+ compact
9
+ variant="day_only"
10
+ {...props}
11
+ />
12
+ <WeekdayStacked
13
+ align="center"
14
+ compact
15
+ variant="month_day"
16
+ {...props}
17
+ />
18
+ <WeekdayStacked
19
+ align="right"
20
+ compact
21
+ variant="expanded"
22
+ {...props}
23
+ />
24
+ </div>
25
+ )
26
+
27
+ export default WeekdayStackedCompact
@@ -0,0 +1,3 @@
1
+ <%= pb_rails("weekday_stacked") %>
2
+ <%= pb_rails("weekday_stacked", props: {align: 'center'}) %>
3
+ <%= pb_rails("weekday_stacked", props: {align: 'right'}) %>
@@ -0,0 +1,22 @@
1
+ import React from 'react'
2
+
3
+ import WeekdayStacked from '../_weekday_stacked'
4
+
5
+ const WeekdayStackedDefault = (props) => (
6
+ <div>
7
+ <WeekdayStacked
8
+ className="test"
9
+ {...props}
10
+ />
11
+ <WeekdayStacked
12
+ align="center"
13
+ {...props}
14
+ />
15
+ <WeekdayStacked
16
+ align="right"
17
+ {...props}
18
+ />
19
+ </div>
20
+ )
21
+
22
+ export default WeekdayStackedDefault
@@ -0,0 +1,3 @@
1
+ <%= pb_rails("weekday_stacked", props: {variant: "expanded", }) %>
2
+ <%= pb_rails("weekday_stacked", props: { variant: "day_only", align: "center" }) %>
3
+ <%= pb_rails("weekday_stacked", props: { variant: "month_day", align: "right" }) %>
@@ -0,0 +1,24 @@
1
+ import React from 'react'
2
+
3
+ import WeekdayStacked from '../_weekday_stacked'
4
+
5
+ const WeekdayStackedVariant = (props) => (
6
+ <div>
7
+ <WeekdayStacked
8
+ variant="day_only"
9
+ {...props}
10
+ />
11
+ <WeekdayStacked
12
+ align="center"
13
+ variant="month_day"
14
+ {...props}
15
+ />
16
+ <WeekdayStacked
17
+ align="right"
18
+ variant="expanded"
19
+ {...props}
20
+ />
21
+ </div>
22
+ )
23
+
24
+ export default WeekdayStackedVariant
@@ -0,0 +1,12 @@
1
+ examples:
2
+
3
+ rails:
4
+ - weekday_stacked_default: Default
5
+ - weekday_stacked_compact: Compact
6
+ - weekday_stacked_variant: Variant
7
+
8
+
9
+ react:
10
+ - weekday_stacked_default: Default
11
+ - weekday_stacked_compact: Compact
12
+ - weekday_stacked_variant: Variant
@@ -0,0 +1,3 @@
1
+ export { default as WeekdayStackedDefault } from './_weekday_stacked_default.jsx'
2
+ export { default as WeekdayStackedVariant } from './_weekday_stacked_variant.jsx'
3
+ export { default as WeekdayStackedCompact } from './_weekday_stacked_compact.jsx'
@@ -0,0 +1,4 @@
1
+ <%= pb_content_tag do %>
2
+ <%= pb_rails("caption", props: {dark: object.dark, text: object.day_of_week}) %>
3
+ <%= pb_rails("title", props: {dark: object.dark, size: 4, tag: "span", text: object.formatted_month_and_day}) %>
4
+ <% end %>
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Playbook
4
+ module PbWeekdayStacked
5
+ class WeekdayStacked < Playbook::KitBase
6
+ prop :align, type: Playbook::Props::Enum,
7
+ values: %w[left center right],
8
+ default: "left"
9
+
10
+ prop :date, type: Playbook::Props::Date,
11
+ default: ::Date.current
12
+
13
+ prop :compact, type: Playbook::Props::Boolean,
14
+ default: false
15
+
16
+ prop :variant, type: Playbook::Props::Enum,
17
+ values: %w[day_only expanded month_day],
18
+ default: "month_day"
19
+
20
+ def classname
21
+ generate_classname("pb_weekday_stacked_kit", align)
22
+ end
23
+
24
+ def day_of_week
25
+ day = Playbook::PbKit::PbDateTime.new(date)
26
+ formatted_day = compact ? day.to_day_of_week_compact : day.to_day_of_week
27
+ content_tag(:time, datetime: day.to_iso) do
28
+ formatted_day
29
+ end
30
+ end
31
+
32
+ def formatted_month_and_day
33
+ case variant
34
+ when "day_only" then day
35
+ when "expanded" then month_and_day(format: "%b %-d")
36
+ else month_and_day
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def month_and_day(format: "%-m/%-d")
43
+ month_and_day = Playbook::PbKit::PbDateTime.new(date)
44
+ content_tag(:time, datetime: month_and_day.to_iso) do
45
+ date.strftime(format)
46
+ end
47
+ end
48
+
49
+ def day
50
+ day = Playbook::PbKit::PbDateTime.new(date)
51
+ content_tag(:time, datetime: day.to_iso) do
52
+ day.to_unpadded_day
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,105 @@
1
+ import React from "react";
2
+ import { render, screen } from "../utilities/test-utils";
3
+
4
+ import WeekdayStacked from "./_weekday_stacked";
5
+
6
+ const TEST_DATE = "01/01/2020 00:00:000 GMT-0500";
7
+ jest.setSystemTime(new Date(TEST_DATE));
8
+ const testId = "weekdaystacked-kit";
9
+ const realDate = Date;
10
+
11
+ beforeEach(() => {
12
+ global.Date.now = jest.fn(() => new Date(TEST_DATE));
13
+ });
14
+
15
+ afterEach(() => {
16
+ global.Date = realDate;
17
+ });
18
+
19
+ describe("WeekdayStacked Kit", () => {
20
+ test("renders className", () => {
21
+ render(
22
+ <WeekdayStacked
23
+ data={{ testid: testId }}
24
+ />
25
+ );
26
+
27
+ const kit = screen.getByTestId(testId);
28
+ expect(kit).toHaveClass("pb_weekday_stacked_kit_left");
29
+ });
30
+
31
+ test("renders Caption with weekday", () => {
32
+ render(
33
+ <WeekdayStacked
34
+ data={{ testid: testId }}
35
+ />
36
+ );
37
+
38
+ const kit = screen.getByTestId(testId);
39
+ const text = kit.querySelector(".pb_caption_kit_md");
40
+ expect(text.textContent).toEqual("Wed")
41
+ });
42
+
43
+ test("renders Title with date", () => {
44
+ render(
45
+ <WeekdayStacked
46
+ data={{ testid: testId }}
47
+ />
48
+ );
49
+
50
+ const kit = screen.getByTestId(testId);
51
+ const text = kit.querySelector(".pb_title_kit_size_4");
52
+ expect(text.textContent).toEqual("1/1")
53
+ });
54
+
55
+ test("renders compact prop", () => {
56
+ render(
57
+ <WeekdayStacked
58
+ compact
59
+ data={{ testid: testId }}
60
+ />
61
+ );
62
+
63
+ const kit = screen.getByTestId(testId);
64
+ const text = kit.querySelector(".pb_caption_kit_md");
65
+ expect(text.textContent).toEqual("W")
66
+ });
67
+
68
+ test("renders align prop", () => {
69
+ render(
70
+ <WeekdayStacked
71
+ align="left"
72
+ data={{ testid: testId }}
73
+ />
74
+ );
75
+
76
+ const kit = screen.getByTestId(testId);
77
+ expect(kit).toHaveClass("pb_weekday_stacked_kit_left")
78
+ });
79
+
80
+ test("renders day_only variant prop", () => {
81
+ render(
82
+ <WeekdayStacked
83
+ data={{ testid: testId }}
84
+ variant="day_only"
85
+ />
86
+ );
87
+
88
+ const kit = screen.getByTestId(testId);
89
+ const text = kit.querySelector(".pb_title_kit_size_4");
90
+ expect(text.textContent).toEqual("1")
91
+ });
92
+
93
+ test("renders expanded variant prop", () => {
94
+ render(
95
+ <WeekdayStacked
96
+ data={{ testid: testId }}
97
+ variant="expanded"
98
+ />
99
+ );
100
+
101
+ const kit = screen.getByTestId(testId);
102
+ const text = kit.querySelector(".pb_title_kit_size_4");
103
+ expect(text.textContent).toEqual("Jan 1")
104
+ });
105
+ });
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Playbook
4
4
  PREVIOUS_VERSION = "13.34.0"
5
- VERSION = "13.34.0.pre.alpha.PLAY14143372"
5
+ VERSION = "13.34.0.pre.alpha.PLAY14143373"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playbook_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.34.0.pre.alpha.PLAY14143372
4
+ version: 13.34.0.pre.alpha.PLAY14143373
5
5
  platform: ruby
6
6
  authors:
7
7
  - Power UX
@@ -2899,6 +2899,19 @@ files:
2899
2899
  - app/pb_kits/playbook/pb_walkthrough/docs/example.yml
2900
2900
  - app/pb_kits/playbook/pb_walkthrough/docs/index.js
2901
2901
  - app/pb_kits/playbook/pb_walkthrough/walkthrough.test.jsx
2902
+ - app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.scss
2903
+ - app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx
2904
+ - app/pb_kits/playbook/pb_weekday_stacked/docs/_weekday_stacked_compact.html.erb
2905
+ - app/pb_kits/playbook/pb_weekday_stacked/docs/_weekday_stacked_compact.jsx
2906
+ - app/pb_kits/playbook/pb_weekday_stacked/docs/_weekday_stacked_default.html.erb
2907
+ - app/pb_kits/playbook/pb_weekday_stacked/docs/_weekday_stacked_default.jsx
2908
+ - app/pb_kits/playbook/pb_weekday_stacked/docs/_weekday_stacked_variant.html.erb
2909
+ - app/pb_kits/playbook/pb_weekday_stacked/docs/_weekday_stacked_variant.jsx
2910
+ - app/pb_kits/playbook/pb_weekday_stacked/docs/example.yml
2911
+ - app/pb_kits/playbook/pb_weekday_stacked/docs/index.js
2912
+ - app/pb_kits/playbook/pb_weekday_stacked/weekday_stacked.html.erb
2913
+ - app/pb_kits/playbook/pb_weekday_stacked/weekday_stacked.rb
2914
+ - app/pb_kits/playbook/pb_weekday_stacked/weekday_stacked.test.jsx
2902
2915
  - app/pb_kits/playbook/tokens/_animation-curves.scss
2903
2916
  - app/pb_kits/playbook/tokens/_border_radius.scss
2904
2917
  - app/pb_kits/playbook/tokens/_colors.scss