diff --git a/lib/components/TagsInput/TagsInput.stories.tsx b/lib/components/TagsInput/TagsInput.stories.tsx new file mode 100644 index 0000000..b2d80e9 --- /dev/null +++ b/lib/components/TagsInput/TagsInput.stories.tsx @@ -0,0 +1,30 @@ +import type { Meta, StoryObj } from '@storybook/react'; + +import { TagsInput } from './TagsInput'; + +const meta = { + title: 'TagsInput', + component: TagsInput, + tags: ['autodocs'], +} satisfies Meta; + +export default meta; + +type Story = StoryObj; + +const parameters = { + design: { + type: 'figma', + url: 'https://www.figma.com/file/6M2LrpSCcB0thlFDaQAI2J/cx_jod_client?type=design&node-id=542-7646', + }, +}; + +export const Default: Story = { + parameters: { + ...parameters, + }, + args: { + label: 'Label for screenreader at least', + placeholder: 'Lorem ipsum dolor sit amet', + }, +}; diff --git a/lib/components/TagsInput/TagsInput.test.tsx b/lib/components/TagsInput/TagsInput.test.tsx new file mode 100644 index 0000000..0a3e71a --- /dev/null +++ b/lib/components/TagsInput/TagsInput.test.tsx @@ -0,0 +1,26 @@ +import { describe, expect, it } from 'vitest'; +import { screen, render } from '@testing-library/react'; +import { TagsInput } from './TagsInput'; + +describe('Snapshot testing', () => { + it('matches the snapshot', () => { + const { container } = render(); + expect(container).toMatchSnapshot(); + }); +}); + +describe('TagsInput', () => { + it('renders the label', () => { + const label = 'Test Label'; + render(); + const labelElement = screen.getByText(label); + expect(labelElement).toBeInTheDocument(); + }); + + it('renders the placeholder', () => { + const placeholder = 'Test Placeholder'; + render(); + const inputElement = screen.getByPlaceholderText(`(${placeholder})`); + expect(inputElement).toBeInTheDocument(); + }); +}); diff --git a/lib/components/TagsInput/TagsInput.tsx b/lib/components/TagsInput/TagsInput.tsx new file mode 100644 index 0000000..59d3c27 --- /dev/null +++ b/lib/components/TagsInput/TagsInput.tsx @@ -0,0 +1,43 @@ +import { TagsInput as ArkTagsInput } from '@ark-ui/react'; + +export interface TagsInputProps { + label: string; + placeholder?: string; +} + +export const TagsInput = ({ label, placeholder }: TagsInputProps) => { + return ( + + + {(tagsInput) => ( + <> + + + + {tagsInput.value.map((value, index) => ( + + + + {value} + + + + {'close'} + + + + + + ))} + + + )} + + + ); +}; diff --git a/lib/components/TagsInput/__snapshots__/TagsInput.test.tsx.snap b/lib/components/TagsInput/__snapshots__/TagsInput.test.tsx.snap new file mode 100644 index 0000000..cfdb9b4 --- /dev/null +++ b/lib/components/TagsInput/__snapshots__/TagsInput.test.tsx.snap @@ -0,0 +1,44 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`Snapshot testing > matches the snapshot 1`] = ` +
+
+ + +
+
+
+`;