@devbug/react-svg-buttons

0.5.0 • Public • Published

React SVG buttons

Version

React SVG buttons

This package provides a <MorphIcon /> component used to compose available buttons, it's able to morph from whatever icon type to another one.

The <MorphIcon /> component exposes 18 icon types.

It also provides a set of button components.

Please, take a look at the demo.

Installation

npm install @devbug/react-svg-buttons

Usage

You can create your own personalized buttons.

For instance, adding new react components:

Morphing onClick

// MorphingButtonClick.jsx
import { useState } from 'react';
import { MorphIcon } from '@devbug/react-svg-buttons';

const MorphingButtonClick = () => {
  const [iconType, setIconType] = useState('home');

  return (
    <MorphIcon
      type={iconType}
      size={100}
      thickness={2}
      color="#dd6e78"
      onClick={() => setIconType(iconType === 'home' ? 'thunderbolt' : 'home')}
    />
  );
};

export default MorphingButtonClick;

Morphing onMouseEnter/onMouseLeave

// MorphingButtonHover.jsx
import { useState } from 'react';
import { MorphIcon } from '@devbug/react-svg-buttons';

const MorphingButtonHover = () => {
  const [iconType, setIconType] = useState('home');

  return (
    <MorphIcon
      type={iconType}
      size={100}
      thickness={2}
      color="#dd6e78"
      onMouseEnter={() => setIconType('thunderbolt')}
      onMouseLeave={() => setIconType('home')}
    />
  );
};

export default MorphingButtonHover;

Then just add the new components to the react app or you can use the Pre configured buttons.

// main.jsx
import React from 'react'
import ReactDOM from 'react-dom/client'
import MorphingButtonClick from './components/MorphingButtonClick'
import MorphingButtonHover from './components/MorphingButtonHover'

import {
  MorphIcon,
  CloseButton
} from '@devbug/react-svg-buttons'

ReactDOM.createRoot(document.getElementById('root')).render(
  <React.StrictMode>
       <div>
        <MorphingButtonClick />
        <MorphingButtonHover />
        <MorphIcon
            type="hashtag"
            size={100}
            thickness={2}
            color="blue"
        />
        <CloseButton/>
      </div>
  </React.StrictMode>,
)

Result:

React SVG buttons

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Original work:

Updated to support React v18:

Package Sidebar

Install

npm i @devbug/react-svg-buttons

Weekly Downloads

2

Version

0.5.0

License

MIT

Unpacked Size

82 kB

Total Files

39

Last publish

Collaborators

  • devbug