Input Group
import React from 'react';
import { InputGroup, InputGroupAddon, InputGroupText, Input } from 'reactstrap';
const Example = (props) => {
return (
<div>
<InputGroup>
<InputGroupAddon addonType="prepend">@</InputGroupAddon>
<Input placeholder="username" />
</InputGroup>
<br />
<InputGroup>
<InputGroupAddon addonType="prepend">
<InputGroupText>
<Input addon type="checkbox" aria-label="Checkbox for following text input" />
</InputGroupText>
</InputGroupAddon>
<Input placeholder="Check it out" />
</InputGroup>
<br />
<InputGroup>
<Input placeholder="username" />
<InputGroupAddon addonType="append">
<InputGroupText>@example.com</InputGroupText>
</InputGroupAddon>
</InputGroup>
<br />
<InputGroup>
<InputGroupAddon addonType="prepend">
<InputGroupText>$</InputGroupText>
<InputGroupText>$</InputGroupText>
</InputGroupAddon>
<Input placeholder="Dolla dolla billz yo!" />
<InputGroupAddon addonType="append">
<InputGroupText>$</InputGroupText>
<InputGroupText>$</InputGroupText>
</InputGroupAddon>
</InputGroup>
<br />
<InputGroup>
<InputGroupAddon addonType="prepend">$</InputGroupAddon>
<Input placeholder="Amount" min={0} max={100} type="number" step="1" />
<InputGroupAddon addonType="append">.00</InputGroupAddon>
</InputGroup>
</div>
);
};
export default Example;
Properties
InputGroup.propTypes = {
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
size: PropTypes.string,
className: PropTypes.string
};
InputGroupAddOn.propTypes = {
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
addonType: PropTypes.oneOf(['prepend', 'append']).isRequired,
className: PropTypes.string
};
InputGroupButton.propTypes = {
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
addonType: PropTypes.oneOf(['prepend', 'append']).isRequired,
children: PropTypes.node,
groupClassName: PropTypes.string, // only used in shorthand
groupAttributes: PropTypes.object, // only used in shorthand
className: PropTypes.string
};
Addons
import React from 'react';
import { InputGroup, InputGroupText, InputGroupAddon, Input } from 'reactstrap';
const Example = (props) => {
return (
<div>
<InputGroup>
<InputGroupAddon addonType="prepend">
<InputGroupText>To the Left!</InputGroupText>
</InputGroupAddon>
<Input />
</InputGroup>
<br />
<InputGroup>
<Input />
<InputGroupAddon addonType="append">
<InputGroupText>To the Right!</InputGroupText>
</InputGroupAddon>
</InputGroup>
<br />
<InputGroup>
<InputGroupAddon addonType="prepend">
<InputGroupText>To the Left!</InputGroupText>
</InputGroupAddon>
<Input placeholder="and..." />
<InputGroupAddon addonType="append">
<InputGroupText>To the Right!</InputGroupText>
</InputGroupAddon>
</InputGroup>
</div>
);
};
export default Example;
Addon Sizing
import React from 'react';
import { InputGroup, InputGroupAddon, Input } from 'reactstrap';
const Example = (props) => {
return (
<div>
<InputGroup size="lg">
<InputGroupAddon addonType="prepend">@lg</InputGroupAddon>
<Input />
</InputGroup>
<br />
<InputGroup>
<InputGroupAddon addonType="prepend">@normal</InputGroupAddon>
<Input />
</InputGroup>
<br />
<InputGroup size="sm">
<InputGroupAddon addonType="prepend">@sm</InputGroupAddon>
<Input />
</InputGroup>
</div>
);
};
export default Example;
Buttons / Dropdowns
import React from 'react';
import {
InputGroup,
InputGroupAddon,
InputGroupButtonDropdown,
InputGroupDropdown,
Input,
Button,
Dropdown,
DropdownToggle,
DropdownMenu,
DropdownItem
} from 'reactstrap';
export default class Example extends React.Component {
constructor(props) {
super(props);
this.toggleDropDown = this.toggleDropDown.bind(this);
this.toggleSplit = this.toggleSplit.bind(this);
this.state = {
dropdownOpen: false,
splitButtonOpen: false
};
}
toggleDropDown() {
this.setState({
dropdownOpen: !this.state.dropdownOpen
});
}
toggleSplit() {
this.setState({
splitButtonOpen: !this.state.splitButtonOpen
});
}
render() {
return (
<div>
<InputGroup>
<InputGroupAddon addonType="prepend"><Button>I'm a button</Button></InputGroupAddon>
<Input />
</InputGroup>
<br />
<InputGroup>
<Input />
<InputGroupButtonDropdown addonType="append" isOpen={this.state.dropdownOpen} toggle={this.toggleDropDown}>
<DropdownToggle caret>
Button Dropdown
</DropdownToggle>
<DropdownMenu>
<DropdownItem header>Header</DropdownItem>
<DropdownItem disabled>Action</DropdownItem>
<DropdownItem>Another Action</DropdownItem>
<DropdownItem divider />
<DropdownItem>Another Action</DropdownItem>
</DropdownMenu>
</InputGroupButtonDropdown>
</InputGroup>
<br />
<InputGroup>
<InputGroupButtonDropdown addonType="prepend" isOpen={this.state.splitButtonOpen} toggle={this.toggleSplit}>
<Button outline>Split Button</Button>
<DropdownToggle split outline />
<DropdownMenu>
<DropdownItem header>Header</DropdownItem>
<DropdownItem disabled>Action</DropdownItem>
<DropdownItem>Another Action</DropdownItem>
<DropdownItem divider />
<DropdownItem>Another Action</DropdownItem>
</DropdownMenu>
</InputGroupButtonDropdown>
<Input placeholder="and..." />
<InputGroupAddon addonType="append"><Button color="secondary">I'm a button</Button></InputGroupAddon>
</InputGroup>
</div>
);
}
}
Button Shorthand (DEPRECATED)
Button shorthand is deprecated. Below are the updated examples of how to use InputGroupAddon
to accomplish the same output.
Button shorthand is a convenience method for adding just a button. It is triggered when only a single string is the child. A Button will be created and all of the props will be passed to it with the exception ofgroupClassName
and groupAttributes
, which are used to added classes and attributes to the wrapping container. This means you can add your onClick
and other handlers directly toInputGroupButton
. If you want your string to not be wrapped in a button, then you really want to use InputGroupAddon
(see Addons above for that).
import React from 'react';
import { InputGroup, InputGroupAddon, Button, Input } from 'reactstrap';
const Example = (props) => {
return (
<div>
<InputGroup>
<InputGroupAddon addonType="prepend">
<Button>To the Left!</Button>
</InputGroupAddon>
<Input />
</InputGroup>
<br />
<InputGroup>
<Input />
<InputGroupAddon addonType="append">
<Button color="secondary">To the Right!</Button>
</InputGroupAddon>
</InputGroup>
<br />
<InputGroup>
<InputGroupAddon addonType="prepend">
<Button color="danger">To the Left!</Button>
</InputGroupAddon>
<Input placeholder="and..." />
<InputGroupAddon addonType="append">
<Button color="success">To the Right!</Button>
</InputGroupAddon>
</InputGroup>
</div>
);
};
export default Example;
当前内容版权归 reactstrap 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 reactstrap .