-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Take NoResult component out of table, update stories
- Loading branch information
1 parent
ea811ef
commit 93dc1e3
Showing
6 changed files
with
134 additions
and
70 deletions.
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,51 @@ | ||
import styled from 'styled-components'; | ||
import { Icon } from './icon/Icon.component'; | ||
import { Loader } from './loader/Loader.component'; | ||
import { | ||
TableHeightKeyType, | ||
TableLocalType, | ||
tableRowHeight, | ||
translatedMessages, | ||
} from './tablev2/TableUtils'; | ||
import { Text } from './text/Text.component'; | ||
import { Box } from '../next'; | ||
import { spacing } from '../spacing'; | ||
|
||
export const NoResult = styled(Box)<{ height?: number | string }>` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
color: ${(props) => props.theme.textSecondary}; | ||
height: ${(props) => props.height}rem; | ||
gap: ${spacing.r8}; | ||
`; | ||
|
||
export type UnsuccessfulResultProps = { | ||
name?: { | ||
en: { singular: string; plural: string }; | ||
fr?: { singular: string; plural: string }; | ||
}; | ||
locale?: TableLocalType; | ||
status: 'error' | 'loading' | 'idle' | 'noResult'; | ||
heightInRem?: number | string; | ||
} & ( | ||
| { rowHeight?: TableHeightKeyType; heightInRem?: never } | ||
| { rowHeight?: never; heightInRem?: number | string } | ||
); | ||
|
||
export const UnsuccessfulResult = (props: UnsuccessfulResultProps) => { | ||
const { heightInRem = 5, name, locale, status, rowHeight } = props; | ||
const height = rowHeight ? tableRowHeight[rowHeight] : heightInRem; | ||
return ( | ||
<NoResult height={height}> | ||
{(status === 'loading' || status === 'idle') && <Loader />} | ||
{status === 'error' && ( | ||
<Icon name="Exclamation-circle" color="statusWarning" /> | ||
)} | ||
|
||
<Text color="textSecondary"> | ||
{translatedMessages(status, name, locale)} | ||
</Text> | ||
</NoResult> | ||
); | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { | ||
UnsuccessfulResult, | ||
UnsuccessfulResultProps, | ||
} from '../src/lib/components/UnsuccessfulResult.component.tsx'; | ||
|
||
type Story = StoryObj<UnsuccessfulResultProps>; | ||
|
||
const meta: Meta<UnsuccessfulResultProps> = { | ||
title: 'Components/NoResult', | ||
component: UnsuccessfulResult, | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Loading: Story = { | ||
render: () => { | ||
return <UnsuccessfulResult status="loading" />; | ||
}, | ||
}; | ||
|
||
export const Error: Story = { | ||
render: () => { | ||
return <UnsuccessfulResult status="error" />; | ||
}, | ||
}; | ||
|
||
export const NoResult: Story = { | ||
render: () => { | ||
return <UnsuccessfulResult status="noResult" />; | ||
}, | ||
}; |
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