tramway 4.0.1.3 → 4.0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b083339a12222cbc2f03468e474dd7b909fda5f60a8d9d8d3f64f6bc55881de
4
- data.tar.gz: c049ab9613c2aacb337b716d6ee24c097199f19e82a19d96fca7f4241bc01aac
3
+ metadata.gz: 9d8281006bde6f8928a12ffc94cef931ff7b3c4e8bdc774ad4e690b7a529a0e8
4
+ data.tar.gz: 644f44899bc6919f0ea8f08fbb9708fa4fec87b54a398668714209f905a54d87
5
5
  SHA512:
6
- metadata.gz: 83a5d1fff5a20503ba9e80ebbe9dae8c980973e0943f9d33df8b2ede46e8c6aad4442fb34a47ab7884e483a5c475a217d0525c09b116e30971e3f77d75642272
7
- data.tar.gz: 3c7d778b02ab2b42d96f9668a8c5c65a94204ab7e3e83873b685d3718b1267d81236fc5d5bcfc59a4fc4a2b2f0d1d53a9d23837b4198cd2be8851e7acde6db77
6
+ metadata.gz: 506f5ed78da723c554832b299ef0f0415f63b328fa9e4ff72e6f52b4972d699398a26b5101f869563eb91ce786cd244fd977cbab9f634d7bfdbbab7cef96dcff
7
+ data.tar.gz: f68ae4382f2301f34ac572d725d41b0503f9ff5b6d2396e97a3afc95053d2c66e1f5818f2d9a0a6808f968e71ab386e3c789cbf9138f2616d0ee72f2af3c9104
data/README.md CHANGED
@@ -436,7 +436,9 @@ end
436
436
 
437
437
  You can inject custom content above an entity's index table by defining an
438
438
  `index_header_content` lambda on its decorator. The lambda receives the
439
- collection of decorated records and can render any component you need.
439
+ collection of decorated records and can render any component you need. See
440
+ [docs/users/tramway_entities.md](docs/users/tramway_entities.md) for where exactly this content is placed on
441
+ the page.
440
442
 
441
443
  *config/initializers/tramway.rb*
442
444
  ```ruby
@@ -480,7 +482,7 @@ end
480
482
  ```
481
483
 
482
484
  With this configuration in place, the index page will render the `Create`
483
- button component above the table of projects.
485
+ button and the header content above the table of projects.
484
486
 
485
487
  #### Add header content to show pages
486
488
 
@@ -947,6 +949,22 @@ end
947
949
 
948
950
  will render [this](https://play.tailwindcss.com/UZPTCudFw5)
949
951
 
952
+ #### Icons on navbar items
953
+
954
+ `nav.item` accepts an optional `icon:` option with a Font Awesome class string, rendered before the item's label:
955
+
956
+ ```ruby
957
+ nav.left do
958
+ nav.item 'Users', '/users', icon: 'fa fa-users'
959
+ nav.item 'Podcasts', '/podcasts', icon: 'fa fa-podcast'
960
+ end
961
+ ```
962
+
963
+ Icons are optional — items without one just render as plain text links. When the vertical sidebar is collapsed on
964
+ desktop, items rendered with an `icon:` stay visible and clickable as icon-only links (their text label is hidden
965
+ but still available to screen readers via the item's `aria-label`); items without an icon have nothing to show once
966
+ collapsed.
967
+
950
968
  #### tramway_navbar
951
969
 
952
970
  This helper provides several options. Here is YAML view of `tramway_navbar` options structure
@@ -457,13 +457,10 @@ class Navbar extends Controller {
457
457
 
458
458
  this.hiddenInteractionClasses.forEach((className) => {
459
459
  this.desktopHeader.classList.toggle(className, !expanded)
460
- this.desktopMenu.classList.toggle(className, !expanded)
461
460
  })
462
461
 
463
462
  this.desktopHeader.toggleAttribute('inert', !expanded)
464
- this.desktopMenu.toggleAttribute('inert', !expanded)
465
463
  this.desktopHeader.setAttribute('aria-hidden', expanded ? 'false' : 'true')
466
- this.desktopMenu.setAttribute('aria-hidden', expanded ? 'false' : 'true')
467
464
 
468
465
  this.desktopToggleWrapper.classList.toggle('justify-end', expanded)
469
466
  this.desktopToggleWrapper.classList.toggle('justify-center', !expanded)
@@ -1,3 +1,6 @@
1
1
  %li.whitespace-nowrap
2
2
  = button_to @href, method: @method, class: "#{style} cursor-pointer", **@options do
3
- = content
3
+ - if icon?
4
+ %i{ class: icon_classes, aria: { hidden: true } }
5
+ %span.tramway-navbar-item-label
6
+ = content
@@ -11,7 +11,8 @@ module Tramway
11
11
  def initialize(**options)
12
12
  @href = options[:href]
13
13
  @method = options[:method]
14
- @options = options.except(:href, :method)
14
+ @icon = options[:icon]
15
+ @options = options.except(:href, :method, :icon)
15
16
  end
16
17
  end
17
18
  end
@@ -1,3 +1,6 @@
1
1
  %li.whitespace-nowrap
2
2
  = link_to @href, class: style, **@options do
3
- = content
3
+ - if icon?
4
+ %i{ class: icon_classes, aria: { hidden: true } }
5
+ %span.tramway-navbar-item-label
6
+ = content
@@ -10,7 +10,10 @@ module Tramway
10
10
  class LinkComponent < Tramway::Nav::ItemComponent
11
11
  def initialize(**options)
12
12
  @href = options[:href]
13
- @options = Rules::TurboHtmlAttributesRules.prepare_turbo_html_attributes(options:)
13
+ @icon = options[:icon]
14
+ @options = Rules::TurboHtmlAttributesRules.prepare_turbo_html_attributes(
15
+ options: options.except(:href, :icon)
16
+ )
14
17
  end
15
18
  end
16
19
  end
@@ -7,10 +7,18 @@ module Tramway
7
7
  class ItemComponent < TailwindComponent
8
8
  def style
9
9
  @style ||= [
10
- 'tramway-navbar-item inline-flex items-center rounded-md px-4 py-3 text-base font-medium text-zinc-100',
11
- 'transition-colors hover:bg-zinc-800 hover:text-zinc-50 sm:px-3 sm:py-2 sm:text-sm'
10
+ 'tramway-navbar-item inline-flex items-center gap-2 rounded-md px-4 py-3 text-base font-medium',
11
+ 'text-zinc-100 transition-colors hover:bg-zinc-800 hover:text-zinc-50 sm:px-3 sm:py-2 sm:text-sm'
12
12
  ].join(' ')
13
13
  end
14
+
15
+ def icon?
16
+ @icon.present?
17
+ end
18
+
19
+ def icon_classes
20
+ [@icon, 'tramway-navbar-item-icon w-5 shrink-0 text-center'].join(' ')
21
+ end
14
22
  end
15
23
  end
16
24
  end
@@ -114,21 +114,16 @@
114
114
  })();
115
115
 
116
116
  :css
117
- .tramway-navbar-desktop-vertical .tramway-navbar-item {
118
- width: 100%;
119
- }
120
-
121
- .tramway-navbar-desktop-vertical .tramway-navbar-item > a,
122
- .tramway-navbar-desktop-vertical .tramway-navbar-item > form {
117
+ .tramway-navbar-desktop-vertical li.whitespace-nowrap {
123
118
  width: 100%;
124
119
  }
125
120
 
126
- .tramway-navbar-desktop-vertical .tramway-navbar-item > form {
121
+ .tramway-navbar-desktop-vertical li.whitespace-nowrap > form {
127
122
  display: block;
123
+ width: 100%;
128
124
  }
129
125
 
130
- .tramway-navbar-desktop-vertical .tramway-navbar-item > a,
131
- .tramway-navbar-desktop-vertical .tramway-navbar-item > form > button {
126
+ .tramway-navbar-desktop-vertical .tramway-navbar-item {
132
127
  width: 100%;
133
128
  justify-content: flex-start;
134
129
  }
@@ -142,12 +137,26 @@
142
137
  padding-left: 6rem;
143
138
  }
144
139
 
145
- html[data-tramway-navbar-expanded="false"] #desktop-navbar-header,
146
- html[data-tramway-navbar-expanded="false"] #desktop-navbar-content {
140
+ html[data-tramway-navbar-expanded="false"] #desktop-navbar-header {
147
141
  opacity: 0;
148
142
  pointer-events: none;
149
143
  }
150
144
 
145
+ html[data-tramway-navbar-expanded="false"] #desktop-navbar-content {
146
+ opacity: 1;
147
+ pointer-events: auto;
148
+ }
149
+
150
+ html[data-tramway-navbar-expanded="false"] #desktop-navbar-content .tramway-navbar-item-label {
151
+ display: none;
152
+ }
153
+
154
+ html[data-tramway-navbar-expanded="false"] #desktop-navbar-content .tramway-navbar-item {
155
+ justify-content: center;
156
+ padding-left: 0;
157
+ padding-right: 0;
158
+ }
159
+
151
160
  html[data-tramway-navbar-expanded="false"] #desktop-navbar-toggle-wrapper {
152
161
  justify-content: center;
153
162
  }
@@ -16,7 +16,9 @@
16
16
  path: Tramway::Engine.routes.url_helpers.public_send(@entity.routes.new),
17
17
  type: :will
18
18
 
19
- = decorator.constantize.index_header_content.call(@entities) if decorator.constantize.index_header_content.present?
19
+ - if decorator.constantize.index_header_content.present?
20
+ .mt-4
21
+ = decorator.constantize.index_header_content.call(@entities)
20
22
 
21
23
  .flex.flex-row.justify-end.mt-2.gap-4
22
24
  - if @entity.page(:index).search
@@ -6,6 +6,9 @@ const buildUtilities = (prefix, start, end) =>
6
6
  module.exports = {
7
7
  safelist: [
8
8
  // === Navbar ===
9
+ 'w-5',
10
+ 'shrink-0',
11
+ 'text-center',
9
12
  'ml-4',
10
13
  'text-white',
11
14
  'md:flex',
@@ -416,6 +419,7 @@ module.exports = {
416
419
  'mb-4',
417
420
  'mb-2',
418
421
  'mt-8',
422
+ 'mt-4',
419
423
  'mt-2',
420
424
 
421
425
  // === Pagination styles ===
@@ -35,13 +35,13 @@ module Tramway
35
35
  reset_filling
36
36
  end
37
37
 
38
- def item(text_or_url, url = nil, **, &)
38
+ def item(text_or_url, url = nil, icon: nil, **, &)
39
39
  raise 'You cannot provide an argument and a code block at the same time' if provided_url_and_block?(url, &)
40
40
 
41
41
  if url.present?
42
- render_ignoring_block(text_or_url, url, **)
42
+ render_ignoring_block(text_or_url, url, icon:, **)
43
43
  else
44
- render_using_block(text_or_url, **, &)
44
+ render_using_block(text_or_url, icon:, **, &)
45
45
  end => rendered_item
46
46
 
47
47
  @items[@filling] << rendered_item
@@ -73,8 +73,9 @@ module Tramway
73
73
  @filling = nil
74
74
  end
75
75
 
76
- def render_ignoring_block(text_or_url, url, method: nil, **options)
77
- options.merge!(href: url)
76
+ def render_ignoring_block(text_or_url, url, method: nil, icon: nil, **options)
77
+ options.merge!(href: url, icon:)
78
+ apply_icon_accessibility_attributes(options, label: text_or_url, icon:)
78
79
 
79
80
  if method.present? && method.to_sym != :get
80
81
  context.render(Tramway::Nav::Item::ButtonComponent.new(method:, **options)) { text_or_url }
@@ -83,8 +84,8 @@ module Tramway
83
84
  end
84
85
  end
85
86
 
86
- def render_using_block(text_or_url, method: nil, **options, &)
87
- options.merge!(href: text_or_url)
87
+ def render_using_block(text_or_url, method: nil, icon: nil, **options, &)
88
+ options.merge!(href: text_or_url, icon:)
88
89
 
89
90
  if method.present? && method.to_sym != :get
90
91
  context.render(Tramway::Nav::Item::ButtonComponent.new(method:, **options), &)
@@ -92,5 +93,12 @@ module Tramway
92
93
  context.render(Tramway::Nav::Item::LinkComponent.new(method:, **options), &)
93
94
  end
94
95
  end
96
+
97
+ def apply_icon_accessibility_attributes(options, label:, icon:)
98
+ return if icon.blank?
99
+
100
+ options[:title] = label if options[:title].blank?
101
+ options[:'aria-label'] = label if options[:'aria-label'].blank?
102
+ end
95
103
  end
96
104
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '4.0.1.3'
4
+ VERSION = '4.0.1.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1.3
4
+ version: 4.0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - kalashnikovisme