-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd661b8
commit ccea558
Showing
8 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/components/empty-data/__tests__/__snapshots__/empty-data.test.tsx.snap
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,25 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`EmptyData > should render default component properly and match snapshot 1`] = ` | ||
<DocumentFragment> | ||
<div | ||
class="mocked-styled-3 el-empty-data" | ||
> | ||
<div | ||
class="mocked-styled-0 el-empty-data-description" | ||
> | ||
Description | ||
</div> | ||
<div | ||
class="mocked-styled-1 el-empty-data-secondary-description" | ||
> | ||
Secondary Description | ||
</div> | ||
<button | ||
class="mocked-styled-2 el-empty-data-action-button" | ||
> | ||
Action Button Text | ||
</button> | ||
</div> | ||
</DocumentFragment> | ||
`; |
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,15 @@ | ||
import { render } from '@testing-library/react' | ||
import { EmptyData } from '../empty-data' | ||
|
||
describe('EmptyData', () => { | ||
it('should render default component properly and match snapshot', () => { | ||
const { asFragment } = render( | ||
<EmptyData> | ||
<EmptyData.Description>Description</EmptyData.Description> | ||
<EmptyData.SecondaryDescription>Secondary Description</EmptyData.SecondaryDescription> | ||
<EmptyData.ActionButton onClick={console.log}>Action Button Text</EmptyData.ActionButton> | ||
</EmptyData>, | ||
) | ||
expect(asFragment()).toMatchSnapshot() | ||
}) | ||
}) |
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,32 @@ | ||
import { Meta, Story, Canvas, Controls, Description } from '@storybook/blocks' | ||
import { RenderHtmlMarkup } from '../../storybook/render-html-markup' | ||
import * as EmptyDataStories from './empty-data.stories' | ||
|
||
<Meta of={EmptyDataStories} /> | ||
|
||
|
||
# Empty Data | ||
|
||
<Description of={EmptyDataStories.Default} /> | ||
|
||
<Controls /> | ||
|
||
## Default | ||
|
||
<Canvas of={EmptyDataStories.Default} /> | ||
|
||
<RenderHtmlMarkup of={EmptyDataStories.Default} /> | ||
|
||
## Description Only | ||
|
||
<Canvas of={EmptyDataStories.DescriptionOnly} /> | ||
|
||
<RenderHtmlMarkup of={EmptyDataStories.DescriptionOnly} /> | ||
|
||
|
||
## Action Only | ||
|
||
<Canvas of={EmptyDataStories.ActionOnly} /> | ||
|
||
<RenderHtmlMarkup of={EmptyDataStories.ActionOnly} /> | ||
|
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,50 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import { EmptyData } from './empty-data' | ||
|
||
const meta: Meta<typeof EmptyData> = { | ||
title: 'Components/Empty Data', | ||
} | ||
|
||
export default meta | ||
type Story = StoryObj<typeof EmptyData> | ||
|
||
/** | ||
* The EmptyData component is designed to emphasize that current section of the page | ||
* has empty data, but could possibly have different content when there is data available. | ||
* The default variant renders a circle with children. | ||
* | ||
* There are three variants available for the EmptyData component: | ||
* Default (full version), Description Only, and Action Only. | ||
* See the examples below for more details of the usage. | ||
*/ | ||
export const Default: Story = { | ||
render() { | ||
return ( | ||
<EmptyData> | ||
<EmptyData.Description>No things found</EmptyData.Description> | ||
<EmptyData.SecondaryDescription>Secondary text</EmptyData.SecondaryDescription> | ||
<EmptyData.ActionButton onClick={console.log}>Add Thing</EmptyData.ActionButton> | ||
</EmptyData> | ||
) | ||
}, | ||
} | ||
|
||
export const DescriptionOnly: Story = { | ||
render() { | ||
return ( | ||
<EmptyData> | ||
<EmptyData.Description>No things found</EmptyData.Description> | ||
<EmptyData.SecondaryDescription>Secondary text</EmptyData.SecondaryDescription> | ||
</EmptyData> | ||
) | ||
}, | ||
} | ||
export const ActionOnly: Story = { | ||
render() { | ||
return ( | ||
<EmptyData> | ||
<EmptyData.ActionButton onClick={console.log}>Action</EmptyData.ActionButton> | ||
</EmptyData> | ||
) | ||
}, | ||
} |
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 type { HTMLAttributes } from 'react' | ||
import { ElEmptyData, ElEmptyDataActionButton, ElEmptyDataDescription, ElEmptyDataSecondaryDescription } from './styles' | ||
import type React from 'react' | ||
|
||
type EmptyDataFC = React.FC<HTMLAttributes<HTMLDivElement>> & { | ||
Description: typeof ElEmptyDataDescription | ||
SecondaryDescription: typeof ElEmptyDataSecondaryDescription | ||
ActionButton: typeof ElEmptyDataActionButton | ||
} | ||
|
||
const EmptyData: EmptyDataFC = ({ children, ...props }) => <ElEmptyData {...props}>{children}</ElEmptyData> | ||
|
||
EmptyData.Description = ElEmptyDataDescription | ||
EmptyData.SecondaryDescription = ElEmptyDataSecondaryDescription | ||
EmptyData.ActionButton = ElEmptyDataActionButton | ||
|
||
export { EmptyData } |
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 * from './empty-data.js' | ||
export * from './styles.js' |
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,50 @@ | ||
import { styled } from '@linaria/react' | ||
|
||
export const ElEmptyDataDescription = styled.div` | ||
color: var(text-primary); | ||
font-size: var(--font-size-base); | ||
font-weight: var(--font-weight-regular); | ||
line-height: var(--line-height-base); | ||
letter-spacing: var(--letter-spacing-base); | ||
` | ||
|
||
export const ElEmptyDataSecondaryDescription = styled.div` | ||
color: var(--text-secondary); | ||
font-size: var(--font-size-sm,); | ||
font-weight: var(--font-weight-regular,); | ||
line-height: var(--line-height-sm,); | ||
letter-spacing: var(--letter-spacing-sm); | ||
` | ||
|
||
export const ElEmptyDataActionButton = styled.button` | ||
color: var(--text-action); | ||
font-size: var(--font-size-sm); | ||
font-weight: var(--font-weight-medium); | ||
line-height: var(--line-height-sm); | ||
letter-spacing: var(--letter-spacing-sm); | ||
border: none; | ||
background: none; | ||
cursor: pointer; | ||
` | ||
|
||
export const ElEmptyData = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
width: 100%; | ||
// TODO: ask design team to clarify | ||
height: 186px; | ||
padding: var(--spacing-6); | ||
border-radius: var(--corner-lg); | ||
background: var(--fill-default-lightest); | ||
${ElEmptyDataSecondaryDescription} + ${ElEmptyDataActionButton} { | ||
margin-top: var(--spacing-1); | ||
} | ||
& * { | ||
font-family: var(--font-family); | ||
} | ||
` |
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