Class: Keystone::Ui::FunnelComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/keystone/ui/funnel_component.rb

Defined Under Namespace

Classes: Layer

Constant Summary collapse

CONTAINER_CLASSES =
"space-y-2"
LAYER_CLASSES =
"space-y-1"
ROW_CLASSES =
"flex items-baseline justify-between gap-3"
LABEL_CLASSES =
"text-sm font-medium text-surface-700 truncate"
VALUE_CLASSES =
"text-sm font-semibold text-surface-900 tabular-nums"
BAR_CLASSES =
"h-8 rounded-md bg-accent-500 transition-all"
TRANSITION_CLASSES =
"py-1 text-center text-xs text-surface-500"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(steps:) ⇒ FunnelComponent

Returns a new instance of FunnelComponent.



18
19
20
# File 'app/components/keystone/ui/funnel_component.rb', line 18

def initialize(steps:)
  @steps = steps
end

Instance Attribute Details

#stepsObject (readonly)

Returns the value of attribute steps.



16
17
18
# File 'app/components/keystone/ui/funnel_component.rb', line 16

def steps
  @steps
end

Instance Method Details

#bar_classesObject



49
50
51
# File 'app/components/keystone/ui/funnel_component.rb', line 49

def bar_classes
  BAR_CLASSES
end

#container_classesObject



37
38
39
# File 'app/components/keystone/ui/funnel_component.rb', line 37

def container_classes
  CONTAINER_CLASSES
end

#label_classesObject



53
54
55
# File 'app/components/keystone/ui/funnel_component.rb', line 53

def label_classes
  LABEL_CLASSES
end

#layer_classesObject



41
42
43
# File 'app/components/keystone/ui/funnel_component.rb', line 41

def layer_classes
  LAYER_CLASSES
end

#layersObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/components/keystone/ui/funnel_component.rb', line 22

def layers
  previous = nil

  steps.map do |step|
    layer = Layer.new(
      label: step[:label],
      value: step[:value],
      width_percent: width_percent(step[:value]),
      conversion_percent: conversion_percent(step[:value], previous)
    )
    previous = step[:value]
    layer
  end
end

#row_classesObject



45
46
47
# File 'app/components/keystone/ui/funnel_component.rb', line 45

def row_classes
  ROW_CLASSES
end

#transition_classesObject



61
62
63
# File 'app/components/keystone/ui/funnel_component.rb', line 61

def transition_classes
  TRANSITION_CLASSES
end

#value_classesObject



57
58
59
# File 'app/components/keystone/ui/funnel_component.rb', line 57

def value_classes
  VALUE_CLASSES
end