Skip to content

Instantly share code, notes, and snippets.

@codebutler
Last active March 14, 2023 20:03
Show Gist options
  • Save codebutler/1478e946ed4bc14be8be62effd17bf03 to your computer and use it in GitHub Desktop.
Save codebutler/1478e946ed4bc14be8be62effd17bf03 to your computer and use it in GitHub Desktop.
Storybook dynamic auto-generated icon gallery
import { IconGallery, IconItem, Meta } from "@storybook/blocks";
import React from "react";
export const icons = import.meta.glob("../shared/icons/*.tsx", { eager: true });
<Meta title="Documentation/Icons" />
# Icons
<IconGallery>
{
Object.values(icons).map((module) => {
const [iconName, IconComponent] = Object.entries(module)[0];
return (
<IconItem name={iconName}>
<IconComponent />
</IconItem>
);
})
}
</IconGallery>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment