-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also changed the editorconfig for markdown files to ease up on the tabbing restrictions to the code samples can be aligned nicely.
- Loading branch information
1 parent
96dfd4a
commit f31e7df
Showing
3 changed files
with
167 additions
and
10 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 |
---|---|---|
@@ -1,21 +1,141 @@ | ||
### Minimal Usage | ||
|
||
By default, a "text" input field will be rendered, but other types are also supported. | ||
|
||
``` | ||
<div> | ||
<Input label="First name (default)" /> | ||
<Input label="First name" value="Lucy" /> | ||
<Input type="password" label="Password" value="123abc" /> | ||
<Input type="number" label="Age" value="32" /> | ||
<Input type="number" label="Age" value="35" /> | ||
<Input type="password" label="Tax ID" value="123456789" /> | ||
</div> | ||
``` | ||
|
||
<Input label="First name (auto focus)" autoFocus /> | ||
### Disabling an input | ||
|
||
<Input label="First name (disabled)" disabled /> | ||
``` | ||
<Input label="Address" disabled /> | ||
``` | ||
|
||
<Input label="First name (success)" feedback="success" /> | ||
<Input label="First name (error)" feedback="error" /> | ||
### Showing feedback for entered values | ||
|
||
<Input label="First name (error msg)" feedback="error" error="First name is required" /> | ||
Use the `feedback` attribute to give the user feedback regarding their input. You can affirm that the user's input | ||
was correct, or highlight errors that must be corrected. | ||
|
||
<Input label="First name (helper)" feedback="success" | ||
helper={<Input.Helper>Some helper stuff</Input.Helper>} | ||
``` | ||
<div> | ||
<Input label="Username" value="guest12345" feedback="success" /> | ||
<Input label="Email" value="[email protected]" feedback="error" | ||
error="That email is already associated with another account. Choose another one." | ||
/> | ||
</div> | ||
``` | ||
|
||
TDS does not perform input validations, as that is an application level concern. You will need to track the value of your | ||
input fields and perform any required data validations either client side or server side, depending on the context. | ||
|
||
Here is an example. Enter a value into the field below, then click away to lose focus. If you enter less than 10 | ||
characters you will receive an error message. Enter 10 or more characters to receive the success feedback. | ||
|
||
``` | ||
initialState = { | ||
value: '', | ||
status: undefined, | ||
errorMessage: undefined | ||
}; | ||
const updateValue = (event) => { | ||
setState({ value: event.target.value }) | ||
} | ||
const validate = (event) => { | ||
const value = event.target.value | ||
if (value.length < 10) { | ||
setState({ | ||
status: 'error', | ||
errorMessage: 'Your name must be greater than 10 characters' | ||
}) | ||
} | ||
else { | ||
setState({ | ||
status: 'success', | ||
errorMessage: undefined | ||
}) | ||
} | ||
}; | ||
<div> | ||
<Input label="Name" value={state.value} | ||
feedback={state.status} error={state.errorMessage} | ||
onChange={updateValue} onBlur={validate} | ||
/> | ||
</div> | ||
``` | ||
|
||
### Supplying extra information | ||
|
||
Use a `helper` to offer the user a detailed explanation of the input expected by a form field. Use the `Input.Helper` | ||
component. | ||
|
||
``` | ||
const passwordRequirements = ( | ||
<Input.Helper> | ||
<Text bold>Your password must be:</Text> | ||
<ul className="list list--compact"> | ||
<li className="list__item">16 characters or longer</li> | ||
<li className="list__item">Not repeated from previous password</li> | ||
</ul> | ||
</Input.Helper> | ||
); | ||
<Input label="Password" type="password" helper={passwordRequirements} /> | ||
``` | ||
|
||
The helper will also receive the feedback state and will be styled accordingly in response to user input. | ||
|
||
Here is an example. Enter a value into the field below, then click away to lose focus. If you enter less than the 16 | ||
character minimum the helper will show as an error. Enter 16 or more characters to receive the success feedback. | ||
|
||
``` | ||
initialState = { | ||
value: '', | ||
status: undefined, | ||
errorMessage: undefined | ||
} | ||
const updateValue = (event) => { | ||
setState({ value: event.target.value }) | ||
} | ||
const validate = (event) => { | ||
const value = event.target.value | ||
if (value.length < 16) { | ||
setState({ status: 'error' }) | ||
} | ||
else { | ||
setState({ status: 'success' }) | ||
} | ||
} | ||
const passwordRequirements = ( | ||
<Input.Helper> | ||
<Text bold>Your password must be:</Text> | ||
<ul className="list list--compact"> | ||
<li className="list__item">16 characters or longer</li> | ||
<li className="list__item">Not repeated from previous password</li> | ||
</ul> | ||
</Input.Helper> | ||
); | ||
<div> | ||
<Input label="Password" type="password" id="password-2" | ||
value={state.value} feedback={state.status} | ||
onChange={updateValue} onBlur={validate} | ||
helper={passwordRequirements} | ||
/> | ||
</div> | ||
``` |