debian-mirror-gitlab/app/components/pajamas/checkbox_component.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.6 KiB
Ruby
Raw Permalink Normal View History

2022-07-23 23:45:48 +05:30
# frozen_string_literal: true
# Renders a Pajamas compliant checkbox element
2022-08-27 11:52:29 +05:30
# An instance of `ActionView::Helpers::FormBuilder` must be passed as the `form` argument.
# The easiest way to use this component is by using the `gitlab_ui_checkbox_component` helper.
# See https://docs.gitlab.com/ee/development/fe_guide/haml.html#gitlab_ui_checkbox_component
# To use a checkbox without an instance of `ActionView::Helpers::FormBuilder` use `CheckboxTagComponent`.
2022-07-23 23:45:48 +05:30
module Pajamas
class CheckboxComponent < Pajamas::Component
include Pajamas::Concerns::CheckboxRadioLabelWithHelpText
include Pajamas::Concerns::CheckboxRadioOptions
renders_one :label
renders_one :help_text
def initialize(
form:,
method:,
label: nil,
help_text: nil,
label_options: {},
checkbox_options: {},
checked_value: '1',
unchecked_value: '0'
)
@form = form
@method = method
@label_argument = label
@help_text_argument = help_text
@label_options = label_options
@input_options = checkbox_options
@checked_value = checked_value
@unchecked_value = unchecked_value
@value = checked_value if checkbox_options[:multiple]
end
2022-08-27 11:52:29 +05:30
private
2022-07-23 23:45:48 +05:30
attr_reader(
:form,
:method,
:label_argument,
:help_text_argument,
:label_options,
:input_options,
:checked_value,
:unchecked_value,
:value
)
def label_content
label? ? label : label_argument
end
def help_text_content
help_text? ? help_text : help_text_argument
end
end
end