Skip to content

Commit a7acb0e

Browse files
committed
Improve typing
1 parent 699a619 commit a7acb0e

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

src/util/LabelBlock.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react';
2+
import Hint, { HintProps } from '../components/hint/Hint';
3+
import Label, { LabelProps } from '../components/label/Label';
4+
import ErrorMessage, { ErrorMessageProps } from '../components/error-message/ErrorMessage';
5+
6+
interface LabelBlockProps {
7+
elementId?: string;
8+
label?: string;
9+
labelProps?: LabelProps;
10+
hint?: string;
11+
hintProps?: HintProps;
12+
error?: string | boolean;
13+
errorProps?: ErrorMessageProps;
14+
}
15+
16+
const LabelBlock: React.FC<LabelBlockProps> = ({
17+
elementId,
18+
label,
19+
labelProps,
20+
hint,
21+
hintProps,
22+
error,
23+
errorProps,
24+
}) => (
25+
<>
26+
{label ? (
27+
<Label id={elementId ? `${elementId}--label` : undefined} htmlFor={elementId} {...labelProps}>
28+
{label}
29+
</Label>
30+
) : null}
31+
{hint ? (
32+
<Hint id={elementId ? `${elementId}--hint` : undefined} {...hintProps}>
33+
{hint}
34+
</Hint>
35+
) : null}
36+
{error && typeof error === 'string' ? (
37+
<ErrorMessage id={elementId ? `${elementId}--error-message` : undefined} {...errorProps}>
38+
{error}
39+
</ErrorMessage>
40+
) : null}
41+
</>
42+
);
43+
44+
export default LabelBlock;

src/util/types/FormTypes.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ErrorMessageProps } from '../../components/error-message/ErrorMessage';
2+
import { HintProps } from '../../components/hint/Hint';
3+
import { LabelProps } from '../../components/label/Label';
4+
5+
export interface FormElementProps {
6+
label?: string;
7+
labelProps?: LabelProps;
8+
error?: string;
9+
errorProps?: ErrorMessageProps;
10+
hint?: string;
11+
hintProps?: HintProps
12+
}

src/util/types/NHSUKTypes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export type NHSUKSize = 's' | 'm' | 'l' | 'xl';
2+
3+
export type InputWidth = '2' | '3' | '4' | '5' | '10';
4+
5+
export type CareCardType = 'non-urgent' | 'urgent' | 'immediate';
6+
7+
export type ColWidth = 'full' | 'three-quarters' | 'one-half' | 'two-thirds' | 'one-third' | 'one-quarter';

0 commit comments

Comments
 (0)