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 #2370 from teamleadercrm/TIDAL-2601-add-processing…
Browse files Browse the repository at this point in the history
…-state

Add a processing state to the split button
  • Loading branch information
lorgan3 authored Sep 19, 2022
2 parents 3de534d + 7b49168 commit 01cee07
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 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))
- `SplitButton`: `processing` prop equivalent to processing on the regular button. ([@lorgan3](https://github.com/lorgan3)) in [#2370](https://github.com/teamleadercrm/ui/pull/2370))

### Changed

Expand Down
26 changes: 20 additions & 6 deletions src/components/splitButton/SplitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { BoxProps } from '../box/Box';
import { GenericComponent } from '../../@types/types';
import isReactElement from '../utils/is-react-element';
import { SIZES } from '../../constants';
import theme from './theme.css';

interface SplitButtonProps extends Omit<BoxProps, 'children' | 'size'> {
/** The MenuItems we pass to our component. */
Expand All @@ -23,6 +24,8 @@ interface SplitButtonProps extends Omit<BoxProps, 'children' | 'size'> {
onSecondaryButtonClick?: (event: MouseEvent<HTMLElement>) => void;
/** If true, component will be disabled. */
disabled?: boolean;
/** If true, component will show a loading spinner instead of label. */
processing?: 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. */
Expand All @@ -41,6 +44,7 @@ const SplitButton: GenericComponent<SplitButtonProps> = ({
onButtonClick,
onSecondaryButtonClick,
disabled,
processing,
popoverProps,
...others
}) => {
Expand Down Expand Up @@ -82,16 +86,26 @@ const SplitButton: GenericComponent<SplitButtonProps> = ({

return (
<Box display="flex" justifyContent="center" {...boxProps} data-teamleader-ui="split-menu">
<ButtonGroup segmented>
<Button label={buttonLabel} level={level} size={size} disabled={disabled} onClick={handleMainButtonClick} />
{processing ? (
<Button
icon={<IconChevronDownSmallOutline />}
label={buttonLabel}
level={level}
size={size}
disabled={disabled}
onClick={handleSecondaryButtonClick}
processing
className={theme[`split-button-${size}--processing`]}
/>
</ButtonGroup>
) : (
<ButtonGroup segmented>
<Button label={buttonLabel} level={level} size={size} disabled={disabled} onClick={handleMainButtonClick} />
<Button
icon={<IconChevronDownSmallOutline />}
level={level}
size={size}
disabled={disabled}
onClick={handleSecondaryButtonClick}
/>
</ButtonGroup>
)}
<Popover
active={popoverActive}
anchorEl={popoverAnchorEl?.current}
Expand Down
19 changes: 19 additions & 0 deletions src/components/splitButton/theme.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.split-button {
&-small {
&--processing {
padding-right: 42px;
}
}

&-medium {
&--processing {
padding-right: 47px;
}
}

&-large {
&--processing {
padding-right: 65px;
}
}
}

0 comments on commit 01cee07

Please sign in to comment.