fix: resolve TS2322 ref type error and Tailwind class conflict in Mascot
- Change SvgProps.svgRef to React.Ref<SVGSVGElement> for React 18 compat
- className now replaces default w-32/h-32 instead of appending (avoids
Tailwind specificity conflicts)
- Replace inline style={{ position: 'relative' }} with Tailwind 'relative'
This commit is contained in:
@@ -18,7 +18,7 @@ interface MascotProps {
|
|||||||
interface SvgProps {
|
interface SvgProps {
|
||||||
palette: (typeof MASCOT_PALETTES)[MascotState];
|
palette: (typeof MASCOT_PALETTES)[MascotState];
|
||||||
gradientId: string;
|
gradientId: string;
|
||||||
svgRef: React.RefObject<SVGSVGElement | null>;
|
svgRef: React.Ref<SVGSVGElement>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function IdleSvg({ palette, gradientId, svgRef }: SvgProps) {
|
function IdleSvg({ palette, gradientId, svgRef }: SvgProps) {
|
||||||
@@ -240,10 +240,8 @@ export function Mascot({ state, className }: MascotProps) {
|
|||||||
|
|
||||||
useMascotAnimation(svgRef, containerRef, state);
|
useMascotAnimation(svgRef, containerRef, state);
|
||||||
|
|
||||||
const classes = className ? `w-32 h-32 ${className}` : 'w-32 h-32';
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={containerRef} role="presentation" className={classes} style={{ position: 'relative' }}>
|
<div ref={containerRef} role="presentation" className={`relative ${className ?? 'w-32 h-32'}`}>
|
||||||
{state === 'idle' && <IdleSvg palette={palette} gradientId={gradientId} svgRef={svgRef} />}
|
{state === 'idle' && <IdleSvg palette={palette} gradientId={gradientId} svgRef={svgRef} />}
|
||||||
{state === 'sleeping' && <SleepingSvg palette={palette} gradientId={gradientId} svgRef={svgRef} />}
|
{state === 'sleeping' && <SleepingSvg palette={palette} gradientId={gradientId} svgRef={svgRef} />}
|
||||||
{state === 'excited' && <ExcitedSvg palette={palette} gradientId={gradientId} svgRef={svgRef} />}
|
{state === 'excited' && <ExcitedSvg palette={palette} gradientId={gradientId} svgRef={svgRef} />}
|
||||||
|
|||||||
@@ -94,11 +94,20 @@ describe('Mascot', () => {
|
|||||||
expect(shadow).toBeTruthy();
|
expect(shadow).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies custom className', () => {
|
it('applies custom className replacing default size', () => {
|
||||||
const { container } = render(<Mascot state="idle" className="w-48 h-48" />);
|
const { container } = render(<Mascot state="idle" className="w-48 h-48" />);
|
||||||
const wrapper = container.firstElementChild as HTMLElement;
|
const wrapper = container.firstElementChild as HTMLElement;
|
||||||
expect(wrapper.className).toContain('w-48');
|
expect(wrapper.className).toContain('w-48');
|
||||||
expect(wrapper.className).toContain('h-48');
|
expect(wrapper.className).toContain('h-48');
|
||||||
|
// Custom className replaces default w-32 h-32 to avoid Tailwind conflicts
|
||||||
|
expect(wrapper.className).not.toContain('w-32');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses default w-32 h-32 when no className provided', () => {
|
||||||
|
const { container } = render(<Mascot state="idle" />);
|
||||||
|
const wrapper = container.firstElementChild as HTMLElement;
|
||||||
|
expect(wrapper.className).toContain('w-32');
|
||||||
|
expect(wrapper.className).toContain('h-32');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders the sleeping mouth ellipse', () => {
|
it('renders the sleeping mouth ellipse', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user