# frozen_string_literal: true module Ariadne # :nodoc: class FormBuilder < ActionView::Helpers::FormBuilder include ClassNameHelper DEFAULT_SECTION_CLASSES = "pt-8 space-y-6 sm:pt-10 sm:space-y-5" 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 = "text-lg leading-6 font-medium 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 = "mt-1 max-w-2xl text-sm 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 = "block text-sm font-medium text-gray-700 pl-2" def label(object_name, content, ptions = {}, &block) options[:class] = class_names(DEFAULT_LABEL_CLASSES, options.delete(:classes)) super(object_name, content, options, &block) end DEFAULT_TEXT_CLASSES = "shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 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:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 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:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 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 = "shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border border-gray-300 rounded-md" def text_area(method, options = {}) options[:class] = class_names(DEFAULT_TEXTAREA_CLASSES, options.delete(:classes)) super(method, **options) end DEFAULT_EMAIL_CLASSES = "shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 rounded-md" def email_field(method, options = {}) options[:class] = class_names(DEFAULT_EMAIL_CLASSES, options.delete(:classes)) super(method, **options) end DEFAULT_PASSWORD_CLASSES = "appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" def password_field(method, options = {}) options[:class] = class_names(DEFAULT_PASSWORD_CLASSES, options.delete(:classes)) super(method, **options) end end end