-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathlabel.rb
More file actions
80 lines (69 loc) · 2.97 KB
/
label.rb
File metadata and controls
80 lines (69 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# frozen_string_literal: true
module Primer
module Beta
# Use `Label` to add contextual metadata to a design.
#
# @accessibility
# Use `aria-label` if the `Label` or the context around it don't explain the label.
class Label < Primer::Component
status :beta
DEFAULT_TAG = :span
TAG_OPTIONS = [DEFAULT_TAG, :summary, :a, :div].freeze
DEFAULT_SCHEME = :default
SCHEME_MAPPINGS = {
DEFAULT_SCHEME => "",
:primary => "Label--primary",
:secondary => "Label--secondary",
:accent => "Label--accent",
:success => "Label--success",
:attention => "Label--attention",
:danger => "Label--danger",
:severe => "Label--severe",
:done => "Label--done",
:sponsors => "Label--sponsors",
# deprecated
:info => "Label--info",
:warning => "Label--warning",
:orange => "Label--orange",
:purple => "Label--purple"
}.freeze
DEPRECATED_SCHEME_OPTIONS = [:info, :warning, :orange, :purple].freeze
SCHEME_OPTIONS = (SCHEME_MAPPINGS.keys - DEPRECATED_SCHEME_OPTIONS).freeze
DEFAULT_SIZE = :medium
SIZE_MAPPINGS = {
DEFAULT_SIZE => nil,
:large => "Label--large"
}.freeze
SIZE_OPTIONS = SIZE_MAPPINGS.keys
DEFAULT_VARIANT = :none
VARIANT_OPTIONS = [DEFAULT_VARIANT].freeze
DEPRECATED_VARIANT_OPTIONS = [:large, :inline].freeze
INLINE_CLASS = "Label--inline"
# @param tag [Symbol] <%= one_of(Primer::Beta::Label::TAG_OPTIONS) %>
# @param scheme [Symbol] <%= one_of(Primer::Beta::Label::SCHEME_MAPPINGS.keys) %>
# @param size [Symbol] <%= one_of(Primer::Beta::Label::SIZE_OPTIONS) %>
# @param inline [Boolean] Whether or not to render this label inline.
# @param variant [Symbol] <%= one_of(Primer::Beta::Label::VARIANT_OPTIONS + Primer::Beta::Label::DEPRECATED_VARIANT_OPTIONS) %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(tag: DEFAULT_TAG, scheme: DEFAULT_SCHEME, size: DEFAULT_SIZE, inline: false, variant: DEFAULT_VARIANT, **system_arguments)
@system_arguments = system_arguments
@variant = fetch_or_fallback(VARIANT_OPTIONS, variant, nil, deprecated_values: DEPRECATED_VARIANT_OPTIONS)
@scheme = fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME, deprecated_values: DEPRECATED_SCHEME_OPTIONS)
@size = fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)
@size = :large if @variant == :large
@inline = inline || @variant == :inline
@system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG)
@system_arguments[:classes] = class_names(
"Label",
system_arguments[:classes],
SCHEME_MAPPINGS[@scheme],
SIZE_MAPPINGS[@size],
@inline ? INLINE_CLASS : nil
)
end
def call
render(Primer::BaseComponent.new(**@system_arguments)) { content }
end
end
end
end