Skip to content

Commit

Permalink
Merge pull request #135 from primer/label-next-colors
Browse files Browse the repository at this point in the history
add support for functional colors to Label
  • Loading branch information
joelhawksley authored Nov 16, 2020
2 parents 0ec555a + 8e9f3e5 commit 68ac68d
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## main

## 0.0.14

* Add functional colors to Label.

*Joel Hawksley*

## 0.0.13

* Add support for `xl` breakpoint.
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
primer_view_components (0.0.13)
primer_view_components (0.0.14)
octicons_helper (>= 9.0.0, < 12.0.0)
rails (>= 5.0.0, < 7.0)
view_component (>= 2.0.0, < 3.0)
Expand Down
20 changes: 13 additions & 7 deletions app/components/primer/label_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,30 @@
module Primer
# Use labels to add contextual metadata to a design.
class LabelComponent < Primer::Component
SCHEME_MAPPINGS = {
# gray
NEW_SCHEME_MAPPINGS = {
primary: "Label--primary",
secondary: "Label--secondary",
info: "Label--info",
success: "Label--success",
warning: "Label--warning",
danger: "Label--danger",
}

DEPRECATED_SCHEME_MAPPINGS = {
gray: "Label--gray",
dark_gray: "Label--gray-darker",

# colored
yellow: "Label--yellow",
orange: "Label--orange",
red: "Label--red",
green: "Label--green",
blue: "Label--blue",
purple: "Label--purple",
pink: "Label--pink",

# Deprecated
outline: "Label--outline",
green_outline: "Label--outline-green",
}.freeze

SCHEME_MAPPINGS = NEW_SCHEME_MAPPINGS.merge(DEPRECATED_SCHEME_MAPPINGS)
SCHEME_OPTIONS = SCHEME_MAPPINGS.keys << nil

VARIANT_MAPPINGS = {
Expand All @@ -42,7 +48,7 @@ class LabelComponent < Primer::Component
# <%= render(Primer::LabelComponent.new(title: "Label: Label", variant: :large)) { "Large" } %>
#
# @param title [String] `title` attribute for the component element.
# @param scheme [Symbol] <%= one_of(Primer::LabelComponent::SCHEME_OPTIONS) %>
# @param scheme [Symbol] <%= one_of(Primer::LabelComponent::DEPRECATED_SCHEME_MAPPINGS.keys) %>
# @param variant [Symbol] <%= one_of(Primer::LabelComponent::VARIANT_OPTIONS) %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(title:, scheme: nil, variant: nil, **system_arguments)
Expand Down
8 changes: 4 additions & 4 deletions demo/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
primer_view_components (0.0.10)
primer_view_components (0.0.13)
octicons_helper (>= 9.0.0, < 12.0.0)
rails (>= 5.0.0, < 7.0)
view_component (>= 2.0.0, < 3.0)
Expand Down Expand Up @@ -105,10 +105,10 @@ GEM
nio4r (2.5.4)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
octicons (11.0.0)
octicons (11.1.0)
nokogiri (>= 1.6.3.1)
octicons_helper (11.0.0)
octicons (= 11.0.0)
octicons_helper (11.1.0)
octicons (= 11.1.0)
rails
pry (0.13.1)
coderay (~> 1.1)
Expand Down
4 changes: 2 additions & 2 deletions docs/content/components/label.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Use labels to add contextual metadata to a design.

### Schemes

<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>
<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>

```erb
<%= render(Primer::LabelComponent.new(title: "Label: Label")) { "default" } %>
Expand All @@ -33,6 +33,6 @@ Use labels to add contextual metadata to a design.
| Name | Type | Default | Description |
| :- | :- | :- | :- |
| `title` | `String` | N/A | `title` attribute for the component element. |
| `scheme` | `Symbol` | `nil` | One of `:gray`, `:dark_gray`, `:yellow`, `:orange`, `:red`, `:green`, `:blue`, `:purple`, `:pink`, `:outline`, `:green_outline`, or `nil`. |
| `scheme` | `Symbol` | `nil` | One of `:gray`, `:dark_gray`, `:yellow`, `:orange`, `:red`, `:green`, `:blue`, `:purple`, `:pink`, `:outline`, or `:green_outline`. |
| `variant` | `Symbol` | `nil` | One of `:large`, `:inline`, or `nil`. |
| `system_arguments` | `Hash` | N/A | [System Arguments](/system-arguments) |
2 changes: 1 addition & 1 deletion lib/primer/view_components/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module ViewComponents
module VERSION
MAJOR = 0
MINOR = 0
PATCH = 13
PATCH = 14

STRING = [MAJOR, MINOR, PATCH].join(".")
end
Expand Down
3 changes: 2 additions & 1 deletion stories/primer/label_component_stories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class Primer::LabelComponentStories < ViewComponent::Storybook::Stories
story(:label) do
controls do
title "this is a label"
select(:scheme, Primer::LabelComponent::SCHEME_MAPPINGS.keys, :blue)
# TODO: Update to use functional scheme mappings
select(:scheme, Primer::LabelComponent::DEPRECATED_SCHEME_MAPPINGS.keys, :blue)
select(:variant, Primer::LabelComponent::VARIANT_MAPPINGS.keys, :large)
end

Expand Down
6 changes: 6 additions & 0 deletions test/components/label_component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def test_defaults_to_bg_blue
assert_selector(".bg-blue")
end

def test_supports_functional_schemes
render_inline(Primer::LabelComponent.new(title: "foo", scheme: :danger)) { "private" }

assert_selector(".Label--danger")
end

def test_falls_back_when_scheme_isn_t_valid
render_inline(Primer::LabelComponent.new(title: "title", scheme: :pink)) { "content" }

Expand Down

1 comment on commit 68ac68d

@vercel
Copy link

@vercel vercel bot commented on 68ac68d Nov 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.