-
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 branch 'main' into readme-update
- Loading branch information
Showing
26 changed files
with
897 additions
and
171 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import 'cdktf/lib/testing/adapters/jest'; | ||
|
||
describe('atj-platform app stack', () => { | ||
describe('Forms Platform app stack', () => { | ||
it.todo('should be tested'); | ||
}); |
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
88 changes: 88 additions & 0 deletions
88
packages/design/src/Form/components/DateOfBirth/DateOfBirth.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,88 @@ | ||
import React from 'react'; | ||
import { FormProvider, useForm } from 'react-hook-form'; | ||
import { type Meta, type StoryObj } from '@storybook/react'; | ||
|
||
import { DateOfBirthPattern } from './DateOfBirth.js'; | ||
|
||
const meta: Meta<typeof DateOfBirthPattern> = { | ||
title: 'patterns/DateOfBirthPattern', | ||
component: DateOfBirthPattern, | ||
decorators: [ | ||
(Story, args) => { | ||
const FormDecorator = () => { | ||
const formMethods = useForm({ | ||
defaultValues: { | ||
'date-of-birth-1.day': '', | ||
'date-of-birth-1.month': '', | ||
'date-of-birth-1.year': '', | ||
}, | ||
}); | ||
return ( | ||
<FormProvider {...formMethods}> | ||
<Story {...args} /> | ||
</FormProvider> | ||
); | ||
}; | ||
return <FormDecorator />; | ||
}, | ||
], | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Default: StoryObj<typeof DateOfBirthPattern> = { | ||
args: { | ||
_patternId: '', | ||
type: 'date-of-birth', | ||
monthId: 'date-of-birth-1.month', | ||
dayId: 'date-of-birth-1.day', | ||
yearId: 'date-of-birth-1.year', | ||
label: 'Select a date of birth', | ||
hint: 'For example: January 19, 2000', | ||
required: false, | ||
}, | ||
}; | ||
|
||
export const WithoutHint: StoryObj<typeof DateOfBirthPattern> = { | ||
args: { | ||
_patternId: '', | ||
type: 'date-of-birth', | ||
monthId: 'date-of-birth-1.month', | ||
dayId: 'date-of-birth-1.day', | ||
yearId: 'date-of-birth-1.year', | ||
label: 'Select a date of birth', | ||
hint: undefined, | ||
required: false, | ||
}, | ||
}; | ||
|
||
export const WithError: StoryObj<typeof DateOfBirthPattern> = { | ||
args: { | ||
_patternId: '', | ||
type: 'date-of-birth', | ||
monthId: 'date-of-birth-1.month', | ||
dayId: 'date-of-birth-1.day', | ||
yearId: 'date-of-birth-1.year', | ||
label: 'Select a date of birth with error', | ||
hint: 'For example: January 19, 2000', | ||
required: false, | ||
error: { | ||
type: 'custom', | ||
message: 'This field has an error', | ||
}, | ||
}, | ||
}; | ||
|
||
export const Required: StoryObj<typeof DateOfBirthPattern> = { | ||
args: { | ||
_patternId: '', | ||
type: 'date-of-birth', | ||
monthId: 'date-of-birth-1.month', | ||
dayId: 'date-of-birth-1.day', | ||
yearId: 'date-of-birth-1.year', | ||
label: 'Select a required date of birth', | ||
hint: 'For example: January 19, 2000', | ||
required: true, | ||
}, | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/design/src/Form/components/DateOfBirth/DateOfBirth.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 './DateOfBirth.stories.js'; | ||
|
||
describeStories(meta, stories); |
102 changes: 102 additions & 0 deletions
102
packages/design/src/Form/components/DateOfBirth/DateOfBirth.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,102 @@ | ||
import React from 'react'; | ||
import { useFormContext } from 'react-hook-form'; | ||
import { type DateOfBirthProps } from '@atj/forms'; | ||
import { type PatternComponent } from '../../index.js'; | ||
|
||
const months = [ | ||
{ value: '01', label: 'January' }, | ||
{ value: '02', label: 'February' }, | ||
{ value: '03', label: 'March' }, | ||
{ value: '04', label: 'April' }, | ||
{ value: '05', label: 'May' }, | ||
{ value: '06', label: 'June' }, | ||
{ value: '07', label: 'July' }, | ||
{ value: '08', label: 'August' }, | ||
{ value: '09', label: 'September' }, | ||
{ value: '10', label: 'October' }, | ||
{ value: '11', label: 'November' }, | ||
{ value: '12', label: 'December' }, | ||
]; | ||
|
||
export const DateOfBirthPattern: PatternComponent<DateOfBirthProps> = ({ | ||
monthId, | ||
dayId, | ||
yearId, | ||
label, | ||
hint, | ||
required, | ||
error, | ||
}) => { | ||
const { register } = useFormContext(); | ||
|
||
return ( | ||
<fieldset className="usa-fieldset"> | ||
<legend className="usa-legend"> | ||
{label} | ||
{required && <span className="required-indicator">*</span>} | ||
</legend> | ||
{hint && ( | ||
<span className="usa-hint" id="mdHint"> | ||
{hint} | ||
</span> | ||
)} | ||
<div className="usa-memorable-date"> | ||
<div className="usa-form-group usa-form-group--month usa-form-group--select"> | ||
<label className="usa-label" htmlFor={monthId}> | ||
Month | ||
</label> | ||
<select | ||
className="usa-select" | ||
id={monthId} | ||
{...register(monthId)} | ||
aria-describedby="mdHint" | ||
> | ||
<option key="default" value=""> | ||
- Select - | ||
</option> | ||
{months.map((option, index) => ( | ||
<option key={index} value={option.value}> | ||
{option.label} | ||
</option> | ||
))} | ||
</select> | ||
</div> | ||
<div className="usa-form-group usa-form-group--day"> | ||
<label className="usa-label" htmlFor={dayId}> | ||
Day | ||
</label> | ||
<input | ||
className="usa-input" | ||
aria-describedby="mdHint" | ||
id={dayId} | ||
{...register(dayId)} | ||
minLength={2} | ||
maxLength={2} | ||
pattern="[0-9]*" | ||
inputMode="numeric" | ||
/> | ||
</div> | ||
<div className="usa-form-group usa-form-group--year"> | ||
<label className="usa-label" htmlFor={yearId}> | ||
Year | ||
</label> | ||
<input | ||
className="usa-input" | ||
aria-describedby="mdHint" | ||
id={yearId} | ||
{...register(yearId)} | ||
minLength={4} | ||
maxLength={4} | ||
pattern="[0-9]*" | ||
inputMode="numeric" | ||
/> | ||
</div> | ||
</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 { DateOfBirthPattern } from './DateOfBirth.js'; | ||
|
||
export default DateOfBirthPattern; |
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
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.