-
Notifications
You must be signed in to change notification settings - Fork 63
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
Adds ListSkeleton
component [LG-4196]
#2295
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ad04af8
initial list skeleton
TheSonOfThomp e2bc0f6
Updates list skeleton styles
TheSonOfThomp 1229b13
adds test case
TheSonOfThomp ca6801a
Create swift-garlics-wave.md
TheSonOfThomp e1a5720
update import
TheSonOfThomp f2fb5ce
revert table stories
TheSonOfThomp e6e258c
Merge branch 'main' into adam/skeleton-list
TheSonOfThomp cd75576
Merge branch 'main' into adam/skeleton-list
TheSonOfThomp 2921624
update docs & comments
TheSonOfThomp 801e8e9
Merge branch 'main' into adam/skeleton-list
shaneeza 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@leafygreen-ui/skeleton-loader': minor | ||
--- | ||
|
||
Adds `ListSkeleton` component |
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
17 changes: 17 additions & 0 deletions
17
packages/skeleton-loader/src/ListSkeleton/ListSkeleton.spec.tsx
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,17 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import { ListSkeleton } from '.'; | ||
|
||
describe('packages/skeleton-list', () => { | ||
test('renders', () => { | ||
const { queryByTestId } = render(<ListSkeleton />); | ||
expect(queryByTestId('lg-skeleton-list')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders `count` items', () => { | ||
const { queryAllByTestId } = render(<ListSkeleton count={3} />); | ||
const listItems = queryAllByTestId('lg-skeleton-list_item'); | ||
expect(listItems.length).toBe(3); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
packages/skeleton-loader/src/ListSkeleton/ListSkeleton.stories.tsx
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,36 @@ | ||
import React from 'react'; | ||
import { StoryMetaType, StoryType } from '@lg-tools/storybook-utils'; | ||
|
||
import { ListSkeleton, type ListSkeletonProps } from '.'; | ||
|
||
const meta: StoryMetaType<typeof ListSkeleton> = { | ||
title: 'Components/SkeletonLoader/List', | ||
component: ListSkeleton, | ||
parameters: { | ||
default: null, | ||
}, | ||
args: { | ||
count: 5, | ||
bulletsOnly: false, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Basic: StoryType<typeof ListSkeleton> = ( | ||
args: ListSkeletonProps, | ||
) => { | ||
return ( | ||
<div style={{ width: 256 }}> | ||
<ListSkeleton {...args} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export const BulletsOnly: StoryType<typeof ListSkeleton> = () => { | ||
return ( | ||
<div style={{ width: 256 }}> | ||
<ListSkeleton bulletsOnly /> | ||
</div> | ||
); | ||
}; |
31 changes: 31 additions & 0 deletions
31
packages/skeleton-loader/src/ListSkeleton/ListSkeleton.styles.ts
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,31 @@ | ||
import { css } from '@leafygreen-ui/emotion'; | ||
import { spacing } from '@leafygreen-ui/tokens'; | ||
|
||
export const skeletonListWrapperStyles = css` | ||
width: 100%; | ||
padding: 0; | ||
margin: 0; | ||
`; | ||
|
||
export const getSkeletonListItemStyles = ( | ||
index = 0, | ||
bulletsOnly?: boolean, | ||
) => css` | ||
list-style: none; | ||
|
||
&:not(:first-child), | ||
&:not(:last-child) { | ||
margin-block: ${spacing[300]}px; | ||
} | ||
|
||
width: ${getWidth(index, bulletsOnly)}; | ||
`; | ||
|
||
const getWidth = (index = 0, bulletsOnly?: boolean) => { | ||
if (bulletsOnly) { | ||
return spacing[400] + 'px'; | ||
} | ||
|
||
const offset = 25 * (index % 3); | ||
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. Can you add comments here? |
||
return 100 - offset + '%'; | ||
}; |
43 changes: 43 additions & 0 deletions
43
packages/skeleton-loader/src/ListSkeleton/ListSkeleton.tsx
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,43 @@ | ||
import React from 'react'; | ||
import range from 'lodash/range'; | ||
|
||
import LeafyGreenProvider from '@leafygreen-ui/leafygreen-provider'; | ||
|
||
import { Skeleton } from '../Skeleton'; | ||
|
||
import { | ||
getSkeletonListItemStyles, | ||
skeletonListWrapperStyles, | ||
} from './ListSkeleton.styles'; | ||
import { ListSkeletonProps } from './ListSkeleton.types'; | ||
|
||
export function ListSkeleton({ | ||
count = 5, | ||
bulletsOnly, | ||
darkMode, | ||
...rest | ||
}: ListSkeletonProps) { | ||
return ( | ||
<LeafyGreenProvider darkMode={darkMode}> | ||
<ul | ||
className={skeletonListWrapperStyles} | ||
data-testid="lg-skeleton-list" | ||
aria-busy="true" | ||
{...rest} | ||
> | ||
{range(count).map(i => ( | ||
<li | ||
// Update the key when `count` changes so the item animation stays in sync | ||
key={`${i}/${count}`} | ||
className={getSkeletonListItemStyles(i, bulletsOnly)} | ||
data-testid="lg-skeleton-list_item" | ||
> | ||
<Skeleton size="small" /> | ||
</li> | ||
))} | ||
</ul> | ||
</LeafyGreenProvider> | ||
); | ||
} | ||
|
||
ListSkeleton.displayName = 'ListSkeleton'; |
8 changes: 8 additions & 0 deletions
8
packages/skeleton-loader/src/ListSkeleton/ListSkeleton.types.ts
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,8 @@ | ||
import { DarkModeProps, HTMLElementProps } from '@leafygreen-ui/lib'; | ||
|
||
export interface ListSkeletonProps | ||
extends DarkModeProps, | ||
HTMLElementProps<'ul'> { | ||
count?: number; | ||
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. Can you add docs? |
||
bulletsOnly?: boolean; | ||
} |
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,2 @@ | ||
export { ListSkeleton } from './ListSkeleton'; | ||
export { ListSkeletonProps } from './ListSkeleton.types'; |
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
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.
this still targets the first and last element, is that what you want?
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.
what about
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.
Ah, I don't actually need this anymore since I'm using margin. (was using padding previously)