|
1 | 1 | import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
|
2 |
| -import { Theme } from '@mui/material'; |
| 2 | +import { Theme, useTheme } from '@mui/material'; |
3 | 3 | import { MouseEvent, useState } from 'react';
|
4 | 4 | import { Button, Menu, MenuItem } from '../../base';
|
5 | 5 | import { iconXSmall } from '../../constants/iconsSizes';
|
6 | 6 | import { ALICE_BLUE, CHINESE_SILVER, NOT_FOUND, styled } from '../../theme';
|
7 | 7 |
|
| 8 | +export const VIEW_VISIBILITY = { |
| 9 | + PUBLIC: 'public', |
| 10 | + PRIVATE: 'private', |
| 11 | + PUBLISHED: 'published' |
| 12 | +} as const; |
| 13 | + |
| 14 | +export type VIEW_VISIBILITY = (typeof VIEW_VISIBILITY)[keyof typeof VIEW_VISIBILITY]; |
| 15 | + |
8 | 16 | interface VisibilityChipMenuProps {
|
9 |
| - value: string; |
| 17 | + value: VIEW_VISIBILITY; |
10 | 18 | onChange: (value: string) => void;
|
11 | 19 | options: [string, React.ElementType][];
|
12 | 20 | enabled: boolean;
|
@@ -42,24 +50,25 @@ const StyledButton = styled(Button)(() => ({
|
42 | 50 | width: '100%'
|
43 | 51 | }));
|
44 | 52 |
|
45 |
| -const StyledDiv = styled('div')(({ theme, enabled }: { theme?: Theme; enabled: boolean }) => ({ |
46 |
| - paddingLeft: '0.3rem', |
47 |
| - height: '1.5rem', |
48 |
| - paddingRight: enabled ? '0' : '0.3rem', |
49 |
| - borderRadius: '0.25rem', |
50 |
| - border: `1px solid ${NOT_FOUND}`, |
51 |
| - background: |
52 |
| - theme?.palette.mode === 'light' ? ALICE_BLUE : theme?.palette.background.constant?.table, |
53 |
| - |
54 |
| - textTransform: 'uppercase', |
55 |
| - color: theme?.palette.text.default, |
56 |
| - display: 'flex', |
57 |
| - justifyContent: 'center', |
58 |
| - alignItems: 'center', |
59 |
| - width: '3.8rem', |
60 |
| - fontSize: '0.75rem', |
61 |
| - fontFamily: theme?.typography.fontFamily |
62 |
| -})); |
| 53 | +const StyledDiv = styled('div')( |
| 54 | + ({ theme, enabled, type }: { theme: Theme; enabled: boolean; type: VIEW_VISIBILITY }) => ({ |
| 55 | + paddingLeft: '0.3rem', |
| 56 | + height: '1.5rem', |
| 57 | + paddingRight: enabled ? '0' : '0.3rem', |
| 58 | + borderRadius: '0.25rem', |
| 59 | + border: `1px solid ${NOT_FOUND}`, |
| 60 | + background: |
| 61 | + theme?.palette.mode === 'light' ? ALICE_BLUE : theme?.palette.background.constant?.table, |
| 62 | + textTransform: 'uppercase', |
| 63 | + color: theme?.palette.text.default, |
| 64 | + display: 'flex', |
| 65 | + justifyContent: 'center', |
| 66 | + alignItems: 'center', |
| 67 | + width: type !== 'published' ? '3.8rem' : 'auto', |
| 68 | + fontSize: '0.75rem', |
| 69 | + fontFamily: theme?.typography.fontFamily |
| 70 | + }) |
| 71 | +); |
63 | 72 |
|
64 | 73 | const StyledMenuItem = styled(MenuItem)(({ theme }) => ({
|
65 | 74 | textTransform: 'capitalize',
|
@@ -92,14 +101,15 @@ const VisibilityChipMenu: React.FC<VisibilityChipMenuProps> = ({
|
92 | 101 | onChange(value);
|
93 | 102 | close(e);
|
94 | 103 | };
|
| 104 | + const theme = useTheme(); |
95 | 105 | return (
|
96 | 106 | <>
|
97 | 107 | <StyledButton
|
98 | 108 | disabled={!enabled}
|
99 | 109 | onClick={handleOpen}
|
100 | 110 | data-testid={`design-visibility-${value.toLowerCase()}`}
|
101 | 111 | >
|
102 |
| - <StyledDiv enabled={enabled}> |
| 112 | + <StyledDiv theme={theme} enabled={enabled} type={value}> |
103 | 113 | <span style={{ fontSize: '0.7rem' }}>{value}</span>
|
104 | 114 | {enabled && <ArrowDropDownIcon style={{ ...iconXSmall }} />}
|
105 | 115 | </StyledDiv>
|
|
0 commit comments