-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Layout foundations] Stack component prototype #7036
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
chazdean
merged 13 commits into
layout-foundations-prototype
from
feat/add-stack-component
Sep 2, 2022
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
21f54af
Add AlphaStack component
chazdean d5b50cc
Update AlphaStack
chazdean 9602707
add changeset
chazdean af58578
Fix token name
chazdean c295e9a
Remove `Item` component
chazdean a1adabe
Refactor `AlphaStack`
chazdean 83e1e29
Update Stack.scss
chazdean 4a0331f
Remove `stackItems` & add default alignment
chazdean 07c89c3
Update .changeset/poor-kiwis-travel.md
chazdean 8afd07f
Update AlphaStack styling
chazdean c6d9384
Create AlphaStack.stories.tsx
chazdean 048c0f1
Create AlphaStack.test.tsx
chazdean eb89d90
Update custom style properties
chazdean 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 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,5 @@ | ||
| --- | ||
| '@shopify/polaris': patch | ||
| --- | ||
|
|
||
| Add `AlphaStack` component | ||
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,45 @@ | ||
| import React from 'react'; | ||
| import type {spacing} from '@shopify/polaris-tokens'; | ||
|
|
||
| import {classNames, variationName} from '../../utilities/css'; | ||
| import {elementChildren} from '../../utilities/components'; | ||
|
|
||
| import styles from './Stack.scss'; | ||
|
|
||
| type SpacingTokenGroup = typeof spacing; | ||
| type SpacingTokenName = keyof SpacingTokenGroup; | ||
|
|
||
| // TODO: Bring this logic into tokens | ||
| type Spacing = SpacingTokenName extends `space-${infer Scale}` ? Scale : never; | ||
|
|
||
| type Align = 'start' | 'end' | 'center'; | ||
|
|
||
| export interface AlphaStackProps { | ||
| /** Elements to display inside stack */ | ||
| children?: React.ReactNode; | ||
| /** Adjust spacing between elements */ | ||
| spacing?: Spacing; | ||
| /** Adjust vertical alignment of elements */ | ||
| align?: Align; | ||
| } | ||
|
|
||
| export const AlphaStack = ({children, spacing, align}: AlphaStackProps) => { | ||
chazdean marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const className = classNames( | ||
| styles.Stack, | ||
| align && styles[variationName('align', align)], | ||
| ); | ||
|
|
||
| const style = { | ||
| '--pc-stack-spacing': spacing ? `var(--p-space-${spacing})` : '', | ||
chazdean marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } as React.CSSProperties; | ||
|
|
||
| const stackItems = elementChildren(children).map((child, index) => { | ||
| return <div key={index}>{child}</div>; | ||
| }); | ||
chazdean marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
| <div className={className} style={style}> | ||
| {stackItems} | ||
| </div> | ||
| ); | ||
| }; | ||
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,19 @@ | ||
| .Stack { | ||
| --pc-stack-spacing: var(--p-space-4); | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: start; | ||
chazdean marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| gap: var(--pc-stack-spacing); | ||
| } | ||
|
|
||
| .alignStart { | ||
| align-items: flex-start; | ||
chazdean marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| .alignEnd { | ||
| align-items: flex-end; | ||
| } | ||
|
|
||
| .alignCenter { | ||
| align-items: center; | ||
| } | ||
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 @@ | ||
| export * from './AlphaStack'; |
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
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.
Uh oh!
There was an error while loading. Please reload this page.