Coder Social home page Coder Social logo

huozhi / react-jsx-style Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 773 KB

React library to render CSS dynamic with JSX component or hooks

JavaScript 15.54% TypeScript 81.48% HTML 2.98%
css-in-js css-in-react dynamic-css hooks-api animation animation-css styling

react-jsx-style's Introduction

React JSX Style

create dynamic injected styles with react component or hooks

Installation

npm install -S react-jsx-style

Usage

Animation

import {Keyframe} from 'react-jsx-style'

// Using react component - Keyframe, Keyframe.Block + <style>
// Scale animation
function AnimatedBlock() {
  return (
    <div
      style={{
        textAlign: 'center',
        width: 200,
        animation: 'scale_2 3000ms infinite',
        transformOrigin: 'center',
      }}
    >
      <h3>scale</h3>
      <style>
        <Keyframe identity={'scale_2'}>
          <Keyframe.Block selector={'from'} value={{WebkitTransform: 'scale(1)'}} />
          <Keyframe.Block selector={'to'} value={{WebkitTransform: 'scale(2)'}} />
        </Keyframe>
      </style>
    </div>
  )
}


// Using hooks - useKeyframe
// Rotate animation
function HookAnimationBlock() {
  return (
    <div>
      <div
        style={{
          width: 60,
          height: 60,
          backgroundColor: 'orange',
          animationName: useKeyframe({
            from: {WebkitTransform: `rotate(0deg)`},
            to: {WebkitTransform: `rotate(135deg)`},
          }),
          animationDuration: '400ms',
          animationIterationCount: 'infinite',
        }}
      >
        Rotate
      </div>
    </div>
  )
}

License

MIT

react-jsx-style's People

Contributors

dependabot[bot] avatar huozhi avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.