keystone_ui 0.91.0 → 0.93.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: f09a621fcad17f9df319563b9bd9930a6782fdf8ba9721258ed464d69a749b29
4
- data.tar.gz: 040667ef0b3556f75dcd9cbfabdb9f1048f641317a95e23402b0e0c900689811
3
+ metadata.gz: 5d9b4e6f41ef819c8ec38c53466d6b07df34c049365d24a5f76386405add852a
4
+ data.tar.gz: 966e103db50821bb96a65be8903437e490b102c0159c9fad164a0fbd34a144d5
5
5
  SHA512:
6
- metadata.gz: c54c88339b33025ed7b127c010bb02ca62fd4812ddee1b6ade127ea6db371cfa92823dc23dbae00ad91af170faae43b9c53256a85cbfa339a1e69f66790eaf18
7
- data.tar.gz: 6f24aff529bc396da614cbc3218de08b9be47cb8f7a2ad1411d2ef27521cfe414e5149ce20317562b21f6ee6065f0480e7bf2cd7decea41efde3251729bd7d73
6
+ metadata.gz: 22dcbeea0616fd58e8e1b928c472d62988a07f23aec2c9f568cc7f90e6a0052a830461d7056af400f606075a426ea34d02d69680af0785dbc1e1941415e8d7ca
7
+ data.tar.gz: 01b0b39ecd8881953cef928e658121a5aadf618dc3df79a1f6880d4d09353b6cc62185a7473ae03564501878b14bfd9d1bba04acc1215bc5f2fb42b4eeb22748
@@ -5,13 +5,22 @@ module Keystone
5
5
  class ButtonRowComponent < ViewComponent::Base
6
6
  ROW_CLASSES = "flex flex-wrap ks-grid-gap-sm max-sm:*:min-h-11 [&>form]:flex [&>form>*]:flex-1"
7
7
  EQUAL_WIDTH_CLASSES = "*:flex-1 *:whitespace-nowrap"
8
+ PHONE_EQUAL_WIDTH_CLASSES = "max-sm:*:flex-1 max-sm:*:whitespace-nowrap"
8
9
 
9
10
  def initialize(equal_width: false)
10
11
  @equal_width = equal_width
11
12
  end
12
13
 
13
14
  def row_classes
14
- [ ROW_CLASSES, (EQUAL_WIDTH_CLASSES if @equal_width) ].compact.join(" ")
15
+ [ ROW_CLASSES, equal_width_classes ].compact.join(" ")
16
+ end
17
+
18
+ private
19
+
20
+ def equal_width_classes
21
+ return PHONE_EQUAL_WIDTH_CLASSES if @equal_width == :phone
22
+
23
+ EQUAL_WIDTH_CLASSES if @equal_width
15
24
  end
16
25
  end
17
26
  end
@@ -0,0 +1,15 @@
1
+ <%= form_with url: @url, method: @method, class: FORM_CLASSES do %>
2
+ <div class="<%= BAR_CLASSES %>">
3
+ <% if @note %>
4
+ <label class="<%= NOTE_CLASSES %>"><span class="<%= NOTE_LABEL_CLASSES %>"><%= @note[:label] %></span><%= render Keystone::Ui::InputComponent.new(name: @note[:name], placeholder: @note[:placeholder]) %></label>
5
+ <% end %>
6
+ <%= buttons %>
7
+ </div>
8
+ <% if @hint %>
9
+ <p class="<%= HINT_CLASSES %>"><%= @hint %></p>
10
+ <% end %>
11
+ <% end %>
12
+ <div class="<%= SPACER_CLASSES %>" data-decision-bar-spacer inert>
13
+ <div class="<%= BAR_CLASSES %> <%= BAR_COPY_CLASSES %>"><%= buttons %></div>
14
+ <div class="<%= TAB_BAR_ROOM_CLASSES %>"></div>
15
+ </div>
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Keystone
4
+ module Ui
5
+ class DecisionBarComponent < ViewComponent::Base
6
+ FORM_CLASSES = "ks-panel ks-panel-radius-md ks-panel-padding-sm flex flex-wrap items-center ks-grid-gap-sm max-sm:contents"
7
+ BAR_CLASSES = "ks-bottom-action max-sm:flex-col ks-grid-gap-sm sm:contents hotwire-native:bottom-0"
8
+ PRIMARY_CLASSES = "max-sm:order-first max-sm:*:w-full max-sm:*:min-h-12"
9
+ ACTION_CLASSES = "flex *:flex-1"
10
+ PHONE_ONLY_CLASSES = "sm:hidden"
11
+ PHONE_ORDER_CLASSES = { 1 => "max-sm:order-1", 2 => "max-sm:order-2", 3 => "max-sm:order-3" }.freeze
12
+ PHONE_LABEL_CLASSES = "sm:hidden"
13
+ FULL_LABEL_CLASSES = "max-sm:hidden"
14
+ HINT_CLASSES = "ks-hint basis-full max-sm:hidden"
15
+ BAR_COPY_CLASSES = "!static invisible"
16
+ SPACER_CLASSES = "sm:hidden"
17
+ TAB_BAR_ROOM_CLASSES = "hidden h-(--ks-bottom-nav-height) [html:not(.hotwire-native)_body:has(.ks-bottom-nav)_&]:block"
18
+ NOTE_LABEL_CLASSES = "ks-label shrink-0"
19
+ NOTE_CLASSES = "flex flex-1 basis-60 items-center ks-grid-gap-sm max-sm:hidden"
20
+
21
+ def initialize(url:, primary:, actions: [], note: nil, hint: nil, method: :post)
22
+ @url = url
23
+ @primary = primary
24
+ @actions = actions
25
+ @note = note
26
+ @hint = hint
27
+ @method = method
28
+ end
29
+
30
+ def buttons
31
+ safe_join([ secondary_row, primary_button ])
32
+ end
33
+
34
+ private
35
+
36
+ def secondary_row
37
+ render(ButtonRowComponent.new(equal_width: :phone)) do
38
+ safe_join(@actions.map { |action| secondary_button(action) })
39
+ end
40
+ end
41
+
42
+ def secondary_button(action)
43
+ tag.div(class: [ ACTION_CLASSES, (PHONE_ONLY_CLASSES if action[:phone_only]), PHONE_ORDER_CLASSES[action[:phone_order]] ].compact.join(" ")) do
44
+ render ButtonComponent.new(variant: :secondary, **action.except(:phone_only, :phone_order, :phone_label), label: action_label(action))
45
+ end
46
+ end
47
+
48
+ def action_label(action)
49
+ return action[:label] unless action[:phone_label]
50
+
51
+ safe_join([ tag.span(action[:label], class: FULL_LABEL_CLASSES), tag.span(action[:phone_label], class: PHONE_LABEL_CLASSES) ])
52
+ end
53
+
54
+ def primary_button
55
+ tag.div(class: PRIMARY_CLASSES) { render ButtonComponent.new(**@primary) }
56
+ end
57
+ end
58
+ end
59
+ end
@@ -7,9 +7,15 @@
7
7
  <% end %>
8
8
  </div>
9
9
  <span class="<%= TITLE_CLASSES %>">
10
+ <% if @overline.present? %>
11
+ <span class="<%= OVERLINE_CLASSES %>"><%= @overline %></span>
12
+ <% end %>
10
13
  <%= @title %>
11
14
  <% if @subtitle.present? %>
12
15
  <span class="<%= SUBTITLE_CLASSES %>"><%= @subtitle %></span>
13
16
  <% end %>
14
17
  </span>
18
+ <% if @badge %>
19
+ <%= render Keystone::Ui::BadgeComponent.new(**@badge, class: BADGE_CLASSES) %>
20
+ <% end %>
15
21
  </div>
@@ -20,6 +20,8 @@ module Keystone
20
20
  BACK_LINK_CLASSES = "ks-mobile-header-back"
21
21
  TITLE_CLASSES = "ks-mobile-header-title flex-[1_1_6rem] min-w-0 self-center lg:hidden truncate"
22
22
  SUBTITLE_CLASSES = "ks-mobile-header-subtitle block text-xs truncate"
23
+ OVERLINE_CLASSES = "ks-mobile-header-subtitle block text-xs truncate"
24
+ BADGE_CLASSES = "ml-auto shrink-0 self-center"
23
25
  DROPDOWN_CLASSES = "ks-action-menu hidden absolute right-0 z-50 w-48 origin-top-right"
24
26
 
25
27
  # Renders the left-side and title of the mobile header.
@@ -29,10 +31,12 @@ module Keystone
29
31
  # <% if content_for?(:form_page) %>
30
32
  # <%= ui_mobile_header_left %>
31
33
  # <% end %>
32
- def initialize(title:, back_url:, subtitle: nil)
34
+ def initialize(title:, back_url:, subtitle: nil, overline: nil, badge: nil)
33
35
  @title = title
34
36
  @back_url = back_url
35
37
  @subtitle = subtitle
38
+ @overline = overline
39
+ @badge = badge
36
40
  end
37
41
  end
38
42
  end
@@ -169,6 +169,10 @@ module KeystoneUiHelper
169
169
  render Keystone::Ui::BottomActionComponent.new
170
170
  end
171
171
 
172
+ def ui_decision_bar(**args)
173
+ render Keystone::Ui::DecisionBarComponent.new(**args)
174
+ end
175
+
172
176
  def ui_navbar(**args, &block)
173
177
  render Keystone::Ui::NavbarComponent.new(**args), &block
174
178
  end
@@ -53,6 +53,7 @@ module Keystone
53
53
  Keystone::Ui::MobileActionsComponent,
54
54
  Keystone::Ui::MobileActionComponent,
55
55
  Keystone::Ui::BottomActionComponent,
56
+ Keystone::Ui::DecisionBarComponent,
56
57
  Keystone::Ui::MobileHeaderComponent,
57
58
  Keystone::Ui::ShowPageComponent,
58
59
  Keystone::Ui::OptionCardComponent,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.91.0"
4
+ VERSION = "0.93.0"
5
5
  end
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: keystone_ui-develop
3
- description: Use PROACTIVELY for building or editing screens in a Rails app that has keystone_ui — page shells with Back links and breadcrumbs, forms and fields, a search field that picks a record or enters a new one, data tables with saved columns, desktop navigation, sidebars and bottom tabs, a page's main action as a phone top-bar icon or a button fixed to the bottom of the screen, a question asked before a button or main action goes ahead, action menus for a record's Edit and Delete, dashboards with stat cards, charts, funnels, goal buckets and timelines of timed steps, drawn one line per step with a marked time axis if wanted, with retries and their count, queued time, failed tries, steps still running, steps waiting on approval, links to each try and the current step marked, amounts shown in green or red as a gain or loss, status dots coloured by state, pictures held to half the screen, a short note or badge at the right of a section's title, a record's details as labelled values in rows or in two columns, two versions of a text compared line by line side by side, info buttons and breakdowns, marketing sections, a light/dark theme switch — MUST BE USED instead of hand-writing ERB and Tailwind for UI.
3
+ description: Use PROACTIVELY for building or editing screens in a Rails app that has keystone_ui — page shells with Back links and breadcrumbs, forms and fields, a search field that picks a record or enters a new one, data tables with saved columns, desktop navigation, sidebars and bottom tabs, a phone header with a line above its title and a badge at its right end, a page's main action as a phone top-bar icon or a button fixed to the bottom of the screen, a decision bar of a note field and several buttons sent as one form and fixed to the bottom of a phone screen, a question asked before a button or main action goes ahead, action menus for a record's Edit and Delete, dashboards with stat cards, charts, funnels, goal buckets and timelines of timed steps, drawn one line per step with a marked time axis if wanted, with retries and their count, queued time, failed tries, steps still running, steps waiting on approval, links to each try and the current step marked, amounts shown in green or red as a gain or loss, status dots coloured by state, pictures held to half the screen, a short note or badge at the right of a section's title, a record's details as labelled values in rows or in two columns, two versions of a text compared line by line side by side, info buttons and breakdowns, marketing sections, a light/dark theme switch — MUST BE USED instead of hand-writing ERB and Tailwind for UI.
4
4
  tools: Bash, Read, Write, Edit, Grep
5
5
  scope: UI — pages, forms, tables, navigation, dashboards
6
6
  ---
@@ -41,10 +41,11 @@ not available in the app yet, that is `keystone_ui-install`'s job.
41
41
  - `ui_nav_dropdown` — a navbar dropdown menu.
42
42
  - `ui_bottom_nav` — the mobile bottom tab bar.
43
43
  - `ui_bottom_nav_item` — one tab in the bottom tab bar.
44
- - `ui_mobile_header` — a mobile back arrow and a title beside it.
44
+ - `ui_mobile_header` — a mobile back arrow and a title beside it, with an optional line above the title and a badge at the right end.
45
45
  - `ui_mobile_actions` — an ellipsis menu of actions shown only below `lg:`.
46
46
  - `ui_mobile_action` — a plus icon link to the action a screen's page header publishes, for the phone top bar.
47
47
  - `ui_bottom_action` — a full-width button for the action a screen's page header publishes, in a bar fixed to the bottom of a phone screen.
48
+ - `ui_decision_bar` — one form of a note field, secondary buttons and a primary button on one wrapping line, fixed to the bottom of a phone screen with the primary button above the others.
48
49
  - `ui_action_menu` — an ellipsis menu of actions shown at every screen size.
49
50
  - `ui_action_menu_item` — one action in an action menu, as a link or a button sending a method.
50
51
  - `ui_settings_link` — a full-width settings row with a chevron.
@@ -66,7 +67,7 @@ not available in the app yet, that is `keystone_ui-install`'s job.
66
67
  - `Keystone::Ui::Column` — a table column with options a `{ key: "Label" }` hash cannot carry.
67
68
  - `ui_column_picker` — a Columns menu that saves which columns are hidden and their order to an app endpoint.
68
69
  - `ui_button` — a link or a button styled as a button, or a button sending a POST, PATCH or DELETE request, optionally asking a question before it goes ahead.
69
- - `ui_button_row` — a row of buttons that wraps onto further lines, optionally giving each button an equal share of its width.
70
+ - `ui_button_row` — a row of buttons that wraps onto further lines, optionally giving each button an equal share of its width at every width or on a phone only.
70
71
  - `ui_badge` — a coloured pill holding a short label.
71
72
  - `ui_status_dot` — a small dot coloured by state, with its label read only by screen readers.
72
73
  - `ui_figure` — one amount as inline text, coloured as a gain or a loss.
@@ -319,7 +320,7 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
319
320
  where `icon:` is a raw SVG string and `count:` above zero shows in a badge
320
321
  over the icon. The bar is hidden from `lg:` up and inside a
321
322
  Hotwire Native web view.
322
- - `ui_mobile_header(title:, back_url:, subtitle: nil)` is hidden from `lg:`
323
+ - `ui_mobile_header(title:, back_url:, subtitle: nil, overline: nil, badge: nil)` is hidden from `lg:`
323
324
  up and goes in the navbar's `mobile_left` slot or directly in the
324
325
  layout's `<header>`. `back_url:` must be passed, and `nil` renders the
325
326
  title with no back arrow. Outside a top bar it draws the arrow, title and
@@ -332,7 +333,13 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
332
333
  under it. In a hand-written top bar, give the bar the `top-nav` class,
333
334
  make the header a direct child of the bar's flex row, and add
334
335
  `max-lg:has-[.ks-mobile-header-title]:flex-wrap` to the bar if its
335
- controls can fill its width.
336
+ controls can fill its width. `overline:` is a short muted line shown
337
+ above the title, such as `"Inbox · 7 items"`. `badge:` takes the
338
+ `label:` and `variant:` keywords of `ui_badge`, such as
339
+ `{ label: "46h left", variant: :warning }`, and draws the badge at the
340
+ right end of the header, before the bar's right-side controls, at its
341
+ full width, so a long title ends in an ellipsis instead of pushing the
342
+ badge off the screen.
336
343
  - `ui_mobile_action` takes no keywords and no block, and goes in the top
337
344
  bar's right side, such as the navbar's `mobile_right` slot. It draws a plus
338
345
  icon linking to the `action_url:` a screen gives `ui_page_header`, named
@@ -358,6 +365,32 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
358
365
  both. Add no padding of your own for them. It and `ui_mobile_action`
359
366
  draw the same action, so ask the developer which one a screen shows on a
360
367
  phone.
368
+ - `ui_decision_bar(url:, primary:, actions: [], note: nil, hint: nil, method: :post)`
369
+ draws one form sending to `url:` with `method:`. `primary:` and each hash
370
+ in `actions:` are `ui_button` keywords, usually `label:`, `name:` and
371
+ `value:`, so the button pressed tells the controller which decision was
372
+ made. An action with `href:` is a link, such as a `Next ›` to the next
373
+ item. Each action also takes `phone_label:`, a shorter label shown below
374
+ `sm:` in its place, `phone_only: true`, which shows the action below
375
+ `sm:` only, and `phone_order:` 1, 2 or 3, its place in the phone row, so
376
+ one call can give a desktop row and a phone row that differ in labels,
377
+ buttons and order. Do not give an action `href:` with a `method:` other than `:get`,
378
+ since that draws a form inside the bar's form. `note:` takes `name:`,
379
+ `label:` and `placeholder:` and draws a text field inside its label, sent
380
+ with the form. `hint:` is a short line of muted text, such as keyboard
381
+ keys. From `sm:` up it draws a panel holding the note field, the
382
+ `actions:` as secondary buttons and the `primary:` button on one line
383
+ that wraps, with the hint on its own line under them. Below `sm:` it is a
384
+ bar fixed to the bottom of the screen, above `ui_bottom_nav` on a page
385
+ that has one, with the primary button at full width and 48 pixels tall
386
+ above a row of the secondary buttons, each an equal share of the row and
387
+ 44 pixels tall. The note field and hint are not shown below `sm:`. Give
388
+ it three secondary actions at most on a phone so the phone row fits. It stays shown
389
+ inside a Hotwire Native web view, at the bottom of the web view. It draws
390
+ an invisible copy of its phone bar in the page's flow, plus the bottom
391
+ nav's height when the page has a `ui_bottom_nav`, so the page's last
392
+ content scrolls clear of both. Add no padding of your own for them, and
393
+ do not show `ui_bottom_action` on the same screen.
361
394
  - `ui_settings_link(label:, href:)` renders one settings row.
362
395
  - `ui_theme_toggle` takes no keywords and no block. Its buttons switch the
363
396
  theme at once and store the choice in the `keystone_theme` cookie for a
@@ -630,8 +663,10 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
630
663
  what sits in the row, fills that form, so it takes the same share and
631
664
  height as a link or plain button beside it. `equal_width: true` gives each
632
665
  item an equal share of the row's width and keeps each label on one line,
633
- so the row wraps only when a label no longer fits in its share. Use it in
634
- place of a hand-written flex `div` around a set of buttons.
666
+ so the row wraps only when a label no longer fits in its share.
667
+ `equal_width: :phone` does that below `sm:` only, and from `sm:` up each
668
+ button keeps the width of its label. Use it in place of a hand-written
669
+ flex `div` around a set of buttons.
635
670
  - `ui_link(label:, href:)` draws a text link in the link colour. Use it in
636
671
  place of a hand-written `link_to` with colour classes.
637
672
  - With `href:` and `method:` `:post` `:patch` `:put` or `:delete`, it
@@ -153,7 +153,8 @@ One decision: is keystone_ui set up in the app?
153
153
  is at least a phone's tap height, and a button that sends a request fills its
154
154
  share of the row like a link does. A row can give each button an equal share
155
155
  of its width, keeping each label on one line, so the row wraps only when a
156
- label no longer fits.
156
+ label no longer fits. It can do that on a phone only, leaving each button
157
+ the width of its label on a wider screen.
157
158
  - **Confirmation.** A button can carry a confirmation question, and the
158
159
  browser asks it before following the link or sending the form. Nothing is
159
160
  sent when the user cancels.
@@ -169,6 +170,17 @@ One decision: is keystone_ui set up in the app?
169
170
  own button below `sm:` so the action is not shown twice. Both forms show
170
171
  nothing when the header names no action, and both are hidden inside a
171
172
  Hotwire Native web view and in print.
173
+ - **A decision bar.** A decision bar is one form holding an optional note
174
+ field, several secondary buttons and one primary button, and the button
175
+ pressed tells the app which decision was made. On a wider screen it is a
176
+ panel with all of them on one line that wraps, and an optional hint line
177
+ under them. On a phone it is a bar fixed to the bottom of the screen, above
178
+ the bottom tab bar when the page has one, with the primary button at full
179
+ width above a row of the secondary buttons in equal shares, and with no note
180
+ field or hint. Each secondary button can have a shorter label on a phone, be
181
+ shown on a phone only, and take another place in the phone row. The page leaves room under its last content so the bar does
182
+ not cover it. Unlike the main action's bottom bar, it stays shown inside a
183
+ Hotwire Native web view.
172
184
  - **Action menus.** Each action is a label, an address and an HTTP method. A
173
185
  plain visit is a link, and any other method is a button, so an action that
174
186
  changes data is never a bare link. A delete asks for confirmation by default.
@@ -45,6 +45,7 @@ develop:
45
45
  - ui_mobile_actions
46
46
  - ui_mobile_action
47
47
  - ui_bottom_action
48
+ - ui_decision_bar
48
49
  - ui_action_menu
49
50
  - ui_action_menu_item
50
51
  - ui_navbar
@@ -158,6 +159,8 @@ sources:
158
159
  - app/components/keystone/ui/mobile_actions_component.rb
159
160
  - app/components/keystone/ui/mobile_action_component.rb
160
161
  - app/components/keystone/ui/bottom_action_component.rb
162
+ - app/components/keystone/ui/decision_bar_component.rb
163
+ - app/components/keystone/ui/decision_bar_component.html.erb
161
164
  - app/components/keystone/ui/action_menu_component.rb
162
165
  - app/components/keystone/ui/action_menu_item_component.rb
163
166
  - 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.91.0
4
+ version: 0.93.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider
@@ -128,6 +128,8 @@ files:
128
128
  - app/components/keystone/ui/cta_banner_component.rb
129
129
  - app/components/keystone/ui/data_table_component.html.erb
130
130
  - app/components/keystone/ui/data_table_component.rb
131
+ - app/components/keystone/ui/decision_bar_component.html.erb
132
+ - app/components/keystone/ui/decision_bar_component.rb
131
133
  - app/components/keystone/ui/desktop_back_link_component.html.erb
132
134
  - app/components/keystone/ui/desktop_back_link_component.rb
133
135
  - app/components/keystone/ui/disclosure_component.html.erb