From 0b459207c6f3de9e7cdb57e854ac01a3f6778713 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 5 Sep 2023 17:50:21 +0200 Subject: [PATCH] Add a ui/panel component --- .../solidus_admin/ui/panel/component.html.erb | 36 +++++++++++ .../solidus_admin/ui/panel/component.js | 14 +++++ .../solidus_admin/ui/panel/component.rb | 12 ++++ .../solidus_admin/ui/panel/component.yml | 4 ++ .../ui/panel/component_preview.rb | 10 +++ .../panel/component_preview/overview.html.erb | 63 +++++++++++++++++++ .../solidus_admin/ui/panel/component_spec.rb | 9 +++ 7 files changed, 148 insertions(+) create mode 100644 admin/app/components/solidus_admin/ui/panel/component.html.erb create mode 100644 admin/app/components/solidus_admin/ui/panel/component.js create mode 100644 admin/app/components/solidus_admin/ui/panel/component.rb create mode 100644 admin/app/components/solidus_admin/ui/panel/component.yml create mode 100644 admin/spec/components/previews/solidus_admin/ui/panel/component_preview.rb create mode 100644 admin/spec/components/previews/solidus_admin/ui/panel/component_preview/overview.html.erb create mode 100644 admin/spec/components/solidus_admin/ui/panel/component_spec.rb diff --git a/admin/app/components/solidus_admin/ui/panel/component.html.erb b/admin/app/components/solidus_admin/ui/panel/component.html.erb new file mode 100644 index 00000000000..38fd349fb2c --- /dev/null +++ b/admin/app/components/solidus_admin/ui/panel/component.html.erb @@ -0,0 +1,36 @@ +
+ <% if @title %> +
+ <%= @title %> + <%= render component('ui/toggletip').new(guide: @title_hint, position: :left) if @title_hint %> +
+ <% end %> + + <% if content&.present? %> +
+ <%= content %> +
+ <% end %> + + <% if actions? %> +
+ <%= actions %> +
+ <% end %> +
diff --git a/admin/app/components/solidus_admin/ui/panel/component.js b/admin/app/components/solidus_admin/ui/panel/component.js new file mode 100644 index 00000000000..b6e2b996c67 --- /dev/null +++ b/admin/app/components/solidus_admin/ui/panel/component.js @@ -0,0 +1,14 @@ +import { Controller } from '@hotwired/stimulus' + +export default class extends Controller { + static targets = ['output'] + + typed(event) { + this.text = event.currentTarget.value + this.render() + } + + render() { + this.outputTarget.innerText = this.text + } +} diff --git a/admin/app/components/solidus_admin/ui/panel/component.rb b/admin/app/components/solidus_admin/ui/panel/component.rb new file mode 100644 index 00000000000..0c9523742ed --- /dev/null +++ b/admin/app/components/solidus_admin/ui/panel/component.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class SolidusAdmin::UI::Panel::Component < SolidusAdmin::BaseComponent + renders_one :actions + + # @param title [String] the title of the panel + # @param title_hint [String] the title hint of the panel + def initialize(title: nil, title_hint: nil) + @title = title + @title_hint = title_hint + end +end diff --git a/admin/app/components/solidus_admin/ui/panel/component.yml b/admin/app/components/solidus_admin/ui/panel/component.yml new file mode 100644 index 00000000000..6fcfbdd6df7 --- /dev/null +++ b/admin/app/components/solidus_admin/ui/panel/component.yml @@ -0,0 +1,4 @@ +# Add your component translations here. +# Use the translation in the example in your template with `t(".hello")`. +en: + hello: "Hello world!" diff --git a/admin/spec/components/previews/solidus_admin/ui/panel/component_preview.rb b/admin/spec/components/previews/solidus_admin/ui/panel/component_preview.rb new file mode 100644 index 00000000000..c6e96d0e5c5 --- /dev/null +++ b/admin/spec/components/previews/solidus_admin/ui/panel/component_preview.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +# @component "ui/panel" +class SolidusAdmin::UI::Panel::ComponentPreview < ViewComponent::Preview + include SolidusAdmin::Preview + + def overview + render_with_template + end +end diff --git a/admin/spec/components/previews/solidus_admin/ui/panel/component_preview/overview.html.erb b/admin/spec/components/previews/solidus_admin/ui/panel/component_preview/overview.html.erb new file mode 100644 index 00000000000..a96f55e179a --- /dev/null +++ b/admin/spec/components/previews/solidus_admin/ui/panel/component_preview/overview.html.erb @@ -0,0 +1,63 @@ +
+
+ Content only +
+ + <%= render current_component.new do %> + + <% end %> +
+ +
+
+ With title +
+ + <%= render current_component.new(title: "SEO") do %> + + <% end %> +
+ +
+
+ With title and hint +
+ + <%= render current_component.new(title: "SEO", title_hint: "Search Engine Optimization") do %> + + <% end %> +
+ +
+
+ With title, hint, and actions +
+ + <%= render current_component.new(title: "SEO", title_hint: "Search Engine Optimization") do |panel| %> + + + <% panel.with_actions do %> + foo action + <% end %> + <% end %> +
+ +
+
+ With no content +
+ + <%= render current_component.new(title: "SEO", title_hint: "Search Engine Optimization").with_actions_content("foo action") %> +
diff --git a/admin/spec/components/solidus_admin/ui/panel/component_spec.rb b/admin/spec/components/solidus_admin/ui/panel/component_spec.rb new file mode 100644 index 00000000000..1da12566322 --- /dev/null +++ b/admin/spec/components/solidus_admin/ui/panel/component_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe SolidusAdmin::UI::Panel::Component, type: :component do + it "renders the overview preview" do + render_preview(:overview) + end +end