From 9fed41e2880150dc141ebdf68460b48f9fccc94b Mon Sep 17 00:00:00 2001 From: David Alejandro <15317732+davidalejandroaguilar@users.noreply.github.com> Date: Wed, 9 Oct 2024 19:14:03 +0000 Subject: [PATCH] Link to Github code from sidebar for undocumented components --- app/models/component.rb | 4 ++++ app/views/components/shared/github_svg.rb | 10 +++++++++- app/views/components/sidebar.rb | 19 ++++++++++++------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/models/component.rb b/app/models/component.rb index 1a248c0..b263a58 100644 --- a/app/models/component.rb +++ b/app/models/component.rb @@ -52,6 +52,10 @@ def implemented? "PhlexyUI::#{name}".safe_constantize.present? end + def github_url + "https://github.com/PhlexyUI/phlexy_ui/blob/main/lib/phlexy_ui/#{name.underscore}.rb" + end + private def file_exists? diff --git a/app/views/components/shared/github_svg.rb b/app/views/components/shared/github_svg.rb index d7275ed..144d919 100644 --- a/app/views/components/shared/github_svg.rb +++ b/app/views/components/shared/github_svg.rb @@ -1,9 +1,13 @@ module Shared class GithubSvg < ApplicationComponent + def initialize(**options) + @classes = options[:class] || "w-5 h-5" + end + def view_template svg( viewbox: "0 0 16 16", - class: "w-5 h-5", + class: classes, fill: "currentColor", aria_hidden: "true" ) do |s| @@ -13,5 +17,9 @@ def view_template ) end end + + private + + attr_reader :classes end end diff --git a/app/views/components/sidebar.rb b/app/views/components/sidebar.rb index 2b6696c..31069f6 100644 --- a/app/views/components/sidebar.rb +++ b/app/views/components/sidebar.rb @@ -62,18 +62,23 @@ def view_template ) elsif component.implemented? link_to( - "#", - class: "!cursor-default", - data: {turbo_frame: :content} + component.github_url, + class: "!cursor-alias", + data: {turbo_frame: :content}, + target: "_blank" ) do - span class: "opacity-50" do + span do component.name end - Tooltip tip: "Implemented, not documented" do - Badge :outline, :info, class: "opacity-50" do - "Undocumented" + div class: "flex gap-2 justify-end items-center" do + Tooltip tip: "Implemented, undocumented" do + Badge :outline, :info, :sm, class: "opacity-50" do + "Undocumented" + end end + + render GithubSvg.new(class: "w-4 h-4 opacity-50") end end else