diff --git a/docs/content/FilterList.mdx b/docs/content/FilterList.mdx index 547aad27195..687243fcb4c 100644 --- a/docs/content/FilterList.mdx +++ b/docs/content/FilterList.mdx @@ -4,7 +4,7 @@ title: FilterList status: Alpha --- -import data from '../../src/FilterList.docs.json' +import data from '../../src/FilterList/FilterList.docs.json' The FilterList component is a menu with filter options that filter the main content of the page. diff --git a/e2e/components/FilterList.test.ts b/e2e/components/FilterList.test.ts new file mode 100644 index 00000000000..b2aaa6493b0 --- /dev/null +++ b/e2e/components/FilterList.test.ts @@ -0,0 +1,61 @@ +import {test, expect} from '@playwright/test' +import {visit} from '../test-helpers/storybook' +import {themes} from '../test-helpers/themes' + +test.describe('FilterList', () => { + test.describe('Default', () => { + for (const theme of themes) { + test.describe(theme, () => { + test('default @vrt', async ({page}) => { + await visit(page, { + id: 'components-filterlist--default', + globals: { + colorScheme: theme, + }, + }) + + // Default state + expect(await page.screenshot()).toMatchSnapshot(`FilterList.Default.${theme}.png`) + }) + + test('axe @aat', async ({page}) => { + await visit(page, { + id: 'components-filterlist--default', + globals: { + colorScheme: theme, + }, + }) + await expect(page).toHaveNoViolations() + }) + }) + } + }) + + test.describe('Playground', () => { + for (const theme of themes) { + test.describe(theme, () => { + test('default @vrt', async ({page}) => { + await visit(page, { + id: 'components-filterlist--playground', + globals: { + colorScheme: theme, + }, + }) + + // Default state + expect(await page.screenshot()).toMatchSnapshot(`FilterList.Playground.${theme}.png`) + }) + + test('axe @aat', async ({page}) => { + await visit(page, { + id: 'components-filterlist--playground', + globals: { + colorScheme: theme, + }, + }) + await expect(page).toHaveNoViolations() + }) + }) + } + }) +}) diff --git a/script/generate-e2e-tests.js b/script/generate-e2e-tests.js index 76ff402cb72..0e6cc420cbc 100644 --- a/script/generate-e2e-tests.js +++ b/script/generate-e2e-tests.js @@ -402,6 +402,21 @@ const components = new Map([ ], }, ], + [ + 'FilterList', + { + stories: [ + { + id: 'components-filterlist--default', + name: 'Default', + }, + { + id: 'components-filterlist--playground', + name: 'Playground', + }, + ], + }, + ], [ 'Flash', { diff --git a/src/FilterList.docs.json b/src/FilterList/FilterList.docs.json similarity index 100% rename from src/FilterList.docs.json rename to src/FilterList/FilterList.docs.json diff --git a/src/FilterList/FilterList.stories.tsx b/src/FilterList/FilterList.stories.tsx new file mode 100644 index 00000000000..c98fac8907a --- /dev/null +++ b/src/FilterList/FilterList.stories.tsx @@ -0,0 +1,53 @@ +import React, {useState} from 'react' +import {Meta, ComponentStory} from '@storybook/react' +import FilterList from './FilterList' + +export default { + title: 'Components/FilterList', + component: FilterList, +} as Meta + +export const Default = () => { + const [selectedIndex, setSelectedIndex] = useState(0) + return ( + + setSelectedIndex(0)} count={32}> + First Filter + + setSelectedIndex(1)} count={16}> + Second Filter + + setSelectedIndex(2)}> + Third Filter + + + ) +} + +export const Playground: ComponentStory = args => { + const [selectedIndex, setSelectedIndex] = useState(0) + return ( + + setSelectedIndex(0)} count={32}> + First Filter + + setSelectedIndex(1)} count={16}> + Second Filter + + setSelectedIndex(2)}> + Third Filter + + + ) +} + +Playground.args = {} + +Playground.argTypes = { + sx: { + controls: false, + table: { + disabled: true, + }, + }, +} diff --git a/src/FilterList.tsx b/src/FilterList/FilterList.tsx similarity index 90% rename from src/FilterList.tsx rename to src/FilterList/FilterList.tsx index 99979f92e1d..8fee74ce2a1 100644 --- a/src/FilterList.tsx +++ b/src/FilterList/FilterList.tsx @@ -1,8 +1,8 @@ import React from 'react' import styled from 'styled-components' -import {get} from './constants' -import sx, {SxProp} from './sx' -import {ComponentProps} from './utils/types' +import {get} from '../constants' +import sx, {SxProp} from '../sx' +import {ComponentProps} from '../utils/types' const FilterListBase = styled.ul` list-style-type: none; @@ -57,7 +57,7 @@ const FilterListItemBase = styled.a` export type FilterListItemProps = {count?: number} & ComponentProps -function FilterListItem({children, count, ...rest}: React.PropsWithChildren) { +const FilterListItem = ({children, count, ...rest}: React.PropsWithChildren) => { return ( {count && ( diff --git a/src/FilterList/index.ts b/src/FilterList/index.ts new file mode 100644 index 00000000000..967ba6cf4af --- /dev/null +++ b/src/FilterList/index.ts @@ -0,0 +1 @@ +export {default, FilterListProps, FilterListItemProps} from './FilterList'