# frozen_string_literal: true module Ariadne # :nodoc: # Many of the form methods simply call out to the corresponding ActionView::Helpers::FormBuilder methods, # documented at https://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html, with # default Tailwind classes applied. class FormBuilder < ActionView::Helpers::FormBuilder include ClassNameHelper DEFAULT_SECTION_CLASSES = "ariadne-space-y-6 ariadne-px-4" def section(classes: "", attributes: {}, &block) actual_classes = class_names(DEFAULT_SECTION_CLASSES, classes) options = { class: actual_classes, **attributes } @template.content_tag(:div, **options, &block) end DEFAULT_SECTION_HEADING_CLASSES = "ariadne-text-lg ariadne-leading-6 ariadne-py-4 ariadne-font-medium ariadne-text-gray-900" def heading(tag: :h3, classes: "", attributes: {}, &block) actual_classes = class_names(DEFAULT_SECTION_HEADING_CLASSES, classes) options = { class: actual_classes, **attributes } @template.content_tag(tag, **options, &block) end DEFAULT_SECTION_SUBHEADING_CLASSES = "ariadne-mt-1 ariadne-max-w-2xl ariadne-text-sm ariadne-text-gray-500" def subheading(classes: "", attributes: {}, &block) actual_classes = class_names(DEFAULT_SECTION_SUBHEADING_CLASSES, classes) options = { class: actual_classes, **attributes } @template.content_tag(:p, **options, &block) end DEFAULT_LABEL_CLASSES = "ariadne-block ariadne-text-sm ariadne-font-medium ariadne-text-gray-700 ariadne-pl-2" def label(method, text = nil, options = {}, &block) options[:class] = class_names(DEFAULT_LABEL_CLASSES, options.delete(:classes)) super(method, text, options, &block) end DEFAULT_TEXT_CLASSES = "ariadne-shadow-sm focus:ariadne-ring-slate-500 focus:ariadne-border-slate-500 ariadne-block ariadne-w-full sm:ariadne-text-sm ariadne-border-gray-300 ariadne-rounded-md" def text_field(method, options = {}) options[:class] = class_names(DEFAULT_TEXT_CLASSES, options.delete(:classes)) super(method, **options) end DEFAULT_CHECKBOX_CLASSES = "focus:ariadne-ring-slate-500 ariadne-h-4 ariadne-w-4 ariadne-text-slate-600 ariadne-border-slate-300 ariadne-rounded" def check_box(method, options = {}, checked_value = "1", unchecked_value = "0") options[:class] = class_names(DEFAULT_CHECKBOX_CLASSES, options.delete(:classes)) super(method, options, checked_value, unchecked_value) end DEFAULT_RADIO_CLASSES = "focus:ariadne-ring-slate-500 ariadne-h-4 ariadne-w-4 ariadne-text-slate-600 ariadne-border-gray-300 ariadne-rounded" def radio_button(method, tag_value, options = {}) options[:class] = class_names(DEFAULT_RADIO_CLASSES, options.delete(:classes)) super(method, tag_value, **options) end DEFAULT_TEXTAREA_CLASSES = "ariadne-shadow-sm focus:ariadne-ring-slate-500 focus:ariadne-border-slate-500 ariadne-block ariadne-w-full sm:ariadne-text-sm ariadne-border ariadne-border-gray-300 ariadne-rounded-md" def text_area(method, options = {}) options[:class] = class_names(DEFAULT_TEXTAREA_CLASSES, options.delete(:classes)) super(method, **options) end DEFAULT_EMAIL_CLASSES = "ariadne-shadow-sm focus:ariadne-ring-slate-500 focus:ariadne-border-slate-500 ariadne-block ariadne-w-full sm:ariadne-text-sm ariadne-border-gray-300 ariadne-rounded-md" def email_field(method, options = {}) options[:class] = class_names(DEFAULT_EMAIL_CLASSES, options.delete(:classes)) super(method, **options) end DEFAULT_PASSWORD_CLASSES = "ariadne-appearance-none ariadne-block ariadne-w-full ariadne-px-3 ariadne-py-2 ariadne-border ariadne-border-gray-300 ariadne-rounded-md ariadne-shadow-sm ariadne-placeholder-gray-400 focus:ariadne-outline-none focus:ariadne-ring-slate-500 focus:ariadne-border-slate-500 sm:ariadne-text-sm" def password_field(method, options = {}) options[:class] = class_names(DEFAULT_PASSWORD_CLASSES, options.delete(:classes)) super(method, **options) end end end