# Icons

ShipClojure uses SVG sprites for [optimal icon performance](https://benadam.me/thoughts/react-svg-sprites/). You'll find raw SVGs in the [resources/icons](https://github.com/shipclojure/shipclojure/blob/main/resources/icons/README.md) directory. These are then compiled into a sprite using the `bb run build-icons` script, which generates the `sprite.svg` file, which is loaded into your html.

[Here](https://www.ovistoica.com/blog/20241009T084633--the-best-way-to-handle-svg-icons-in-fullstack-clojure-project__blog_clojure_clojurescript_web) is a blog post I wrote about the full technique used in ShipClojure.

The SVGs used by default in ShipClojure come from [lucide.dev](https://lucide.dev/). You can download additional SVG icons from there, or provide your own. Once you've added new files in the [icons directory](https://github.com/shipclojure/shipclojure/blob/main/resources/icons/README.md), run `bb run build-icons` and you can then use the [icon.cljc](https://github.com/shipclojure/shipclojure/blob/main/src/cljc/saas/common/ui/icon.cljc) component to render it.

```clojure
(ns example
 (:require
    [uix.core :refer [$ defui]]
    [saas.common.ui.icon :refer [icon]]))

(defui my-cool-component
    []
    ($ :div
      ($ icon {:icon :moon
               :size :lg
               :class "text-red-300"})))
```

The `:icon` or `:name` prop is the name of the file without the `.svg` extension. We recommend using `kebab-case` filenames rather than `PascalCase` to avoid casing issues with different operating systems.

Note that the [build\_icons.clj](https://github.com/shipclojure/shipclojure/blob/main/src/bb/build_icons.clj) script automatically removes `width` and `height` props from your SVGs to ensure they scale properly.

By default, all the icons will have a height and width of `1em` so they should match the font-size of the text they're next to. You can also customize the size using the `:size` prop or `:class "w-8 h-8"`

You can use the sprite.svg on server rendered pages also, and even in the blog templates like so:

```html
<div>
    <svg class="inline self-center w-[1em] h-[1em]">
       <use href="/svg/sprite.svg#moon" />
    </svg>
</div>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://shipclojure.gitbook.io/shipclojure-docs/frontend/icons.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
