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

Commit

Permalink
feat(Pivot): Support the ability to specify Pivot item sizes. (#529)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dreadwail authored Sep 12, 2018
1 parent 719c776 commit 5a8f431
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 3 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/components/Pivot/Pivot.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ const pivotItems = [{ text: 'DISCOVERY', key: '0' }, { text: 'ALL', key: '1' },
<Pivot onChange={action('onChange')} pivotItems={pivotItems} />;
```

With large pivot items:

```js { "props": { "data-description": "with large pivot items" } }
const { PivotLinkSize } = require('./Pivot');

const pivotItems = [
{ text: 'DISCOVERY', key: '0' },
{ text: 'ALL', key: '1' },
{ text: 'FOLLOWING', key: '2' }
];

<Pivot onChange={action('onChange')} pivotItems={pivotItems} linkSize={PivotLinkSize.large} />
```

With Dark theme:

```js { "props": { "data-description": "with dark background" } }
Expand Down
22 changes: 20 additions & 2 deletions src/components/Pivot/Pivot.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. */
import * as React from 'react';
import { shallow, ShallowWrapper } from 'enzyme';
import Pivot, { PivotProps, PivotItem } from './index';
import Pivot, { PivotProps, PivotItem, PivotLinkSize } from './index';

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

return shallow<PivotProps>(<Pivot selectedKey="1" pivotItems={pivotItems} onChange={jest.fn()} {...overrides} />);
const props: PivotProps = {
selectedKey: '1',
pivotItems,
onChange: jest.fn(),
linkSize: PivotLinkSize.normal,
...overrides,
};

return shallow<PivotProps>(<Pivot {...props} />);
};

describe('with default options', () => {
Expand Down Expand Up @@ -82,4 +90,14 @@ describe('<Pivot />', () => {
expect(component).toMatchSnapshot();
});
});

describe('with large pivot items', () => {
beforeEach(() => {
component = getComponent({ linkSize: PivotLinkSize.large });
});

it('matches its snapshot', () => {
expect(component).toMatchSnapshot();
});
});
});
9 changes: 8 additions & 1 deletion src/components/Pivot/Pivot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import '../../yamui';
import * as React from 'react';
import { BaseComponentProps } from '../../util/BaseComponent/props';
import { Pivot as FabricPivot, PivotItem as FabricPivotItem } from 'office-ui-fabric-react/lib/Pivot';
import { Pivot as FabricPivot, PivotItem as FabricPivotItem, PivotLinkSize } from 'office-ui-fabric-react/lib/Pivot';
import { join } from '../../util/classNames';

import './Pivot.css';
Expand All @@ -14,6 +14,8 @@ export interface PivotItem {
itemCount?: number;
}

export { PivotLinkSize };

export interface PivotProps extends BaseComponentProps {
/**
* Indicates whether the text on the tabs will be rendered on white colors
Expand All @@ -28,6 +30,10 @@ export interface PivotProps extends BaseComponentProps {
* Contains the information of the pivot items that will be rendered within this component.
*/
pivotItems: PivotItem[];
/**
* Sets the size of the individual pivot items.
*/
linkSize?: PivotLinkSize;
/**
* Callback that will be executed every time there is a change in the selected pivot item.
*/
Expand All @@ -42,6 +48,7 @@ export default class Pivot extends React.Component<PivotProps> {
selectedKey={this.props.selectedKey}
onLinkClick={this.onLinkClick}
headersOnly={true}
linkSize={this.props.linkSize}
>
{this.getFabricPivotItems()}
</FabricPivot>
Expand Down
30 changes: 30 additions & 0 deletions src/components/Pivot/__snapshots__/Pivot.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ exports[`<Pivot /> when given a className matches its snapshot 1`] = `
<StyledPivotBase
className="y-pivot Test"
headersOnly={true}
linkSize={0}
onLinkClick={[Function]}
selectedKey="1"
>
Expand All @@ -46,6 +47,34 @@ exports[`<Pivot /> with default options matches its snapshot 1`] = `
<StyledPivotBase
className="y-pivot"
headersOnly={true}
linkSize={0}
onLinkClick={[Function]}
selectedKey="1"
>
<PivotItem
ariaLabel="test"
headerText="Tab 1"
itemKey="1"
key="1"
/>
<PivotItem
headerText="Tab 2"
itemKey="2"
key="2"
/>
<PivotItem
headerText="Tab 3"
itemKey="3"
key="3"
/>
</StyledPivotBase>
`;

exports[`<Pivot /> with large pivot items matches its snapshot 1`] = `
<StyledPivotBase
className="y-pivot"
headersOnly={true}
linkSize={1}
onLinkClick={[Function]}
selectedKey="1"
>
Expand All @@ -72,6 +101,7 @@ exports[`<Pivot /> with overDarkBackground as true matches its snapshot 1`] = `
<StyledPivotBase
className="y-pivot y-pivot__overDarkBackground"
headersOnly={true}
linkSize={0}
onLinkClick={[Function]}
selectedKey="1"
>
Expand Down

0 comments on commit 5a8f431

Please sign in to comment.