Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/website/plugins/remark-branded-content.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import visit from 'unist-util-visit';
import {visit} from 'unist-util-visit';

export default function remarkBrandedContent() {
/**
Expand Down
1 change: 0 additions & 1 deletion components/o3-form/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"check:type": "tsc --noEmit"
},
"peerDependencies": {
"@financial-times/o-utils": "^2.2.1",
"@financial-times/o3-foundation": "^3.0.0"
},
"devDependencies": {
Expand Down
8 changes: 1 addition & 7 deletions components/o3-form/src/tsx/CheckBox.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import {uidBuilder} from '@financial-times/o-utils';
import {TitledFormField, FormFieldset} from './fieldComponents/FormField';
import type {CheckBoxProps, FormFieldsetProps} from '../types/index';

const uniqueId = uidBuilder('o3-form-checkbox-input');

export const CheckBoxItem = (props: CheckBoxProps) => {
let {inputId, checkboxDescription, attributes, optional, error} = props;

if (!inputId) {
inputId = uniqueId('_');
}

const classNames = ['o3-form-input-checkbox__input', 'o3-visually-hidden'];

if (error) {
Expand Down Expand Up @@ -45,6 +38,7 @@ export const CheckBox = (props: CheckBoxProps) => {
const newProps = {
...props,
labelId: props.inputId,
labelsElement: props.inputId,
descriptionId: props.inputId,
};

Expand Down
9 changes: 2 additions & 7 deletions components/o3-form/src/tsx/DateInput.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import {uidBuilder} from '@financial-times/o-utils';
import {DateInputProps} from '../types';
import {LabeledFormField} from './fieldComponents/FormField';
import {useEffect, useRef} from 'react';
import {DateInputMask} from './DateInputMask';

const uniqueId = uidBuilder('o3-form-date-input');

export const DateInput = ({
label,
feedback,
Expand All @@ -17,8 +14,6 @@ export const DateInput = ({
}: DateInputProps) => {
let inputRef = useRef<HTMLInputElement | null>(null);

const id = inputId || uniqueId('_');

const inputClasses = [
'o3-form',
'o3-form-text-input',
Expand All @@ -41,11 +36,11 @@ export const DateInput = ({
label={label}
feedback={feedback}
description={description}
inputId={id}
labelsElement={inputId}
optional={optional}>
<input
{...attributes}
id={id}
id={inputId}
ref={inputRef}
disabled={disabled}
className={inputClasses.join(' ')}
Expand Down
8 changes: 2 additions & 6 deletions components/o3-form/src/tsx/DateInputPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {uidBuilder} from '@financial-times/o-utils';
import {DateInputProps} from '../types';
import {LabeledFormField} from './fieldComponents/FormField';

const uniqueId = uidBuilder('o3-form-date-input');

export const DateInputPicker = ({
label,
feedback,
Expand All @@ -13,7 +10,6 @@ export const DateInputPicker = ({
inputId,
optional,
}: DateInputProps) => {
const id = inputId || uniqueId('_');

const inputClasses = [
'o3-form',
Expand All @@ -29,11 +25,11 @@ export const DateInputPicker = ({
label={label}
feedback={feedback}
description={description}
inputId={id}
labelsElement={inputId}
optional={optional}>
<input
{...attributes}
id={id}
id={inputId}
disabled={disabled}
className={inputClasses.join(' ')}
required={!optional}
Expand Down
11 changes: 4 additions & 7 deletions components/o3-form/src/tsx/FileInput.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {uidBuilder} from '@financial-times/o-utils';
import {FileInputProps} from '../types';
import {LabeledFormField} from './fieldComponents/FormField';
import {ChangeEvent, useState} from "react";

const uniqueId = uidBuilder('o3-form-file-input');

export const FileInput = ({
label,
feedback,
Expand All @@ -15,7 +12,7 @@ export const FileInput = ({
optional,
isUploading
}: FileInputProps) => {
const id: string = inputId || uniqueId('_');

const [file, setFile] = useState<File | null>(null);

const onUpload = (event: ChangeEvent<HTMLInputElement>) => {
Expand All @@ -37,11 +34,11 @@ export const FileInput = ({
label={label}
feedback={feedback}
description={description}
inputId={id}
labelsElement={inputId}
optional={optional}>
<>
<div className={inputClasses.join(' ')}>
<label htmlFor={id} className="o3-form-file-input__label">
<label htmlFor={inputId} className="o3-form-file-input__label">
<span
className="o3-form-file-input__label-button o3-button o3-button--primary o3-button-icon o3-button-icon--upload">
File Upload
Expand All @@ -51,7 +48,7 @@ export const FileInput = ({
</label>
<input
{...attributes}
id={id}
id={inputId}
className="o3-form-file-input__input-field"
disabled={disabled}
required={!optional}
Expand Down
8 changes: 2 additions & 6 deletions components/o3-form/src/tsx/PasswordInput.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import {uidBuilder} from '@financial-times/o-utils';
import {PasswordInputProps} from '../types';
import {LabeledFormField} from './fieldComponents/FormField';
import {PasswordInputToggle as PasswordInputToggleController} from './PasswordInputToggle';
import {useEffect, useRef} from 'react';

const uniqueId = uidBuilder('o3-form-password-input');

export const PasswordInput = ({
label,
feedback,
Expand All @@ -16,7 +13,6 @@ export const PasswordInput = ({
optional,
forgotPasswordLink,
}: PasswordInputProps) => {
const id = inputId || uniqueId('_');

let inputRef = useRef<HTMLInputElement | null>(null);
let buttonRef = useRef<HTMLButtonElement | null>(null);
Expand Down Expand Up @@ -54,12 +50,12 @@ export const PasswordInput = ({
label={label}
feedback={feedback}
description={description}
inputId={id}
labelsElement={inputId}
optional={optional}>
<div className="o3-password-input__container">
<input
{...attributes}
id={id}
id={inputId}
ref={inputRef}
disabled={disabled}
data-testid="o3-password-input"
Expand Down
7 changes: 1 addition & 6 deletions components/o3-form/src/tsx/RadioButton.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import {uidBuilder} from '@financial-times/o-utils';
import {FormFieldset} from './fieldComponents/FormField';
import type {RadioButtonProps, FormFieldsetProps} from '../types';

const uniqueId = uidBuilder('o3-form-radio-button-input');

export const RadioButtonItem = (props: RadioButtonProps) => {
let {inputId, attributes, optional, error} = props;
if (!inputId) {
inputId = uniqueId('_');
}

const classNames = ['o3-form-input-radio-button', 'o3-visually-hidden'];

if (error) {
Expand Down
8 changes: 2 additions & 6 deletions components/o3-form/src/tsx/SelectInput.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {uidBuilder} from '@financial-times/o-utils';
import {SelectInputProps} from '../types/index';
import {LabeledFormField} from './fieldComponents/FormField';

const uniqueId = uidBuilder('o3-form-select-input');

export const SelectInput = ({
label,
feedback,
Expand All @@ -15,7 +12,6 @@ export const SelectInput = ({
children,
length,
}: SelectInputProps) => {
const id = inputId || uniqueId('_');
const inputClasses = ['o3-form', 'o3-form-select-input'];

if (feedback && feedback.type === 'error') {
Expand All @@ -27,15 +23,15 @@ export const SelectInput = ({
label={label}
feedback={feedback}
description={description}
inputId={id}
labelsElement={inputId}
optional={optional}>
<div
className={`o3-form-select-input__container ${
length ? `o3-form-select-input--short-${length}` : ''
}`}>
<select
{...attributes}
id={id}
id={inputId}
disabled={disabled}
className={inputClasses.join(' ')}
required={!optional}
Expand Down
8 changes: 2 additions & 6 deletions components/o3-form/src/tsx/TextInput.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {uidBuilder} from '@financial-times/o-utils';
import {TextInputProps} from '../types/index';
import {LabeledFormField} from './fieldComponents/FormField';

const uniqueId = uidBuilder('o3-form-text-input');

export const TextInput = ({
label,
feedback,
Expand All @@ -14,7 +11,6 @@ export const TextInput = ({
inputId,
optional,
}: TextInputProps) => {
const id = inputId || uniqueId('_');
const inputClasses = ['o3-form', 'o3-form-text-input'];

if (feedback && feedback.type === 'error') {
Expand All @@ -29,11 +25,11 @@ export const TextInput = ({
label={label}
feedback={feedback}
description={description}
inputId={id}
labelsElement={inputId}
optional={optional}>
<input
{...attributes}
id={id}
id={inputId}
disabled={disabled}
className={inputClasses.join(' ')}
required={!optional}
Expand Down
19 changes: 9 additions & 10 deletions components/o3-form/src/tsx/fieldComponents/FormField.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import {uidBuilder} from '@financial-times/o-utils';
import {Feedback} from './Feedback';

import type {FormFieldProps, FormFieldsetProps} from '../../types';

const uniqueId = uidBuilder('o3-form');

export const LabeledFormField = ({
inputId,
label,
labelsElement,
description,
feedback,
children,
optional,
}: FormFieldProps) => {
const id = inputId || uniqueId('input_');
const descriptionId = description ? uniqueId('description_') : undefined;
const descriptionId = description ? `description_${labelsElement}` : undefined;
const labelId = `label_${labelsElement}`;
const labelClasses = ['o3-form-field__label'];
if (optional) {
labelClasses.push('o3-form-field--optional');
}
return (
<div className="o3-form-field">
<label className={labelClasses.join(' ')} htmlFor={id}>
<label className={labelClasses.join(' ')} id={labelId} htmlFor={labelsElement}>
{label}
</label>

Expand All @@ -38,13 +35,14 @@ export const LabeledFormField = ({

export const TitledFormField = ({
label,
labelsElement,
description,
feedback,
children,
optional,
}: FormFieldProps) => {
const descriptionId = description ? uniqueId('description_') : undefined;
const labelId = uniqueId('label_');
const descriptionId = description ? `description_${labelsElement}` : undefined;
const labelId = `label_${labelsElement}`;
const labelClasses = ['o3-form-field__title'];
if (optional) {
labelClasses.push('o3-form-field--optional');
Expand All @@ -71,8 +69,9 @@ export const FormFieldset = ({
feedback,
children,
optional,
inputId
}: FormFieldsetProps) => {
const descriptionId = uniqueId('checkbox_');
const descriptionId = `checkbox_${inputId}`;
const labelClasses = ['o3-form-field__legend'];
if (optional) {
labelClasses.push('o3-form-field--optional');
Expand Down
12 changes: 7 additions & 5 deletions components/o3-form/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Base Input Props
export type BaseInputProps = {
inputId?: string;
label?: string;
inputId: string;
label: string;
description?: string;
optional?: boolean;
error?: boolean;
Expand Down Expand Up @@ -30,8 +30,8 @@ export interface SelectInputProps {
disabled?: boolean;
feedback?: FeedbackProps;
children?: React.JSX.Element[];
inputId?: string;
label?: string;
inputId: string;
label: string;
length?: 1 | 3;
description?: string;
optional?: boolean;
Expand All @@ -58,14 +58,16 @@ export interface RadioButtonProps extends BaseInputProps {
radioButtonLabel: string; // Label specifically for the radio button.
}
export interface FormFieldsetProps {
inputId: string;
label: string;
description?: string;
children: React.JSX.Element | React.JSX.Element[];
feedback?: FeedbackProps;
optional?: boolean;
}

export interface FormFieldProps extends BaseInputProps {
export interface FormFieldProps extends Omit<BaseInputProps, 'inputId'> {
labelsElement: string;
feedback?: FeedbackProps;
children: React.JSX.Element & JSX.IntrinsicElements['input'];
}
Expand Down
3 changes: 3 additions & 0 deletions libraries/o3-figma-sb-links/src/figma-links.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"o3-form--error-summary": "",
"o3-form--file-input": "",
"o3-form--file-input-error-state": "",
"o3-form--file-input-javascript": "",
"o3-form--password-input": "",
"o3-form--password-input-error-state": "",
"o3-form--radio-button": "",
Expand Down Expand Up @@ -225,6 +226,8 @@
"sustainable-views-o3-tooltip--toggle-tooltip": "https://www.figma.com/design/Y7u0SwIJ1mCNDE0dpzgHCJ/%F0%9F%92%A0-Sustainable-Views---Origami-(o3)?node-id=6318-473&t=jZcQ882g8fhmd6uu-4",
"sustainable-views-o3-typography-orderedlist--ordered-list-story": "",
"sustainable-views-o3-typography-unorderedlist--unordered-list-story": "",
"tests-o3-form--file-input-javascript-delete-button": "",
"tests-o3-form--file-input-javascript-upload-display": "",
"tests-o3-form--password-input-test": "",
"tests-o3-tooltip--onboarding-tooltip-test": "",
"tests-o3-tooltip--toggle-tooltip-test": "",
Expand Down
Loading
Loading