Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit e3bb701

Browse files
mgr34Matt Goo
authored and
Matt Goo
committed
feat(top-app-bar): TopAppBarFixedAdjust variants added (#524)
1 parent 461cce9 commit e3bb701

15 files changed

+83
-26
lines changed

packages/top-app-bar/FixedAdjust.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,42 @@ const FixedAdjust = (props) => {
2929
tag: Tag,
3030
children,
3131
className,
32+
dense,
33+
prominent,
34+
short,
3235
...otherProps
3336
} = props;
3437

38+
const base = 'mdc-top-app-bar';
39+
const suffix = '-fixed-adjust';
40+
const classes = classnames(className, {
41+
[base + '--short' + suffix]: short,
42+
[base + '--dense' + suffix]: dense && !prominent,
43+
[base + '--dense-prominent' + suffix]: dense && prominent,
44+
[base + '--prominent' + suffix]: !dense && prominent,
45+
[base + '-' + suffix]: !short && !dense && !prominent,
46+
});
47+
3548
return (
36-
<Tag
37-
className={classnames('mdc-top-app-bar--fixed-adjust', className)}
38-
{...otherProps}
39-
>
40-
{children}
41-
</Tag>
49+
<Tag className={classes} {...otherProps}>{children}</Tag>
4250
);
4351
};
4452

4553
FixedAdjust.propTypes = {
4654
tag: PropTypes.string,
4755
children: PropTypes.node.isRequired,
4856
className: PropTypes.string,
57+
dense: PropTypes.bool,
58+
prominent: PropTypes.bool,
59+
short: PropTypes.bool,
4960
};
5061

5162
FixedAdjust.defaultProps = {
5263
tag: 'main',
5364
className: '',
65+
dense: false,
66+
prominent: false,
67+
short: false,
5468
};
5569

5670
export default FixedAdjust;

packages/top-app-bar/README.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Use the `<TopAppBarFixedAdjust />` component to give your content top-padding, s
5252

5353
## Props
5454

55+
### TopAppBar
56+
5557
Prop Name | Type | Description
5658
--- | --- | ---
5759
actionItems | Array | Accepts an array of elements that should be rendered to the opposite side of the title. Note that a single action item should also be passed as an array.
@@ -62,10 +64,21 @@ short | Boolean | Enables short variant.
6264
shortCollapsed | Boolean | Enables short collapsed variant.
6365
prominent | Boolean | Enables prominent variant.
6466
fixed | Boolean | Enables fixed variant.
65-
dense | Boolean | Enables dense variant.
67+
dense | Boolean | Enables dense variant.
68+
69+
> NOTES: As per design guidelines, prominent and dense variants should not be used with short or short collapsed. Additionally, dense variants should only be used on desktop.
6670
67-
> NOTE: As per design guidelines, prominent and dense variants should not be used with short or short collapsed.
71+
### TopAppBarFixedAdjust
72+
73+
Prop Name | Type | Description
74+
--- | --- | ---
75+
className | String | Classes to be applied to the root element.
76+
dense | Boolean | Enables dense variant.
77+
prominent | Boolean | Enables prominent variant.
78+
short | Boolean | Enables short variant.
79+
tag | String | Customizes the TopAppBarFixedAdjust tag (defaults to `<main>`)
6880

81+
> NOTE: if not dense, prominent, or short will apply `mdc-top-app-bar--fixed-adjust`
6982
7083
## Icons
7184

packages/top-app-bar/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export default class TopAppBar extends React.Component {
143143
/* eslint-disable no-unused-vars */
144144
actionItems,
145145
className,
146+
dense,
146147
fixed,
147148
title,
148149
navigationIcon,

test/screenshot/golden.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
"text-field/fullWidth": "7c854723b1b4ce7e6df614f44f7b7845bef6098ac30714da5c5128bbd57eb51f",
2727
"text-field/outlined": "5d7fd01cfe503a0651daeb7acdf8163dd39a3b3f0ce3d872613bb15db30400ec",
2828
"top-app-bar/fixed": "7a2dd6318d62ac2eabd66f1b28100db7c15840ccb753660065fa9524db6435d6",
29-
"top-app-bar/prominent": "5a63148610f315001fbf80bd3f4b8ceb37691bd1a7ec81a33228bb3c2b364dae",
30-
"top-app-bar/short": "0e0e8a6c812e93910a540689bc6a962a1c8097c9f4e8b9ca65f35994bb380cfc",
31-
"top-app-bar/shortCollapsed": "5934b2260760fa716c461c55aadb5b2da2695a8eeb507cd4afe49e088e8a28c3",
29+
"top-app-bar/prominent": "2506ed2dd5f370c7bab69315d2daebd58b443d2b9e32bbaec762e40a8736309b",
30+
"top-app-bar/short": "4d9b86955a026da5bfebeb13389022b9360e779dbd6c23c8761e7bb78e14d6fd",
31+
"top-app-bar/shortCollapsed": "d53239e0f8cffd81010e30c5dc9563cc323b3945328dcc4460486e5d0d1131db",
3232
"top-app-bar/standard": "7a2dd6318d62ac2eabd66f1b28100db7c15840ccb753660065fa9524db6435d6",
3333
"top-app-bar/standardNoActionItems": "6d361edb994cafcc6ac720336d12ee7d7114745993e16abd6e6b00f078424ff2",
3434
"top-app-bar/standardWithNavigationIconElement": "95afd559c35dede805e4d4b51ad1fabd82b4117c358a8679e3166b88e059bf68",
35-
"top-app-bar/dense": "e8e288b997fa6cf112053e4ee62ed7c3d601c23a87eaece29348fc172dd5ebe4",
36-
"top-app-bar/prominentDense": "280995e7c3df950c72ea39f1673e359c9032ebdfa3ab0309831591b9f79227d6",
35+
"top-app-bar/dense": "e273e6c777f168248f5757c1f00a74206f4cce51c484d91cc7d36dc16de7d0de",
36+
"top-app-bar/prominentDense": "cc8af934f9187ffd8f250834ef7c73e5c53c5ace10126bb855f74878ba125149",
3737
"drawer/permanentBelowTopAppBar": "587ee2605c4b3e3f0408c6130b824b58587e05cedf9b964e14fc481b9de1e4c2",
3838
"drawer/dismissibleBelowTopAppBar": "a9bf24c0edd3dcc9167516ce3bdd146fd1a352c4f5b9ea76a1f9dad1ba61e0f8",
3939
"drawer/permanent": "6355905c2241b5e6fdddc2e25119a1cc3b062577375a88b59e6750c4b76e4561",

test/screenshot/top-app-bar/dense.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const TopAppBarDenseScreenshotTest = () => {
1616
/>}
1717
actionItems={[<MaterialIcon key='item' icon='bookmark' />]}
1818
/>
19-
<MainTopAppBarContent />
19+
<MainTopAppBarContent dense/>
2020
</div>
2121
);
2222
};

test/screenshot/top-app-bar/fixed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const TopAppBarFixedScreenshotTest = () => {
1515
/>}
1616
actionItems={[<MaterialIcon key='item' icon='bookmark' />]}
1717
/>
18-
<MainTopAppBarContent />
18+
<MainTopAppBarContent/>
1919
</div>
2020
);
2121
};

test/screenshot/top-app-bar/mainContent.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
22
import {TopAppBarFixedAdjust} from '../../../packages/top-app-bar';
33

4-
const MainTopAppBarContent = () => {
4+
const MainTopAppBarContent = (props) => {
55
return (
6-
<TopAppBarFixedAdjust>
6+
<TopAppBarFixedAdjust {...props}>
77
<h1>
88
{'Look at me I\'m a header'}
99
</h1>

test/screenshot/top-app-bar/prominent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const TopAppBarProminentScreenshotTest = () => {
1616
/>}
1717
actionItems={[<MaterialIcon key='item' icon='bookmark' />]}
1818
/>
19-
<MainTopAppBarContent />
19+
<MainTopAppBarContent prominent/>
2020
</div>
2121
);
2222
};

test/screenshot/top-app-bar/prominentDense.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const TopAppBarProminentDenseScreenshotTest = () => {
1717
/>}
1818
actionItems={[<MaterialIcon key='item' icon='bookmark' />]}
1919
/>
20-
<MainTopAppBarContent />
20+
<MainTopAppBarContent prominent dense/>
2121
</div>
2222
);
2323
};

test/screenshot/top-app-bar/short.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const TopAppBarShortScreenshotTest = () => {
1515
/>}
1616
actionItems={[<MaterialIcon key='item' icon='bookmark' />]}
1717
/>
18-
<MainTopAppBarContent />
18+
<MainTopAppBarContent short/>
1919
</div>
2020
);
2121
};

test/screenshot/top-app-bar/shortCollapsed.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ const TopAppBarShortCollapsedScreenshotTest = () => {
1010
shortCollapsed
1111
navigationIcon={<MaterialIcon
1212
icon='menu'
13-
onClick={() => console.log('click')}
13+
onClick={() => console.log('shortCollapsed click')}
1414
/>}
1515
/>
16-
<MainTopAppBarContent />
16+
<MainTopAppBarContent short/>
1717
</div>
1818
);
1919
};

test/screenshot/top-app-bar/standard.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ const TopAppBarStandardScreenshotTest = () => {
1010
title='Miami, FL'
1111
navigationIcon={<MaterialIcon
1212
icon='menu'
13-
onClick={() => console.log('click')}
13+
onClick={() => console.log('standard click')}
1414
/>}
1515
actionItems={[<MaterialIcon key='item' icon='bookmark' />]}
1616
/>
17-
<MainTopAppBarContent />
17+
<MainTopAppBarContent/>
1818
</div>
1919
);
2020
};

test/screenshot/top-app-bar/standardNoActionItems.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const TopAppBarStandardNoActionItemsScreenshotTest = () => {
1313
onClick={() => console.log('click')}
1414
/>}
1515
/>
16-
<MainTopAppBarContent />
16+
<MainTopAppBarContent/>
1717
</div>
1818
);
1919
};

test/screenshot/top-app-bar/standardWithNavigationIconElement.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ const TopAppBarStandardWithNavigationIconElementScreenshotTest = () => {
3535
<div className='top-app-bar-container'>
3636
<TopAppBar
3737
title='Miami, FL'
38+
dense={false}
3839
navigationIcon={<NavigationIconWithRipple unbounded />}
3940
actionItems={[<MaterialIcon key='item' icon='bookmark' />]}
4041
/>
41-
<MainTopAppBarContent />
42+
<MainTopAppBarContent/>
4243
</div>
4344
);
4445
};

test/unit/top-app-bar/FixedAdjust.test.js

+28
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,31 @@ test('renders as a different tag name when passed props.tag', () => {
2525
assert.equal(wrapper.find('main').length, 0);
2626
assert.equal(wrapper.type(), 'div');
2727
});
28+
29+
test('has correct dense class', () => {
30+
const wrapper = shallow(<TopAppBarFixedAdjust dense>
31+
hello
32+
</TopAppBarFixedAdjust>);
33+
assert.isTrue(wrapper.hasClass('mdc-top-app-bar--dense-fixed-adjust'));
34+
});
35+
36+
test('has correct dense prominent class', () => {
37+
const wrapper = shallow(<TopAppBarFixedAdjust dense prominent>
38+
hello
39+
</TopAppBarFixedAdjust>);
40+
assert.isTrue(wrapper.hasClass('mdc-top-app-bar--dense-prominent-fixed-adjust'));
41+
});
42+
43+
test('has correct prominent class', () => {
44+
const wrapper = shallow(<TopAppBarFixedAdjust prominent>
45+
hello
46+
</TopAppBarFixedAdjust>);
47+
assert.isTrue(wrapper.hasClass('mdc-top-app-bar--prominent-fixed-adjust'));
48+
});
49+
50+
test('has correct short class', () => {
51+
const wrapper = shallow(<TopAppBarFixedAdjust short>
52+
hello
53+
</TopAppBarFixedAdjust>);
54+
assert.isTrue(wrapper.hasClass('mdc-top-app-bar--short-fixed-adjust'));
55+
});

0 commit comments

Comments
 (0)