diff --git a/packages/components/src/Field-Next/Label.stories.tsx b/packages/components/src/Field-Next/Label.stories.tsx new file mode 100644 index 0000000000..379892c860 --- /dev/null +++ b/packages/components/src/Field-Next/Label.stories.tsx @@ -0,0 +1,27 @@ +import React from 'react'; +import type { Meta, ComponentStory } from '@storybook/react'; +import { Label } from './Label'; + +export default { + title: 'Field/Label', + argTypes: { + children: { + control: { + type: 'text', + }, + description: 'Text of the label', + defaultValue: 'Label', + }, + required: { + control: { + type: 'boolean', + }, + description: 'Hint that the related control required', + defaultValue: false, + }, + }, +} as Meta; + +export const Basic: ComponentStory = ({ children, ...args }) => ( + +); diff --git a/packages/components/src/Field-Next/Label.test.tsx b/packages/components/src/Field-Next/Label.test.tsx new file mode 100644 index 0000000000..82b5fb0123 --- /dev/null +++ b/packages/components/src/Field-Next/Label.test.tsx @@ -0,0 +1,74 @@ +import React from 'react'; +import { render, screen, within } from '@testing-library/react'; +import { ThemeProvider } from '@marigold/system'; +import { Label } from './Label'; + +const theme = { + fonts: { + body: 'Inter Regular', + label: 'Oswald', + }, + colors: { + text: 'black', + }, + label: { + fontFamily: 'body', + color: 'text', + }, +}; + +test('supports default variant and styles', () => { + render( + + + + ); + const label = screen.getByText(/label/); + + expect(label).toHaveStyle(`font-family: Inter Regular`); + expect(label).toHaveStyle(`color: black`); +}); + +test('supports htmlFor prop', () => { + render( + + + + ); + const label = screen.getByText(/label/); + + expect(label).toHaveAttribute('for'); +}); + +test('supports required prop', () => { + render( + + + + ); + const label = screen.getByTestId(/label/); + const requiredIcon = within(label).getByRole('img'); + expect(requiredIcon).toBeInTheDocument(); +}); + +test('renders