This repository was archived by the owner on Jan 20, 2022. It is now read-only.
forked from Semantic-Org/Semantic-UI-React
-
Notifications
You must be signed in to change notification settings - Fork 2
feat(Input): add new component #64
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e89b951
adding input component - first implementation
a003138
adding Input examples
0d9d8b5
adding placeholder to the Input simple example
alinais 2e05f5d
adding focus property to the Input component
alinais 37e0f8f
updating icon variations
alinais 9b86c46
updating the component to use the UIComponent
alinais 943a2ca
updating line endings; updating css rules
alinais 199af34
fixing LF lines ending
alinais 628441b
adding accessibility tag to the Input Component
alinais eed501d
removing focus, error properties, simplifying the PR
alinais 0e6c628
adding shorthands examples; removing not needed styles
alinais 0586ff7
removing unused prop type for the icon property - keeping only the sh…
alinais 7467269
moving the padding to variables object
alinais 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
This file contains hidden or 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
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Input/Types/InputExample.shorthand.tsx
This file contains hidden or 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,6 @@ | ||
| import React from 'react' | ||
| import { Input } from 'stardust' | ||
|
|
||
| const InputExample = () => <Input placeholder="Search..." /> | ||
|
|
||
| export default InputExample |
This file contains hidden or 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,15 @@ | ||
| import React from 'react' | ||
| import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
| import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' | ||
|
|
||
| const Types = () => ( | ||
| <ExampleSection title="Types"> | ||
| <ComponentExample | ||
| title="Default" | ||
| description="A default Input." | ||
| examplePath="components/Input/Types/InputExample" | ||
| /> | ||
| </ExampleSection> | ||
| ) | ||
|
|
||
| export default Types |
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Input/Variations/InputExampleIcon.shorthand.tsx
This file contains hidden or 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,6 @@ | ||
| import React from 'react' | ||
| import { Input } from 'stardust' | ||
|
|
||
| const InputExampleIcon = () => <Input icon="search" placeholder="Search..." /> | ||
|
|
||
| export default InputExampleIcon |
This file contains hidden or 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,15 @@ | ||
| import React from 'react' | ||
| import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
| import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' | ||
|
|
||
| const Variations = () => ( | ||
| <ExampleSection title="Variations"> | ||
| <ComponentExample | ||
| title="Icon" | ||
| description="An input can have a search icon." | ||
| examplePath="components/Input/Variations/InputExampleIcon" | ||
| /> | ||
| </ExampleSection> | ||
| ) | ||
|
|
||
| export default Variations |
This file contains hidden or 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 @@ | ||
| import React from 'react' | ||
| import Types from './Types' | ||
| import Variations from './Variations' | ||
|
|
||
| const InputExamples = () => ( | ||
| <div> | ||
| <Types /> | ||
| <Variations /> | ||
| </div> | ||
| ) | ||
|
|
||
| export default InputExamples |
This file contains hidden or 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 hidden or 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,129 @@ | ||
| import PropTypes from 'prop-types' | ||
| import React, { Children, cloneElement } from 'react' | ||
| import cx from 'classnames' | ||
| import _ from 'lodash' | ||
|
|
||
| import { | ||
| childrenExist, | ||
| createHTMLInput, | ||
| customPropTypes, | ||
| getUnhandledProps, | ||
| partitionHTMLProps, | ||
| UIComponent, | ||
| } from '../../lib' | ||
| import inputRules from './inputRules' | ||
| import inputVariables from './inputVariables' | ||
| import Icon from '../Icon' | ||
|
|
||
| /** | ||
| * An Input | ||
| * @accessibility This is example usage of the accessibility tag. | ||
| */ | ||
| class Input extends UIComponent<any, any> { | ||
| static className = 'ui-input' | ||
|
|
||
| static displayName = 'Input' | ||
|
|
||
| static rules = inputRules | ||
| static variables = inputVariables | ||
|
|
||
| static propTypes = { | ||
| /** An element type to render as (string or function). */ | ||
| as: customPropTypes.as, | ||
|
|
||
| /** Primary content. */ | ||
| children: PropTypes.node, | ||
|
|
||
| /** Additional classes. */ | ||
| className: PropTypes.string, | ||
|
|
||
| /** Optional Icon to display inside the Input. */ | ||
| icon: customPropTypes.itemShorthand, | ||
|
|
||
| /** Shorthand for creating the HTML Input. */ | ||
| input: customPropTypes.itemShorthand, | ||
|
|
||
| /** The HTML input type. */ | ||
| type: PropTypes.string, | ||
| } | ||
|
|
||
| static handledProps = ['as', 'children', 'className', 'icon', 'input', 'type'] | ||
|
|
||
| static defaultProps = { | ||
| as: 'div', | ||
| type: 'text', | ||
| } | ||
|
|
||
| handleChildOverrides = (child, defaultProps) => ({ | ||
| ...defaultProps, | ||
| ...child.props, | ||
| }) | ||
|
|
||
| partitionProps = () => { | ||
| const { type } = this.props | ||
|
|
||
| const unhandled = getUnhandledProps(Input, this.props) | ||
| const [htmlInputProps, rest] = partitionHTMLProps(unhandled) | ||
|
|
||
| return [ | ||
| { | ||
| ...htmlInputProps, | ||
| type, | ||
| }, | ||
| rest, | ||
| ] | ||
| } | ||
|
|
||
| computeIcon = () => { | ||
| const { icon } = this.props | ||
|
|
||
| if (!_.isNil(icon)) return icon | ||
| return null | ||
| } | ||
|
|
||
| renderComponent({ ElementType, classes, rest }) { | ||
| const { children, className, icon, input, type } = this.props | ||
| const [htmlInputProps, restProps] = this.partitionProps() | ||
|
|
||
| const inputClasses = cx(classes.input) | ||
|
|
||
| // Render with children | ||
| // ---------------------------------------- | ||
| if (childrenExist(children)) { | ||
| // add htmlInputProps to the `<input />` child | ||
| const childElements = _.map(Children.toArray(children), child => { | ||
| if (child.type !== 'input') return child | ||
| return cloneElement(child, this.handleChildOverrides(child, htmlInputProps)) | ||
| }) | ||
|
|
||
| return ( | ||
| <ElementType {...rest} className={classes.root}> | ||
| {childElements} | ||
| </ElementType> | ||
| ) | ||
| } | ||
|
|
||
| if (this.computeIcon()) { | ||
| return ( | ||
| <ElementType {...rest} className={classes.root} {...htmlInputProps}> | ||
| {createHTMLInput(input || type, { | ||
| defaultProps: htmlInputProps, | ||
| overrideProps: { className: inputClasses }, | ||
| })} | ||
| <Icon name={this.computeIcon()} /> | ||
| </ElementType> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <ElementType {...rest} className={classes.root} {...htmlInputProps}> | ||
| {createHTMLInput(input || type, { | ||
| defaultProps: htmlInputProps, | ||
| overrideProps: { className: inputClasses }, | ||
| })} | ||
| </ElementType> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default Input |
This file contains hidden or 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 @@ | ||
| export { default } from './Input' |
This file contains hidden or 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,23 @@ | ||
| const inputRules = { | ||
| root: ({ props, variables }) => { | ||
| return { | ||
| display: 'inline-flex', | ||
| position: 'relative', | ||
| alignItems: 'center', | ||
| justifyContent: 'flex-end', | ||
| border: variables.defaultBorder, | ||
| borderRadius: variables.borderRadius, | ||
| outline: 0, | ||
| padding: variables.defaultPadding, | ||
| } | ||
| }, | ||
|
|
||
| input: ({ props, variables }) => { | ||
| return { | ||
| outline: 0, | ||
| border: 0, | ||
| } | ||
| }, | ||
| } | ||
|
|
||
| export default inputRules |
This file contains hidden or 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,14 @@ | ||
| import { pxToRem } from '../../lib' | ||
|
|
||
| export default (siteVars: any) => { | ||
| const vars: any = {} | ||
|
|
||
| vars.borderRadius = `${pxToRem(3)} ${pxToRem(3)} ${pxToRem(2)} ${pxToRem(2)}` | ||
|
|
||
| vars.defaultBorder = `${pxToRem(1)} solid #222426` | ||
| vars.defaultBorderFocus = `${pxToRem(1)} solid #85b7d9` | ||
| vars.defaultBorderError = `${pxToRem(1)} solid #e0b4b4` | ||
| vars.defaultPadding = `${pxToRem(6)} 0 ${pxToRem(6)} ${pxToRem(10)}` | ||
|
|
||
| return vars | ||
| } |
This file contains hidden or 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 hidden or 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,10 @@ | ||
| import React from 'react' | ||
|
|
||
| import { isConformant } from 'test/specs/commonTests' | ||
| import { getTestingRenderedComponent } from 'test/utils' | ||
|
|
||
| import Input from 'src/components/Input/Input' | ||
|
|
||
| describe('Input', () => { | ||
| isConformant(Input) | ||
| }) |
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.
This would be a great place to dog food our own new Input component!
I think Stardust's first Input iteration will support everything that is needed here, except icon. The styling won't look quite as nice until we introduce
invertedandfluid, but that is ok. It will serve as a reminder to us.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.
will add in a different PR