diff --git a/packages/desktop-client/src/components/common/Menu.tsx b/packages/desktop-client/src/components/common/Menu.tsx index a948ca5ec4e..68490d7baa2 100644 --- a/packages/desktop-client/src/components/common/Menu.tsx +++ b/packages/desktop-client/src/components/common/Menu.tsx @@ -144,7 +144,6 @@ export function Menu({ ); } - const lastItem = items[idx - 1]; const Icon = item.icon; return ( @@ -153,14 +152,9 @@ export function Menu({ key={item.name} style={{ cursor: 'default', - padding: '9px 10px', - marginTop: - idx === 0 || - lastItem === Menu.line || - lastItem.type === Menu.label - ? 0 - : -3, + padding: 10, flexDirection: 'row', + justifyContent: 'center', alignItems: 'center', color: theme.menuItemText, ...(item.disabled && { color: theme.buttonBareDisabledText }), diff --git a/packages/desktop-client/src/components/common/Modal.tsx b/packages/desktop-client/src/components/common/Modal.tsx index 9c07af48ff0..e61f6a064ad 100644 --- a/packages/desktop-client/src/components/common/Modal.tsx +++ b/packages/desktop-client/src/components/common/Modal.tsx @@ -10,6 +10,7 @@ import { useHotkeysContext } from 'react-hotkeys-hook'; import ReactModal from 'react-modal'; import { AnimatedLoading } from '../../icons/AnimatedLoading'; +import { SvgLogo } from '../../icons/logo'; import { SvgDelete } from '../../icons/v0'; import { type CSSProperties, styles, theme } from '../../style'; import { tokens } from '../../tokens'; @@ -19,21 +20,16 @@ import { Input } from './Input'; import { Text } from './Text'; import { View } from './View'; -type ModalChildrenProps = { - isEditingTitle: boolean; -}; - export type ModalProps = { - title?: string; + title?: ReactNode; isCurrent?: boolean; isHidden?: boolean; - children: ReactNode | ((props: ModalChildrenProps) => ReactNode); + children: ReactNode | (() => ReactNode); size?: { width?: CSSProperties['width']; height?: CSSProperties['height'] }; padding?: CSSProperties['padding']; showHeader?: boolean; leftHeaderContent?: ReactNode; showTitle?: boolean; - editableTitle?: boolean; showClose?: boolean; showOverlay?: boolean; loading?: boolean; @@ -42,11 +38,9 @@ export type ModalProps = { stackIndex?: number; parent?: HTMLElement; style?: CSSProperties; - titleStyle?: CSSProperties; contentStyle?: CSSProperties; overlayStyle?: CSSProperties; onClose?: () => void; - onTitleUpdate?: (title: string) => void; }; export const Modal = ({ @@ -58,7 +52,6 @@ export const Modal = ({ showHeader = true, leftHeaderContent, showTitle = true, - editableTitle = false, showClose = true, showOverlay = true, loading = false, @@ -67,12 +60,10 @@ export const Modal = ({ stackIndex, parent, style, - titleStyle, contentStyle, overlayStyle, children, onClose, - onTitleUpdate, }: ModalProps) => { const { enableScope, disableScope } = useHotkeysContext(); @@ -83,20 +74,6 @@ export const Modal = ({ return () => disableScope(scopeId); }, [enableScope, disableScope, scopeId]); - const [isEditingTitle, setIsEditingTitle] = useState(false); - const [_title, setTitle] = useState(title); - - const onTitleClick = () => { - setIsEditingTitle(true); - }; - - const _onTitleUpdate = newTitle => { - if (newTitle !== title) { - onTitleUpdate?.(newTitle); - } - setIsEditingTitle(false); - }; - return ( - - {leftHeaderContent && !isEditingTitle - ? leftHeaderContent - : null} - + {leftHeaderContent} {showTitle && ( - {isEditingTitle ? ( - setTitle(e.target.value)} - onKeyDown={e => { - if (e.key === 'Enter') { - e.preventDefault(); - _onTitleUpdate(e.currentTarget.value); - } - }} - onBlur={e => _onTitleUpdate(e.target.value)} + {!title ? ( + + ) : typeof title === 'string' || typeof title === 'number' ? ( + ) : ( - - {_title} - + title )} )} @@ -249,36 +193,24 @@ export const Modal = ({ style={{ position: 'absolute', right: 0, - top: 0, - bottom: 0, - justifyContent: 'center', - alignItems: 'center', + margin: '0 5px', }} > - - {showClose && !isEditingTitle && ( - - )} - + {showClose && ( + + )} )} - {typeof children === 'function' - ? children({ isEditingTitle }) - : children} + {typeof children === 'function' ? children() : children} {loading && ( ); }; + +type ModalTitleProps = { + title: string; + isEditable?: boolean; + getStyle?: (isEditing: boolean) => CSSProperties; + onEdit?: (isEditing: boolean) => void; + onTitleUpdate?: (newName: string) => void; +}; + +export function ModalTitle({ + title, + isEditable, + getStyle, + onTitleUpdate, +}: ModalTitleProps) { + const [isEditing, setIsEditing] = useState(false); + const style = getStyle?.(isEditing); + + const _onEdit = () => { + if (!isEditable) { + return; + } + + setIsEditing(true); + }; + + const _onTitleUpdate = newTitle => { + if (newTitle !== title) { + onTitleUpdate?.(newTitle); + } + setIsEditing(false); + }; + + const inputRef = useRef(); + useEffect(() => { + if (isEditing) { + if (inputRef.current) { + inputRef.current.scrollLeft = 0; + } + } + }, [isEditing]); + + return isEditing ? ( + { + if (e.key === 'Enter') { + e.preventDefault(); + _onTitleUpdate?.(e.currentTarget.value); + } + }} + /> + ) : ( + + {title} + + ); +} diff --git a/packages/desktop-client/src/components/modals/AccountMenuModal.tsx b/packages/desktop-client/src/components/modals/AccountMenuModal.tsx index c6759989192..2ee3920b8fb 100644 --- a/packages/desktop-client/src/components/modals/AccountMenuModal.tsx +++ b/packages/desktop-client/src/components/modals/AccountMenuModal.tsx @@ -10,7 +10,7 @@ import { SvgNotesPaper } from '../../icons/v2'; import { type CSSProperties, styles, theme } from '../../style'; import { Button } from '../common/Button'; import { Menu } from '../common/Menu'; -import { Modal } from '../common/Modal'; +import { Modal, ModalTitle } from '../common/Modal'; import { View } from '../common/View'; import { type CommonModalProps } from '../Modals'; import { Notes } from '../Notes'; @@ -88,8 +88,9 @@ export function AccountMenuModal({ return ( + } showHeader focusAfterClose={false} {...modalProps} @@ -101,8 +102,6 @@ export function AccountMenuModal({ padding: '0 10px', borderRadius: '6px', }} - editableTitle={true} - onTitleUpdate={onRename} leftHeaderContent={ } > - {({ isEditingTitle }) => ( + - - 0 - ? originalNotes - : 'No notes' - } - editable={false} - focused={false} - getStyle={() => ({ - borderRadius: 6, - ...((!originalNotes || originalNotes.length === 0) && { - justifySelf: 'center', - alignSelf: 'center', - color: theme.pageTextSubdued, - }), - })} - /> - - 0 + ? originalNotes + : 'No notes' + } + editable={false} + focused={false} + getStyle={() => ({ + borderRadius: 6, + ...((!originalNotes || originalNotes.length === 0) && { + justifySelf: 'center', + alignSelf: 'center', + color: theme.pageTextSubdued, + }), + })} + /> + + + - + + Edit notes + - )} + ); } diff --git a/packages/desktop-client/src/components/modals/BudgetMenuModal.tsx b/packages/desktop-client/src/components/modals/BudgetMenuModal.tsx index 74e31e12343..59a7d867c7e 100644 --- a/packages/desktop-client/src/components/modals/BudgetMenuModal.tsx +++ b/packages/desktop-client/src/components/modals/BudgetMenuModal.tsx @@ -25,7 +25,6 @@ export function BudgetMenuModal({ return ( - {() => ( - defaultMenuItemStyle} - month={month} - onToggleHiddenCategories={onToggleHiddenCategories} - onSwitchBudgetType={onSwitchBudgetType} - /> - )} + defaultMenuItemStyle} + month={month} + onToggleHiddenCategories={onToggleHiddenCategories} + onSwitchBudgetType={onSwitchBudgetType} + /> ); } diff --git a/packages/desktop-client/src/components/modals/CategoryGroupMenuModal.tsx b/packages/desktop-client/src/components/modals/CategoryGroupMenuModal.tsx index c963e668fb8..f3337184994 100644 --- a/packages/desktop-client/src/components/modals/CategoryGroupMenuModal.tsx +++ b/packages/desktop-client/src/components/modals/CategoryGroupMenuModal.tsx @@ -11,7 +11,7 @@ import { SvgNotesPaper, SvgViewHide, SvgViewShow } from '../../icons/v2'; import { type CSSProperties, styles, theme } from '../../style'; import { Button } from '../common/Button'; import { Menu } from '../common/Menu'; -import { Modal } from '../common/Modal'; +import { Modal, ModalTitle } from '../common/Modal'; import { View } from '../common/View'; import { type CommonModalProps } from '../Modals'; import { Notes } from '../Notes'; @@ -91,7 +91,9 @@ export function CategoryGroupMenuModal({ return ( + } showHeader focusAfterClose={false} {...modalProps} @@ -103,9 +105,6 @@ export function CategoryGroupMenuModal({ padding: '0 10px', borderRadius: '6px', }} - editableTitle={true} - titleStyle={styles.underlinedText} - onTitleUpdate={onRename} leftHeaderContent={ } > - {({ isEditingTitle }) => ( + - - 0 ? notes : 'No notes'} - editable={false} - focused={false} - getStyle={() => ({ - ...styles.mediumText, - borderRadius: 6, - ...((!notes || notes.length === 0) && { - justifySelf: 'center', - alignSelf: 'center', - color: theme.pageTextSubdued, - }), - })} - /> - - - - - + 0 ? notes : 'No notes'} + editable={false} + focused={false} + getStyle={() => ({ + ...styles.mediumText, + borderRadius: 6, + ...((!notes || notes.length === 0) && { + justifySelf: 'center', + alignSelf: 'center', + color: theme.pageTextSubdued, + }), + })} + /> + + + + - )} + ); } diff --git a/packages/desktop-client/src/components/modals/CategoryMenuModal.tsx b/packages/desktop-client/src/components/modals/CategoryMenuModal.tsx index a67c1188957..5f7e31fe8cf 100644 --- a/packages/desktop-client/src/components/modals/CategoryMenuModal.tsx +++ b/packages/desktop-client/src/components/modals/CategoryMenuModal.tsx @@ -11,7 +11,7 @@ import { SvgNotesPaper, SvgViewHide, SvgViewShow } from '../../icons/v2'; import { type CSSProperties, styles, theme } from '../../style'; import { Button } from '../common/Button'; import { Menu } from '../common/Menu'; -import { Modal } from '../common/Modal'; +import { Modal, ModalTitle } from '../common/Modal'; import { View } from '../common/View'; import { type CommonModalProps } from '../Modals'; import { Notes } from '../Notes'; @@ -82,8 +82,9 @@ export function CategoryMenuModal({ return ( + } showHeader focusAfterClose={false} {...modalProps} @@ -95,8 +96,6 @@ export function CategoryMenuModal({ padding: '0 10px', borderRadius: '6px', }} - editableTitle={true} - onTitleUpdate={onRename} leftHeaderContent={ } > - {({ isEditingTitle }) => ( + - - 0 ? originalNotes : 'No notes'} - editable={false} - focused={false} - getStyle={() => ({ - borderRadius: 6, - ...((!originalNotes || originalNotes.length === 0) && { - justifySelf: 'center', - alignSelf: 'center', - color: theme.pageTextSubdued, - }), - })} - /> - - - - + 0 ? originalNotes : 'No notes'} + editable={false} + focused={false} + getStyle={() => ({ + borderRadius: 6, + ...((!originalNotes || originalNotes.length === 0) && { + justifySelf: 'center', + alignSelf: 'center', + color: theme.pageTextSubdued, + }), + })} + /> + + + - )} + ); } diff --git a/packages/desktop-client/src/components/modals/ReportBalanceMenuModal.tsx b/packages/desktop-client/src/components/modals/ReportBalanceMenuModal.tsx index 6c4d5e6e1ea..788d9e19d58 100644 --- a/packages/desktop-client/src/components/modals/ReportBalanceMenuModal.tsx +++ b/packages/desktop-client/src/components/modals/ReportBalanceMenuModal.tsx @@ -25,7 +25,6 @@ export function ReportBalanceMenuModal({ return ( - {() => ( - defaultMenuItemStyle} - onCarryover={onCarryover} - /> - )} + defaultMenuItemStyle} + onCarryover={onCarryover} + /> ); } diff --git a/packages/desktop-client/src/components/modals/RolloverBalanceMenuModal.tsx b/packages/desktop-client/src/components/modals/RolloverBalanceMenuModal.tsx index 75c4159103f..247fb0526f4 100644 --- a/packages/desktop-client/src/components/modals/RolloverBalanceMenuModal.tsx +++ b/packages/desktop-client/src/components/modals/RolloverBalanceMenuModal.tsx @@ -27,7 +27,6 @@ export function RolloverBalanceMenuModal({ return ( - {() => ( - defaultMenuItemStyle} - onCarryover={onCarryover} - onTransfer={onTransfer} - onCover={onCover} - /> - )} + defaultMenuItemStyle} + onCarryover={onCarryover} + onTransfer={onTransfer} + onCover={onCover} + /> ); } diff --git a/packages/desktop-client/src/components/modals/RolloverToBudgetMenuModal.tsx b/packages/desktop-client/src/components/modals/RolloverToBudgetMenuModal.tsx index da62d53d08f..9daa6ac60b1 100644 --- a/packages/desktop-client/src/components/modals/RolloverToBudgetMenuModal.tsx +++ b/packages/desktop-client/src/components/modals/RolloverToBudgetMenuModal.tsx @@ -26,7 +26,6 @@ export function RolloverToBudgetMenuModal({ return ( - {() => ( - defaultMenuItemStyle} - onTransfer={onTransfer} - onHoldBuffer={onHoldBuffer} - onResetHoldBuffer={onResetHoldBuffer} - /> - )} + defaultMenuItemStyle} + onTransfer={onTransfer} + onHoldBuffer={onHoldBuffer} + onResetHoldBuffer={onResetHoldBuffer} + /> ); } diff --git a/packages/desktop-client/src/components/modals/ScheduledTransactionMenuModal.tsx b/packages/desktop-client/src/components/modals/ScheduledTransactionMenuModal.tsx index cfadec05dab..8a70ceb1572 100644 --- a/packages/desktop-client/src/components/modals/ScheduledTransactionMenuModal.tsx +++ b/packages/desktop-client/src/components/modals/ScheduledTransactionMenuModal.tsx @@ -24,7 +24,6 @@ export function ScheduledTransactionMenuModal({ return ( - {() => ( - defaultMenuItemStyle} - /> - )} + defaultMenuItemStyle} + /> ); }