Skip to content

Commit

Permalink
feat: add fwd ref, rm unused JSX exports
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-anderson committed Feb 20, 2024
1 parent 185dede commit 0daf0ce
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions src/components/Icons/InvoiceStatusIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import SvgIcon, { type SvgIconProps } from "@mui/material/SvgIcon";
import React, { forwardRef } from "react";
import DollarCheckmarkIcon from "@mui/icons-material/PriceCheckRounded";
import ExclamationMarkIcon from "@mui/icons-material/PriorityHighRounded";
import { useMaybeRef } from "@/hooks/useMaybeRef";
import { FileInvoiceDollarIcon } from "./FileInvoiceDollarIcon";
import type { InvoiceStatus } from "@graphql/types";
import type { InvoiceStatus } from "@/graphql/types";
import type { SvgIconProps } from "@mui/material/SvgIcon";

export const InvoiceStatusIcon = ({ status, ...props }: InvoiceStatusIconProps) => {
const InvStatusIcon = INV_STATUS_ICONS[status];
export const InvoiceStatusIcon = forwardRef<SVGSVGElement, InvoiceStatusIconProps>(
function InvoiceStatusIcon({ status, ...svgIconProps }, ref) {
const svgRef = useMaybeRef(ref);

return <InvStatusIcon {...props} />;
};
const StatusIcon = INVOICE_STATUS_ICONS[status];

export const INV_STATUS_ICONS: Record<InvoiceStatus, typeof SvgIcon> = {
OPEN: FileInvoiceDollarIcon as typeof SvgIcon,
return <StatusIcon ref={svgRef} {...svgIconProps} />;
}
);

/**
* Map of {@link InvoiceStatus|Invoice statuses} to their corresponding icon component.
*/
export const INVOICE_STATUS_ICONS = {
OPEN: FileInvoiceDollarIcon,
CLOSED: DollarCheckmarkIcon,
DISPUTED: ExclamationMarkIcon,
};
} as const satisfies Record<InvoiceStatus, React.ComponentType>;

export const INV_STATUS_ICON_REACT_NODES: Record<InvoiceStatus, React.ReactElement> = {
OPEN: <FileInvoiceDollarIcon />,
CLOSED: <DollarCheckmarkIcon />,
DISPUTED: <ExclamationMarkIcon />,
};
/**
* Map of {@link InvoiceStatus|Invoice statuses} to their corresponding icon as JSX.
* > If you need to pass props to the icon, use {@link INVOICE_STATUS_ICONS} instead.
*/
export const INVOICE_STATUS_ICONS_JSX = Object.fromEntries(
Object.entries(INVOICE_STATUS_ICONS).map(([status, Icon]) => [status, <Icon key={status} />])
) as Record<InvoiceStatus, JSX.Element>;

export type InvoiceStatusIconProps = {
status: InvoiceStatus;
Expand Down

0 comments on commit 0daf0ce

Please sign in to comment.