Class: PhlexKit::Badge
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::Badge
- Defined in:
- app/components/phlex_kit/badge/badge.rb
Overview
Pill/label badge, ported from ruby_ui's RubyUI::Badge and matched to
shadcn/ui's current badge. Same kit shape as PhlexKit::Button — a
variant:/size: selector plus attrs/block passed through. Pass href:
to render an (shadcn's asChild link badge — hover fills only apply to
links). Mark leading/trailing svg glyphs with data-icon: "inline-start" /
"inline-end" to tighten the near-side padding, like theirs:
render PhlexKit::Badge.new(variant: :secondary) do
render PhlexKit::Icon.new(:circle_check, size: nil, data: { icon: "inline-start" })
plain "Verified"
end
shadcn ships default/secondary/destructive/outline/ghost/link (:primary is
their :default); success/warning and the sm/lg sizes are kit extras.
VARIANTS.fetch fails loud.
Constant Summary collapse
- VARIANTS =
{ primary: "primary", secondary: "secondary", outline: "outline", destructive: "destructive", ghost: "ghost", link: "link", success: "success", warning: "warning" }.freeze
- SIZES =
{ sm: "sm", md: nil, lg: "lg" }.freeze
Instance Method Summary collapse
-
#initialize(variant: :primary, size: :md, href: nil, **attrs) ⇒ Badge
constructor
A new instance of Badge.
- #view_template(&block) ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(variant: :primary, size: :md, href: nil, **attrs) ⇒ Badge
Returns a new instance of Badge.
35 36 37 38 39 40 |
# File 'app/components/phlex_kit/badge/badge.rb', line 35 def initialize(variant: :primary, size: :md, href: nil, **attrs) @variant = variant.to_sym @size = size.to_sym @href = href @attrs = attrs end |
Instance Method Details
#view_template(&block) ⇒ Object
42 43 44 45 46 47 48 |
# File 'app/components/phlex_kit/badge/badge.rb', line 42 def view_template(&block) if @href a(**mix({ class: classes, href: @href }, @attrs), &block) else span(**mix({ class: classes }, @attrs), &block) end end |