@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.
Files changed (45) hide show
  1. package/cjs/CheckBox.d.ts +1 -1
  2. package/cjs/CheckBox.js +8 -3
  3. package/cjs/Error-summary.d.ts +6 -0
  4. package/cjs/Error-summary.js +30 -0
  5. package/cjs/PasswordInput.d.ts +6 -0
  6. package/cjs/PasswordInput.js +59 -0
  7. package/cjs/RadioButton.d.ts +7 -0
  8. package/cjs/RadioButton.js +54 -0
  9. package/cjs/TextInput.d.ts +1 -1
  10. package/cjs/TextInput.js +8 -5
  11. package/cjs/fieldComponents/Feedback.d.ts +6 -0
  12. package/cjs/fieldComponents/Feedback.js +7 -0
  13. package/cjs/fieldComponents/Form.d.ts +7 -0
  14. package/cjs/fieldComponents/Form.js +7 -0
  15. package/cjs/fieldComponents/FormField.d.ts +8 -0
  16. package/cjs/fieldComponents/FormField.js +72 -0
  17. package/cjs/{index-BZth9mTZ.d.ts → index-D6jDTWIC.d.ts} +19 -2
  18. package/cjs/index.d.ts +9 -14
  19. package/cjs/index.js +4 -0
  20. package/css/core.css +23 -0
  21. package/css/internal.css +23 -0
  22. package/css/main.css +231 -55
  23. package/css/professional.css +23 -0
  24. package/css/sustainable-views.css +23 -0
  25. package/css/whitelabel.css +15 -5
  26. package/esm/CheckBox.d.ts +1 -1
  27. package/esm/CheckBox.js +8 -3
  28. package/esm/Error-summary.d.ts +6 -0
  29. package/esm/Error-summary.js +30 -0
  30. package/esm/PasswordInput.d.ts +6 -0
  31. package/esm/PasswordInput.js +59 -0
  32. package/esm/RadioButton.d.ts +7 -0
  33. package/esm/RadioButton.js +54 -0
  34. package/esm/TextInput.d.ts +1 -1
  35. package/esm/TextInput.js +8 -5
  36. package/esm/fieldComponents/Feedback.d.mts +6 -0
  37. package/esm/fieldComponents/Feedback.js +7 -0
  38. package/esm/fieldComponents/Form.d.mts +7 -0
  39. package/esm/fieldComponents/Form.js +7 -0
  40. package/esm/fieldComponents/FormField.d.mts +8 -0
  41. package/esm/fieldComponents/FormField.js +72 -0
  42. package/esm/{index-BZth9mTZ.d.ts → index-D6jDTWIC.d.ts} +19 -2
  43. package/esm/index.d.ts +9 -14
  44. package/esm/index.js +4 -0
  45. 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
+ };
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { T as TextInputProps } from './index-BZth9mTZ.js';
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 "../../main.css";
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: inputId,
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,6 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { a as FeedbackProps } from '../index-D6jDTWIC.mjs';
3
+
4
+ declare const Feedback: ({ message, type }: FeedbackProps) => react_jsx_runtime.JSX.Element;
5
+
6
+ export { Feedback };
@@ -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,7 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ declare const Form: ({ children }: {
4
+ children: JSX.Element | JSX.Element[];
5
+ }) => react_jsx_runtime.JSX.Element;
6
+
7
+ export { Form };
@@ -0,0 +1,7 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ const Form = ({ children }) => {
3
+ return /* @__PURE__ */ jsx("form", { className: "o3-form", children });
4
+ };
5
+ export {
6
+ Form
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 FormFieldProps {
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, FeedbackProps as F, TextInputProps as T, FormFieldProps as a, FormFieldsetProps as b };
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
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { F as FeedbackProps, a as FormFieldProps, b as FormFieldsetProps } from './index-BZth9mTZ.js';
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
- declare const Feedback: ({ message, type }: FeedbackProps) => react_jsx_runtime.JSX.Element;
6
-
7
- declare const LabeledFormField: ({ inputId, label, description, feedback, children, }: FormFieldProps) => react_jsx_runtime.JSX.Element;
8
- declare const TitledFormField: ({ label, description, feedback, children, }: FormFieldProps) => react_jsx_runtime.JSX.Element;
9
- declare const FormFieldset: ({ label, description, feedback, children, }: FormFieldsetProps) => react_jsx_runtime.JSX.Element;
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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/o3-form",
3
- "version": "0.3.3",
3
+ "version": "0.5.0",
4
4
  "description": "Provides a viewport-aware tooltip for annotating or or highlighting other aspects of a product's UI",
5
5
  "keywords": [
6
6
  "form",