-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create search bar component and use it in the header
- Loading branch information
1 parent
2c8e7ed
commit bb9f381
Showing
4 changed files
with
56 additions
and
8 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
app/assets/stylesheets/components/_search_bar_component.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.search-bar{ | ||
display: flex; | ||
column-gap: 0.5em; | ||
background-color: var(--primary-50); | ||
padding: 0.5em; | ||
border-radius: 0.5em; | ||
align-items: center; | ||
|
||
.search-field input{ | ||
padding-inline: 0.5em; | ||
width: 400px; | ||
background-color: transparent; | ||
border: none; | ||
height: 2em; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
class SearchBarComponent < ViewComponent::Base | ||
include ApplicationHelper | ||
erb_template <<-ERB | ||
<%# locals: () -%> | ||
<%= form_with(url: search_path, method: :get, class: 'search-bar') do |f| %> | ||
<div class='search-field'> | ||
<%= f.text_field :q, required: true, placeholder: 'Type your search here...'%> | ||
</div> | ||
<%= render(IconButtonComponent.new(path: 'search', action: :search)) %> | ||
<% end %> | ||
ERB | ||
|
||
def initialize( | ||
search_path:, | ||
method: :get, | ||
data: { turbo: false }, | ||
placeholder: 'Type your search here...' | ||
) | ||
super() | ||
@search_path = search_path | ||
@method = method | ||
@data = data | ||
@placeholder = placeholder | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
<%# locals: () -%> | ||
|
||
<%= form_with(url: search_path, method: :get) do |f| %> | ||
<div> | ||
<%= f.text_field :q, required: true, placeholder: 'Type your search here...'%> | ||
</div> | ||
<%= f.button "search", name: nil do%> | ||
<%= svg_icon_tag "icon_search" %> | ||
<% end %> | ||
<% end %> | ||
<%= render(SearchBarComponent.new(search_path: search_path)) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class SearchBarComponentTest < ViewComponent::TestCase | ||
def test_component_renders_something_useful | ||
# assert_equal( | ||
# %(<span>Hello, components!</span>), | ||
# render_inline(SearchBarComponent.new(message: "Hello, components!")).css("span").to_html | ||
# ) | ||
end | ||
end |