Class: Pulse::Badge
- Inherits:
-
Component
- Object
- Component
- Pulse::Badge
- Defined in:
- app/components/pulse/badge.rb
Overview
Renders a badge component see: /lookbook/inspect/pulse/badge/default
Constant Summary collapse
- DEFAULT_TAG =
:span- TAG_OPTIONS =
[DEFAULT_TAG, :summary, :a, :div].freeze
- DEFAULT_VARIANT =
:standard- VARIANT_MAPPINGS =
{ standard: 'pulse-inline-block pulse-rounded pulse-uppercase ' \ 'pulse-py-0.5 pulse-px-1.5 pulse-text-[10px] ' \ 'pulse-font-bold', pill: 'pulse-inline-block pulse-rounded-2xl pulse-min-w-[8rem] ' \ 'pulse-text-center pulse-p-2 pulse-text-sm ' \ 'pulse-leading-none pulse-font-bold' }.freeze
- VARIANT_OPTIONS =
VARIANT_MAPPINGS.keys.freeze
- DEFAULT_SCHEME =
:secondary- SCHEME_MAPPINGS =
{ primary: 'pulse-bg-primary pulse-text-white hover:pulse-text-white', secondary: 'pulse-bg-secondary pulse-text-white', secondary_outline: 'pulse-bg-white pulse-border pulse-border-secondary ' \ 'pulse-text-secondary ' \ 'pulse-hover:pulse-text-secondary', invited: 'pulse-bg-secondary-200 pulse-text-gray ' \ 'pulse-hover:pulse-text-gray', active: 'pulse-bg-success-200 pulse-text-gray hover:pulse-text-gray', disabled: 'pulse-bg-gray-100 pulse-text-gray hover:pulse-text-gray', info: 'pulse-bg-gray-600 pulse-text-white hover:pulse-text-white' }.freeze
- SCHEME_OPTIONS =
SCHEME_MAPPINGS.keys.freeze
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(tag: DEFAULT_TAG, variant: DEFAULT_VARIANT, scheme: DEFAULT_SCHEME, **system_arguments) ⇒ Badge
constructor
A new instance of Badge.
- #render? ⇒ Boolean
Constructor Details
#initialize(tag: DEFAULT_TAG, variant: DEFAULT_VARIANT, scheme: DEFAULT_SCHEME, **system_arguments) ⇒ Badge
Returns a new instance of Badge.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/components/pulse/badge.rb', line 36 def initialize(tag: DEFAULT_TAG, variant: DEFAULT_VARIANT, scheme: DEFAULT_SCHEME, **system_arguments) @system_arguments = system_arguments @variant = fetch_or_fallback(VARIANT_OPTIONS, variant, DEFAULT_VARIANT) @scheme = fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME) @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG) @system_arguments[:classes] = merge_classes( VARIANT_MAPPINGS[@variant], SCHEME_MAPPINGS[@scheme], system_arguments[:classes] ) end |
Instance Method Details
#call ⇒ Object
51 52 53 |
# File 'app/components/pulse/badge.rb', line 51 def call render(Pulse::BaseComponent.new(**@system_arguments)) { content } end |
#render? ⇒ Boolean
55 56 57 |
# File 'app/components/pulse/badge.rb', line 55 def render? content.present? end |