-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [feature] add InputGroup Component.
- Loading branch information
1 parent
d46cab3
commit db1a98c
Showing
21 changed files
with
388 additions
and
79 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
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,53 @@ | ||
import React, { PropTypes } from 'react' | ||
import anyPass from 'ramda/src/anyPass'; | ||
import classnames from 'classnames'; | ||
|
||
const factory = (Select, Input, Button) => { | ||
|
||
const isSelect = child => child.type === Select; | ||
const isInput = child => child.type === Input; | ||
const isButton = child => child.type === Button; | ||
|
||
class InputGroup extends React.Component { | ||
static propTypes = { | ||
children: PropTypes.node, | ||
size: PropTypes.oneOf(['small', 'normal', 'large']), | ||
theme: PropTypes.shape({ | ||
inputGroup: PropTypes.string, | ||
input: PropTypes.string, | ||
}), | ||
} | ||
|
||
static defaultProps = { | ||
size: 'normal', | ||
} | ||
|
||
renderChildren = (children) => { | ||
return React.Children.map(this.props.children, (item, index) => | ||
anyPass([isInput, isSelect, isButton])(item) && React.cloneElement(item, { | ||
key: index, | ||
theme: this.props.theme, | ||
})); | ||
} | ||
|
||
render () { | ||
const { | ||
size, | ||
theme, | ||
children, | ||
} = this.props; | ||
|
||
const classes = classnames(theme.inputGroup, theme[size]); | ||
|
||
return ( | ||
<div className={classes}> | ||
{this.renderChildren(children)} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
return InputGroup; | ||
} | ||
|
||
export {factory as inputGroupFactory}; |
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 @@ | ||
import {inputGroupFactory} from './InputGroup'; | ||
import Button from '../button'; | ||
import Input from '../input'; | ||
import Select from '../select'; | ||
import { themr } from 'react-css-themr'; | ||
import { INPUTGROUP } from '../identifiers'; | ||
import theme from './theme.css'; | ||
|
||
const ThemedInputGroup = themr(INPUTGROUP, theme)(inputGroupFactory(Select, Input, Button)); | ||
|
||
export default ThemedInputGroup; | ||
export {ThemedInputGroup as InputGroup}; |
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,68 @@ | ||
@import "../colors.css"; | ||
@import "../variables.css"; | ||
|
||
:root { | ||
--input-group-large-padding: calc(.8 * var(--unit)); | ||
--input-group-normal-padding: calc(.4 * var(--unit)); | ||
--input-text-border-color: color(var(--color-black) a(12%)); | ||
} | ||
|
||
.inputGroup { | ||
display: flex; | ||
|
||
& > :first-child { | ||
border-top-left-radius: 4px; | ||
border-bottom-left-radius: 4px; | ||
} | ||
|
||
& > * { | ||
border-radius: 0; | ||
} | ||
|
||
& > :last-child { | ||
border-top-right-radius: 4px; | ||
border-bottom-right-radius: 4px; | ||
} | ||
|
||
& .select_input { | ||
min-width: auto; | ||
} | ||
|
||
& .input, | ||
& .select_input, | ||
& .neutral:not([disabled]).flat { | ||
border-width: 1px 0 1px 1px; | ||
border-style: solid; | ||
border-color: var(--input-text-border-color); | ||
|
||
&:last-child { | ||
border-right-width: 1px; | ||
} | ||
} | ||
|
||
& .input { | ||
flex: 1; | ||
} | ||
|
||
& .bar { | ||
display: none; | ||
} | ||
} | ||
|
||
.small { | ||
& .input { | ||
padding: 0; | ||
} | ||
} | ||
|
||
.normal { | ||
& .input { | ||
padding: var(--input-group-normal-padding); | ||
} | ||
} | ||
|
||
.large { | ||
& .input { | ||
padding: var(--input-group-large-padding); | ||
} | ||
} |
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,7 @@ | ||
import rippleFactory from './Ripple'; | ||
import theme from './theme.css'; | ||
|
||
const ripple = rippleFactory({ theme }); | ||
|
||
export default options => rippleFactory({ ...options, theme }); | ||
export {ripple}; |
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,48 +1,55 @@ | ||
import React, { PropTypes } from 'react'; | ||
import Button from '../button'; | ||
import {CaretDownIcon} from '../font_icon'; | ||
import classnames from 'classnames'; | ||
|
||
class SelectInput extends React.Component { | ||
static propTypes = { | ||
// 选择的值 | ||
selectedItem: PropTypes.object, | ||
// 下拉框激活 | ||
isActive: PropTypes.bool, | ||
placeholder: PropTypes.string, | ||
theme: PropTypes.object, | ||
onClick: PropTypes.func, | ||
const factory = (ripple) => { | ||
class SelectInput extends React.Component { | ||
static propTypes = { | ||
// 选择的值 | ||
selectedItem: PropTypes.object, | ||
// 下拉框激活 | ||
isActive: PropTypes.bool, | ||
placeholder: PropTypes.string, | ||
theme: PropTypes.object, | ||
onClick: PropTypes.func, | ||
} | ||
|
||
static defaultProps = { | ||
isActive: false, | ||
placeholder: '', | ||
} | ||
|
||
render () { | ||
const { | ||
selectedItem, | ||
placeholder, | ||
theme, | ||
isActive, | ||
onClick, | ||
children, | ||
...other | ||
} = this.props; | ||
|
||
const iconClasses = classnames({ | ||
[theme.open]: isActive, | ||
}, theme.arrow); | ||
|
||
return ( | ||
<button | ||
type="button" | ||
data-react-toolbox="select_input" | ||
onClick={onClick} | ||
className={theme.select_input} | ||
{...other}> | ||
<div className={theme.value}>{selectedItem.label || placeholder}</div> | ||
<CaretDownIcon className={iconClasses} /> | ||
{children} | ||
</button> | ||
); | ||
} | ||
} | ||
|
||
static defaultProps = { | ||
isActive: false, | ||
placeholder: '', | ||
} | ||
|
||
render () { | ||
const { | ||
selectedItem, | ||
placeholder, | ||
theme, | ||
isActive, | ||
onClick, | ||
} = this.props; | ||
|
||
const iconClasses = classnames({ | ||
[theme.open]: isActive, | ||
}, theme.arrow); | ||
|
||
|
||
|
||
return ( | ||
<Button | ||
onClick={onClick} | ||
className={theme.select_input}> | ||
<div className={theme.value}>{selectedItem.label || placeholder}</div> | ||
<CaretDownIcon className={iconClasses} /> | ||
</Button> | ||
); | ||
} | ||
return ripple(SelectInput); | ||
} | ||
|
||
export default SelectInput; | ||
export {factory as selectInputFactory}; |
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 @@ | ||
:root { | ||
--input-background-color: var(--color-white); | ||
--input-border-color: var(--palette-grey-300); | ||
--input-field-padding: calc(.8 * var(--unit)); | ||
--input-line-height: 26px; | ||
--input-color: var(--palette-grey-900); | ||
} |
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,9 +1,11 @@ | ||
import SelectInput from './SelectInput'; | ||
import theme from './theme.css'; | ||
import { themr } from 'react-css-themr'; | ||
import { SELECT_INPUT } from '../identifiers'; | ||
import {selectInputFactory} from './SelectInput'; | ||
import themedRippleFactory from '../ripple'; | ||
import theme from './theme.css'; | ||
|
||
const SelectInput = selectInputFactory(themedRippleFactory({centered: false })); | ||
const ThemedSelectInput = themr(SELECT_INPUT, theme)(SelectInput); | ||
|
||
export default ThemedSelectInput; | ||
export {ThemedSelectInput}; | ||
export {ThemedSelectInput as SelectInput}; |
Oops, something went wrong.