-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[UI Framework][K7]: Form components #13435
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fbe6b91
scaffolding for form components
snide 31763c3
switches and dropdowns for forms
snide f6249b5
more form styling
snide a48e7b7
move textfield mixin to a base class
snide 01c83db
code cleanup
snide d9c6e86
add number component
snide 994aec3
form checkbox use array
snide 23e2680
code cleanup for react
snide 54d3eda
replace textfield with mixin, add form row validation, add form valid…
snide 9406718
rename to CJ recomendation
snide 2a1148f
validation documentation
snide 784887d
more documentation
snide a1afb2d
more docs
snide 777ab5b
clone id onto inputs, make random ids in docs
snide cd732cb
make checkboxes use an object so ids can be passed
snide 06f4160
better checkbox / selects
snide 8783e8f
fix dark color validation
snide 75ca7b9
address feedback
snide ebf3e21
nest properly
snide ce67bc3
fix range selectors / spelling
snide File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,2 +1,3 @@ | ||
@import "../../dist/ui_framework.css"; | ||
@import "../../src/global_styling/variables/_index.scss"; | ||
@import "./components/guide_components"; |
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,65 @@ | ||
import React, { | ||
Component, | ||
} from 'react'; | ||
|
||
import { | ||
KuiFormRow, | ||
KuiFieldText, | ||
} from '../../../../components'; | ||
|
||
// Don't use this, make proper ids instead. This is just for the example. | ||
function makeId() { | ||
return Math.random().toString(36).substr(2, 5); | ||
} | ||
|
||
export default class extends Component { | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<KuiFieldText name="naked_text" placeholder="Naked component with placeholder" /> | ||
|
||
<br/><br/> | ||
|
||
<KuiFormRow | ||
id={makeId()} | ||
label="Text field in a form row" | ||
> | ||
<KuiFieldText name="text_name_in_row" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to self: update examples with ARIA attributes. |
||
</KuiFormRow> | ||
|
||
<KuiFormRow | ||
id={makeId()} | ||
label="Icons should only be used on field level components" | ||
icon="user" | ||
> | ||
<KuiFieldText name="text_name_in_row_with_icon" /> | ||
</KuiFormRow> | ||
|
||
<KuiFormRow | ||
id={makeId()} | ||
label="Text field with helptext" | ||
helpText="I'm some help text!" | ||
> | ||
<KuiFieldText name="text_name_in_row_with_help" /> | ||
</KuiFormRow> | ||
<KuiFormRow | ||
id={makeId()} | ||
label="Text field is invalid" | ||
invalid | ||
> | ||
<KuiFieldText name="text_name_in_row_is_invalid" /> | ||
</KuiFormRow> | ||
<KuiFormRow | ||
id={makeId()} | ||
label="Text field is invalid with errors" | ||
invalid | ||
errors={['Hello, I\'m some local error text passed as an array']} | ||
> | ||
<KuiFieldText name="text_name_in_row_has_errors" /> | ||
</KuiFormRow> | ||
</div> | ||
); | ||
} | ||
} | ||
|
154 changes: 154 additions & 0 deletions
154
ui_framework/doc_site/src/views/form/form_everything.js
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,154 @@ | ||
import React, { | ||
Component, | ||
} from 'react'; | ||
|
||
import { | ||
KuiForm, | ||
KuiCheckbox, | ||
KuiFieldNumber, | ||
KuiFieldPassword, | ||
KuiRange, | ||
KuiFormRow, | ||
KuiFieldSearch, | ||
KuiSelect, | ||
KuiSwitch, | ||
KuiFieldText, | ||
KuiTextArea, | ||
} from '../../../../components'; | ||
|
||
|
||
// Don't use this, make proper ids instead. This is just for the example. | ||
function makeId() { | ||
return Math.random().toString(36).substr(2, 5); | ||
} | ||
|
||
export default class extends Component { | ||
|
||
render() { | ||
|
||
// Checkboxes are passed as an array of objects. They can be optionally checked to start. | ||
const checkboxOptions = [ | ||
{ id: makeId(), label: 'Option one' }, | ||
{ id: makeId(), label: 'Option two is checked by default', checked: true }, | ||
{ id: makeId(), label: 'Option three' }, | ||
]; | ||
|
||
// Select options are passed as an array of objects. | ||
const selectOptions = [ | ||
{ value: 'option_one', text: 'Option one' }, | ||
{ value: 'option_two', text: 'Option two' }, | ||
{ value: 'option_three', text: 'Option three' }, | ||
]; | ||
|
||
|
||
const formSample = ( | ||
<KuiForm> | ||
|
||
<KuiFormRow | ||
id={makeId()} | ||
label="Number" | ||
helpText="Any number between 1 and 5" | ||
> | ||
<KuiFieldNumber | ||
name="number" | ||
min={1} | ||
max={5} | ||
/> | ||
</KuiFormRow> | ||
|
||
<KuiFormRow | ||
id={makeId()} | ||
label="First name" | ||
helpText="I am some friendly help text." | ||
> | ||
<KuiFieldText name="first" /> | ||
</KuiFormRow> | ||
|
||
<KuiFormRow | ||
id={makeId()} | ||
label="Last name with icon" | ||
icon="user" | ||
> | ||
<KuiFieldText | ||
name="first" | ||
placeholder="Some placeholder text" | ||
/> | ||
</KuiFormRow> | ||
|
||
<KuiFormRow | ||
id={makeId()} | ||
label="Password" | ||
icon="lock" | ||
> | ||
<KuiFieldPassword name="pass" /> | ||
</KuiFormRow> | ||
|
||
<KuiFormRow | ||
id={makeId()} | ||
label="Range" | ||
> | ||
<KuiRange | ||
min={0} | ||
max={100} | ||
name="range" | ||
id="range" | ||
/> | ||
</KuiFormRow> | ||
|
||
<KuiFormRow | ||
id={makeId()} | ||
label="Search" | ||
icon="search" | ||
> | ||
<KuiFieldSearch | ||
label="Search" | ||
name="search1" | ||
placeholder="Search..." | ||
/> | ||
</KuiFormRow> | ||
|
||
<KuiFormRow | ||
id={makeId()} | ||
label="Select dropdown" | ||
icon="arrowDown" | ||
containsSelect | ||
> | ||
<KuiSelect | ||
options={selectOptions} | ||
name="dropdown" | ||
/> | ||
</KuiFormRow> | ||
<KuiFormRow | ||
label="Textarea" | ||
id={makeId()} | ||
> | ||
<KuiTextArea name="textarea"/> | ||
</KuiFormRow> | ||
|
||
<KuiFormRow | ||
label="Use a swich if you only need one checkbox" | ||
> | ||
<KuiSwitch | ||
name="switch" | ||
id={makeId()} | ||
label="Should we do this?" | ||
/> | ||
</KuiFormRow> | ||
|
||
<KuiFormRow | ||
id={makeId()} | ||
label="You should always use more than one checkbox" | ||
> | ||
<KuiCheckbox options={checkboxOptions} /> | ||
</KuiFormRow> | ||
|
||
</KuiForm> | ||
); | ||
|
||
return ( | ||
<div> | ||
{formSample} | ||
</div> | ||
); | ||
} | ||
} |
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,112 @@ | ||
import React from 'react'; | ||
|
||
import { renderToHtml } from '../../services'; | ||
|
||
import { | ||
GuideDemo, | ||
GuideCode, | ||
GuidePage, | ||
GuideSection, | ||
GuideSectionTypes, | ||
GuideText, | ||
} from '../../components'; | ||
|
||
import FieldText from './field_text'; | ||
const fieldTextSource = require('!!raw!./field_text'); | ||
const fieldTextHtml = renderToHtml(FieldText); | ||
|
||
import FormEverything from './form_everything'; | ||
const formEverythingSource = require('!!raw!./form_everything'); | ||
const formEverythingHtml = renderToHtml(FormEverything); | ||
|
||
import FormValidation from './form_validation'; | ||
const formValidationSource = require('!!raw!./form_validation'); | ||
const formValidationHtml = renderToHtml(FormValidation); | ||
|
||
import FormPopover from './form_popover'; | ||
const formPopoverSource = require('!!raw!./form_popover'); | ||
const formPopoverHtml = renderToHtml(FormPopover); | ||
|
||
export default props => ( | ||
<GuidePage title={props.route.name}> | ||
<GuideSection | ||
title="Component structure" | ||
source={[{ | ||
type: GuideSectionTypes.JS, | ||
code: fieldTextSource, | ||
}, { | ||
type: GuideSectionTypes.HTML, | ||
code: fieldTextHtml, | ||
}]} | ||
> | ||
<GuideText> | ||
Each form input has a base component to cover generic use cases. These are raw HTML elements with only basic styling. | ||
Additionally, you can wrap any of these elements with a <GuideCode>FormRow</GuideCode> which gives you optional | ||
prebuilt labels, help text and validation. Below is an example showing the <GuideCode>FieldText</GuideCode> component | ||
in a bunch of configurations, but they all act roughly the same. Farther down in the docs you can see an example | ||
showing every form element and their individual prop settings (which mirror their HTML counterparts). | ||
</GuideText> | ||
|
||
<GuideDemo> | ||
<FieldText /> | ||
</GuideDemo> | ||
</GuideSection> | ||
<GuideSection | ||
title="Form component examples" | ||
source={[{ | ||
type: GuideSectionTypes.JS, | ||
code: formEverythingSource, | ||
}, { | ||
type: GuideSectionTypes.HTML, | ||
code: formEverythingHtml, | ||
}]} | ||
> | ||
<GuideText> | ||
This example shows every form element in use and showcases a variety of styles. Note that each one of these elements is wrapped | ||
by <GuideCode>FormRow</GuideCode>. | ||
</GuideText> | ||
|
||
<GuideDemo> | ||
<FormEverything /> | ||
</GuideDemo> | ||
</GuideSection> | ||
<GuideSection | ||
title="Form in popover" | ||
source={[{ | ||
type: GuideSectionTypes.JS, | ||
code: formPopoverSource, | ||
}, { | ||
type: GuideSectionTypes.HTML, | ||
code: formPopoverHtml, | ||
}]} | ||
> | ||
<GuideText> | ||
Forms can be placed within popovers and should scale accordingly. | ||
</GuideText> | ||
|
||
<GuideDemo> | ||
<FormPopover /> | ||
</GuideDemo> | ||
</GuideSection> | ||
<GuideSection | ||
title="Form validation" | ||
source={[{ | ||
type: GuideSectionTypes.JS, | ||
code: formValidationSource, | ||
}, { | ||
type: GuideSectionTypes.HTML, | ||
code: formValidationHtml, | ||
}]} | ||
> | ||
<GuideText> | ||
Validation is achieved by applying <GuideCode>invalid</GuideCode> and optionally <GuideCode>error</GuideCode> props | ||
onto the <GuideCode>KuiForm</GuideCode> or <GuideCode>KuiFormRow</GuideCode> components. Errors are optional | ||
and are passed as an array in case you need to list many errors. | ||
</GuideText> | ||
|
||
<GuideDemo> | ||
<FormValidation /> | ||
</GuideDemo> | ||
</GuideSection> | ||
</GuidePage> | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: port @BigFunger's ID generator over to the UI Framework.