link.tsx 645 B

1234567891011121314151617181920212223242526
  1. import { ComponentProps, splitProps } from "solid-js"
  2. import { usePlatform } from "@/context/platform"
  3. export interface LinkProps extends Omit<ComponentProps<"a">, "href"> {
  4. href: string
  5. }
  6. export function Link(props: LinkProps) {
  7. const platform = usePlatform()
  8. const [local, rest] = splitProps(props, ["href", "children", "class"])
  9. return (
  10. <a
  11. href={local.href}
  12. class={`text-text-strong underline ${local.class ?? ""}`}
  13. onClick={(event) => {
  14. if (!local.href) return
  15. event.preventDefault()
  16. platform.openLink(local.href)
  17. }}
  18. {...rest}
  19. >
  20. {local.children}
  21. </a>
  22. )
  23. }