Skip to content

Instantly share code, notes, and snippets.

@ktortolini
Last active December 19, 2024 01:19
Show Gist options
  • Select an option

  • Save ktortolini/8596c1c6ba5a3715e061f8e6b3299d1d to your computer and use it in GitHub Desktop.

Select an option

Save ktortolini/8596c1c6ba5a3715e061f8e6b3299d1d to your computer and use it in GitHub Desktop.
πŸ’™ Fresh Project Iconify Components
const example = () => {
return (
<div>
{/* @ts-ignore */}
<iconify-icon
icon="tabler:copy"
width="24"
height="24
></iconify-icon>
</div>
);
};
export default example;

Using Iconify Web Components in Fresh Projects

This is a guide on how to use @iconify/iconify web components in a @fresh project.

Table of Contents

Installation

Starting a @fresh project begins with the following command.

deno run -A -r https://fresh.deno.dev

πŸ“– Note: Define the project directory with the . argument to set the current directory as the project directory.

Importing Web Components

To use @iconify/iconify web components in your @fresh project, you need to add the following script to your _app.tsx file.

<script src="https://code.iconify.design/iconify-icon/1.0.7/iconify-icon.min.js"></script>

πŸ“– Note: The script should be added to the <head> element or <Head> component of your _app.tsx file.

To search for your desired icon, visit the @iconify/icon-sets resource. In this example we will use the @iconify/tabler icon set. In the filter field, enter copy to follow along with this example. Select the third icon that appears in the results, and select the Iconify Icon tab to view the component code.

Using Selected Icons

After you have copied the component code, you can use it in your project by adding it to the JSX file of your choice. Below is an example of how to use the copy icon in an example component.

const example = () => {
	return (
		<div>
			{/* @ts-ignore */}
			<iconify-icon icon="tabler:copy" width="24" height="24"></iconify-icon>
		</div>
	);
};

export default example;

πŸ“– Note: The @ts-ignore comment is used to suppress the TypeScript error that occurs when using the iconify-icon component.

External Resources

Feel free to search through other icon sets using the @iconify/icon-sets resource. Some great choices are @iconify/tabler, @iconify/lucide, and @iconify/heroicons.

Author

This gist is also available in a public respository created by the author ktortolini. Please, feel free to contact the author via email βœ‰ ktortolini@smu.edu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment