Skip to content

Commit

Permalink
Update close button
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-jeremy committed Apr 11, 2024
1 parent 1f7f5b2 commit de0b24b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/FatalError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export function FatalError({ buttonText, error }: FatalErrorProps) {
const showSimpleRender = 'type' in error && error.type === 'app-init-failure';

return (
<Modal isCurrent={true} showClose={false} title="Fatal Error">
<Modal isCurrent={true} CloseButton={null} title="Fatal Error">
<View
style={{
maxWidth: 500,
Expand Down
36 changes: 24 additions & 12 deletions packages/desktop-client/src/components/common/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import React, {
useLayoutEffect,
type ReactNode,
useState,
type ComponentProps,
type ComponentType,
type ComponentPropsWithRef,
} from 'react';
import { useHotkeysContext } from 'react-hotkeys-hook';
import ReactModal from 'react-modal';
Expand Down Expand Up @@ -32,9 +35,9 @@ export type ModalProps = {
padding?: CSSProperties['padding'];
showHeader?: boolean;
leftHeaderContent?: ReactNode;
CloseButton?: ComponentType<ComponentPropsWithRef<typeof CloseButton>>;
showTitle?: boolean;
editableTitle?: boolean;
showClose?: boolean;
showOverlay?: boolean;
loading?: boolean;
noAnimation?: boolean;
Expand All @@ -57,9 +60,9 @@ export const Modal = ({
padding = 20,
showHeader = true,
leftHeaderContent,
CloseButton: CloseButtonComponent = CloseButton,
showTitle = true,
editableTitle = false,
showClose = true,
showOverlay = true,
loading = false,
noAnimation = false,
Expand Down Expand Up @@ -261,16 +264,7 @@ export const Modal = ({
marginRight: 15,
}}
>
{showClose && !isEditingTitle && (
<Button
type="bare"
onClick={onClose}
style={{ padding: '10px 10px' }}
aria-label="Close"
>
<SvgDelete width={10} />
</Button>
)}
{!isEditingTitle && <CloseButtonComponent onClick={onClose} />}
</View>
</View>
</View>
Expand Down Expand Up @@ -427,3 +421,21 @@ export const ModalButtons = ({
</View>
);
};

type CloseButtonProps = {
onClick: ComponentProps<typeof Button>['onClick'];
style?: CSSProperties;
};

export function CloseButton({ onClick, style }: CloseButtonProps) {
return (
<Button
type="bare"
onClick={onClick}
style={{ padding: '10px 10px' }}
aria-label="Close"
>
<SvgDelete width={10} style={style} />
</Button>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function GoCardlessLink() {
window.close();

return (
<Modal isCurrent={true} showClose={false} title="Account sync">
<Modal isCurrent={true} CloseButton={null} title="Account sync">

Check failure on line 11 in packages/desktop-client/src/components/gocardless/GoCardlessLink.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Type 'null' is not assignable to type 'ComponentType<CloseButtonProps> | undefined'.
{() => (
<View style={{ maxWidth: 500 }}>
<Paragraph>Please wait...</Paragraph>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { type ComponentPropsWithoutRef } from 'react';
import { useResponsive } from '../../ResponsiveProvider';
import { theme } from '../../style';
import { AccountAutocomplete } from '../autocomplete/AccountAutocomplete';
import { Modal } from '../common/Modal';
import { CloseButton, Modal } from '../common/Modal';
import { View } from '../common/View';
import { SectionLabel } from '../forms';
import { type CommonModalProps } from '../Modals';
Expand Down Expand Up @@ -48,6 +48,9 @@ export function AccountAutocompleteModal({
borderRadius: '6px',
backgroundColor: theme.menuAutoCompleteBackground,
}}
CloseButton={props => (
<CloseButton {...props} style={{ color: theme.menuAutoCompleteText }} />
)}
>
{() => (
<View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { type ComponentPropsWithoutRef } from 'react';
import { useResponsive } from '../../ResponsiveProvider';
import { theme } from '../../style';
import { CategoryAutocomplete } from '../autocomplete/CategoryAutocomplete';
import { Modal } from '../common/Modal';
import { CloseButton, Modal } from '../common/Modal';
import { View } from '../common/View';
import { SectionLabel } from '../forms';
import { type CommonModalProps } from '../Modals';
Expand Down Expand Up @@ -49,6 +49,9 @@ export function CategoryAutocompleteModal({
borderRadius: '6px',
backgroundColor: theme.menuAutoCompleteBackground,
}}
CloseButton={props => (
<CloseButton {...props} style={{ color: theme.menuAutoCompleteText }} />
)}
>
{() => (
<View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { usePayees } from '../../hooks/usePayees';
import { useResponsive } from '../../ResponsiveProvider';
import { theme } from '../../style';
import { PayeeAutocomplete } from '../autocomplete/PayeeAutocomplete';
import { Modal } from '../common/Modal';
import { CloseButton, Modal } from '../common/Modal';
import { type CommonModalProps } from '../Modals';

type PayeeAutocompleteModalProps = {
Expand Down Expand Up @@ -51,6 +51,9 @@ export function PayeeAutocompleteModal({
borderRadius: '6px',
backgroundColor: theme.menuAutoCompleteBackground,
}}
CloseButton={props => (
<CloseButton {...props} style={{ color: theme.menuAutoCompleteText }} />
)}
>
{() => (
<PayeeAutocomplete
Expand Down

0 comments on commit de0b24b

Please sign in to comment.