Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 5a8f431

Browse files
authored
feat(Pivot): Support the ability to specify Pivot item sizes. (#529)
Fabric supports the ability to customize the size of Pivot items. Previously we were not supporting that. This change allows pivot items in YamUI to have the size prop that Fabric accepts.
1 parent 719c776 commit 5a8f431

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed
Loading

src/components/Pivot/Pivot.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ const pivotItems = [{ text: 'DISCOVERY', key: '0' }, { text: 'ALL', key: '1' },
88
<Pivot onChange={action('onChange')} pivotItems={pivotItems} />;
99
```
1010

11+
With large pivot items:
12+
13+
```js { "props": { "data-description": "with large pivot items" } }
14+
const { PivotLinkSize } = require('./Pivot');
15+
16+
const pivotItems = [
17+
{ text: 'DISCOVERY', key: '0' },
18+
{ text: 'ALL', key: '1' },
19+
{ text: 'FOLLOWING', key: '2' }
20+
];
21+
22+
<Pivot onChange={action('onChange')} pivotItems={pivotItems} linkSize={PivotLinkSize.large} />
23+
```
24+
1125
With Dark theme:
1226

1327
```js { "props": { "data-description": "with dark background" } }

src/components/Pivot/Pivot.test.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. */
22
import * as React from 'react';
33
import { shallow, ShallowWrapper } from 'enzyme';
4-
import Pivot, { PivotProps, PivotItem } from './index';
4+
import Pivot, { PivotProps, PivotItem, PivotLinkSize } from './index';
55

66
describe('<Pivot />', () => {
77
let component: ShallowWrapper<PivotProps>;
@@ -14,7 +14,15 @@ describe('<Pivot />', () => {
1414
{ key: '3', text: 'Tab 3' },
1515
];
1616

17-
return shallow<PivotProps>(<Pivot selectedKey="1" pivotItems={pivotItems} onChange={jest.fn()} {...overrides} />);
17+
const props: PivotProps = {
18+
selectedKey: '1',
19+
pivotItems,
20+
onChange: jest.fn(),
21+
linkSize: PivotLinkSize.normal,
22+
...overrides,
23+
};
24+
25+
return shallow<PivotProps>(<Pivot {...props} />);
1826
};
1927

2028
describe('with default options', () => {
@@ -82,4 +90,14 @@ describe('<Pivot />', () => {
8290
expect(component).toMatchSnapshot();
8391
});
8492
});
93+
94+
describe('with large pivot items', () => {
95+
beforeEach(() => {
96+
component = getComponent({ linkSize: PivotLinkSize.large });
97+
});
98+
99+
it('matches its snapshot', () => {
100+
expect(component).toMatchSnapshot();
101+
});
102+
});
85103
});

src/components/Pivot/Pivot.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import '../../yamui';
33
import * as React from 'react';
44
import { BaseComponentProps } from '../../util/BaseComponent/props';
5-
import { Pivot as FabricPivot, PivotItem as FabricPivotItem } from 'office-ui-fabric-react/lib/Pivot';
5+
import { Pivot as FabricPivot, PivotItem as FabricPivotItem, PivotLinkSize } from 'office-ui-fabric-react/lib/Pivot';
66
import { join } from '../../util/classNames';
77

88
import './Pivot.css';
@@ -14,6 +14,8 @@ export interface PivotItem {
1414
itemCount?: number;
1515
}
1616

17+
export { PivotLinkSize };
18+
1719
export interface PivotProps extends BaseComponentProps {
1820
/**
1921
* Indicates whether the text on the tabs will be rendered on white colors
@@ -28,6 +30,10 @@ export interface PivotProps extends BaseComponentProps {
2830
* Contains the information of the pivot items that will be rendered within this component.
2931
*/
3032
pivotItems: PivotItem[];
33+
/**
34+
* Sets the size of the individual pivot items.
35+
*/
36+
linkSize?: PivotLinkSize;
3137
/**
3238
* Callback that will be executed every time there is a change in the selected pivot item.
3339
*/
@@ -42,6 +48,7 @@ export default class Pivot extends React.Component<PivotProps> {
4248
selectedKey={this.props.selectedKey}
4349
onLinkClick={this.onLinkClick}
4450
headersOnly={true}
51+
linkSize={this.props.linkSize}
4552
>
4653
{this.getFabricPivotItems()}
4754
</FabricPivot>

src/components/Pivot/__snapshots__/Pivot.test.tsx.snap

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ exports[`<Pivot /> when given a className matches its snapshot 1`] = `
2020
<StyledPivotBase
2121
className="y-pivot Test"
2222
headersOnly={true}
23+
linkSize={0}
2324
onLinkClick={[Function]}
2425
selectedKey="1"
2526
>
@@ -46,6 +47,34 @@ exports[`<Pivot /> with default options matches its snapshot 1`] = `
4647
<StyledPivotBase
4748
className="y-pivot"
4849
headersOnly={true}
50+
linkSize={0}
51+
onLinkClick={[Function]}
52+
selectedKey="1"
53+
>
54+
<PivotItem
55+
ariaLabel="test"
56+
headerText="Tab 1"
57+
itemKey="1"
58+
key="1"
59+
/>
60+
<PivotItem
61+
headerText="Tab 2"
62+
itemKey="2"
63+
key="2"
64+
/>
65+
<PivotItem
66+
headerText="Tab 3"
67+
itemKey="3"
68+
key="3"
69+
/>
70+
</StyledPivotBase>
71+
`;
72+
73+
exports[`<Pivot /> with large pivot items matches its snapshot 1`] = `
74+
<StyledPivotBase
75+
className="y-pivot"
76+
headersOnly={true}
77+
linkSize={1}
4978
onLinkClick={[Function]}
5079
selectedKey="1"
5180
>
@@ -72,6 +101,7 @@ exports[`<Pivot /> with overDarkBackground as true matches its snapshot 1`] = `
72101
<StyledPivotBase
73102
className="y-pivot y-pivot__overDarkBackground"
74103
headersOnly={true}
104+
linkSize={0}
75105
onLinkClick={[Function]}
76106
selectedKey="1"
77107
>

0 commit comments

Comments
 (0)