asafefe.dev

Eye Icon

New

Blinks on hover. Closes, lashes and all, for show and hide password toggles.

motion@soultel/use-reduced-motion-safe@soultel/use-icon-trigger
hover me

Installation

$ pnpm dlx shadcn@latest add @soultel/icon-eye

No namespace set up? npx shadcn@latest add https://asafefe.dev/r/icon-eye.json works too.

Manual installation
  1. 1. Install the dependencies.
    terminal1 lines
    npm install motion
  2. 2. Copy the source from the Code tab into components/icon-eye.tsx.

Usage

example.tsx15 lines
import { useState } from "react"
import { EyeIcon } from "@/components/icon-eye"

export function PasswordInput() {
  const [shown, setShown] = useState(false)

  return (
    <div className="flex items-center">
      <input type={shown ? "text" : "password"} />
      <button onClick={() => setShown(!shown)} aria-label={shown ? "Hide password" : "Show password"}>
        <EyeIcon size={18} closed={!shown} />
      </button>
    </div>
  )
}

Props

PropTypeDefaultDescription
closedbooleanfalseShows the eye shut.
sizenumber24Width and height in px.
strokeWidthnumber2Stroke width on the 24 by 24 grid.
animate"hover" | "always" | boolean"hover""hover" plays when the nearest button or link (or the icon) is hovered, focused or tapped. "always" loops. A boolean plays each time it turns true, so a parent can drive it.
labelstring-Accessible name. Without one the icon is aria-hidden.
classNamestring-Classes for the svg. Color comes from currentColor.