-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] migrating Primer::LabelComponent to Primer::Beta::Label (#1530)
- Loading branch information
1 parent
488532c
commit 72866fc
Showing
25 changed files
with
311 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@primer/view-components': patch | ||
--- | ||
|
||
migrating Primer::LabelComponent to Primer::Beta::Label |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# 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" | ||
|
||
# @example Schemes | ||
# <%= render(Primer::Beta::Label.new) { "Default" } %> | ||
# <%= render(Primer::Beta::Label.new(scheme: :primary)) { "Primary" } %> | ||
# <%= render(Primer::Beta::Label.new(scheme: :secondary)) { "Secondary" } %> | ||
# <%= render(Primer::Beta::Label.new(scheme: :accent)) { "Accent" } %> | ||
# <%= render(Primer::Beta::Label.new(scheme: :success)) { "Success" } %> | ||
# <%= render(Primer::Beta::Label.new(scheme: :attention)) { "Attention" } %> | ||
# <%= render(Primer::Beta::Label.new(scheme: :danger)) { "Danger" } %> | ||
# <%= render(Primer::Beta::Label.new(scheme: :severe)) { "Severe" } %> | ||
# <%= render(Primer::Beta::Label.new(scheme: :done)) { "Done" } %> | ||
# <%= render(Primer::Beta::Label.new(scheme: :sponsors)) { "Sponsors" } %> | ||
# | ||
# @example Sizes | ||
# <%= render(Primer::Beta::Label.new) { "Medium" } %> | ||
# <%= render(Primer::Beta::Label.new(size: :large)) { "Large" } %> | ||
# | ||
# @example Inline | ||
# <%= render(Primer::Beta::Label.new) { "Default" } %> | ||
# <%= render(Primer::Beta::Label.new(inline: true)) { "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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
# 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 LabelComponent < 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" | ||
|
||
# @example Schemes | ||
# <%= render(Primer::LabelComponent.new) { "Default" } %> | ||
# <%= render(Primer::LabelComponent.new(scheme: :primary)) { "Primary" } %> | ||
# <%= render(Primer::LabelComponent.new(scheme: :secondary)) { "Secondary" } %> | ||
# <%= render(Primer::LabelComponent.new(scheme: :accent)) { "Accent" } %> | ||
# <%= render(Primer::LabelComponent.new(scheme: :success)) { "Success" } %> | ||
# <%= render(Primer::LabelComponent.new(scheme: :attention)) { "Attention" } %> | ||
# <%= render(Primer::LabelComponent.new(scheme: :danger)) { "Danger" } %> | ||
# <%= render(Primer::LabelComponent.new(scheme: :severe)) { "Severe" } %> | ||
# <%= render(Primer::LabelComponent.new(scheme: :done)) { "Done" } %> | ||
# <%= render(Primer::LabelComponent.new(scheme: :sponsors)) { "Sponsors" } %> | ||
# | ||
# @example Sizes | ||
# <%= render(Primer::LabelComponent.new) { "Medium" } %> | ||
# <%= render(Primer::LabelComponent.new(size: :large)) { "Large" } %> | ||
# | ||
# @example Inline | ||
# <%= render(Primer::LabelComponent.new) { "Default" } %> | ||
# <%= render(Primer::LabelComponent.new(inline: true)) { "Inline" } %> | ||
# | ||
# @param tag [Symbol] <%= one_of(Primer::LabelComponent::TAG_OPTIONS) %> | ||
# @param scheme [Symbol] <%= one_of(Primer::LabelComponent::SCHEME_MAPPINGS.keys) %> | ||
# @param size [Symbol] <%= one_of(Primer::LabelComponent::SIZE_OPTIONS) %> | ||
# @param inline [Boolean] Whether or not to render this label inline. | ||
# @param variant [Symbol] <%= one_of(Primer::LabelComponent::VARIANT_OPTIONS + Primer::LabelComponent::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 | ||
class LabelComponent < Primer::Beta::Label | ||
status :deprecated | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
module Beta | ||
# @label Label | ||
class LabelPreview < ViewComponent::Preview | ||
# @label Default Options | ||
# | ||
# @param size [Symbol] select [medium, large] | ||
# @param tag [Symbol] select [span, summary, a, div] | ||
# @param inline [Boolean] toggle | ||
def default(size: :medium, tag: :span, inline: false) | ||
render(Primer::Beta::Label.new(tag: tag, size: size, inline: inline)) { "Label" } | ||
end | ||
|
||
# @label Playground | ||
# | ||
# @param size [Symbol] select [medium, large] | ||
# @param tag [Symbol] select [span, summary, a, div] | ||
# @param inline [Boolean] toggle | ||
def playground(size: :medium, tag: :span, inline: false) | ||
render(Primer::Beta::Label.new(tag: tag, size: size, inline: inline)) { "Label" } | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.