# Rivet Icons
[Icons](https://rivet.iu.edu/icons-stickers/) (`16px` square) for Indiana University's Rivet Design System.
[Migrate from v2 to v3](MIGRATION.md).
## Contents
1. [Usage](#usage)
1. [HTML API](#html-api)
1. [CSS API](#css-api)
1. [JavaScript API](#javascript-api)
1. [Request a new icon](#request-a-new-icon)
## Usage
### Development
This approach is recommended for development, prototyping, or restrictive production environments.
Link to:
- The Rivet Icon Element styles (`./dist/rivet-icon-element.css`)
- The bundle containing all the icons (`./dist/rivet-icons.js`)
These files can be linked from a service like [UNPKG](https://unpkg.com/browse/rivet-icons/).
```html
```
### Production
For production, install the npm package.
```
npm install --save rivet-icons
```
Create a custom module which imports only the icons needed. The icon module name (such as `./dist/heart.js`) matches its corresponding SVG file name (such as `./src/icons/heart.svg`).
```js
// ./src/icons.js
import 'rivet-icons/dist/heart.js';
import 'rivet-icons/dist/heart-solid.js';
```
Link to:
- The Rivet Icon Element styles (`./dist/rivet-icon-element.css`)
- The custom module (for example, `./src/icons.js`)
```html
```
### Accessibility
By default, stickers are considered decorative images and hidden from screen reader users.
Ask this question to test if alternative text is needed: "Would this content still make sense to sighted users if the icon was removed?" If no, then add alternative text using the Rivet class `rvt-sr-only`.
In this first example, the link text of "Favorites" is presented to all users. The icon acts as a visual anchor and perhaps a legend to the rest of the page. No additional accessible description is needed.
```html
Favorites
```
In this second example, this icon is used to visually indicate the pressed state of the button. It is "heart" if the button is not pressed. It is "heart-solid" if the button is pressed. `aria-pressed` communicates the necessary information to screen readers. This attribute value changes the icon via the [CSS API](#--name-variable) in order to communicate equivalent information to visual users.
```html
```
In this case, even if a text label for sighted users is not wanted, it is required for screen reader users.
```html
```
### Testing
Download or clone this repo, then install dependencies.
```
npm install
```
Start the server to launch the local test environment.
```
npm run start
```
## HTML API
### `name` attribute
Use the `name` attribute to declare the icon to be rendered. The name of an icon matches its corresponding SVG file name (`./src/icons/*.svg`).
```html
```
## CSS API
### `--name` variable
Change the icon in CSS by setting the `--name` variable on the `rvt-icon` element to the desired icon name, such as `var(--heart)` for the "heart" icon.
In this example, the button toggles the value of `aria-pressed` for screen reader users, while the icon updates between the solid heart and outlined heart for visual users.
```html
```
The `--name` CSS variable declaration overrides the `name` HTML attribute. In this case, the icon will render as `heart-solid`, not `heart`.
```html
```
### `color` property
Change the icon color with the CSS `color` property. It is recommended to use the [Rivet color utility classes](https://rivet.uits.iu.edu/utilities/color/).
```html
```
## JavaScript API
### `registerIcon()` function
If the provided icon set does not have an icon you need, first [request a new icon](#request-a-new-icon) from the Rivet team.
If you must proceed with designing your own SVG icon, follow these specifications so they best align with the provided icon set:
- `16px` square grid
- `2px` stroke for all icon outlines
- Expand all strokes before exporting and merge/flatten artwork in to one group.
- Set `fill` attribute to `currentColor` on exported SVGs.
Use the `registerIcon()` function to register the name and SVG code for this custom icon. Then, it can be used like any of the provided icons.
```js
// ./src/icon-diamond.js
import { registerIcon } from 'rivet-icons';
const name = 'diamond';
const svg = ``;
registerIcon(name, svg);
```
If left unspecified, the `