By default, all the <Panel />
does is apply a basic border and padding to contain some content.
You can pass on any additional properties you need, e.g. a custom onClick
handler, as it is shown in the example code. They all will apply to the wrapper div
element.
function handleClick() { alert('You have clicked on me'); } const panelInstance = ( <Panel onClick={handleClick}> <Panel.Body>Basic panel example</Panel.Body> </Panel> ); render(panelInstance);
Easily add a heading container to your panel with the <Panel.Heading>
and <Panel.Title>
sub-components.
<div> <Panel> <Panel.Heading>Panel heading without a title</Panel.Heading> <Panel.Body>Panel content</Panel.Body> </Panel> <Panel> <Panel.Heading> <Panel.Title componentClass="h3">Panel heading with a title</Panel.Title> </Panel.Heading> <Panel.Body>Panel content</Panel.Body> </Panel> </div>;
Pass buttons or secondary text in the <Panel.Footer>
sub-component. Note that panel footers do not inherit colors and borders when using contextual variations as they are not meant to be in the foreground.
<Panel> <Panel.Body>Panel content</Panel.Body> <Panel.Footer>Panel footer</Panel.Footer> </Panel>;
Like other components, easily make a panel more meaningful to a particular context by adding a bsStyle
prop.
<div> <Panel bsStyle="primary"> <Panel.Heading> <Panel.Title componentClass="h3">Panel heading</Panel.Title> </Panel.Heading> <Panel.Body>Panel content</Panel.Body> </Panel> <Panel bsStyle="success"> <Panel.Heading> <Panel.Title componentClass="h3">Panel heading</Panel.Title> </Panel.Heading> <Panel.Body>Panel content</Panel.Body> </Panel> <Panel bsStyle="info"> <Panel.Heading> <Panel.Title componentClass="h3">Panel heading</Panel.Title> </Panel.Heading> <Panel.Body>Panel content</Panel.Body> </Panel> <Panel bsStyle="warning"> <Panel.Heading> <Panel.Title componentClass="h3">Panel heading</Panel.Title> </Panel.Heading> <Panel.Body>Panel content</Panel.Body> </Panel> <Panel bsStyle="danger"> <Panel.Heading> <Panel.Title componentClass="h3">Panel heading</Panel.Title> </Panel.Heading> <Panel.Body>Panel content</Panel.Body> </Panel> </div>;
Add any <Table />
, <ListGroup />
to a panel for a seamless integration. Mix and match with Panel.Body
as needed.
<Panel> <Panel.Heading>Panel heading</Panel.Heading> <Panel.Body>Some default panel content here.</Panel.Body> <ListGroup> <ListGroupItem>Item 1</ListGroupItem> <ListGroupItem>Item 2</ListGroupItem> <ListGroupItem>…</ListGroupItem> </ListGroup> <Panel.Body>Some more panel content here.</Panel.Body> </Panel>;
You can also make the Panel heading toggle the collapse.
Or use a Panel.Toggle component to customize
class Example extends React.Component { constructor(props, context) { super(props, context); this.state = { open: true }; } render() { return ( <div> <Button onClick={() => this.setState({ open: !this.state.open })}> Click to toggle </Button> <br /> <Panel id="collapsible-panel-example-1" expanded={this.state.open}> <Panel.Collapse> <Panel.Body> Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. </Panel.Body> </Panel.Collapse> </Panel> <p>You can also make the Panel heading toggle the collapse.</p> <Panel id="collapsible-panel-example-2" defaultExpanded> <Panel.Heading> <Panel.Title toggle> Title that functions as a collapse toggle </Panel.Title> </Panel.Heading> <Panel.Collapse> <Panel.Body> Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. </Panel.Body> </Panel.Collapse> </Panel> <p>Or use a Panel.Toggle component to customize</p> <Panel id="collapsible-panel-example-3" defaultExpanded> <Panel.Heading> <Panel.Title>Title that functions as a collapse toggle</Panel.Title> <Panel.Toggle componentClass="a">My own toggle</Panel.Toggle> </Panel.Heading> <Panel.Collapse> <Panel.Body> Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. </Panel.Body> </Panel.Collapse> </Panel> </div> ); } } render(<Example />);
PanelGroup
s can be controlled by a parent component. The activeKey
prop dictates which panel is open.
class ControlledPanelGroup extends React.Component { constructor(props, context) { super(props, context); this.handleSelect = this.handleSelect.bind(this); this.state = { activeKey: '1' }; } handleSelect(activeKey) { this.setState({ activeKey }); } render() { return ( <PanelGroup accordion id="accordion-controlled-example" activeKey={this.state.activeKey} onSelect={this.handleSelect} > <Panel eventKey="1"> <Panel.Heading> <Panel.Title toggle>Panel heading 1</Panel.Title> </Panel.Heading> <Panel.Body collapsible>Panel content 1</Panel.Body> </Panel> <Panel eventKey="2"> <Panel.Heading> <Panel.Title toggle>Panel heading 2</Panel.Title> </Panel.Heading> <Panel.Body collapsible>Panel content 2</Panel.Body> </Panel> </PanelGroup> ); } } render(<ControlledPanelGroup />);
PanelGroup
s can also be uncontrolled where they manage their own state. The defaultActiveKey
prop dictates which panel is open when initially.
<PanelGroup accordion id="accordion-uncontrolled-example" defaultActiveKey="2"> <Panel eventKey="1"> <Panel.Heading> <Panel.Title toggle>Panel heading 1</Panel.Title> </Panel.Heading> <Panel.Body collapsible>Panel content 1</Panel.Body> </Panel> <Panel eventKey="2"> <Panel.Heading> <Panel.Title toggle>Panel heading 2</Panel.Title> </Panel.Heading> <Panel.Body collapsible>Panel content 2</Panel.Body> </Panel> </PanelGroup>;
Use <PanelGroup accordion />
to create an accordion style collapsing Panel set.
<PanelGroup accordion id="accordion-example"> <Panel eventKey="1"> <Panel.Heading> <Panel.Title toggle>Collapsible Group Item #1</Panel.Title> </Panel.Heading> <Panel.Body collapsible> Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. </Panel.Body> </Panel> <Panel eventKey="2"> <Panel.Heading> <Panel.Title toggle>Collapsible Group Item #2</Panel.Title> </Panel.Heading> <Panel.Body collapsible> Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. </Panel.Body> </Panel> <Panel eventKey="3"> <Panel.Heading> <Panel.Title toggle>Collapsible Group Item #3</Panel.Title> </Panel.Heading> <Panel.Body collapsible> Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. </Panel.Body> </Panel> </PanelGroup>;
Name | Type | Default | Description |
---|---|---|---|
expanded | boolean | controlled by: onToggle , initial prop: defaultExpanded Controls the collapsed/expanded state ofthe Panel. Requires
a | |
onToggle | function | controls expanded A callback fired when the collapse state changes. | |
eventKey | any | A unique identifier for the Component, the | |
id | string | An HTML |
Name | Type | Default | Description |
---|---|---|---|
componentClass | elementType | 'div' | You can use a custom element type for this component. |
bsClass | string | 'panel' | Base CSS class and prefix for the component. Generally one should only change |
Name | Type | Default | Description |
---|---|---|---|
componentClass | elementType | 'div' | You can use a custom element type for this component. |
toggle | boolean | A convenience prop that renders the Panel.Title as a panel collapse toggle component for the common use-case. | |
bsClass | string | 'panel' | Base CSS class and prefix for the component. Generally one should only change |
Name | Type | Default | Description |
---|---|---|---|
componentClass | elementType | SafeAnchor | You can use a custom element for this component |
Name | Type | Default | Description |
---|---|---|---|
onEnter | function | Callback fired before the component expands | |
onEntering | function | Callback fired after the component starts to expand | |
onEntered | function | Callback fired after the component has expanded | |
onExit | function | Callback fired before the component collapses | |
onExiting | function | Callback fired after the component starts to collapse | |
onExited | function | Callback fired after the component has collapsed | |
bsClass | string | 'panel' | Base CSS class and prefix for the component. Generally one should only change |
Name | Type | Default | Description |
---|---|---|---|
collapsible | boolean | false | A convenience prop that renders a Collapse component around the Body for situations when the parent Panel only contains a single Panel.Body child. renders:
|
bsClass | string | 'panel' | Base CSS class and prefix for the component. Generally one should only change |
Name | Type | Default | Description |
---|---|---|---|
bsClass | string | 'panel' | Base CSS class and prefix for the component. Generally one should only change |
Name | Type | Default | Description |
---|---|---|---|
accordion | boolean | false | |
activeKey | any | controlled by: onSelect , initial prop: defaultActiveKey When | |
onSelect | function | controls activeKey A callback fired when a child Panel collapse state changes. It's called with the next expanded | |
role | string | An HTML role attribute | |
generateChildId | function | (eventKey, type) => `${this.props.id}-${type}-${key}` | A function that takes an eventKey and type and returns a
unique id for each Panel heading and Panel Collapse. The function must be a pure function,
meaning it should always return the same id for the same set of inputs. The default
value requires that an The |
id | generatedId('PanelGroup') | HTML id attribute, required if no |