Skip to content

Commit ad9510b

Browse files
authored
feat(listitem): add disabled and loading state to list item (#275)
1 parent 8ecfefb commit ad9510b

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

src/components/dropdown-button/stories.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export default {
1919
value: 'project_1',
2020
metadata: {},
2121
onClick: action('onClick'),
22+
isLoading: true,
23+
disabled: true,
2224
},
2325
{
2426
value: 'project_2',
@@ -31,6 +33,7 @@ export default {
3133
icon: IconName.plus,
3234
metadata: {},
3335
onClick: action('onClick'),
36+
isLoading: true,
3437
},
3538
],
3639
},

src/components/dropdown/index.tsx

+24-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import useOnClickOutside from '../../utils/useClickOutside';
88
// Types
99
import { DropdownItem } from './types';
1010
import { GetIcon } from '../icon';
11+
import Spinner from '../spinner';
12+
import { Flex } from 'rebass';
1113

1214
export interface DropdownProps extends Omit<ListProps, 'css' | 'children'> {
1315
items: DropdownItem[];
@@ -31,16 +33,35 @@ const Dropdown: FC<DropdownProps> = ({
3133
return (
3234
<List {...props} ref={containerRef}>
3335
{items?.map((item) => {
34-
const { value, id, icon, hasDivider, onClick } = item;
36+
const { value, id, icon, hasDivider, onClick, isLoading, disabled } =
37+
item;
3538

3639
return (
3740
<ListItem
3841
hasDivider={hasDivider}
3942
key={id || value}
4043
onClick={() => onClick(item)}
44+
disabled={disabled}
4145
>
42-
{icon && <GetIcon icon={icon} size="sm" />}
43-
{value}
46+
<Flex width="100%">
47+
<Flex flexGrow={1}>
48+
{icon && (
49+
<GetIcon
50+
color={disabled ? 'gray' : 'black'}
51+
icon={icon}
52+
size="sm"
53+
/>
54+
)}
55+
{value}
56+
</Flex>
57+
{isLoading && (
58+
<Spinner
59+
size={16}
60+
ml="15px"
61+
color={disabled ? 'gray' : 'primary'}
62+
/>
63+
)}
64+
</Flex>
4465
</ListItem>
4566
);
4667
})}

src/components/dropdown/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ export interface DropdownItem<Metadata = {}> {
77
hasDivider?: boolean;
88
metadata?: Metadata;
99
onClick: (item: DropdownItem) => void;
10+
isLoading?: boolean;
11+
disabled?: boolean;
1012
}

src/components/list/item/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const ListItem: FC<ListItemProps> = ({
2222
action,
2323
isActive = false,
2424
isRightAlignment,
25+
disabled,
2526
...props
2627
}: ListItemProps) => {
2728
const [actionTitle, actionCallback] = action || [];
@@ -33,7 +34,7 @@ const ListItem: FC<ListItemProps> = ({
3334
tx="variants.list.item"
3435
variant={variant}
3536
{...props}
36-
sx={styles(isActive)}
37+
sx={styles(isActive, disabled)}
3738
css={!hasDivider ? withoutBorder : undefined}
3839
>
3940
{children}

src/components/list/item/list-item.styles.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
export const withoutBorder = { borderBottomColor: 'transparent' };
22

3-
export default (isActive: boolean) => ({
3+
export default (isActive: boolean, disablde?: boolean) => ({
44
height: '35px',
55

66
bg: isActive ? 'grayShade3' : 'initial',
7+
color: disablde ? 'gray' : 'initial',
78

89
display: 'flex',
910
alignItems: 'center',

0 commit comments

Comments
 (0)