organism-ui 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +35 -0
  5. data/app/assets/config/ui_manifest.js +1 -0
  6. data/app/assets/stylesheets/ui/application.css +15 -0
  7. data/app/controllers/ui/application_controller.rb +7 -0
  8. data/app/controllers/ui/style_guide_controller.rb +8 -0
  9. data/app/helpers/ui/application_helper.rb +4 -0
  10. data/app/javascript/ui/application.js +1 -0
  11. data/app/jobs/ui/application_job.rb +4 -0
  12. data/app/mailers/ui/application_mailer.rb +6 -0
  13. data/app/models/ui/application_record.rb +5 -0
  14. data/app/views/ui/style_guide/show.html.erb +1035 -0
  15. data/config/routes.rb +3 -0
  16. data/lib/tasks/ui_tasks.rake +4 -0
  17. data/lib/ui.rb +64 -0
  18. data/lib/ui/actionable.rb +19 -0
  19. data/lib/ui/breadcrumbs.rb +31 -0
  20. data/lib/ui/breadcrumbs/breadcrumb.rb +36 -0
  21. data/lib/ui/breadcrumbs/crumb.rb +15 -0
  22. data/lib/ui/buttons/base.rb +146 -0
  23. data/lib/ui/buttons/primary.rb +11 -0
  24. data/lib/ui/buttons/secondary.rb +11 -0
  25. data/lib/ui/buttons/tertiary.rb +11 -0
  26. data/lib/ui/card.rb +36 -0
  27. data/lib/ui/card/show.erb +16 -0
  28. data/lib/ui/collapse.rb +24 -0
  29. data/lib/ui/collapse/panel.rb +37 -0
  30. data/lib/ui/collapse/panel/show.erb +16 -0
  31. data/lib/ui/component.rb +23 -0
  32. data/lib/ui/descriptive_list.rb +50 -0
  33. data/lib/ui/descriptive_list/item.rb +24 -0
  34. data/lib/ui/descriptive_list/show.erb +7 -0
  35. data/lib/ui/dropdown.rb +22 -0
  36. data/lib/ui/dropdown/show.erb +13 -0
  37. data/lib/ui/empty.rb +36 -0
  38. data/lib/ui/empty/show.erb +11 -0
  39. data/lib/ui/engine.rb +13 -0
  40. data/lib/ui/list.rb +77 -0
  41. data/lib/ui/list/item.rb +9 -0
  42. data/lib/ui/list/show.erb +5 -0
  43. data/lib/ui/menu.rb +29 -0
  44. data/lib/ui/menu/callable.rb +11 -0
  45. data/lib/ui/menu/item.rb +39 -0
  46. data/lib/ui/menu/show.erb +4 -0
  47. data/lib/ui/menu/submenu.rb +55 -0
  48. data/lib/ui/notification.rb +37 -0
  49. data/lib/ui/notification/show.erb +19 -0
  50. data/lib/ui/page_header.rb +29 -0
  51. data/lib/ui/page_header/show.erb +18 -0
  52. data/lib/ui/pagination.rb +105 -0
  53. data/lib/ui/pagination/page_link.rb +24 -0
  54. data/lib/ui/pagination/show.erb +11 -0
  55. data/lib/ui/pagination/window.rb +85 -0
  56. data/lib/ui/step.rb +57 -0
  57. data/lib/ui/step/show.erb +13 -0
  58. data/lib/ui/steps.rb +67 -0
  59. data/lib/ui/steps/show.erb +5 -0
  60. data/lib/ui/stylable.rb +21 -0
  61. data/lib/ui/table.rb +162 -0
  62. data/lib/ui/table/header.rb +20 -0
  63. data/lib/ui/table/row.rb +25 -0
  64. data/lib/ui/table/select.rb +16 -0
  65. data/lib/ui/table/select/many.rb +38 -0
  66. data/lib/ui/table/select/one.rb +38 -0
  67. data/lib/ui/table/select_all.rb +36 -0
  68. data/lib/ui/table/show.erb +5 -0
  69. data/lib/ui/table/sort.rb +19 -0
  70. data/lib/ui/tooltip.rb +35 -0
  71. data/lib/ui/tooltip/show.erb +14 -0
  72. data/lib/ui/types.rb +7 -0
  73. data/lib/ui/value.rb +4 -0
  74. data/lib/ui/version.rb +3 -0
  75. data/lib/ui/wizard.rb +87 -0
  76. data/lib/ui/wizard/content.rb +20 -0
  77. data/lib/ui/wizard/show.erb +10 -0
  78. metadata +265 -0
@@ -0,0 +1,13 @@
1
+ <article
2
+ data-wizard-target="step"
3
+ data-position="<%= position %>"
4
+ class="<%= style %>">
5
+ <%= render_icon %>
6
+
7
+ <header class="ui-step__header">
8
+ <%= title %>
9
+ <%= subtitle %>
10
+ </header>
11
+
12
+ <%= description %>
13
+ </article>
data/lib/ui/steps.rb ADDED
@@ -0,0 +1,67 @@
1
+ module Ui
2
+ class Steps < Component
3
+ include Stylable
4
+
5
+ class Step < Value
6
+ attribute :position, Types::Strict::Integer
7
+ attribute :title, Types::Strict::String
8
+ attribute? :icon, Types::Strict::String.default(''.freeze)
9
+ attribute? :current, Types::Strict::Bool.default(false.freeze)
10
+ attribute? :last, Types::Strict::Bool.default(false.freeze)
11
+ attribute? :description, Types::Strict::String.default(''.freeze)
12
+ attribute? :subtitle, Types::Strict::String.default(''.freeze)
13
+ attribute? :status, Types::String.default('waiting'.freeze).enum(
14
+ 'finished',
15
+ 'processing',
16
+ 'waiting',
17
+ 'error'
18
+ )
19
+
20
+ def last?
21
+ last
22
+ end
23
+
24
+ def current?
25
+ current
26
+ end
27
+ end
28
+
29
+ def show
30
+ render
31
+ end
32
+
33
+ private
34
+
35
+ def render_steps
36
+ cell(
37
+ Ui::Step,
38
+ collection: steps,
39
+ current_step: current_step
40
+ )
41
+ end
42
+
43
+ def steps
44
+ model.map.with_index do |step, index|
45
+ Step.new(step.merge({
46
+ current: current_step == index + 1,
47
+ last: model.size == index + 1,
48
+ position: index + 1
49
+ }))
50
+ end
51
+ end
52
+
53
+ def component_style
54
+ ["ui-steps"].tap do |styles|
55
+ styles << "ui-steps--#{direction}"
56
+ end
57
+ end
58
+
59
+ def current_step
60
+ options.fetch(:current_step, 1)
61
+ end
62
+
63
+ def direction
64
+ options.fetch(:direction, 'horizontal')
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,5 @@
1
+ <nav class="<%= style %>">
2
+ <ul>
3
+ <%= render_steps %>
4
+ </ul>
5
+ </nav>
@@ -0,0 +1,21 @@
1
+ module Ui
2
+ module Stylable
3
+
4
+ private
5
+
6
+ def user_defined_style
7
+ options.fetch(:style, '')
8
+ end
9
+
10
+ def style
11
+ [
12
+ user_defined_style,
13
+ component_style
14
+ ].join(' ')
15
+ end
16
+
17
+ def component_style
18
+ raise NotImplementedError
19
+ end
20
+ end
21
+ end
data/lib/ui/table.rb ADDED
@@ -0,0 +1,162 @@
1
+ require "ui/table/header"
2
+ require "ui/table/row"
3
+
4
+ module Ui
5
+ class Table < Component
6
+ include Actionable
7
+ include Stylable
8
+
9
+ def show
10
+ render
11
+ end
12
+
13
+ private
14
+
15
+ def table
16
+ content_tag(:table, data: table_data_attributes) do
17
+ render_group([
18
+ content_tag(:thead, table_headers),
19
+ content_tag(:tbody, table_rows, data: table_body_data_attributes)
20
+ ])
21
+ end
22
+ end
23
+
24
+ def table_headers
25
+ content_tag(:tr) do
26
+ cell(
27
+ Ui::Table::Header,
28
+ collection: columns
29
+ ).()
30
+ end
31
+ end
32
+
33
+ def table_rows
34
+ if rows.any?
35
+ cell(
36
+ Ui::Table::Row,
37
+ collection: rows,
38
+ columns: columns
39
+ )
40
+ else
41
+ render_empty
42
+ end
43
+ end
44
+
45
+ def table_data_attributes
46
+ {
47
+ controller: table_controllers,
48
+ "selectable-selected-value": "[]",
49
+ "selectable-type-value": multi_select? ? 'many' : 'one'
50
+ }
51
+ end
52
+
53
+ def table_body_data_attributes
54
+ {
55
+ 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
+ }
59
+ end
60
+
61
+ def table_controllers
62
+ [].tap do |array|
63
+ array << "selectable" if selectable?
64
+ end.join(' ')
65
+ end
66
+
67
+ def table_body_controllers
68
+ [].tap do |array|
69
+ array << "sortable" if sortable?
70
+ end.join(' ')
71
+ end
72
+
73
+ def header
74
+ content_tag(
75
+ :header,
76
+ render_group([
77
+ options[:header],
78
+ actions
79
+ ])
80
+ ) if options[:header] || has_actions?
81
+ end
82
+
83
+ def footer
84
+ content_tag(
85
+ :footer,
86
+ options[:footer]
87
+ ) if options[:footer]
88
+ end
89
+
90
+ def component_style
91
+ "ui-table"
92
+ end
93
+
94
+ def columns
95
+ @columns ||= options.fetch(:columns, Array.new).tap do |columns|
96
+ columns.unshift(selectable_column) if selectable?
97
+ columns.unshift(sortable_column) if sortable?
98
+ end
99
+ end
100
+
101
+ def selectable_column
102
+ [
103
+ ->() { select_all },
104
+ ->(data) { cell(Ui::Table::Select, data, selectable_options) }
105
+ ]
106
+ end
107
+
108
+ def sortable_column
109
+ [
110
+ ->() { nil },
111
+ ->(data) { cell(Ui::Table::Sort, data, sortable_options) }
112
+ ]
113
+ end
114
+
115
+ def selectable?
116
+ features.keys.include? :selectable
117
+ end
118
+
119
+ def sortable?
120
+ features.keys.include? :sortable
121
+ end
122
+
123
+ def select_all
124
+ cell(Ui::Table::SelectAll, nil) if multi_select?
125
+ end
126
+
127
+ def multi_select?
128
+ selectable_options.fetch(:multiple, false)
129
+ end
130
+
131
+ def selectable_options
132
+ features.fetch(:selectable, {})
133
+ end
134
+
135
+ def sortable_options
136
+ features.fetch(:sortable, {})
137
+ end
138
+
139
+ def features
140
+ options.fetch(:features, Hash.new)
141
+ end
142
+
143
+ def rows
144
+ model
145
+ end
146
+
147
+ def render_empty
148
+ content_tag(:tr, empty)
149
+ end
150
+
151
+ def empty
152
+ content_tag(
153
+ :td,
154
+ cell(
155
+ Ui::Empty,
156
+ nil,
157
+ ).(),
158
+ colspan: columns.size
159
+ )
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,20 @@
1
+ module Ui
2
+ class Table < Component
3
+ class Header < Component
4
+ def show
5
+ content_tag(:th, title)
6
+ end
7
+
8
+ private
9
+
10
+ def title
11
+ case
12
+ when model[0].is_a?(Proc)
13
+ model[0].call
14
+ else
15
+ model[0]
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ module Ui
2
+ class Table < Component
3
+ class Row < Component
4
+ def show
5
+ content_tag(:tr, render_group(table_data))
6
+ end
7
+
8
+ private
9
+
10
+ def table_data
11
+ columns.map do |column|
12
+ content_tag(:td, apply(column))
13
+ end
14
+ end
15
+
16
+ def apply(column)
17
+ column[1].call(model)
18
+ end
19
+
20
+ def columns
21
+ options.fetch(:columns, Array.new)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ require "ui/table/select/one"
2
+ require "ui/table/select/many"
3
+
4
+ module Ui
5
+ class Table < Component
6
+ class Select < Component
7
+ include ::Cell::Builder
8
+
9
+ builds do |model, options|
10
+ options.fetch(:multiple, false) ?
11
+ Ui::Table::Select::Many :
12
+ Ui::Table::Select::One
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,38 @@
1
+ module Ui
2
+ class Table < Component
3
+ class Select < Component
4
+ class Many < Component
5
+ def show
6
+ check_box_tag(
7
+ name,
8
+ value,
9
+ selected,
10
+ disabled: disabled,
11
+ data: {
12
+ "selectable-target": "input",
13
+ action: "click->selectable#select"
14
+ }
15
+ )
16
+ end
17
+
18
+ private
19
+
20
+ def name
21
+ "row[selected]"
22
+ end
23
+
24
+ def value
25
+ model
26
+ end
27
+
28
+ def selected
29
+ options.fetch(:selected, false)
30
+ end
31
+
32
+ def disabled
33
+ options.fetch(:disabled, false)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ module Ui
2
+ class Table < Component
3
+ class Select < Component
4
+ class One < Component
5
+ def show
6
+ radio_button_tag(
7
+ name,
8
+ value,
9
+ selected,
10
+ disabled: disabled,
11
+ data: {
12
+ "selectable-target": "input",
13
+ action: "click->selectable#select"
14
+ }
15
+ )
16
+ end
17
+
18
+ private
19
+
20
+ def name
21
+ "row[selected]"
22
+ end
23
+
24
+ def value
25
+ model
26
+ end
27
+
28
+ def selected
29
+ options.fetch(:selected, false)
30
+ end
31
+
32
+ def disabled
33
+ options.fetch(:disabled, false)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,36 @@
1
+ module Ui
2
+ class Table < Component
3
+ class SelectAll < Component
4
+ def show
5
+ check_box_tag(
6
+ name,
7
+ value,
8
+ selected,
9
+ disabled: disabled,
10
+ data: {
11
+ "selectable-target": "selectAll",
12
+ action: "click->selectable#selectAll"
13
+ }
14
+ )
15
+ end
16
+
17
+ private
18
+
19
+ def name
20
+ "row[selected]"
21
+ end
22
+
23
+ def value
24
+ ""
25
+ end
26
+
27
+ def selected
28
+ options.fetch(:selected, false)
29
+ end
30
+
31
+ def disabled
32
+ options.fetch(:disabled, false)
33
+ end
34
+ end
35
+ end
36
+ end