Skip to content

Commit 68ac68d

Browse files
authored
Merge pull request #135 from primer/label-next-colors
add support for functional colors to Label
2 parents 0ec555a + 8e9f3e5 commit 68ac68d

File tree

8 files changed

+35
-16
lines changed

8 files changed

+35
-16
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## main
44

5+
## 0.0.14
6+
7+
* Add functional colors to Label.
8+
9+
*Joel Hawksley*
10+
511
## 0.0.13
612

713
* Add support for `xl` breakpoint.

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
primer_view_components (0.0.13)
4+
primer_view_components (0.0.14)
55
octicons_helper (>= 9.0.0, < 12.0.0)
66
rails (>= 5.0.0, < 7.0)
77
view_component (>= 2.0.0, < 3.0)

app/components/primer/label_component.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,30 @@
33
module Primer
44
# Use labels to add contextual metadata to a design.
55
class LabelComponent < Primer::Component
6-
SCHEME_MAPPINGS = {
7-
# gray
6+
NEW_SCHEME_MAPPINGS = {
7+
primary: "Label--primary",
8+
secondary: "Label--secondary",
9+
info: "Label--info",
10+
success: "Label--success",
11+
warning: "Label--warning",
12+
danger: "Label--danger",
13+
}
14+
15+
DEPRECATED_SCHEME_MAPPINGS = {
816
gray: "Label--gray",
917
dark_gray: "Label--gray-darker",
10-
11-
# colored
1218
yellow: "Label--yellow",
1319
orange: "Label--orange",
1420
red: "Label--red",
1521
green: "Label--green",
1622
blue: "Label--blue",
1723
purple: "Label--purple",
1824
pink: "Label--pink",
19-
20-
# Deprecated
2125
outline: "Label--outline",
2226
green_outline: "Label--outline-green",
2327
}.freeze
28+
29+
SCHEME_MAPPINGS = NEW_SCHEME_MAPPINGS.merge(DEPRECATED_SCHEME_MAPPINGS)
2430
SCHEME_OPTIONS = SCHEME_MAPPINGS.keys << nil
2531

2632
VARIANT_MAPPINGS = {
@@ -42,7 +48,7 @@ class LabelComponent < Primer::Component
4248
# <%= render(Primer::LabelComponent.new(title: "Label: Label", variant: :large)) { "Large" } %>
4349
#
4450
# @param title [String] `title` attribute for the component element.
45-
# @param scheme [Symbol] <%= one_of(Primer::LabelComponent::SCHEME_OPTIONS) %>
51+
# @param scheme [Symbol] <%= one_of(Primer::LabelComponent::DEPRECATED_SCHEME_MAPPINGS.keys) %>
4652
# @param variant [Symbol] <%= one_of(Primer::LabelComponent::VARIANT_OPTIONS) %>
4753
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
4854
def initialize(title:, scheme: nil, variant: nil, **system_arguments)

demo/Gemfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ..
33
specs:
4-
primer_view_components (0.0.10)
4+
primer_view_components (0.0.13)
55
octicons_helper (>= 9.0.0, < 12.0.0)
66
rails (>= 5.0.0, < 7.0)
77
view_component (>= 2.0.0, < 3.0)
@@ -105,10 +105,10 @@ GEM
105105
nio4r (2.5.4)
106106
nokogiri (1.10.10)
107107
mini_portile2 (~> 2.4.0)
108-
octicons (11.0.0)
108+
octicons (11.1.0)
109109
nokogiri (>= 1.6.3.1)
110-
octicons_helper (11.0.0)
111-
octicons (= 11.0.0)
110+
octicons_helper (11.1.0)
111+
octicons (= 11.1.0)
112112
rails
113113
pry (0.13.1)
114114
coderay (~> 1.1)

docs/content/components/label.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Use labels to add contextual metadata to a design.
88

99
### Schemes
1010

11-
<iframe style="width: 100%; border: 0px; height: 40px;" srcdoc="<html><head><link href='https://unpkg.com/@primer/css/dist/primer.css' rel='stylesheet'></head><body><span title='Label: Label' class='Label bg-blue'>default</span><span title='Label: Label' class='Label Label--gray '>gray</span><span title='Label: Label' class='Label Label--gray-darker '>dark_gray</span><span title='Label: Label' class='Label Label--yellow '>yellow</span><span title='Label: Label' class='Label Label--green '>green</span><span title='Label: Label' class='Label Label--purple '>purple</span></body></html>"></iframe>
11+
<iframe style="width: 100%; border: 0px; height: 40px;" srcdoc="<html><head><link href='https://unpkg.com/@primer/css/dist/primer.css' rel='stylesheet'></head><body><span title='Label: Label' class='Label bg-blue'>default</span><span title='Label: Label' class='Label '>gray</span><span title='Label: Label' class='Label '>dark_gray</span><span title='Label: Label' class='Label '>yellow</span><span title='Label: Label' class='Label '>green</span><span title='Label: Label' class='Label '>purple</span></body></html>"></iframe>
1212

1313
```erb
1414
<%= render(Primer::LabelComponent.new(title: "Label: Label")) { "default" } %>
@@ -33,6 +33,6 @@ Use labels to add contextual metadata to a design.
3333
| Name | Type | Default | Description |
3434
| :- | :- | :- | :- |
3535
| `title` | `String` | N/A | `title` attribute for the component element. |
36-
| `scheme` | `Symbol` | `nil` | One of `:gray`, `:dark_gray`, `:yellow`, `:orange`, `:red`, `:green`, `:blue`, `:purple`, `:pink`, `:outline`, `:green_outline`, or `nil`. |
36+
| `scheme` | `Symbol` | `nil` | One of `:gray`, `:dark_gray`, `:yellow`, `:orange`, `:red`, `:green`, `:blue`, `:purple`, `:pink`, `:outline`, or `:green_outline`. |
3737
| `variant` | `Symbol` | `nil` | One of `:large`, `:inline`, or `nil`. |
3838
| `system_arguments` | `Hash` | N/A | [System Arguments](/system-arguments) |

lib/primer/view_components/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module ViewComponents
55
module VERSION
66
MAJOR = 0
77
MINOR = 0
8-
PATCH = 13
8+
PATCH = 14
99

1010
STRING = [MAJOR, MINOR, PATCH].join(".")
1111
end

stories/primer/label_component_stories.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ class Primer::LabelComponentStories < ViewComponent::Storybook::Stories
66
story(:label) do
77
controls do
88
title "this is a label"
9-
select(:scheme, Primer::LabelComponent::SCHEME_MAPPINGS.keys, :blue)
9+
# TODO: Update to use functional scheme mappings
10+
select(:scheme, Primer::LabelComponent::DEPRECATED_SCHEME_MAPPINGS.keys, :blue)
1011
select(:variant, Primer::LabelComponent::VARIANT_MAPPINGS.keys, :large)
1112
end
1213

test/components/label_component_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ def test_defaults_to_bg_blue
1717
assert_selector(".bg-blue")
1818
end
1919

20+
def test_supports_functional_schemes
21+
render_inline(Primer::LabelComponent.new(title: "foo", scheme: :danger)) { "private" }
22+
23+
assert_selector(".Label--danger")
24+
end
25+
2026
def test_falls_back_when_scheme_isn_t_valid
2127
render_inline(Primer::LabelComponent.new(title: "title", scheme: :pink)) { "content" }
2228

0 commit comments

Comments
 (0)