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

Deprecate FlexComponent in favor of BoxComponent #511

Merged
merged 3 commits into from
Apr 30, 2021
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

*Jon Rohan*

* Deprecate `FlexItem` in favor of `BoxComponent`.
* Deprecate `FlexItem` and `Flex` in favor of `BoxComponent`.

*Manuel Puyol*

Expand Down
27 changes: 27 additions & 0 deletions app/components/primer/flex_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,32 @@ module Primer
# Before using these utilities, you should be familiar with CSS3 Flexible Box
# spec. If you are not, check out MDN's guide [Using CSS Flexible
# Boxes](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox).
#
# @deprecated
# Use <%= link_to_component(Primer::BoxComponent) %> instead.
#
# **Before**:
#
# ```erb
# <%%= render Primer::FlexComponent.new(justify_content: :center) %>
# <%%= render Primer::FlexComponent.new(inline: true) %>
# <%%= render Primer::FlexComponent.new(flex_wrap: true) %>
# <%%= render Primer::FlexComponent.new(align_items: :start) %>
# <%%= render Primer::FlexComponent.new(direction: :column) %>
# ```
#
# **After**:
#
# ```erb
# <%%= render Primer::BoxComponent.new(display: :flex, justify_content: :center) %>
# <%%= render Primer::BoxComponent.new(display: :inline_flex) %>
# <%%= render Primer::BoxComponent.new(display: :flex, flex_wrap: :wrap) %>
# <%%= render Primer::BoxComponent.new(display: :flex, align_items: :start) %>
# <%%= render Primer::BoxComponent.new(display: :flex, direction: :column) %>
# ```
class FlexComponent < Primer::Component
status :deprecated

JUSTIFY_CONTENT_DEFAULT = nil
JUSTIFY_CONTENT_MAPPINGS = {
flex_start: "flex-justify-start",
Expand Down Expand Up @@ -77,6 +102,8 @@ def initialize(
direction: nil,
**system_arguments
)
deprecated_component_warning(new_class: Primer::BoxComponent, version: "0.0.40")

@align_items = fetch_or_fallback(ALIGN_ITEMS_OPTIONS, align_items, ALIGN_ITEMS_DEFAULT)
@justify_content = fetch_or_fallback(JUSTIFY_CONTENT_OPTIONS, justify_content, JUSTIFY_CONTENT_DEFAULT)
@flex_wrap = fetch_or_fallback(FLEX_WRAP_OPTIONS, flex_wrap, FLEX_WRAP_DEFAULT)
Expand Down
2 changes: 1 addition & 1 deletion app/components/primer/flex_item_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FlexItemComponent < Primer::Component
# @param flex_auto [Boolean] Fills available space and auto-sizes based on the content. Defaults to <%= Primer::FlexItemComponent::FLEX_AUTO_DEFAULT %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(flex_auto: FLEX_AUTO_DEFAULT, **system_arguments)
deprecated_component_warning(new_class: Primer::BoxComponent, version: "0.0.39")
deprecated_component_warning(new_class: Primer::BoxComponent, version: "0.0.40")

@system_arguments = system_arguments
@system_arguments[:classes] =
Expand Down
26 changes: 25 additions & 1 deletion docs/content/components/flex.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Flex
status: Alpha
status: Deprecated
source: https://github.com/primer/view_components/tree/main/app/components/primer/flex_component.rb
storybook: https://primer.style/view-components/stories/?path=/story/primer-flex-component
---
Expand All @@ -14,6 +14,30 @@ Before using these utilities, you should be familiar with CSS3 Flexible Box
spec. If you are not, check out MDN's guide [Using CSS Flexible
Boxes](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox).

## Deprecation

Use [Box](/components/box) instead.

**Before**:

```erb
<%= render Primer::FlexComponent.new(justify_content: :center) %>
<%= render Primer::FlexComponent.new(inline: true) %>
<%= render Primer::FlexComponent.new(flex_wrap: true) %>
<%= render Primer::FlexComponent.new(align_items: :start) %>
<%= render Primer::FlexComponent.new(direction: :column) %>
```

**After**:

```erb
<%= render Primer::BoxComponent.new(display: :flex, justify_content: :center) %>
<%= render Primer::BoxComponent.new(display: :inline_flex) %>
<%= render Primer::BoxComponent.new(display: :flex, flex_wrap: :wrap) %>
<%= render Primer::BoxComponent.new(display: :flex, align_items: :start) %>
<%= render Primer::BoxComponent.new(display: :flex, direction: :column) %>
```

## Examples

### Default
Expand Down
2 changes: 1 addition & 1 deletion static/statuses.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Primer::AutoComplete":"beta","Primer::AutoComplete::Item":"beta","Primer::AvatarComponent":"beta","Primer::AvatarStackComponent":"beta","Primer::BaseButton":"beta","Primer::BaseComponent":"beta","Primer::BlankslateComponent":"beta","Primer::BorderBoxComponent":"beta","Primer::BoxComponent":"stable","Primer::BreadcrumbComponent":"beta","Primer::BreadcrumbComponent::ItemComponent":"alpha","Primer::ButtonComponent":"beta","Primer::ButtonGroup":"beta","Primer::ButtonMarketingComponent":"alpha","Primer::ClipboardCopy":"alpha","Primer::CloseButton":"beta","Primer::CounterComponent":"beta","Primer::DetailsComponent":"beta","Primer::Dropdown::MenuComponent":"alpha","Primer::DropdownComponent":"alpha","Primer::DropdownMenuComponent":"deprecated","Primer::FlashComponent":"beta","Primer::FlexComponent":"alpha","Primer::FlexItemComponent":"deprecated","Primer::HeadingComponent":"beta","Primer::HiddenTextExpander":"alpha","Primer::IconButton":"alpha","Primer::LabelComponent":"beta","Primer::LayoutComponent":"alpha","Primer::LinkComponent":"beta","Primer::MarkdownComponent":"alpha","Primer::MenuComponent":"alpha","Primer::Navigation::TabComponent":"alpha","Primer::OcticonComponent":"beta","Primer::PopoverComponent":"beta","Primer::ProgressBarComponent":"beta","Primer::SpinnerComponent":"beta","Primer::StateComponent":"beta","Primer::SubheadComponent":"beta","Primer::TabContainerComponent":"alpha","Primer::TabNavComponent":"alpha","Primer::TextComponent":"beta","Primer::TimeAgoComponent":"beta","Primer::TimelineItemComponent":"beta","Primer::TimelineItemComponent::BadgeComponent":"alpha","Primer::TooltipComponent":"alpha","Primer::Truncate":"beta","Primer::UnderlineNavComponent":"alpha"}
{"Primer::AutoComplete":"beta","Primer::AutoComplete::Item":"beta","Primer::AvatarComponent":"beta","Primer::AvatarStackComponent":"beta","Primer::BaseButton":"beta","Primer::BaseComponent":"beta","Primer::BlankslateComponent":"beta","Primer::BorderBoxComponent":"beta","Primer::BoxComponent":"stable","Primer::BreadcrumbComponent":"beta","Primer::BreadcrumbComponent::ItemComponent":"alpha","Primer::ButtonComponent":"beta","Primer::ButtonGroup":"beta","Primer::ButtonMarketingComponent":"alpha","Primer::ClipboardCopy":"alpha","Primer::CloseButton":"beta","Primer::CounterComponent":"beta","Primer::DetailsComponent":"beta","Primer::Dropdown::MenuComponent":"alpha","Primer::DropdownComponent":"alpha","Primer::DropdownMenuComponent":"deprecated","Primer::FlashComponent":"beta","Primer::FlexComponent":"deprecated","Primer::FlexItemComponent":"deprecated","Primer::HeadingComponent":"beta","Primer::HiddenTextExpander":"alpha","Primer::IconButton":"alpha","Primer::LabelComponent":"beta","Primer::LayoutComponent":"alpha","Primer::LinkComponent":"beta","Primer::MarkdownComponent":"alpha","Primer::MenuComponent":"alpha","Primer::Navigation::TabComponent":"alpha","Primer::OcticonComponent":"beta","Primer::PopoverComponent":"beta","Primer::ProgressBarComponent":"beta","Primer::SpinnerComponent":"beta","Primer::StateComponent":"beta","Primer::SubheadComponent":"beta","Primer::TabContainerComponent":"alpha","Primer::TabNavComponent":"alpha","Primer::TextComponent":"beta","Primer::TimeAgoComponent":"beta","Primer::TimelineItemComponent":"beta","Primer::TimelineItemComponent::BadgeComponent":"alpha","Primer::TooltipComponent":"alpha","Primer::Truncate":"beta","Primer::UnderlineNavComponent":"alpha"}
7 changes: 7 additions & 0 deletions test/components/flex_component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,11 @@ def test_renders_responsive_direction

assert_selector(".flex-row.flex-sm-column")
end

def test_warns_of_deprecation_if_not_silenced
with_silence_deprecations(false) do
ActiveSupport::Deprecation.expects(:warn).with("Primer::FlexComponent is deprecated and will be removed in v0.0.40. Use Primer::BoxComponent instead.").once
Primer::FlexComponent.new
end
end
end
2 changes: 1 addition & 1 deletion test/components/flex_item_component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_flex_auto_falls_back_to_false

def test_warns_of_deprecation_if_not_silenced
with_silence_deprecations(false) do
ActiveSupport::Deprecation.expects(:warn).with("Primer::FlexItemComponent is deprecated and will be removed in v0.0.39. Use Primer::BoxComponent instead.").once
ActiveSupport::Deprecation.expects(:warn).with("Primer::FlexItemComponent is deprecated and will be removed in v0.0.40. Use Primer::BoxComponent instead.").once
Primer::FlexItemComponent.new
end
end
Expand Down