nfg_ui 0.9.8.17 → 0.9.8.18

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: 3b85f443237f204368e6f3dd6fd5b749cc7f6a5ab17d10a7c508c6b4a81a12d6
4
- data.tar.gz: d2cd103b34f4980a6cb1af31689e84a05d5ee9c1b10495c4549f2c786f17c4a3
3
+ metadata.gz: 0f540ed4257fe4de0037fc5de979e560d0b5625687de36ed13a43bf9ae2bfe01
4
+ data.tar.gz: e718cb003e1ffcdd1db29dcfa93515dc07099843b369c60c6ef89f5c366c30dd
5
5
  SHA512:
6
- metadata.gz: 306eac19ce4097d139be9d8312425a9f6226b456e893ae746837472f3abb8ec002f0f00a571df3df779250097c2766f7b41c36bbf9618fa0f15d699b6cf10b17
7
- data.tar.gz: 7b696ef0b1ff08185adf93a21c1cdaa8ea0ff51c9211dfe5419f7cc3597fd1252a6817ec3cd4874c88f9df383d0a1075a063a7c712f3e6fadd76fb2bad8b7cbe
6
+ metadata.gz: 2131c8f600c03eac815811d706e4be84be703f331ebab52d1727c8e7af55e969b0ba88c324ad3cdfa272f9c43b4e9f5c80b376537c211797ea94a32c79394063
7
+ data.tar.gz: 0a04d17b0116d9ab759ef03ff0452221e5171d5d291500b2adce2e64b37c9d5424ef9c39c86fdb9e8199986e48288570f1e7f098c48f2f5ad3e46f121a9ac9ed
@@ -24,14 +24,13 @@
24
24
  flex-grow: 2;
25
25
 
26
26
  // Sizing options
27
- &.slat-item-sm { flex-grow: 0; }
27
+ &.slat-item-sm { flex-grow: 1; }
28
28
  &.slat-item-lg { flex-grow: 6; }
29
29
  }
30
30
  }
31
31
  }
32
32
 
33
33
 
34
-
35
34
  // Action Column
36
35
  .slat-actions {
37
36
  padding-left: ($grid-gutter-width * .5);
@@ -21,7 +21,7 @@
21
21
  -ms-flex-positive: 2;
22
22
 
23
23
  // Sizing options
24
- &.slat-item-sm { -ms-flex-positive: 0; }
24
+ &.slat-item-sm { -ms-flex-positive: 1; }
25
25
  &.slat-item-lg { -ms-flex-positive: 6; }
26
26
  }
27
27
  }
@@ -24,7 +24,7 @@
24
24
  flex-grow: 2;
25
25
 
26
26
  // Sizing options
27
- &.slat-item-sm { flex-grow: 0; }
27
+ &.slat-item-sm { flex-grow: 1; }
28
28
  &.slat-item-lg { flex-grow: 6; }
29
29
  }
30
30
  }
@@ -54,7 +54,7 @@ module NfgUi
54
54
  end
55
55
 
56
56
  def html_options
57
- options.except(*non_html_attribute_options)
57
+ options.except(*non_html_attribute_options.uniq)
58
58
  .merge!(id: id,
59
59
  class: css_classes,
60
60
  data: data,
@@ -122,7 +122,7 @@ module NfgUi
122
122
  # adding a new string of css classes to this method
123
123
  # ex: super.push('new-class')
124
124
  def css_classes
125
- @css_classes ||= [component_css_class, options[:class]].join(' ').squish
125
+ @css_classes ||= [component_css_class, options[:class]].reject(&:nil?).uniq.join(' ').squish
126
126
  end
127
127
 
128
128
  def defaults
@@ -5,63 +5,48 @@ module NfgUi
5
5
  module Patterns
6
6
  # Slat doc coming soon
7
7
  class SlatActions < NfgUi::Components::Base
8
- include NfgUi::Components::Utilities::Iconable
9
-
10
- include NfgUi::Components::Traits::Theme
8
+ # Includes a workaround suite of functionality
9
+ # to integrate a singular SlatAction automatically when
10
+ # The SlatActions component is rendered when the `:menu` option is set to false.
11
+ #
12
+ # When menu is set to false:
13
+ # You can then pass in SlatAction options in the parent SlatAction
14
+ #
15
+ # Example usage:
16
+ # ui.nfg(:slat_actions, menu: false, theme: :parent, body: 'My Custom Slat Action')
17
+ # require 'nfg_ui/components/utilities/patches/integrated_slat_action'
18
+ include NfgUi::Components::Utilities::Patches::IntegratedSlatAction
11
19
 
12
20
  def component_family
13
21
  :slats
14
22
  end
15
23
 
24
+ # Signals whether or not this SlatActions will house a menu
25
+ # This is a critical condition.
26
+ # When false, a SlatAction is automatically integrated on your behalf.
16
27
  def menu
17
28
  options.fetch(:menu, true)
18
29
  end
19
30
 
20
- def confirm
21
- options.fetch(:confirm, nil)
22
- end
23
-
24
- def method
25
- return if delete_link?
26
- options.fetch(:method, nil)
27
- end
28
-
29
- def delete_link?
30
- @delete_link ||= options.fetch(:method, nil) == :delete
31
- end
32
-
31
+ # Signal if this slat_action is being used
32
+ # In the slat_header area of the Slats
33
+ #
34
+ # If so, this then customizes the output of the
35
+ # SlatActions to ensure that the widths of the slat_header columns
36
+ # is accurate and matches the width of the slats below.
33
37
  def slat_header
34
38
  options.fetch(:slat_header, false)
35
39
  end
36
40
 
41
+ # Signals if this is a wide SlatActions.
42
+ # This is a stylistic update which is used in situations like shopping carts where
43
+ # you may only be providing a summary and have no actions or extra columns.
44
+ #
45
+ # Note: Further documentation is needed on this
37
46
  def wide
38
47
  options.fetch(:wide, true)
39
48
  end
40
49
 
41
- def disable_with
42
- options.fetch(:disable_with, nil)
43
- end
44
-
45
- def remote
46
- options.fetch(:remote, nil)
47
- end
48
-
49
- def action_link_html_options
50
- { href: href,
51
- class: [
52
- (theme ? "text-#{theme}" : ''),
53
- 'd-block'
54
- ].join(' ').squish,
55
- method: send(:method),
56
- remote: remote,
57
- data: { disable_with: disable_with,
58
- confirm: confirm }.merge(delete_link? ? { method: :delete } : {}) }
59
- end
60
-
61
- def theme
62
- options.fetch(:theme, nil)
63
- end
64
-
65
50
  def render
66
51
  content_tag(:div, html_options) do
67
52
  if menu
@@ -70,7 +55,7 @@ module NfgUi
70
55
  else
71
56
  NfgUi::Components::Patterns::Dropdown.new({ }, view_context).render do
72
57
  capture do
73
- concat(NfgUi::Components::Elements::DropdownToggle.new({ traits: [:outlined, :secondary], body: ('Actions' if wide)}, view_context).render)
58
+ concat(NfgUi::Components::Elements::DropdownToggle.new({ **default_dropdown_toggle_options, body: ('Actions' if wide)}, view_context).render)
74
59
  concat(NfgUi::Components::Patterns::DropdownMenu.new({ traits: [:right] }, view_context).render {
75
60
  (block_given? ? yield : body)
76
61
  })
@@ -78,27 +63,19 @@ module NfgUi
78
63
  end
79
64
  end
80
65
  else
81
- if href.present?
82
- content_tag(:a, href: href, **action_link_html_options) do
83
- if icon
84
- NfgUi::Components::Foundations::Icon.new({ traits: [icon], text: (block_given? ? yield : body), theme: theme }, view_context).render
85
- else
86
- (block_given? ? yield : body)
87
- end
88
- end
89
- else
90
- if icon
91
- NfgUi::Components::Foundations::Icon.new({ traits: [icon], text: (block_given? ? yield : body), theme: theme }, view_context).render
92
- else
93
- (block_given? ? yield : body)
94
- end
95
- end
66
+ # Render the integrated slat action and pass in all of the
67
+ # related slat action options that are present in this SlatActions `:options`
68
+ render_integrated_slat_action
96
69
  end
97
70
  end
98
71
  end
99
72
 
100
73
  private
101
74
 
75
+ def default_dropdown_toggle_options
76
+ { outlined: true, theme: :secondary }
77
+ end
78
+
102
79
  def css_classes
103
80
  [
104
81
  super,
@@ -107,7 +84,7 @@ module NfgUi
107
84
  end
108
85
 
109
86
  def non_html_attribute_options
110
- super.push(:slat_header, :wide, :menu, :theme, :method, :remote, :confirm, :disable_with)
87
+ super.push(:slat_header, :wide, :menu)
111
88
  end
112
89
  end
113
90
  end
@@ -5,17 +5,20 @@ module NfgUi
5
5
  module Traits
6
6
  # Access to pre-designed theme traits
7
7
  module Theme
8
- # TODO: Figure out how to get NfgUi::BOOTSTRAP_THEMES to be recognized for TRAITS
9
- TRAITS = %i[primary
10
- secondary
11
- success
12
- danger
13
- warning
14
- info
15
- light
16
- dark
17
- white
18
- outlined].freeze
8
+ COLOR_TRAITS = %i[primary
9
+ secondary
10
+ success
11
+ danger
12
+ warning
13
+ info
14
+ light
15
+ dark
16
+ white]
17
+
18
+ TRAITS = [*COLOR_TRAITS,
19
+ :outlined].freeze
20
+
21
+
19
22
 
20
23
  def primary_trait
21
24
  options[:theme] = :primary
@@ -0,0 +1,215 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This module should be removed upon re-evaluation of Slat components.
4
+ module NfgUi
5
+ module Components
6
+ module Utilities
7
+ module Patches
8
+ # Terminology:
9
+ # SlatAction - is the equivalent of a dropdown menu item
10
+ # SlatActions - is the parent / wrapping component of the SlatAction(s)
11
+ #
12
+ # and... Integrated Slat Action essentially replaces a dropdown toggle & dropdown menu with either a text link or a button component.
13
+ #
14
+ # Usage: When you are creating a slat that does not need a menu but has a singular action link
15
+ # For example: when the only option you have on a slat is to delete that item.
16
+ #
17
+ # This module allows you to pass in options that will
18
+ # automatically generate a slat action for you
19
+ # ... without having to manually add a slat_action to your code.
20
+ #
21
+ # Example usage:
22
+ # = ui.nfg :slat_actions, menu: false, icon: 'trash', body: 'Delete', href: '#nogo'
23
+ #
24
+ # The above will automatically generate a slat action so you
25
+ # do not need to add a slat action in the slat_actions (note: plural slat_actions)
26
+ #
27
+ # This is a monkeypatch while we re-evaluate the Slat component suite
28
+ # so as not to break existing code implementation on our apps.
29
+ module IntegratedSlatAction
30
+ # Allows for icons to be passed into the integrated slat action component
31
+ include NfgUi::Components::Utilities::Iconable
32
+
33
+ # Allows for using theme traits on the slat action component
34
+ # that is then passed through to the integrated slat action.
35
+ include NfgUi::Components::Traits::Theme
36
+
37
+ # This sets whether or not the SlatAction is a button.
38
+ # If it's not a button, the integrated slat action
39
+ # is rendered via a content_tag as a normal link.
40
+ #
41
+ # If it is a button, the integrated slat action
42
+ # is rendered as a button component
43
+ # (NfgUi::Components::Elements::Button)
44
+ def button
45
+ options.fetch(:button, false)
46
+ end
47
+
48
+ # Passes in the rails confirm option to the slat action component.
49
+ # Rails example: link_to 'Delete', ..., confirm: 'Are you sure?'
50
+ def confirm
51
+ options.fetch(:confirm, nil)
52
+ end
53
+
54
+ # Passes the :disable_with option, when present, to the
55
+ # integrated slat action component -- this adds the rails disable_with
56
+ # Rails example: link_to 'Delete', ..., disable_with: 'Deleting...'
57
+ def disable_with
58
+ options.fetch(:disable_with, nil)
59
+ end
60
+
61
+ # Sets a fallback for href so that
62
+ # integrated action items are still
63
+ # correctly styled
64
+ def href
65
+ options[:href] || '#'
66
+ end
67
+
68
+ # Passes in the rails confirm option to the slat action component.
69
+ # Rails example: link_to 'Update', ..., method: :patch
70
+ def method
71
+ options.fetch(:method, nil)
72
+ end
73
+
74
+ # Allow for outline settings to be added
75
+ # Assumes true if `button: true` per design system
76
+ # style guide expectations.
77
+ def outlined
78
+ options[:outlined] || button
79
+ end
80
+
81
+ # Passes in the rails :remote option to the slat action component
82
+ # Rails example: link_to 'Get Started', remote: true
83
+ def remote
84
+ options.fetch(:remote, nil)
85
+ end
86
+
87
+ def render_integrated_slat_action
88
+ button ? render_button : render_link
89
+ end
90
+
91
+ # Passes the standard `:theme` option to the integrated Slat Action
92
+ #
93
+ # When the slat action component is a `button` (`button: true`):
94
+ # The integrated slat action will default to the `:secondary` theme
95
+ # per the design system style guide.
96
+ #
97
+ # The default `:secondary` theme can be manually overridden by passing in a
98
+ # `:theme` trait or `:theme` option to the parent SlatActions component.
99
+ def theme
100
+ # Note: this needs to be solved / addressed
101
+ # For whatever reason, the traits are not being picked up by the
102
+ # button version of the slat action.
103
+ # This ensures that any theme traits get applied here.
104
+ # calculated_theme = (traits & NfgUi::Components::Traits::Theme::COLOR_TRAITS)
105
+
106
+ # calculated_theme.any? ? calculated_theme.first : options[:theme]
107
+ # raise options.inspect
108
+ # options[:theme]
109
+ # options.fetch(:theme, super)
110
+ options.fetch(:theme, nil)
111
+ end
112
+
113
+ private
114
+
115
+ # Supplies the SlatActions with
116
+ # the appropriate css classes for the action link
117
+ # when the SlatActions is used to bypass writing a manual slat action component
118
+ # This is complicated, and thus...
119
+ # This is why we are creating a patching module -- so that we can later rip this stuff out.
120
+ def integrated_slat_action_link_css_classes
121
+ [
122
+ ("text-#{theme}" if theme),
123
+ 'd-block'
124
+ ].join(' ').squish
125
+ end
126
+
127
+ # Determines if the slat action component is a delete link
128
+ # Evaluated by examining the :method option
129
+ #
130
+ # This is used to determine where to inject the `delete` HTML data attribute (data-method)
131
+ # and value ('delete') in the integrated slat action's HTML options
132
+ def delete_link?
133
+ @delete_link ||= options.fetch(:method, nil) == :delete
134
+ end
135
+
136
+ # When the slat action component is a button component,
137
+ # These are the compiled options that are passed
138
+ # through from the SlatActions options into the integrated button's options.
139
+ #
140
+ # This also acts as a filter against what is allowed to pass
141
+ # and what is not allowed to pass into the
142
+ # integrated component.
143
+ def integrated_slat_action_button_component_options
144
+ # Do not set theme to nil (so theme defaults will run)
145
+ # Instead, do not pass in a theme at all.
146
+ # theme_options_hash = theme ? { theme: theme } : {}
147
+
148
+ { theme: (theme || :secondary),
149
+ # **theme_options_hash,
150
+ traits: traits,
151
+ as: :a,
152
+ confirm: confirm,
153
+ disable_with: disable_with,
154
+ href: href,
155
+ method: send(:method),
156
+ remote: remote,
157
+ outlined: outlined,
158
+ icon: icon }
159
+ end
160
+
161
+ # Given the complexity of the data-attributes,
162
+ # this isolates them into their own method for ease
163
+ # of following what's going on.
164
+ #
165
+ # Essentially, since the :delete method is actually
166
+ # converted to a data-attribute in rails, we
167
+ # have to manually merge the `data-method='delete'` into the data attributes hash
168
+ #
169
+ # This brings the whole data-attributes suite together
170
+ # and optionally merges in the data-method='delete' if
171
+ # this is a delete button/link.
172
+ def integrated_slat_action_html_data_attributes
173
+ mergable_delete_link = delete_link? ? { method: :delete } : {}
174
+
175
+ { disable_with: disable_with,
176
+ confirm: confirm }.merge(mergable_delete_link)
177
+ end
178
+
179
+ # The HTML options that are passed into the manually created slat action component
180
+ # For instances where you are bypassing the manual slat action component by leveraging the
181
+ def integrated_slat_action_html_options
182
+ { href: href,
183
+ class: integrated_slat_action_link_css_classes,
184
+ method: send(:method),
185
+ remote: remote,
186
+ data: integrated_slat_action_html_data_attributes }
187
+ end
188
+
189
+ # These options are removed from attributes because
190
+ # they are picked up and placed on the *SlatActions*
191
+ # and not on the integrated *slat action component*
192
+ def non_html_attribute_options
193
+ super.push(:button, :confirm, :disable_with, :href, :method, :remote, :theme)
194
+ end
195
+
196
+ # When `:button` is `true`, this is what is rendered
197
+ def render_button
198
+ NfgUi::Components::Elements::Button.new({ **integrated_slat_action_button_component_options, body: (block_given? ? yield : body) }, view_context).render
199
+ end
200
+
201
+ # When `:button` is `false`, a link is rendered
202
+ def render_link
203
+ content_tag(:a, **integrated_slat_action_html_options) do
204
+ if icon
205
+ NfgUi::Components::Foundations::Icon.new({ traits: [icon], text: (block_given? ? yield : body), theme: theme }, view_context).render
206
+ else
207
+ (block_given? ? yield : body)
208
+ end
209
+ end
210
+ end
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NfgUi
4
- VERSION = '0.9.8.17'
4
+ VERSION = '0.9.8.18'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nfg_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8.17
4
+ version: 0.9.8.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Roehm
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-05-28 00:00:00.000000000 Z
12
+ date: 2019-06-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bootstrap
@@ -53,20 +53,6 @@ dependencies:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '4.7'
56
- - !ruby/object:Gem::Dependency
57
- name: haml
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '5.0'
63
- type: :runtime
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '5.0'
70
56
  - !ruby/object:Gem::Dependency
71
57
  name: inky-rb
72
58
  requirement: !ruby/object:Gem::Requirement
@@ -702,6 +688,7 @@ files:
702
688
  - lib/nfg_ui/components/utilities/iconable.rb
703
689
  - lib/nfg_ui/components/utilities/left_iconable.rb
704
690
  - lib/nfg_ui/components/utilities/methodable.rb
691
+ - lib/nfg_ui/components/utilities/patches/integrated_slat_action.rb
705
692
  - lib/nfg_ui/components/utilities/renderable.rb
706
693
  - lib/nfg_ui/components/utilities/resource_themeable.rb
707
694
  - lib/nfg_ui/components/utilities/titleable.rb