diff --git a/apps/website/e2e/models-sign-in-draft.spec.ts b/apps/website/e2e/models-sign-in-draft.spec.ts index 4d53505f4a8..7982a05b941 100644 --- a/apps/website/e2e/models-sign-in-draft.spec.ts +++ b/apps/website/e2e/models-sign-in-draft.spec.ts @@ -35,9 +35,7 @@ for (const { entry, randomUUID, failRead } of [ }) await page.goto(path) const chooser = page.waitForEvent('filechooser') - await page - .getByText('Choose images or drop them here', { exact: true }) - .click() + await page.getByText(/^Select or drop /).click() await (await chooser).setFiles('e2e/assets/placeholder-1x1.webp') const replacement = page.getByRole('button', { name: 'Replace placeholder-1x1.webp' @@ -154,9 +152,7 @@ test('unavailable draft storage does not trap sign-in and reports missing files }) await page.goto(path) const chooser = page.waitForEvent('filechooser') - await page - .getByText('Choose images or drop them here', { exact: true }) - .click() + await page.getByText(/^Select or drop /).click() await (await chooser).setFiles('e2e/assets/placeholder-1x1.webp') await page.getByRole('link', { name: 'Sign in to run', exact: true }).click() await expect(page).toHaveURL(/\/login\/\?returnTo=/) diff --git a/apps/website/e2e/workshop.spec.ts b/apps/website/e2e/workshop.spec.ts index c0a18da8236..46d4b7fe8eb 100644 --- a/apps/website/e2e/workshop.spec.ts +++ b/apps/website/e2e/workshop.spec.ts @@ -166,11 +166,13 @@ test.describe('Models catalog', () => { const sections = page.getByTestId('workshop-sections') await expect(sections).toBeVisible() const videos = page.getByTestId('section-generate-videos') - const rowHeading = await videos - .getByRole('heading', { level: 2 }) + const rowLabel = ( + await videos.getByRole('heading', { level: 2 }).innerText() + ).trim() + const seeAll = await videos + .getByTestId('section-generate-videos-see-all') .innerText() - const promisedCount = Number(rowHeading.match(/(\d+)\s*$/)?.[1]) - const rowLabel = rowHeading.replace(/\s*\d+\s*$/, '').trim() + const promisedCount = Number(seeAll.match(/(\d+)/)?.[1]) expect(promisedCount).toBeGreaterThan(0) await videos.getByTestId('section-generate-videos-open').click() const cards = page @@ -370,6 +372,45 @@ test.describe('Models catalog', () => { '/models/byteplus--seedance-2-5-text-to-video--generate-videos/' ) }) + + test('the row arrow sits level with the middle of a card', async ({ + page + }) => { + for (const width of [1440, 820, 420]) { + await page.setViewportSize({ width, height: 1000 }) + await page.goto('/models/') + const row = page.getByTestId('section-generate-images') + const card = row.getByTestId('workshop-model-card').first() + await expect(card).toBeVisible() + await card.hover() + const cardBox = await card.boundingBox() + const arrowBox = await row.getByTestId('card-row-next').boundingBox() + if (!cardBox || !arrowBox) throw new Error('the row did not lay out') + const middleOf = (box: { y: number; height: number }) => + box.y + box.height / 2 + expect(Math.abs(middleOf(arrowBox) - middleOf(cardBox))).toBeLessThan(1) + } + }) + + test('the fade reaches both ends of the scrolling row', async ({ page }) => { + await page.goto('/models/') + const row = page.getByTestId('section-generate-images') + await expect(row.getByTestId('workshop-model-card').first()).toBeVisible() + await row.hover() + const edges = await row.evaluate((section) => { + const span = (selector: string) => { + const element = section.querySelector(selector) + if (!element) return undefined + const { x, width } = element.getBoundingClientRect() + return { left: x, right: x + width } + } + return { + scroller: span('ul'), + fades: span('[data-testid="card-row-arrows"]') + } + }) + expect(edges.fades).toEqual(edges.scroller) + }) }) test.describe('Model playground', () => { @@ -427,7 +468,7 @@ test.describe('Model playground', () => { await expect(page.getByTestId('run-button')).toBeEnabled() const [chooser] = await Promise.all([ page.waitForEvent('filechooser'), - page.getByText('Choose images or drop them here', { exact: true }).click() + page.getByText(/^Select or drop /).click() ]) await chooser.setFiles('e2e/assets/placeholder-1x1.webp') await expect( @@ -473,7 +514,7 @@ test.describe('Model playground', () => { await page.goto('/models/byteplus--seedream-4-5--edit-images/') const [chooser] = await Promise.all([ page.waitForEvent('filechooser'), - page.getByText('Choose images or drop them here', { exact: true }).click() + page.getByText(/^Select or drop /).click() ]) await chooser.setFiles('e2e/assets/placeholder-1x1.webp') await page.getByRole('tab', { name: 'API', exact: true }).click() diff --git a/apps/website/src/components/workshop/CardRow.test.ts b/apps/website/src/components/workshop/CardRow.test.ts index caa6de6798b..35d50685459 100644 --- a/apps/website/src/components/workshop/CardRow.test.ts +++ b/apps/website/src/components/workshop/CardRow.test.ts @@ -5,7 +5,7 @@ import { describe, expect, it } from 'vitest' import CardRow from './CardRow.vue' describe('CardRow', () => { - it('shows paging controls and disables each one at its edge', async () => { + it('offers each arrow only while that side has somewhere to go', async () => { render(CardRow, { slots: { default: '
  • One
  • Two
  • ' } }) @@ -18,24 +18,27 @@ describe('CardRow', () => { await fireEvent.scroll(row) await nextTick() - expect( - screen.getByRole('button', { name: 'Scroll back' }) - .disabled - ).toBe(true) - expect( - screen.getByRole('button', { name: 'Scroll forward' }) - .disabled - ).toBe(false) + expect(screen.queryByRole('button', { name: 'Scroll back' })).toBeNull() + expect(screen.getByRole('button', { name: 'Scroll forward' })).toBeTruthy() row.scrollLeft = 200 await fireEvent.scroll(row) - expect( - screen.getByRole('button', { name: 'Scroll back' }) - .disabled - ).toBe(false) - expect( - screen.getByRole('button', { name: 'Scroll forward' }) - .disabled - ).toBe(true) + await nextTick() + expect(screen.getByRole('button', { name: 'Scroll back' })).toBeTruthy() + expect(screen.queryByRole('button', { name: 'Scroll forward' })).toBeNull() + }) + + it('carries no arrows while every card already fits', async () => { + render(CardRow, { slots: { default: '
  • Only
  • ' } }) + const row = screen.getByRole('list') + Object.defineProperties(row, { + clientWidth: { configurable: true, value: 300 }, + scrollWidth: { configurable: true, value: 300 }, + scrollLeft: { configurable: true, writable: true, value: 0 } + }) + + await fireEvent.scroll(row) + await nextTick() + expect(screen.queryByTestId('card-row-arrows')).toBeNull() }) }) diff --git a/apps/website/src/components/workshop/CardRow.vue b/apps/website/src/components/workshop/CardRow.vue index f0ecece86d8..dd723dd738c 100644 --- a/apps/website/src/components/workshop/CardRow.vue +++ b/apps/website/src/components/workshop/CardRow.vue @@ -13,7 +13,6 @@ const { locale = 'en' } = defineProps<{ locale?: Locale }>() const row = useTemplateRef('row') const atStart = ref(true) const atEnd = ref(true) -const scrollable = ref(false) // The row carries a little padding so focus rings are not clipped, and snapping // rests inside it, so "at the start" is a few pixels wide. @@ -22,7 +21,6 @@ const EDGE = 8 function measure() { const el = row.value if (!el) return - scrollable.value = el.scrollWidth > el.clientWidth + EDGE atStart.value = el.scrollLeft <= EDGE atEnd.value = el.scrollLeft + el.clientWidth >= el.scrollWidth - EDGE } @@ -39,13 +37,24 @@ onMounted(() => void nextTick(measure)) useResizeObserver(row, measure) useMutationObserver(row, measure, { childList: true, subtree: true }) -const arrowClass = (spent: boolean) => - cn( - 'grid size-9 place-items-center rounded-xl border border-transparency-white-t20 text-primary-warm-white transition-colors outline-none focus-visible:ring-3 focus-visible:ring-primary-comfy-yellow/50', - spent - ? 'cursor-default opacity-30' - : 'cursor-pointer hover:border-primary-comfy-yellow hover:text-primary-comfy-yellow' - ) +// The arrows straddle the edge of the row, half over the cards and half over +// the page, so the row reads as running past them. They are opaque, because a +// card showing through a control reads as a rendering fault. Hovering lifts +// them without colour: the yellow belongs to See all, and two yellows on one +// row compete. +const arrowClass = + 'focus-visible:ring-primary-comfy-yellow/50 hover:border-primary-warm-gray hover:bg-site-dropdown bg-page pointer-events-auto absolute top-1/2 z-10 grid size-9 -translate-y-1/2 cursor-pointer place-items-center rounded-xl border border-transparency-white-t20 text-primary-warm-white shadow-lg shadow-black/40 transition-colors outline-none focus-visible:ring-3' + +// A pointer that can hover earns them by hovering, so a page of rows is not a +// page of chrome, and a keyboard earns them by focusing. A touch screen can do +// neither, so there they stay: the fade is the only thing saying there is more. +const revealClass = + 'pointer-events-none absolute -inset-x-1 top-0 bottom-2 transition-opacity duration-200 can-hover:opacity-0 can-hover:group-hover/row:opacity-100 can-hover:group-focus-within/row:opacity-100' + +// The fade says there is more that way, so it keeps the arrows' company: each +// side carries one only while that side has somewhere to go. +const fadeClass = + 'pointer-events-none absolute inset-y-0 z-0 w-20 from-page via-page/70 to-transparent' diff --git a/apps/website/src/components/workshop/ExamplesTab.vue b/apps/website/src/components/workshop/ExamplesTab.vue index 378cbb3c49c..bbd7b2c561b 100644 --- a/apps/website/src/components/workshop/ExamplesTab.vue +++ b/apps/website/src/components/workshop/ExamplesTab.vue @@ -56,9 +56,6 @@ function actionFor(example: PlaygroundExample, active = false) { ) }} -

    - {{ t('workshop.examples.samplesSubtitle', locale) }} -

    diff --git a/apps/website/src/components/workshop/FeaturedBanner.vue b/apps/website/src/components/workshop/FeaturedBanner.vue index 3761d775214..679a80773f9 100644 --- a/apps/website/src/components/workshop/FeaturedBanner.vue +++ b/apps/website/src/components/workshop/FeaturedBanner.vue @@ -145,7 +145,7 @@ const fill = computed(() => decoding="async" />