Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
✨ Add game card badges (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephannv authored Sep 7, 2022
1 parent d2d0a09 commit 59ade47
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/components/games/card/badge_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= content_tag :span, class: classes do %>
<%= text %>
<% end %>
47 changes: 47 additions & 0 deletions app/components/games/card/badge_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

module Games
module Card
class BadgeComponent < ViewComponent::Base
BASE_CLASSES = "absolute -top-2 -right-2 uppercase p-2 text-xs rounded drop-shadow-md
font-black lg:font-bold border".squish

COLOR_CLASSES = {
coming_soon: "bg-[#5A94FF] text-white border-[#4876cc]",
pre_order: "bg-[#C65AFF] text-white border-[#763699]",
new_release: "bg-[#ADFF5A] text-black border-[#80FE00]"
}.freeze

def initialize(game:)
@game = game
end

private

attr_reader :game

def render?
type.present?
end

def type
if game.pre_order? then :pre_order
elsif game.coming_soon? then :coming_soon
elsif game.new_release? then :new_release
end
end

def text
{
coming_soon: t(".coming_soon"),
pre_order: t(".pre_order"),
new_release: t(".new_release")
}[type]
end

def classes
[BASE_CLASSES, COLOR_CLASSES[type]]
end
end
end
end
6 changes: 4 additions & 2 deletions app/components/games/card_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<div class="card border border-gray-700 bg-base-200">
<div class="card border border-gray-700 bg-base-200 overflow-visible w-[98%]">
<%= badge %>

<%= link_to game_path(game.slug) do %>
<figure class="w-full aspect-video">
<%= image_tag game.small_banner_url, class: "w-full", width: 480, height: 320, alt: game.title, loading: :lazy %>
<%= image_tag game.small_banner_url, class: "w-full rounded-t-xl", width: 480, height: 320, alt: game.title, loading: :lazy %>
</figure>
<% end %>

Expand Down
4 changes: 4 additions & 0 deletions app/components/games/card_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ def initialize(game:)
private

attr_reader :game

def badge
render Games::Card::BadgeComponent.new(game: game)
end
end
end
6 changes: 6 additions & 0 deletions config/locales/pt-BR/components/games.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ pt-BR:
title: Nenhum jogo encontrado
description: Não há nenhum jogo para ser exibido aqui
action: Ver todos os jogos

card:
badge_component:
coming_soon: Em breve
pre_order: Reserve já
new_release: Lançamento

0 comments on commit 59ade47

Please sign in to comment.