-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into hotfix/uws-cork
- Loading branch information
Showing
20 changed files
with
361 additions
and
374 deletions.
There are no files selected for viewing
138 changes: 104 additions & 34 deletions
138
packages/client/components/ActivityLibrary/ActivityCard.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 |
---|---|---|
@@ -1,68 +1,138 @@ | ||
import clsx from 'clsx' | ||
import React, {ComponentPropsWithoutRef, PropsWithChildren} from 'react' | ||
import React, {PropsWithChildren, useEffect, useRef, useState} from 'react' | ||
import {upperFirst} from '../../utils/upperFirst' | ||
import {MeetingTypeEnum} from '../../__generated__/NewMeetingQuery.graphql' | ||
import {ActivityCard_template$key} from '../../__generated__/ActivityCard_template.graphql' | ||
import {backgroundImgMap, CategoryID, MEETING_TYPE_TO_CATEGORY} from './Categories' | ||
import {twMerge} from 'tailwind-merge' | ||
import {Tooltip} from '../../ui/Tooltip/Tooltip' | ||
import {TooltipTrigger} from '../../ui/Tooltip/TooltipTrigger' | ||
import {TooltipContent} from '../../ui/Tooltip/TooltipContent' | ||
import {useFragment} from 'react-relay' | ||
import graphql from 'babel-plugin-relay/macro' | ||
import {ActivityLibraryCardDescription} from './ActivityLibraryCardDescription' | ||
|
||
export interface CardTheme { | ||
primary: string | ||
secondary: string | ||
text: string | ||
} | ||
|
||
export const ActivityCardImage = ( | ||
props: PropsWithChildren<React.ImgHTMLAttributes<HTMLImageElement>> | ||
) => { | ||
const {className, src} = props | ||
|
||
return ( | ||
<div | ||
className={clsx( | ||
'my-1 flex flex-1 items-center justify-center overflow-hidden px-4', | ||
className | ||
)} | ||
> | ||
<img className={'h-full w-full object-contain'} src={src} /> | ||
</div> | ||
) | ||
type ActivityCardImageProps = { | ||
className?: string | ||
src: string | ||
category: CategoryID | ||
} | ||
|
||
const ActivityCardTitle = (props: ComponentPropsWithoutRef<'div'>) => { | ||
const {children, className, ...rest} = props | ||
export const ActivityCardImage = (props: PropsWithChildren<ActivityCardImageProps>) => { | ||
const {className, src, category} = props | ||
const backgroundSrc = backgroundImgMap[category] | ||
|
||
return ( | ||
<div | ||
className={clsx( | ||
'px-2 py-1 text-sm font-semibold leading-5 text-slate-800 sm:text-base', | ||
className={twMerge( | ||
'relative flex h-full w-full items-center justify-center overflow-hidden', | ||
className | ||
)} | ||
{...rest} | ||
style={{backgroundImage: `url(${backgroundSrc})`, backgroundSize: 'cover'}} | ||
> | ||
{children} | ||
<img | ||
className='absolute top-0 left-0 z-10 h-full w-full object-contain p-10' | ||
src={src} | ||
alt='Card Illustration' | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export interface ActivityCardProps { | ||
className?: string | ||
theme: CardTheme | ||
titleAs?: React.ElementType | ||
title?: string | ||
badge?: React.ReactNode | ||
children?: React.ReactNode | ||
type?: MeetingTypeEnum | ||
templateRef?: ActivityCard_template$key | ||
} | ||
|
||
export const ActivityCard = (props: ActivityCardProps) => { | ||
const {className, theme, title, titleAs, badge, children} = props | ||
const Title = titleAs ?? ActivityCardTitle | ||
const {className, theme, title, children, type, badge, templateRef} = props | ||
const category = type && MEETING_TYPE_TO_CATEGORY[type] | ||
const [showTooltip, setShowTooltip] = useState(false) | ||
const hoverTimeout = useRef<NodeJS.Timeout | null>(null) | ||
|
||
const template = useFragment( | ||
graphql` | ||
fragment ActivityCard_template on MeetingTemplate { | ||
...ActivityLibraryCardDescription_template | ||
} | ||
`, | ||
templateRef ?? null | ||
) | ||
|
||
const handleMouseEnter = () => { | ||
hoverTimeout.current = setTimeout(() => { | ||
setShowTooltip(true) | ||
}, 500) | ||
} | ||
|
||
const handleMouseLeave = () => { | ||
if (hoverTimeout.current) { | ||
clearTimeout(hoverTimeout.current) | ||
} | ||
setShowTooltip(false) | ||
} | ||
|
||
useEffect(() => { | ||
return () => { | ||
if (hoverTimeout.current) { | ||
clearTimeout(hoverTimeout.current) | ||
} | ||
} | ||
}, []) | ||
|
||
return ( | ||
<div className={clsx('flex flex-col overflow-hidden rounded-lg', theme.secondary, className)}> | ||
<div className='flex flex-shrink-0'> | ||
<Title>{title}</Title> | ||
<div className={clsx('ml-auto h-8 w-8 flex-shrink-0 rounded-bl-full', theme.primary)} /> | ||
</div> | ||
{children} | ||
<div className='flex flex-shrink-0 group-hover/card:hidden'> | ||
<div className={clsx('mt-auto h-8 w-8 flex-shrink-0 rounded-tr-full', theme.primary)} /> | ||
<div className='ml-auto'>{badge}</div> | ||
<div | ||
className='flex w-full flex-col' | ||
onMouseEnter={handleMouseEnter} | ||
onMouseLeave={handleMouseLeave} | ||
> | ||
<div | ||
className={twMerge( | ||
'relative flex h-full min-w-0 flex-col overflow-hidden rounded-lg', | ||
`bg-${theme.secondary}`, | ||
className | ||
)} | ||
> | ||
<div className='flex-1'> | ||
{children} | ||
<div className='absolute bottom-0 right-0'>{badge}</div> | ||
</div> | ||
{template && ( | ||
<Tooltip open={showTooltip}> | ||
<TooltipTrigger asChild> | ||
<div className='h-50 w-50 text-sky-500 hover:text-sky-700' /> | ||
</TooltipTrigger> | ||
<TooltipContent | ||
side='bottom' | ||
align='center' | ||
sideOffset={20} | ||
className='max-w-md whitespace-normal rounded-lg bg-white p-4 text-left text-slate-700 shadow-lg hover:cursor-pointer sm:max-w-sm' | ||
> | ||
<div className='mb-2 text-left text-lg font-semibold'>{title}</div> | ||
<ActivityLibraryCardDescription templateRef={template} /> | ||
</TooltipContent> | ||
</Tooltip> | ||
)} | ||
</div> | ||
{title && category && ( | ||
<div className='mt-2 px-2 pb-2'> | ||
<div className='truncate pb-1 text-lg leading-5 text-slate-800'>{title}</div> | ||
<div className={clsx('font-semibold italic', `text-${theme.primary}`)}> | ||
{upperFirst(category)} | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} |
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
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.