Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions apps/website/src/components/workshop/WorkshopCardMark.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<script setup lang="ts">
// Who answers for the card: the provider of a model, the model a workflow runs
// on. It rides over the artwork rather than in the title, where it would spend
// the line and truncate, and it opens to the name on hover so a shelf reads as
// marks until the reader asks.
const { label, logo } = defineProps<{
label: string
logo: string | null
}>()
</script>

<template>
<span
class="pointer-events-none absolute right-4 bottom-4 z-10 inline-flex h-7 max-w-[calc(100%-2rem)] min-w-7 items-center justify-center rounded-lg bg-black/45 px-1.5 text-2xs/4 font-semibold text-white backdrop-blur-md"
data-testid="model-card-provider"
>
<span
v-if="logo"
class="size-3.5 shrink-0 bg-white mask-contain mask-center mask-no-repeat"
:style="{ maskImage: `url(${logo})` }"
aria-hidden="true"
/>
<span v-else class="shrink-0 text-xs" aria-hidden="true">
{{ label.charAt(0).toUpperCase() }}
</span>
<span
class="grid grid-cols-[0fr] transition-[grid-template-columns] duration-300 ease-out group-focus-within:grid-cols-[1fr] group-hover:grid-cols-[1fr]"
>
<span class="overflow-hidden">
<span class="block truncate pl-1.5 whitespace-nowrap">
{{ label }}
</span>
</span>
</span>
</span>
</template>
8 changes: 6 additions & 2 deletions apps/website/src/components/workshop/WorkshopCardMedia.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ const previewSrc = usePreviewVideo(video, () => model.thumbnail?.url)
</script>

<template>
<!-- The card names itself in its heading and marks its provider over the
artwork, so a third reading of the name here is noise in the link. -->
<video
v-if="model.thumbnail?.kind === 'video'"
ref="video"
:src="previewSrc"
:aria-label="model.name"
class="size-full object-cover transition-transform duration-300 group-hover:scale-105"
aria-hidden="true"
data-testid="model-card-media"
muted
loop
playsinline
Expand All @@ -24,8 +27,9 @@ const previewSrc = usePreviewVideo(video, () => model.thumbnail?.url)
<img
v-else-if="model.thumbnail"
:src="model.thumbnail.url"
:alt="model.name"
alt=""
class="size-full object-cover transition-transform duration-300 select-none group-hover:scale-105"
data-testid="model-card-media"
loading="lazy"
decoding="async"
draggable="false"
Expand Down
26 changes: 22 additions & 4 deletions apps/website/src/components/workshop/WorkshopModelCard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ describe('WorkshopModelCard', () => {
render(WorkshopModelCard, { props: { model: base } })
const link = screen.getByTestId('workshop-model-card')
expect(link.getAttribute('href')).toBe('/models/flux/')
expect(screen.getByText('Flux')).toBeTruthy()
expect(screen.getByRole('img', { name: 'Black Forest Labs' })).toBeTruthy()
expect(screen.getByTestId('model-card-name').textContent).toBe('Flux')
expect(screen.getByTestId('model-card-provider')).toHaveTextContent(
'Black Forest Labs'
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
expect(screen.getByTestId('model-card-task').textContent).toBe(
'Image to Image'
)
Expand All @@ -39,6 +40,23 @@ describe('WorkshopModelCard', () => {
expect(screen.queryByLabelText('Flux')).toBeNull()
})

// The artwork is decorative: the mark says who made this and the heading
// says what it is, so a reader hears each of them once.
it('names the card link by its provider and then the model', () => {
render(WorkshopModelCard, {
props: {
model: {
...base,
thumbnail: { kind: 'image', url: 'https://assets.example/flux' }
}
}
})
expect(screen.getByRole('link')).toHaveAccessibleName(
/^Black Forest Labs Flux Image to Image/
)
expect(screen.queryByRole('img', { name: 'Flux' })).toBeNull()
})

it.for([
{ locale: 'en', label: 'Incomplete' },
{ locale: 'zh-CN', label: '尚未完善' }
Expand Down Expand Up @@ -83,7 +101,7 @@ describe('WorkshopModelCard', () => {
}
})
await nextTick()
const video = screen.getByLabelText<HTMLVideoElement>('Flux')
const video = screen.getByTestId<HTMLVideoElement>('model-card-media')
expect(video).not.toHaveAttribute('src')
expect(video.paused).toBe(true)
expect(screen.getByRole('link', { name: /Flux/ })).toHaveAttribute(
Expand All @@ -106,7 +124,7 @@ describe('WorkshopModelCard', () => {
}
})
await setAllIntersecting(true)
expect(screen.getByLabelText('Flux')).toHaveAttribute(
expect(screen.getByTestId('model-card-media')).toHaveAttribute(
'src',
'https://assets.example/preview.mp4'
)
Expand Down
112 changes: 18 additions & 94 deletions apps/website/src/components/workshop/WorkshopModelCard.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<script setup lang="ts">
import { computed } from 'vue'

import { cn } from '@comfyorg/tailwind-utils'

import type { WorkshopModel } from '../../config/models-catalogue'
import type { Locale } from '../../i18n/translations'
import { t } from '../../i18n/translations'
Expand All @@ -11,6 +9,7 @@ import { getLogoPath } from '../../lib/hub/model-logos'
import { taskLabelFor } from '../../lib/workshop/task-label'
import TagRow from '../hub/TagRow.vue'
import ModelSupport from './ModelSupport.vue'
import WorkshopCardMark from './WorkshopCardMark.vue'
import WorkshopCardMedia from './WorkshopCardMedia.vue'

const {
Expand Down Expand Up @@ -51,124 +50,49 @@ const pillClass =
<template>
<a
:href="model.href"
class="group flex cursor-pointer flex-col gap-4 overflow-hidden rounded-4xl bg-hub-surface px-2 pt-2 pb-4 transition-colors duration-200 hover:bg-hub-surface-hover"
class="group flex cursor-pointer flex-col gap-3 overflow-hidden rounded-4xl bg-hub-surface px-2 pt-2 pb-4 transition-colors duration-200 hover:bg-hub-surface-hover"
data-testid="workshop-model-card"
:data-kind="workflow ? 'workflow' : 'model'"
>
<div
class="relative aspect-4/3 overflow-hidden rounded-3.5xl bg-hub-surface"
>
<!-- First in the link, so the reader hears who answers for the card
before its name rather than after everything else on it. -->
<WorkshopCardMark :label="providerName" :logo />

<!-- Only the hub mixes graphs, apps and models in one grid, so only
there does a card have to say which it is. -->
<HubTypeBadge v-if="providerBadge" kind="model" :locale />
<ModelSupport
v-if="model.incompleteReason"
:reason="model.incompleteReason"
:locale
:class="
cn(
'absolute z-10',
thumbnailLabel && providerBadge ? 'top-12 left-3' : 'top-3 right-3'
)
"
class="absolute top-3 right-3 z-10"
/>

<WorkshopCardMedia :model />

<span
v-if="thumbnailLabel"
:class="
cn(
'pointer-events-none absolute z-10 rounded-xl border border-white/10 bg-site-dropdown px-3 py-2 text-sm leading-none font-bold whitespace-nowrap text-primary-warm-white shadow-sm transition-all duration-500 select-none group-hover:opacity-0',
providerBadge
? 'top-3 right-3 group-hover:translate-x-1 group-hover:-translate-y-1'
: 'bottom-3 left-3 group-hover:-translate-x-1 group-hover:translate-y-1'
)
"
class="pointer-events-none absolute bottom-3 left-3 z-10 rounded-xl border border-white/10 bg-site-dropdown px-3 py-2 text-sm leading-none font-bold whitespace-nowrap text-primary-warm-white shadow-sm transition-all duration-500 select-none group-hover:-translate-x-1 group-hover:translate-y-1 group-hover:opacity-0"
aria-hidden="true"
data-testid="model-thumbnail-label"
>
{{ thumbnailLabel }}
</span>

<template v-if="providerBadge || workflow">
<div
class="pointer-events-none absolute inset-x-0 bottom-0 h-2/3 bg-linear-to-t from-black/70 via-black/30 to-transparent"
aria-hidden="true"
/>
<h3
:class="
cn(
'pointer-events-none absolute bottom-5 left-5 z-10 line-clamp-2 text-sm/[1.35] font-medium text-content-bright drop-shadow-md lg:text-base',
providerBadge ? 'right-16' : 'right-5'
)
"
:title="model.name"
>
{{ model.name }}
</h3>
</template>

<!-- The mark names its provider on hover, as a tooltip: spelled out on
the card it crossed the title. -->
<span
v-if="providerBadge"
class="pointer-events-none absolute right-5 bottom-5 z-10 inline-flex items-center gap-1.5 text-white drop-shadow-md"
:title="providerName"
data-testid="model-card-provider-badge"
>
<span
v-if="logo"
class="size-5 shrink-0 bg-white mask-contain mask-center mask-no-repeat"
:style="{ maskImage: `url(${logo})` }"
/>
<span v-else class="text-sm font-bold">
{{ providerName.charAt(0).toUpperCase() }}
</span>
</span>
</div>

<div class="flex flex-col gap-2 px-3">
<div class="flex min-w-0 items-center gap-2 text-content-secondary">
<!-- With the mark over the thumbnail, repeating it here would say the
same thing twice. -->
<span
v-if="!providerBadge && logo"
role="img"
:aria-label="providerName"
class="grid size-5 shrink-0 place-items-center"
data-testid="model-card-logo"
>
<span
class="size-5 bg-content-secondary mask-contain mask-center mask-no-repeat"
:style="{ maskImage: `url(${logo})` }"
/>
</span>
<span
v-else-if="!providerBadge"
class="grid size-5 shrink-0 place-items-center rounded-full bg-brand text-2xs font-bold text-page"
aria-hidden="true"
>
{{ providerName.charAt(0).toUpperCase() }}
</span>
<span
v-if="providerBadge || workflow"
class="ppformula-text-center-sm truncate text-sm"
data-testid="model-card-provider"
:title="providerName"
>
{{ providerName }}
</span>
<!-- The name reads better beside the mark than over the artwork, and
the mark says the provider without spending a line on it. -->
<h3
v-else
class="truncate text-sm font-medium text-content-bright"
data-testid="model-card-name"
>
{{ model.name }}
</h3>
</div>
<div class="flex flex-col gap-3 px-3">
<!-- The mark over the artwork already says who answers for this, so the
line under it is the card's own name and nothing else. -->
<h3
class="truncate text-xs font-medium text-content-bright lg:text-sm"
:title="model.name"
data-testid="model-card-name"
>
{{ model.name }}
</h3>
<div class="flex h-6 min-w-0 items-center gap-1.5 overflow-hidden">
<span :class="pillClass" data-testid="model-card-task">
{{ taskLabel }}
Expand Down
4 changes: 2 additions & 2 deletions apps/website/src/components/workshop/WorkshopSections.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('WorkshopSections', () => {
render(WorkshopSections, { props: { models, labelKey } })

const row = within(screen.getByTestId('section-generate-videos'))
await user.click(row.getByRole('link', { name: /^a\b/i }))
await user.click(row.getByRole('link', { name: /\ba\b/i }))
expect(lastShelf('/models/a/')).toBe('generate-videos')
})

Expand All @@ -71,7 +71,7 @@ describe('WorkshopSections', () => {

// userEvent.click cannot express a non-primary button or click modifier.
// eslint-disable-next-line testing-library/prefer-user-event
await fireEvent.click(row.getByRole('link', { name: /^a\b/i }), event)
await fireEvent.click(row.getByRole('link', { name: /\ba\b/i }), event)

expect(lastShelf('/models/a/')).toBeUndefined()
}
Expand Down
Loading