@financial-times/o3-form 0.3.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/CheckBox.d.ts +1 -1
- package/cjs/CheckBox.js +8 -3
- package/cjs/Error-summary.d.ts +6 -0
- package/cjs/Error-summary.js +30 -0
- package/cjs/PasswordInput.d.ts +6 -0
- package/cjs/PasswordInput.js +59 -0
- package/cjs/RadioButton.d.ts +7 -0
- package/cjs/RadioButton.js +54 -0
- package/cjs/TextInput.d.ts +1 -1
- package/cjs/TextInput.js +8 -5
- package/cjs/fieldComponents/Feedback.d.ts +6 -0
- package/cjs/fieldComponents/Feedback.js +7 -0
- package/cjs/fieldComponents/Form.d.ts +7 -0
- package/cjs/fieldComponents/Form.js +7 -0
- package/cjs/fieldComponents/FormField.d.ts +8 -0
- package/cjs/fieldComponents/FormField.js +72 -0
- package/cjs/{index-BZth9mTZ.d.ts → index-D6jDTWIC.d.ts} +19 -2
- package/cjs/index.d.ts +9 -14
- package/cjs/index.js +4 -0
- package/css/core.css +23 -0
- package/css/internal.css +23 -0
- package/css/main.css +231 -55
- package/css/professional.css +23 -0
- package/css/sustainable-views.css +23 -0
- package/css/whitelabel.css +15 -5
- package/esm/CheckBox.d.ts +1 -1
- package/esm/CheckBox.js +8 -3
- package/esm/Error-summary.d.ts +6 -0
- package/esm/Error-summary.js +30 -0
- package/esm/PasswordInput.d.ts +6 -0
- package/esm/PasswordInput.js +59 -0
- package/esm/RadioButton.d.ts +7 -0
- package/esm/RadioButton.js +54 -0
- package/esm/TextInput.d.ts +1 -1
- package/esm/TextInput.js +8 -5
- package/esm/fieldComponents/Feedback.d.mts +6 -0
- package/esm/fieldComponents/Feedback.js +7 -0
- package/esm/fieldComponents/Form.d.mts +7 -0
- package/esm/fieldComponents/Form.js +7 -0
- package/esm/fieldComponents/FormField.d.mts +8 -0
- package/esm/fieldComponents/FormField.js +72 -0
- package/esm/{index-BZth9mTZ.d.ts → index-D6jDTWIC.d.ts} +19 -2
- package/esm/index.d.ts +9 -14
- package/esm/index.js +4 -0
- package/package.json +1 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
import { uidBuilder } from "@financial-times/o-utils";
|
|
4
|
+
import { FormFieldset } from "./fieldComponents/FormField";
|
|
5
|
+
const uniqueId = uidBuilder("o3-form-radio-button-input");
|
|
6
|
+
const RadioButtonItem = (props) => {
|
|
7
|
+
let { inputId, attributes, optional, error } = props;
|
|
8
|
+
if (!inputId) {
|
|
9
|
+
inputId = uniqueId("_");
|
|
10
|
+
}
|
|
11
|
+
const classNames = ["o3-form-input-radio-button", "o3-visually-hidden"];
|
|
12
|
+
if (error) {
|
|
13
|
+
classNames.push("o3-form-input-error");
|
|
14
|
+
}
|
|
15
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
16
|
+
/* @__PURE__ */ jsx(
|
|
17
|
+
"input",
|
|
18
|
+
{
|
|
19
|
+
...attributes,
|
|
20
|
+
type: "radio",
|
|
21
|
+
id: inputId,
|
|
22
|
+
className: classNames.join(" "),
|
|
23
|
+
required: !optional,
|
|
24
|
+
"aria-required": !optional
|
|
25
|
+
}
|
|
26
|
+
),
|
|
27
|
+
/* @__PURE__ */ jsx("label", { htmlFor: inputId, className: "o3-form-input-radio-button__label", children: props.radioButtonLabel })
|
|
28
|
+
] });
|
|
29
|
+
};
|
|
30
|
+
const RadioButtonGroup = (props) => {
|
|
31
|
+
const { children, ...restProps } = props;
|
|
32
|
+
const radioGroupName = Math.random().toString(36).substring(7);
|
|
33
|
+
return /* @__PURE__ */ jsx(FormFieldset, { ...restProps, children: children.map((child) => {
|
|
34
|
+
const hasError = props.feedback?.errorElementIds?.includes(
|
|
35
|
+
child.props.inputId
|
|
36
|
+
);
|
|
37
|
+
return /* @__PURE__ */ createElement(
|
|
38
|
+
RadioButtonItem,
|
|
39
|
+
{
|
|
40
|
+
...child.props,
|
|
41
|
+
error: hasError,
|
|
42
|
+
key: child.props.inputId,
|
|
43
|
+
attributes: {
|
|
44
|
+
...child.props.attributes,
|
|
45
|
+
name: radioGroupName
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}) });
|
|
50
|
+
};
|
|
51
|
+
export {
|
|
52
|
+
RadioButtonGroup,
|
|
53
|
+
RadioButtonItem
|
|
54
|
+
};
|
package/esm/TextInput.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { T as TextInputProps } from './index-
|
|
2
|
+
import { T as TextInputProps } from './index-D6jDTWIC.js';
|
|
3
3
|
|
|
4
4
|
declare const TextInput: ({ label, feedback, description, disabled, length, attributes, inputId, optional, }: TextInputProps) => react_jsx_runtime.JSX.Element;
|
|
5
5
|
|
package/esm/TextInput.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import "
|
|
2
|
+
import { uidBuilder } from "@financial-times/o-utils";
|
|
3
3
|
import { LabeledFormField } from "./fieldComponents/FormField";
|
|
4
|
+
const uniqueId = uidBuilder("o3-form-text-input");
|
|
4
5
|
const TextInput = ({
|
|
5
6
|
label,
|
|
6
7
|
feedback,
|
|
@@ -11,6 +12,7 @@ const TextInput = ({
|
|
|
11
12
|
inputId,
|
|
12
13
|
optional
|
|
13
14
|
}) => {
|
|
15
|
+
const id = inputId || uniqueId("_");
|
|
14
16
|
const inputClasses = ["o3-form", "o3-form-text-input"];
|
|
15
17
|
if (feedback && feedback.type === "error") {
|
|
16
18
|
inputClasses.push("o3-form-text-input--error");
|
|
@@ -24,16 +26,17 @@ const TextInput = ({
|
|
|
24
26
|
label,
|
|
25
27
|
feedback,
|
|
26
28
|
description,
|
|
27
|
-
inputId,
|
|
29
|
+
inputId: id,
|
|
30
|
+
optional,
|
|
28
31
|
children: /* @__PURE__ */ jsx(
|
|
29
32
|
"input",
|
|
30
33
|
{
|
|
31
34
|
...attributes,
|
|
32
|
-
id
|
|
35
|
+
id,
|
|
33
36
|
disabled,
|
|
34
37
|
className: inputClasses.join(" "),
|
|
35
|
-
required: optional,
|
|
36
|
-
"aria-required": optional,
|
|
38
|
+
required: !optional,
|
|
39
|
+
"aria-required": !optional,
|
|
37
40
|
maxLength: length,
|
|
38
41
|
type: "text"
|
|
39
42
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
const Feedback = ({ message, type }) => {
|
|
3
|
+
return /* @__PURE__ */ jsx("div", { className: `o3-form-feedback o3-form-feedback__${type}`, children: /* @__PURE__ */ jsx("span", { className: `o3-form-feedback__${type}-message`, children: message }) });
|
|
4
|
+
};
|
|
5
|
+
export {
|
|
6
|
+
Feedback
|
|
7
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { b as FormFieldProps, F as FormFieldsetProps } from '../index-D6jDTWIC.mjs';
|
|
3
|
+
|
|
4
|
+
declare const LabeledFormField: ({ inputId, label, description, feedback, children, optional, }: FormFieldProps) => react_jsx_runtime.JSX.Element;
|
|
5
|
+
declare const TitledFormField: ({ label, description, feedback, children, optional, }: FormFieldProps) => react_jsx_runtime.JSX.Element;
|
|
6
|
+
declare const FormFieldset: ({ label, description, feedback, children, optional, }: FormFieldsetProps) => react_jsx_runtime.JSX.Element;
|
|
7
|
+
|
|
8
|
+
export { FormFieldset, LabeledFormField, TitledFormField };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { uidBuilder } from "@financial-times/o-utils";
|
|
3
|
+
import { Feedback } from "./Feedback";
|
|
4
|
+
const uniqueId = uidBuilder("o3-form");
|
|
5
|
+
const LabeledFormField = ({
|
|
6
|
+
inputId,
|
|
7
|
+
label,
|
|
8
|
+
description,
|
|
9
|
+
feedback,
|
|
10
|
+
children,
|
|
11
|
+
optional
|
|
12
|
+
}) => {
|
|
13
|
+
const id = inputId || uniqueId("input_");
|
|
14
|
+
const descriptionId = description ? uniqueId("description_") : void 0;
|
|
15
|
+
const labelClasses = ["o3-form-field__label"];
|
|
16
|
+
if (optional) {
|
|
17
|
+
labelClasses.push("o3-form-field--optional");
|
|
18
|
+
}
|
|
19
|
+
return /* @__PURE__ */ jsxs("div", { className: "o3-form-field", children: [
|
|
20
|
+
/* @__PURE__ */ jsx("label", { className: labelClasses.join(" "), htmlFor: id, children: label }),
|
|
21
|
+
description && /* @__PURE__ */ jsx("span", { className: "o3-form-input__description", id: descriptionId, children: description }),
|
|
22
|
+
children,
|
|
23
|
+
feedback && /* @__PURE__ */ jsx(Feedback, { ...feedback })
|
|
24
|
+
] });
|
|
25
|
+
};
|
|
26
|
+
const TitledFormField = ({
|
|
27
|
+
label,
|
|
28
|
+
description,
|
|
29
|
+
feedback,
|
|
30
|
+
children,
|
|
31
|
+
optional
|
|
32
|
+
}) => {
|
|
33
|
+
const descriptionId = description ? uniqueId("description_") : void 0;
|
|
34
|
+
const labelId = uniqueId("label_");
|
|
35
|
+
const labelClasses = ["o3-form-field__title"];
|
|
36
|
+
if (optional) {
|
|
37
|
+
labelClasses.push("o3-form-field--optional");
|
|
38
|
+
}
|
|
39
|
+
return /* @__PURE__ */ jsxs("div", { className: "o3-form-field", children: [
|
|
40
|
+
/* @__PURE__ */ jsx("span", { className: labelClasses.join(" "), id: labelId, children: label }),
|
|
41
|
+
description && /* @__PURE__ */ jsx("span", { className: "o3-form-input__description", id: descriptionId, children: description }),
|
|
42
|
+
children,
|
|
43
|
+
feedback && /* @__PURE__ */ jsx(Feedback, { ...feedback })
|
|
44
|
+
] });
|
|
45
|
+
};
|
|
46
|
+
const FormFieldset = ({
|
|
47
|
+
label,
|
|
48
|
+
description,
|
|
49
|
+
feedback,
|
|
50
|
+
children,
|
|
51
|
+
optional
|
|
52
|
+
}) => {
|
|
53
|
+
const descriptionId = uniqueId("checkbox_");
|
|
54
|
+
const labelClasses = ["o3-form-field__legend"];
|
|
55
|
+
if (optional) {
|
|
56
|
+
labelClasses.push("o3-form-field--optional");
|
|
57
|
+
}
|
|
58
|
+
return /* @__PURE__ */ jsxs("fieldset", { className: "o3-form-field", "aria-describedby": `${descriptionId}`, children: [
|
|
59
|
+
/* @__PURE__ */ jsxs("legend", { className: labelClasses.join(" "), children: [
|
|
60
|
+
label,
|
|
61
|
+
" ",
|
|
62
|
+
description && /* @__PURE__ */ jsx("span", { className: "o3-form-input__description", id: descriptionId, children: description })
|
|
63
|
+
] }),
|
|
64
|
+
children,
|
|
65
|
+
feedback && /* @__PURE__ */ jsx(Feedback, { ...feedback })
|
|
66
|
+
] });
|
|
67
|
+
};
|
|
68
|
+
export {
|
|
69
|
+
FormFieldset,
|
|
70
|
+
LabeledFormField,
|
|
71
|
+
TitledFormField
|
|
72
|
+
};
|
|
@@ -6,21 +6,30 @@ type BaseInputProps = {
|
|
|
6
6
|
error?: boolean;
|
|
7
7
|
attributes?: JSX.IntrinsicElements['input'];
|
|
8
8
|
};
|
|
9
|
-
interface TextInputProps extends
|
|
9
|
+
interface TextInputProps extends BaseInputProps {
|
|
10
10
|
disabled?: boolean;
|
|
11
11
|
length?: 2 | 3 | 4 | 5;
|
|
12
12
|
feedback?: FeedbackProps;
|
|
13
13
|
}
|
|
14
|
+
interface PasswordInputProps extends BaseInputProps {
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
feedback?: FeedbackProps;
|
|
17
|
+
}
|
|
14
18
|
interface CheckBoxProps extends BaseInputProps {
|
|
15
19
|
inputId: string;
|
|
16
20
|
checkboxLabel: string;
|
|
17
21
|
feedback?: FeedbackProps;
|
|
18
22
|
}
|
|
23
|
+
interface RadioButtonProps extends BaseInputProps {
|
|
24
|
+
inputId: string;
|
|
25
|
+
radioButtonLabel: string;
|
|
26
|
+
}
|
|
19
27
|
interface FormFieldsetProps {
|
|
20
28
|
label: string;
|
|
21
29
|
description?: string;
|
|
22
30
|
children: JSX.Element | JSX.Element[];
|
|
23
31
|
feedback?: FeedbackProps;
|
|
32
|
+
optional?: boolean;
|
|
24
33
|
}
|
|
25
34
|
interface FormFieldProps extends BaseInputProps {
|
|
26
35
|
feedback?: FeedbackProps;
|
|
@@ -31,5 +40,13 @@ type FeedbackProps = {
|
|
|
31
40
|
message: string;
|
|
32
41
|
type: 'error';
|
|
33
42
|
};
|
|
43
|
+
type ErrorSummaryProps = {
|
|
44
|
+
errorMessage?: string;
|
|
45
|
+
errors: {
|
|
46
|
+
id: string;
|
|
47
|
+
fieldName: string;
|
|
48
|
+
message: string;
|
|
49
|
+
}[];
|
|
50
|
+
};
|
|
34
51
|
|
|
35
|
-
export type { CheckBoxProps as C,
|
|
52
|
+
export type { CheckBoxProps as C, ErrorSummaryProps as E, FormFieldsetProps as F, PasswordInputProps as P, RadioButtonProps as R, TextInputProps as T, FeedbackProps as a, FormFieldProps as b };
|
package/esm/index.d.ts
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { Feedback } from './fieldComponents/Feedback.js';
|
|
2
|
+
export { FormFieldset, LabeledFormField, TitledFormField } from './fieldComponents/FormField.js';
|
|
3
|
+
export { Form } from './fieldComponents/Form.js';
|
|
3
4
|
export { CheckBox, CheckBoxGroup, CheckBoxItem } from './CheckBox.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
declare const Form: ({ children }: {
|
|
12
|
-
children: JSX.Element | JSX.Element[];
|
|
13
|
-
}) => react_jsx_runtime.JSX.Element;
|
|
14
|
-
|
|
15
|
-
export { Feedback, Form, FormFieldset, LabeledFormField, TitledFormField };
|
|
5
|
+
export { RadioButtonGroup, RadioButtonItem } from './RadioButton.js';
|
|
6
|
+
export { ErrorSummary } from './Error-summary.js';
|
|
7
|
+
export { PasswordInput } from './PasswordInput.js';
|
|
8
|
+
export { TextInput } from './TextInput.js';
|
|
9
|
+
import 'react/jsx-runtime';
|
|
10
|
+
import './index-D6jDTWIC.js';
|
package/esm/index.js
CHANGED
|
@@ -2,3 +2,7 @@ export * from "./fieldComponents/Feedback";
|
|
|
2
2
|
export * from "./fieldComponents/FormField";
|
|
3
3
|
export * from "./fieldComponents/Form";
|
|
4
4
|
export * from "./CheckBox";
|
|
5
|
+
export * from "./RadioButton";
|
|
6
|
+
export * from "./Error-summary";
|
|
7
|
+
export * from "./PasswordInput";
|
|
8
|
+
export * from "./TextInput";
|