All Projects → metonym → svelvg

metonym / svelvg

Licence: MIT License
Convert SVG files into Svelte components with TypeScript definitions

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
Svelte
593 projects
HTML
75241 projects

Labels

Projects that are alternatives of or similar to svelvg

focus-svelte
focus lock for svelte
Stars: ✭ 18 (-5.26%)
Mutual labels:  svelte
svelte-trivia
A Quiz app completely made using Svelte
Stars: ✭ 25 (+31.58%)
Mutual labels:  svelte
http-interceptors
The Web apps in this monorepo make HTTP requests and require uniform consistency in how they are executed and handled. This monorepo demonstrates the same app written with Angular and with Svelte. Each app uses HTTP interceptors. The Angular app uses HttpClient and its interceptors while the Svelte app uses Axios and its interceptors.
Stars: ✭ 46 (+142.11%)
Mutual labels:  svelte
safenetwork-gitportal
p2p git portal - a decentralised alternative to github
Stars: ✭ 12 (-36.84%)
Mutual labels:  svelte
cv
My online CV using Svelte
Stars: ✭ 35 (+84.21%)
Mutual labels:  svelte
svelte-fast-dimension
Fast dimension bindings using ResizeObservers
Stars: ✭ 23 (+21.05%)
Mutual labels:  svelte
sveld
Generate TypeScript definitions for your Svelte components
Stars: ✭ 281 (+1378.95%)
Mutual labels:  svelte
clui
A command system with extra steps
Stars: ✭ 18 (-5.26%)
Mutual labels:  svelte
svelte-meteor-data
Reactively track Meteor data inside Svelte components
Stars: ✭ 14 (-26.32%)
Mutual labels:  svelte
blockhead
Crypto portfolio tracker, DeFi dashboard, NFT viewer and data explorer for the Ethereum/EVM-based blockchain ecosystem and the web 3.0-powered metaverse https://gitcoin.co/grants/2966/blockhead
Stars: ✭ 41 (+115.79%)
Mutual labels:  svelte
svelteit
Svelteit is a minimalistic UI/UX component library for Svelte and Sapper projects
Stars: ✭ 64 (+236.84%)
Mutual labels:  svelte
modern-fluid-typography-editor
Modern fluid typography editor
Stars: ✭ 222 (+1068.42%)
Mutual labels:  svelte
svelte-router
Router component for Svelte
Stars: ✭ 63 (+231.58%)
Mutual labels:  svelte
todomvc-svelte
TodoMVC built with Svelte and Store
Stars: ✭ 34 (+78.95%)
Mutual labels:  svelte
memento-svelte-electron-typescript
Template to create a desktop app with Svelte, TailwindCSS, Electron and TypeScript (with electron-updater, electron-reload and electron-builder)
Stars: ✭ 27 (+42.11%)
Mutual labels:  svelte
svelte-avatar
An avatar component for Svelte
Stars: ✭ 12 (-36.84%)
Mutual labels:  svelte
sveltober
Cybernetically enhanced October applications
Stars: ✭ 19 (+0%)
Mutual labels:  svelte
svelte-style-directive
A custom Svelte preprocessor to add support for style directive.
Stars: ✭ 19 (+0%)
Mutual labels:  svelte
svelte-hamburgers
Custom Hamburger Icons in Svelte with ease
Stars: ✭ 27 (+42.11%)
Mutual labels:  svelte
svelte-generic-crud-table
Agnostic web-component for object-arrays with CRUD functionality.
Stars: ✭ 38 (+100%)
Mutual labels:  svelte

svelvg

Convert SVG files into Svelte components with TypeScript definitions.

Successor to svg-to-svelte

This library transforms SVG files into Svelte components through the following:

  • convert the svg file name into a valid module name (e.g., alarm-fill --> AlarmFill)
  • forward $$restProps to the svg element while preserving attributes from the original svg
  • add a default slot as child element to svg
  • generate a TypeScript definition by extending the SvelteComponentTyped interface

Usage

CLI

The easiest way to use this library is through npx.

The glob value represents the relative path to the folder containing SVG files inside node_modules/.

For example, say you have bootstrap-icons installed as a development dependency, which contains icon SVG files in the "icons" folder.

npx svelvg glob=bootstrap-icons/icons

By default, the output directory is "lib". Customize the directory using the outDir flag:

npx svelvg glob=bootstrap-icons/icons outDir=dist

Optionally, generate an index of icons (a list of all module names) by enabling the iconIndex flag. It will default to creating a ICON_INDEX.md file in your working directory.

npx svelvg glob=bootstrap-icons/icons iconIndex

Customize the icon index file name like so:

npx svelvg glob=bootstrap-icons/icons iconIndex=ICONS.md

Node.js

Alternatively, install svelvg from NPM to use it programmatically.

# Yarn
yarn add -D svelvg

# NPM
npm i -D svelvg

# pnpm
pnpm i -D svelvg

Note that the top-level await requires Node.js v14 or greater.

const svelvg = require("svelvg");

// Emits components to the `lib` folder
svelvg.createLibrary("bootstrap-icons/icons");

// Customize the output directory to be `dist`
svelvg.createLibrary("bootstrap-icons/icons", { outDir: "dist" });

API

createLibrary

interface CreateLibraryOptions {
  /** @default "lib" */
  outDir: string;

  /** @default false */
  iconIndex: boolean | string;

  /**
   * Callback to add a list of classes to the SVG element
   * provided the original filename and module name
   * @example
   * filename: "alarm-fill"
   * moduleName: "AlarmFill"
   */
  appendClassNames: (filename: string, moduleName: string) => string[];

  /**
   * Override the default module name
   */
  toModuleName: (params: {
    path: path.ParsedPath;
    moduleName: string;
  }) => string;
}

Template

Scaffold a new project using the template:

npx degit metonym/svelvg/template <folder-name>

IconLibrary.svelte

svelvg exports an IconLibrary.svelte to make listing and searching icons easier.

See template/index.html for an example.

<script type="module">
  import IconLibrary from "svelvg/lib/IconLibrary.svelte";
  import * as icons from "./lib";
  import pkg from "./package.json";

  const app = new IconLibrary({
    target: document.getElementById("svelte"),
    props: {
      pkg,
      icons,
    },
  });
</script>

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].