Skip to content

Commit f633d73

Browse files
committed
Enhance Toolbar and Toolbar Group with dense and nowrap options, now available for both
1 parent aad877f commit f633d73

File tree

12 files changed

+66
-27
lines changed

12 files changed

+66
-27
lines changed

src/demo/pages/DemoContainer.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,10 @@ class DemoContainer extends React.Component {
789789
/>
790790
<h3 id="layout-components-toolbar" className="typography-size-4 mb-6">Toolbar</h3>
791791
<Documentation
792-
name="Example layout with group and space-between justification"
792+
name="Example layout with not-wrapping dense group and space-between justification"
793793
component={(
794794
<Toolbar justify="space-between">
795-
<ToolbarGroup>
795+
<ToolbarGroup dense nowrap>
796796
<ToolbarItem>
797797
<Placeholder text="grouped item 1" />
798798
</ToolbarItem>
@@ -813,9 +813,9 @@ class DemoContainer extends React.Component {
813813
)}
814814
/>
815815
<Documentation
816-
name="Toolbar with disabled wrapping"
816+
name="Dense toolbar with disabled wrapping (groups still wrap)"
817817
component={(
818-
<Toolbar justify="space-between" nowrap>
818+
<Toolbar justify="space-between" dense nowrap>
819819
<ToolbarGroup>
820820
<ToolbarItem>
821821
<Placeholder text="grouped item 1" />

src/lib/components/layout/Toolbar/Toolbar.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const Toolbar = (props) => {
66
const {
77
align,
88
children,
9+
dense,
910
justify,
1011
nowrap,
1112
} = props;
@@ -46,6 +47,7 @@ const Toolbar = (props) => {
4647
<div
4748
className={[
4849
styles.toolbar,
50+
dense ? styles.isDense : null,
4951
nowrap ? styles.isNowrap : null,
5052
alignClass(align),
5153
justifyClass(justify),
@@ -58,13 +60,15 @@ const Toolbar = (props) => {
5860

5961
Toolbar.defaultProps = {
6062
align: 'top',
63+
dense: false,
6164
justify: 'start',
6265
nowrap: false,
6366
};
6467

6568
Toolbar.propTypes = {
6669
align: PropTypes.oneOf(['top', 'middle', 'bottom', 'baseline']),
6770
children: PropTypes.node.isRequired,
71+
dense: PropTypes.bool,
6872
justify: PropTypes.oneOf(['start', 'center', 'end', 'space-between']),
6973
nowrap: PropTypes.bool,
7074
};

src/lib/components/layout/Toolbar/Toolbar.scss

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@
1515
margin: $toolbar-spacing;
1616
}
1717

18-
.isNowrap {
19-
flex-wrap: nowrap;
20-
}
21-
22-
.isNowrap > .item {
23-
flex: 0 1 auto;
24-
}
25-
2618
.isAlignedToTop {
2719
align-items: flex-start;
2820
}
@@ -54,3 +46,28 @@
5446
.isJustifiedToSpaceBetween {
5547
justify-content: space-between;
5648
}
49+
50+
.isNowrap {
51+
flex-wrap: nowrap;
52+
}
53+
54+
.isNowrap > .item {
55+
flex: 0 1 auto;
56+
}
57+
58+
.isDense {
59+
margin: calc(-1 * #{$toolbar-spacing-dense});
60+
}
61+
62+
.isDense .item {
63+
margin: $toolbar-spacing-dense;
64+
}
65+
66+
.isDense > .isDense {
67+
margin: 0;
68+
}
69+
70+
.toolbar:not(.isDense) > .isDense,
71+
.group:not(.isDense) > .isDense {
72+
margin: $toolbar-spacing-dense;
73+
}

src/lib/components/layout/Toolbar/ToolbarGroup.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const ToolbarGroup = (props) => {
66
const {
77
align,
88
children,
9+
dense,
10+
nowrap,
911
} = props;
1012

1113
const alignClass = (value) => {
@@ -28,6 +30,8 @@ const ToolbarGroup = (props) => {
2830
<div
2931
className={[
3032
styles.group,
33+
dense ? styles.isDense : null,
34+
nowrap ? styles.isNowrap : null,
3135
alignClass(align),
3236
].join(' ')}
3337
>
@@ -38,11 +42,15 @@ const ToolbarGroup = (props) => {
3842

3943
ToolbarGroup.defaultProps = {
4044
align: 'top',
45+
dense: false,
46+
nowrap: false,
4147
};
4248

4349
ToolbarGroup.propTypes = {
4450
align: PropTypes.oneOf(['top', 'middle', 'bottom', 'baseline']),
4551
children: PropTypes.node.isRequired,
52+
dense: PropTypes.bool,
53+
nowrap: PropTypes.bool,
4654
};
4755

4856
export default ToolbarGroup;

src/lib/components/layout/Toolbar/__tests__/Toolbar.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('rendering', () => {
4646

4747
it('renders correctly with group and all props', () => {
4848
const tree = shallow((
49-
<Toolbar align="middle" justify="space-between" nowrap>
49+
<Toolbar align="middle" justify="space-between" dense nowrap>
5050
<ToolbarItem>item 1</ToolbarItem>
5151
<ToolbarItem>item 2</ToolbarItem>
5252
<ToolbarItem>item 3</ToolbarItem>

src/lib/components/layout/Toolbar/__tests__/ToolbarGroup.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('rendering', () => {
2828

2929
it('renders correctly with all props', () => {
3030
const tree = shallow((
31-
<ToolbarGroup align="middle">
31+
<ToolbarGroup align="middle" dense nowrap>
3232
<ToolbarItem>item</ToolbarItem>
3333
</ToolbarGroup>
3434
));

src/lib/components/layout/Toolbar/__tests__/__snapshots__/Toolbar.test.jsx.snap

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`rendering renders correctly with a single child 1`] = `
44
<div
5-
className="toolbar isAlignedToTop isJustifiedToStart"
5+
className="toolbar isAlignedToTop isJustifiedToStart"
66
>
77
<ToolbarItem>
88
item
@@ -12,7 +12,7 @@ exports[`rendering renders correctly with a single child 1`] = `
1212

1313
exports[`rendering renders correctly with group and all props 1`] = `
1414
<div
15-
className="toolbar isNowrap isAlignedToMiddle isJustifiedToSpaceBetween"
15+
className="toolbar isDense isNowrap isAlignedToMiddle isJustifiedToSpaceBetween"
1616
>
1717
<ToolbarItem>
1818
item 1
@@ -25,6 +25,8 @@ exports[`rendering renders correctly with group and all props 1`] = `
2525
</ToolbarItem>
2626
<ToolbarGroup
2727
align="top"
28+
dense={false}
29+
nowrap={false}
2830
>
2931
<ToolbarItem>
3032
group item 1
@@ -41,7 +43,7 @@ exports[`rendering renders correctly with group and all props 1`] = `
4143

4244
exports[`rendering renders correctly with multiple children 1`] = `
4345
<div
44-
className="toolbar isAlignedToTop isJustifiedToStart"
46+
className="toolbar isAlignedToTop isJustifiedToStart"
4547
>
4648
<ToolbarItem>
4749
item 1
@@ -57,7 +59,7 @@ exports[`rendering renders correctly with multiple children 1`] = `
5759

5860
exports[`rendering renders correctly with multiple children and groups 1`] = `
5961
<div
60-
className="toolbar isAlignedToTop isJustifiedToStart"
62+
className="toolbar isAlignedToTop isJustifiedToStart"
6163
>
6264
<ToolbarItem>
6365
item 1
@@ -70,6 +72,8 @@ exports[`rendering renders correctly with multiple children and groups 1`] = `
7072
</ToolbarItem>
7173
<ToolbarGroup
7274
align="top"
75+
dense={false}
76+
nowrap={false}
7377
>
7478
<ToolbarItem>
7579
group item 1

src/lib/components/layout/Toolbar/__tests__/__snapshots__/ToolbarGroup.test.jsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`rendering renders correctly with a single child 1`] = `
44
<div
5-
className="group isAlignedToTop"
5+
className="group isAlignedToTop"
66
>
77
<ToolbarItem>
88
item
@@ -12,7 +12,7 @@ exports[`rendering renders correctly with a single child 1`] = `
1212

1313
exports[`rendering renders correctly with all props 1`] = `
1414
<div
15-
className="group isAlignedToMiddle"
15+
className="group isDense isNowrap isAlignedToMiddle"
1616
>
1717
<ToolbarItem>
1818
item
@@ -22,7 +22,7 @@ exports[`rendering renders correctly with all props 1`] = `
2222

2323
exports[`rendering renders correctly with multiple children 1`] = `
2424
<div
25-
className="group isAlignedToTop"
25+
className="group isAlignedToTop"
2626
>
2727
<ToolbarItem>
2828
item 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
$toolbar-spacing: var(--rui-toolbar-spacing);
2+
$toolbar-spacing-dense: var(--rui-toolbar-spacing-dense);

src/lib/components/ui/Modal/Modal.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class Modal extends React.Component {
107107
{this.props.children}
108108
</div>
109109
<div className={styles.footer}>
110-
<Toolbar>
110+
<Toolbar dense>
111111
{this.props.actions.map((action) => (
112112
<ToolbarItem key={action.label}>
113113
<Button

0 commit comments

Comments
 (0)