-
Notifications
You must be signed in to change notification settings - Fork 114
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
Add docs for {Flex,FlexItem}Component #190
Merged
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d795979
Add docs for FlexItemComponent
srt32 a8e0562
Add docs for FlexComponent
srt32 3fbcebf
Merge branch 'main' into st-docs-for-flex-item
srt32 0dfd567
Single periods only, pls
srt32 0a22760
Add some examples
srt32 ffaa1c0
Add flex stories
srt32 df686b2
Merge branch 'main' into st-docs-for-flex-item
srt32 3245ffc
Make story better
srt32 c15478c
Exclude builds on rails@main and ruby<2.7
srt32 c5ec1fc
Remove errant new line
srt32 6da5b83
Use html divs to resolve styling problem
srt32 e919f50
Resolve lint issue in story
srt32 9fa5b2d
Add missing period
srt32 ed55318
Merge branch 'main' into st-docs-for-flex-item
srt32 c32bb94
Use Box instead of div
srt32 35af920
Use bg system arg
srt32 c28d0f1
Merge branch 'main' into st-docs-for-flex-item
srt32 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,73 @@ | ||
--- | ||
title: Flex | ||
status: Experimental | ||
source: https://github.com/primer/view_components/tree/main/app/components/primer/flex_component.rb | ||
--- | ||
|
||
<!-- Warning: AUTO-GENERATED file, do not edit. Add code comments to your Ruby instead <3 --> | ||
|
||
Use FlexComponent to make an element lay out its content using the flexbox model. | ||
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). | ||
|
||
## Examples | ||
|
||
### Default | ||
|
||
<iframe style="width: 100%; border: 0px; height: 100px;" srcdoc="<html><head><link href='https://unpkg.com/@primer/css/dist/primer.css' rel='stylesheet'></head><body><div class='bg-gray d-flex'> <div class='border p-5 bg-gray-light'>Item 1</div> <div class='border p-5 bg-gray-light'>Item 2</div> <div class='border p-5 bg-gray-light'>Item 3</div></div></body></html>"></iframe> | ||
|
||
```erb | ||
<%= render(Primer::FlexComponent.new(bg: :gray)) do %> | ||
<%= render(Primer::BoxComponent.new(p: 5, bg: :gray_light, classes: "border")) { "Item 1" } %> | ||
<%= render(Primer::BoxComponent.new(p: 5, bg: :gray_light, classes: "border")) { "Item 2" } %> | ||
<%= render(Primer::BoxComponent.new(p: 5, bg: :gray_light, classes: "border")) { "Item 3" } %> | ||
<% end %> | ||
``` | ||
|
||
### Justify center | ||
|
||
<iframe style="width: 100%; border: 0px; height: 100px;" srcdoc="<html><head><link href='https://unpkg.com/@primer/css/dist/primer.css' rel='stylesheet'></head><body><div class='flex-justify-center bg-gray d-flex'> <div class='border p-5 bg-gray-light'>Item 1</div> <div class='border p-5 bg-gray-light'>Item 2</div> <div class='border p-5 bg-gray-light'>Item 3</div></div></body></html>"></iframe> | ||
|
||
```erb | ||
<%= render(Primer::FlexComponent.new(justify_content: :center, bg: :gray)) do %> | ||
<%= render(Primer::BoxComponent.new(p: 5, bg: :gray_light, classes: "border")) { "Item 1" } %> | ||
<%= render(Primer::BoxComponent.new(p: 5, bg: :gray_light, classes: "border")) { "Item 2" } %> | ||
<%= render(Primer::BoxComponent.new(p: 5, bg: :gray_light, classes: "border")) { "Item 3" } %> | ||
<% end %> | ||
``` | ||
|
||
### Align end | ||
|
||
<iframe style="width: 100%; border: 0px; height: 100px;" srcdoc="<html><head><link href='https://unpkg.com/@primer/css/dist/primer.css' rel='stylesheet'></head><body><div class='flex-items-end bg-gray d-flex'> <div class='border p-5 bg-gray-light'>Item 1</div> <div class='border p-5 bg-gray-light'>Item 2</div> <div class='border p-5 bg-gray-light'>Item 3</div></div></body></html>"></iframe> | ||
|
||
```erb | ||
<%= render(Primer::FlexComponent.new(align_items: :end, bg: :gray)) do %> | ||
<%= render(Primer::BoxComponent.new(p: 5, bg: :gray_light, classes: "border")) { "Item 1" } %> | ||
<%= render(Primer::BoxComponent.new(p: 5, bg: :gray_light, classes: "border")) { "Item 2" } %> | ||
<%= render(Primer::BoxComponent.new(p: 5, bg: :gray_light, classes: "border")) { "Item 3" } %> | ||
<% end %> | ||
``` | ||
|
||
### Direction column | ||
|
||
<iframe style="width: 100%; border: 0px; height: 100px;" srcdoc="<html><head><link href='https://unpkg.com/@primer/css/dist/primer.css' rel='stylesheet'></head><body><div class='bg-gray flex-column d-flex'> <div class='border p-5 bg-gray-light'>Item 1</div> <div class='border p-5 bg-gray-light'>Item 2</div> <div class='border p-5 bg-gray-light'>Item 3</div></div></body></html>"></iframe> | ||
|
||
```erb | ||
<%= render(Primer::FlexComponent.new(direction: :column, bg: :gray)) do %> | ||
<%= render(Primer::BoxComponent.new(p: 5, bg: :gray_light, classes: "border")) { "Item 1" } %> | ||
<%= render(Primer::BoxComponent.new(p: 5, bg: :gray_light, classes: "border")) { "Item 2" } %> | ||
<%= render(Primer::BoxComponent.new(p: 5, bg: :gray_light, classes: "border")) { "Item 3" } %> | ||
<% end %> | ||
``` | ||
|
||
## Arguments | ||
|
||
| Name | Type | Default | Description | | ||
| :- | :- | :- | :- | | ||
| `justify_content` | `Symbol` | `JUSTIFY_CONTENT_DEFAULT` | Use this param to distribute space between and around flex items along the main axis of the container. One of `nil`, `:flex_start`, `:flex_end`, `:center`, `:space_between`, or `:space_around`. | | ||
| `inline` | `Boolean` | `false` | Defaults to false. | | ||
| `flex_wrap` | `Boolean` | `FLEX_WRAP_DEFAULT` | Defaults to nil. | | ||
| `align_items` | `Symbol` | `ALIGN_ITEMS_DEFAULT` | Use this param to align items on the cross axis. One of `nil`, `:start`, `:end`, `:center`, `:baseline`, or `:stretch`. | | ||
| `direction` | `Symbol` | `nil` | Use this param to define the orientation of the main axis (row or column). By default, flex items will display in a row. One of `nil`, `:column`, `:column_reverse`, `:row`, or `:row_reverse`. | | ||
| `system_arguments` | `Hash` | N/A | [System arguments](/system-arguments) | |
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,35 @@ | ||
--- | ||
title: FlexItem | ||
status: Experimental | ||
source: https://github.com/primer/view_components/tree/main/app/components/primer/flex_item_component.rb | ||
--- | ||
|
||
<!-- Warning: AUTO-GENERATED file, do not edit. Add code comments to your Ruby instead <3 --> | ||
|
||
Use FlexItemComponent to specify the ability of a flex item to alter its | ||
dimensions to fill available space | ||
|
||
## Examples | ||
|
||
### Default | ||
|
||
<iframe style="width: 100%; border: 0px; height: 100px;" srcdoc="<html><head><link href='https://unpkg.com/@primer/css/dist/primer.css' rel='stylesheet'></head><body><div class='d-flex'> <div> Item 1</div> <div class='flex-auto '> Item 2</div></div></body></html>"></iframe> | ||
|
||
```erb | ||
<%= render(Primer::FlexComponent.new) do %> | ||
<%= render(Primer::FlexItemComponent.new) do %> | ||
Item 1 | ||
<% end %> | ||
|
||
<%= render(Primer::FlexItemComponent.new(flex_auto: true)) do %> | ||
Item 2 | ||
<% end %> | ||
<% end %> | ||
``` | ||
|
||
## Arguments | ||
|
||
| Name | Type | Default | Description | | ||
| :- | :- | :- | :- | | ||
| `flex_auto` | `Boolean` | `false` | Fills available space and auto-sizes based on the content. Defaults to false | | ||
| `system_arguments` | `Hash` | N/A | [System arguments](/system-arguments) | |
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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
class Primer::FlexComponentStories < ViewComponent::Storybook::Stories | ||
layout "storybook_preview" | ||
|
||
story(:default) do | ||
controls do | ||
select(:justify_content, Primer::FlexComponent::JUSTIFY_CONTENT_OPTIONS, :center) | ||
select(:align_items, Primer::FlexComponent::ALIGN_ITEMS_OPTIONS, :start) | ||
select(:direction, Primer::FlexComponent::ALLOWED_DIRECTIONS, :row) | ||
inline false | ||
flex_wrap false | ||
end | ||
|
||
content do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @manuelpuyol is there anything you think we could do to avoid the |
||
# rubocop:disable Rails/OutputSafety | ||
"<div class='p-5 border bg-gray-light'>Item 1</div> | ||
<div class='p-5 border bg-gray-light'>Item 2</div> | ||
<div class='p-5 border bg-gray-light'>Item 3</div>".html_safe | ||
# rubocop:enable Rails/OutputSafety | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a boolean but also defaults to nil... what's the right thing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@srt32 that's a good question. What do we do in Primer React?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question!
I also just noticed this on https://primer.style/components/Flex
Maybe we should deprecate FlexItem?
I am having a hard time grokking the PRC (I'm new to the codebase) but it looks to mainly delegate to
Box
, which delegates to styleSystem.The API though is directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emplums what do you think? I'd generally lean towards deprecating all of the Flex-related components and just encourage the usage of Box with the flex-related system arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joelhawksley the proposed game plan for PRC is that
Box
andFlex
will have all the same properties, the only difference isFlex
will havedisplay: flex
set by default. The idea is that it will be handy shortcut from having to typedisplay: flex
over and over, and will still keep the ease of grokking the code to see exactly where flex is being used