47 lines
2.0 KiB
TypeScript
47 lines
2.0 KiB
TypeScript
import * as React from "react"
|
|
|
|
import { cn } from "~/lib/utils"
|
|
|
|
/**
|
|
* A `@subframe/core` Feather icon component. It renders
|
|
* `<span><svg width="1em" height="1em" stroke="currentColor" /></span>` and is
|
|
* therefore sized via `font-size` (Subframe's own convention uses `text-*`
|
|
* utilities for sizing).
|
|
*/
|
|
type FeatherComponent = React.ComponentType<
|
|
React.HTMLAttributes<HTMLSpanElement> & React.RefAttributes<HTMLSpanElement>
|
|
>
|
|
|
|
/**
|
|
* Bridges a Subframe Feather icon onto the boilerplate's existing icon
|
|
* contract `({ className }: { className?: string })`.
|
|
*
|
|
* Every legacy hand-authored icon was a bare `<svg className={className}>` sized
|
|
* through Tailwind width/height utilities (`h-4 w-4`, `size-4`, …) and coloured
|
|
* through `text-*` (the svg used `fill="currentColor"`). Call sites — ~350 of
|
|
* them — rely on exactly that.
|
|
*
|
|
* Feather icons size via `font-size` instead, so a naive re-export would render
|
|
* every icon at the inherited text size and ignore `h-4 w-4`. To keep all call
|
|
* sites working untouched we:
|
|
* - put the incoming `className` on the wrapper span (so width/height/colour/
|
|
* margin utilities land where they always did), and
|
|
* - force the inner `<svg>` to fill that span (`[&>svg]:size-full`), so the
|
|
* span's Tailwind size drives the rendered icon size.
|
|
*
|
|
* `size-4` is the default (the most common call-site size) and is overridden by
|
|
* any explicit size utility in `className` via tailwind-merge. Colour keeps
|
|
* working because Feather's svg uses `stroke="currentColor"`.
|
|
*/
|
|
export function featherIcon(Feather: FeatherComponent) {
|
|
function Icon({ className }: { className?: string }) {
|
|
// Icons in this folder are decorative (call sites needing a label put it on
|
|
// the surrounding button/link). Mark the wrapper aria-hidden so the icon
|
|
// subtree is ignored by assistive tech.
|
|
return (
|
|
<Feather aria-hidden="true" className={cn("inline-flex size-4 shrink-0 [&>svg]:size-full", className)} />
|
|
)
|
|
}
|
|
return Icon
|
|
}
|