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

rename FlashComponent to Flash #1185

Merged
merged 3 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all 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/large-beers-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/view-components": patch
---

Rename FlashComponent to Flash
2 changes: 1 addition & 1 deletion .erb-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ EnableDefaultLinters: true
linters:
ButtonComponentMigrationCounter:
enabled: true
FlashComponentMigrationCounter:
FlashMigrationCounter:
enabled: true
LabelComponentMigrationCounter:
enabled: true
Expand Down
71 changes: 71 additions & 0 deletions app/components/primer/beta/flash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# frozen_string_literal: true

module Primer
module Beta
# Use `Flash` to inform users of successful or pending actions.
class Flash < Primer::Component
status :beta

# Optional action content showed on the right side of the component.
#
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
renders_one :action, lambda { |**system_arguments|
deny_tag_argument(**system_arguments)
system_arguments[:tag] = :div
system_arguments[:classes] = class_names(system_arguments[:classes], "flash-action")

Primer::BaseComponent.new(**system_arguments)
}

DEFAULT_SCHEME = :default
SCHEME_MAPPINGS = {
DEFAULT_SCHEME => "",
:warning => "flash-warn",
:danger => "flash-error",
:success => "flash-success"
}.freeze
# @example Schemes
# <%= render(Primer::Beta::Flash.new) { "This is a flash message!" } %>
# <%= render(Primer::Beta::Flash.new(scheme: :warning)) { "This is a warning flash message!" } %>
# <%= render(Primer::Beta::Flash.new(scheme: :danger)) { "This is a danger flash message!" } %>
# <%= render(Primer::Beta::Flash.new(scheme: :success)) { "This is a success flash message!" } %>
#
# @example Full width
# <%= render(Primer::Beta::Flash.new(full: true)) { "This is a full width flash message!" } %>
#
# @example Dismissible
# <%= render(Primer::Beta::Flash.new(dismissible: true)) { "This is a dismissible flash message!" } %>
#
# @example Icon
# <%= render(Primer::Beta::Flash.new(icon: :people)) { "This is a flash message with an icon!" } %>
#
# @example With actions
# <%= render(Primer::Beta::Flash.new) do |component| %>
# This is a flash message with actions!
# <% component.action do %>
# <%= render(Primer::ButtonComponent.new(size: :small)) { "Take action" } %>
# <% end %>
# <% end %>
#
# @param full [Boolean] Whether the component should take up the full width of the screen.
# @param spacious [Boolean] Whether to add margin to the bottom of the component.
# @param dismissible [Boolean] Whether the component can be dismissed with an X button.
# @param icon [Symbol] Name of Octicon icon to use.
# @param scheme [Symbol] <%= one_of(Primer::Beta::Flash::SCHEME_MAPPINGS.keys) %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(full: false, spacious: false, dismissible: false, icon: nil, scheme: DEFAULT_SCHEME, **system_arguments)
@icon = icon
@dismissible = dismissible
@system_arguments = deny_tag_argument(**system_arguments)
@system_arguments[:tag] = :div
@system_arguments[:classes] = class_names(
@system_arguments[:classes],
"flash",
SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_MAPPINGS.keys, scheme, DEFAULT_SCHEME)],
"flash-full": full
)
@system_arguments[:mb] ||= spacious ? 4 : nil
end
end
end
end
69 changes: 0 additions & 69 deletions app/components/primer/flash_component.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module ArgumentMappers
# Maps classes in a flash element to arguments for the Flash component.
class Flash < Base
SCHEME_MAPPINGS = Primer::ViewComponents::Constants.get(
component: "Primer::FlashComponent",
component: "Primer::Beta::Flash",
constant: "SCHEME_MAPPINGS",
symbolize: true
).freeze
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
module ERBLint
module Linters
# Counts the number of times a HTML flash is used instead of the component.
class FlashComponentMigrationCounter < BaseLinter
class FlashMigrationCounter < BaseLinter
include Autocorrectable

TAGS = %w[div].freeze
CLASSES = %w[flash].freeze
MESSAGE = "We are migrating flashes to use [Primer::FlashComponent](https://primer.style/view-components/components/flash), please try to use that instead of raw HTML."
MESSAGE = "We are migrating flashes to use [Primer::Beta::Flash](https://primer.style/view-components/components/flash), please try to use that instead of raw HTML."
ARGUMENT_MAPPER = ArgumentMappers::Flash
COMPONENT = "Primer::FlashComponent"
COMPONENT = "Primer::Beta::Flash"

def map_arguments(tag, tag_tree)
# We can only autocorrect elements with simple text as content.
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/docs.rake
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace :docs do
Primer::DetailsComponent,
Primer::Dropdown,
Primer::DropdownMenuComponent,
Primer::FlashComponent,
Primer::Beta::Flash,
Primer::FlexComponent,
Primer::FlexItemComponent,
Primer::HeadingComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class FlashComponentPreview < ViewComponent::Preview
# @param icon [Symbol] select [alert, check, info, people]
# @param scheme [Symbol] select [default, warning, danger, success]
# @param content text
def playground(full: false, spacious: false, dismissible: false, icon: :people, scheme: Primer::FlashComponent::DEFAULT_SCHEME, content: "This is a flash message!")
render(Primer::FlashComponent.new(full: full, spacious: spacious, dismissible: dismissible, icon: icon, scheme: scheme)) { content }
def playground(full: false, spacious: false, dismissible: false, icon: :people, scheme: Primer::Beta::Flash::DEFAULT_SCHEME, content: "This is a flash message!")
render(Primer::Beta::Flash.new(full: full, spacious: spacious, dismissible: dismissible, icon: icon, scheme: scheme)) { content }
end
end
end
54 changes: 27 additions & 27 deletions static/arguments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,33 @@
type: Hash
default: N/A
description: "[System arguments](/system-arguments)"
- component: Flash
source: https://github.com/primer/view_components/tree/main/app/components/primer/beta/flash.rb
parameters:
- name: full
type: Boolean
default: "`false`"
description: Whether the component should take up the full width of the screen.
- name: spacious
type: Boolean
default: "`false`"
description: Whether to add margin to the bottom of the component.
- name: dismissible
type: Boolean
default: "`false`"
description: Whether the component can be dismissed with an X button.
- name: icon
type: Symbol
default: "`nil`"
description: Name of Octicon icon to use.
- name: scheme
type: Symbol
default: "`:default`"
description: One of `:danger`, `:default`, `:success`, or `:warning`.
- name: system_arguments
type: Hash
default: N/A
description: "[System arguments](/system-arguments)"
- component: Text
source: https://github.com/primer/view_components/tree/main/app/components/primer/beta/text.rb
parameters:
Expand Down Expand Up @@ -546,33 +573,6 @@
type: Hash
default: N/A
description: "[System arguments](/system-arguments)"
- component: Flash
source: https://github.com/primer/view_components/tree/main/app/components/primer/flash_component.rb
parameters:
- name: full
type: Boolean
default: "`false`"
description: Whether the component should take up the full width of the screen.
- name: spacious
type: Boolean
default: "`false`"
description: Whether to add margin to the bottom of the component.
- name: dismissible
type: Boolean
default: "`false`"
description: Whether the component can be dismissed with an X button.
- name: icon
type: Symbol
default: "`nil`"
description: Name of Octicon icon to use.
- name: scheme
type: Symbol
default: "`:default`"
description: One of `:danger`, `:default`, `:success`, or `:warning`.
- name: system_arguments
type: Hash
default: N/A
description: "[System arguments](/system-arguments)"
- component: Flex
source: https://github.com/primer/view_components/tree/main/app/components/primer/flex_component.rb
parameters:
Expand Down
2 changes: 1 addition & 1 deletion static/audited_at.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"Primer::Beta::Blankslate": "",
"Primer::Beta::Breadcrumbs": "",
"Primer::Beta::Breadcrumbs::Item": "",
"Primer::Beta::Flash": "",
"Primer::Beta::Text": "",
"Primer::Beta::Truncate": "",
"Primer::Beta::Truncate::TruncateText": "",
Expand All @@ -35,7 +36,6 @@
"Primer::Dropdown::Menu": "",
"Primer::Dropdown::Menu::Item": "",
"Primer::DropdownMenuComponent": "",
"Primer::FlashComponent": "",
"Primer::FlexComponent": "",
"Primer::FlexItemComponent": "",
"Primer::HeadingComponent": "",
Expand Down
18 changes: 9 additions & 9 deletions static/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,15 @@
},
"Primer::Beta::Breadcrumbs::Item": {
},
"Primer::Beta::Flash": {
"DEFAULT_SCHEME": "default",
"SCHEME_MAPPINGS": {
"default": "",
"warning": "flash-warn",
"danger": "flash-error",
"success": "flash-success"
}
},
"Primer::Beta::Text": {
"DEFAULT_TAG": "span"
},
Expand Down Expand Up @@ -427,15 +436,6 @@
"dark": "dropdown-menu-dark"
}
},
"Primer::FlashComponent": {
"DEFAULT_SCHEME": "default",
"SCHEME_MAPPINGS": {
"default": "",
"warning": "flash-warn",
"danger": "flash-error",
"success": "flash-success"
}
},
"Primer::FlexComponent": {
"ALIGN_ITEMS_DEFAULT": null,
"ALIGN_ITEMS_MAPPINGS": {
Expand Down
2 changes: 1 addition & 1 deletion static/statuses.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"Primer::Beta::Blankslate": "beta",
"Primer::Beta::Breadcrumbs": "beta",
"Primer::Beta::Breadcrumbs::Item": "alpha",
"Primer::Beta::Flash": "beta",
"Primer::Beta::Text": "beta",
"Primer::Beta::Truncate": "beta",
"Primer::Beta::Truncate::TruncateText": "alpha",
Expand All @@ -35,7 +36,6 @@
"Primer::Dropdown::Menu": "alpha",
"Primer::Dropdown::Menu::Item": "alpha",
"Primer::DropdownMenuComponent": "deprecated",
"Primer::FlashComponent": "beta",
"Primer::FlexComponent": "deprecated",
"Primer::FlexItemComponent": "deprecated",
"Primer::HeadingComponent": "beta",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

class Primer::FlashComponentStories < ViewComponent::Storybook::Stories
class Primer::Beta::FlashStories < ViewComponent::Storybook::Stories
layout "storybook_preview"

story(:flash) do
controls do
text(:icon, "people")
select(:scheme, Primer::FlashComponent::SCHEME_MAPPINGS.keys, :default)
select(:scheme, Primer::Beta::Flash::SCHEME_MAPPINGS.keys, :default)
full false
spacious false
dismissible false
Expand Down
Loading