Skip to content

Commit 1113be3

Browse files
authored
refactor(shared/components): remove forwardRef, unused files (#1151)
1 parent f6d6bf4 commit 1113be3

7 files changed

Lines changed: 83 additions & 210 deletions

File tree

src/pages/shared/components/ErrorMessage.tsx

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,36 @@ import React from 'react';
22
import { XIcon } from './Icons';
33
import { cn } from '@/pages/shared/lib/utils';
44

5-
interface ErrorMessageProps extends React.HTMLAttributes<HTMLDivElement> {
5+
interface ErrorMessageProps extends React.ComponentPropsWithRef<'div'> {
66
error?: string;
77
}
8-
export const ErrorMessage = React.forwardRef<HTMLDivElement, ErrorMessageProps>(
9-
({ error, className, children, ...props }, ref) => {
10-
if (!error) return null;
8+
export const ErrorMessage = ({
9+
error,
10+
className,
11+
children,
12+
ref,
13+
...props
14+
}: ErrorMessageProps) => {
15+
if (!error) return null;
1116

12-
return (
13-
<div
14-
{...props}
15-
data-testid="ErrorMessage"
16-
ref={ref}
17-
className={cn(
18-
'break-word mb-4 flex items-center gap-2 rounded-xl border border-red-300 bg-red-500/10 px-3 py-2',
19-
className,
20-
)}
21-
role="alert"
22-
>
23-
<XIcon className="size-8 text-red-500" />
24-
<div>
25-
<span>{error}</span>
26-
{children}
27-
</div>
17+
return (
18+
<div
19+
{...props}
20+
data-testid="ErrorMessage"
21+
ref={ref}
22+
className={cn(
23+
'break-word mb-4 flex items-center gap-2 rounded-xl border border-red-300 bg-red-500/10 px-3 py-2',
24+
className,
25+
)}
26+
role="alert"
27+
>
28+
<XIcon className="size-8 text-red-500" />
29+
<div>
30+
<span>{error}</span>
31+
{children}
2832
</div>
29-
);
30-
},
31-
);
33+
</div>
34+
);
35+
};
3236

3337
ErrorMessage.displayName = 'ErrorMessage';

src/pages/shared/components/WarningMessage.tsx

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import { forwardRef } from 'react';
32
import { type VariantProps, cva } from 'class-variance-authority';
43

54
import { LoadingSpinner } from '@/pages/shared/components/LoadingSpinner';
@@ -39,50 +38,46 @@ const buttonVariants = cva(
3938

4039
export interface ButtonProps
4140
extends VariantProps<typeof buttonVariants>,
42-
React.ButtonHTMLAttributes<HTMLButtonElement> {
41+
React.ComponentPropsWithRef<'button'> {
4342
loading?: boolean;
4443
loadingText?: string;
4544
/** Optional only when children are passed */
4645
'aria-label'?: string;
4746
}
4847

49-
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
50-
function Button(
51-
{
52-
variant,
53-
size,
54-
fullWidth,
55-
loading = false,
56-
loadingText,
57-
className,
58-
type = 'button',
59-
children,
60-
...props
61-
},
62-
ref,
63-
) {
64-
return (
65-
<button
66-
ref={ref}
67-
type={type}
68-
className={cn(
69-
buttonVariants({ variant, size, fullWidth, loading }),
70-
className,
71-
)}
72-
data-progress={loading.toString()}
73-
disabled={props.disabled ?? loading ?? false}
74-
aria-disabled={props.disabled ?? loading ?? false}
75-
{...props}
76-
>
77-
{loading ? (
78-
<>
79-
<LoadingSpinner />
80-
{loadingText}
81-
</>
82-
) : (
83-
children
84-
)}
85-
</button>
86-
);
87-
},
88-
);
48+
export function Button({
49+
variant,
50+
size,
51+
fullWidth,
52+
loading = false,
53+
loadingText,
54+
className,
55+
type = 'button',
56+
ref,
57+
children,
58+
...props
59+
}: ButtonProps) {
60+
return (
61+
<button
62+
ref={ref}
63+
type={type}
64+
className={cn(
65+
buttonVariants({ variant, size, fullWidth, loading }),
66+
className,
67+
)}
68+
data-progress={loading.toString()}
69+
disabled={props.disabled ?? loading ?? false}
70+
aria-disabled={props.disabled ?? loading ?? false}
71+
{...props}
72+
>
73+
{loading ? (
74+
<>
75+
<LoadingSpinner />
76+
{loadingText}
77+
</>
78+
) : (
79+
children
80+
)}
81+
</button>
82+
);
83+
}

src/pages/shared/components/ui/Label.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ const labelVariants = cva(
99

1010
export interface LabelProps
1111
extends VariantProps<typeof labelVariants>,
12-
React.LabelHTMLAttributes<HTMLLabelElement> {
12+
React.ComponentPropsWithRef<'label'> {
1313
children: React.ReactNode;
1414
}
1515

16-
export const Label = React.forwardRef<HTMLLabelElement, LabelProps>(
17-
function Label({ className, children, ...props }, ref) {
18-
return (
19-
// biome-ignore lint/a11y/noLabelWithoutControl: We add the relevant props to the label
20-
<label ref={ref} className={cn(labelVariants(), className)} {...props}>
21-
{children}
22-
</label>
23-
);
24-
},
25-
);
16+
export function Label({ className, children, ref, ...props }: LabelProps) {
17+
return (
18+
// biome-ignore lint/a11y/noLabelWithoutControl: We add the relevant props to the label
19+
<label ref={ref} className={cn(labelVariants(), className)} {...props}>
20+
{children}
21+
</label>
22+
);
23+
}

src/pages/shared/components/ui/Slider.tsx

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/pages/shared/components/ui/Switch.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { type VariantProps, cva } from 'class-variance-authority';
22
import React from 'react';
3-
import { forwardRef } from 'react';
43

54
import { cn } from '@/pages/shared/lib/utils';
65

@@ -35,17 +34,22 @@ const switchVariants = cva(
3534

3635
export interface SwitchProps
3736
extends VariantProps<typeof switchVariants>,
38-
React.HTMLAttributes<HTMLInputElement> {
37+
Omit<React.ComponentPropsWithRef<'input'>, 'size'> {
3938
checked?: boolean;
4039
disabled?: boolean;
4140
label?: string;
4241
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
4342
}
4443

45-
export const Switch = forwardRef<HTMLInputElement, SwitchProps>(function Switch(
46-
{ size, label, className, disabled = false, onChange = () => {}, ...props },
44+
export function Switch({
45+
size,
46+
label,
47+
className,
48+
disabled = false,
49+
onChange = () => {},
4750
ref,
48-
) {
51+
...props
52+
}: SwitchProps) {
4953
return (
5054
<label className="flex items-center gap-x-4">
5155
<input
@@ -63,4 +67,4 @@ export const Switch = forwardRef<HTMLInputElement, SwitchProps>(function Switch(
6367
{label ? <span className="font-normal">{label}</span> : null}
6468
</label>
6569
);
66-
});
70+
}

src/pages/shared/components/ui/__tests__/Slider.test.tsx

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)