Skip to content

Commit 3d8958d

Browse files
authored
feat(popup): make TinyPopup buttons customizable (#289)
* feat(popup): make TinyPopup buttons customizable accepting all button props for each button * Refac styling
1 parent 6db649b commit 3d8958d

File tree

2 files changed

+35
-51
lines changed

2 files changed

+35
-51
lines changed

src/components/popup/popup.stories.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,15 @@ export const PopupTiny: Story<TinyPopupProps> = (props) => {
9898
{...props}
9999
onClose={handleToggle}
100100
isOpen={isOpen}
101-
mainButton={['main', action('main')]}
102-
secondaryButton={['secondary', action('secondary')]}
101+
mainButtonProps={{
102+
children: 'main',
103+
onClick: action('main'),
104+
isLoading: true,
105+
}}
106+
secondaryButtonProps={{
107+
children: 'secondary',
108+
onClick: action('secondary'),
109+
}}
103110
>
104111
<Input label="Value" />
105112
</TinyPopup>

src/components/popup/tiny/index.tsx

+26-49
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import React, { FC } from 'react';
2-
import { Box } from 'rebass';
3-
import Action from '../../action.type';
2+
import { Box, Flex } from 'rebass';
43
import Button from '../../button';
54

65
// Components
76
import Popup, { PopupProps } from '../index';
87
import Subtitle from '../../typography/subtitle';
98
import Text from '../../typography/text';
9+
import { ButtonProps } from '../../..';
1010

11-
export interface TinyPopupProps extends Omit<PopupProps, 'css' | 'children'> {
11+
export interface TinyPopupProps
12+
extends Omit<
13+
PopupProps,
14+
'css' | 'children' | 'disabledMainButton' | 'disabledSecondaryButton'
15+
> {
1216
title: string;
1317
secondaryText: string;
14-
mainButton?: Action<React.MouseEvent<HTMLButtonElement>>;
15-
secondaryButton?: Action<React.MouseEvent<HTMLButtonElement>>;
16-
tertiaryButton?: Action<React.MouseEvent<HTMLButtonElement>>;
17-
disabledTertiaryButton?: boolean;
18+
mainButtonProps?: ButtonProps;
19+
secondaryButtonProps?: ButtonProps;
20+
tertiaryButtonProps?: ButtonProps;
1821
onClose?: () => void;
1922
children?: React.ReactNode;
2023
contentHeight?: string;
@@ -23,35 +26,27 @@ export interface TinyPopupProps extends Omit<PopupProps, 'css' | 'children'> {
2326
const TinyPopup: FC<TinyPopupProps> = ({
2427
title,
2528
secondaryText,
26-
mainButton,
27-
secondaryButton,
28-
tertiaryButton,
2929
onClose = () => {},
30-
disabledMainButton = false,
31-
disabledSecondaryButton = false,
32-
disabledTertiaryButton = false,
30+
mainButtonProps,
31+
secondaryButtonProps,
32+
tertiaryButtonProps,
3333
children,
3434
contentHeight,
35+
sx,
3536
...props
3637
}: TinyPopupProps) => {
37-
const [mainActionTitle, mainActionCallback] = mainButton || [];
38-
const [secondaryActionTitle, secondaryActionCallback] = secondaryButton || [];
39-
const [tertiaryActionTitle, tertiaryActionCallback] = tertiaryButton || [];
40-
4138
return (
4239
<Popup
43-
pt="20px"
44-
pl="20px"
45-
pr="20px"
46-
pb="20px"
40+
p="20px"
4741
width="fit-content"
4842
sx={{
4943
left: '50%',
5044
top: '50%',
5145
transform: 'translate(-50%, -50%)',
46+
...sx,
5247
}}
53-
{...props}
5448
onClose={onClose}
49+
{...props}
5550
>
5651
<Subtitle pb="20px" lineHeight="22px">
5752
{title}
@@ -62,35 +57,17 @@ const TinyPopup: FC<TinyPopupProps> = ({
6257
</Text>
6358
)}
6459
<Box sx={contentHeight ? { height: contentHeight } : {}}>{children}</Box>
65-
<Box display="flex" mt="auto">
66-
<Box display="flex" ml="auto">
67-
{tertiaryButton && (
68-
<Button
69-
disabled={disabledTertiaryButton}
70-
intent="secondary"
71-
onClick={tertiaryActionCallback}
72-
mr="20px"
73-
>
74-
{tertiaryActionTitle}
75-
</Button>
76-
)}
77-
{secondaryButton && (
78-
<Button
79-
disabled={disabledSecondaryButton}
80-
intent="secondary"
81-
onClick={secondaryActionCallback}
82-
mr="20px"
83-
>
84-
{secondaryActionTitle}
85-
</Button>
60+
<Flex>
61+
<Flex width="100%" sx={{ gap: '20px', justifyContent: 'flex-end' }}>
62+
{tertiaryButtonProps && (
63+
<Button intent="secondary" {...tertiaryButtonProps} />
8664
)}
87-
{mainButton && (
88-
<Button disabled={disabledMainButton} onClick={mainActionCallback}>
89-
{mainActionTitle}
90-
</Button>
65+
{secondaryButtonProps && (
66+
<Button intent="secondary" {...secondaryButtonProps} />
9167
)}
92-
</Box>
93-
</Box>
68+
{mainButtonProps && <Button {...mainButtonProps} />}
69+
</Flex>
70+
</Flex>
9471
</Popup>
9572
);
9673
};

0 commit comments

Comments
 (0)