@financial-times/o3-form 0.2.0 → 0.3.1

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/README.md CHANGED
@@ -1 +1,108 @@
1
1
  # o3-form[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](#licence)
2
+
3
+ Provides components to construct forms.
4
+
5
+ ## Overview
6
+
7
+ o3-form provides UI form elements with consistent labelling, descriptions, and error styles and interfaces.
8
+
9
+ ## Components
10
+
11
+ ### Text Input
12
+
13
+ A standard text input for collecting text values.
14
+ label: 'Full name',
15
+ description: 'Your full name as printed on your driving license',
16
+
17
+ ```tsx
18
+ <TextInput label='Full name'
19
+ disabled={false}
20
+ description='Your full name as printed on your driving license'
21
+ />
22
+ ```
23
+
24
+ **HTML**
25
+
26
+ ```
27
+ <div data-o3-brand="whitelabel">
28
+ <div class="o3-form-field">
29
+ <label for="my-input-field">Full name</label>
30
+ <span
31
+ class="o3-form-input-description"
32
+ >
33
+ Your full name as printed on your driving license
34
+ </span>
35
+ <input id="my-input-field" class="o3-form o3-form-text-input" type="text" />
36
+ </div>
37
+ </div>
38
+ ```
39
+
40
+ #### Short text input
41
+
42
+ The size and max length of the text input can be limited with the `length` property.
43
+
44
+ ```html
45
+
46
+ <TextInput label="Security code"
47
+ description="3 digit security code as printed on the back of your credit card."
48
+ length={3} />;
49
+ ```
50
+
51
+ **HTML**
52
+
53
+ ```html
54
+ <div class="o3-form-field">
55
+ <label for="my-input-field">Security Code</label>
56
+ <span
57
+ class="o3-form-input-description"
58
+ >
59
+ 3 digit security code as printed on the back of your credit card.
60
+ </span>
61
+ <input
62
+ id="my-input-field"
63
+ class="o3-form o3-form-text-input o3-form-text-input--short-3"
64
+ maxlength="3"
65
+ type="text"
66
+ />
67
+ ```
68
+
69
+ This will provide a text box 3 characters wide and only allow 3 characters to be typed.
70
+
71
+ If you prefer to limit the length without styling, use the `maxLength` attribute instead.
72
+
73
+ ```tsx
74
+ <TextInput label="Security code"
75
+ description="3 digit security code as printed on the back of your credit card."
76
+ feedback={args.feedback}
77
+ attributes={{
78
+ maxLength: 3
79
+ }} />;
80
+ ```
81
+
82
+ **HTML**
83
+
84
+ ```html
85
+ <div class="o3-form-field">
86
+ <label for="my-input-field">Security Code</label>
87
+ <span
88
+ class="o3-form-input-description"
89
+ >
90
+ 3 digit security code as printed on the back of your credit card.
91
+ </span>
92
+ <input
93
+ id="my-input-field"
94
+ class="o3-form o3-form-text-input"
95
+ maxlength="3"
96
+ type="text"
97
+ />
98
+ ```
99
+
100
+ ## Contact
101
+
102
+ If you have any questions or comments about this component, or need help using it, please either [raise an issue](https://github.com/Financial-Times/o3-editorial-typography/issues), visit [#origami-support](https://financialtimes.slack.com/messages/origami-support/) or email [Origami Support](mailto:origami-support@ft.com).
103
+
104
+ ---
105
+
106
+ ## Licence
107
+
108
+ This software is published by the Financial Times under the [MIT licence](http://opensource.org/licenses/MIT).
package/cjs/CheckBox.d.ts CHANGED
@@ -1,2 +1,8 @@
1
- import 'react/jsx-runtime';
2
- export { c as CheckBox, d as CheckBoxGroup, C as CheckBoxItem } from './CheckBox-DRFC93iL.js';
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { C as CheckBoxProps, b as FormFieldsetProps } from './index-BP51ZwQo.js';
3
+
4
+ declare const CheckBoxItem: (props: CheckBoxProps) => react_jsx_runtime.JSX.Element;
5
+ declare const CheckBox: (props: CheckBoxProps) => react_jsx_runtime.JSX.Element;
6
+ declare const CheckBoxGroup: (props: FormFieldsetProps) => react_jsx_runtime.JSX.Element;
7
+
8
+ export { CheckBox, CheckBoxGroup, CheckBoxItem };
@@ -0,0 +1,6 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { T as TextInputProps } from './index-BP51ZwQo.js';
3
+
4
+ declare const TextInput: ({ label, feedback, description, disabled, length, attributes, inputId, optional, }: TextInputProps) => react_jsx_runtime.JSX.Element;
5
+
6
+ export { TextInput };
@@ -0,0 +1,45 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _jsxruntime = require('react/jsx-runtime');
2
+ require('../../main.css');
3
+ var _FormField = require('./fieldComponents/FormField');
4
+ const TextInput = ({
5
+ label,
6
+ feedback,
7
+ description,
8
+ disabled,
9
+ length,
10
+ attributes,
11
+ inputId,
12
+ optional
13
+ }) => {
14
+ const inputClasses = ["o3-form", "o3-form-text-input"];
15
+ if (feedback && feedback.type === "error") {
16
+ inputClasses.push("o3-form-text-input--error");
17
+ }
18
+ if (length) {
19
+ inputClasses.push(`o3-form-text-input--short-${length}`);
20
+ }
21
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
22
+ _FormField.LabeledFormField,
23
+ {
24
+ label,
25
+ feedback,
26
+ description,
27
+ children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
28
+ "input",
29
+ {
30
+ ...attributes,
31
+ id: inputId,
32
+ disabled,
33
+ className: inputClasses.join(" "),
34
+ required: optional,
35
+ "aria-required": optional,
36
+ maxLength: length,
37
+ type: "text"
38
+ }
39
+ )
40
+ }
41
+ );
42
+ };
43
+
44
+
45
+ exports.TextInput = TextInput;
@@ -1,5 +1,3 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
-
3
1
  type BaseInputProps = {
4
2
  inputId?: string;
5
3
  label?: string;
@@ -8,6 +6,11 @@ type BaseInputProps = {
8
6
  error?: boolean;
9
7
  attributes?: JSX.IntrinsicElements['input'];
10
8
  };
9
+ interface TextInputProps extends FormFieldProps {
10
+ disabled?: boolean;
11
+ length?: 2 | 3 | 4 | 5;
12
+ feedback?: FeedbackProps;
13
+ }
11
14
  interface CheckBoxProps extends BaseInputProps {
12
15
  inputId: string;
13
16
  checkboxLabel: string;
@@ -28,8 +31,4 @@ type FeedbackProps = {
28
31
  type: 'error';
29
32
  };
30
33
 
31
- declare const CheckBoxItem: (props: CheckBoxProps) => react_jsx_runtime.JSX.Element;
32
- declare const CheckBox: (props: CheckBoxProps) => react_jsx_runtime.JSX.Element;
33
- declare const CheckBoxGroup: (props: FormFieldsetProps) => react_jsx_runtime.JSX.Element;
34
-
35
- export { CheckBoxItem as C, type FeedbackProps as F, type FormFieldProps as a, type FormFieldsetProps as b, CheckBox as c, CheckBoxGroup as d };
34
+ export type { CheckBoxProps as C, FeedbackProps as F, TextInputProps as T, FormFieldProps as a, FormFieldsetProps as b };
package/cjs/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { F as FeedbackProps, a as FormFieldProps, b as FormFieldsetProps } from './CheckBox-DRFC93iL.js';
3
- export { c as CheckBox, d as CheckBoxGroup, C as CheckBoxItem } from './CheckBox-DRFC93iL.js';
2
+ import { F as FeedbackProps, a as FormFieldProps, b as FormFieldsetProps } from './index-BP51ZwQo.js';
3
+ export { CheckBox, CheckBoxGroup, CheckBoxItem } from './CheckBox.js';
4
4
 
5
5
  declare const Feedback: ({ message, type }: FeedbackProps) => react_jsx_runtime.JSX.Element;
6
6
 
package/css/main.css CHANGED
@@ -1,3 +1,5 @@
1
+ @import "@financial-times/o3-foundation/grid.css";
2
+
1
3
  /* src/css/components/form.css */
2
4
  .o3-form {
3
5
  font-family: var(--o3-font-family-metric);
@@ -56,6 +58,32 @@
56
58
  margin-left: var(--o3-spacing-5xs);
57
59
  }
58
60
 
61
+ /* src/css/components/text-input.css */
62
+ .o3-form-text-input {
63
+ border: var(--_o3-form-text-input-border);
64
+ padding: var(--o3-spacing-3xs) var(--o3-spacing-2xs);
65
+ background-color: var(--_o3-form-text-input-background-color);
66
+ border-radius: var(--_o3-form-text-input-border-radius);
67
+ --o3-grid-columns-to-span-count: 4;
68
+ max-width: var(--_o3-form-text-input-max-width, var(--o3-grid-columns-to-span-width));
69
+ }
70
+ .o3-form-text-input--short-2 {
71
+ --_o3-form-text-input-max-width: 1.5em;
72
+ }
73
+ .o3-form-text-input--short-3 {
74
+ --_o3-form-text-input-max-width: 2.5em;
75
+ }
76
+ .o3-form-text-input--short-4 {
77
+ --_o3-form-text-input-max-width: 3.5em;
78
+ }
79
+ .o3-form-text-input--short-5 {
80
+ --_o3-form-text-input-max-width: 4.5em;
81
+ }
82
+ .o3-form-text-input--error {
83
+ border: var(--_o3-form-text-input-border-error);
84
+ background-color: var(--_o3-form-text-input-background-color-error);
85
+ }
86
+
59
87
  /* src/css/components/checkbox.css */
60
88
  .o3-form-input__checkbox-input + label::before {
61
89
  content: "";
@@ -1,4 +1,13 @@
1
1
  @import "@financial-times/o3-foundation/css/whitelabel.css";
2
2
  @import "./main.css";
3
3
 
4
+ /* src/css/tokens/whitelabel/o3-form/_variables.css */
5
+ [data-o3-brand=whitelabel] .o3-form {
6
+ --_o3-form-text-input-border: 2px solid var(--o3-color-palette-black-30);
7
+ --_o3-form-text-input-border-error: 2px solid var(--o3-color-use-case-alert-text);
8
+ --_o3-form-text-input-background-color: var(--o3-color-palette-white);
9
+ --_o3-form-text-input-background-color-error: rgba(204, 0, 0, 0.06);
10
+ --_o3-form-text-input-border-radius: 0.375rem;
11
+ }
12
+
4
13
  /* src/css/brands/whitelabel.css */
package/esm/CheckBox.d.ts CHANGED
@@ -1,2 +1,8 @@
1
- import 'react/jsx-runtime';
2
- export { c as CheckBox, d as CheckBoxGroup, C as CheckBoxItem } from './CheckBox-DRFC93iL.js';
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { C as CheckBoxProps, b as FormFieldsetProps } from './index-BP51ZwQo.js';
3
+
4
+ declare const CheckBoxItem: (props: CheckBoxProps) => react_jsx_runtime.JSX.Element;
5
+ declare const CheckBox: (props: CheckBoxProps) => react_jsx_runtime.JSX.Element;
6
+ declare const CheckBoxGroup: (props: FormFieldsetProps) => react_jsx_runtime.JSX.Element;
7
+
8
+ export { CheckBox, CheckBoxGroup, CheckBoxItem };
@@ -0,0 +1,6 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { T as TextInputProps } from './index-BP51ZwQo.js';
3
+
4
+ declare const TextInput: ({ label, feedback, description, disabled, length, attributes, inputId, optional, }: TextInputProps) => react_jsx_runtime.JSX.Element;
5
+
6
+ export { TextInput };
@@ -0,0 +1,45 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import "../../main.css";
3
+ import { LabeledFormField } from "./fieldComponents/FormField";
4
+ const TextInput = ({
5
+ label,
6
+ feedback,
7
+ description,
8
+ disabled,
9
+ length,
10
+ attributes,
11
+ inputId,
12
+ optional
13
+ }) => {
14
+ const inputClasses = ["o3-form", "o3-form-text-input"];
15
+ if (feedback && feedback.type === "error") {
16
+ inputClasses.push("o3-form-text-input--error");
17
+ }
18
+ if (length) {
19
+ inputClasses.push(`o3-form-text-input--short-${length}`);
20
+ }
21
+ return /* @__PURE__ */ jsx(
22
+ LabeledFormField,
23
+ {
24
+ label,
25
+ feedback,
26
+ description,
27
+ children: /* @__PURE__ */ jsx(
28
+ "input",
29
+ {
30
+ ...attributes,
31
+ id: inputId,
32
+ disabled,
33
+ className: inputClasses.join(" "),
34
+ required: optional,
35
+ "aria-required": optional,
36
+ maxLength: length,
37
+ type: "text"
38
+ }
39
+ )
40
+ }
41
+ );
42
+ };
43
+ export {
44
+ TextInput
45
+ };
@@ -1,5 +1,3 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
-
3
1
  type BaseInputProps = {
4
2
  inputId?: string;
5
3
  label?: string;
@@ -8,6 +6,11 @@ type BaseInputProps = {
8
6
  error?: boolean;
9
7
  attributes?: JSX.IntrinsicElements['input'];
10
8
  };
9
+ interface TextInputProps extends FormFieldProps {
10
+ disabled?: boolean;
11
+ length?: 2 | 3 | 4 | 5;
12
+ feedback?: FeedbackProps;
13
+ }
11
14
  interface CheckBoxProps extends BaseInputProps {
12
15
  inputId: string;
13
16
  checkboxLabel: string;
@@ -28,8 +31,4 @@ type FeedbackProps = {
28
31
  type: 'error';
29
32
  };
30
33
 
31
- declare const CheckBoxItem: (props: CheckBoxProps) => react_jsx_runtime.JSX.Element;
32
- declare const CheckBox: (props: CheckBoxProps) => react_jsx_runtime.JSX.Element;
33
- declare const CheckBoxGroup: (props: FormFieldsetProps) => react_jsx_runtime.JSX.Element;
34
-
35
- export { CheckBoxItem as C, type FeedbackProps as F, type FormFieldProps as a, type FormFieldsetProps as b, CheckBox as c, CheckBoxGroup as d };
34
+ export type { CheckBoxProps as C, FeedbackProps as F, TextInputProps as T, FormFieldProps as a, FormFieldsetProps as b };
package/esm/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { F as FeedbackProps, a as FormFieldProps, b as FormFieldsetProps } from './CheckBox-DRFC93iL.js';
3
- export { c as CheckBox, d as CheckBoxGroup, C as CheckBoxItem } from './CheckBox-DRFC93iL.js';
2
+ import { F as FeedbackProps, a as FormFieldProps, b as FormFieldsetProps } from './index-BP51ZwQo.js';
3
+ export { CheckBox, CheckBoxGroup, CheckBoxItem } from './CheckBox.js';
4
4
 
5
5
  declare const Feedback: ({ message, type }: FeedbackProps) => react_jsx_runtime.JSX.Element;
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/o3-form",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
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",