Class: SolidusAdmin::UI::Forms::Switch::Component

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/solidus_admin/ui/forms/switch/component.rb

Constant Summary collapse

SIZES =
{
  s: 'w-8 h-5 after:w-4 after:h-4 after:checked:translate-x-3',
  m: 'w-10 h-6 after:w-5 after:h-5 after:checked:translate-x-4',
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(size: :m, include_hidden: false, **attributes) ⇒ Component

Returns a new instance of Component.



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
# File 'app/components/solidus_admin/ui/forms/switch/component.rb', line 9

def initialize(size: :m, include_hidden: false, **attributes)
  @size = size
  @attributes = attributes
  @include_hidden = include_hidden
  @attributes[:class] = "
    #{SIZES.fetch(@size)}
    rounded-full after:rounded-full
    appearance-none	inline-block relative p-0.5 cursor-pointer

    outline-none
    focus:ring focus:ring-gray-300 focus:ring-0.5 focus:ring-offset-1
    active:ring active:ring-gray-300 active:ring-0.5 active:ring-offset-1

    disabled:cursor-not-allowed
    after:top-0 after:left-0
    after:content-[''] after:block
    after:transition-all after:duration-300 after:ease-in-out

    bg-gray-200 after:bg-white
    hover:bg-gray-300
    checked:bg-gray-500 checked:hover:bg-gray-70
    disabled:opacity-40
    #{attributes[:class]}
  "
end

Instance Method Details

#callObject



35
36
37
38
39
40
41
42
# File 'app/components/solidus_admin/ui/forms/switch/component.rb', line 35

def call
  input = tag.input(
    type: 'checkbox',
    **@attributes,
  )

  @include_hidden ? hidden_field_tag(@attributes.fetch(:name), false) + input : input
end