Skip to content

A local-first personal finance app

:recycle: (components) moving Input component to comp. library (#4563)

Matiss Janis Aboltinsf2267587c845
diff --git a/packages/component-library/package.json b/packages/component-library/package.json
index e4dc7c331f..8ed9ccf9c8 100644
--- a/packages/component-library/package.json
+++ b/packages/component-library/package.json
@@ -28,6 +28,7 @@
"./form-error": "./src/FormError.tsx",
"./initial-focus": "./src/InitialFocus.ts",
"./inline-field": "./src/InlineField.tsx",
+ "./input": "./src/Input.tsx",
"./label": "./src/Label.tsx",
"./menu": "./src/Menu.tsx",
"./paragraph": "./src/Paragraph.tsx",
diff --git a/packages/desktop-client/src/components/common/Input.tsx b/packages/component-library/src/Input.tsx
similarity index 94%
rename from packages/desktop-client/src/components/common/Input.tsx
rename to packages/component-library/src/Input.tsx
index 4f9573f6cc..deb0e0a303 100644
--- a/packages/desktop-client/src/components/common/Input.tsx
+++ b/packages/component-library/src/Input.tsx
@@ -4,10 +4,11 @@ import React, {
type Ref,
} from 'react';
-import { styles, type CSSProperties } from '@actual-app/components/styles';
-import { theme } from '@actual-app/components/theme';
import { css, cx } from '@emotion/css';
+import { styles, type CSSProperties } from './styles';
+import { theme } from './theme';
+
export const defaultInputStyle = {
outline: 0,
backgroundColor: theme.tableBackground,
diff --git a/packages/desktop-client/src/components/common/InfoBubble.tsx b/packages/desktop-client/src/components/common/InfoBubble.tsx
deleted file mode 100644
index 69d7f271e3..0000000000
--- a/packages/desktop-client/src/components/common/InfoBubble.tsx
+++ /dev/null
@@ -1,68 +0,0 @@
-import React, { useState } from 'react';
-import { useLocation } from 'react-router-dom';
-
-import { Text } from '@actual-app/components/text';
-import { View } from '@actual-app/components/view';
-
-import { SvgInformationCircle } from '../../icons/v2';
-import { theme } from '../../style';
-
-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/common/Input.ts b/packages/desktop-client/src/components/common/Input.ts
new file mode 100644
index 0000000000..9b76602e5a
--- /dev/null
+++ b/packages/desktop-client/src/components/common/Input.ts
@@ -0,0 +1,10 @@
+import {
+ BigInput as ActualBigInput,
+ Input as ActualInput,
+} from '@actual-app/components/input';
+
+/** @deprecated please import this directly from `@actual-app/components/input` */
+export const Input = ActualInput;
+
+/** @deprecated please import this directly from `@actual-app/components/input` */
+export const BigInput = ActualBigInput;
diff --git a/packages/desktop-client/src/components/common/InputWithContent.tsx b/packages/desktop-client/src/components/common/InputWithContent.tsx
index 0c02931704..e1ffc8ffc4 100644
--- a/packages/desktop-client/src/components/common/InputWithContent.tsx
+++ b/packages/desktop-client/src/components/common/InputWithContent.tsx
@@ -1,11 +1,10 @@
import { useState, type ComponentProps, type ReactNode } from 'react';
+import { Input, defaultInputStyle } from '@actual-app/components/input';
+import { type CSSProperties } from '@actual-app/components/styles';
+import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
-import { theme, type CSSProperties } from '../../style';
-
-import { Input, defaultInputStyle } from './Input';
-
type InputWithContentProps = ComponentProps<typeof Input> & {
leftContent?: ReactNode;
rightContent?: ReactNode;
diff --git a/packages/desktop-client/src/style/styles.ts b/packages/desktop-client/src/style/styles.ts
index 5ea78501c7..e034de44b9 100644
--- a/packages/desktop-client/src/style/styles.ts
+++ b/packages/desktop-client/src/style/styles.ts
@@ -1,9 +1,13 @@
// @ts-strict-ignore
-import { styles } from '@actual-app/components/styles';
+import {
+ styles,
+ type CSSProperties as ActualCSSProperties,
+} from '@actual-app/components/styles';
import * as Platform from 'loot-core/client/platform';
-export { type CSSProperties } from '@actual-app/components/styles';
+/** @deprecated please import this directly from `@actual-app/components/styles` */
+export type CSSProperties = ActualCSSProperties;
let hiddenScrollbars = false;
diff --git a/upcoming-release-notes/4563.md b/upcoming-release-notes/4563.md
new file mode 100644
index 0000000000..aaa2153798
--- /dev/null
+++ b/upcoming-release-notes/4563.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [MatissJanis]
+---
+
+Moving `Input` component to the component library.