lib/primer/forms/dsl/input.rb in openproject-primer_view_components-0.14.0 vs lib/primer/forms/dsl/input.rb in openproject-primer_view_components-0.15.0
- old
+ new
@@ -43,10 +43,21 @@
DEFAULT_SIZE => "FormControl-medium",
:large => "FormControl-large"
}.freeze
SIZE_OPTIONS = SIZE_MAPPINGS.keys
+ DEFAULT_INPUT_WIDTH = :auto
+ INPUT_WIDTH_MAPPINGS = {
+ DEFAULT_INPUT_WIDTH => "FormControl-input-width--auto",
+ :small => "FormControl-input-width--small",
+ :medium => "FormControl-input-width--medium",
+ :large => "FormControl-input-width--large",
+ :xlarge => "FormControl-input-width--xlarge",
+ :xxlarge => "FormControl-input-width--xxlarge"
+ }.freeze
+ INPUT_WIDTH_OPTIONS = INPUT_WIDTH_MAPPINGS.keys
+
include Primer::ClassNameHelper
attr_reader :builder, :form, :input_arguments, :label_arguments, :caption, :validation_message, :ids, :form_control, :base_id
alias form_control? form_control
@@ -71,10 +82,11 @@
@caption = @input_arguments.delete(:caption)
@validation_message = @input_arguments.delete(:validation_message)
@invalid = @input_arguments.delete(:invalid)
@full_width = @input_arguments.delete(:full_width)
@size = @input_arguments.delete(:size)
+ @input_width = @input_arguments.delete(:input_width)
# If scope_name_to_model is false, the name of the input for eg. `my_field`
# will be `my_field` instead of the Rails default of `model[my_field]`.
#
# We achieve this by passing the `name` option to Rails form builder
@@ -150,10 +162,11 @@
# :nocov:
def remove_input_data(key)
input_data.delete(key)
end
+
# :nocov:
def merge_input_arguments!(arguments)
arguments.each do |k, v|
case k
@@ -224,10 +237,14 @@
def size
@size ||= SIZE_MAPPINGS.include?(@size) ? @size : DEFAULT_SIZE
end
+ def input_width
+ @input_width ||= INPUT_WIDTH_MAPPINGS.include?(@input_width) ? @input_width : DEFAULT_INPUT_WIDTH
+ end
+
def validation_messages
@validation_messages ||=
if validation_message
[validation_message]
elsif builder.object.respond_to?(:errors)
@@ -255,10 +272,11 @@
end
def to_component
raise_for_abstract_method!(__method__)
end
+
# :nocov:
def focusable?
false
end
@@ -307,9 +325,10 @@
# :nocov:
def raise_for_abstract_method!(method_name)
raise NotImplementedError, "subclasses must implement ##{method_name}."
end
+
# :nocov:
end
end
end
end