Skip to content

Commit

Permalink
feat: add profile types filtering to new map
Browse files Browse the repository at this point in the history
  • Loading branch information
benfurber committed Sep 6, 2024
1 parent d551b2b commit 590f9e3
Show file tree
Hide file tree
Showing 19 changed files with 506 additions and 69 deletions.
16 changes: 16 additions & 0 deletions packages/components/src/CardButton/CardButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { CardButton } from './CardButton'

import type { Meta, StoryFn } from '@storybook/react'

export default {
title: 'Components/CardButton',
component: CardButton,
} as Meta<typeof CardButton>

export const Basic: StoryFn<typeof CardButton> = () => (
<div style={{ width: '300px' }}>
<CardButton>
<div style={{ padding: '20px' }}>Basic Implementation</div>
</CardButton>
</div>
)
43 changes: 43 additions & 0 deletions packages/components/src/CardButton/CardButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Card } from 'theme-ui'

import type { BoxProps, ThemeUIStyleObject } from 'theme-ui'

export interface IProps extends BoxProps {
children: React.ReactNode
extraSx?: ThemeUIStyleObject | undefined
}

export const CardButton = (props: IProps) => {
const { children, extraSx } = props

return (
<Card
sx={{
alignItems: 'center',
alignContent: 'center',
marginTop: '2px',
borderRadius: 2,
padding: 0,
transition: 'borderBottom 0.2s, transform 0.2s',
'&:hover': {
animationSpeed: '0.3s',
cursor: 'pointer',
marginTop: '0',
borderBottom: '4px solid',
transform: 'translateY(-2px)',
borderColor: 'black',
},
'&:active': {
transform: 'translateY(1px)',
borderBottom: '3px solid',
borderColor: 'grey',
transition: 'borderBottom 0.2s, transform 0.2s, borderColor 0.2s',
},
...extraSx,
}}
{...props}
>
{children}
</Card>
)
}
6 changes: 3 additions & 3 deletions packages/components/src/CardList/CardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ export const CardList = (props: IProps) => {

const isListEmpty = displayItems.length === 0
const hasListLoaded = list
const results = `${displayItems.length} ${
displayItems.length == 1 ? 'result' : 'results'
}`
const results = `${displayItems.length} result${displayItems.length == 1 ? '' : 's'} in view`

return (
<Flex
data-cy={`CardList-${dataCy}`}
sx={{
flexDirection: 'column',
gap: 2,
padding: 2,
}}
>
{!hasListLoaded && <Loader />}
Expand All @@ -49,6 +48,7 @@ export const CardList = (props: IProps) => {
sx={{
justifyContent: 'space-between',
paddingX: 2,
paddingTop: 2,
fontSize: 2,
}}
>
Expand Down
30 changes: 4 additions & 26 deletions packages/components/src/CardListItem/CardListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Card, Flex } from 'theme-ui'
import { Flex } from 'theme-ui'

import { CardButton } from '../CardButton/CardButton'
import { InternalLink } from '../InternalLink/InternalLink'
import { CardDetailsFallback } from './CardDetailsFallback'
import { CardDetailsMemberProfile } from './CardDetailsMemberProfile'
Expand All @@ -26,30 +27,7 @@ export const CardListItem = ({ item }: IProps) => {
padding: 2,
}}
>
<Card
sx={{
marginTop: '2px',
borderRadius: 2,
padding: 0,
'&:hover': {
animationSpeed: '0.3s',
cursor: 'pointer',
marginTop: '0',
borderBottom: '4px solid',
transform: 'translateY(-2px)',
transition: 'borderBottom 0.2s, transform 0.2s',
borderColor: 'black',
},
'&:active': {
transform: 'translateY(1px)',
borderBottom: '3px solid',
borderColor: 'grey',
transition: 'borderBottom 0.2s, transform 0.2s, borderColor 0.2s',
},
alignItems: 'stretch',
alignContent: 'stretch',
}}
>
<CardButton>
<Flex sx={{ gap: 2, alignItems: 'stretch', alignContent: 'stretch' }}>
{isMember && <CardDetailsMemberProfile creator={creator} />}

Expand All @@ -59,7 +37,7 @@ export const CardListItem = ({ item }: IProps) => {

{!creator && <CardDetailsFallback item={item} />}
</Flex>
</Card>
</CardButton>
</InternalLink>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const DonationRequest = (props: IProps) => {

<Flex
sx={{
backgroundColor: 'offwhite',
backgroundColor: 'offWhite',
borderTop: '2px solid',
flexDirection: ['column', 'row'],
padding: 2,
Expand Down
107 changes: 107 additions & 0 deletions packages/components/src/FilterList/FilterList.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { useState } from 'react'

import { FilterList } from './FilterList'

import type { Meta, StoryFn } from '@storybook/react'
import type { ProfileTypeName } from 'oa-shared'

export default {
title: 'Components/FilterList',
component: FilterList,
} as Meta<typeof FilterList>

const availableFilters = [
{
label: 'Workspace',
type: 'workspace' as ProfileTypeName,
},
{
label: 'Machine Builder',
type: 'machine-builder' as ProfileTypeName,
},
{
label: 'Collection Point',
type: 'collection-point' as ProfileTypeName,
},
{
label: 'Want to get started',
type: 'member' as ProfileTypeName,
},
]

export const Basic: StoryFn<typeof FilterList> = () => {
const [activeFilters, setActiveFilters] = useState<string[]>([])

const onFilterChange = (label: string) => {
const filter = label.toLowerCase()
const isFilterPresent = !!activeFilters.find(
(existing) => existing === filter,
)
if (isFilterPresent) {
return setActiveFilters(activeFilters.filter((f) => f !== filter))
}
return setActiveFilters((existing) => [...existing, filter])
}

return (
<div style={{ maxWidth: '500px' }}>
<FilterList
activeFilters={activeFilters}
availableFilters={availableFilters}
onFilterChange={onFilterChange}
/>
</div>
)
}

export const OnlyOne: StoryFn<typeof FilterList> = () => {
const [activeFilters, setActiveFilters] = useState<string[]>([])

const onFilterChange = (label: string) => {
const filter = label.toLowerCase()
const isFilterPresent = !!activeFilters.find(
(existing) => existing === filter,
)
if (isFilterPresent) {
return setActiveFilters(activeFilters.filter((f) => f !== filter))
}
return setActiveFilters((existing) => [...existing, filter])
}

return (
<div style={{ maxWidth: '500px' }}>
<FilterList
activeFilters={activeFilters}
availableFilters={[availableFilters[0]]}
onFilterChange={onFilterChange}
/>
(Shouldn't see anything, only renders for two or more)
</div>
)
}

export const OnlyTwo: StoryFn<typeof FilterList> = () => {
const [activeFilters, setActiveFilters] = useState<string[]>([])

const onFilterChange = (label: string) => {
const filter = label.toLowerCase()
const isFilterPresent = !!activeFilters.find(
(existing) => existing === filter,
)
if (isFilterPresent) {
return setActiveFilters(activeFilters.filter((f) => f !== filter))
}
return setActiveFilters((existing) => [...existing, filter])
}

return (
<div style={{ maxWidth: '500px' }}>
<FilterList
activeFilters={activeFilters}
availableFilters={[availableFilters[0], availableFilters[1]]}
onFilterChange={onFilterChange}
/>
(No buttons rendered)
</div>
)
}
Loading

0 comments on commit 590f9e3

Please sign in to comment.