Repository navigation
Components: Add VStack #28798
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
Merged
Merged
Components: Add VStack #28798
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
981578e
Rename hstack stories file to match Gutenberg
sarayourfriend 0cecc59
Components: Add G2 VStack
sarayourfriend a087692
Clean up README
sarayourfriend b5994e4
Add v stack and h stack to the ui/index
sarayourfriend 0dd5cf2
Update VStack snapshots
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
File renamed without changes.
This file contains hidden or 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,5 +1,7 @@ | ||
| export * from './flex'; | ||
| export * from './grid'; | ||
| export * from './h-stack'; | ||
| export * from './text'; | ||
| export * from './truncate'; | ||
| export * from './v-stack'; | ||
| export * from './view'; |
This file contains hidden or 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,123 @@ | ||
| # VStack | ||
|
|
||
| `VStack` (or Vertical Stack) is a layout component that arranges child elements in a vertical line. | ||
|
|
||
| ## Usage | ||
|
|
||
| `VStack` can render anything inside. | ||
|
|
||
| ```jsx live | ||
| import { VStack, Text, View } from '@wp-g2/components'; | ||
| import { ui } from '@wp-g2/styles'; | ||
|
|
||
| function Example() { | ||
| return ( | ||
| <VStack css={[ui.frame.height(200)]}> | ||
| <View css={[ui.background.blue]}> | ||
| <Text>Ana</Text> | ||
| </View> | ||
| <View css={[ui.background.blue]}> | ||
| <Text>Elsa</Text> | ||
| </View> | ||
| <View css={[ui.background.blue]}> | ||
| <Text>Olaf</Text> | ||
| </View> | ||
| </VStack> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ## Props | ||
|
|
||
| ##### alignment | ||
|
|
||
| **Type**: `HStackAlignment`,`CSS['alignItems']` | ||
|
|
||
| Determines how the child elements are aligned. | ||
|
|
||
| - `top`: Aligns content to the top. | ||
| - `topLeft`: Aligns content to the top/left. | ||
| - `topRight`: Aligns content to the top/right. | ||
| - `left`: Aligns content to the left. | ||
| - `center`: Aligns content to the center. | ||
| - `right`: Aligns content to the right. | ||
| - `bottom`: Aligns content to the bottom. | ||
| - `bottomLeft`: Aligns content to the bottom/left. | ||
| - `bottomRight`: Aligns content to the bottom/right. | ||
| - `edge`: Aligns content to the edges of the container. | ||
| - `stretch`: Stretches content to the edges of the container. | ||
|
|
||
| ##### direction | ||
|
|
||
| **Type**: `FlexDirection` | ||
|
|
||
| The direction flow of the children content can be adjusted with `direction`. `column` will align children vertically and `row` will align children horizontally. | ||
|
|
||
| ##### expanded | ||
|
|
||
| **Type**: `boolean` | ||
|
|
||
| Expands to the maximum available width (if horizontal) or height (if vertical). | ||
|
|
||
| ##### justify | ||
|
|
||
| **Type**: `CSS['justifyContent']` | ||
|
|
||
| Horizontally aligns content if the `direction` is `row`, or vertically aligns content if the `direction` is `column`. | ||
| In the example below, `flex-start` will align the children content to the left. | ||
|
|
||
| ##### spacing | ||
|
|
||
| **Type**: `CSS['width']` | ||
|
|
||
| The amount of space between each child element. Spacing in between each child can be adjusted by using `spacing`. | ||
| The value of `spacing` works as a multiplier to the library's grid system (base of `4px`). | ||
|
|
||
| ##### wrap | ||
|
|
||
| **Type**: `boolean` | ||
|
|
||
| Determines if children should wrap. | ||
|
|
||
| ## Spacer | ||
|
|
||
| When a `Spacer` is used within an `VStack`, the `Spacer` adaptively expands to take up the remaining space. | ||
|
|
||
| ```jsx | ||
| function Example() { | ||
| return ( | ||
| <VStack css={[ui.frame.height(200)]}> | ||
| <View css={[ui.background.blue]}> | ||
| <Text>Ana</Text> | ||
| </View> | ||
| <Spacer css={[ui.background.blue]}> | ||
| <Text>Elsa</Text> | ||
| </Spacer> | ||
| <View css={[ui.background.blue]}> | ||
| <Text>Olaf</Text> | ||
| </View> | ||
| </VStack> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| `Spacer` can also be used in-between items to push them apart. | ||
|
|
||
| ```jsx live | ||
| function Example() { | ||
| return ( | ||
| <VStack css={[ui.frame.height(200)]}> | ||
| <View css={[ui.background.blue]}> | ||
| <Text>Ana</Text> | ||
| </View> | ||
| <Spacer /> | ||
| <View css={[ui.background.blue]}> | ||
| <Text>Elsa</Text> | ||
| </View> | ||
| <View css={[ui.background.blue]}> | ||
| <Text>Olaf</Text> | ||
| </View> | ||
| </VStack> | ||
| ); | ||
| } | ||
| ``` | ||
This file contains hidden or 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,3 @@ | ||
| export { default as VStack } from './v-stack'; | ||
|
|
||
| export * from './use-v-stack'; |
Oops, something went wrong.
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.
I think we discussed avoiding these css props in public components right? what's the status of that?
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.
It's a good point, we should avoid it in the examples as well. I'll make a note to clean these up as we go along
cc/ @ItsJonQ
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.
@sarayourfriend Good call. We'll remove it from the examples