Getting started
This guide will help you get started with YCloud in your Vanilla JavaScript project. Make sure you have a your environment set up. If you don't have one yet, you can create a new project using Vite, Parcel or any other boilerplate of your choice.
Installation
Package Managers
sh
pnpm add @ycloud-web/iconssh
yarn add @ycloud-web/iconssh
npm install @ycloud-web/iconssh
bun add @ycloud-web/iconsImporting your first icon
YCloud is built with ES Modules, so it's completely tree-shakable.
The createIcons function will search for HTMLElements with the attribute data-ycloud and replace it with the svg from the given icon name.
Example
html
<!-- Your HTML file -->
<i data-ycloud="menu"></i>js
import { createIcons, icons } from '@ycloud-web/icons';
// Caution, this will import all the icons and bundle them.
createIcons({ icons });
// Recommended way, to include only the icons you need.
import { createIcons, Menu, ArrowRight, Globe } from '@ycloud-web/icons';
createIcons({
icons: {
Menu,
ArrowRight,
Globe,
},
});Advanced Usage
Additional Options
In the createIcons function you can pass some extra parameters:
- you can pass
nameAttrto adjust the attribute name to replace icons (default isdata-ycloud). - you can pass
attrsto pass additional custom attributes, for instance CSS classes or stroke options. - you can pass
rootto provide a custom DOM element the icons should be replaced in (useful when manipulating small sections of a large DOM or elements in the shadow DOM) - you can pass
inTemplates: trueto also replace icons inside<template>tags.
Here is a full example:
js
import { createIcons } from '@ycloud-web/icons';
createIcons({
attrs: {
class: ['my-custom-class', 'icon'],
'stroke-width': 1,
stroke: '#333',
},
nameAttr: 'data-ycloud', // attribute for the icon name.
root: element, // DOM element to replace icons in.
inTemplates: true, // Also replace icons inside <template> tags.
});