Skip to content

Commit

Permalink
feat: FormControlコンポーネントを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
yamakeeeeeeeeen committed Feb 2, 2025
1 parent 7225160 commit ff972c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/views/components/_form_control.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<% if false %>
必要なパラメータ:
- label: ラベルテキスト(必須)
オプションパラメータ:
- classes: 追加のCSSクラス
<% end %>

<% classes ||= "" %>
<% input_id = "input_#{SecureRandom.hex(8)}" %>

<div class="<%= classes %>">
<label
for="<%= input_id %>"
class="block mb-1 text-sm font-bold"
>
<%= label %>
</label>

<%= yield input_id %>
</div>
7 changes: 6 additions & 1 deletion app/views/components/_text_field.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<% classes ||= "" %>
<% placeholder ||= "" %>
<% id ||= nil %>
<% text_field_classes = [
"border border-[var(--textColor)] rounded-md px-4 py-2 text-[var(--textColor)] focus:outline-none focus:ring-2 focus:ring-blue-500",
classes
].join(" ") %>
<input type="text" class="<%= text_field_classes %>" placeholder="<%= placeholder %>" />
<input type="text"
class="<%= text_field_classes %>"
placeholder="<%= placeholder %>"
<%= "id=#{id}" if id.present? %>
/>

0 comments on commit ff972c5

Please sign in to comment.