Repository navigation
feat(mosaic): add Card.Media #10590
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
feat(mosaic): add Card.Media #10590
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 @@ | ||
| --- | ||
| '@clerk/mosaic': patch | ||
| --- | ||
|
|
||
| Add `Card.Media`, a slot for a logo, icon or image at the top of `Card.Header`, with 24px of space below it. Style it with `.cl-card-media`. `Card.Header` also takes an `align` prop, `start` by default, so `align='center'` centers its content. |
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,81 @@ | ||
| import { cleanup, render, screen } from '@testing-library/react'; | ||
| import { afterEach, describe, expect, it } from 'vitest'; | ||
|
|
||
| import { Dialog } from '../dialog'; | ||
| import { Card } from './card'; | ||
|
|
||
| afterEach(() => cleanup()); | ||
|
|
||
| describe('Card.Media', () => { | ||
| it('leaves 24px between the media and the title', () => { | ||
| render( | ||
| <Card.Root renderBranding={false}> | ||
| <Card.Header> | ||
| <Card.Media data-testid='media'> | ||
| <svg | ||
| width='32' | ||
| height='32' | ||
| /> | ||
| </Card.Media> | ||
| <Card.Title data-testid='title'>Title</Card.Title> | ||
| <Card.Description>Description</Card.Description> | ||
| </Card.Header> | ||
| </Card.Root>, | ||
| ); | ||
|
|
||
| const mediaBottom = screen.getByTestId('media').getBoundingClientRect().bottom; | ||
| const titleTop = screen.getByTestId('title').getBoundingClientRect().top; | ||
|
|
||
| expect(titleTop - mediaBottom).toBe(24); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Card.Header align', () => { | ||
| function CenteredCard() { | ||
| return ( | ||
| <Card.Root | ||
| renderBranding={false} | ||
| data-testid='root' | ||
| > | ||
| <Card.Header align='center'> | ||
| <Card.Media data-testid='media'> | ||
| <svg | ||
| width='32' | ||
| height='32' | ||
| /> | ||
| </Card.Media> | ||
| <Card.Title> | ||
| <span data-testid='title'>Title</span> | ||
| </Card.Title> | ||
| </Card.Header> | ||
| </Card.Root> | ||
| ); | ||
| } | ||
|
|
||
| function expectCentered(testId: string) { | ||
| const root = screen.getByTestId('root').getBoundingClientRect(); | ||
| const part = screen.getByTestId(testId).getBoundingClientRect(); | ||
| expect(part.left + part.width / 2).toBeCloseTo(root.left + root.width / 2, 0); | ||
| } | ||
|
|
||
| it('centers the media and title in the card', () => { | ||
| render(<CenteredCard />); | ||
|
|
||
| expectCentered('media'); | ||
| expectCentered('title'); | ||
| }); | ||
|
|
||
| it('keeps them centered in the card beside the dialog close button', () => { | ||
| render( | ||
| <Dialog.Root defaultOpen> | ||
| <Dialog.Popup> | ||
| <CenteredCard /> | ||
| </Dialog.Popup> | ||
| </Dialog.Root>, | ||
| ); | ||
|
|
||
| expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument(); | ||
| expectCentered('media'); | ||
| expectCentered('title'); | ||
| }); | ||
| }); | ||
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
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
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
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,2 +1,2 @@ | ||
| export { Card } from './card'; | ||
| export type { CardBannerProps, CardProps, CardSize } from './card'; | ||
| export type { CardBannerProps, CardHeaderAlign, CardHeaderProps, CardProps, CardSize } from './card'; |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.