keystone_ui 0.56.0 → 0.58.0

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: 1d60dc9eb75d07285fc1f90e102456631d1462851a5fcb2af7f2b28a3ddcc550
4
- data.tar.gz: 65b03bbda334318e51b71014cbc1d9b2fa5b10841eb5d62c9cb963da5d7532ee
3
+ metadata.gz: 8c9ad83a2a5881bc553774b36f62fe5509470caed7fcd74dd79972c1ee4936e3
4
+ data.tar.gz: 698cdaadc0c5c9244862e60cc76b02a0fd273a1a5c5e70acc75247c39fbd5b9c
5
5
  SHA512:
6
- metadata.gz: 4316551b415b8ea4b392ad4929d7c6601ce7e2cc0a9284a83b060201d772f8c8257d20f819f1cc433dc3fc3b008d43fae47c28ce4c206cb026e48433cf926a36
7
- data.tar.gz: e34615f42f57d85cfcc9602624c8c3e8a4fd86e56cc4decec8835796330d27fe6994b0de3c92b18d5ad98162f6c1459761aefce6fefc71a96bb24fdeba2a1056
6
+ metadata.gz: de6f443de49b13769218d2bb0bacd47b85bb37b4d7d6bb478bb0c0f925a1e930f3e849cdaef9ebe65f4bf8039c6e820aa5f0ef8336ef718eb7195f33d90b42db
7
+ data.tar.gz: e30496556e65b64b211a8a95580dcee1fcfcf6d51b7a92f5020dbfb20e88c7e38abb1f648e676ed8399a1829ce9b729c02333fe8869eee5f200a7289340cc755
@@ -19,11 +19,17 @@ export default class extends Controller {
19
19
  this.menuTarget.classList.add("hidden")
20
20
  }
21
21
 
22
+ follow() {
23
+ if (!this.menuTarget.classList.contains("hidden")) this.place()
24
+ }
25
+
22
26
  place() {
23
27
  const button = this.buttonTarget.getBoundingClientRect()
28
+ const screenHeight = this.element.ownerDocument.documentElement.clientHeight
29
+ const roomBelow = button.bottom + this.menuTarget.offsetHeight <= screenHeight
24
30
  Object.assign(this.menuTarget.style, {
25
31
  position: "fixed",
26
- top: `${button.bottom}px`,
32
+ top: `${roomBelow ? button.bottom : Math.max(0, button.top - this.menuTarget.offsetHeight)}px`,
27
33
  left: `${button.right - this.menuTarget.offsetWidth}px`,
28
34
  right: "auto"
29
35
  })
@@ -1,6 +1,6 @@
1
- <div class="<%= WRAPPER_CLASSES %>" data-controller="action-menu" data-action="scroll@window->action-menu#close resize@window->action-menu#close">
1
+ <div class="<%= WRAPPER_CLASSES %>" data-controller="action-menu" data-action="scroll@window->action-menu#follow resize@window->action-menu#close">
2
2
  <button type="button"
3
- data-action="click->action-menu#toggle click@window->action-menu#hide"
3
+ data-action="click->action-menu#toggle pointerup@window->action-menu#hide"
4
4
  data-action-menu-target="button"
5
5
  class="<%= BUTTON_CLASSES %>"
6
6
  aria-label="Actions">
@@ -8,8 +8,8 @@
8
8
  <% if checkbox? %>
9
9
  <div class="<%= CHECKBOX_WRAPPER_CLASSES %>">
10
10
  <input type="hidden" name="<%= @attribute %>" value="0">
11
- <input type="checkbox" name="<%= @attribute %>" value="1" class="<%= CHECKBOX_CLASSES %>"<%= " checked" if @value.to_s == "1" %>>
12
- <span class="text-sm text-gray-700 dark:text-gray-300"><%= label_text %></span>
11
+ <input type="checkbox" name="<%= @attribute %>" id="<%= field_id %>" value="1" class="<%= CHECKBOX_CLASSES %>"<%= " checked" if @value.to_s == "1" %>>
12
+ <label for="<%= field_id %>" class="text-sm text-gray-700 dark:text-gray-300"><%= label_text %></label>
13
13
  </div>
14
14
  <% elsif textarea? %>
15
15
  <textarea name="<%= @attribute %>" id="<%= field_id %>" rows="3" class="<%= Keystone::Ui::TextareaComponent::BASE_CLASSES %>"<% if @placeholder %> placeholder="<%= @placeholder %>"<% end %>><%= @value %></textarea>
@@ -3,7 +3,8 @@
3
3
  module Keystone
4
4
  module Ui
5
5
  class HeroComponent < ViewComponent::Base
6
- WRAPPER_CLASSES = "ks-hero relative min-h-screen"
6
+ WRAPPER_CLASSES = "ks-hero relative"
7
+ SCREEN_HEIGHT_CLASSES = "min-h-screen"
7
8
  INNER_CLASSES = "ks-hero-inner mx-auto max-w-6xl"
8
9
 
9
10
  CONTENT_COLUMN_CLASSES = "ks-hero-content flex flex-col"
@@ -21,15 +22,20 @@ module Keystone
21
22
 
22
23
  attr_reader :title, :subtitle, :badge
23
24
 
24
- def initialize(title:, subtitle: nil, badge: nil, layout: :split)
25
+ def initialize(title:, subtitle: nil, badge: nil, layout: :split, height: :screen)
26
+ raise ArgumentError, "a hero's height is :screen or :content, got #{height.inspect}" unless %i[screen content].include?(height)
27
+
25
28
  @title = title
26
29
  @subtitle = subtitle
27
30
  @badge = badge
28
31
  @layout = layout
32
+ @height = height
29
33
  end
30
34
 
31
35
  def classes
32
- WRAPPER_CLASSES
36
+ return WRAPPER_CLASSES if @height == :content
37
+
38
+ "#{WRAPPER_CLASSES} #{SCREEN_HEIGHT_CLASSES}"
33
39
  end
34
40
 
35
41
  def inner_classes
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Keystone
4
+ module Ui
5
+ class MobileActionComponent < ViewComponent::Base
6
+ PLUS_ICON = <<~SVG.freeze
7
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
8
+ <path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
9
+ </svg>
10
+ SVG
11
+
12
+ LINK_CLASSES = "ks-action-menu-button sm:hidden hotwire-native:hidden print:hidden"
13
+
14
+ def render?
15
+ content_for?(:mobile_action_url)
16
+ end
17
+
18
+ def call
19
+ link_to(PLUS_ICON.html_safe, content_for(:mobile_action_url), class: LINK_CLASSES, aria: { label: content_for(:mobile_action_label) })
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,11 +1,12 @@
1
- <div class="<%= WRAPPER_CLASSES %>" data-controller="dropdown">
1
+ <div class="<%= WRAPPER_CLASSES %>" data-controller="action-menu" data-action="scroll@window->action-menu#follow resize@window->action-menu#close">
2
2
  <button type="button"
3
- data-action="click->dropdown#toggle click@window->dropdown#hide"
3
+ data-action="click->action-menu#toggle pointerup@window->action-menu#hide"
4
+ data-action-menu-target="button"
4
5
  class="<%= BUTTON_CLASSES %>"
5
6
  aria-label="Actions">
6
7
  <%= ELLIPSIS_ICON.html_safe %>
7
8
  </button>
8
- <div data-dropdown-target="menu" class="<%= DROPDOWN_CLASSES %>">
9
+ <div data-action-menu-target="menu" class="<%= DROPDOWN_CLASSES %>">
9
10
  <%= content %>
10
11
  </div>
11
12
  </div>
@@ -14,7 +14,7 @@ module Keystone
14
14
  DROPDOWN_CLASSES = "ks-action-menu hidden absolute right-0 z-50 w-48 origin-top-right"
15
15
 
16
16
  def wrapper_data
17
- { controller: "dropdown" }
17
+ { controller: "action-menu" }
18
18
  end
19
19
  end
20
20
  end
@@ -6,7 +6,7 @@
6
6
  <% end %>
7
7
 
8
8
  <% if logo? %>
9
- <div class="<%= LOGO_CLASSES %>">
9
+ <div class="<%= logo_classes %>">
10
10
  <%= logo %>
11
11
  </div>
12
12
  <% end %>
@@ -7,6 +7,7 @@ module Keystone
7
7
  NAV_STICKY = "sticky top-0 z-40"
8
8
  MOBILE_LEFT_CLASSES = "lg:hidden flex items-center"
9
9
  LOGO_CLASSES = "logo"
10
+ LOGO_MOBILE_HIDDEN_CLASSES = "hidden lg:flex"
10
11
  MOBILE_CENTER_CLASSES = "ks-navbar-title absolute left-1/2 -translate-x-1/2 lg:hidden truncate max-w-[60%]"
11
12
  DESKTOP_LINKS_CLASSES = "nav-container hidden lg:flex"
12
13
  MOBILE_RIGHT_CLASSES = "nav-user-controls ml-auto"
@@ -18,8 +19,9 @@ module Keystone
18
19
  renders_one :mobile_center
19
20
  renders_one :mobile_right
20
21
 
21
- def initialize(sticky: true)
22
+ def initialize(sticky: true, hide_logo_on_mobile: false)
22
23
  @sticky = sticky
24
+ @hide_logo_on_mobile = hide_logo_on_mobile
23
25
  end
24
26
 
25
27
  def nav_classes
@@ -27,6 +29,12 @@ module Keystone
27
29
  classes << NAV_STICKY if @sticky
28
30
  classes.join(" ")
29
31
  end
32
+
33
+ def logo_classes
34
+ classes = [ LOGO_CLASSES ]
35
+ classes << LOGO_MOBILE_HIDDEN_CLASSES if @hide_logo_on_mobile
36
+ classes.join(" ")
37
+ end
30
38
  end
31
39
  end
32
40
  end
@@ -13,5 +13,9 @@
13
13
  <div class="<%= ACTIONS_CLASSES %>">
14
14
  <%= @action_block.call %>
15
15
  </div>
16
+ <% elsif action_url %>
17
+ <div class="<%= ACTIONS_CLASSES %>">
18
+ <%= render Keystone::Ui::ButtonComponent.new(label: action_label, href: action_url) %>
19
+ </div>
16
20
  <% end %>
17
21
  </div>
@@ -141,6 +141,10 @@ module KeystoneUiHelper
141
141
  render Keystone::Ui::MobileActionsComponent.new(**args), &block
142
142
  end
143
143
 
144
+ def ui_mobile_action
145
+ render Keystone::Ui::MobileActionComponent.new
146
+ end
147
+
144
148
  def ui_navbar(**args, &block)
145
149
  render Keystone::Ui::NavbarComponent.new(**args), &block
146
150
  end
@@ -47,6 +47,7 @@ module Keystone
47
47
  Keystone::Ui::SettingsLinkComponent,
48
48
  Keystone::Ui::FormPageComponent,
49
49
  Keystone::Ui::MobileActionsComponent,
50
+ Keystone::Ui::MobileActionComponent,
50
51
  Keystone::Ui::MobileHeaderComponent,
51
52
  Keystone::Ui::ShowPageComponent,
52
53
  Keystone::Ui::OptionCardComponent,
@@ -76,7 +77,7 @@ module Keystone
76
77
  ].freeze
77
78
 
78
79
  # Constants that hold non-CSS values (e.g. HTML input type maps)
79
- SKIP_CONSTANTS = %i[TYPE_MAP ELLIPSIS_ICON BACK_ICON CARET_ICON CLOSE_ICON COPY_ICON SORT_ASC_ICON SORT_DESC_ICON SORT_NEUTRAL_ICON COLUMNS_ICON UPLOAD_ICON].freeze
80
+ SKIP_CONSTANTS = %i[TYPE_MAP ELLIPSIS_ICON BACK_ICON CARET_ICON CLOSE_ICON COPY_ICON SORT_ASC_ICON SORT_DESC_ICON SORT_NEUTRAL_ICON COLUMNS_ICON UPLOAD_ICON PLUS_ICON].freeze
80
81
 
81
82
  # Classes used in Ruby methods or ERB templates, not in frozen constants.
82
83
  # These cannot be auto-extracted and must be listed manually.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.56.0"
4
+ VERSION = "0.58.0"
5
5
  end
@@ -42,6 +42,7 @@ not available in the app yet, that is `keystone_ui-install`'s job.
42
42
  - `ui_bottom_nav_item` — one tab in the bottom tab bar.
43
43
  - `ui_mobile_header` — a mobile back arrow and centred title.
44
44
  - `ui_mobile_actions` — an ellipsis menu of actions shown only below `lg:`.
45
+ - `ui_mobile_action` — a plus icon link to the action a screen's page header publishes, for the phone top bar.
45
46
  - `ui_action_menu` — an ellipsis menu of actions shown at every screen size.
46
47
  - `ui_action_menu_item` — one action in an action menu, as a link or a button sending a method.
47
48
  - `ui_settings_link` — a full-width settings row with a chevron.
@@ -166,9 +167,11 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
166
167
  directly, since those pass `trail: []`.
167
168
  - `ui_page_header(title:, subtitle: nil, action_url: nil, action_label: "Add new", class: nil)`
168
169
  takes a block yielding the header and is hidden below `sm:`. Call
169
- `header.action { ... }` in the block to place a control on its right, and
170
- only what `action` receives is rendered. `action_url:` publishes that URL
171
- and label for a mobile navbar to pick up.
170
+ `header.action { ... }` in the block to place a control on its right.
171
+ `action_url:` declares the screen's main action. It publishes that URL and
172
+ label for `ui_mobile_action` to pick up, and with no `action` block the
173
+ header draws them as a button. An `action` block is drawn alone when both
174
+ are given.
172
175
  - `ui_breadcrumbs(trail:, current: nil)` renders `trail:` as links separated
173
176
  by `›`, then `current:` unlinked and marked as the current page, shown
174
177
  only from `lg:` up. On a form or detail screen pass `trail:` to the shell
@@ -241,6 +244,10 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
241
244
  `mobile_center`, `mobile_right`. Desktop slots are hidden below `lg:` and
242
245
  mobile slots from `lg:` up. `desktop_right` renders only when
243
246
  `desktop_links` is also filled.
247
+ - `ui_navbar(hide_logo_on_mobile: true)` hides the `logo` slot below `lg:`
248
+ and keeps it from `lg:` up, for a page that shows its own title in
249
+ `ui_mobile_header`. It defaults to `false`, which keeps the logo at every
250
+ width.
244
251
  - `ui_nav_item(label:, href:, active: false)` is one desktop link.
245
252
  `ui_nav_dropdown(title:, area:, active: false)` takes a block holding the
246
253
  menu links.
@@ -251,6 +258,14 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
251
258
  - `ui_mobile_header(title:, back_url:, subtitle: nil)` is hidden from `lg:`
252
259
  up and goes in the navbar's `mobile_left` slot. `back_url:` must be
253
260
  passed, and `nil` renders the title with no back arrow.
261
+ - `ui_mobile_action` takes no keywords and no block, and goes in the top
262
+ bar's right side, such as the navbar's `mobile_right` slot. It draws a plus
263
+ icon linking to the `action_url:` a screen gives `ui_page_header`, named
264
+ with its `action_label:`, and draws nothing when the screen gives none. It
265
+ is hidden from `sm:` up, where the page header shows the action, and inside
266
+ a Hotwire Native web view, so give native users another way to reach the
267
+ action, such as `ui_mobile_actions`. The layout must also write the
268
+ `hotwire-native` class on `<html>` and declare that Tailwind variant.
254
269
  - `ui_settings_link(label:, href:)` renders one settings row.
255
270
  - `ui_theme_toggle` takes no keywords and no block. Its buttons switch the
256
271
  theme at once and store the choice in the `keystone_theme` cookie for a
@@ -290,9 +305,10 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
290
305
  `:email` `:password` `:date` `:datetime` and is ignored by the other types. Its list
291
306
  is identified by `attribute:`, so two fields with suggestions on one
292
307
  screen need different `attribute:` values.
293
- - The field's label is tied to its input, textarea or select through an
294
- `id` built from `attribute:`, so tapping the label focuses the input and
295
- a screen reader reads the label. `"player[email]"` gets the id
308
+ - The field's label is tied to its input, textarea, select or checkbox
309
+ through an `id` built from `attribute:`, so tapping the label focuses the
310
+ input, or ticks and unticks the checkbox, and a screen reader reads the
311
+ label. `"player[email]"` gets the id
296
312
  `player-email`, so two fields on one screen need different `attribute:`
297
313
  values.
298
314
  - `required: true` marks the label with an asterisk and, on a `:text`
@@ -590,10 +606,13 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
590
606
 
591
607
  13. Build marketing sections.
592
608
 
593
- - `ui_hero(title:, subtitle: nil, badge: nil, layout: :split)` takes a
594
- block holding the call-to-action buttons and yields the component, so
595
- its `aside` slot can hold an image or panel. `layout:` is `:split` or
596
- `:centered`.
609
+ - `ui_hero(title:, subtitle: nil, badge: nil, layout: :split,
610
+ height: :screen)` takes a block holding the call-to-action buttons and
611
+ yields the component, so its `aside` slot can hold an image or panel.
612
+ `layout:` is `:split` or `:centered`. `height: :screen` keeps the hero at
613
+ least the full screen height, and `height: :content` draws it only as
614
+ tall as its content and its padding, for a page with more sections
615
+ after it.
597
616
  - `ui_cta_banner(title:, subtitle: nil)` takes a block holding the
598
617
  buttons.
599
618
  - `ui_feature_grid(title:, features:, subtitle: nil)` — `features:` is
@@ -37,6 +37,7 @@ develop:
37
37
  - ui_breadcrumbs
38
38
  - ui_mobile_header
39
39
  - ui_mobile_actions
40
+ - ui_mobile_action
40
41
  - ui_action_menu
41
42
  - ui_action_menu_item
42
43
  - ui_navbar
@@ -133,6 +134,7 @@ sources:
133
134
  - app/components/keystone/ui/input_component.rb
134
135
  - app/components/keystone/ui/line_chart_component.rb
135
136
  - app/components/keystone/ui/mobile_actions_component.rb
137
+ - app/components/keystone/ui/mobile_action_component.rb
136
138
  - app/components/keystone/ui/action_menu_component.rb
137
139
  - app/components/keystone/ui/action_menu_item_component.rb
138
140
  - app/components/keystone/ui/mobile_header_component.rb
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keystone_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.56.0
4
+ version: 0.58.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider
@@ -153,6 +153,7 @@ files:
153
153
  - app/components/keystone/ui/input_component.rb
154
154
  - app/components/keystone/ui/line_chart_component.html.erb
155
155
  - app/components/keystone/ui/line_chart_component.rb
156
+ - app/components/keystone/ui/mobile_action_component.rb
156
157
  - app/components/keystone/ui/mobile_actions_component.html.erb
157
158
  - app/components/keystone/ui/mobile_actions_component.rb
158
159
  - app/components/keystone/ui/mobile_header_component.html.erb