organism-ui 0.2.14 → 0.2.15

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: 93f273285d90a758e4f76dc2edf5c9c1024868f65750f86d9a4d21a0be03e2b3
4
- data.tar.gz: 8024fe03394aaad8b44904b09a5dd6c38f9552e42b01d9c2fdcf44a9352433c8
3
+ metadata.gz: f27836996619577882186d159e7ca50cc282dddcfd8090832f901965cce8828c
4
+ data.tar.gz: abb2ae83b2f31627e6df9ea53b2f5fbe9a240ea1a7ec1f6e089c97ae265789a8
5
5
  SHA512:
6
- metadata.gz: 25f414159a5bbfd726a9a7da8baeab7d2082b8294e897c4e80e870149a9872e3faa0172f65024e1513b3fb3a74e1b244a8a6ceef344e9a69f661728ab31c48be
7
- data.tar.gz: 7ae976e18d782c1b025bd1ad24f64b6e4cddc43ca0b735a6cae3a11e57bfbd1d92e5d4e8cf5b4cb8394e14f2e006c8b949f2dfdfa3000e5f9d7e1101bf2832e8
6
+ metadata.gz: 5a4e588f073083ac3d9dc3cb735567c4e5fd7d9b899de3c33e040c0af948e68700ceba48d76d893f7ad2e2ab6ba60df8b6514749aa16d14821c5e6f787acf916
7
+ data.tar.gz: ae0d450685712bc9d35669299de10c8ba0f132ec56ff03865d78004d1b7917105ffc59a041a4d70768f84c1cb4731cf96bfdb9c6c294be73b5a12bd7950e2fdd
@@ -677,7 +677,7 @@
677
677
  renderable: ->(item) {
678
678
  content_tag(
679
679
  :div,
680
- [
680
+ render_group([
681
681
  content_tag(:p, item),
682
682
  content_tag(
683
683
  :nav,
@@ -688,7 +688,7 @@
688
688
  size: :small
689
689
  ).call(:edit)
690
690
  )
691
- ].join(' ').html_safe,
691
+ ]),
692
692
  class: 'flex flex-row justify-between items-center p-4'
693
693
  )
694
694
  }
@@ -727,6 +727,32 @@
727
727
  </div>
728
728
  </section>
729
729
 
730
+ <section class="style-guide__example" id="type">
731
+ <header>
732
+ <h2>Vertical</h2>
733
+ </header>
734
+
735
+ <div class="space-y-4">
736
+ <%= cell(
737
+ Ui::Table,
738
+ [
739
+ "Data 1",
740
+ "Data 2",
741
+ "Data 3",
742
+ ],
743
+ columns: [
744
+ ["", ->(data) { data } ],
745
+ ["Column 2", ->(data) { "Column 2 data" } ],
746
+ ["Column 3", ->(data) { "Column 3 data" } ],
747
+ ["Actions", ->(data) { cell(Ui::Buttons::Tertiary, 'More')} ],
748
+ ],
749
+ header: 'My title',
750
+ orientation: 'vertical',
751
+ style: 'my-style'
752
+ ).() %>
753
+ </div>
754
+ </section>
755
+
730
756
  <section class="style-guide__example" id="type">
731
757
  <header>
732
758
  <h2>Selectable</h2>
@@ -748,6 +774,8 @@
748
774
  ],
749
775
  header: 'Multi select',
750
776
  style: 'my-style',
777
+ row_renderer: ->(row, columns) {
778
+ },
751
779
  features: {
752
780
  selectable: {
753
781
  multiple: true
data/lib/ui/actionable.rb CHANGED
@@ -1,21 +1,27 @@
1
1
  module Ui
2
2
  module Actionable
3
+ Actions = Types::Array.default([].freeze).of(Types::Callable)
4
+
3
5
  def actions
4
6
  content_tag(:nav, class: 'ui-actions', role: 'navigation') do
5
7
  render_group(
6
- options.fetch(:actions, Array.new).map do |action|
8
+ Actions[actions_list].map do |action|
7
9
  action.call(model)
8
10
  end
9
11
  )
10
12
  end
11
13
  end
12
14
 
15
+ def actions_list
16
+ options.fetch(:actions, Array.new) || Array.new
17
+ end
18
+
13
19
  def actions_length
14
20
  options.fetch(:actions, Array.new).size
15
21
  end
16
22
 
17
23
  def has_actions?
18
- options.fetch(:actions, []).any?
24
+ actions_list.any?
19
25
  end
20
26
  end
21
27
  end
@@ -13,11 +13,13 @@ module Ui
13
13
  end
14
14
 
15
15
  def breadcrumb_links
16
- breadcrumbs.map.with_index do |crumb, index|
17
- [item_renderer.call(crumb)].tap do |renderable|
18
- renderable.unshift(delimiter) unless index == 0
19
- end
20
- end.flatten.join(' ').html_safe
16
+ render_group(
17
+ breadcrumbs.map.with_index do |crumb, index|
18
+ [item_renderer.call(crumb)].tap do |renderable|
19
+ renderable.unshift(delimiter) unless index == 0
20
+ end
21
+ end.flatten
22
+ )
21
23
  end
22
24
 
23
25
  def delimiter
@@ -9,9 +9,7 @@ module Ui
9
9
  def show
10
10
  content_tag(
11
11
  :span,
12
- link_to(path) do
13
- title.html_safe
14
- end,
12
+ link_to(path, title),
15
13
  class: style
16
14
  )
17
15
  end
@@ -1,6 +1,8 @@
1
1
  module Ui
2
2
  module Buttons
3
3
  class Base < Component
4
+ include Stylable
5
+
4
6
  def show
5
7
  display(
6
8
  text_with_icon(icon),
@@ -38,6 +40,22 @@ module Ui
38
40
  )
39
41
  end
40
42
 
43
+ def phone
44
+ display(
45
+ text_with_icon(phone_icon),
46
+ "tel:#{path}",
47
+ button_options
48
+ )
49
+ end
50
+
51
+ def email
52
+ mail_to(
53
+ path,
54
+ text_with_icon(email_icon),
55
+ button_options
56
+ )
57
+ end
58
+
41
59
  private
42
60
 
43
61
  def display(*args)
@@ -46,7 +64,7 @@ module Ui
46
64
  :button,
47
65
  args.first,
48
66
  disabled: true,
49
- class: button_classes
67
+ class: style
50
68
  )
51
69
  else
52
70
  if path == '#'
@@ -69,13 +87,12 @@ module Ui
69
87
  'fas fa-trash'
70
88
  end
71
89
 
72
- def button_classes
73
- [
74
- "button",
75
- style,
76
- size,
77
- options.fetch(:style, '')
78
- ].compact.join(' ')
90
+ def phone_icon
91
+ 'fas fa-phone'
92
+ end
93
+
94
+ def email_icon
95
+ 'fas fa-envelope'
79
96
  end
80
97
 
81
98
  def size
@@ -92,25 +109,40 @@ module Ui
92
109
  end
93
110
 
94
111
  def text_with_icon(icon)
95
- if icon
96
- content_tag(
97
- :span,
98
- render_group([
99
- content_tag(:i, nil, class: icon),
100
- text
101
- ].compact)
102
- )
103
- else
104
- text
112
+ order = [text].tap do |array|
113
+ case icon_position
114
+ when 'end'
115
+ array.push(display_icon(icon))
116
+ else
117
+ array.unshift(display_icon(icon))
118
+ end
105
119
  end
120
+
121
+ render_group(order)
122
+ end
123
+
124
+ def display_icon(icon)
125
+ content_tag(:i, nil, class: icon) unless icon.blank?
106
126
  end
107
127
 
108
- def style
109
- ''
128
+ def component_style
129
+ [
130
+ 'button',
131
+ size,
132
+ ].join(' ')
110
133
  end
111
134
 
112
135
  def icon
113
- options[:icon]
136
+ icon_options.fetch(:style, '')
137
+ end
138
+
139
+ def icon_position
140
+ icon_options.fetch(:position, 'start')
141
+ end
142
+
143
+ def icon_options
144
+ opts = options.fetch(:icon, {})
145
+ opts.is_a?(Hash) ? opts : { style: opts }
114
146
  end
115
147
 
116
148
  def path
@@ -135,7 +167,7 @@ module Ui
135
167
 
136
168
  def button_options
137
169
  {
138
- class: button_classes,
170
+ class: style,
139
171
  disabled: disabled?,
140
172
  data: data,
141
173
  method: method
@@ -3,8 +3,11 @@ module Ui
3
3
  class Primary < Base
4
4
  private
5
5
 
6
- def style
7
- 'button--primary'
6
+ def component_style
7
+ [
8
+ 'button--primary',
9
+ super
10
+ ].flatten
8
11
  end
9
12
  end
10
13
  end
@@ -3,8 +3,11 @@ module Ui
3
3
  class Secondary < Base
4
4
  private
5
5
 
6
- def style
7
- 'button--secondary'
6
+ def component_style
7
+ [
8
+ 'button--secondary',
9
+ super
10
+ ].flatten
8
11
  end
9
12
  end
10
13
  end
@@ -3,8 +3,11 @@ module Ui
3
3
  class Tertiary < Base
4
4
  private
5
5
 
6
- def style
7
- 'button--tertiary'
6
+ def component_style
7
+ [
8
+ 'button--tertiary',
9
+ super
10
+ ].flatten
8
11
  end
9
12
  end
10
13
  end
data/lib/ui/collapse.rb CHANGED
@@ -13,7 +13,8 @@ module Ui
13
13
  def panels
14
14
  cell(
15
15
  Ui::Collapse::Panel,
16
- collection: model
16
+ collection: model,
17
+ actions: options[:actions]
17
18
  ).()
18
19
  end
19
20
 
@@ -1,6 +1,8 @@
1
1
  module Ui
2
2
  class Collapse < Component
3
3
  class Panel < Component
4
+ include Actionable
5
+
4
6
  def show
5
7
  render
6
8
  end
@@ -18,11 +20,11 @@ module Ui
18
20
  end
19
21
 
20
22
  def header
21
- content_tag(:p, display(model[0]))
23
+ display(model[0])
22
24
  end
23
25
 
24
26
  def content
25
- content_tag(:p, display(model[1]))
27
+ display(model[1])
26
28
  end
27
29
 
28
30
  def display(item)
@@ -1,16 +1,17 @@
1
1
  <article
2
2
  class="ui-collapse-panel"
3
3
  data-controller="collapsable"
4
- data-collapsable-collapsed-value="false"
4
+ data-collapsable-collapsed-value="true"
5
5
  data-collapsable-hidden-class="hidden"
6
6
  data-collapsable-collapsed-class="ui-collapsed">
7
7
 
8
- <header data-action="click->collapsable#toggle">
8
+ <header data-action="click->collapsable#toggle" class="ui-collapse-panel__header">
9
9
  <%= collapse_icon %>
10
10
  <%= header %>
11
+ <%= actions %>
11
12
  </header>
12
13
 
13
- <div data-collapsable-target="content" class="ui-collapse-panel__content">
14
+ <section data-collapsable-target="content" class="ui-collapse-panel__content">
14
15
  <%= content %>
15
- </div>
16
+ </section>
16
17
  </article>
data/lib/ui/component.rb CHANGED
@@ -9,7 +9,12 @@ module Ui
9
9
  self.view_paths << VIEWPATH
10
10
 
11
11
  def capture(*args)
12
- yield(*args).html_safe
12
+ content = yield(*args)
13
+ if content.is_a?(String)
14
+ content.html_safe
15
+ else
16
+ content
17
+ end
13
18
  end
14
19
 
15
20
  def render_group(items)
@@ -25,14 +25,14 @@ module Ui
25
25
  content_tag(
26
26
  :header,
27
27
  render_group([
28
- content_tag(:h2, title),
29
- content_tag(:nav, actions)
28
+ options[:header],
29
+ actions
30
30
  ])
31
- ) if title || has_actions?
31
+ ) if display_header?
32
32
  end
33
33
 
34
- def title
35
- options[:title]
34
+ def display_header?
35
+ options[:header] || has_actions?
36
36
  end
37
37
 
38
38
  def items
@@ -6,7 +6,7 @@ module Ui
6
6
  :div,
7
7
  render_group([
8
8
  content_tag(:dt, title),
9
- content_tag(:dd, value.html_safe)
9
+ content_tag(:dd, value)
10
10
  ]),
11
11
  class: 'ui-descriptive-list__item'
12
12
  )
data/lib/ui/menu/item.rb CHANGED
@@ -24,7 +24,7 @@ module Ui
24
24
  private
25
25
 
26
26
  def render_item
27
- model.html_safe
27
+ model
28
28
  end
29
29
 
30
30
  def depth
@@ -9,7 +9,7 @@ module Ui
9
9
  :ul,
10
10
  render_group([
11
11
  previous_window,
12
- page_links.html_safe,
12
+ page_links,
13
13
  next_window
14
14
  ]),
15
15
  class: 'ui-pagination__window',
@@ -58,15 +58,17 @@ module Ui
58
58
 
59
59
 
60
60
  def page_links
61
- pages.inject('') do |content, page|
62
- content += content_tag(
63
- :li,
64
- cell(
65
- Ui::Pagination::PageLink,
66
- page
67
- ).()
68
- )
69
- end
61
+ render_group(
62
+ pages.map do |page|
63
+ content += content_tag(
64
+ :li,
65
+ cell(
66
+ Ui::Pagination::PageLink,
67
+ page
68
+ ).()
69
+ )
70
+ end
71
+ )
70
72
  end
71
73
 
72
74
  def last_window?
data/lib/ui/table.rb CHANGED
@@ -1,10 +1,21 @@
1
1
  require "ui/table/header"
2
2
  require "ui/table/row"
3
+ require "ui/table/vertical"
3
4
 
4
5
  module Ui
5
6
  class Table < Component
6
7
  include Actionable
7
8
  include Stylable
9
+ include ::Cell::Builder
10
+
11
+ builds do |model, options|
12
+ case options.fetch(:orientation, 'horizontal')
13
+ when 'vertical'
14
+ Ui::Table::Vertical
15
+ else
16
+ self
17
+ end
18
+ end
8
19
 
9
20
  def show
10
21
  render
@@ -22,6 +33,20 @@ module Ui
22
33
  end
23
34
 
24
35
  def table_headers
36
+ custom_header_renderer.is_a?(Proc) ?
37
+ custom_table_headers :
38
+ default_table_headers
39
+ end
40
+
41
+ def custom_table_headers
42
+ render_group(
43
+ columns.map do |column|
44
+ custom_header_renderer.call(column)
45
+ end
46
+ )
47
+ end
48
+
49
+ def default_table_headers
25
50
  content_tag(:tr) do
26
51
  cell(
27
52
  Ui::Table::Header,
@@ -31,31 +56,53 @@ module Ui
31
56
  end
32
57
 
33
58
  def table_rows
34
- if rows.any?
35
- cell(
36
- Ui::Table::Row,
37
- collection: rows,
38
- columns: columns
39
- )
59
+ if model.any?
60
+ custom_row_renderer.is_a?(Proc) ?
61
+ custom_table_rows :
62
+ default_table_rows
40
63
  else
41
64
  render_empty
42
65
  end
43
66
  end
44
67
 
68
+ def custom_table_rows
69
+ render_group(
70
+ model.map do |row|
71
+ custom_row_renderer.call(row, columns)
72
+ end
73
+ )
74
+ end
75
+
76
+ def default_table_rows
77
+ cell(
78
+ Ui::Table::Row,
79
+ collection: model,
80
+ columns: columns
81
+ ).()
82
+ end
83
+
45
84
  def table_data_attributes
46
85
  {
47
86
  controller: table_controllers,
48
- "selectable-selected-value": "[]",
49
- "selectable-type-value": multi_select? ? 'many' : 'one'
50
- }
87
+ }.tap do |hash|
88
+ if selectable?
89
+ hash["selectable-selected-value"] = "[]"
90
+ hash["selectable-type-value"] = multi_select? ? 'many' : 'one'
91
+ end
92
+ end
51
93
  end
52
94
 
53
95
  def table_body_data_attributes
54
96
  {
55
97
  controller: table_body_controllers,
56
- "sortable-update-url-value": sortable_options.fetch(:update_url, '#'),
57
- "sortable-input-name-value": sortable_options.fetch(:input_name, "object[position]")
58
- }
98
+ }.tap do |hash|
99
+ if sortable?
100
+ hash["sortable-update-url-value"] =
101
+ sortable_options.fetch(:update_url, '#')
102
+ hash["sortable-input-name-value"] =
103
+ sortable_options.fetch(:input_name, "object[position]")
104
+ end
105
+ end
59
106
  end
60
107
 
61
108
  def table_controllers
@@ -87,10 +134,6 @@ module Ui
87
134
  ) if options[:footer]
88
135
  end
89
136
 
90
- def component_style
91
- "ui-table"
92
- end
93
-
94
137
  def columns
95
138
  @columns ||= options.fetch(:columns, Array.new).tap do |columns|
96
139
  columns.unshift(selectable_column) if selectable?
@@ -140,8 +183,12 @@ module Ui
140
183
  options.fetch(:features, Hash.new)
141
184
  end
142
185
 
143
- def rows
144
- model
186
+ def custom_row_renderer
187
+ options.fetch(:row_renderer, nil)
188
+ end
189
+
190
+ def custom_header_renderer
191
+ options.fetch(:header_renderer, nil)
145
192
  end
146
193
 
147
194
  def render_empty
@@ -158,5 +205,9 @@ module Ui
158
205
  colspan: columns.size
159
206
  )
160
207
  end
208
+
209
+ def component_style
210
+ "ui-table ui-table--horizontal"
211
+ end
161
212
  end
162
213
  end
@@ -1,20 +1,30 @@
1
1
  module Ui
2
2
  class Table < Component
3
3
  class Header < Component
4
+ include Stylable
5
+
4
6
  def show
5
- content_tag(:th, title)
7
+ content_tag(:th, title, class: style)
6
8
  end
7
9
 
8
10
  private
9
11
 
12
+ def component_style
13
+ 'ui-table__header'
14
+ end
15
+
10
16
  def title
11
17
  case
12
- when model[0].is_a?(Proc)
13
- model[0].call
18
+ when column_title.is_a?(Proc)
19
+ column_title.call
14
20
  else
15
- model[0]
21
+ column_title
16
22
  end
17
23
  end
24
+
25
+ def column_title
26
+ model[0]
27
+ end
18
28
  end
19
29
  end
20
30
  end
data/lib/ui/table/row.rb CHANGED
@@ -1,12 +1,18 @@
1
1
  module Ui
2
2
  class Table < Component
3
3
  class Row < Component
4
+ include Stylable
5
+
4
6
  def show
5
- content_tag(:tr, render_group(table_data))
7
+ content_tag(:tr, render_group(table_data), class: style)
6
8
  end
7
9
 
8
10
  private
9
11
 
12
+ def component_style
13
+ 'ui-table__row'
14
+ end
15
+
10
16
  def table_data
11
17
  columns.map do |column|
12
18
  content_tag(:td, apply(column))
@@ -0,0 +1,45 @@
1
+ module Ui
2
+ class Table < Component
3
+ class Vertical < Table
4
+
5
+ private
6
+
7
+ def table_rows
8
+ if model.any?
9
+ cell(
10
+ row_renderer,
11
+ collection: columns[1..-1],
12
+ data: model
13
+ )
14
+ else
15
+ render_empty
16
+ end
17
+ end
18
+
19
+ def table_headers
20
+ content_tag(:tr) do
21
+ render_group([
22
+ content_tag(:th, columns[0].try(:first)),
23
+ cell(
24
+ header_renderer,
25
+ collection: model,
26
+ column: columns[0],
27
+ )
28
+ ])
29
+ end
30
+ end
31
+
32
+ def row_renderer
33
+ Ui::Table::Vertical::Row
34
+ end
35
+
36
+ def header_renderer
37
+ Ui::Table::Vertical::Header
38
+ end
39
+
40
+ def component_style
41
+ "ui-table ui-table--vertical"
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,26 @@
1
+ module Ui
2
+ class Table < Component
3
+ class Vertical < Table
4
+ class Header < Ui::Table::Header
5
+ def show
6
+ content_tag(:th, title)
7
+ end
8
+
9
+ private
10
+
11
+ def title
12
+ case
13
+ when column[1].is_a?(Proc)
14
+ column[1].call(model)
15
+ else
16
+ model.to_s
17
+ end
18
+ end
19
+
20
+ def column
21
+ options[:column]
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,34 @@
1
+ module Ui
2
+ class Table < Component
3
+ class Vertical < Table
4
+ class Row < Ui::Table::Row
5
+
6
+ private
7
+
8
+ def table_data
9
+ data.map do |item|
10
+ content_tag(:td, apply(item))
11
+ end.tap do |array|
12
+ array.unshift(content_tag(:th, column_title))
13
+ end
14
+ end
15
+
16
+ def apply(item)
17
+ column[1].call(item)
18
+ end
19
+
20
+ def column
21
+ model
22
+ end
23
+
24
+ def column_title
25
+ column[0]
26
+ end
27
+
28
+ def data
29
+ options.fetch(:data, Array.new)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
data/lib/ui/types.rb CHANGED
@@ -3,5 +3,7 @@ require 'dry-types'
3
3
  module Ui
4
4
  module Types
5
5
  include Dry.Types()
6
+
7
+ Callable = Types.Interface(:call)
6
8
  end
7
9
  end
data/lib/ui/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ui
2
- VERSION = '0.2.14'
2
+ VERSION = '0.2.15'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: organism-ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
4
+ version: 0.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nolan Tait
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-20 00:00:00.000000000 Z
11
+ date: 2021-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -245,6 +245,9 @@ files:
245
245
  - lib/ui/table/select_all.rb
246
246
  - lib/ui/table/show.erb
247
247
  - lib/ui/table/sort.rb
248
+ - lib/ui/table/vertical.rb
249
+ - lib/ui/table/vertical/header.rb
250
+ - lib/ui/table/vertical/row.rb
248
251
  - lib/ui/tooltip.rb
249
252
  - lib/ui/tooltip/show.erb
250
253
  - lib/ui/types.rb