diff --git a/app/javascript/packages/components/index.ts b/app/javascript/packages/components/index.ts index 776e12c5b4a..e4de7ac68ec 100644 --- a/app/javascript/packages/components/index.ts +++ b/app/javascript/packages/components/index.ts @@ -19,10 +19,8 @@ export { default as ScrollIntoView } from './scroll-into-view'; export { default as SpinnerDots } from './spinner-dots'; export { default as StatusPage } from './status-page'; export { default as Tag } from './tag'; -export { default as TextInput } from './text-input'; export { default as TroubleshootingOptions } from './troubleshooting-options'; export type { ButtonProps } from './button'; export type { FullScreenRefHandle } from './full-screen'; export type { LinkProps } from './link'; -export type { TextInputProps } from './text-input'; diff --git a/app/javascript/packages/components/text-input.spec.tsx b/app/javascript/packages/components/text-input.spec.tsx deleted file mode 100644 index 310a3cab1d6..00000000000 --- a/app/javascript/packages/components/text-input.spec.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import { createRef } from 'react'; -import { render } from '@testing-library/react'; -import TextInput from './text-input'; - -describe('TextInput', () => { - it('renders with an associated label', () => { - const { getByLabelText } = render(); - - const input = getByLabelText('Input'); - - expect(input).to.be.an.instanceOf(HTMLInputElement); - expect(input.classList.contains('usa-input')).to.be.true(); - }); - - it('uses an explicitly-provided ID', () => { - const customId = 'custom-id'; - const { getByLabelText } = render(); - - const input = getByLabelText('Input'); - - expect(input.id).to.equal(customId); - }); - - it('applies additional given classes', () => { - const customClass = 'custom-class'; - const { getByLabelText } = render(); - - const input = getByLabelText('Input'); - - expect([...input.classList.values()]).to.have.all.members(['usa-input', customClass]); - }); - - it('applies additional input attributes', () => { - const type = 'password'; - const { getByLabelText } = render(); - - const input = getByLabelText('Input') as HTMLInputElement; - - expect(input.type).to.equal(type); - }); - - it('forwards ref', () => { - const ref = createRef(); - render(); - - expect(ref.current).to.be.an.instanceOf(HTMLInputElement); - }); -}); diff --git a/app/javascript/packages/components/text-input.tsx b/app/javascript/packages/components/text-input.tsx deleted file mode 100644 index 31f07aa42a8..00000000000 --- a/app/javascript/packages/components/text-input.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import { forwardRef } from 'react'; -import type { InputHTMLAttributes, ForwardedRef } from 'react'; -import { useInstanceId } from '@18f/identity-react-hooks'; - -export interface TextInputProps extends InputHTMLAttributes { - /** - * Text of label associated with input. - */ - label: string; - - /** - * Optional explicit ID to use in place of default behavior. - */ - id?: string; - - /** - * Additional class name to be applied to the input element. - */ - className?: string; -} - -function TextInput( - { label, id, className, ...inputProps }: TextInputProps, - ref: ForwardedRef, -) { - const instanceId = useInstanceId(); - const inputId = id ?? `text-input-${instanceId}`; - const classes = ['usa-input', className].filter(Boolean).join(' '); - - return ( - <> - - - - ); -} - -export default forwardRef(TextInput); diff --git a/app/javascript/packages/password-toggle/index.ts b/app/javascript/packages/password-toggle/index.ts deleted file mode 100644 index 78ae0b948d5..00000000000 --- a/app/javascript/packages/password-toggle/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as PasswordToggle } from './password-toggle'; diff --git a/app/javascript/packages/password-toggle/password-toggle.spec.tsx b/app/javascript/packages/password-toggle/password-toggle.spec.tsx deleted file mode 100644 index b4b1c2c3264..00000000000 --- a/app/javascript/packages/password-toggle/password-toggle.spec.tsx +++ /dev/null @@ -1,69 +0,0 @@ -import { createRef } from 'react'; -import { computeAccessibleDescription } from 'dom-accessibility-api'; -import { render } from '@testing-library/react'; -import PasswordToggle from './password-toggle'; - -describe('PasswordToggle', () => { - it('renders with default labels', () => { - const { getByLabelText } = render(); - - expect(getByLabelText('components.password_toggle.label')).to.exist(); - expect(getByLabelText('components.password_toggle.toggle_label')).to.exist(); - }); - - it('renders with custom input label', () => { - const { getByLabelText } = render(); - - expect(getByLabelText('Input').classList.contains('password-toggle__input')).to.be.true(); - }); - - it('renders with custom toggle label', () => { - const { getByLabelText } = render(); - - expect(getByLabelText('Toggle').classList.contains('password-toggle__toggle')).to.be.true(); - }); - - it('renders default toggle position', () => { - const { container } = render(); - - expect(container.querySelector('.password-toggle--toggle-top')).to.exist(); - }); - - it('renders explicit toggle position', () => { - const { container } = render(); - - expect(container.querySelector('.password-toggle--toggle-bottom')).to.exist(); - }); - - it('applies custom class to wrapper element', () => { - const { container } = render(); - - expect(container.querySelector('lg-password-toggle.my-custom-class')).to.exist(); - }); - - it('passes additional props to underlying text input', () => { - const type = 'password'; - const { getByLabelText } = render(); - - const input = getByLabelText('Input') as HTMLInputElement; - - expect(input.type).to.equal(type); - }); - - it('forwards ref to the underlying text input', () => { - const ref = createRef(); - render(); - - expect(ref.current).to.be.an.instanceOf(HTMLInputElement); - }); - - it('validates input as a ValidatedField', () => { - const { getByLabelText } = render(); - - const input = getByLabelText('Input') as HTMLInputElement; - - input.reportValidity(); - const description = computeAccessibleDescription(input); - expect(description).to.equal('simple_form.required.text'); - }); -}); diff --git a/app/javascript/packages/password-toggle/password-toggle.tsx b/app/javascript/packages/password-toggle/password-toggle.tsx deleted file mode 100644 index 46e02ae58a0..00000000000 --- a/app/javascript/packages/password-toggle/password-toggle.tsx +++ /dev/null @@ -1,91 +0,0 @@ -import { forwardRef } from 'react'; -import type { HTMLAttributes, ForwardedRef } from 'react'; -import { t } from '@18f/identity-i18n'; -import { TextInput } from '@18f/identity-components'; -import { useInstanceId } from '@18f/identity-react-hooks'; -import type { TextInputProps } from '@18f/identity-components'; -import { ValidatedField } from '@18f/identity-validated-field'; -import './password-toggle-element'; -import type PasswordToggleElement from './password-toggle-element'; - -declare global { - namespace JSX { - interface IntrinsicElements { - 'lg-password-toggle': HTMLAttributes & { class: string }; - } - } -} - -type TogglePosition = 'top' | 'bottom'; - -type PasswordToggleProps = Partial & { - /** - * Input label text. - */ - label?: string; - - /** - * Toggle label text. - */ - toggleLabel?: string; - - /** - * Placement of toggle relative to the input. - */ - togglePosition?: TogglePosition; - - /** - * Additional classes to apply to wrapper. - */ - className?: string; -}; - -function PasswordToggle( - { - label = t('components.password_toggle.label'), - toggleLabel = t('components.password_toggle.toggle_label'), - togglePosition = 'top', - className, - ...textInputProps - }: PasswordToggleProps, - ref: ForwardedRef, -) { - const instanceId = useInstanceId(); - const inputId = `password-toggle-input-${instanceId}`; - const toggleId = `password-toggle-${instanceId}`; - - const classes = [ - className, - togglePosition === 'top' && 'password-toggle--toggle-top', - togglePosition === 'bottom' && 'password-toggle--toggle-bottom', - ] - .filter(Boolean) - .join(' '); - - return ( - - - - -
- - -
-
- ); -} - -export default forwardRef(PasswordToggle);