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

Consolidate Link props #2558

Merged
merged 12 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ module.exports = {
'Using default React import is discouraged, please use named exports directly instead.',
},
{
// forbid <a> in favor of <LinkButton> or <ExternalLink>
// forbid <a> in favor of <Button type={'link'}> or <ExternalLink>
carkom marked this conversation as resolved.
Show resolved Hide resolved
selector: 'JSXOpeningElement[name.name="a"]',
message:
'Using <a> is discouraged, please use <LinkButton> or <ExternalLink> instead.',
'Using <a> is discouraged, please use <Button type={link}> or <ExternalLink> instead.',
carkom marked this conversation as resolved.
Show resolved Hide resolved
},
],
'no-restricted-imports': [
Expand Down
13 changes: 9 additions & 4 deletions packages/desktop-client/src/components/FatalError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React, { useState } from 'react';
import { Block } from './common/Block';
import { Button } from './common/Button';
import { ExternalLink } from './common/ExternalLink';
import { LinkButton } from './common/LinkButton';
import { Modal } from './common/Modal';
import { Paragraph } from './common/Paragraph';
import { Stack } from './common/Stack';
Expand Down Expand Up @@ -146,9 +145,13 @@ function SharedArrayBufferOverride() {
</Button>
</>
) : (
<LinkButton onClick={() => setExpanded(true)} style={{ marginLeft: 5 }}>
<Button
type="link"
onClick={() => setExpanded(true)}
style={{ marginLeft: 5 }}
>
Advanced options
</LinkButton>
</Button>
);
}

Expand All @@ -171,7 +174,9 @@ export function FatalError({ buttonText, error }: FatalErrorProps) {
</Button>
</Paragraph>
<Paragraph isLast={true} style={{ fontSize: 11 }}>
<LinkButton onClick={() => setShowError(true)}>Show Error</LinkButton>
<Button type="link" onClick={() => setShowError(true)}>
Show Error
</Button>
{showError && (
<Block
style={{
Expand Down
6 changes: 3 additions & 3 deletions packages/desktop-client/src/components/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { styles, theme, type CSSProperties } from '../style';

import { Button, ButtonWithLoading } from './common/Button';
import { ExternalLink } from './common/ExternalLink';
import { LinkButton } from './common/LinkButton';
import { Stack } from './common/Stack';
import { Text } from './common/Text';
import { View } from './common/View';
Expand All @@ -43,7 +42,8 @@ function compileMessage(
if (href[0] === '#') {
const actionName = href.slice(1);
return (
<LinkButton
<Button
type="link"
key={idx}
onClick={async e => {
e.preventDefault();
Expand All @@ -55,7 +55,7 @@ function compileMessage(
}}
>
{text}
</LinkButton>
</Button>
);
}

Expand Down
11 changes: 6 additions & 5 deletions packages/desktop-client/src/components/UpdateNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { SvgClose } from '../icons/v1';
import { theme } from '../style';

import { Button } from './common/Button';
import { LinkButton } from './common/LinkButton';
import { Text } from './common/Text';
import { View } from './common/View';

Expand Down Expand Up @@ -45,17 +44,19 @@ export function UpdateNotification() {
<View style={{ flex: 1 }} />
<View style={{ marginTop: -1 }}>
<Text>
<LinkButton
<Button
type="link"
onClick={updateApp}
style={{
color: theme.buttonPrimaryText,
textDecoration: 'underline',
}}
>
Restart
</LinkButton>{' '}
</Button>{' '}
(
<LinkButton
<Button
type="link"
style={{
color: theme.buttonPrimaryText,
textDecoration: 'underline',
Expand All @@ -67,7 +68,7 @@ export function UpdateNotification() {
}
>
notes
</LinkButton>
</Button>
)
<Button
type="bare"
Expand Down
40 changes: 0 additions & 40 deletions packages/desktop-client/src/components/common/AnchorLink.tsx

This file was deleted.

35 changes: 0 additions & 35 deletions packages/desktop-client/src/components/common/ButtonLink.tsx

This file was deleted.

37 changes: 17 additions & 20 deletions packages/desktop-client/src/components/common/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React, {
type ComponentProps,
type MouseEvent,
type ReactNode,
} from 'react';
import React, { type ComponentProps, type ReactNode } from 'react';
import { NavLink, useMatch } from 'react-router-dom';

import { css } from 'glamor';

import { type CustomReportEntity } from 'loot-core/types/models/reports';

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

Expand All @@ -22,23 +20,12 @@ type AnchorLinkProps = {
style?: CSSProperties;
activeStyle?: CSSProperties;
children?: ReactNode;
report?: CustomReportEntity;
};

const ButtonLink = ({
to,
style,
activeStyle,
onClick,
...props
}: ButtonLinkProps) => {
const ButtonLink = ({ to, style, activeStyle, ...props }: ButtonLinkProps) => {
const navigate = useNavigate();
const match = useMatch({ path: to });

const handleClick = (e: MouseEvent<HTMLButtonElement>) => {
onClick?.(e);
navigate(to);
};

return (
<Button
style={{
Expand All @@ -47,17 +34,27 @@ const ButtonLink = ({
}}
activeStyle={activeStyle}
{...props}
onClick={handleClick}
onClick={e => {
props.onClick?.(e);
navigate(to);
}}
/>
);
};

const AnchorLink = ({ to, style, activeStyle, children }: AnchorLinkProps) => {
const AnchorLink = ({
to,
style,
activeStyle,
children,
report,
}: AnchorLinkProps) => {
const match = useMatch({ path: to });

return (
<NavLink
to={to}
state={report ? { report } : {}}
className={`${css([
styles.smallText,
style,
Expand Down
39 changes: 0 additions & 39 deletions packages/desktop-client/src/components/common/LinkButton.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { send } from 'loot-core/platform/client/fetch';
import { SvgAdd } from '../../../icons/v1';
import { SvgSearchAlternate } from '../../../icons/v2';
import { styles, theme } from '../../../style';
import { ButtonLink } from '../../common/ButtonLink';
import { InputWithContent } from '../../common/InputWithContent';
import { Label } from '../../common/Label';
import { Link } from '../../common/Link';
import { Text } from '../../common/Text';
import { View } from '../../common/View';
import { MobileBackButton } from '../../MobileBackButton';
Expand Down Expand Up @@ -174,7 +174,8 @@ export function AccountDetails({
}
headerLeftContent={<MobileBackButton />}
headerRightContent={
<ButtonLink
<Link
variant="button"
to="transactions/new"
type="bare"
aria-label="Add Transaction"
Expand All @@ -190,7 +191,7 @@ export function AccountDetails({
activeStyle={{ background: 'transparent' }}
>
<SvgAdd width={20} height={20} />
</ButtonLink>
</Link>
}
padding={0}
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { AccountAutocomplete } from '../autocomplete/AccountAutocomplete';
import { CategoryAutocomplete } from '../autocomplete/CategoryAutocomplete';
import { Button } from '../common/Button';
import { FormError } from '../common/FormError';
import { LinkButton } from '../common/LinkButton';
import { Modal } from '../common/Modal';
import { Paragraph } from '../common/Paragraph';
import { Text } from '../common/Text';
Expand Down Expand Up @@ -218,7 +217,8 @@ export function CloseAccountModal({
<View style={{ marginBottom: 15 }}>
<Text style={{ fontSize: 12 }}>
You can also{' '}
<LinkButton
<Button
type="link"
onClick={() => {
setLoading(true);

Expand All @@ -228,7 +228,7 @@ export function CloseAccountModal({
style={{ color: theme.errorText }}
>
force close
</LinkButton>{' '}
</Button>{' '}
the account which will delete it and all its transactions
permanently. Doing so may change your budget unexpectedly
since money in it may vanish.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { Error, Warning } from '../alerts';
import { Autocomplete } from '../autocomplete/Autocomplete';
import { Button } from '../common/Button';
import { ExternalLink } from '../common/ExternalLink';
import { LinkButton } from '../common/LinkButton';
import { Menu } from '../common/Menu';
import { Modal } from '../common/Modal';
import { Paragraph } from '../common/Paragraph';
Expand Down Expand Up @@ -169,12 +168,13 @@ export function GoCardlessExternalMsg({
<Error>
Failed loading available banks: GoCardless access credentials might
be misconfigured. Please{' '}
<LinkButton
<Button
type="link"
onClick={onGoCardlessInit}
style={{ color: theme.formLabelText, display: 'inline' }}
>
set them up
</LinkButton>{' '}
</Button>{' '}
again.
</Error>
) : (
Expand Down Expand Up @@ -297,9 +297,9 @@ export function GoCardlessExternalMsg({
</View>

{waiting === 'browser' && (
<LinkButton onClick={onJump} style={{ marginTop: 10 }}>
<Button type="link" onClick={onJump} style={{ marginTop: 10 }}>
(Account linking not opening in a new tab? Click here)
</LinkButton>
</Button>
)}
</View>
) : success ? (
Expand Down
Loading
Loading