Skip to content

Commit

Permalink
pass renderer as props for cell content
Browse files Browse the repository at this point in the history
  • Loading branch information
pKalaga committed May 31, 2023
1 parent 17ca96c commit ecb9646
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "add onRenderCellContent to override cell internals",
"packageName": "@fluentui/react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const ColorPickerGridCellBase: React.FunctionComponent<IColorPickerGridCe
});

// Render the core of a color cell
const onRenderColorOption = (colorOption: IColorCellProps): JSX.Element => {
const renderColorOption = (colorOption: IColorCellProps): JSX.Element => {
const svgClassName = classNames.svg;

// Build an SVG for the cell with the given shape and color properties
Expand All @@ -119,6 +119,11 @@ export const ColorPickerGridCellBase: React.FunctionComponent<IColorPickerGridCe
);
};

const onRenderItem = (option: IColorCellProps): JSX.Element => {
const { onRenderCellContent = renderColorOption } = props;
return onRenderCellContent(option, renderColorOption) as JSX.Element;
};

const cellSemantics = isRadio
? {
role: 'radio',
Expand All @@ -138,7 +143,7 @@ export const ColorPickerGridCellBase: React.FunctionComponent<IColorPickerGridCe
disabled={disabled}
{...cellSemantics}
// eslint-disable-next-line react/jsx-no-bind
onRenderItem={onRenderColorOption}
onRenderItem={onRenderItem}
onClick={onClick}
onHover={onHover}
onFocus={onFocus}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import type { IStyle, ITheme } from '../../Styling';
import type { IStyleFunctionOrObject } from '../../Utilities';
import type { IRenderFunction, IStyleFunctionOrObject } from '../../Utilities';

/**
* {@docCategory SwatchColorPicker}
Expand Down Expand Up @@ -113,6 +113,11 @@ export interface IColorPickerGridCellProps {
onWheel?: (ev: React.MouseEvent<HTMLButtonElement>) => void;

onKeyDown?: (ev: React.KeyboardEvent<HTMLButtonElement>) => void;

/**
* Custom content render function for rendering core of cell
*/
onRenderCellContent?: IRenderFunction<IColorCellProps>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const SwatchColorPickerBase: React.FunctionComponent<ISwatchColorPickerPr
cellHeight,
cellWidth,
cellBorderWidth,
onRenderColorCellContent,
} = props;

/**
Expand Down Expand Up @@ -321,6 +322,7 @@ export const SwatchColorPickerBase: React.FunctionComponent<ISwatchColorPickerPr
onMouseLeave={onMouseLeave}
onWheel={setNavigationTimeout}
onKeyDown={onKeyDown}
onRenderCellContent={onRenderColorCellContent}
height={cellHeight}
width={cellWidth}
borderWidth={cellBorderWidth}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ export interface ISwatchColorPickerProps extends React.RefAttributes<HTMLElement
*/
onRenderColorCell?: IRenderFunction<IColorCellProps>;

/**
* Custom render function for button/cell content area
*/
onRenderColorCellContent?: IRenderFunction<IColorCellProps>;

/**
* Whether the control is disabled.
*/
Expand Down

0 comments on commit ecb9646

Please sign in to comment.