Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add post reduce grow callbacks #3752

Merged
merged 2 commits into from
Jan 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@uifabric/experiments",
"comment": "Add callbacks for onDataReduced and onDataGrown",
"type": "minor"
}
],
"packageName": "@uifabric/experiments",
"email": "staylo@microsoft.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class CommandBarBase extends BaseComponent<ICommandBarProps, {}> implemen

@autobind
private _onReduceData(data: ICommandBarData): ICommandBarData | undefined {
const { endAligned } = this.props;
const { endAligned, onDataReduced } = this.props;
let { primaryItems, overflowItems, cacheKey, farItems } = data;

// Use first item if endAligned, otherwise use last item
Expand All @@ -168,6 +168,10 @@ export class CommandBarBase extends BaseComponent<ICommandBarProps, {}> implemen
primaryItems = endAligned ? primaryItems.slice(1) : primaryItems.slice(0, -1);
cacheKey = this._computeCacheKey(primaryItems, farItems!, !!overflowItems.length);

if (onDataReduced) {
onDataReduced(movedItem);
}

return { ...data, primaryItems, overflowItems, cacheKey };
}

Expand All @@ -176,7 +180,7 @@ export class CommandBarBase extends BaseComponent<ICommandBarProps, {}> implemen

@autobind
private _onGrowData(data: ICommandBarData): ICommandBarData | undefined {
const { endAligned } = this.props;
const { endAligned, onDataGrown } = this.props;
let { primaryItems, overflowItems, cacheKey, minimumOverflowItems, farItems } = data;
const movedItem = overflowItems[0];

Expand All @@ -189,6 +193,10 @@ export class CommandBarBase extends BaseComponent<ICommandBarProps, {}> implemen
primaryItems = endAligned ? [movedItem, ...primaryItems] : [...primaryItems, movedItem];
cacheKey = this._computeCacheKey(primaryItems, farItems!, !!overflowItems.length);

if (onDataGrown) {
onDataGrown(movedItem);
}

return { ...data, primaryItems, overflowItems, cacheKey };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ export interface ICommandBarProps extends React.HTMLAttributes<HTMLDivElement> {
*/
onGrowData?: (data: ICommandBarData) => ICommandBarData;

/**
* Function callback invoked when data has been reduced.
*/
onDataReduced?: (movedItem: ICommandBarItemProps) => void;

/**
* Function callback invoked when data has been grown.
*/
onDataGrown?: (movedItem: ICommandBarItemProps) => void;

/**
* Additional css class to apply to the command bar
* @defaultvalue undefined
Expand Down