diff --git a/packages/lib-components/src/components/actions/Button/style.ts b/packages/lib-components/src/components/actions/Button/style.ts index ffe4703d67..e5cd9b9b50 100644 --- a/packages/lib-components/src/components/actions/Button/style.ts +++ b/packages/lib-components/src/components/actions/Button/style.ts @@ -36,20 +36,20 @@ export const Default = styled.button<{ font-weight: 600; white-space: nowrap; color: ${({ theme, color }) => { - switch (color) { - case 'white': - return theme.colors.primary; - case 'background': - return theme.colors.text; - default: - return 'white'; - } - }}; + switch (color) { + case 'white': + return theme.colors.primary; + case 'background': + return theme.colors.text; + default: + return 'white'; + } + }}; margin-left: ${({ icon, isLoading, iconPosition }): string => - iconPosition === 'left' && (icon || isLoading) ? '10px' : '0px'}; + iconPosition === 'left' && (icon || isLoading) ? '10px' : '0px'}; margin-right: ${({ icon, isLoading, iconPosition }): string => - iconPosition === 'right' && (icon || isLoading) ? '10px' : '0px'}; + iconPosition === 'right' && (icon || isLoading) ? '10px' : '0px'}; } &:disabled { @@ -62,15 +62,15 @@ export const Default = styled.button<{ display: ${({ icon, isLoading }): string => (icon || isLoading ? 'block' : 'none')}; cursor: ${({ disabled }) => (disabled ? 'default' : 'pointer')}; fill: ${({ theme, color }) => { - switch (color) { - case 'white': - return theme.colors.primary; - case 'background': - return theme.colors.text; - default: - return 'white'; - } - }}; + switch (color) { + case 'white': + return theme.colors.primary; + case 'background': + return theme.colors.text; + default: + return 'white'; + } + }}; stroke: white; } @@ -103,7 +103,7 @@ export const Default = styled.button<{ }} `; -export const Outline = styled(Default)<{ color: ButtonColor }>` +export const Outline = styled(Default) <{ color: ButtonColor }>` background: transparent; border: 0.1rem solid ${({ theme, color }): string => theme.colors[color]}; span { diff --git a/packages/lib-components/src/components/actions/DropdownButton/index.tsx b/packages/lib-components/src/components/actions/DropdownButton/index.tsx index 60a2a3b7dd..b937a8792e 100644 --- a/packages/lib-components/src/components/actions/DropdownButton/index.tsx +++ b/packages/lib-components/src/components/actions/DropdownButton/index.tsx @@ -4,6 +4,8 @@ import { MdChevronRight as ArrowIcon } from 'react-icons/md'; import { ActionMenu } from '../../../components'; import { styled } from '../../../styled'; import { useFloating } from '@floating-ui/react'; +import { shade } from 'polished'; +import { ButtonColor } from '../Button/style'; const Arrow = styled(ArrowIcon)` transform: rotate(90deg); @@ -12,7 +14,7 @@ const Arrow = styled(ArrowIcon)` const Wrapper = styled.div``; -const DropdownActionContainer = styled.div<{ isVisible: boolean }>` +const DropdownActionContainer = styled.div<{ color: ButtonColor }>` font-weight: 500; display: flex; align-items: center; @@ -20,40 +22,36 @@ const DropdownActionContainer = styled.div<{ isVisible: boolean }>` justify-content: center; cursor: pointer; width: 3.2rem; - border: .1rem solid ${({ theme, isVisible }) => (isVisible ? theme.colors.primary : theme.colors.backgroundAccent)}}; + + background: ${({ theme, color }) => shade(0.5, theme.colors[color])}; + border: .1rem solid ${({ theme, color }) => theme.colors[color === 'background' ? 'backgroundAccent' : color]}}; border-top-right-radius: ${({ theme }) => theme.borderRadius.small}}; border-bottom-right-radius: ${({ theme }) => theme.borderRadius.small}}; - - &:hover { - border-color:${({ theme }) => theme.colors.primary}; - svg { - fill: ${({ theme }) => theme.colors.primary}; - } + svg { + fill: ${({ theme }) => theme.colors.text}; } &:active { background-color: transparent; } `; -const CurrentAction = styled.div` +const CurrentAction = styled.div<{ color: ButtonColor }>` padding: ${({ theme }) => `${theme.spacing['0_5']} ${theme.spacing[1]}`}; font-weight: 500; cursor: pointer; min-width: 10rem; height: 100%; color: ${({ theme }) => theme.colors.text}; - border-top: 0.1rem solid ${({ theme }) => theme.colors.backgroundAccent}; - border-left: 0.1rem solid ${({ theme }) => theme.colors.backgroundAccent}; - border-bottom: 0.1rem solid ${({ theme }) => theme.colors.backgroundAccent}; + + background: ${({ theme, color }) => shade(0.5, theme.colors[color])}; + border-top: 0.1rem solid ${({ theme, color }) => theme.colors[color === 'background' ? 'backgroundAccent' : color]}; + border-left: 0.1rem solid ${({ theme, color }) => theme.colors[color === 'background' ? 'backgroundAccent' : color]}; + border-bottom: 0.1rem solid ${({ theme, color }) => theme.colors[color === 'background' ? 'backgroundAccent' : color]}; border-top-left-radius: ${({ theme }) => theme.borderRadius.small}; border-bottom-left-radius: ${({ theme }) => theme.borderRadius.small}; text-align: center; - &:hover { - color: ${({ theme }) => theme.colors.primary}; - border-color: ${({ theme }) => theme.colors.primary}; - } &:active { background-color: transparent; } @@ -65,44 +63,43 @@ const Container = styled.div` flex-wrap: wrap; border-radius: ${({ theme }) => theme.borderRadius.large}; width: max-content; - - &:hover ${DropdownActionContainer} { - border-left-color: ${({ theme }) => theme.colors.primary}; - } `; export interface DropdownButtonProps { children: ReactElement[]; + color?: ButtonColor; } -export const DropdownButton: FC = ({ children }) => { - const [visible, setVisible] = useState(false); +export const DropdownButton: FC = ({ children, color = 'primary' }) => { + const [listVisible, setListVisible] = useState(false); const [selected, setSelected] = useState(0); const { x, y, refs, strategy } = useFloating(); const parentRef = useRef(null); useOutsideAlerter(parentRef, () => { - setVisible(false); + setListVisible(false); }); useEffect(() => { - setVisible(false); + setListVisible(false); }, [selected]); const handleSelectedActionClicked = () => { - setVisible(false); + setListVisible(false); children[selected].props.onClick(); }; return ( - {children[selected].props.text} - setVisible(!visible)} isVisible={visible}> + + {children[selected].props.text} + + setListVisible(!listVisible)}> - {visible && ( + {listVisible && ( {children} diff --git a/packages/lib-components/src/components/other/ActionMenu/index.tsx b/packages/lib-components/src/components/other/ActionMenu/index.tsx index 0c9c4303c5..cb7b80555c 100644 --- a/packages/lib-components/src/components/other/ActionMenu/index.tsx +++ b/packages/lib-components/src/components/other/ActionMenu/index.tsx @@ -16,7 +16,7 @@ export interface ActionMenuProps { export const ActionMenu = forwardRef(function ActionMenu( { attributes, children, selectedState, elevation = 4 }, - ref, + ref ) { const [selected, setSelected] = selectedState; @@ -31,7 +31,12 @@ export const ActionMenu = forwardRef(function ref={ref} > {Children.map(children, (child: ReactElement, idx) => ( - setSelected(idx)}> + { + if (child.props.disabled) return; + setSelected(idx); + }} + > {child} {selected === idx ? (
@@ -49,8 +54,8 @@ export const ActionMenu = forwardRef(function interface ActionProps { onClick: () => unknown; text: string; - // TODO: implement disabled when needed + disabled?: boolean; } -export const Action: FC> = ({ children }) => { +export const Action: FC> = ({ children, disabled = false }) => { return
{children}
; };