Skip to content
This repository was archived by the owner on Jun 9, 2024. It is now read-only.

Commit 6d8ed53

Browse files
committed
feat(ControlGroup): add ControlGroup component
1 parent 42cc12a commit 6d8ed53

File tree

5 files changed

+183
-0
lines changed

5 files changed

+183
-0
lines changed

__tests__/ControlGroup.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react';
2+
import { renderToStaticMarkup } from 'react-dom/server';
3+
import { ControlGroup } from '../src/index';
4+
5+
describe('<ControlGroup />', () => {
6+
it('renders basic <ControlGroup />', () => {
7+
expect(renderToStaticMarkup(<ControlGroup />)).toEqual(
8+
'<div class="pt-control-group"></div>'
9+
);
10+
});
11+
12+
it('renders basic <ControlGroup /> with props', () => {
13+
expect(renderToStaticMarkup(<ControlGroup fill />)).toEqual(
14+
'<div class="pt-control-group pt-fill"></div>'
15+
);
16+
17+
expect(renderToStaticMarkup(<ControlGroup vertical />)).toEqual(
18+
'<div class="pt-control-group pt-vertical"></div>'
19+
);
20+
21+
expect(
22+
renderToStaticMarkup(<ControlGroup fill className="css-extra-class" />)
23+
).toEqual('<div class="pt-control-group pt-fill css-extra-class"></div>');
24+
});
25+
26+
it('renders basic <ControlGroup /> with children', () => {
27+
expect(
28+
renderToStaticMarkup(<ControlGroup>Children Content</ControlGroup>)
29+
).toEqual('<div class="pt-control-group">Children Content</div>');
30+
});
31+
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import classnames from 'classnames';
4+
5+
const ControlGroup = ({ children, fill, vertical, className, ...rest }) => {
6+
return (
7+
<div
8+
className={classnames(
9+
'pt-control-group',
10+
{ 'pt-fill': fill },
11+
{ 'pt-vertical': vertical },
12+
className
13+
)}
14+
{...rest}
15+
>
16+
{children}
17+
</div>
18+
);
19+
};
20+
21+
/**
22+
* ControlGroup property types.
23+
*/
24+
ControlGroup.propTypes = {
25+
/**
26+
* Primary content.
27+
*/
28+
children: PropTypes.node,
29+
30+
/**
31+
* Additional CSS classes.
32+
*/
33+
className: PropTypes.string,
34+
35+
/**
36+
* Make all elements expand equally.
37+
*/
38+
fill: PropTypes.bool,
39+
40+
/**
41+
* Create a vertical control group.
42+
*/
43+
vertical: PropTypes.bool,
44+
};
45+
46+
/**
47+
* ControlGroup default properties.
48+
*/
49+
ControlGroup.defaultProps = {
50+
children: null,
51+
className: '',
52+
fill: false,
53+
vertical: false,
54+
};
55+
56+
export default ControlGroup;
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
Control group renders several distinct controls as one unit, squaring the borders between them.
2+
3+
It supports any number of `Button`, `InputGroup`, `input` and `select` elements as direct children.
4+
5+
> Note that `ControlGroup` does not cascade any modifiers to its children. For example, each child must be marked individually as `.pt-large` for uniform large appearance.
6+
7+
```js static
8+
import { ControlGroup } from 'blueprint-components';
9+
```
10+
11+
Additionally:
12+
13+
```js static
14+
import { Button, Classes, Icon, InputGroup, Intent } from '@blueprintjs/core';
15+
```
16+
17+
```jsx
18+
<ControlGroup>
19+
<Button text="filter" iconName="filter" />
20+
<input type="text" className="pt-input" placeholder="Find filters..." />
21+
</ControlGroup>
22+
```
23+
24+
```jsx
25+
<ControlGroup>
26+
<div className="pt-select">
27+
<select onChange={() => {}}>
28+
<option>Filter...</option>
29+
<option value="1">Issues</option>
30+
<option value="2">Requests</option>
31+
<option value="3">Projects</option>
32+
</select>
33+
</div>
34+
<InputGroup leftIconName="search" placeholder="from:ggray to:allorca" />
35+
</ControlGroup>
36+
```
37+
38+
```jsx
39+
<ControlGroup>
40+
<InputGroup
41+
leftIconName="people"
42+
placeholder="Find collaborators..."
43+
rightElement={<Button text="can view" rightIconName="caret-down" className="pt-minimal" intent={Intent.PRIMARY} />}
44+
/>
45+
<Button intent={Intent.PRIMARY} text="Add" />
46+
</ControlGroup>
47+
```
48+
49+
### Responsive Control Group
50+
51+
To make all elements expand equally to fill the available space, just add the optional `fill` prop.
52+
53+
Then add `Classes.FIXED` or `pt-fixed` CSS class to individual elements to revert them to their original default sizes.
54+
55+
```html static
56+
<ControlGroup fill>
57+
...
58+
</ControlGroup>
59+
```
60+
61+
```jsx
62+
<ControlGroup fill>
63+
<Button className={Classes.FIXED} iconName="minus" />
64+
<input type="text" placeholder="Enter a value..." className="pt-input" />
65+
<Button className={Classes.FIXED} iconName="plus" />
66+
</ControlGroup>
67+
```
68+
69+
> Note: In the example below, `ControlGroup` does not have `fill` prop, but instead `InputGroup` has `className={Classes.FILL}`.
70+
71+
```jsx
72+
<ControlGroup>
73+
<InputGroup className={Classes.FILL} leftIconName="people" placeholder="Find collaborators..." />
74+
<Button intent={Intent.PRIMARY} text="Add" />
75+
</ControlGroup>
76+
```
77+
78+
### Vertical Control Group
79+
80+
To create a vertical control group, just add optional `vertical` prop:
81+
82+
```html static
83+
<ControlGroup vertical>
84+
...
85+
</ControlGroup>
86+
```
87+
88+
```jsx
89+
<ControlGroup vertical style={{width: 300}}>
90+
<InputGroup className={Classes.LARGE} leftIconName="person" placeholder="Username" />
91+
<InputGroup className={Classes.LARGE} leftIconName="lock" placeholder="Password" />
92+
<Button className={Classes.LARGE} intent={Intent.PRIMARY} text="Login" />
93+
</ControlGroup>
94+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as ControlGroup } from './ControlGroup';

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export { ButtonGroup } from './components/ButtonGroup';
22
export { Callout } from './components/Callout';
33
export { Card } from './components/Card';
4+
export { ControlGroup } from './components/ControlGroup';
45
export { Navbar } from './components/Navbar';
56
export { NavbarDivider } from './components/NavbarDivider';
67
export { NavbarGroup } from './components/NavbarGroup';

0 commit comments

Comments
 (0)