Skip to content

Commit

Permalink
Allow size override on heading
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed Feb 7, 2024
1 parent 01c5096 commit 54ad10d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/components/tailwind/heading.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<h1 class="text-4xl font-bold text-navy font-display max-w-4xl <%= @extra_classes %>">
<h1 class="<%= @size_class %> font-bold text-navy font-display max-w-4xl <%= @extra_classes %>">
<%= content %>
</h1>
15 changes: 13 additions & 2 deletions app/components/tailwind/heading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@ module Tailwind
class Heading < ViewComponent::Base
extend T::Sig

sig { params(tag: Symbol, extra_classes: String).void }
def initialize(tag:, extra_classes: "")
# TODO: Perhaps we should allow the size override to work by saying we want an h1 heading but with the styling of an h2?
sig { params(tag: Symbol, size: T.nilable(String), extra_classes: String).void }
def initialize(tag:, size: nil, extra_classes: "")
super

raise "Invalid tag" unless tag == :h1

@extra_classes = extra_classes

case size
when "3xl"
@size_class = T.let("text-3xl", String)
# 4xl is the default size for h1
when "4xl", nil
@size_class = T.let("text-4xl", String)
else
raise "Unexpected size #{size}"
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<% if applications %>
<section class="pt-16">
<%# TODO: This is smaller than the "standard" h1 heading defined in the component %>
<h1 class="text-3xl font-bold text-navy font-display">Search results</h1>
<%= render Tailwind::Heading.new(tag: :h1, size: "3xl").with_content("Search results") %>

<div class="flex justify-between pt-6">
<div>
Expand Down

0 comments on commit 54ad10d

Please sign in to comment.