-
-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add banner component * refactor: move some map related typing to shared * chore: drop unused map store function * feat: add CardList component for new map display * ci: separate unit test run commands
- Loading branch information
Showing
56 changed files
with
863 additions
and
345 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
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,30 @@ | ||
import { Banner } from './Banner' | ||
|
||
import type { Meta, StoryFn } from '@storybook/react' | ||
|
||
export default { | ||
title: 'Layout/Banner', | ||
component: Banner, | ||
} as Meta<typeof Banner> | ||
|
||
export const Default: StoryFn<typeof Banner> = () => ( | ||
<Banner>Defaults to a failure banner when no varient defined</Banner> | ||
) | ||
|
||
export const AccentWithOnclick: StoryFn<typeof Banner> = () => ( | ||
<Banner variant="accent" onClick={() => null}> | ||
This is an accent with onClick | ||
</Banner> | ||
) | ||
|
||
export const InfoWithCustomStylings: StoryFn<typeof Banner> = () => ( | ||
<Banner variant="info" sx={{ height: '200px', border: '4px solid #333' }}> | ||
Info with custom stylings | ||
</Banner> | ||
) | ||
|
||
export const Success: StoryFn<typeof Banner> = () => ( | ||
<Banner variant="success" onClick={() => null}> | ||
Success Banner | ||
</Banner> | ||
) |
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,16 @@ | ||
import { fireEvent } from '@testing-library/react' | ||
import { describe, expect, it, vi } from 'vitest' | ||
|
||
import { render } from '../test/utils' | ||
import { Banner } from './Banner' | ||
|
||
describe('Banner', () => { | ||
it('sets the default varient if none is provided', () => { | ||
const onClick = vi.fn() | ||
const { getByText } = render(<Banner onClick={onClick}>Some words</Banner>) | ||
|
||
fireEvent.click(getByText('Some words')) | ||
|
||
expect(onClick).toHaveBeenCalled() | ||
}) | ||
}) |
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,37 @@ | ||
import { Alert } from 'theme-ui' | ||
|
||
import type { ThemeUIStyleObject } from 'theme-ui' | ||
|
||
// Types of alert currently specificed in the theme | ||
type AlertVariants = 'accent' | 'failure' | 'info' | 'success' | ||
|
||
export interface IProps { | ||
children: React.ReactNode | ||
onClick?: () => void | ||
sx?: ThemeUIStyleObject | undefined | ||
variant?: AlertVariants | ||
} | ||
|
||
export const Banner = (props: IProps) => { | ||
const { children, onClick, sx, variant } = props | ||
|
||
return ( | ||
<Alert | ||
data-cy="Banner" | ||
onClick={onClick} | ||
variant={variant || 'failure'} | ||
sx={{ | ||
borderRadius: 0, | ||
alignItems: 'center', | ||
flex: '1', | ||
justifyContent: 'center', | ||
cursor: onClick ? 'pointer' : 'default', | ||
fontSize: 2, | ||
':hover': { textDecoration: onClick ? 'underline' : 'none' }, | ||
...sx, | ||
}} | ||
> | ||
{children} | ||
</Alert> | ||
) | ||
} |
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,30 @@ | ||
import { CardList } from './CardList' | ||
|
||
import type { Meta, StoryFn } from '@storybook/react' | ||
import type { ProfileTypeName } from 'oa-shared' | ||
|
||
export default { | ||
title: 'Layout/CardList', | ||
component: CardList, | ||
} as Meta<typeof CardList> | ||
|
||
const allItems = [ | ||
{ _id: 'first-one', type: 'member' as ProfileTypeName }, | ||
{ _id: 'second-one', type: 'collection-point' as ProfileTypeName }, | ||
{ _id: 'third', type: 'member' as ProfileTypeName }, | ||
{ _id: '4th', type: 'member' as ProfileTypeName }, | ||
] | ||
|
||
export const Default: StoryFn<typeof CardList> = () => { | ||
return <CardList list={allItems} filteredList={null} /> | ||
} | ||
|
||
export const FiltedDisplay: StoryFn<typeof CardList> = () => { | ||
const filteredList = [allItems[0], allItems[2]] | ||
|
||
return <CardList list={allItems} filteredList={filteredList} /> | ||
} | ||
|
||
export const WhenFiltedDisplayIsZero: StoryFn<typeof CardList> = () => { | ||
return <CardList list={allItems} filteredList={[]} /> | ||
} |
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,35 @@ | ||
import '@testing-library/jest-dom/vitest' | ||
|
||
import { describe, expect, it } from 'vitest' | ||
|
||
import { render } from '../test/utils' | ||
import { EMPTY_LIST, type IProps } from './CardList' | ||
import { | ||
Default, | ||
FiltedDisplay, | ||
WhenFiltedDisplayIsZero, | ||
} from './CardList.stories' | ||
|
||
describe('CardList', () => { | ||
it('Shows all items when no filtering is done', () => { | ||
const { getAllByTestId } = render(<Default {...(Default.args as IProps)} />) | ||
|
||
expect(getAllByTestId('CardListItem').length).toBe(4) | ||
}) | ||
|
||
it('Shows only filted items when provided', () => { | ||
const { getAllByTestId } = render( | ||
<FiltedDisplay {...(FiltedDisplay.args as IProps)} />, | ||
) | ||
|
||
expect(getAllByTestId('CardListItem').length).toBe(2) | ||
}) | ||
|
||
it('Shows the no items label when filted items is empty', () => { | ||
const { getByText } = render( | ||
<WhenFiltedDisplayIsZero {...(WhenFiltedDisplayIsZero.args as IProps)} />, | ||
) | ||
|
||
expect(getByText(EMPTY_LIST)).toBeInTheDocument() | ||
}) | ||
}) |
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,57 @@ | ||
import { Flex, Grid, Text } from 'theme-ui' | ||
|
||
import { CardListItem } from '../CardListItem/CardListItem' | ||
import { Loader } from '../Loader/Loader' | ||
|
||
import type { ListItem } from '../CardListItem/CardListItem' | ||
|
||
export interface IProps { | ||
filteredList: ListItem[] | null | ||
list: ListItem[] | ||
} | ||
|
||
export const EMPTY_LIST = 'Oh nos! Nothing to show!' | ||
|
||
export const CardList = (props: IProps) => { | ||
const { filteredList, list } = props | ||
|
||
const listToShow = filteredList === null ? list : filteredList | ||
const displayItems = listToShow.map((item) => ( | ||
<CardListItem item={item} key={item._id} /> | ||
)) | ||
|
||
const isListEmpty = displayItems.length === 0 | ||
const hasListLoaded = list | ||
const results = `${displayItems.length} ${displayItems.length == 1 ? 'result' : 'results'}` | ||
|
||
return ( | ||
<Flex | ||
data-cy="CardList" | ||
sx={{ | ||
flexDirection: 'column', | ||
gap: 4, | ||
}} | ||
> | ||
{!hasListLoaded && <Loader />} | ||
{hasListLoaded && ( | ||
<> | ||
<Flex> | ||
<Text data-cy="list-results">{results}</Text> | ||
</Flex> | ||
<Grid | ||
sx={{ | ||
alignItems: 'flex-start', | ||
flexWrap: 'wrap', | ||
gap: 4, | ||
}} | ||
width="250px" | ||
columns={3} | ||
> | ||
{!isListEmpty && displayItems} | ||
{isListEmpty && EMPTY_LIST} | ||
</Grid> | ||
</> | ||
)} | ||
</Flex> | ||
) | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/components/src/CardListItem/CardListItem.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,27 @@ | ||
import { CardListItem } from './CardListItem' | ||
|
||
import type { Meta, StoryFn } from '@storybook/react' | ||
import type { ProfileTypeName } from 'oa-shared' | ||
|
||
export default { | ||
title: 'Components/CardListItem', | ||
component: CardListItem, | ||
} as Meta<typeof CardListItem> | ||
|
||
export const DefaultMember: StoryFn<typeof CardListItem> = () => { | ||
const item = { | ||
_id: 'not-selected-onload', | ||
type: 'member' as ProfileTypeName, | ||
} | ||
|
||
return <CardListItem item={item} /> | ||
} | ||
|
||
export const DefaultSpace: StoryFn<typeof CardListItem> = () => { | ||
const item = { | ||
_id: 'not-selected-onload', | ||
type: 'workspace' as ProfileTypeName, | ||
} | ||
|
||
return <CardListItem item={item} /> | ||
} |
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,58 @@ | ||
import { Card, Flex } from 'theme-ui' | ||
|
||
import { InternalLink } from '../InternalLink/InternalLink' | ||
import { MemberBadge } from '../MemberBadge/MemberBadge' | ||
import { Username } from '../Username/Username' | ||
|
||
import type { ProfileTypeName } from 'oa-shared' | ||
|
||
export interface ListItem { | ||
_id: string | ||
type: ProfileTypeName | ||
} | ||
|
||
export interface IProps { | ||
item: ListItem | ||
} | ||
|
||
export const CardListItem = (props: IProps) => { | ||
const { item } = props | ||
|
||
return ( | ||
<InternalLink | ||
data-cy="CardListItem" | ||
data-testid="CardListItem" | ||
to={`/u/${item._id}`} | ||
sx={{ | ||
borderRadius: 2, | ||
marginTop: '2px', | ||
'&:hover': { | ||
animationSpeed: '0.3s', | ||
cursor: 'pointer', | ||
marginTop: '0', | ||
borderBottom: '2px solid', | ||
transform: 'translateY(-2px)', | ||
transition: 'borderBottom 0.2s, transform 0.2s', | ||
borderColor: 'black', | ||
}, | ||
'&:active': { | ||
transform: 'translateY(1px)', | ||
borderBottom: '1px solid', | ||
borderColor: 'grey', | ||
transition: 'borderBottom 0.2s, transform 0.2s, borderColor 0.2s', | ||
}, | ||
}} | ||
> | ||
<Card> | ||
<Flex sx={{ flexDirection: 'row', gap: 2, padding: 2 }}> | ||
<MemberBadge profileType={item.type} size={30} /> | ||
<Username | ||
user={{ userName: item._id }} | ||
hideFlag | ||
sx={{ alignSelf: 'flex-start' }} | ||
/> | ||
</Flex> | ||
</Card> | ||
</InternalLink> | ||
) | ||
} |
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.