keystone_ui 0.77.0 → 0.79.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: 27865b2e7f95837a7c915aea020f129702dd705cea1dbc53cfb65f54039de0ac
4
- data.tar.gz: fc80893a3e533c51f238cc4ac4e2162f567557a3ebb620fd959ab46be72dd196
3
+ metadata.gz: facf365bdd0f3e806b1db58e72e26b58500b8db01ea8a016c5b89b39e5739d66
4
+ data.tar.gz: d098dc9c4105caa20816e8f47c2acd357697abb2e11f9918c05d4c2959fcd99b
5
5
  SHA512:
6
- metadata.gz: 5f7f08636bb8c78b3f5e8036f4decf9fa5781628c9d4fba01c748a409fb421840295b0914ae64629a8a9fbfdab0cf64f3f7fa4fa94494ef8dc3ad0ad4fb25c54
7
- data.tar.gz: bd4a3ff320b6628a12bdf0a2678542885bbb1b679aecc8e0d5d8e89cc05280417631db2945f5eac98794352321765d66be7ae0d4a55d6ff3c8df40becf1eb039
6
+ metadata.gz: 3ce67331b86779a466fcc1090400fa6b839f856fddb731a6c78a3bc78e82a6eeef590e388e24fb1a25e0a9920a05046b6db3f9f2d34bddde7a65c5995b3e5979
7
+ data.tar.gz: 9807d78d7a16382b8224f61f8eadf99753e5df8de684011454b7b81261598505b11ed78e5c3b5354d724c244564380f9a34c4be04fb526f0629125d79abda39c
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Keystone
4
+ module Ui
5
+ class StatusDotComponent < ViewComponent::Base
6
+ STATE_CLASSES = {
7
+ neutral: "ks-status-dot-neutral",
8
+ success: "ks-status-dot-success",
9
+ danger: "ks-status-dot-danger",
10
+ warning: "ks-status-dot-warning",
11
+ info: "ks-status-dot-info"
12
+ }.freeze
13
+
14
+ LABEL_CLASSES = "sr-only"
15
+
16
+ def initialize(state:, label:)
17
+ raise ArgumentError, "Unknown status dot state #{state.inspect}, expected one of #{STATE_CLASSES.keys.join(', ')}" unless STATE_CLASSES.key?(state)
18
+
19
+ @state = state
20
+ @label = label
21
+ end
22
+
23
+ def call
24
+ tag.span(class: "ks-status-dot #{STATE_CLASSES[@state]}") { tag.span(@label, class: LABEL_CLASSES) }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ <div class="<%= Keystone::Ui::TextDiffComponent::WRAPPER_CLASSES %>">
2
+ <div class="<%= Keystone::Ui::TextDiffComponent::COLUMNS_CLASSES %>">
3
+ <% Keystone::Ui::TextDiffComponent::SIDES.each do |side| %>
4
+ <div class="<%= Keystone::Ui::TextDiffComponent::SIDE_CLASSES %>" data-diff-side="<%= side %>">
5
+ <% cells(side).each do |cell| %>
6
+ <div class="<%= [ Keystone::Ui::TextDiffComponent::ROW_CLASSES, cell&.dig(:mark) ].compact.join(" ") %>" data-diff-row><span class="<%= Keystone::Ui::TextDiffComponent::NUMBER_CLASSES %>" data-diff-number><%= cell&.dig(:number) %></span><span class="<%= Keystone::Ui::TextDiffComponent::SIGN_CLASSES %>" data-diff-sign><%= cell&.dig(:sign) %></span><span class="<%= Keystone::Ui::TextDiffComponent::TEXT_CLASSES %>" data-diff-text><%= cell&.dig(:text) %></span></div>
7
+ <% end %>
8
+ </div>
9
+ <% end %>
10
+ </div>
11
+ </div>
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Keystone
4
+ module Ui
5
+ class TextDiffComponent < ViewComponent::Base
6
+ SIDES = %w[before after].freeze
7
+ WRAPPER_CLASSES = "ks-code overflow-hidden"
8
+ COLUMNS_CLASSES = "grid grid-cols-1 sm:grid-cols-2"
9
+ SIDE_CLASSES = "ks-code-block min-w-0 overflow-x-auto font-mono text-sm leading-relaxed"
10
+ ROW_CLASSES = "flex h-[1lh]"
11
+ NUMBER_CLASSES = "w-8 shrink-0 select-none text-right"
12
+ SIGN_CLASSES = "w-6 shrink-0 select-none text-center"
13
+ TEXT_CLASSES = "whitespace-pre"
14
+
15
+ def initialize(before:, after:)
16
+ @before = before.to_s.lines(chomp: true)
17
+ @after = after.to_s.lines(chomp: true)
18
+ end
19
+
20
+ def cells(side)
21
+ rows.map { |row| row[SIDES.index(side)] }
22
+ end
23
+
24
+ private
25
+
26
+ def rows
27
+ @rows ||= compare
28
+ end
29
+
30
+ def compare
31
+ before_index = after_index = 0
32
+ rows = []
33
+ while before_index < @before.size || after_index < @after.size
34
+ if before_index < @before.size && after_index < @after.size && @before[before_index] == @after[after_index]
35
+ rows << [ { text: @before[before_index], number: before_index + 1 }, { text: @after[after_index], number: after_index + 1 } ]
36
+ before_index += 1
37
+ after_index += 1
38
+ elsif before_index < @before.size && (after_index == @after.size || shared[before_index + 1][after_index] >= shared[before_index][after_index + 1])
39
+ rows << [ { text: @before[before_index], number: before_index + 1, mark: "ks-diff-removed", sign: "-" }, nil ]
40
+ before_index += 1
41
+ else
42
+ rows << [ nil, { text: @after[after_index], number: after_index + 1, mark: "ks-diff-added", sign: "+" } ]
43
+ after_index += 1
44
+ end
45
+ end
46
+ rows
47
+ end
48
+
49
+ def shared
50
+ @shared ||= begin
51
+ table = Array.new(@before.size + 1) { Array.new(@after.size + 1, 0) }
52
+ (@before.size - 1).downto(0) do |before_index|
53
+ (@after.size - 1).downto(0) do |after_index|
54
+ table[before_index][after_index] = if @before[before_index] == @after[after_index]
55
+ table[before_index + 1][after_index + 1] + 1
56
+ else
57
+ [ table[before_index + 1][after_index], table[before_index][after_index + 1] ].max
58
+ end
59
+ end
60
+ end
61
+ table
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -205,6 +205,10 @@ module KeystoneUiHelper
205
205
  render Keystone::Ui::ProgressComponent.new(**args)
206
206
  end
207
207
 
208
+ def ui_status_dot(**args)
209
+ render Keystone::Ui::StatusDotComponent.new(**args)
210
+ end
211
+
208
212
  def ui_settings_link(**args)
209
213
  render Keystone::Ui::SettingsLinkComponent.new(**args)
210
214
  end
@@ -261,6 +265,10 @@ module KeystoneUiHelper
261
265
  render Keystone::Ui::CodeComponent.new(**args), &block
262
266
  end
263
267
 
268
+ def ui_text_diff(**args)
269
+ render Keystone::Ui::TextDiffComponent.new(**args)
270
+ end
271
+
264
272
  def ui_disclosure(**args, &block)
265
273
  render Keystone::Ui::DisclosureComponent.new(**args), &block
266
274
  end
@@ -73,9 +73,11 @@ module Keystone
73
73
  Keystone::Ui::BucketSeriesComponent,
74
74
  Keystone::Ui::PipelineComponent,
75
75
  Keystone::Ui::CodeComponent,
76
+ Keystone::Ui::TextDiffComponent,
76
77
  Keystone::Ui::DisclosureComponent,
77
78
  Keystone::Ui::ThemeToggleComponent,
78
79
  Keystone::Ui::TimelineComponent,
80
+ Keystone::Ui::StatusDotComponent,
79
81
  Keystone::Ui::CalculationComponent,
80
82
  Keystone::Ui::DesktopBackLinkComponent,
81
83
  Keystone::Ui::BreadcrumbsComponent,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.77.0"
4
+ VERSION = "0.79.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, action menus for a record's Edit and Delete, dashboards with stat cards, charts, funnels, goal buckets and timelines of timed steps, amounts shown in green or red as a gain or loss, pictures held to half the screen, 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 page's main action as a phone top-bar icon or a button fixed to the bottom of the screen, action menus for a record's Edit and Delete, dashboards with stat cards, charts, funnels, goal buckets and timelines of timed steps, amounts shown in green or red as a gain or loss, status dots coloured by state, pictures held to half the screen, 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
  ---
@@ -67,6 +67,7 @@ not available in the app yet, that is `keystone_ui-install`'s job.
67
67
  - `ui_column_picker` — a Columns menu that saves which columns are hidden and their order to an app endpoint.
68
68
  - `ui_button` — a link or a button styled as a button, or a button sending a POST, PATCH or DELETE request.
69
69
  - `ui_badge` — a coloured pill holding a short label.
70
+ - `ui_status_dot` — a small dot coloured by state, with its label read only by screen readers.
70
71
  - `ui_figure` — one amount as inline text, coloured as a gain or a loss.
71
72
  - `ui_picture` — an image never taller than half the screen, optionally opening its full-size file.
72
73
  - `ui_heading` — a heading at one of three sizes, with an optional short note on its right.
@@ -82,6 +83,7 @@ not available in the app yet, that is `keystone_ui-install`'s job.
82
83
  - `ui_stat_card` — a single metric tile with optional change, link and info button.
83
84
  - `ui_copy_button` — a button that copies text to the clipboard.
84
85
  - `ui_code` — a block of code with an optional caption.
86
+ - `ui_text_diff` — two versions of a text side by side, with removed and added lines marked.
85
87
  - `ui_disclosure` — a native expandable section with a clickable summary.
86
88
  - `ui_calculation` — the steps behind a figure, closed under a summary row.
87
89
  - `ui_info` — an inline info button showing a summary, and optional detail, in floating panels.
@@ -602,6 +604,13 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
602
604
  the developer which version of an uploaded image each address points at.
603
605
  - `ui_badge(label:, variant: :neutral, class: nil)` — `variant:` is
604
606
  `:neutral` `:success` `:danger` `:warning` `:info`.
607
+ - `ui_status_dot(state:, label:)` — `state:` is `:neutral` `:success`
608
+ `:danger` `:warning` `:info`, and any other value raises `ArgumentError`
609
+ naming it. `label:` is not shown on screen and is read out by screen
610
+ readers, so pass words that say what the state means. The dot takes the
611
+ colour of a `ui_badge` of the same name. Use it where a badge's words
612
+ would crowd the row, such as beside a name in a list, and ask the
613
+ developer which states a record has and what each one means.
605
614
  - `ui_alert(message:, type: :info, title: nil, dismissible: false, class: nil)`
606
615
  — `type:` is `:info` `:success` `:warning` `:error`, and `dismissible: true`
607
616
  adds a close button.
@@ -619,6 +628,20 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
619
628
  - `ui_code(language: nil, caption: nil)` takes a block holding the code.
620
629
  `caption:` is a strip above it and `language:` sets the `language-*`
621
630
  class for a highlighter.
631
+ - `ui_text_diff(before:, after:)` takes no block. It splits each text into
632
+ lines and draws the earlier version in the left column and the later one
633
+ in the right, stacked with the earlier above below `sm:`. Lines the two
634
+ share sit on the same row. A line only `before:` has is marked removed with
635
+ a `-` and a line only `after:` has is marked added with a `+`, each
636
+ coloured by keystone_ui-styles and each with a
637
+ blank row opposite, so a changed line shows as a removed row followed by
638
+ an added row. Each column numbers its own lines, and a long line scrolls
639
+ sideways inside its column. Lines must match exactly, spaces included, to
640
+ count as shared. A `nil` text is treated as empty, and both are shown as
641
+ plain text. The work grows with the line count of one text times the
642
+ other's, so pass texts a person reads, not whole files of thousands of
643
+ lines. Ask the developer which two versions a screen compares and which
644
+ is the earlier one.
622
645
  - `ui_disclosure(open: false)` takes a block yielding the component. Fill
623
646
  its `summary` slot with the header, and the rest of the block is the body.
624
647
  - `ui_accordion(items: [])` — `items:` is `[{ question:, answer: }, ...]`.
@@ -782,7 +805,9 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
782
805
  shows nothing, a breakdown in one run of text, a `:success` or `:danger`
783
806
  figure in plain colour, a joined funnel with no band, a locked column the
784
807
  others show through, a Columns menu with no greyed name for a hidden
785
- column, or a table row whose caret does not open its detail — the app's Stimulus controllers or keystone_ui-styles version are
808
+ column, a table row whose caret does not open its detail, a text diff whose
809
+ removed and added rows look like its shared rows, or a status dot
810
+ that draws nothing — the app's Stimulus controllers or keystone_ui-styles version are
786
811
  out of date. Stop and hand that part to `keystone_ui-install`, and add no
787
812
  classes to fix it.
788
813
 
@@ -12,8 +12,9 @@ nothing and gives no steps.
12
12
 
13
13
  keystone_ui is a Rails engine gem that supplies a host app's UI as view helpers
14
14
  built on ViewComponent. Screens are built from named pieces — page shells,
15
- sections, panels, grids, forms and fields, search dropdowns, data tables, navigation, cards, stat
16
- tiles, charts, timelines, funnels, goal buckets, pipelines, breakdowns and info buttons —
15
+ sections, panels, grids, forms and fields, search dropdowns, data tables, navigation, cards,
16
+ badges, status dots, stat tiles, charts, timelines, funnels, goal buckets, pipelines, breakdowns, code blocks,
17
+ text diffs and info buttons —
17
18
  instead of hand-written ERB and Tailwind. Every class the UI renders lives in the
18
19
  gem, so two pages built from the same helpers cannot disagree about spacing,
19
20
  colour or dark-mode treatment, and a change to a component reaches every page
@@ -104,6 +105,18 @@ One decision: is keystone_ui set up in the app?
104
105
  - **Action menus.** Each action is a label, an address and an HTTP method. A
105
106
  plain visit is a link, and any other method is a button, so an action that
106
107
  changes data is never a bare link. A delete asks for confirmation by default.
108
+ - **Status states.** A badge and a status dot share five states: neutral,
109
+ success, danger, warning and info. A badge shows its label as text. A status
110
+ dot shows only its state's colour, for places with no room for text, and its label
111
+ is read only by screen readers. A status dot raises `ArgumentError` on any
112
+ other state.
113
+ - **Text diffs.** A text diff compares two texts line by line and shows them
114
+ side by side, stacked on a phone, in the code block's look. Lines the two
115
+ share sit on the same row, a line only the first text has is marked removed
116
+ with a minus, a line only the second has is marked added with a plus, the
117
+ other side shows a blank row beside either one, and each side numbers its own
118
+ lines. On a phone the first text's column sits above the second's. It compares whole lines, so a line with one word
119
+ changed shows as one line removed and one added.
107
120
  - **Semantic colour.** The themed hue is `accent-*` and the themed neutrals are
108
121
  `surface-*`, CSS custom properties whose defaults (blue and zinc) come from
109
122
  the keystone_ui-styles gem. Retheming changes those values, not the
@@ -164,7 +164,7 @@ built on ViewComponent; hook it in before building any screen with those helpers
164
164
  action menu, the action menu, the column picker, multi select, search select, copy button, theme toggle,
165
165
  checkbox row, radio card, option card, file upload and colour picker read
166
166
  these variables. So do the data display components: stat card, chart card,
167
- card link, CTA banner, feature grid, hero, data table, code, accordion,
167
+ card link, CTA banner, feature grid, hero, data table, code, text diff, accordion,
168
168
  disclosure, calculation, info button, breakdown, figure, tab switcher, progress,
169
169
  timeline, funnel, bucket, pipeline and swipe deck.
170
170
  So do the navigation components: navbar, nav item, nav dropdown, bottom nav,
@@ -18,6 +18,7 @@ develop:
18
18
  - ui_hero
19
19
  - ui_modal
20
20
  - ui_badge
21
+ - ui_status_dot
21
22
  - ui_copy_button
22
23
  - ui_card
23
24
  - ui_button
@@ -69,6 +70,7 @@ develop:
69
70
  - ui_bucket_series
70
71
  - ui_pipeline
71
72
  - ui_code
73
+ - ui_text_diff
72
74
  - ui_disclosure
73
75
  - ui_calculation
74
76
  - ui_info
@@ -103,6 +105,7 @@ sources:
103
105
  - app/components/keystone/ui/link_list_component.rb
104
106
  - app/components/keystone/ui/link_list_component.html.erb
105
107
  - app/components/keystone/ui/badge_component.rb
108
+ - app/components/keystone/ui/status_dot_component.rb
106
109
  - app/components/keystone/ui/bottom_nav_component.rb
107
110
  - app/components/keystone/ui/bottom_nav_item_component.rb
108
111
  - app/components/keystone/ui/button_component.rb
@@ -112,6 +115,8 @@ sources:
112
115
  - app/components/keystone/ui/checkbox_row_component.rb
113
116
  - app/components/keystone/ui/checkbox_row_component.html.erb
114
117
  - app/components/keystone/ui/code_component.rb
118
+ - app/components/keystone/ui/text_diff_component.rb
119
+ - app/components/keystone/ui/text_diff_component.html.erb
115
120
  - app/components/keystone/ui/color_picker_component.rb
116
121
  - app/components/keystone/ui/column_picker_component.rb
117
122
  - app/components/keystone/ui/column.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.77.0
4
+ version: 0.79.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider
@@ -214,10 +214,13 @@ files:
214
214
  - app/components/keystone/ui/sortable_list_component.rb
215
215
  - app/components/keystone/ui/stat_card_component.html.erb
216
216
  - app/components/keystone/ui/stat_card_component.rb
217
+ - app/components/keystone/ui/status_dot_component.rb
217
218
  - app/components/keystone/ui/swipe_deck_component.html.erb
218
219
  - app/components/keystone/ui/swipe_deck_component.rb
219
220
  - app/components/keystone/ui/tab_switcher_component.html.erb
220
221
  - app/components/keystone/ui/tab_switcher_component.rb
222
+ - app/components/keystone/ui/text_diff_component.html.erb
223
+ - app/components/keystone/ui/text_diff_component.rb
221
224
  - app/components/keystone/ui/textarea_component.html.erb
222
225
  - app/components/keystone/ui/textarea_component.rb
223
226
  - app/components/keystone/ui/theme_toggle_component.html.erb