summaryrefslogtreecommitdiff
path: root/app/components/pajamas/checkbox_tag_component.rb
blob: 45e88588059d19f08eff7aea8a848ca1cc72c387 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

# Renders a Pajamas compliant checkbox element
module Pajamas
  class CheckboxTagComponent < Pajamas::Component
    include Pajamas::Concerns::CheckboxRadioLabelWithHelpText
    include Pajamas::Concerns::CheckboxRadioOptions

    renders_one :label
    renders_one :help_text

    def initialize(
      name:,
      label_options: {},
      checkbox_options: {},
      value: '1',
      checked: false
    )
      @name = name
      @label_options = label_options
      @input_options = checkbox_options
      @value = value
      @checked = checked
    end

    private

    attr_reader(
      :name,
      :label_options,
      :input_options,
      :value,
      :checked
    )

    def label_content
      label
    end

    def help_text_content
      help_text
    end
  end
end