playbook_ui 2.9.5 → 2.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/pb_avatar/_avatar.html.erb +5 -5
  3. data/app/pb_kits/playbook/pb_avatar/avatar.rb +14 -63
  4. data/app/pb_kits/playbook/pb_bar_graph/_bar_graph.html.erb +1 -9
  5. data/app/pb_kits/playbook/pb_bar_graph/bar_graph.rb +13 -5
  6. data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_default.html.erb +1 -1
  7. data/app/pb_kits/playbook/pb_dashboard_value/docs/_dashboard_value_align.html.erb +3 -3
  8. data/app/pb_kits/playbook/pb_dashboard_value/docs/_dashboard_value_default.html.erb +3 -3
  9. data/app/pb_kits/playbook/pb_icon/_icon.html.erb +5 -7
  10. data/app/pb_kits/playbook/pb_icon/icon.rb +69 -120
  11. data/app/pb_kits/playbook/pb_label_pill/_label_pill.html.erb +3 -3
  12. data/app/pb_kits/playbook/pb_label_pill/label_pill.rb +10 -48
  13. data/app/pb_kits/playbook/pb_label_value/_label_value.html.erb +3 -3
  14. data/app/pb_kits/playbook/pb_label_value/label_value.rb +7 -45
  15. data/app/pb_kits/playbook/pb_line_graph/_line_graph.html.erb +2 -10
  16. data/app/pb_kits/playbook/pb_line_graph/docs/_line_graph_default.html.erb +1 -1
  17. data/app/pb_kits/playbook/pb_line_graph/line_graph.rb +24 -69
  18. data/app/pb_kits/playbook/pb_stat_value/_stat_value.html.erb +10 -4
  19. data/app/pb_kits/playbook/pb_stat_value/docs/_stat_value_unit.html.erb +1 -1
  20. data/app/pb_kits/playbook/pb_stat_value/stat_value.rb +7 -51
  21. data/app/pb_kits/playbook/pb_title_count/_title_count.html.erb +6 -3
  22. data/app/pb_kits/playbook/pb_title_count/docs/_title_count_default.html.erb +1 -1
  23. data/app/pb_kits/playbook/pb_title_count/title_count.rb +15 -75
  24. data/app/pb_kits/playbook/pb_title_detail/_title_detail.html.erb +3 -3
  25. data/app/pb_kits/playbook/pb_title_detail/title_detail.rb +10 -59
  26. data/app/pb_kits/playbook/props.rb +2 -1
  27. data/app/pb_kits/playbook/props/numeric.rb +13 -0
  28. data/app/pb_kits/playbook/props/percentage.rb +1 -1
  29. data/lib/playbook/version.rb +1 -1
  30. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 538626b25c8cfe2a426a8cb708a5bc832dc50e5cac5fc73d1c2c6f5eb7a9bafc
4
- data.tar.gz: 02ec4a247e32c0e92372b0da5fd4a2060daa333b86a6dc410b9047e3749b3526
3
+ metadata.gz: 468316bdb9eaf492b0e250410de1241ffd0ab4c38f8a605ce42665d59924bb8d
4
+ data.tar.gz: 7bcf743ce36bfa07ff916bd44be34b84d3de0beb78891292c317c36c5523c91b
5
5
  SHA512:
6
- metadata.gz: c7a4624ab3daffb11381327e70a0bee6e9ec820a831b0989b3637b872f07da29dc763f51218ae2f512c65e61f906adb8385bb9dbeed8f1846d5d8c75b792d19b
7
- data.tar.gz: 02d4a3bf6b766d826e2cba344bcee3c918657e62e393ded122617144f7e8bd12844e96d06ee80f716fe76396d528d10f62de7186f92ab0a767586cb91694ea62
6
+ metadata.gz: 2cc3c3454e5a37b857b03642b4b2b0f2a9667e4ca0b6ca26285bd8be6f89cb0babe6c617ef4cb8b6bedd63fdcbc82f78f4fc8760274e947a0bc1473016913130
7
+ data.tar.gz: 1532380e45d62b933b33172925672f560b608e12125901cab907555fe4d4a6e588c11ac61658fe53152e8e1d5895868de400855b8c078b01e8433f7e25d80f58
@@ -1,12 +1,12 @@
1
1
  <%= content_tag(:div,
2
2
  id: object.id,
3
- data: object.data(initials: object.initials),
4
- class: object.classname(object.kit_class),
3
+ data: object.data.merge(initials: object.initials),
4
+ class: object.classname,
5
5
  aria: object.aria) do %>
6
6
  <%= content_tag(:div,
7
7
  data: { initials: object.initials },
8
8
  class: "avatar_wrapper") do %>
9
- <%= object.image %>
10
- <% end %>
11
- <%= object.status %>
9
+ <%= pb_rails("image", props: object.image) if object.image.present? %>
10
+ <% end %>
11
+ <%= pb_rails("online_status", props: object.online_status_props) if object.status %>
12
12
  <% end %>
@@ -2,78 +2,29 @@
2
2
 
3
3
  module Playbook
4
4
  module PbAvatar
5
- class Avatar < Playbook::PbKit::Base
6
- PROPS = %i[configured_aria
7
- configured_classname
8
- configured_data
9
- configured_id
10
- configured_image
11
- configured_name
12
- configured_size
13
- configured_status].freeze
5
+ class Avatar
6
+ include Playbook::Props
14
7
 
15
- def initialize(aria: default_configuration,
16
- classname: default_configuration,
17
- data: default_configuration,
18
- id: default_configuration,
19
- image: default_configuration,
20
- name: default_configuration,
21
- size: default_configuration,
22
- status: default_configuration)
23
- self.configured_aria = aria
24
- self.configured_classname = classname
25
- self.configured_data = data
26
- self.configured_id = id
27
- self.configured_image = image
28
- self.configured_name = name
29
- self.configured_size = size
30
- self.configured_status = status
31
- end
8
+ partial "pb_avatar/avatar"
32
9
 
33
- def image
34
- if is_set? configured_image
35
- pb_image = Playbook::PbImage::Image.new(configured_image)
36
- ApplicationController.renderer.render(partial: pb_image, as: :object)
37
- end
38
- end
10
+ prop :image, type: Playbook::Props::Hash, default: {}
11
+ prop :name, default: ""
12
+ prop :size, type: Playbook::Props::Enum,
13
+ values: %w[xs sm md base lg xl],
14
+ default: "md"
15
+ prop :status
39
16
 
40
17
  def initials
41
- adjusted_value(configured_name, configured_name.split.map(&:first).join.downcase, "")
18
+ name.split.map(&:first).join.downcase
42
19
  end
43
20
 
44
- def size
45
- size_options = %w[xs sm md base lg xl]
46
- one_of_value(configured_size, size_options, "md")
21
+ def classname
22
+ generate_classname("pb_avatar_kit", size)
47
23
  end
48
24
 
49
- def status
50
- if is_set? configured_status
51
- online_status_props = { status: configured_status, classname: "size_#{size}" }
52
- pb_status = Playbook::PbOnlineStatus::OnlineStatus.new(online_status_props)
53
- ApplicationController.renderer.render(partial: pb_status, as: :object)
54
- end
55
- end
56
-
57
- def kit_class
58
- avatar_options = [
59
- "pb_avatar_kit",
60
- size,
61
- ]
62
- avatar_options.join("_")
63
- end
64
-
65
- def to_partial_path
66
- "pb_avatar/avatar"
67
- end
68
-
69
- private
70
-
71
- DEFAULT = Object.new
72
- private_constant :DEFAULT
73
- def default_configuration
74
- DEFAULT
25
+ def online_status_props
26
+ { status: status, classname: "size_#{size}" }
75
27
  end
76
- attr_accessor(*PROPS)
77
28
  end
78
29
  end
79
30
  end
@@ -6,15 +6,7 @@
6
6
  <% content_for :pb_js do %>
7
7
  <%= javascript_tag do %>
8
8
  window.addEventListener('DOMContentLoaded', function() {
9
- new pbChart('.selector', {
10
- id: "<%= object.id %>",
11
- chartData: <%= object.sanitized_chart_data %>,
12
- type: "<%= object.chart_type %>",
13
- title: "<%= object.title %>",
14
- subtitle: "<%= object.subtitle %>",
15
- axisTitle: "<%= object.axis_title %>",
16
- pointStart: <%= object.point_start %>,
17
- })
9
+ new pbChart('.selector', <%= object.chart_options %>)
18
10
  })
19
11
  <% end %>
20
12
  <% end %>
@@ -12,7 +12,7 @@ module Playbook
12
12
  prop :orientation, type: Playbook::Props::Enum,
13
13
  values: %w[vertical horizontal],
14
14
  default: "vertical"
15
- prop :point_start
15
+ prop :point_start, type: Playbook::Props::Numeric
16
16
  prop :subtitle
17
17
  prop :title
18
18
 
@@ -20,12 +20,20 @@ module Playbook
20
20
  orientation == "horizontal" ? "bar" : "column"
21
21
  end
22
22
 
23
- def classname
24
- generate_classname("pb_bar_graph")
23
+ def chart_options
24
+ {
25
+ id: id,
26
+ chartData: chart_data,
27
+ type: chart_type,
28
+ title: title,
29
+ subtitle: subtitle,
30
+ axisTitle: axis_title,
31
+ pointStart: point_start
32
+ }.to_json.html_safe
25
33
  end
26
34
 
27
- def sanitized_chart_data
28
- chart_data.to_json.html_safe
35
+ def classname
36
+ generate_classname("pb_bar_graph")
29
37
  end
30
38
  end
31
39
  end
@@ -19,7 +19,7 @@
19
19
  axis_title: 'Number of Employees',
20
20
  chart_data: data,
21
21
  id: "bar-test",
22
- point_start: "2012",
22
+ point_start: 2012,
23
23
  subtitle: 'Source: thesolarfoundation.com',
24
24
  title: 'Solar Employment Growth by Sector, 2010-2016'
25
25
  }) %>
@@ -1,6 +1,6 @@
1
1
  <%= pb_rails("dashboard_value", props: {
2
2
  stat_label: {label: "Top Title Value"},
3
- stat_value: {value: "1,428", unit: "appts"},
3
+ stat_value: {value: 1428, unit: "appts"},
4
4
  stat_change: {change: "decrease", value: "26.1%"}
5
5
  }) %>
6
6
 
@@ -9,7 +9,7 @@
9
9
  <%= pb_rails("dashboard_value", props: {
10
10
  align: "center",
11
11
  stat_label: {label: "Top Title Value"},
12
- stat_value: {value: "1,428", unit: "appts"},
12
+ stat_value: {value: 1428, unit: "appts"},
13
13
  stat_change: {change: "decrease", value: "26.1%"}
14
14
  }) %>
15
15
 
@@ -18,6 +18,6 @@
18
18
  <%= pb_rails("dashboard_value", props: {
19
19
  align: "right",
20
20
  stat_label: {label: "Top Title Value"},
21
- stat_value: {value: "1,428", unit: "appts"},
21
+ stat_value: {value: 1428, unit: "appts"},
22
22
  stat_change: {change: "decrease", value: "26.1%"}
23
23
  }) %>
@@ -1,6 +1,6 @@
1
1
  <%= pb_rails("dashboard_value", props: {
2
2
  stat_label: {label: "Decreased Value"},
3
- stat_value: {value: "1,428", unit: "appts"},
3
+ stat_value: {value: 1428, unit: "appts"},
4
4
  stat_change: {change: "decrease", value: "26.1%"}
5
5
  }) %>
6
6
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  <%= pb_rails("dashboard_value", props: {
10
10
  stat_label: {label: "Increased Value"},
11
- stat_value: {value: "938", unit: "homes"},
11
+ stat_value: {value: 938, unit: "homes"},
12
12
  stat_change: {change: "increase", value: "26.1%"}
13
13
  }) %>
14
14
 
@@ -16,6 +16,6 @@
16
16
 
17
17
  <%= pb_rails("dashboard_value", props: {
18
18
  stat_label: {label: "Neutral Value"},
19
- stat_value: {value: "261", unit: "windows"},
19
+ stat_value: {value: 261, unit: "windows"},
20
20
  stat_change: {value: "26.1%"}
21
21
  }) %>
@@ -1,7 +1,5 @@
1
- <% if !object.icon_class.nil? %>
2
- <%= content_tag(:i, nil,
3
- id: object.id,
4
- data: object.data,
5
- class: object.classname(object.kit_class),
6
- aria: object.aria) %>
7
- <% end %>
1
+ <%= content_tag(:i, nil,
2
+ id: object.id,
3
+ data: object.data,
4
+ class: object.classname,
5
+ aria: object.aria) %>
@@ -2,159 +2,108 @@
2
2
 
3
3
  module Playbook
4
4
  module PbIcon
5
- class Icon < Playbook::PbKit::Base
6
- PROPS = %i[configured_aria
7
- configured_border
8
- configured_classname
9
- configured_data
10
- configured_fixed_width
11
- configured_flip
12
- configured_icon
13
- configured_id
14
- configured_inverse
15
- configured_list_item
16
- configured_pull
17
- configured_pulse
18
- configured_rotation
19
- configured_size
20
- configured_spin].freeze
21
-
22
- def initialize(aria: default_configuration,
23
- border: default_configuration,
24
- classname: default_configuration,
25
- data: default_configuration,
26
- fixed_width: default_configuration,
27
- flip: default_configuration,
28
- icon: default_configuration,
29
- id: default_configuration,
30
- inverse: default_configuration,
31
- list_item: default_configuration,
32
- pull: default_configuration,
33
- pulse: default_configuration,
34
- rotation: default_configuration,
35
- size: default_configuration,
36
- spin: default_configuration)
37
- self.configured_aria = aria
38
- self.configured_border = border
39
- self.configured_classname = classname
40
- self.configured_data = data
41
- self.configured_fixed_width = fixed_width
42
- self.configured_flip = flip
43
- self.configured_icon = icon
44
- self.configured_id = id
45
- self.configured_inverse = inverse
46
- self.configured_list_item = list_item
47
- self.configured_pull = pull
48
- self.configured_pulse = pulse
49
- self.configured_rotation = rotation
50
- self.configured_size = size
51
- self.configured_spin = spin
5
+ class Icon
6
+ include Playbook::Props
7
+
8
+ partial "pb_icon/icon"
9
+
10
+ prop :border, type: Playbook::Props::Boolean,
11
+ default: false
12
+ prop :fixed_width, type: Playbook::Props::Boolean,
13
+ default: false
14
+ prop :flip, type: Playbook::Props::Enum,
15
+ values: ["horizontal", "vertical", "both", nil],
16
+ default: nil
17
+ prop :icon, required: true
18
+ prop :inverse, type: Playbook::Props::Boolean,
19
+ default: false
20
+ prop :list_item, type: Playbook::Props::Boolean,
21
+ default: false
22
+ prop :pull, type: Playbook::Props::Enum,
23
+ values: ["left", "right", nil],
24
+ default: nil
25
+ prop :pulse, type: Playbook::Props::Boolean,
26
+ default: false
27
+ prop :rotation, type: Playbook::Props::Enum,
28
+ values: [90, 180, 270, nil],
29
+ default: nil
30
+ prop :size, type: Playbook::Props::Enum,
31
+ values: ["lg", "xs", "sm", "1x", "2x", "3x", "4x", "5x", "6x", "7x", "8x", "9x", "10x", nil],
32
+ default: nil
33
+ prop :spin, type: Playbook::Props::Boolean,
34
+ default: false
35
+
36
+ def classname
37
+ generate_classname(
38
+ "pb_icon_kit",
39
+ "far",
40
+ icon_class,
41
+ border_class,
42
+ fixed_width_class,
43
+ flip_class,
44
+ inverse_class,
45
+ list_item_class,
46
+ pull_class,
47
+ pulse_class,
48
+ rotation_class,
49
+ size_class,
50
+ spin_class,
51
+ separator: " "
52
+ )
52
53
  end
53
54
 
55
+ private
56
+
54
57
  def border_class
55
- true_value(configured_border, "fa-border", nil)
58
+ border ? "fa-border" : nil
56
59
  end
57
60
 
58
61
  def fixed_width_class
59
- true_value(configured_fixed_width, "fa-fw", nil)
60
- end
61
-
62
- def flip
63
- flip_options = %w[horizontal vertical both]
64
- one_of_value(configured_flip, flip_options, nil)
65
- end
66
-
67
- def flip_class
68
- h_class = "fa-flip-horizontal"
69
- v_class = "fa-flip-vertical"
70
- case flip
71
- when "horizontal"
72
- h_class
73
- when "vertical"
74
- v_class
75
- when "both"
76
- [h_class, v_class].join(" ")
77
- end
62
+ fixed_width ? "fa-fw" : nil
78
63
  end
79
64
 
80
65
  def icon_class
81
- adjusted_value(configured_icon, "fa-#{configured_icon}", nil)
66
+ icon ? "fa-#{icon}" : nil
82
67
  end
83
68
 
84
69
  def inverse_class
85
- true_value(configured_inverse, "fa-inverse", nil)
70
+ inverse ? "fa-inverse" : nil
86
71
  end
87
72
 
88
73
  def list_item_class
89
- true_value(configured_list_item, "fa-li", nil)
74
+ list_item ? "fa-li" : nil
90
75
  end
91
76
 
92
- def pull
93
- pull_options = %w[left right]
94
- one_of_value(configured_pull, pull_options, default_configuration)
77
+ def flip_class
78
+ case flip
79
+ when "horizontal"
80
+ "fa-flip-horizontal"
81
+ when "vertical"
82
+ "fa-flip-vertical"
83
+ when "both"
84
+ "fa-flip-horizontal fa-flip-vertical"
85
+ end
95
86
  end
96
87
 
97
88
  def pull_class
98
- adjusted_value(pull, "fa-pull-#{pull}", nil)
89
+ pull ? "fa-pull-#{pull}" : nil
99
90
  end
100
91
 
101
92
  def pulse_class
102
- true_value(configured_pulse, "fa-pulse", nil)
103
- end
104
-
105
- def rotation
106
- rotation_options = [90, 180, 270]
107
- one_of_value(configured_rotation, rotation_options, default_configuration)
93
+ pulse ? "fa-pulse" : nil
108
94
  end
109
95
 
110
96
  def rotation_class
111
- adjusted_value(rotation, "fa-rotate-#{rotation}", nil)
112
- end
113
-
114
- def size
115
- size_options = %w[lg xs sm 1x 2x 3x 4x 5x 6x 7x 8x 9x 10x]
116
- one_of_value(configured_size, size_options, default_configuration)
97
+ rotation ? "fa-rotate-#{rotation}" : nil
117
98
  end
118
99
 
119
100
  def size_class
120
- adjusted_value(size, "fa-#{size}", nil)
101
+ size ? "fa-#{size}" : nil
121
102
  end
122
103
 
123
104
  def spin_class
124
- true_value(configured_spin, "fa-spin", nil)
125
- end
126
-
127
- def kit_class
128
- icon_options = [
129
- "pb_icon_kit",
130
- "far",
131
- icon_class,
132
- border_class,
133
- fixed_width_class,
134
- flip_class,
135
- inverse_class,
136
- list_item_class,
137
- pull_class,
138
- pulse_class,
139
- rotation_class,
140
- size_class,
141
- spin_class,
142
- ]
143
- icon_options.reject(&:nil?).join(" ")
144
- end
145
-
146
- def to_partial_path
147
- "pb_icon/icon"
148
- end
149
-
150
- private
151
-
152
- DEFAULT = Object.new
153
- private_constant :DEFAULT
154
- def default_configuration
155
- DEFAULT
105
+ spin ? "fa-spin" : nil
156
106
  end
157
- attr_accessor(*PROPS)
158
107
  end
159
108
  end
160
109
  end
@@ -1,7 +1,7 @@
1
1
  <%= content_tag(:div,
2
2
  id: object.id,
3
3
  data: object.data,
4
- class: object.classname("pb_label_pill_kit")) do %>
5
- <%= object.label %>
6
- <%= object.pill %>
4
+ class: object.classname) do %>
5
+ <%= pb_rails("caption", props: { text: object.label, classname: "pb_label_pill_label"}) %>
6
+ <%= pb_rails("pill", props: { text: object.pill_value, variant: object.variant, classname: "pb_label_pill_pill" }) %>
7
7
  <% end %>
@@ -2,58 +2,20 @@
2
2
 
3
3
  module Playbook
4
4
  module PbLabelPill
5
- class LabelPill < Playbook::PbKit::Base
6
- PROPS = %i[configured_classname
7
- configured_data
8
- configured_id
9
- configured_label
10
- configured_pill_value
11
- configured_variant].freeze
5
+ class LabelPill
6
+ include Playbook::Props
12
7
 
13
- def initialize(classname: default_configuration,
14
- data: default_configuration,
15
- id: default_configuration,
16
- label: default_configuration,
17
- pill_value: default_configuration,
18
- variant: default_configuration)
19
- self.configured_classname = classname
20
- self.configured_data = data
21
- self.configured_id = id
22
- self.configured_label = label
23
- self.configured_pill_value = pill_value
24
- self.configured_variant = variant
25
- end
26
-
27
- def label
28
- if is_set? configured_label
29
- pb_caption = Playbook::PbCaption::Caption.new(text: configured_label, classname: "pb_label_pill_label")
30
- ApplicationController.renderer.render(partial: pb_caption, as: :object)
31
- end
32
- end
33
-
34
- def pill
35
- if is_set? configured_pill_value
36
- pb_pill = Playbook::PbPill::Pill.new(text: configured_pill_value, variant: variant, classname: "pb_label_pill_pill")
37
- ApplicationController.renderer.render(partial: pb_pill, as: :object)
38
- end
39
- end
40
-
41
- def variant
42
- default_value(configured_variant, "neutral")
43
- end
44
-
45
- def to_partial_path
46
- "pb_label_pill/label_pill"
47
- end
8
+ partial "pb_label_pill/label_pill"
48
9
 
49
- private
10
+ prop :variant, type: Playbook::Props::Enum,
11
+ values: %w[success warning error info neutral],
12
+ default: "neutral"
13
+ prop :label
14
+ prop :pill_value
50
15
 
51
- DEFAULT = Object.new
52
- private_constant :DEFAULT
53
- def default_configuration
54
- DEFAULT
16
+ def classname
17
+ generate_classname("pb_label_pill_kit", variant)
55
18
  end
56
- attr_accessor(*PROPS)
57
19
  end
58
20
  end
59
21
  end
@@ -1,7 +1,7 @@
1
1
  <%= content_tag(:div,
2
2
  id: object.id,
3
3
  data: object.data,
4
- class: object.classname(object.kit_class)) do %>
5
- <%= object.label %>
6
- <%= object.value %>
4
+ class: object.classname) do %>
5
+ <%= pb_rails("caption", props: { text: object.label }) %>
6
+ <%= pb_rails("body", props: { text: object.value }) %>
7
7
  <% end %>
@@ -2,55 +2,17 @@
2
2
 
3
3
  module Playbook
4
4
  module PbLabelValue
5
- class LabelValue < Playbook::PbKit::Base
6
- PROPS = %i[configured_classname
7
- configured_data
8
- configured_id
9
- configured_label
10
- configured_value].freeze
5
+ class LabelValue
6
+ include Playbook::Props
11
7
 
12
- def initialize(classname: default_configuration,
13
- data: default_configuration,
14
- id: default_configuration,
15
- label: default_configuration,
16
- value: default_configuration)
17
- self.configured_classname = classname
18
- self.configured_data = data
19
- self.configured_id = id
20
- self.configured_label = label
21
- self.configured_value = value
22
- end
23
-
24
- def label
25
- if is_set? configured_label
26
- pb_label = Playbook::PbCaption::Caption.new(text: configured_label)
27
- ApplicationController.renderer.render(partial: pb_label, as: :object)
28
- end
29
- end
30
-
31
- def value
32
- pb_body = Playbook::PbBody::Body.new do
33
- default_value(configured_value, "")
34
- end
35
- ApplicationController.renderer.render(partial: pb_body, as: :object)
36
- end
37
-
38
- def kit_class
39
- "pb_label_value_kit"
40
- end
41
-
42
- def to_partial_path
43
- "pb_label_value/label_value"
44
- end
8
+ partial "pb_label_value/label_value"
45
9
 
46
- private
10
+ prop :label, required: true
11
+ prop :value, required: true
47
12
 
48
- DEFAULT = Object.new
49
- private_constant :DEFAULT
50
- def default_configuration
51
- DEFAULT
13
+ def classname
14
+ generate_classname("pb_label_value_kit")
52
15
  end
53
- attr_accessor(*PROPS)
54
16
  end
55
17
  end
56
18
  end
@@ -2,20 +2,12 @@
2
2
  aria: object.aria,
3
3
  id: object.id,
4
4
  data: object.data,
5
- class: object.classname("pb_line_graph")
5
+ class: object.classname
6
6
  ) %>
7
7
  <% content_for :pb_js do %>
8
8
  <%= javascript_tag do %>
9
9
  window.addEventListener('DOMContentLoaded', function() {
10
- new pbChart('.selector', {
11
- id: "<%= object.id %>",
12
- chartData: <%= object.chart_data %>,
13
- type: "<%= object.chart_type %>",
14
- title: "<%= object.title %>",
15
- subtitle: "<%= object.subtitle %>",
16
- axisTitle: "<%= object.axis_title %>",
17
- pointStart: <%= object.point_start %>,
18
- })
10
+ new pbChart('.selector', <%= object.chart_options %>)
19
11
  })
20
12
  <% end %>
21
13
  <% end %>
@@ -15,7 +15,7 @@
15
15
  data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
16
16
  }] %>
17
17
 
18
- <%= pb_rails("line_graph", props: { id: "line-test", gradient: false, chart_data: data, point_start: "1", title: 'Solar Employment Growth by Sector, 2010-2016', subtitle: 'Source: thesolarfoundation.com', axis_title: 'Number of Employees' } ) %>
18
+ <%= pb_rails("line_graph", props: { id: "line-test", gradient: false, chart_data: data, point_start: 1, title: 'Solar Employment Growth by Sector, 2010-2016', subtitle: 'Source: thesolarfoundation.com', axis_title: 'Number of Employees' } ) %>
19
19
 
20
20
 
21
21
 
@@ -2,84 +2,39 @@
2
2
 
3
3
  module Playbook
4
4
  module PbLineGraph
5
- class LineGraph < Playbook::PbKit::Base
6
- PROPS = %i[
7
- configured_aria
8
- configured_axis_title
9
- configured_chart_data
10
- configured_classname
11
- configured_data
12
- configured_gradient
13
- configured_id
14
- configured_point_start
15
- configured_subtitle
16
- configured_title
17
- ].freeze
5
+ class LineGraph
6
+ include Playbook::Props
18
7
 
19
- def initialize(
20
- aria: default_configuration,
21
- axis_title: default_configuration,
22
- chart_data: default_configuration,
23
- classname: default_configuration,
24
- data: default_configuration,
25
- gradient: default_configuration,
26
- id: default_configuration,
27
- point_start: default_configuration,
28
- subtitle: default_configuration,
29
- title: default_configuration
30
- )
31
- self.configured_aria = aria
32
- self.configured_axis_title = axis_title
33
- self.configured_chart_data = chart_data
34
- self.configured_classname = classname
35
- self.configured_data = data
36
- self.configured_gradient = gradient
37
- self.configured_id = id
38
- self.configured_point_start = point_start
39
- self.configured_subtitle = subtitle
40
- self.configured_title = title
41
- end
8
+ partial "pb_line_graph/line_graph"
42
9
 
43
- def gradient
44
- is_true? configured_gradient
45
- end
10
+ prop :axis_title
11
+ prop :chart_data, type: Playbook::Props::Array,
12
+ default: []
13
+ prop :gradient, type: Playbook::Props::Boolean,
14
+ default: false
15
+ prop :point_start, type: Playbook::Props::Numeric
16
+ prop :subtitle
17
+ prop :title
46
18
 
47
19
  def chart_type
48
- gradient == true ? "area" : "line"
49
- end
50
-
51
- def title
52
- default_value(configured_title, "")
20
+ gradient ? "area" : "line"
53
21
  end
54
22
 
55
- def subtitle
56
- default_value(configured_subtitle, "")
23
+ def chart_options
24
+ {
25
+ id: id,
26
+ chartData: chart_data,
27
+ type: chart_type,
28
+ title: title,
29
+ subTitle: subtitle,
30
+ axisTitle: axis_title,
31
+ pointStart: point_start,
32
+ }.to_json.html_safe
57
33
  end
58
34
 
59
- def axis_title
60
- default_value(configured_axis_title, "")
61
- end
62
-
63
- def to_partial_path
64
- "pb_line_graph/line_graph"
65
- end
66
-
67
- def point_start
68
- default_value(configured_point_start, "")
69
- end
70
-
71
- def chart_data
72
- adjusted_value(configured_chart_data, configured_chart_data.to_json.html_safe, {})
73
- end
74
-
75
- private
76
-
77
- DEFAULT = Object.new
78
- private_constant :DEFAULT
79
- def default_configuration
80
- DEFAULT
35
+ def classname
36
+ generate_classname("pb_line_graph")
81
37
  end
82
- attr_accessor(*PROPS)
83
38
  end
84
39
  end
85
40
  end
@@ -1,10 +1,16 @@
1
1
  <%= content_tag(:div,
2
2
  id: object.id,
3
3
  data: object.data,
4
- class: object.classname(object.kit_class)) do %>
4
+ class: object.classname) do %>
5
5
  <div class="pb_stat_value_wrapper">
6
- <%= object.display_value %>
7
- &nbsp;
8
- <%= object.display_unit %>
6
+ <%= pb_rails "title", props: {
7
+ classname: "pb_stat_value_kit",
8
+ size: 1,
9
+ text: object.value } %>
10
+ &nbsp;
11
+ <%= pb_rails "title", props: {
12
+ classname: "pb_stat_value_kit",
13
+ size: 3,
14
+ text: object.unit } %>
9
15
  </div>
10
16
  <% end %>
@@ -1 +1 @@
1
- <%= pb_rails("stat_value", props: { value: "5,294", unit: "appt" }) %>
1
+ <%= pb_rails("stat_value", props: { value: 5294, unit: "appt" }) %>
@@ -2,61 +2,17 @@
2
2
 
3
3
  module Playbook
4
4
  module PbStatValue
5
- class StatValue < Playbook::PbKit::Base
6
- PROPS = %i[configured_classname
7
- configured_data
8
- configured_id
9
- configured_unit
10
- configured_value].freeze
5
+ class StatValue
6
+ include Playbook::Props
11
7
 
12
- def initialize(classname: default_configuration,
13
- data: default_configuration,
14
- id: default_configuration,
15
- unit: default_configuration,
16
- value: default_configuration)
17
- self.configured_classname = classname
18
- self.configured_data = data
19
- self.configured_id = id
20
- self.configured_unit = unit
21
- self.configured_value = value
22
- end
23
-
24
- def value
25
- default_value(configured_value, 0)
26
- end
27
-
28
- def display_value
29
- pb_title = Playbook::PbTitle::Title.new(size: 1, text: value)
30
- ApplicationController.renderer.render(partial: pb_title, as: :object)
31
- end
32
-
33
- def unit
34
- default_value(configured_unit, nil)
35
- end
36
-
37
- def display_unit
38
- unless unit.nil?
39
- pb_unit = Playbook::PbTitle::Title.new(size: 3, text: unit)
40
- ApplicationController.renderer.render(partial: pb_unit, as: :object)
41
- end
42
- end
43
-
44
- def kit_class
45
- "pb_stat_value_kit"
46
- end
47
-
48
- def to_partial_path
49
- "pb_stat_value/stat_value"
50
- end
8
+ partial "pb_stat_value/stat_value"
51
9
 
52
- private
10
+ prop :unit
11
+ prop :value, type: Playbook::Props::Number
53
12
 
54
- DEFAULT = Object.new
55
- private_constant :DEFAULT
56
- def default_configuration
57
- DEFAULT
13
+ def classname
14
+ generate_classname("pb_stat_value_kit")
58
15
  end
59
- attr_accessor(*PROPS)
60
16
  end
61
17
  end
62
18
  end
@@ -1,7 +1,10 @@
1
1
  <%= content_tag(:div,
2
2
  id: object.id,
3
3
  data: object.data,
4
- class: object.classname(object.kit_class)) do %>
5
- <%= object.title %>
6
- <%= object.count %>
4
+ class: object.classname) do %>
5
+ <%= pb_rails("title", props: {
6
+ size: object.title_size,
7
+ text: object.title,
8
+ classname: "pb_title_count_text" }) if object.title %>
9
+ <%= pb_rails("body", props: { color: "light" }) { object.format_count } if object.count %>
7
10
  <% end %>
@@ -1,6 +1,6 @@
1
1
  <%= pb_rails("title_count", props: {
2
2
  title: "Appointments",
3
- count: "7,399"
3
+ count: 35.78
4
4
  }) %>
5
5
 
6
6
  <br>
@@ -2,91 +2,31 @@
2
2
 
3
3
  module Playbook
4
4
  module PbTitleCount
5
- class TitleCount < Playbook::PbKit::Base
6
- PROPS = %i[configured_align
7
- configured_classname
8
- configured_count
9
- configured_data
10
- configured_id
11
- configured_size
12
- configured_title].freeze
5
+ class TitleCount
6
+ include Playbook::Props
13
7
 
14
- def initialize(align: default_configuration,
15
- classname: default_configuration,
16
- count: default_configuration,
17
- data: default_configuration,
18
- id: default_configuration,
19
- size: default_configuration,
20
- title: default_configuration)
21
- self.configured_align = align
22
- self.configured_classname = classname
23
- self.configured_count = count
24
- self.configured_data = data
25
- self.configured_id = id
26
- self.configured_size = size
27
- self.configured_title = title
28
- end
8
+ partial "pb_title_count/title_count"
29
9
 
30
- def align
31
- align_options = %w[left center right]
32
- one_of_value(configured_align, align_options, "left")
33
- end
10
+ prop :align, type: Playbook::Props::Enum,
11
+ values: %w[left center right],
12
+ default: "left"
13
+ prop :size, type: Playbook::Props::Enum,
14
+ values: %w[lg sm],
15
+ default: "sm"
16
+ prop :title
17
+ prop :count, type: Playbook::Props::Numeric
34
18
 
35
- def size
36
- size_options = %w[lg sm]
37
- one_of_value(configured_size, size_options, "sm")
19
+ def classname
20
+ generate_classname("pb_title_count_kit", align, size)
38
21
  end
39
22
 
40
23
  def title_size
41
24
  size == "lg" ? 3 : 4
42
25
  end
43
26
 
44
- def title
45
- if is_set? configured_title
46
- pb_title = Playbook::PbTitle::Title.new(size: title_size, text: configured_title, classname: "pb_title_count_text")
47
- ApplicationController.renderer.render(partial: pb_title, as: :object)
48
- end
49
- end
50
-
51
- def count
52
- if is_set? configured_count
53
- value = if configured_count.is_a?(Integer) || configured_count.is_a?(Float)
54
- format_number(configured_count)
55
- else
56
- configured_count
57
- end
58
-
59
- pb_count = Playbook::PbBody::Body.new(color: "light") do
60
- value.to_s
61
- end
62
- ApplicationController.renderer.render(partial: pb_count, as: :object)
63
- end
64
- end
65
-
66
- def format_number(number)
67
- number.to_s.gsub(/(\d)(?=\d{3}+(?:\.|$))(\d{3}\..*)?/, '\1,\2')
68
- end
69
-
70
- def kit_class
71
- kit_options = [
72
- "pb_title_count_kit",
73
- align,
74
- ]
75
- kit_options.join("_")
76
- end
77
-
78
- def to_partial_path
79
- "pb_title_count/title_count"
80
- end
81
-
82
- private
83
-
84
- DEFAULT = Object.new
85
- private_constant :DEFAULT
86
- def default_configuration
87
- DEFAULT
27
+ def format_count
28
+ count.to_s.gsub(/(\d)(?=\d{3}+(?:\.|$))(\d{3}\..*)?/, '\1,\2')
88
29
  end
89
- attr_accessor(*PROPS)
90
30
  end
91
31
  end
92
32
  end
@@ -1,7 +1,7 @@
1
1
  <%= content_tag(:div,
2
2
  id: object.id,
3
3
  data: object.data,
4
- class: object.classname(object.kit_class)) do %>
5
- <%= object.title %>
6
- <%= object.detail %>
4
+ class: object.classname) do %>
5
+ <%= pb_rails("title", props: { text: object.title, size: 4 }) %>
6
+ <%= pb_rails("body", props: { text: object.detail, color: "light" }) %>
7
7
  <% end %>
@@ -2,69 +2,20 @@
2
2
 
3
3
  module Playbook
4
4
  module PbTitleDetail
5
- class TitleDetail < Playbook::PbKit::Base
6
- PROPS = %i[configured_align
7
- configured_classname
8
- configured_data
9
- configured_detail
10
- configured_id
11
- configured_title].freeze
5
+ class TitleDetail
6
+ include Playbook::Props
12
7
 
13
- def initialize(align: default_configuration,
14
- classname: default_configuration,
15
- data: default_configuration,
16
- detail: default_configuration,
17
- id: default_configuration,
18
- title: default_configuration)
19
- self.configured_align = align
20
- self.configured_classname = classname
21
- self.configured_data = data
22
- self.configured_detail = detail
23
- self.configured_id = id
24
- self.configured_title = title
25
- end
26
-
27
- def align
28
- align_options = %w[left center right]
29
- one_of_value(configured_align, align_options, "left")
30
- end
31
-
32
- def title
33
- if is_set? configured_title
34
- pb_title = Playbook::PbTitle::Title.new(size: 4, text: configured_title)
35
- ApplicationController.renderer.render(partial: pb_title, as: :object)
36
- end
37
- end
38
-
39
- def detail
40
- if is_set? configured_detail
41
- pb_detail = Playbook::PbBody::Body.new(color: "light") do
42
- configured_detail
43
- end
44
- ApplicationController.renderer.render(partial: pb_detail, as: :object)
45
- end
46
- end
47
-
48
- def kit_class
49
- kit_options = [
50
- "pb_title_detail_kit",
51
- align,
52
- ]
53
- kit_options.join("_")
54
- end
55
-
56
- def to_partial_path
57
- "pb_title_detail/title_detail"
58
- end
8
+ partial "pb_title_detail/title_detail"
59
9
 
60
- private
10
+ prop :align, type: Playbook::Props::Enum,
11
+ values: %w[left center right],
12
+ default: "left"
13
+ prop :detail, required: true
14
+ prop :title, required: true
61
15
 
62
- DEFAULT = Object.new
63
- private_constant :DEFAULT
64
- def default_configuration
65
- DEFAULT
16
+ def classname
17
+ generate_classname("pb_title_detail_kit", align)
66
18
  end
67
- attr_accessor(*PROPS)
68
19
  end
69
20
  end
70
21
  end
@@ -12,9 +12,10 @@ require_relative "./props/hash"
12
12
  require_relative "./props/hash_array"
13
13
  require_relative "./props/number"
14
14
  require_relative "./props/number_array"
15
- require_relative "./props/string"
15
+ require_relative "./props/numeric"
16
16
  require_relative "./props/percentage"
17
17
  require_relative "./props/proc"
18
+ require_relative "./props/string"
18
19
 
19
20
  module Playbook
20
21
  module Props
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Playbook
4
+ module Props
5
+ class Numeric < Playbook::Props::Base
6
+ def validate(value)
7
+ value.nil? ||
8
+ value.is_a?(Integer) ||
9
+ value.is_a?(Float)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -10,7 +10,7 @@ module Playbook
10
10
  private
11
11
 
12
12
  def numeric_in_range?(value)
13
- (value.is_a?(Numeric) &&
13
+ (value.is_a?(::Numeric) &&
14
14
  value <= 100 &&
15
15
  value >= 0)
16
16
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Playbook
4
- VERSION = "2.9.5"
4
+ VERSION = "2.9.6"
5
5
  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: 2.9.5
4
+ version: 2.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Power UX
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-10-25 00:00:00.000000000 Z
12
+ date: 2019-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -1031,6 +1031,7 @@ files:
1031
1031
  - app/pb_kits/playbook/props/hash_array.rb
1032
1032
  - app/pb_kits/playbook/props/number.rb
1033
1033
  - app/pb_kits/playbook/props/number_array.rb
1034
+ - app/pb_kits/playbook/props/numeric.rb
1034
1035
  - app/pb_kits/playbook/props/percentage.rb
1035
1036
  - app/pb_kits/playbook/props/proc.rb
1036
1037
  - app/pb_kits/playbook/props/string.rb