-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add text-input component (#1786)
- Loading branch information
Showing
19 changed files
with
473 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"o3": { | ||
"form": { | ||
"text-input": { | ||
"border": { | ||
"@": { | ||
"value": { | ||
"color": "{o3.color.palette.black-30}", | ||
"width": "2px", | ||
"style": "solid" | ||
}, | ||
"type": "border" | ||
}, | ||
"error": { | ||
"value": { | ||
"color": "{o3.color.use-case.alert-text}", | ||
"width": "2px", | ||
"style": "solid" | ||
}, | ||
"type": "border" | ||
} | ||
}, | ||
"background-color": { | ||
"@": { | ||
"value": "{o3.color.palette.white}", | ||
"type": "color" | ||
}, | ||
"error": { | ||
"value": "rgba(204, 0, 0, 0.06)", | ||
"type": "color" | ||
} | ||
}, | ||
"border-radius": { | ||
"value": "6px", | ||
"type": "borderRadius" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,108 @@ | ||
# o3-form[](#licence) | ||
|
||
Provides components to construct forms. | ||
|
||
## Overview | ||
|
||
o3-form provides UI form elements with consistent labelling, descriptions, and error styles and interfaces. | ||
|
||
## Components | ||
|
||
### Text Input | ||
|
||
A standard text input for collecting text values. | ||
label: 'Full name', | ||
description: 'Your full name as printed on your driving license', | ||
|
||
```tsx | ||
<TextInput label='Full name' | ||
disabled={false} | ||
description='Your full name as printed on your driving license' | ||
/> | ||
``` | ||
|
||
**HTML** | ||
|
||
``` | ||
<div data-o3-brand="whitelabel"> | ||
<div class="o3-form-field"> | ||
<label for="my-input-field">Full name</label> | ||
<span | ||
class="o3-form-input-description" | ||
> | ||
Your full name as printed on your driving license | ||
</span> | ||
<input id="my-input-field" class="o3-form o3-form-text-input" type="text" /> | ||
</div> | ||
</div> | ||
``` | ||
|
||
#### Short text input | ||
|
||
The size and max length of the text input can be limited with the `length` property. | ||
|
||
```html | ||
|
||
<TextInput label="Security code" | ||
description="3 digit security code as printed on the back of your credit card." | ||
length={3} />; | ||
``` | ||
|
||
**HTML** | ||
|
||
```html | ||
<div class="o3-form-field"> | ||
<label for="my-input-field">Security Code</label> | ||
<span | ||
class="o3-form-input-description" | ||
> | ||
3 digit security code as printed on the back of your credit card. | ||
</span> | ||
<input | ||
id="my-input-field" | ||
class="o3-form o3-form-text-input o3-form-text-input--short-3" | ||
maxlength="3" | ||
type="text" | ||
/> | ||
``` | ||
|
||
This will provide a text box 3 characters wide and only allow 3 characters to be typed. | ||
|
||
If you prefer to limit the length without styling, use the `maxLength` attribute instead. | ||
|
||
```tsx | ||
<TextInput label="Security code" | ||
description="3 digit security code as printed on the back of your credit card." | ||
feedback={args.feedback} | ||
attributes={{ | ||
maxLength: 3 | ||
}} />; | ||
``` | ||
|
||
**HTML** | ||
|
||
```html | ||
<div class="o3-form-field"> | ||
<label for="my-input-field">Security Code</label> | ||
<span | ||
class="o3-form-input-description" | ||
> | ||
3 digit security code as printed on the back of your credit card. | ||
</span> | ||
<input | ||
id="my-input-field" | ||
class="o3-form o3-form-text-input" | ||
maxlength="3" | ||
type="text" | ||
/> | ||
``` | ||
|
||
## Contact | ||
|
||
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:[email protected]). | ||
|
||
--- | ||
|
||
## Licence | ||
|
||
This software is published by the Financial Times under the [MIT licence](http://opensource.org/licenses/MIT). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
@import './src/css/components/form.css'; | ||
@import './src/css/components/form-field.css'; | ||
@import './src/css/components/feedback.css'; | ||
@import './src/css/components/text-input.css'; | ||
@import './src/css/components/checkbox.css'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
@import '@financial-times/o3-foundation/css/whitelabel.css'; | ||
@import '../tokens/whitelabel/o3-form/_variables.css'; | ||
@import '../../../main.css'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
.o3-form-text-input { | ||
border: var(--_o3-form-text-input-border); | ||
padding: var(--o3-spacing-3xs) var(--o3-spacing-2xs); | ||
background-color: var(--_o3-form-text-input-background-color); | ||
border-radius: var(--_o3-form-text-input-border-radius); | ||
max-width: var(--_o3-form-text-input-max-width); | ||
} | ||
|
||
.o3-form-text-input--short-2 { | ||
--_o3-form-text-input-max-width: 1.5em; | ||
} | ||
|
||
.o3-form-text-input--short-3 { | ||
--_o3-form-text-input-max-width: 2.5em; | ||
} | ||
|
||
.o3-form-text-input--short-4 { | ||
--_o3-form-text-input-max-width: 3.5em; | ||
} | ||
|
||
.o3-form-text-input--short-5 { | ||
--_o3-form-text-input-max-width: 4.5em; | ||
} | ||
.o3-form-text-input--error { | ||
border: var(--_o3-form-text-input-border-error); | ||
background-color: var(--_o3-form-text-input-background-color-error); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Do not edit directly | ||
*/ | ||
|
||
|
||
[data-o3-brand="whitelabel"] .o3-form { | ||
--_o3-form-text-input-border: 2px solid var(--o3-color-palette-black-30); | ||
--_o3-form-text-input-border-error: 2px solid var(--o3-color-use-case-alert-text); | ||
--_o3-form-text-input-background-color: var(--o3-color-palette-white); | ||
--_o3-form-text-input-background-color-error: rgba(204, 0, 0, 0.06); | ||
--_o3-form-text-input-border-radius: 0.375rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import {TextInputProps} from '../types/index'; | ||
import '../../main.css'; | ||
import {LabeledFormField} from './fieldComponents/FormField'; | ||
|
||
export const TextInput = ({ | ||
label, | ||
feedback, | ||
description, | ||
disabled, | ||
length, | ||
attributes, | ||
inputId, | ||
optional, | ||
}: TextInputProps) => { | ||
const inputClasses = ['o3-form', 'o3-form-text-input']; | ||
|
||
if (feedback && feedback.type === 'error') { | ||
inputClasses.push('o3-form-text-input--error'); | ||
} | ||
if (length) { | ||
inputClasses.push(`o3-form-text-input--short-${length}`); | ||
} | ||
|
||
return ( | ||
<LabeledFormField | ||
label={label} | ||
feedback={feedback} | ||
description={description}> | ||
<input | ||
{...attributes} | ||
id={inputId} | ||
disabled={disabled} | ||
className={inputClasses.join(' ')} | ||
required={optional} | ||
aria-required={optional} | ||
maxLength={length} | ||
type="text" | ||
/> | ||
</LabeledFormField> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
components/o3-form/stories/whitelabel/textInput.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import type {Meta} from '@storybook/react'; | ||
import links from '@financial-times/o3-figma-sb-links'; | ||
|
||
import {TextInput as TextInputTsx} from '../../src/tsx/TextInput'; | ||
import '../../src/css/brands/whitelabel.css'; | ||
|
||
const meta: Meta<typeof TextInputTsx> = { | ||
title: 'Whitelabel/o3-form', | ||
component: TextInputTsx, | ||
decorators: [ | ||
Story => ( | ||
<div data-o3-brand="whitelabel"> | ||
<Story /> | ||
</div> | ||
), | ||
], | ||
parameters: { | ||
backgrounds: {disable: true}, | ||
}, | ||
} as Meta; | ||
|
||
export const TextInput = { | ||
args: { | ||
label: 'Full name', | ||
description: 'Your full name as printed on your driving license', | ||
feedback: {}, | ||
}, | ||
parameters: { | ||
design: { | ||
type: 'figma', | ||
url: links['whitelabel-o3-form--text-input'].figma, | ||
}, | ||
}, | ||
render: (args) => { | ||
return ( | ||
<TextInputTsx label={args.label} disabled={args.disabled} description={args.description} feedback={args.feedback} | ||
/>); | ||
}, | ||
}; | ||
|
||
export const TextInputErrorState = { | ||
args: { | ||
label: 'Full name', | ||
description: 'Your full name as printed on your driving license', | ||
feedback: {message: 'Something went wrong', type: 'error'}, | ||
}, | ||
parameters: { | ||
design: { | ||
type: 'figma', | ||
url: links['whitelabel-o3-form--text-input-error-state'].figma, | ||
}, | ||
}, | ||
render: (args) => { | ||
return ( | ||
<TextInputTsx label={args.label} disabled={args.disabled} description={args.description} length={args.length} | ||
feedback={args.feedback} | ||
/>); | ||
}, | ||
}; | ||
|
||
export const ShortTextInput = (args) => { | ||
return ( | ||
<> | ||
<TextInputTsx label="Day" description="Two digit day of the month" feedback={args.feedback} length={2} | ||
/> | ||
<TextInputTsx label="Security code" | ||
description="3 digit security code as printed on the back of your credit card." | ||
feedback={args.feedback} length={3} /> | ||
<TextInputTsx label="Date of Bith" description="The year you were born" feedback={args.feedback} length={4} | ||
/> | ||
<TextInputTsx label="Passcode" description="A 5-digin code to authenticate you on login" | ||
feedback={args.feedback} length={5} /> | ||
</> | ||
); | ||
}; | ||
ShortTextInput.parameters = { | ||
controls: { | ||
disable: true | ||
}, | ||
design: { | ||
type: 'figma', | ||
url: links['whitelabel-o3-form--text-input'].figma, | ||
}, | ||
} | ||
|
||
export default meta; |
Oops, something went wrong.