Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Primer::HellipButton to Primer::Alpha::HellipButton #1726

Merged
merged 5 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thin-buckets-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Move `Primer::HellipButton` to `Primer::Alpha::HellipButton`
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions app/components/primer/alpha/hellip_button.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

module Primer
module Alpha
# Use `HellipButton` to render a button with a hellip. Often used for hidden text expanders.
# @accessibility
# Always set an accessible label to help the user interact with the component.
#
# * This button is displaying a hellip as its content (The three dots character). Therefore a label is needed for screen readers.
# * Set the attribute `aria-label` on the system arguments. E.g. `Primer::Alpha::HellipButton.new("aria-label": "Expand next part")`
class HellipButton < Primer::Component
# @example Default
# <%= render(Primer::Alpha::HellipButton.new("aria-label": "No effect")) %>
#
# @example Inline
# <%= render(Primer::Alpha::HellipButton.new(inline: true, "aria-label": "No effect")) %>
#
# @example Styling the button
# <%= render(Primer::Alpha::HellipButton.new(p: 1, classes: "custom-class", "aria-label": "No effect")) %>
#
# @param inline [Boolean] Whether or not the button is inline.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(inline: false, **system_arguments)
@system_arguments = deny_tag_argument(**system_arguments)

validate_aria_label

@system_arguments[:tag] = :button
@system_arguments[:"aria-expanded"] = false
@system_arguments[:classes] = class_names(
@system_arguments[:classes],
"inline" => inline
)
end

def call
render(Primer::Beta::BaseButton.new(**@system_arguments)) { "&hellip;".html_safe }
end
end
end
end
2 changes: 1 addition & 1 deletion app/components/primer/alpha/hidden_text_expander.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def initialize(inline: false, button_arguments: {}, **system_arguments)

def call
render(Primer::BaseComponent.new(**@system_arguments)) do
render(Primer::HellipButton.new(**@button_arguments))
render(Primer::Alpha::HellipButton.new(**@button_arguments))
end
end
end
Expand Down
36 changes: 2 additions & 34 deletions app/components/primer/hellip_button.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
# frozen_string_literal: true

module Primer
# Use `HellipButton` to render a button with a hellip. Often used for hidden text expanders.
# @accessibility
# Always set an accessible label to help the user interact with the component.
#
# * This button is displaying a hellip as its content (The three dots character). Therefore a label is needed for screen readers.
# * Set the attribute `aria-label` on the system arguments. E.g. `Primer::HellipButton.new("aria-label": "Expand next part")`
class HellipButton < Primer::Component
# @example Default
# <%= render(Primer::HellipButton.new("aria-label": "No effect")) %>
#
# @example Inline
# <%= render(Primer::HellipButton.new(inline: true, "aria-label": "No effect")) %>
#
# @example Styling the button
# <%= render(Primer::HellipButton.new(p: 1, classes: "custom-class", "aria-label": "No effect")) %>
#
# @param inline [Boolean] Whether or not the button is inline.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(inline: false, **system_arguments)
@system_arguments = deny_tag_argument(**system_arguments)

validate_aria_label

@system_arguments[:tag] = :button
@system_arguments[:"aria-expanded"] = false
@system_arguments[:classes] = class_names(
@system_arguments[:classes],
"inline" => inline
)
end

def call
render(Primer::Beta::BaseButton.new(**@system_arguments)) { "&hellip;".html_safe }
end
class HellipButton < Primer::Alpha::HellipButton
status :deprecated
end
end
4 changes: 4 additions & 0 deletions lib/primer/deprecations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ deprecations:
autocorrect: true
replacement: "Primer::Alpha::Dropdown::Menu::Item"

- component: "Primer::HellipButton"
autocorrect: true
replacement: "Primer::Alpha::HellipButton"

- component: "Primer::IconButton"
autocorrect: true
replacement: "Primer::Beta::IconButton"
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/docs.rake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace :docs do
Primer::Beta::Button,
Primer::Alpha::SegmentedControl,
Primer::Alpha::Layout,
Primer::HellipButton,
Primer::Alpha::HellipButton,
Primer::Alpha::Image,
Primer::LocalTime,
Primer::Alpha::OcticonSymbols,
Expand Down
24 changes: 24 additions & 0 deletions previews/primer/alpha/hellip_button_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module Primer
module Alpha
# @label HellipButton
class HellipButtonPreview < ViewComponent::Preview
# @label Default Options
#
# @param aria_label [String]
# @param inline [Boolean]
def default(inline: false, aria_label: "No effect")
render(Primer::Alpha::HellipButton.new(inline: inline, "aria-label": aria_label))
end

# @label Playground
#
# @param aria_label [String]
# @param inline [Boolean]
def playground(inline: false, aria_label: "No effect")
render(Primer::Alpha::HellipButton.new(inline: inline, "aria-label": aria_label))
end
end
end
end
22 changes: 0 additions & 22 deletions previews/primer/hellip_button_preview.rb

This file was deleted.

40 changes: 20 additions & 20 deletions static/arguments.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,26 @@
}
]
},
{
"component": "HellipButton",
"status": "alpha",
"source": "https://github.com/primer/view_components/tree/main/app/components/primer/alpha/hellip_button.rb",
"lookbook": "https://primer.style/view-components/lookbook/inspect/primer/alpha/hellip_button_preview/default/",
"parameters": [
{
"name": "inline",
"type": "Boolean",
"default": "`false`",
"description": "Whether or not the button is inline."
},
{
"name": "system_arguments",
"type": "Hash",
"default": "N/A",
"description": "[System arguments](/system-arguments)"
}
]
},
{
"component": "HiddenTextExpander",
"status": "alpha",
Expand Down Expand Up @@ -2177,26 +2197,6 @@
}
]
},
{
"component": "HellipButton",
"status": "alpha",
"source": "https://github.com/primer/view_components/tree/main/app/components/primer/hellip_button.rb",
"lookbook": "https://primer.style/view-components/lookbook/inspect/primer/hellip_button_preview/default/",
"parameters": [
{
"name": "inline",
"type": "Boolean",
"default": "`false`",
"description": "Whether or not the button is inline."
},
{
"name": "system_arguments",
"type": "Hash",
"default": "N/A",
"description": "[System arguments](/system-arguments)"
}
]
},
{
"component": "IconButton",
"status": "deprecated",
Expand Down
1 change: 1 addition & 0 deletions static/audited_at.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"Primer::Alpha::Dropdown": "",
"Primer::Alpha::Dropdown::Menu": "",
"Primer::Alpha::Dropdown::Menu::Item": "",
"Primer::Alpha::HellipButton": "",
"Primer::Alpha::HiddenTextExpander": "",
"Primer::Alpha::Image": "",
"Primer::Alpha::ImageCrop": "",
Expand Down
2 changes: 2 additions & 0 deletions static/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@
"summary"
]
},
"Primer::Alpha::HellipButton": {
},
"Primer::Alpha::HiddenTextExpander": {
},
"Primer::Alpha::Image": {
Expand Down
3 changes: 2 additions & 1 deletion static/statuses.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"Primer::Alpha::Dropdown": "alpha",
"Primer::Alpha::Dropdown::Menu": "alpha",
"Primer::Alpha::Dropdown::Menu::Item": "alpha",
"Primer::Alpha::HellipButton": "alpha",
"Primer::Alpha::HiddenTextExpander": "alpha",
"Primer::Alpha::Image": "alpha",
"Primer::Alpha::ImageCrop": "alpha",
Expand Down Expand Up @@ -77,7 +78,7 @@
"Primer::Dropdown::Menu": "deprecated",
"Primer::Dropdown::Menu::Item": "deprecated",
"Primer::DropdownMenuComponent": "deprecated",
"Primer::HellipButton": "alpha",
"Primer::HellipButton": "deprecated",
"Primer::IconButton": "deprecated",
"Primer::LabelComponent": "deprecated",
"Primer::LayoutComponent": "alpha",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@

require "components/test_helper"

class PrimerHellipButtonTest < Minitest::Test
class PrimerAlphaHellipButtonTest < Minitest::Test
include Primer::ComponentTestHelpers

def test_renders
render_inline(Primer::HellipButton.new("aria-label": "No effect"))
render_inline(Primer::Alpha::HellipButton.new("aria-label": "No effect"))

assert_selector("button[type='button'][aria-expanded='false']", text: "…")
end

def test_renders_inline
render_inline(Primer::HellipButton.new(inline: true, "aria-label": "No effect"))
render_inline(Primer::Alpha::HellipButton.new(inline: true, "aria-label": "No effect"))

assert_selector("button[type='button'][aria-expanded='false'].inline", text: "…")
end

def test_renders_button_custom_classes
render_inline(Primer::HellipButton.new(classes: "custom-class", "aria-label": "No effect"))
render_inline(Primer::Alpha::HellipButton.new(classes: "custom-class", "aria-label": "No effect"))

assert_selector("button[type='button'][aria-expanded='false'].custom-class", text: "…")
end

def test_renders_aria_label
render_inline(Primer::HellipButton.new("aria-label": "Custom aria label"))
render_inline(Primer::Alpha::HellipButton.new("aria-label": "Custom aria label"))

assert_selector("button[aria-label='Custom aria label']")
end

def test_renders_aria_label_provided_as_object
render_inline(Primer::HellipButton.new(aria: { label: "Custom aria label" }))
render_inline(Primer::Alpha::HellipButton.new(aria: { label: "Custom aria label" }))

assert_selector("button[aria-label='Custom aria label']")
end

def test_raises_if_no_aria_label_is_provided
err = assert_raises ArgumentError do
render_inline(Primer::HellipButton.new)
render_inline(Primer::Alpha::HellipButton.new)
end

assert_equal("`aria-label` is required.", err.message)
end

def test_does_not_render_content
render_inline(Primer::HellipButton.new("aria-label": "No effect")) { "content" }
render_inline(Primer::Alpha::HellipButton.new("aria-label": "No effect")) { "content" }

refute_text("content")
end
Expand Down
3 changes: 2 additions & 1 deletion test/components/component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PrimerComponentTest < Minitest::Test
component.with_main(tag: :div) { "Foo" }
component.with_sidebar(tag: :div) { "Bar" }
}],
[Primer::HellipButton, { "aria-label": "No action" }],
[Primer::Alpha::HellipButton, { "aria-label": "No action" }],
[Primer::Alpha::TabPanels, { label: "label" }],
[Primer::Alpha::TabNav, { label: "label" }],
[Primer::Alpha::UnderlinePanels, { label: "Panel label" }],
Expand Down Expand Up @@ -111,6 +111,7 @@ class PrimerComponentTest < Minitest::Test

def test_registered_components
ignored_components = [
"Primer::HellipButton",
"Primer::StateComponent",
"Primer::OcticonSymbolsComponent",
"Primer::SpinnerComponent",
Expand Down