-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into logic-1
- Loading branch information
Showing
34 changed files
with
1,246 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/design/src/Form/components/EmailInput/EmailInput.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from 'react'; | ||
import { FormProvider, useForm } from 'react-hook-form'; | ||
import { type Meta, type StoryObj } from '@storybook/react'; | ||
|
||
import { EmailInputPattern } from './EmailInput.js'; | ||
|
||
const meta: Meta<typeof EmailInputPattern> = { | ||
title: 'patterns/EmailInputPattern', | ||
component: EmailInputPattern, | ||
decorators: [ | ||
(Story, args) => { | ||
const FormDecorator = () => { | ||
const formMethods = useForm({ | ||
defaultValues: { | ||
email: '', | ||
}, | ||
}); | ||
return ( | ||
<FormProvider {...formMethods}> | ||
<Story {...args} /> | ||
</FormProvider> | ||
); | ||
}; | ||
return <FormDecorator />; | ||
}, | ||
], | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Default: StoryObj<typeof EmailInputPattern> = { | ||
args: { | ||
emailId: 'email', | ||
label: 'Email address', | ||
required: true, | ||
}, | ||
}; | ||
|
||
export const WithoutRequired: StoryObj<typeof EmailInputPattern> = { | ||
args: { | ||
emailId: 'email', | ||
label: 'Email address', | ||
required: false, | ||
}, | ||
}; | ||
|
||
export const WithError: StoryObj<typeof EmailInputPattern> = { | ||
args: { | ||
emailId: 'email', | ||
label: 'Email address with error', | ||
required: true, | ||
error: { | ||
type: 'custom', | ||
message: 'This field has an error', | ||
}, | ||
}, | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/design/src/Form/components/EmailInput/EmailInput.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* @vitest-environment jsdom | ||
*/ | ||
import { describeStories } from '../../../test-helper.js'; | ||
import meta, * as stories from './EmailInput.stories.js'; | ||
|
||
describeStories(meta, stories); |
37 changes: 37 additions & 0 deletions
37
packages/design/src/Form/components/EmailInput/EmailInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { useFormContext } from 'react-hook-form'; | ||
import { type EmailInputProps } from '@atj/forms'; | ||
import { type PatternComponent } from '../../index.js'; | ||
|
||
export const EmailInputPattern: PatternComponent<EmailInputProps> = ({ | ||
emailId, | ||
label, | ||
required, | ||
error, | ||
}) => { | ||
const { register } = useFormContext(); | ||
|
||
return ( | ||
<fieldset className="usa-fieldset"> | ||
<div className="usa-form-group"> | ||
<label className="usa-label" htmlFor={emailId}> | ||
{label} | ||
{required && <span className="required-indicator">*</span>} | ||
</label> | ||
<input | ||
className="usa-input margin-bottom-1" | ||
id={emailId} | ||
type="email" | ||
autoCapitalize="off" | ||
autoCorrect="off" | ||
{...register(emailId, { required })} | ||
/> | ||
</div> | ||
{error && ( | ||
<span className="error-message" style={{ color: 'red' }}> | ||
{error.message} | ||
</span> | ||
)} | ||
</fieldset> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { EmailInputPattern } from './EmailInput.js'; | ||
|
||
export default EmailInputPattern; |
76 changes: 76 additions & 0 deletions
76
packages/design/src/Form/components/PhoneNumber/PhoneNumber.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React from 'react'; | ||
import { FormProvider, useForm } from 'react-hook-form'; | ||
import { type Meta, type StoryObj } from '@storybook/react'; | ||
|
||
import { PhoneNumberPattern } from './PhoneNumber.js'; | ||
|
||
const meta: Meta<typeof PhoneNumberPattern> = { | ||
title: 'patterns/PhoneNumberPattern', | ||
component: PhoneNumberPattern, | ||
decorators: [ | ||
(Story, args) => { | ||
const FormDecorator = () => { | ||
const formMethods = useForm(); | ||
return ( | ||
<FormProvider {...formMethods}> | ||
<Story {...args} /> | ||
</FormProvider> | ||
); | ||
}; | ||
return <FormDecorator />; | ||
}, | ||
], | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Default: StoryObj<typeof PhoneNumberPattern> = { | ||
args: { | ||
phoneId: 'phone', | ||
label: 'Phone number', | ||
required: false, | ||
}, | ||
}; | ||
|
||
export const WithRequired: StoryObj<typeof PhoneNumberPattern> = { | ||
args: { | ||
phoneId: 'phone', | ||
label: 'Phone number', | ||
required: true, | ||
}, | ||
}; | ||
|
||
export const WithError: StoryObj<typeof PhoneNumberPattern> = { | ||
args: { | ||
phoneId: 'phone', | ||
label: 'Phone number with error', | ||
required: true, | ||
error: { | ||
type: 'custom', | ||
message: 'This field has an error', | ||
}, | ||
}, | ||
}; | ||
|
||
export const WithHint: StoryObj<typeof PhoneNumberPattern> = { | ||
args: { | ||
phoneId: 'phone', | ||
label: 'Phone number', | ||
hint: '10-digit, U.S. only, for example 999-999-9999', | ||
required: true, | ||
}, | ||
}; | ||
|
||
export const WithHintAndError: StoryObj<typeof PhoneNumberPattern> = { | ||
args: { | ||
phoneId: 'phone', | ||
label: 'Phone number', | ||
hint: '10-digit, U.S. only, for example 999-999-9999', | ||
required: true, | ||
error: { | ||
type: 'custom', | ||
message: 'This field has an error', | ||
}, | ||
}, | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/design/src/Form/components/PhoneNumber/PhoneNumber.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* @vitest-environment jsdom | ||
*/ | ||
import { describeStories } from '../../../test-helper.js'; | ||
import meta, * as stories from './PhoneNumber.stories.js'; | ||
|
||
describeStories(meta, stories); |
57 changes: 57 additions & 0 deletions
57
packages/design/src/Form/components/PhoneNumber/PhoneNumber.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import { useFormContext } from 'react-hook-form'; | ||
import { type PhoneNumberProps } from '@atj/forms'; | ||
import { type PatternComponent } from '../../index.js'; | ||
|
||
export const PhoneNumberPattern: PatternComponent<PhoneNumberProps> = ({ | ||
phoneId, | ||
hint, | ||
label, | ||
required, | ||
error, | ||
value, | ||
}) => { | ||
const { register } = useFormContext(); | ||
|
||
return ( | ||
<fieldset className="usa-fieldset"> | ||
<div className={classNames('usa-form-group margin-top-2')}> | ||
<label | ||
className={classNames('usa-label', { | ||
'usa-label--error': error, | ||
})} | ||
id={`input-message-${phoneId}`} | ||
htmlFor={phoneId} | ||
> | ||
{label} | ||
{required && <span className="required-indicator">*</span>} | ||
</label> | ||
{hint && ( | ||
<div className="usa-hint" id="primaryPnHint"> | ||
{hint} | ||
</div> | ||
)} | ||
{error && ( | ||
<div | ||
className="usa-error-message" | ||
id={`input-error-message-${phoneId}`} | ||
role="alert" | ||
> | ||
{error.message} | ||
</div> | ||
)} | ||
<input | ||
className={classNames('usa-input', { | ||
'usa-input--error': error, | ||
})} | ||
id={phoneId} | ||
type="tel" | ||
defaultValue={value} | ||
{...register(phoneId, { required })} | ||
aria-describedby="primaryPnHint" | ||
/> | ||
</div> | ||
</fieldset> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { PhoneNumberPattern } from './PhoneNumber.js'; | ||
|
||
export default PhoneNumberPattern; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.