Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2369 from teamleadercrm/TIDAL-2601-allow-more-spl…
Browse files Browse the repository at this point in the history
…itbutton-control

Allow more control over SplitButton component
  • Loading branch information
lorgan3 authored Sep 19, 2022
2 parents adbbdd6 + bf07509 commit 3de534d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Added

- `SplitButton`: `popoverProps` prop which allows overwriting the z-index, direction and height of the popover. ([@lorgan3](https://github.com/lorgan3)) in [#2369](https://github.com/teamleadercrm/ui/pull/2369))

### Changed

### Deprecated
Expand Down
11 changes: 11 additions & 0 deletions src/components/splitButton/SplitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ interface SplitButtonProps extends Omit<BoxProps, 'children' | 'size'> {
onSecondaryButtonClick?: (event: MouseEvent<HTMLElement>) => void;
/** If true, component will be disabled. */
disabled?: boolean;
/** Overwrites for the popover */
popoverProps?: {
/** The preferred direction in which the Popover is rendered, is overridden with the opposite or adjacent direction if the Popover cannot be entirely displayed in the current direction. */
direction?: 'north' | 'south';
/** If true, the Popover stretches to fit its content vertically */
fullHeight?: boolean;
/** The z-index of the Popover */
zIndex?: number;
};
}

const SplitButton: GenericComponent<SplitButtonProps> = ({
Expand All @@ -32,6 +41,7 @@ const SplitButton: GenericComponent<SplitButtonProps> = ({
onButtonClick,
onSecondaryButtonClick,
disabled,
popoverProps,
...others
}) => {
const [popoverActive, setPopoverActive] = useState<boolean>(false);
Expand Down Expand Up @@ -90,6 +100,7 @@ const SplitButton: GenericComponent<SplitButtonProps> = ({
onEscKeyDown={handleCloseClick}
onOverlayClick={handleCloseClick}
position="start"
{...popoverProps}
>
<Menu>
{React.Children.map(children, (child) => {
Expand Down
7 changes: 7 additions & 0 deletions src/components/splitButton/splitButton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ export const DefaultStory: ComponentStory<typeof SplitButton> = (args) => (
<MenuItem onClick={handleMenuItemClick} label="Via Marketplace integrations" />
</SplitButton>
);

export const WithPopoverOverrides: ComponentStory<typeof SplitButton> = (args) => (
<SplitButton {...args} popoverProps={{ direction: 'north' }} onButtonClick={handleButtonClick}>
<MenuItem onClick={handleMenuItemClick} label="Main action" />
<MenuItem onClick={handleMenuItemClick} label="I appear above the button" />
</SplitButton>
);

0 comments on commit 3de534d

Please sign in to comment.