Class: Keystone::Ui::SwipeDeckComponent

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

Constant Summary collapse

CARD_CLASSES =
"absolute inset-0 rounded-2xl border border-gray-200 dark:border-zinc-700 bg-white dark:bg-zinc-900 shadow-lg p-6 flex flex-col items-center justify-center transition-transform duration-300"
STACK_SCALE_STEP =
0.05
STACK_TRANSLATE_STEP =
8

Instance Method Summary collapse

Constructor Details

#initialize(items:, empty_title: "All done!", empty_subtitle: nil) ⇒ SwipeDeckComponent

Returns a new instance of SwipeDeckComponent.



11
12
13
14
15
16
# File 'app/components/keystone/ui/swipe_deck_component.rb', line 11

def initialize(items:, empty_title: "All done!", empty_subtitle: nil)
  @items = items
  @empty_title = empty_title
  @empty_subtitle = empty_subtitle
  @item_block = nil
end

Instance Method Details

#before_renderObject



22
23
24
# File 'app/components/keystone/ui/swipe_deck_component.rb', line 22

def before_render
  content
end

#card_dataObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/components/keystone/ui/swipe_deck_component.rb', line 26

def card_data
  @items.each_with_index.map do |item, index|
    scale = 1 - (index * STACK_SCALE_STEP)
    translate_y = index * STACK_TRANSLATE_STEP
    {
      item: item,
      index: index,
      z_index: @items.length - index,
      transform: "scale(#{scale}) translateY(#{translate_y}px)"
    }
  end
end

#empty?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/components/keystone/ui/swipe_deck_component.rb', line 39

def empty?
  @items.empty?
end

#item(&block) ⇒ Object



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

def item(&block)
  @item_block = block
end

#item_id(item, fallback_index: nil) ⇒ Object



43
44
45
46
47
48
49
# File 'app/components/keystone/ui/swipe_deck_component.rb', line 43

def item_id(item, fallback_index: nil)
  if item.respond_to?(:id)
    item.id
  else
    fallback_index
  end
end