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

@emotion/css as drop-in replacement for abandoned glamor library #3471

Merged
merged 25 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions packages/desktop-client/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
import { type CSSObject } from '@emotion/css/dist/declarations/src/create-instance';

// Allow images to be imported
declare module '*.png';

declare module 'react' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions, @typescript-eslint/no-empty-object-type
interface CSSProperties extends CSSObject {}
}
2 changes: 1 addition & 1 deletion packages/desktop-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"build"
],
"devDependencies": {
"@emotion/css": "^11.13.4",
"@fontsource/redacted-script": "^5.0.21",
"@juggle/resize-observer": "^3.4.0",
"@playwright/test": "1.41.1",
Expand Down Expand Up @@ -36,7 +37,6 @@
"debounce": "^1.2.1",
"downshift": "7.6.2",
"focus-visible": "^4.1.5",
"glamor": "^2.20.40",
"i18next": "^23.11.5",
"i18next-parser": "^9.0.0",
"i18next-resources-to-backend": "^1.2.1",
Expand Down
5 changes: 2 additions & 3 deletions packages/desktop-client/src/components/AnimatedRefresh.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// @ts-strict-ignore
import React from 'react';
import React, { type CSSProperties } from 'react';

import { keyframes } from 'glamor';
import { keyframes } from '@emotion/css';

import { SvgRefresh } from '../icons/v1';
import { type CSSProperties } from '../style';

import { View } from './common/View';

Expand Down
6 changes: 3 additions & 3 deletions packages/desktop-client/src/components/AppBackground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { useSelector } from 'react-redux';
import { useTransition, animated } from 'react-spring';

import { css } from 'glamor';
import { css } from '@emotion/css';

import { AnimatedLoading } from '../icons/AnimatedLoading';
import { theme } from '../style';
Expand Down Expand Up @@ -33,7 +33,7 @@ export function AppBackground({ isLoading }: AppBackgroundProps) {
transitions((style, item) => (
<animated.div key={item} style={style}>
<View
className={`${css({
className={css({
position: 'absolute',
top: 0,
left: 0,
Expand All @@ -42,7 +42,7 @@ export function AppBackground({ isLoading }: AppBackgroundProps) {
paddingTop: 200,
color: theme.pageText,
alignItems: 'center',
})}`}
})}
>
<Block style={{ marginBottom: 20, fontSize: 18 }}>
{loadingText}
Expand Down
3 changes: 1 addition & 2 deletions packages/desktop-client/src/components/FixedSizeList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import {
type Ref,
type MutableRefObject,
type UIEvent,
type CSSProperties,
} from 'react';

import memoizeOne from 'memoize-one';

import { type CSSProperties } from '../style';

import { View } from './common/View';

const IS_SCROLLING_DEBOUNCE_INTERVAL = 150;
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop-client/src/components/LoggedInUser.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @ts-strict-ignore
import React, { useState, useEffect, useRef } from 'react';
import React, { useState, useEffect, useRef, type CSSProperties } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';

import { type State } from 'loot-core/src/client/state-types';

import { useActions } from '../hooks/useActions';
import { theme, styles, type CSSProperties } from '../style';
import { theme, styles } from '../style';

import { Button } from './common/Button2';
import { Menu } from './common/Menu';
Expand Down
11 changes: 4 additions & 7 deletions packages/desktop-client/src/components/ManageRules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,14 @@ export function ManageRules({
const { list: categories } = useCategories();
const payees = usePayees();
const accounts = useAccounts();
const state = {
payees,
accounts,
schedules,
};
const filterData = useMemo(
() => ({
...state,
payees,
accounts,
schedules,
categories,
}),
[state, categories],
[payees, accounts, schedules, categories],
);

const filteredRules = useMemo(
Expand Down
12 changes: 6 additions & 6 deletions packages/desktop-client/src/components/Notes.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @ts-strict-ignore
import React, { useEffect, useRef } from 'react';
import React, { useEffect, useRef, type CSSProperties } from 'react';
import ReactMarkdown from 'react-markdown';

import { css } from 'glamor';
import { css } from '@emotion/css';
import remarkGfm from 'remark-gfm';

import { useResponsive } from '../ResponsiveProvider';
import { type CSSProperties, theme } from '../style';
import { theme } from '../style';
import { remarkBreaks, sequentialNewlinesPlugin } from '../util/markdown';

import { Text } from './common/Text';
Expand Down Expand Up @@ -110,22 +110,22 @@ export function Notes({
return editable ? (
<textarea
ref={textAreaRef}
className={`${css({
className={css({
border: '1px solid ' + theme.buttonNormalBorder,
padding: 7,
...(!isNarrowWidth && { minWidth: 350, minHeight: 120 }),
outline: 'none',
backgroundColor: theme.tableBackground,
color: theme.tableText,
...getStyle?.(editable),
})}`}
})}
value={notes || ''}
onChange={e => onChange?.(e.target.value)}
onBlur={e => onBlur?.(e.target.value)}
placeholder="Notes (markdown supported)"
/>
) : (
<Text {...markdownStyles} style={{ ...getStyle?.(editable) }}>
<Text className={css([markdownStyles, getStyle?.(editable)])}>
<ReactMarkdown remarkPlugins={remarkPlugins} linkTarget="_blank">
{notes}
</ReactMarkdown>
Expand Down
10 changes: 8 additions & 2 deletions packages/desktop-client/src/components/NotesButton.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import React, { useEffect, useRef, useState, type ComponentProps } from 'react';
import React, {
useEffect,
useRef,
useState,
type ComponentProps,
type CSSProperties,
} from 'react';

import { send } from 'loot-core/src/platform/client/fetch';

import { useNotes } from '../hooks/useNotes';
import { SvgCustomNotesPaper } from '../icons/v2';
import { type CSSProperties, theme } from '../style';
import { theme } from '../style';

import { Button } from './common/Button2';
import { Popover } from './common/Popover';
Expand Down
49 changes: 24 additions & 25 deletions packages/desktop-client/src/components/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import React, {
useEffect,
useMemo,
type SetStateAction,
type CSSProperties,
} from 'react';
import { useDispatch, useSelector } from 'react-redux';

import { css } from 'glamor';
import { css } from '@emotion/css';

import { removeNotification } from 'loot-core/client/actions';
import { type State } from 'loot-core/src/client/state-types';
Expand All @@ -16,7 +17,7 @@ import type { NotificationWithId } from 'loot-core/src/client/state-types/notifi
import { AnimatedLoading } from '../icons/AnimatedLoading';
import { SvgDelete } from '../icons/v0';
import { useResponsive } from '../ResponsiveProvider';
import { styles, theme, type CSSProperties } from '../style';
import { styles, theme } from '../style';

import { Button, ButtonWithLoading } from './common/Button2';
import { Link } from './common/Link';
Expand Down Expand Up @@ -202,29 +203,27 @@ function Notification({
onRemove();
setLoading(false);
}}
className={String(
css({
backgroundColor: 'transparent',
border: `1px solid ${
positive
? theme.noticeBorder
: error
? theme.errorBorder
: theme.warningBorder
}`,
color: 'currentColor',
...styles.mediumText,
flexShrink: 0,
'&[data-hovered], &[data-pressed]': {
backgroundColor: positive
? theme.noticeBackground
: error
? theme.errorBackground
: theme.warningBackground,
},
...narrowStyle,
}),
)}
className={css({
backgroundColor: 'transparent',
border: `1px solid ${
positive
? theme.noticeBorder
: error
? theme.errorBorder
: theme.warningBorder
}`,
color: 'currentColor',
...styles.mediumText,
flexShrink: 0,
'&[data-hovered], &[data-pressed]': {
backgroundColor: positive
? theme.noticeBackground
: error
? theme.errorBackground
: theme.warningBackground,
},
...narrowStyle,
})}
>
{button.title}
</ButtonWithLoading>
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop-client/src/components/Page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { type ReactNode } from 'react';
import React, { type ReactNode, type CSSProperties } from 'react';

import { useResponsive } from '../ResponsiveProvider';
import { theme, styles, type CSSProperties } from '../style';
import { theme, styles } from '../style';

import { Text } from './common/Text';
import { View } from './common/View';
Expand Down
14 changes: 7 additions & 7 deletions packages/desktop-client/src/components/PrivacyFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, {
type ReactNode,
} from 'react';

import { css } from 'glamor';
import { css } from '@emotion/css';

import { usePrivacyMode } from '../hooks/usePrivacyMode';
import { useResponsive } from '../ResponsiveProvider';
Expand Down Expand Up @@ -73,7 +73,7 @@ function PrivacyOverlay({ children, ...props }) {

return (
<View
className={`${css(
className={css(
[
{
display: 'inline-flex',
Expand All @@ -96,23 +96,23 @@ function PrivacyOverlay({ children, ...props }) {
},
],
style,
)}`}
)}
{...restProps}
>
<div
className={`${css([
className={css([
{
display: 'flex',
flexGrow: 1,
},
])}`}
])}
>
{children}
</div>

<div
aria-hidden="true"
className={`${css({
className={css({
flexDirection: 'column',
fontFamily: 'Redacted Script',
height: '100%',
Expand All @@ -121,7 +121,7 @@ function PrivacyOverlay({ children, ...props }) {
pointerEvents: 'none',
position: 'absolute',
width: '100%',
})}`}
})}
>
{children}
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop-client/src/components/ThemeSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useRef, useState } from 'react';
import React, { useRef, useState, type CSSProperties } from 'react';

import type { Theme } from 'loot-core/src/types/prefs';

import { SvgMoonStars, SvgSun, SvgSystem } from '../icons/v2';
import { useResponsive } from '../ResponsiveProvider';
import { type CSSProperties, themeOptions, useTheme } from '../style';
import { themeOptions, useTheme } from '../style';

import { Button } from './common/Button2';
import { Menu } from './common/Menu';
Expand Down
38 changes: 18 additions & 20 deletions packages/desktop-client/src/components/Titlebar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, type CSSProperties } from 'react';
import { useHotkeys } from 'react-hotkeys-hook';
import { Routes, Route, useLocation } from 'react-router-dom';

import { css } from 'glamor';
import { css } from '@emotion/css';

import * as Platform from 'loot-core/src/client/platform';
import * as queries from 'loot-core/src/client/queries';
Expand All @@ -22,7 +22,7 @@ import {
SvgViewShow,
} from '../icons/v2';
import { useResponsive } from '../ResponsiveProvider';
import { theme, type CSSProperties, styles } from '../style';
import { theme, styles } from '../style';

import { AccountSyncCheck } from './accounts/AccountSyncCheck';
import { AnimatedRefresh } from './AnimatedRefresh';
Expand Down Expand Up @@ -204,23 +204,21 @@ function SyncButton({ style, isMobile = false }: SyncButtonProps) {
<Button
variant="bare"
aria-label="Sync"
className={String(
css({
...(isMobile
? {
...style,
WebkitAppRegion: 'none',
...mobileIconStyle,
}
: {
...style,
WebkitAppRegion: 'none',
color: desktopColor,
}),
'&[data-hovered]': hoveredStyle,
'&[data-pressed]': activeStyle,
}),
)}
className={css({
...(isMobile
? {
...style,
WebkitAppRegion: 'none',
...mobileIconStyle,
}
: {
...style,
WebkitAppRegion: 'none',
color: desktopColor,
}),
'&[data-hovered]': hoveredStyle,
'&[data-pressed]': activeStyle,
})}
onPress={sync}
>
{isMobile ? (
Expand Down
Loading