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
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Ui::Engine.routes.draw do
2
+ resource :style_guide, only: [:show], controller: 'style_guide'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :ui do
3
+ # # Task goes here
4
+ # end
data/lib/ui.rb ADDED
@@ -0,0 +1,64 @@
1
+ require "ui/engine"
2
+ require "cells"
3
+ require "cells-erb"
4
+ require "cells-rails"
5
+ require 'dry-struct'
6
+
7
+ require "ui/types"
8
+ require "ui/value"
9
+
10
+ require "ui/actionable"
11
+ require "ui/stylable"
12
+ require "ui/component"
13
+
14
+ require "ui/buttons/base"
15
+ require "ui/buttons/primary"
16
+ require "ui/buttons/secondary"
17
+ require "ui/buttons/tertiary"
18
+
19
+ require "ui/breadcrumbs"
20
+ require "ui/breadcrumbs/crumb"
21
+ require 'ui/breadcrumbs/breadcrumb'
22
+
23
+ require "ui/page_header"
24
+
25
+ require "ui/menu"
26
+ require "ui/menu/item"
27
+ require "ui/menu/callable"
28
+ require "ui/menu/submenu"
29
+
30
+ require "ui/dropdown"
31
+
32
+ require "ui/pagination"
33
+ require "ui/pagination/page_link"
34
+ require "ui/pagination/window"
35
+
36
+ require "ui/steps"
37
+ require "ui/step"
38
+
39
+ require "ui/wizard"
40
+ require "ui/wizard/content"
41
+
42
+ require "ui/card"
43
+
44
+ require "ui/descriptive_list"
45
+ require "ui/descriptive_list/item"
46
+
47
+ require "ui/empty"
48
+
49
+ require "ui/list"
50
+ require "ui/list/item"
51
+
52
+ require "ui/table"
53
+ require "ui/table/select_all"
54
+ require "ui/table/select"
55
+ require "ui/table/sort"
56
+
57
+ require "ui/collapse"
58
+
59
+ require "ui/tooltip"
60
+
61
+ require "ui/notification"
62
+
63
+ module Ui
64
+ end
@@ -0,0 +1,19 @@
1
+ module Ui
2
+ module Actionable
3
+ def actions
4
+ render_group(
5
+ options.fetch(:actions, Array.new).map do |action|
6
+ action.call(model)
7
+ end
8
+ )
9
+ end
10
+
11
+ def actions_length
12
+ options.fetch(:actions, Array.new).size
13
+ end
14
+
15
+ def has_actions?
16
+ options.fetch(:actions, []).any?
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ module Ui
2
+ class Breadcrumbs < Component
3
+ def show
4
+ content_tag(:nav, class: 'ui-breadcrumbs') do
5
+ breadcrumb_links
6
+ end
7
+ end
8
+
9
+ private
10
+
11
+ def breadcrumbs
12
+ Types::Array.of(Crumb)[model]
13
+ end
14
+
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
21
+ end
22
+
23
+ def delimiter
24
+ options[:delimiter] || content_tag(:span, '>', class: 'breadcrumb-delimiter')
25
+ end
26
+
27
+ def item_renderer
28
+ options[:item_renderer] || Ui::Breadcrumbs::Breadcrumb
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ module Ui
2
+ class Breadcrumbs < Component
3
+ class Breadcrumb < Component
4
+ property :name
5
+ property :path
6
+ property :current?
7
+ property :icon
8
+
9
+ def show
10
+ content_tag(
11
+ :span,
12
+ link_to(path) do
13
+ title.html_safe
14
+ end,
15
+ class: style
16
+ )
17
+ end
18
+
19
+ private
20
+
21
+ def title
22
+ [name].tap do |array|
23
+ array.unshift(content_tag(:i, nil, class: icon)) if model.try(:icon)
24
+ end.join(' ')
25
+ end
26
+
27
+ def style
28
+ [
29
+ 'breadcrumb'
30
+ ].tap do |array|
31
+ array << 'breadcrumb--current' if current?
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,15 @@
1
+ module Ui
2
+ class Breadcrumbs
3
+ class Crumb < Dry::Struct
4
+ attribute :name, Types::Strict::String
5
+ attribute :path, Types::Strict::String.default('#'.freeze)
6
+ attribute :current, Types::Strict::Bool.default(false.freeze)
7
+ attribute :icon, Types::Strict::String.default(''.freeze)
8
+
9
+ def current?
10
+ current
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,146 @@
1
+ module Ui
2
+ module Buttons
3
+ class Base < Component
4
+ def show
5
+ display(
6
+ text_with_icon(icon),
7
+ path,
8
+ button_options,
9
+ )
10
+ end
11
+
12
+ def new
13
+ display(
14
+ text_with_icon(new_icon),
15
+ path,
16
+ button_options
17
+ )
18
+ end
19
+
20
+ def edit
21
+ display(
22
+ text_with_icon(edit_icon),
23
+ path,
24
+ button_options
25
+ )
26
+ end
27
+
28
+ def destroy
29
+ display(
30
+ text_with_icon(destroy_icon),
31
+ path,
32
+ button_options.merge({
33
+ method: :delete,
34
+ data: {
35
+ confirm: 'Are you sure?'
36
+ }
37
+ }),
38
+ )
39
+ end
40
+
41
+ private
42
+
43
+ def display(*args)
44
+ if disabled?
45
+ content_tag(
46
+ :button,
47
+ args.first,
48
+ disabled: true,
49
+ class: button_classes
50
+ )
51
+ else
52
+ if path == '#'
53
+ content_tag(:button, args.first, **args.last)
54
+ else
55
+ link_to(*args)
56
+ end
57
+ end
58
+ end
59
+
60
+ def new_icon
61
+ 'fas fa-plus'
62
+ end
63
+
64
+ def edit_icon
65
+ 'fas fa-edit'
66
+ end
67
+
68
+ def destroy_icon
69
+ 'fas fa-trash'
70
+ end
71
+
72
+ def button_classes
73
+ [
74
+ "button",
75
+ style,
76
+ size,
77
+ options.fetch(:style, '')
78
+ ].compact.join(' ')
79
+ end
80
+
81
+ def size
82
+ case options[:size]
83
+ when :small
84
+ 'button--small'
85
+ else
86
+ ''
87
+ end
88
+ end
89
+
90
+ def text
91
+ content_tag(:span, model) unless model.nil?
92
+ end
93
+
94
+ 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
105
+ end
106
+ end
107
+
108
+ def style
109
+ ''
110
+ end
111
+
112
+ def icon
113
+ options[:icon]
114
+ end
115
+
116
+ def path
117
+ options[:path] || '#'
118
+ end
119
+
120
+ def data
121
+ options[:data] || {}
122
+ end
123
+
124
+ def target
125
+ options[:target]
126
+ end
127
+
128
+ def method
129
+ options[:method] || :get
130
+ end
131
+
132
+ def disabled?
133
+ options[:disabled]
134
+ end
135
+
136
+ def button_options
137
+ {
138
+ class: button_classes,
139
+ disabled: disabled?,
140
+ data: data,
141
+ method: method
142
+ }
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,11 @@
1
+ module Ui
2
+ module Buttons
3
+ class Primary < Base
4
+ private
5
+
6
+ def style
7
+ 'button--primary'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Ui
2
+ module Buttons
3
+ class Secondary < Base
4
+ private
5
+
6
+ def style
7
+ 'button--secondary'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Ui
2
+ module Buttons
3
+ class Tertiary < Base
4
+ private
5
+
6
+ def style
7
+ 'button--tertiary'
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/ui/card.rb ADDED
@@ -0,0 +1,36 @@
1
+ module Ui
2
+ class Card < Component
3
+ include Actionable
4
+ include Stylable
5
+
6
+ def show(&block)
7
+ render(&block)
8
+ end
9
+
10
+ private
11
+
12
+ def cover
13
+ content_tag(:figure, class: 'ui-card__cover') do
14
+ image_tag(options[:cover])
15
+ end if options[:cover]
16
+ end
17
+
18
+ def card_actions
19
+ content_tag(:nav, class: "ui-card__controls") do
20
+ actions
21
+ end if has_actions?
22
+ end
23
+
24
+ def title
25
+ model
26
+ end
27
+
28
+ def extra
29
+ options[:extra]
30
+ end
31
+
32
+ def component_style
33
+ "ui-card"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,16 @@
1
+ <article class="<%= style %>">
2
+ <%= cover %>
3
+
4
+ <% if title || extra %>
5
+ <header class="ui-card__header">
6
+ <%= title %>
7
+ <%= extra %>
8
+ </header>
9
+ <% end %>
10
+
11
+ <section class="ui-card__content">
12
+ <%= yield %>
13
+ </section>
14
+
15
+ <%= card_actions %>
16
+ </article>
@@ -0,0 +1,24 @@
1
+ require "ui/collapse/panel"
2
+
3
+ module Ui
4
+ class Collapse < Component
5
+ include Stylable
6
+
7
+ def show
8
+ content_tag(:ul, panels, class: style)
9
+ end
10
+
11
+ private
12
+
13
+ def panels
14
+ cell(
15
+ Ui::Collapse::Panel,
16
+ collection: model
17
+ ).()
18
+ end
19
+
20
+ def component_style
21
+ "ui-collapse"
22
+ end
23
+ end
24
+ end