|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +class Views::Docs::NativeSelect < Views::Base |
| 4 | + def view_template |
| 5 | + component = "NativeSelect" |
| 6 | + |
| 7 | + div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do |
| 8 | + render Docs::Header.new(title: "Native Select", description: "A styled native HTML select element with consistent design system integration.") |
| 9 | + |
| 10 | + Heading(level: 2) { "Usage" } |
| 11 | + |
| 12 | + render Docs::VisualCodeExample.new(title: "Default", context: self) do |
| 13 | + <<~RUBY |
| 14 | + div(class: "grid w-full max-w-sm items-center gap-1.5") do |
| 15 | + NativeSelect do |
| 16 | + NativeSelectOption(value: "") { "Select a fruit" } |
| 17 | + NativeSelectOption(value: "apple") { "Apple" } |
| 18 | + NativeSelectOption(value: "banana") { "Banana" } |
| 19 | + NativeSelectOption(value: "blueberry") { "Blueberry" } |
| 20 | + NativeSelectOption(value: "pineapple") { "Pineapple" } |
| 21 | + end |
| 22 | + end |
| 23 | + RUBY |
| 24 | + end |
| 25 | + |
| 26 | + render Docs::VisualCodeExample.new(title: "Groups", description: "Use NativeSelectGroup to organize options into categories.", context: self) do |
| 27 | + <<~RUBY |
| 28 | + div(class: "grid w-full max-w-sm items-center gap-1.5") do |
| 29 | + NativeSelect do |
| 30 | + NativeSelectOption(value: "") { "Select a department" } |
| 31 | + NativeSelectGroup(label: "Engineering") do |
| 32 | + NativeSelectOption(value: "frontend") { "Frontend" } |
| 33 | + NativeSelectOption(value: "backend") { "Backend" } |
| 34 | + NativeSelectOption(value: "devops") { "DevOps" } |
| 35 | + end |
| 36 | + NativeSelectGroup(label: "Sales") do |
| 37 | + NativeSelectOption(value: "account_executive") { "Account Executive" } |
| 38 | + NativeSelectOption(value: "sales_development") { "Sales Development" } |
| 39 | + end |
| 40 | + end |
| 41 | + end |
| 42 | + RUBY |
| 43 | + end |
| 44 | + |
| 45 | + render Docs::VisualCodeExample.new(title: "Disabled", description: "Add the disabled attribute to the NativeSelect component to disable the select.", context: self) do |
| 46 | + <<~RUBY |
| 47 | + div(class: "grid w-full max-w-sm items-center gap-1.5") do |
| 48 | + NativeSelect(disabled: true) do |
| 49 | + NativeSelectOption(value: "") { "Select a fruit" } |
| 50 | + NativeSelectOption(value: "apple") { "Apple" } |
| 51 | + NativeSelectOption(value: "banana") { "Banana" } |
| 52 | + NativeSelectOption(value: "blueberry") { "Blueberry" } |
| 53 | + end |
| 54 | + end |
| 55 | + RUBY |
| 56 | + end |
| 57 | + |
| 58 | + render Docs::VisualCodeExample.new(title: "Invalid", description: "Use aria-invalid to show validation errors.", context: self) do |
| 59 | + <<~RUBY |
| 60 | + div(class: "grid w-full max-w-sm items-center gap-1.5") do |
| 61 | + NativeSelect(aria: {invalid: "true"}) do |
| 62 | + NativeSelectOption(value: "") { "Select a fruit" } |
| 63 | + NativeSelectOption(value: "apple") { "Apple" } |
| 64 | + NativeSelectOption(value: "banana") { "Banana" } |
| 65 | + NativeSelectOption(value: "blueberry") { "Blueberry" } |
| 66 | + end |
| 67 | + end |
| 68 | + RUBY |
| 69 | + end |
| 70 | + |
| 71 | + Heading(level: 2) { "Native Select vs Select" } |
| 72 | + |
| 73 | + div(class: "space-y-2 text-sm text-muted-foreground") do |
| 74 | + p { "NativeSelect: Choose for native browser behavior, superior performance, or mobile-optimized dropdowns." } |
| 75 | + p { "Select: Choose for custom styling, animations, or complex interactions." } |
| 76 | + end |
| 77 | + |
| 78 | + render Components::ComponentSetup::Tabs.new(component_name: component) |
| 79 | + |
| 80 | + render Docs::ComponentsTable.new(component_files(component)) |
| 81 | + end |
| 82 | + end |
| 83 | +end |
0 commit comments