Skip to content

Commit

Permalink
Merge pull request #102 from PhlexUI/cirdes/add-form-component
Browse files Browse the repository at this point in the history
Adding form Component
  • Loading branch information
cirdes authored Aug 25, 2024
2 parents 9c1a9ca + 8413f7f commit 9456810
Show file tree
Hide file tree
Showing 25 changed files with 846 additions and 656 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ group :development do
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
gem "standard"
gem "dockerfile-rails", ">= 1.6"
end

group :test do
Expand All @@ -76,5 +77,4 @@ gem "phlex-rails"
gem "phlex_ui", github: "PhlexUI/phlex_ui", branch: "v1"
# gem "phlex_ui", path: "../phlex_ui"

gem "dockerfile-rails", ">= 1.6", group: :development
gem "pry"
5 changes: 2 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
GIT
remote: https://github.com/PhlexUI/phlex_ui.git
revision: c0b011e9c5db8fbbad561298a4560edc8518b958
revision: 2bfac725d3a97324297a6c8460946e11ff71db45
branch: v1
specs:
phlex_ui (0.1.10)
phlex (~> 1.10)
rouge (~> 4.2.0)
tailwind_merge (>= 0.12)
zeitwerk (~> 2.6)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -299,7 +298,7 @@ GEM
railties (>= 6.0.0)
stringio (3.1.1)
strscan (3.1.0)
tailwind_merge (0.12.0)
tailwind_merge (0.12.2)
lru_redux (~> 1.1)
thor (1.3.1)
timeout (0.4.1)
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/docs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def dropdown_menu
render Docs::DropdownMenuView.new
end

def form
render Docs::FormView.new
end

def hover_card
render Docs::HoverCardView.new
end
Expand Down
1 change: 1 addition & 0 deletions app/views/components/shared/menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def components
{name: "Date Picker", path: helpers.docs_date_picker_path},
{name: "Dialog / Modal", path: helpers.docs_dialog_path},
{name: "Dropdown Menu", path: helpers.docs_dropdown_menu_path},
{name: "Form", path: helpers.docs_form_path},
{name: "Input", path: helpers.docs_input_path},
{name: "Hover Card", path: helpers.docs_hover_card_path},
{name: "Link", path: helpers.docs_link_path},
Expand Down
61 changes: 33 additions & 28 deletions app/views/docs/combobox_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,46 @@ class Docs::ComboboxView < ApplicationView

def view_template
div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do
render Docs::Header.new(title: "Combobox", description: "Autocomplete input and command palette with a list of suggestions.", premium: @premium)
render Docs::Header.new(title: "Combobox", description: "Autocomplete input and command palette with a list of suggestions.")

TypographyH2 { "Usage" }

render Docs::VisualCodeExample.new(title: "Example", context: self, premium: @premium) do
render Docs::VisualCodeExample.new(title: "Example", context: self) do
@@code_example = <<~RUBY
Combobox do
ComboboxTrigger(placeholder: "Select event...", aria_controls: "list")
ComboboxContent(id: "list") do
ComboboxSearchInput(placeholder: "Search event...")
ComboboxList do
ComboboxEmpty { "No results found." }
ComboboxGroup(heading: "Suggestions") do
ComboboxItem(value: "railsworld") do
span { "Rails World" }
end
ComboboxItem(value: "tropicalrb") do
span { "Tropical.rb" }
end
ComboboxItem(value: "friendly.rb") do
span { "Friendly.rb" }
div(class: "w-96") do
Combobox do
ComboboxInput()
ComboboxTrigger do
ComboboxValue(placeholder: "Select event...")
end
ComboboxContent do
ComboboxSearchInput(placeholder: "Search event...")
ComboboxList do
ComboboxEmpty { "No results found." }
ComboboxGroup(heading: "Suggestions") do
ComboboxItem(value: "railsworld") do
span { "Rails World" }
end
ComboboxItem(value: "tropicalrb") do
span { "Tropical.rb" }
end
ComboboxItem(value: "friendly.rb") do
span { "Friendly.rb" }
end
end
end
ComboboxSeparator()
ComboboxSeparator()
ComboboxGroup(heading: "Others") do
ComboboxItem(value: "railsconf") do
span { "RailsConf" }
end
ComboboxItem(value: "euruko") do
span { "Euruko" }
end
ComboboxItem(value: "rubykaigi") do
span { "RubyKaigi" }
ComboboxGroup(heading: "Others") do
ComboboxItem(value: "railsconf") do
span { "RailsConf" }
end
ComboboxItem(value: "euruko") do
span { "Euruko" }
end
ComboboxItem(value: "rubykaigi") do
span { "RubyKaigi" }
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/docs/date_picker_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def view_template
Popover(options: { trigger: 'focusin' }) do
PopoverTrigger(class: 'w-full') do
div(class: 'grid w-full max-w-sm items-center gap-1.5') do
Label(for: "date") { "Select a date" }
label(for: "date") { "Select a date" }
Input(type: 'string', placeholder: "Select a date", class: 'rounded-md border shadow', id: 'date', data_controller: 'input')
end
end
Expand Down
147 changes: 147 additions & 0 deletions app/views/docs/form_view.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# frozen_string_literal: true

class Docs::FormView < ApplicationView
@@code_example = nil

def view_template
div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do
render Docs::Header.new(title: "Form", description: "Building forms with built-in client-side validations.")

TypographyH2 { "Usage" }

render Docs::VisualCodeExample.new(title: "Example", context: self) do
@@code_example = <<~RUBY
Form(class: "w-2/3 space-y-6") do
FormField do
FormFieldLabel { "Default error" }
Input(placeholder: "Joel Drapper", required: true, minlength: "3") { "Joel Drapper" }
FormFieldHint()
FormFieldError()
end
Button(type: "submit") { "Save" }
end
RUBY
end

render Docs::VisualCodeExample.new(title: "Custom error message", context: self) do
<<~RUBY
Form(class: "w-2/3 space-y-6") do
FormField do
FormFieldLabel { "Custom error message" }
Input(placeholder: "[email protected]", required: true, data_value_missing: "Custom error message")
FormFieldError()
end
Button(type: "submit") { "Save" }
end
RUBY
end

render Docs::VisualCodeExample.new(title: "Backend error", context: self) do
<<~RUBY
Form(class: "w-2/3 space-y-6") do
FormField do
FormFieldLabel { "Backend error" }
Input(placeholder: "Joel Drapper", required: true)
FormFieldError { "Error from backend" }
end
Button(type: "submit") { "Save" }
end
RUBY
end

render Docs::VisualCodeExample.new(title: "Checkbox", context: self) do
<<~RUBY
Form(class: "w-2/3 space-y-6") do
FormField do
Checkbox(required: true)
label(
class:
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
) { " Accept terms and conditions " }
FormFieldError()
end
Button(type: "submit") { "Save" }
end
RUBY
end

render Docs::VisualCodeExample.new(title: "Select", context: self) do
<<~RUBY
Form(class: "w-2/3 space-y-6") do
FormField do
FormFieldLabel { "Select" }
Select do
SelectInput(required: true)
SelectTrigger do
SelectValue(placeholder: "Select a fruit")
end
SelectContent() do
SelectGroup do
SelectLabel { "Fruits" }
SelectItem(value: "apple") { "Apple" }
SelectItem(value: "orange") { "Orange" }
SelectItem(value: "banana") { "Banana" }
SelectItem(value: "watermelon") { "Watermelon" }
end
end
end
FormFieldError()
end
Button(type: "submit") { "Save" }
end
RUBY
end

render Docs::VisualCodeExample.new(title: "Combobox", context: self) do
<<~RUBY
Form(class: "w-2/3 space-y-6") do
FormField do
FormFieldLabel { "Combobox" }
Combobox do
ComboboxInput(required: true)
ComboboxTrigger do
ComboboxValue(placeholder: "Select event...")
end
ComboboxContent do
ComboboxSearchInput(placeholder: "Search event...")
ComboboxList do
ComboboxEmpty { "No results found." }
ComboboxGroup(heading: "Suggestions") do
ComboboxItem(value: "railsworld") do
span { "Rails World" }
end
ComboboxItem(value: "tropicalrb") do
span { "Tropical.rb" }
end
ComboboxItem(value: "friendly.rb") do
span { "Friendly.rb" }
end
end
ComboboxSeparator()
ComboboxGroup(heading: "Others") do
ComboboxItem(value: "railsconf") do
span { "RailsConf" }
end
ComboboxItem(value: "euruko") do
span { "Euruko" }
end
ComboboxItem(value: "rubykaigi") do
span { "RubyKaigi" }
end
end
end
end
end
FormFieldError()
end
Button(type: "submit") { "Save" }
end
RUBY
end

render Docs::ComponentsTable.new(components("Form", @@code_example), component_files("Form"))
end
end
end
45 changes: 5 additions & 40 deletions app/views/docs/input_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ def view_template
render Docs::VisualCodeExample.new(title: "File", context: self) do
<<~RUBY
div(class: "grid w-full max-w-sm items-center gap-1.5") do
FormItem do
Label(for: "picture") { "Picture" }
Input(type: "file", id: "picture")
end
label(for: "picture") { "Picture" }
Input(type: "file", id: "picture")
end
RUBY
end
Expand All @@ -37,21 +35,8 @@ def view_template
render Docs::VisualCodeExample.new(title: "With label", context: self) do
<<~RUBY
div(class: 'grid w-full max-w-sm items-center gap-1.5') do
FormItem do
Label(for: "email1") { "Email" }
Input(type: "email", placeholder: "Email", id: "email1")
end
end
RUBY
end

render Docs::VisualCodeExample.new(title: "With error", context: self) do
<<~RUBY
div(class: 'grid w-full max-w-sm items-center gap-1.5') do
FormItem do
Label(for: "email1") { "Email" }
Input(type: "email", placeholder: "Email", id: "email1", value: "joel@mail", error: "Invalid email address")
end
label(for: "email1") { "Email" }
Input(type: "email", placeholder: "Email", id: "email1")
end
RUBY
end
Expand All @@ -65,21 +50,6 @@ def view_template
RUBY
end

render Docs::VisualCodeExample.new(title: "Form (Deconstructed)", context: self) do
<<~RUBY
Form(class: 'w-full max-w-sm') do
FormSpacer do
FormItem do
Label(for: "username") { "Username" }
Input(type: "string", placeholder: "Username", id: "username")
Hint { "Can only contain letters, numbers, and underscores." }
end
Button(type: "submit") { "Submit" }
end
end
RUBY
end

render Docs::ComponentsTable.new(components)
end
end
Expand All @@ -89,12 +59,7 @@ def view_template
def components
[
Docs::ComponentStruct.new(name: "InputController", source: "https://github.com/PhlexUI/phlex_ui_stimulus/blob/main/controllers/input_controller.js", built_using: :stimulus),
Docs::ComponentStruct.new(name: "Input", source: "https://github.com/PhlexUI/phlex_ui/blob/main/lib/phlex_ui/input.rb", built_using: :phlex),
Docs::ComponentStruct.new(name: "Label", source: "https://github.com/PhlexUI/phlex_ui/blob/main/lib/phlex_ui/label.rb", built_using: :phlex),
Docs::ComponentStruct.new(name: "Hint", source: "https://github.com/PhlexUI/phlex_ui/blob/main/lib/phlex_ui/hint.rb", built_using: :phlex),
Docs::ComponentStruct.new(name: "Form", source: "https://github.com/PhlexUI/phlex_ui/blob/main/lib/phlex_ui/form.rb", built_using: :phlex),
Docs::ComponentStruct.new(name: "FormSpacer", source: "https://github.com/PhlexUI/phlex_ui/blob/main/lib/phlex_ui/form/spacer.rb", built_using: :phlex),
Docs::ComponentStruct.new(name: "FormItem", source: "https://github.com/PhlexUI/phlex_ui/blob/main/lib/phlex_ui/form/item.rb", built_using: :phlex)
Docs::ComponentStruct.new(name: "Input", source: "https://github.com/PhlexUI/phlex_ui/blob/main/lib/phlex_ui/input.rb", built_using: :phlex)
]
end
end
Loading

0 comments on commit 9456810

Please sign in to comment.