-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[InputAction] Initial implementation of a InputAction
component
#8365
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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
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,7 @@ | ||
import { StyledComponent } from ".."; | ||
|
||
export interface InputActionProps { | ||
component?: React.ReactType; | ||
} | ||
|
||
export default class InputAction extends StyledComponent<InputActionProps> {} |
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,53 @@ | ||
// @flow weak | ||
|
||
import React from 'react'; | ||
import type { Node, ElementType } from 'react'; | ||
import classNames from 'classnames'; | ||
import withStyles from '../styles/withStyles'; | ||
|
||
export const styles = (theme: Object) => ({ | ||
root: { | ||
position: 'absolute', | ||
right: -theme.spacing.unit * 2, | ||
top: theme.spacing.unit, | ||
}, | ||
}); | ||
|
||
type Default = { | ||
classes: Object, | ||
}; | ||
|
||
export type Props = { | ||
/** | ||
* The content of the component, normally an `IconButton`. | ||
*/ | ||
children?: Node, | ||
/** | ||
* Useful to extend the style applied to components. | ||
*/ | ||
classes?: Object, | ||
/** | ||
* @ignore | ||
*/ | ||
className?: string, | ||
/** | ||
* | ||
*/ | ||
component?: ElementType, | ||
}; | ||
|
||
function InputAction(props: Default & Props) { | ||
const { children, component, classes, className, ...other } = props; | ||
|
||
const Component = component || 'div'; | ||
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. React provides a mechanism for default, let's use it, it automatically added in the docs. |
||
|
||
return ( | ||
<Component {...other} className={classNames(classes.root, className)}> | ||
{children} | ||
</Component> | ||
); | ||
} | ||
|
||
InputAction.muiName = 'InputAction'; | ||
|
||
export default withStyles(styles, { name: 'MuiInputAction' })(InputAction); |
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,38 @@ | ||
// @flow | ||
|
||
import React from 'react'; | ||
import { assert } from 'chai'; | ||
import { createShallow, getClasses } from '../test-utils'; | ||
import InputAction from './InputAction'; | ||
|
||
describe('<InputAction />', () => { | ||
let shallow; | ||
let classes; | ||
|
||
before(() => { | ||
shallow = createShallow({ untilSelector: InputAction }); | ||
classes = getClasses(<InputAction />); | ||
}); | ||
|
||
it('should render a div', () => { | ||
const wrapper = shallow(<InputAction />); | ||
assert.strictEqual(wrapper.name(), 'div'); | ||
assert.strictEqual(wrapper.hasClass(classes.root), true); | ||
}); | ||
|
||
it('should render with the user and root classes', () => { | ||
const wrapper = shallow(<InputAction className="woofInputAction" />); | ||
assert.strictEqual(wrapper.hasClass('woofInputAction'), true); | ||
assert.strictEqual(wrapper.hasClass(classes.root), true); | ||
}); | ||
|
||
it('should render with the user and root classes', () => { | ||
const wrapper = shallow(<InputAction other="woofInputAction" />); | ||
assert.strictEqual(wrapper.prop('other'), 'woofInputAction'); | ||
}); | ||
|
||
it('should render Chidren', () => { | ||
const wrapper = shallow(<InputAction>Foo</InputAction>); | ||
assert.strictEqual(wrapper.childAt(0).node, 'Foo'); | ||
}); | ||
}); |
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,56 @@ | ||
// @flow weak | ||
|
||
import React from 'react'; | ||
import type { Node, ElementType } from 'react'; | ||
import classNames from 'classnames'; | ||
import withStyles from '../styles/withStyles'; | ||
|
||
export const styles = () => ({ | ||
root: {}, | ||
}); | ||
|
||
type Default = { | ||
classes: Object, | ||
component: ElementType, | ||
}; | ||
|
||
export type Props = { | ||
/** | ||
* The content of the component, normally an `IconButton`. | ||
*/ | ||
children?: Node, | ||
/** | ||
* Useful to extend the style applied to components. | ||
*/ | ||
classes?: Object, | ||
/** | ||
* @ignore | ||
*/ | ||
className?: string, | ||
/** | ||
* The component used for the root node. | ||
* Either a string to use a DOM element or a component. | ||
*/ | ||
component?: ElementType, | ||
/** | ||
* The position this adornment should appear relative to the `Input`. | ||
*/ | ||
position: 'before' | 'after', | ||
}; | ||
|
||
function InputAdornment(props: Default & Props) { | ||
const { children, component: Component, classes, className, position, ...other } = props; | ||
|
||
return ( | ||
<Component className={classNames(classes.root, className)} {...other}> | ||
{children} | ||
</Component> | ||
); | ||
} | ||
|
||
InputAdornment.muiName = 'InputAdornment'; | ||
InputAdornment.defaultProps = { | ||
component: 'div', | ||
}; | ||
|
||
export default withStyles(styles, { name: 'MuiInputAction' })(InputAdornment); |
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,6 @@ | ||
// @flow | ||
|
||
export { default } from './Input'; | ||
export { default as InputAction } from './InputAction'; | ||
export { default as InputAdornment } from './InputAdornment'; | ||
export { default as InputLabel } from './InputLabel'; |
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.
Missing