A utility library to lookup TailwindCSS Heroicons by their name.

  • By NicolΓ‘s Quiroz
  • Last update: Oct 3, 2022
  • Comments: 2

Welcome to heroicons-lookup πŸ”

Version Documentation Maintenance License: MIT Twitter: naquiroz_

A utility library to lookup TailwindCSS Heroicons by their name. Based on @jsmith's gist

🏠 Homepage

✨ Demo(coming soon)

Use cases

Say for example, you store in database, entities that have an icon. The intuitive thing to do is to store the name of the icon in the database. Another example could be a situacion where you want to change the icon based on the user input, or based on certain conditions.

If you need to import an icon dynamically based on it's name, you can with this library. By using the function below, you can obtain exactly the icon you want, as react component.

Install

npm install heroicons-lookup

Usage

{ const Icon = lookupIcon(iconName, "solid") return ( ) }">
import {lookupIcon} from "heroicons-lookup";

const ExampleComponent = ({iconName="ArrowLeftIcon"}: {iconName: string}) => {
  const Icon = lookupIcon(iconName, "solid")
  return (
    <Icon className="flex h-5 w-5"/>
  )
}

Documentation

lookupIcon(iconName: string, format: "outline"|"solid")

Finds an icon element with the name indicated (if any). Throws an error if not found.

Author

πŸ‘€ Nicolas Quiroz [email protected]

🀝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a ⭐️ if this project helped you!

πŸ“ License

Copyright Β© 2022 Nicolas Quiroz [email protected].
This project is MIT licensed.

This README was generated with ❀️ by readme-md-generator

Github

https://github.com/naquiroz/heroicons-lookup

Comments(2)

  • 1

    Update contributing instructions

    Hey, I wanted to update the package to include some new icons (or their new names), which I have done in https://github.com/naquiroz/heroicons-lookup/pull/2

    But I found the contributing instructions hard to follow, lots of the info in the template doesn't seem to match this project. I wasn't sure what direction you might want to switch (e.g. eslint vs prettier vs whatever) so I haven't made any changes directly.

    The parts I spotted:

    • Are the npm/node versions right? I had npm 6.x on my machine and this rewrote the entirety of package-lock.json to use lockfileVersion:1. Switching to the latest (9.x) resolved it, and I didn't dig into exactlly what version is expected.
    • In step 3 it says npm where I assume it means npm install?
    • Step 4 doesn't seem relevant at all
    • I wasn't clear if the tip was actually wanted?
    • Under the PR submission instructions it says to run the tests, but there are not tests.
    • It also says to run npm run lint but that command doesn't work. It's defined as eslint src but needs to be something like eslint src/**/*.ts. But switching to that just makes eslint complain that there's no config file.
    • I could run prettier OK with npx prettier -w src in case that's useful to include.
  • 2

    Update to use Heroicons 2.0.13

    Updates heroicons-lookup to use the latest heroicons/react

    This adds the following new icons:

    AdjustmentsHorizontalIcon
    AdjustmentsVerticalIcon
    ArchiveBoxArrowDownIcon
    ArchiveBoxIcon
    ArchiveBoxXMarkIcon
    ArrowDownCircleIcon
    ArrowDownLeftIcon
    ArrowDownOnSquareIcon
    ArrowDownOnSquareStackIcon
    ArrowDownRightIcon
    ArrowDownTrayIcon
    ArrowLeftCircleIcon
    ArrowLeftOnRectangleIcon
    ArrowLongDownIcon
    ArrowLongLeftIcon
    ArrowLongRightIcon
    ArrowLongUpIcon
    ArrowPathIcon
    ArrowPathRoundedSquareIcon
    ArrowRightCircleIcon
    ArrowRightOnRectangleIcon
    ArrowSmallDownIcon
    ArrowSmallLeftIcon
    ArrowSmallRightIcon
    ArrowSmallUpIcon
    ArrowTopRightOnSquareIcon
    ArrowTrendingDownIcon
    ArrowTrendingUpIcon
    ArrowUpCircleIcon
    ArrowUpLeftIcon
    ArrowUpOnSquareIcon
    ArrowUpOnSquareStackIcon
    ArrowUpRightIcon
    ArrowUpTrayIcon
    ArrowUturnDownIcon
    ArrowUturnLeftIcon
    ArrowUturnRightIcon
    ArrowUturnUpIcon
    ArrowsPointingInIcon
    ArrowsPointingOutIcon
    ArrowsRightLeftIcon
    ArrowsUpDownIcon
    BackwardIcon
    BanknotesIcon
    Bars2Icon
    Bars3BottomLeftIcon
    Bars3BottomRightIcon
    Bars3CenterLeftIcon
    Bars3Icon
    Bars4Icon
    BarsArrowDownIcon
    BarsArrowUpIcon
    Battery0Icon
    Battery100Icon
    Battery50Icon
    BellAlertIcon
    BellSlashIcon
    BellSnoozeIcon
    BoltIcon
    BoltSlashIcon
    BookmarkSlashIcon
    BookmarkSquareIcon
    BugAntIcon
    BuildingLibraryIcon
    BuildingOffice2Icon
    BuildingOfficeIcon
    BuildingStorefrontIcon
    CalendarDaysIcon
    ChartBarSquareIcon
    ChatBubbleBottomCenterIcon
    ChatBubbleBottomCenterTextIcon
    ChatBubbleLeftEllipsisIcon
    ChatBubbleLeftIcon
    ChatBubbleLeftRightIcon
    ChatBubbleOvalLeftEllipsisIcon
    ChatBubbleOvalLeftIcon
    CheckBadgeIcon
    ChevronUpDownIcon
    CircleStackIcon
    ClipboardDocumentCheckIcon
    ClipboardDocumentIcon
    ClipboardDocumentListIcon
    CloudArrowDownIcon
    CloudArrowUpIcon
    CodeBracketIcon
    CodeBracketSquareIcon
    Cog6ToothIcon
    Cog8ToothIcon
    CommandLineIcon
    ComputerDesktopIcon
    CpuChipIcon
    CursorArrowRaysIcon
    CursorArrowRippleIcon
    DevicePhoneMobileIcon
    DocumentArrowDownIcon
    DocumentArrowUpIcon
    DocumentChartBarIcon
    DocumentCheckIcon
    DocumentMagnifyingGlassIcon
    DocumentMinusIcon
    DocumentPlusIcon
    EllipsisHorizontalCircleIcon
    EllipsisHorizontalIcon
    EllipsisVerticalIcon
    EnvelopeIcon
    EnvelopeOpenIcon
    ExclamationTriangleIcon
    EyeDropperIcon
    EyeSlashIcon
    FaceFrownIcon
    FaceSmileIcon
    FolderArrowDownIcon
    FolderMinusIcon
    FolderPlusIcon
    ForwardIcon
    FunnelIcon
    GifIcon
    GiftTopIcon
    GlobeAmericasIcon
    GlobeAsiaAustraliaIcon
    GlobeEuropeAfricaIcon
    HandRaisedIcon
    HandThumbDownIcon
    HandThumbUpIcon
    HomeModernIcon
    InboxArrowDownIcon
    InboxStackIcon
    LanguageIcon
    LifebuoyIcon
    ListBulletIcon
    MagnifyingGlassCircleIcon
    MagnifyingGlassIcon
    MagnifyingGlassMinusIcon
    MagnifyingGlassPlusIcon
    MapPinIcon
    MegaphoneIcon
    MinusSmallIcon
    MusicalNoteIcon
    NoSymbolIcon
    PaintBrushIcon
    PauseCircleIcon
    PencilSquareIcon
    PhoneArrowDownLeftIcon
    PhoneArrowUpRightIcon
    PhoneXMarkIcon
    PhotoIcon
    PlayCircleIcon
    PlayPauseIcon
    PlusSmallIcon
    PowerIcon
    PuzzlePieceIcon
    QrCodeIcon
    QueueListIcon
    RadioIcon
    ReceiptPercentIcon
    RectangleGroupIcon
    RectangleStackIcon
    RocketLaunchIcon
    ServerStackIcon
    SignalIcon
    SignalSlashIcon
    SpeakerWaveIcon
    SpeakerXMarkIcon
    Square2StackIcon
    Square3Stack3DIcon
    Squares2X2Icon
    SquaresPlusIcon
    StopCircleIcon
    SwatchIcon
    TableCellsIcon
    TrophyIcon
    TvIcon
    UserMinusIcon
    UserPlusIcon
    VideoCameraSlashIcon
    ViewColumnsIcon
    ViewfinderCircleIcon
    WalletIcon
    WindowIcon
    WrenchIcon
    WrenchScrewdriverIcon
    XMarkIcon
    

    And removes the following old icons (mostly renamed into the above list as far as I could see)

    AdjustmentsIcon
    AnnotationIcon
    ArchiveIcon
    ArrowCircleDownIcon
    ArrowCircleLeftIcon
    ArrowCircleRightIcon
    ArrowCircleUpIcon
    ArrowNarrowDownIcon
    ArrowNarrowLeftIcon
    ArrowNarrowRightIcon
    ArrowNarrowUpIcon
    ArrowSmDownIcon
    ArrowSmLeftIcon
    ArrowSmRightIcon
    ArrowSmUpIcon
    ArrowsExpandIcon
    BadgeCheckIcon
    BanIcon
    BookmarkAltIcon
    CashIcon
    ChartSquareBarIcon
    ChatAlt2Icon
    ChatAltIcon
    ChatIcon
    ChipIcon
    ClipboardCheckIcon
    ClipboardCopyIcon
    ClipboardListIcon
    CloudDownloadIcon
    CloudUploadIcon
    CodeIcon
    CollectionIcon
    ColorSwatchIcon
    CursorClickIcon
    DatabaseIcon
    DesktopComputerIcon
    DeviceMobileIcon
    DocumentAddIcon
    DocumentDownloadIcon
    DocumentRemoveIcon
    DocumentReportIcon
    DocumentSearchIcon
    DotsCircleHorizontalIcon
    DotsHorizontalIcon
    DotsVerticalIcon
    DownloadIcon
    DuplicateIcon
    EmojiHappyIcon
    EmojiSadIcon
    ExclamationIcon
    ExternalLinkIcon
    EyeOffIcon
    FastForwardIcon
    FilterIcon
    FolderAddIcon
    FolderDownloadIcon
    FolderRemoveIcon
    GlobeIcon
    HandIcon
    InboxInIcon
    LibraryIcon
    LightningBoltIcon
    LocationMarkerIcon
    LoginIcon
    LogoutIcon
    MailIcon
    MailOpenIcon
    MenuAlt1Icon
    MenuAlt2Icon
    MenuAlt3Icon
    MenuAlt4Icon
    MenuIcon
    MinusSmIcon
    MusicNoteIcon
    OfficeBuildingIcon
    PencilAltIcon
    PhoneIncomingIcon
    PhoneMissedCallIcon
    PhoneOutgoingIcon
    PhotographIcon
    PlusSmIcon
    PuzzleIcon
    QrcodeIcon
    ReceiptTaxIcon
    RefreshIcon
    ReplyIcon
    RewindIcon
    SaveAsIcon
    SaveIcon
    SearchCircleIcon
    SearchIcon
    SelectorIcon
    SortAscendingIcon
    SortDescendingIcon
    SpeakerphoneIcon
    StatusOfflineIcon
    StatusOnlineIcon
    SupportIcon
    SwitchHorizontalIcon
    SwitchVerticalIcon
    TableIcon
    TemplateIcon
    TerminalIcon
    ThumbDownIcon
    ThumbUpIcon
    TranslateIcon
    TrendingDownIcon
    TrendingUpIcon
    UploadIcon
    UserAddIcon
    UserRemoveIcon
    ViewBoardsIcon
    ViewGridAddIcon
    ViewGridIcon
    ViewListIcon
    VolumeOffIcon
    VolumeUpIcon
    XIcon
    ZoomInIcon
    ZoomOutIcon
    

    Closes #1