All Projects → scout24ch → styled-svg

scout24ch / styled-svg

Licence: MIT License
A styled-components generator for SVG files to use in react

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to styled-svg

Project Webcube
Continuously updated JS infrastructure for modern web dev
Stars: ✭ 141 (+281.08%)
Mutual labels:  generator, styled-components
Booben
Web app constructor based on React, with GraphQL bindings
Stars: ✭ 96 (+159.46%)
Mutual labels:  generator, styled-components
Styled By
Simple and powerful lib to handle styled props in your components
Stars: ✭ 122 (+229.73%)
Mutual labels:  styled-components, props
jss-material-ui
A enhanced styling engine for material-ui
Stars: ✭ 15 (-59.46%)
Mutual labels:  styled-components, props
smores-react
🍭 Marshmallow React components
Stars: ✭ 34 (-8.11%)
Mutual labels:  styled-components
twin.examples
Packed with examples for different frameworks, this repo helps you get started with twin a whole lot faster.
Stars: ✭ 320 (+764.86%)
Mutual labels:  styled-components
gulp-boilerplate
🚀 A opinionated gulp boilerplate for individuals and teams
Stars: ✭ 18 (-51.35%)
Mutual labels:  svg-files
prosemirror-react-typescript-example
Minimal boilerplate to start a project with ProseMirror, React, TypeScript
Stars: ✭ 67 (+81.08%)
Mutual labels:  styled-components
desvg
🌅 Converts SVG files into components 🌞
Stars: ✭ 79 (+113.51%)
Mutual labels:  styled-components
nextjs-with-material-ui-and-styled-components
Next.js with material-ui and styled-components
Stars: ✭ 100 (+170.27%)
Mutual labels:  styled-components
paygreen-ui
UI PayGreen Components: React, Styled Component
Stars: ✭ 29 (-21.62%)
Mutual labels:  styled-components
blog-desktop-v2
Yancey Blog website for desktop and mobile.
Stars: ✭ 19 (-48.65%)
Mutual labels:  styled-components
react-awesome-notifications
A beautiful fully customizable React + Redux notification system built with styled-components
Stars: ✭ 29 (-21.62%)
Mutual labels:  styled-components
web-template-project
This repository contains a template for nodeJS and ReactJs projects using TypeScript.
Stars: ✭ 18 (-51.35%)
Mutual labels:  styled-components
parsers
Specify is a central platform for companies who want to unify their brand identity, by connecting their design system tools.
Stars: ✭ 50 (+35.14%)
Mutual labels:  svgo
react-native-whirlwind
Whirlwind is a utility-first styling framework specifically designed for React Native. It is heavily inspired by Tachyons and Tailwind CSS and uses low-level building blocks for rapidly building custom designs.
Stars: ✭ 91 (+145.95%)
Mutual labels:  styled-components
sendight-frontend
P2P File sharing
Stars: ✭ 53 (+43.24%)
Mutual labels:  styled-components
styled-components-docs-zh
💅 styled-components 中文文档翻译 🏇持续施工中
Stars: ✭ 160 (+332.43%)
Mutual labels:  styled-components
mugiwara
fast minimal CSS-in-JS created to reduce size of CSS injected
Stars: ✭ 11 (-70.27%)
Mutual labels:  styled-components
react-easy-ssr
🔥 React Starter Project with Webpack 5, Babel 7, TypeScript, Redux-saga, Styled-components, React-jss, Split code, Server Side Rendering.
Stars: ✭ 31 (-16.22%)
Mutual labels:  styled-components

styled-svg

Generate styled-components 💅 from SVG files

Build Status Known Vulnerabilities

What's this?

This utility generates React components, using the styled.svg function. Just drop the .svg somewhere in the project, run the tool and start using your svg files as inline svg with all React and styled-components beauty. As a bonus, all svg files are optimized, using the awesome svgo library.

How it looks like

Usage of the generated component

import React from 'react'
import Warning from './Warning'

const ComponentWithImage = props => (
  <div>
    {props.children}
    <Warning size='medium' fillColor='red' />
  </div>
)

export default ComponentWithImage

Props of the generated components

name  type default description
fillColor String / null null override fill color of paths and other elements
fillColorRule String '&&& path, &&& use, &&& g' rule for selecting elements to colorize, you only need to change this, for complex svg structures.
size String / null / Object null one of the sizes keys, to set the size, or an object { width, height }
sizes Object {} Override possible sizes, example below (by default these are generated with the --size option, so you probably won't need this)

sizes prop example

const sizes = {
  small: { width: 18, height: 18 },
  medium: { width: 24, height: 24 },
  large: { width: 36, height: 36 }
}

Overriding styles

As the components are just regular styled-components, overriding styles is easy. Note if you just want to change colors for hover and other state-changes, you can use the fillColor prop of the generated components.

import React from 'react'
import styled from 'styled-components'
import Warning from './Warning'

const CustomizedWarning = styled(Warning)`
  width: 100%;
  border-radius: 3px;
`

Usage

npm scripts usage (recommended)

Install the dependency

npm i --save-dev styled-svg

Create a npm script entry in your package.json

{
  //...
  "scripts": {
    "svg": "styled-svg src/**/*.svg --size=small:18x18 --size=medium:24x24"
  },
  //...
}

Then run npm run svg at any time to generate Components

JS usage

Install the dependency

npm i --save-dev styled-svg

JS example

const convert = require('styled-svg')

// options have the same defaults as the command line usage
const options = {
  clean: true,
  dryRun: false
  noTests: false,
  outputDir: './output',
  templatesDir: : './templates',
  testDir: './output',
  size: [
    'small:18x18',
    'medium:24x24'
  ]
}
const files = [
  'path/to/file/a.svg',
  'path/to/file/b.svg',
  'path/to/file/c.svg'
]

// returns a promise that resolves to an array of results
convert(files, options)

Command line usage

Install the package globally

npm i -g styled-svg

Run it in any directory

styled-svg **/*.svg

Changelog

All changes are logged in releases.

Known issues / unimplemented features

  • Improve test coverage
  • Make it usable in JS with specifying svg strings directly, not only file paths

Licence

MIT

Credits

  • Thanks svg2react for some inspiration how to handle attributes
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].