import styled from '@emotion/styled'; import classNames from 'classnames'; import ActionButton from './button'; import ConfirmableAction from './confirmableAction'; const StyledAction = styled('a')<{disabled?: boolean}>` display: flex; align-items: center; ${p => p.disabled && 'cursor: not-allowed;'} `; const StyledActionButton = styled(ActionButton)<{ disabled?: boolean; hasDropdown?: boolean; }>` display: flex; align-items: center; ${p => p.disabled && 'cursor: not-allowed;'} ${p => p.hasDropdown && `border-radius: ${p.theme.borderRadiusLeft}`}; `; type ConfirmableActionProps = React.ComponentProps; type CommonProps = Omit< ConfirmableActionProps, 'onConfirm' | 'confirmText' | 'children' | 'stopPropagation' | 'priority' > & { children: React.ReactChild; className?: string; confirmLabel?: string; confirmPriority?: ConfirmableActionProps['priority']; disabled?: boolean; onAction?: () => void; shouldConfirm?: boolean; title?: string; }; type Props = CommonProps & ({type?: 'button'} & Partial< Omit, 'as' | 'children'> >); export default function ActionLink({ message, className, onAction, type, confirmLabel, disabled, children, shouldConfirm, confirmPriority, header, ...props }: Props) { const actionCommonProps = { className: classNames(className, {disabled}), onClick: disabled ? undefined : onAction, disabled, children, ...props, }; const action = type === 'button' ? ( ) : ( ); if (shouldConfirm && onAction) { return ( {action} ); } return action; }