diff --git a/src/components/forms/InputPrefix/InputPrefix.stories.tsx b/src/components/forms/InputPrefix/InputPrefix.stories.tsx new file mode 100644 index 0000000000..4d23fae3e6 --- /dev/null +++ b/src/components/forms/InputPrefix/InputPrefix.stories.tsx @@ -0,0 +1,50 @@ +import React from 'react' +import { InputPrefix } from './InputPrefix' +import { IconCreditCard } from '../../Icon/Icons' +import { TextInput } from '../TextInput/TextInput' +import { FormGroup } from '../FormGroup/FormGroup' + +export default { + title: 'Components/Input prefix or suffix/InputPrefix', + component: InputPrefix, + parameters: { + docs: { + description: { + component: ` +### USWDS 2.0 InputPrefix component + +Source: https://designsystem.digital.gov/components/input-prefix-suffix/ +`, + }, + }, + }, +} + +export const InputWithTextInputPrefix = (): React.ReactElement => ( + +
+ cvc + +
+
+) + +export const InputWithTextInputPrefixError = (): React.ReactElement => ( + +
+ cvc + +
+
+) + +export const InputWithIconInputPrefix = (): React.ReactElement => ( + +
+ + + + +
+
+) diff --git a/src/components/forms/InputPrefix/InputPrefix.test.tsx b/src/components/forms/InputPrefix/InputPrefix.test.tsx new file mode 100644 index 0000000000..30d6238fd4 --- /dev/null +++ b/src/components/forms/InputPrefix/InputPrefix.test.tsx @@ -0,0 +1,21 @@ +import React from 'react' +import { render } from '@testing-library/react' + +import { InputPrefix } from './InputPrefix' + +describe('InputPrefix component', () => { + it('renders without errors', () => { + const { queryByTestId } = render( + + + + ) + + const inputPrefix = queryByTestId('InputPrefix') + expect(inputPrefix).toBeInTheDocument() + expect(inputPrefix).toHaveClass('usa-input-prefix') + expect(inputPrefix).toHaveClass('test-class') + expect(inputPrefix).toHaveAttribute('aria-hidden') + expect(queryByTestId('svg-test')).toBeInTheDocument() + }) +}) diff --git a/src/components/forms/InputPrefix/InputPrefix.tsx b/src/components/forms/InputPrefix/InputPrefix.tsx new file mode 100644 index 0000000000..7437c2c4dc --- /dev/null +++ b/src/components/forms/InputPrefix/InputPrefix.tsx @@ -0,0 +1,26 @@ +import React from 'react' +import classnames from 'classnames' + +type InputPrefixProps = { + className?: string + children: React.ReactNode +} & JSX.IntrinsicElements['div'] + +export const InputPrefix = ({ + className, + children, + ...divProps +}: InputPrefixProps): React.ReactElement => { + const classes = classnames('usa-input-prefix', className) + + return ( + + ) +} diff --git a/src/components/forms/InputSuffix/InputSuffix.stories.tsx b/src/components/forms/InputSuffix/InputSuffix.stories.tsx new file mode 100644 index 0000000000..2874f2ec1a --- /dev/null +++ b/src/components/forms/InputSuffix/InputSuffix.stories.tsx @@ -0,0 +1,57 @@ +import React from 'react' +import { InputSuffix } from './InputSuffix' +import { FormGroup } from '../FormGroup/FormGroup' +import { TextInput } from '../TextInput/TextInput' +import { IconSearch } from '../../Icon/Icons' + +export default { + title: 'Components/Input prefix or suffix/InputSuffix', + component: InputSuffix, + parameters: { + docs: { + description: { + component: ` +### USWDS 2.0 InputSuffix component + +Source: https://designsystem.digital.gov/components/input-prefix-suffix/ +`, + }, + }, + }, +} + +export const InputWithIconInputSuffix = (): React.ReactElement => ( + +
+ + + + +
+
+) + +export const InputWithIconInputSuffixError = (): React.ReactElement => ( + +
+ + + + +
+
+) + +export const InputWithTextInputSuffix = (): React.ReactElement => ( + +
+ + lbs. +
+
+) diff --git a/src/components/forms/InputSuffix/InputSuffix.test.tsx b/src/components/forms/InputSuffix/InputSuffix.test.tsx new file mode 100644 index 0000000000..0829722ff7 --- /dev/null +++ b/src/components/forms/InputSuffix/InputSuffix.test.tsx @@ -0,0 +1,19 @@ +import React from 'react' +import { render } from '@testing-library/react' +import { InputSuffix } from './InputSuffix' + +describe('InputSuffix component', () => { + it('renders without errors', () => { + const { queryByTestId, getByText } = render( + lbs. + ) + + const inputSuffix = queryByTestId('InputSuffix') + expect(inputSuffix).toBeInTheDocument() + expect(inputSuffix).toHaveClass('usa-input-suffix') + expect(inputSuffix).toHaveClass('test-class') + expect(inputSuffix).toHaveAttribute('aria-hidden') + + expect(getByText('lbs.')).toBeInTheDocument() + }) +}) diff --git a/src/components/forms/InputSuffix/InputSuffix.tsx b/src/components/forms/InputSuffix/InputSuffix.tsx new file mode 100644 index 0000000000..94ee32b85e --- /dev/null +++ b/src/components/forms/InputSuffix/InputSuffix.tsx @@ -0,0 +1,26 @@ +import React from 'react' +import classnames from 'classnames' + +type InputSuffixProps = { + className?: string + children: React.ReactNode +} & JSX.IntrinsicElements['div'] + +export const InputSuffix = ({ + className, + children, + ...divProps +}: InputSuffixProps): React.ReactElement => { + const classes = classnames('usa-input-suffix', className) + + return ( + + ) +} diff --git a/src/index.ts b/src/index.ts index 69836ca144..850d0e73e4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -42,6 +42,8 @@ export { Fieldset } from './components/forms/Fieldset/Fieldset' export { FileInput } from './components/forms/FileInput/FileInput' export { Form } from './components/forms/Form/Form' export { FormGroup } from './components/forms/FormGroup/FormGroup' +export { InputPrefix } from './components/forms/InputPrefix/InputPrefix' +export { InputSuffix } from './components/forms/InputSuffix/InputSuffix' export { Label } from './components/forms/Label/Label' export { Radio } from './components/forms/Radio/Radio' export { RangeInput } from './components/forms/RangeInput/RangeInput'