Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ component library - minimalistic infrastructure #4169

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

MatissJanis
Copy link
Member

Creating a very minimalistic infrastructure for the shared component library. The intention is to eventually publish this to NPM as a package. Next - this package can be consumed in plugins to build beautiful UI that matches the UX of Actual.

More common components would need to be moved to this plugin before we open it up though. But I'll slowly work on moving everything over and updating import paths.

@actual-github-bot actual-github-bot bot changed the title ✨ component library - minimalistic infrastructure [WIP] ✨ component library - minimalistic infrastructure Jan 16, 2025
Copy link

netlify bot commented Jan 16, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 5eb9a5e
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/678c0e41a918b70008faf210
😎 Deploy Preview https://deploy-preview-4169.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Jan 16, 2025

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
14 6.61 MB → 6.61 MB (+170 B) +0.00%
Changeset
File Δ Size
home/runner/work/actual/actual/packages/component-library/src/theme.ts 🆕 +11.29 kB 0 B → 11.29 kB
home/runner/work/actual/actual/packages/component-library/src/Button.tsx 🆕 +4.97 kB 0 B → 4.97 kB
home/runner/work/actual/actual/packages/component-library/src/styles.ts 🆕 +2.86 kB 0 B → 2.86 kB
home/runner/work/actual/actual/packages/component-library/src/icons/Loading.tsx 🆕 +1.61 kB 0 B → 1.61 kB
home/runner/work/actual/actual/packages/component-library/src/icons/AnimatedLoading.tsx 🆕 +543 B 0 B → 543 B
home/runner/work/actual/actual/packages/component-library/src/tokens.ts 🆕 +410 B 0 B → 410 B
home/runner/work/actual/actual/packages/component-library/src/View.tsx 🆕 +366 B 0 B → 366 B
src/components/common/Button2.ts 🆕 +75 B 0 B → 75 B
src/components/common/View.ts 🆕 +20 B 0 B → 20 B
package.json 📈 +42 B (+1.39%) 2.95 kB → 2.99 kB
src/components/FatalError.tsx 📈 +2 B (+0.02%) 8.13 kB → 8.13 kB
src/style/styles.ts 📉 -2.84 kB (-62.41%) 4.55 kB → 1.71 kB
src/style/theme.tsx 📉 -11.29 kB (-83.71%) 13.49 kB → 2.2 kB
src/components/common/Button2.tsx 🔥 -4.97 kB (-100%) 4.97 kB → 0 B
src/icons/Loading.tsx 🔥 -1.61 kB (-100%) 1.61 kB → 0 B
src/icons/AnimatedLoading.tsx 🔥 -543 B (-100%) 543 B → 0 B
src/tokens.ts 🔥 -410 B (-100%) 410 B → 0 B
src/components/common/View.tsx 🔥 -362 B (-100%) 362 B → 0 B
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/index.js 4.27 MB → 4.27 MB (+170 B) +0.00%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/en.js 97.98 kB 0%
static/js/pt-BR.js 99.8 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/en-GB.js 97.12 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/uk.js 119.92 kB 0%
static/js/AppliedFilters.js 10.21 kB 0%
static/js/useAccountPreviewTransactions.js 1.63 kB 0%
static/js/narrow.js 84.68 kB 0%
static/js/wide.js 101.2 kB 0%
static/js/ReportRouter.js 1.59 MB 0%

Copy link
Contributor

github-actions bot commented Jan 16, 2025

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.33 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.js 1.33 MB 0%

@MatissJanis MatissJanis changed the title [WIP] ✨ component library - minimalistic infrastructure ✨ component library - minimalistic infrastructure Jan 16, 2025
Copy link
Contributor

coderabbitai bot commented Jan 16, 2025

Walkthrough

This pull request introduces a new component library package @actual-app/components within the project's workspace. It includes a new package.json file that specifies dependencies, peer dependencies, and exports for various components and assets. The changes also involve the creation of foundational components such as Button, View, and icons like AnimatedLoading and SvgLoading. Additionally, a new styles module, a theme object, and a tokens enumeration are defined to centralize styling and theming. The modifications include updating import paths in existing components within the desktop-client package to utilize the new library, ensuring a consistent and modular approach to UI components across the application.

Possibly related PRs

Suggested labels

sparkles: Merged

Suggested reviewers

  • joel-jeremy
  • MikesGlitch

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cff717f and 5eb9a5e.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (1)
  • packages/desktop-client/package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/desktop-client/package.json
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: typecheck
  • GitHub Check: test
  • GitHub Check: web
  • GitHub Check: build (macos-latest)
  • GitHub Check: crdt
  • GitHub Check: build (windows-latest)
  • GitHub Check: Analyze
  • GitHub Check: compare
  • GitHub Check: lint
  • GitHub Check: Wait for Netlify build to finish
  • GitHub Check: api
  • GitHub Check: build (ubuntu-latest)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (10)
packages/component-library/src/icons/AnimatedLoading.tsx (2)

7-10: Clarify the rotation degrees in keyframes

The rotation animation goes from -90deg to 666deg. Using 666deg is unconventional and might be confusing for future maintainers. Typically, a full rotation is 360deg.

Consider adjusting the keyframes to use full rotations for clarity:

 '0%': { transform: 'rotate(-90deg)' },
-'100%': { transform: 'rotate(666deg)' },
+'100%': { transform: 'rotate(270deg)' },

This change rotates from -90deg to 270deg, resulting in a full 360-degree rotation.


15-21: Enhance animation performance with will-change

Adding the will-change: transform property can hint to the browser to optimize the rendering of the animated element.

Apply this diff to include the will-change property:

 animationIterationCount: 'infinite',
 lineHeight: 0,
+willChange: 'transform',
packages/component-library/src/icons/Loading.tsx (1)

4-5: Optimize gradient ID generation to prevent unnecessary re-renders.

The current implementation generates a new gradient ID on every component mount. Consider using useMemo to optimize this:

-  const [gradientId] = useState('gradient-' + Math.random());
+  const gradientId = useMemo(() => 'gradient-' + Math.random(), []);
packages/desktop-client/src/style/styles.ts (1)

8-9: Consider adding migration guide in deprecation notice.

The deprecation notice should include guidance on how to migrate:

-/** @deprecated please import styles from '@actual-app/components/styles' */
+/**
+ * @deprecated Please import styles from '@actual-app/components/styles'
+ * Migration guide:
+ * 1. Update your imports to use '@actual-app/components/styles'
+ * 2. Replace any local style overrides with theme tokens
+ * @example
+ * import { styles } from '@actual-app/components/styles';
+ */
packages/component-library/src/styles.ts (1)

63-69: Consolidate media queries using a helper function.

Multiple media queries with similar breakpoints could be consolidated:

+const mediaQuery = (breakpoint: string, styles: CSSProperties) => ({
+  [`@media (min-width: ${breakpoint})`]: styles,
+});

 page: {
   flex: 1,
-  '@media (max-height: 550px)': {
-    minHeight: 700,
-  },
-  [`@media (min-width: ${tokens.breakpoint_small})`]: {
-    paddingTop: 36,
-  },
+  ...mediaQuery('(max-height: 550px)', { minHeight: 700 }),
+  ...mediaQuery(tokens.breakpoint_small, { paddingTop: 36 }),
 },

Also applies to: 74-77, 81-83

packages/desktop-client/src/components/FatalError.tsx (1)

Line range hint 18-24: Consider extracting error type definitions.

The error type definitions could be moved to a separate types file for better maintainability:

+// New file: types/errors.ts
+export type AppError = Error & {
+  type?: string;
+  IDBFailure?: boolean;
+  SharedArrayBufferMissing?: boolean;
+  BackendInitFailure?: boolean;
+};

-type AppError = Error & {
-  type?: string;
-  IDBFailure?: boolean;
-  SharedArrayBufferMissing?: boolean;
-  BackendInitFailure?: boolean;
-};
packages/component-library/src/theme.ts (2)

1-203: Consider organizing theme variables into logical groupings for better maintainability.

The theme object contains a comprehensive set of CSS variables, but organizing them into nested objects by component type would improve maintainability and make it easier to extend the theme system in the future.

Consider restructuring the theme object like this:

 export const theme = {
-  pageBackground: 'var(--color-pageBackground)',
+  page: {
+    background: 'var(--color-pageBackground)',
+    text: 'var(--color-pageText)',
+    // ... other page-related variables
+  },
+  button: {
+    primary: {
+      text: 'var(--color-buttonPrimaryText)',
+      // ... other primary button variables
+    },
+    normal: {
+      // ... normal button variables
+    },
+    // ... other button types
+  },
   // ... other components
 };

1-203: Consider adding TypeScript types for better type safety.

The theme object would benefit from TypeScript type definitions to ensure type safety when accessing theme values throughout the application.

Consider adding type definitions:

type ThemeColor = string;

interface ThemeColors {
  pageBackground: ThemeColor;
  pageText: ThemeColor;
  // ... other color definitions
}

export const theme: ThemeColors = {
  // ... existing theme object
};
packages/component-library/package.json (2)

2-4: Consider using 0.1.0 as the initial version.

Following SemVer conventions, 0.1.0 is typically used for initial development releases rather than 0.0.1, especially for packages intended for public release.

 {
   "name": "@actual-app/components",
-  "version": "0.0.1",
+  "version": "0.1.0",
   "license": "MIT",

8-11: Lock the react-aria-components version.

Since this is a new package, it's better to lock the dependency version to avoid potential breaking changes.

   "dependencies": {
     "@emotion/css": "^11.13.4",
-    "react-aria-components": "^1.4.1"
+    "react-aria-components": "1.4.1"
   },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 87428a7 and cff717f.

⛔ Files ignored due to path filters (2)
  • upcoming-release-notes/4169.md is excluded by !**/*.md
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (17)
  • packages/component-library/package.json (1 hunks)
  • packages/component-library/src/Button.tsx (1 hunks)
  • packages/component-library/src/View.tsx (1 hunks)
  • packages/component-library/src/icons/AnimatedLoading.tsx (1 hunks)
  • packages/component-library/src/icons/Loading.tsx (1 hunks)
  • packages/component-library/src/styles.ts (1 hunks)
  • packages/component-library/src/theme.ts (1 hunks)
  • packages/component-library/src/tokens.ts (1 hunks)
  • packages/desktop-client/package.json (1 hunks)
  • packages/desktop-client/src/components/FatalError.tsx (1 hunks)
  • packages/desktop-client/src/components/common/Button.tsx (1 hunks)
  • packages/desktop-client/src/components/common/Button2.ts (1 hunks)
  • packages/desktop-client/src/components/common/View.ts (1 hunks)
  • packages/desktop-client/src/icons/AnimatedLoading.tsx (1 hunks)
  • packages/desktop-client/src/style/styles.ts (1 hunks)
  • packages/desktop-client/src/style/theme.tsx (1 hunks)
  • packages/desktop-client/src/tokens.ts (1 hunks)
✅ Files skipped from review due to trivial changes (7)
  • packages/desktop-client/src/components/common/Button2.ts
  • packages/desktop-client/src/components/common/View.ts
  • packages/desktop-client/src/icons/AnimatedLoading.tsx
  • packages/desktop-client/src/components/common/Button.tsx
  • packages/component-library/src/Button.tsx
  • packages/component-library/src/View.tsx
  • packages/desktop-client/src/tokens.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/component-library/src/tokens.ts

[error] 31-31: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

🔇 Additional comments (4)
packages/desktop-client/src/style/theme.tsx (1)

99-99: Verify compatibility with centralized theme exports

By re-exporting everything from @actual-app/components/theme, ensure that any locally defined theme properties or overrides previously present in theme.tsx are accounted for in the new centralized theme. This change might affect components that relied on local theme customizations.

Do you want me to scan the codebase to identify any components that might be impacted by this change?

packages/desktop-client/src/style/styles.ts (1)

Line range hint 13-71: Verify scrollbar detection impact across platforms.

The scrollbar detection logic is platform-specific. Ensure this works correctly with the new centralized styles.

✅ Verification successful

Scrollbar detection implementation is properly centralized and platform-aware

The scrollbar detection logic is correctly implemented with a clean separation of concerns:

  • Base style structure defined in component-library
  • Platform-specific detection and styling centralized in desktop-client
  • No conflicting implementations found across the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for platform-specific style overrides
rg -l "scrollbar" --type ts --type tsx

Length of output: 66


Script:

#!/bin/bash
# Search for scrollbar-related code in .ts files
rg "scrollbar" --type ts -l

# Search for Platform.env usage
rg "Platform\.env" --type ts -l

# Search for imports of styles.ts
rg "from.*style.?/styles" --type ts -l

Length of output: 1483


Script:

#!/bin/bash
# Check component-library scrollbar implementation
cat packages/component-library/src/styles.ts

# Search for other platform checks that might affect scrollbars
rg -g "*.ts" -g "*.tsx" "(Platform|platform).*(\bweb\b|\bdesktop\b|\bmobile\b)" -l

Length of output: 3671

packages/component-library/src/styles.ts (1)

100-100: Add documentation for the commented line-height TODO.

The TODO comment should be addressed or documented properly:

packages/desktop-client/src/components/FatalError.tsx (1)

4-5: Verify all component imports are migrated consistently.

Check if other components like Block, Link, etc., should also be migrated to the component library.

packages/component-library/src/tokens.ts Show resolved Hide resolved
packages/component-library/src/styles.ts Show resolved Hide resolved
packages/component-library/package.json Show resolved Hide resolved
packages/desktop-client/package.json Show resolved Hide resolved
Copy link
Contributor

@jfdoming jfdoming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look good. Wondering how you're thinking about backward compatibility in the future if we want to do a breaking change in the interface of a component? I feel like we should codify something to protect plugin users a bit, e.g. "Announce breaking changes one release before they are implemented"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants