Class: LightningUiKit::CopyInputComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/lightning_ui_kit/copy_input_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(value:, label: nil, description: nil, secret: false, **options) ⇒ CopyInputComponent

Returns a new instance of CopyInputComponent.



2
3
4
5
6
7
8
# File 'app/components/lightning_ui_kit/copy_input_component.rb', line 2

def initialize(value:, label: nil, description: nil, secret: false, **options)
  @value = value
  @label = label
  @description = description
  @secret = secret
  @options = options
end

Instance Method Details

#action_button_classesObject



47
48
49
# File 'app/components/lightning_ui_kit/copy_input_component.rb', line 47

def action_button_classes
  "lui:flex lui:items-center lui:justify-center lui:px-3 lui:border-l lui:border-border lui:text-foreground-muted lui:hover:text-foreground lui:hover:bg-surface-hover lui:transition-colors lui:cursor-pointer lui:focus:outline-hidden"
end

#classesObject



10
11
12
# File 'app/components/lightning_ui_kit/copy_input_component.rb', line 10

def classes
  merge_classes(["lui:[&>[data-slot=label]+[data-slot=description]]:mt-1 lui:[&>[data-slot=label]+[data-slot=control]]:mt-3 lui:[&>[data-slot=description]+[data-slot=control]]:mt-3 lui:*:data-[slot=label]:font-medium", @options[:class]].compact.join(" "))
end

#control_classesObject



35
36
37
# File 'app/components/lightning_ui_kit/copy_input_component.rb', line 35

def control_classes
  "lui:relative lui:flex lui:w-full lui:rounded-lg lui:border lui:border-border lui:bg-surface-input lui:shadow-sm lui:focus-within:ring-2 lui:focus-within:ring-focus"
end

#copy_button_classesObject



51
52
53
54
55
# File 'app/components/lightning_ui_kit/copy_input_component.rb', line 51

def copy_button_classes
  classes = [action_button_classes]
  classes << "lui:rounded-r-lg" unless @secret
  classes.join(" ")
end

#dataObject



14
15
16
# File 'app/components/lightning_ui_kit/copy_input_component.rb', line 14

def data
  {controller: "lui-clipboard"}.merge(@options[:data] || {})
end

#input_classesObject



39
40
41
# File 'app/components/lightning_ui_kit/copy_input_component.rb', line 39

def input_classes
  "lui:block lui:w-full lui:min-w-0 lui:flex-1 lui:appearance-none lui:bg-transparent lui:px-[calc(--spacing(3.5)-1px)] lui:py-[calc(--spacing(2.5)-1px)] lui:sm:px-[calc(--spacing(3)-1px)] lui:sm:py-[calc(--spacing(1.5)-1px)] lui:text-base/6 lui:text-foreground lui:sm:text-sm/6 lui:border-0 lui:focus:outline-hidden lui:select-all"
end

#input_typeObject



43
44
45
# File 'app/components/lightning_ui_kit/copy_input_component.rb', line 43

def input_type
  @secret ? "password" : "text"
end

#label_dataObject



18
19
20
# File 'app/components/lightning_ui_kit/copy_input_component.rb', line 18

def label_data
  {slot: "label"}
end

#label_html_optionsObject



22
23
24
25
26
27
# File 'app/components/lightning_ui_kit/copy_input_component.rb', line 22

def label_html_options
  {
    class: "lui:text-base/6 lui:text-foreground lui:select-none lui:sm:text-sm/6",
    data: label_data
  }
end

#render_labelObject



29
30
31
32
33
# File 'app/components/lightning_ui_kit/copy_input_component.rb', line 29

def render_label
  return unless @label

  helpers.label_tag(nil, @label, **label_html_options)
end

#toggle_button_classesObject



57
58
59
# File 'app/components/lightning_ui_kit/copy_input_component.rb', line 57

def toggle_button_classes
  "#{action_button_classes} lui:rounded-r-lg"
end