Class: Panda::Core::Admin::SecretFieldComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/panda/core/admin/secret_field_component.rb

Constant Summary

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, masked: true, **attrs) ⇒ SecretFieldComponent

Returns a new instance of SecretFieldComponent.



7
8
9
10
11
# File 'app/components/panda/core/admin/secret_field_component.rb', line 7

def initialize(value:, masked: true, **attrs)
  @value = value
  @masked = masked
  super(**attrs)
end

Instance Attribute Details

#maskedObject (readonly)

Returns the value of attribute masked.



13
14
15
# File 'app/components/panda/core/admin/secret_field_component.rb', line 13

def masked
  @masked
end

#valueObject (readonly)

Returns the value of attribute value.



13
14
15
# File 'app/components/panda/core/admin/secret_field_component.rb', line 13

def value
  @value
end

Instance Method Details

#button_classesObject



25
26
27
# File 'app/components/panda/core/admin/secret_field_component.rb', line 25

def button_classes
  "shrink-0 btn btn-secondary transition"
end

#display_valueObject



15
16
17
18
19
20
21
22
23
# File 'app/components/panda/core/admin/secret_field_component.rb', line 15

def display_value
  return value unless masked && value.present?

  if value.length > 4
    "\u2022" * 12 + value[-4..]
  else
    "\u2022" * value.length
  end
end