index.tsx 856 B

123456789101112131415161718192021222324252627282930313233343536
  1. "use client";
  2. import clsx from "clsx";
  3. import type { ComponentProps, ElementType } from "react";
  4. import styles from "./index.module.scss";
  5. import { Button } from "../unstyled/Button/index.jsx";
  6. import { Link as UnstyledLink } from "../unstyled/Link/index.jsx";
  7. type OwnProps = {
  8. invert?: boolean | undefined;
  9. };
  10. export type Props<T extends ElementType> = Omit<
  11. ComponentProps<T>,
  12. keyof OwnProps
  13. > &
  14. OwnProps;
  15. export const Link = (
  16. props: Props<typeof Button> | Props<typeof UnstyledLink>,
  17. ) =>
  18. "href" in props ? (
  19. <UnstyledLink {...mkProps(props)} />
  20. ) : (
  21. <Button {...mkProps(props)} />
  22. );
  23. const mkProps = ({
  24. className,
  25. invert = false,
  26. ...otherProps
  27. }: OwnProps & { className?: Parameters<typeof clsx>[0] }) => ({
  28. ...otherProps,
  29. "data-invert": invert ? "" : undefined,
  30. className: clsx(styles.link, className),
  31. });