A local-first personal finance app
[WIP] Add info text to Upcoming Length control (#3639)
Samuel Barnese775306f81a6
diff --git a/packages/desktop-client/src/components/common/InfoBubble.tsx b/packages/desktop-client/src/components/common/InfoBubble.tsxnew file mode 100644index 0000000000..d28879d80e--- /dev/null+++ b/packages/desktop-client/src/components/common/InfoBubble.tsx@@ -0,0 +1,68 @@+import React, { useState } from 'react';+import { useLocation } from 'react-router-dom';++import { SvgInformationCircle } from '../../icons/v2';+import { theme } from '../../style';++import { Text } from './Text';+import { View } from './View';++type InfoBubbleProps = {+ label: string;+ textWidth?: number;+};++export function InfoBubble({ label, textWidth }: InfoBubbleProps) {+ const location = useLocation();+ const [visible, setVisible] = useState(location.hash === '#info');++ const width = textWidth || getStringWidth(label);++ return visible ? (+ <View style={{ userSelect: 'none' }}>+ <SvgInformationCircle+ style={{ height: '15px', cursor: 'pointer' }}+ onClick={() => setVisible(false)}+ onMouseLeave={() => setVisible(false)}+ />+ <View+ style={{+ position: 'absolute',+ left: '20px',+ top: '-7px',+ color: theme.buttonNormalText,+ backgroundColor: theme.buttonNormalBackground,+ padding: 5,+ borderRadius: 4,+ border: '1px solid ' + theme.buttonNormalBorder,+ zIndex: 300,+ boxShadow: theme.buttonPrimaryShadow,+ }}+ >+ <Text+ style={{+ width,+ }}+ >+ {label}+ </Text>+ </View>+ </View>+ ) : (+ <View style={{ userSelect: 'none' }}>+ <SvgInformationCircle+ style={{ height: '15px', cursor: 'pointer' }}+ onClick={() => setVisible(true)}+ onMouseOver={() => setTimeout(() => setVisible(true), 500)}+ />+ </View>+ );+}++function getStringWidth(text: string): number {+ const canvas = document.createElement('canvas');+ const context = canvas.getContext('2d')!;+ context.font = getComputedStyle(document.body).font;++ return Math.ceil(context.measureText(text).width);+}diff --git a/packages/desktop-client/src/components/settings/Upcoming.tsx b/packages/desktop-client/src/components/settings/Upcoming.tsxindex 0f1409c75d..e556c2a7c0 100644--- a/packages/desktop-client/src/components/settings/Upcoming.tsx+++ b/packages/desktop-client/src/components/settings/Upcoming.tsx@@ -9,6 +9,7 @@ import { type SyncedPrefs } from 'loot-core/types/prefs';import { useSyncedPref } from '../../hooks/useSyncedPref';import { type CSSProperties, theme } from '../../style';import { Button } from '../common/Button2';+import { InfoBubble } from '../common/InfoBubble';import { Select } from '../common/Select';import { Text } from '../common/Text';import { View } from '../common/View';@@ -44,13 +45,20 @@ export function UpcomingLengthSettings() {<SettingprimaryAction={<View style={{ flexDirection: 'row', gap: '1em' }}>- <Column title="Upcoming Length">- <Select- options={options.map(x => [x.value || '7', x.label])}- value={upcomingLength}- onChange={newValue => setUpcomingLength(newValue)}- style={selectButtonStyle}- />+ <Column>+ <View+ style={{ flexDirection: 'row', alignItems: 'center', gap: 20 }}+ >+ <View title="Upcoming Length">+ <Select+ options={options.map(x => [x.value || '7', x.label])}+ value={upcomingLength}+ onChange={newValue => setUpcomingLength(newValue)}+ style={selectButtonStyle}+ />+ </View>+ <InfoBubble label="Only the first instance of a recurring transaction will be shown." />+ </View></Column></View>}diff --git a/upcoming-release-notes/3639.md b/upcoming-release-notes/3639.mdnew file mode 100644index 0000000000..4d8a7ad914--- /dev/null+++ b/upcoming-release-notes/3639.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [ SamBobBarnes ]+---++Add info text to Upcoming Length control.