npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-nya-style

v0.0.5

Published

Official package for React to provide Nya

Downloads

15

Readme

React-nya-style is official package to let you use nya-style library in reactjs


install

npm i --save react-nya-style


Usage

At first, you should initialize nya-style

import Style from 'nya-style'
let nya = Style();

Ok. Then you need to import NyaProvider from "react-nya-style"

import { NyaProvider } from 'react-nya-style'

Finally, use the render() method.

import React from 'react'
import { render } from 'react-dom'

render((
	<NyaProvider nya={nya}>
		<App />
	</NyaProvider>
), document.querySelector("#root"))

Full code

import React from 'react'
import { render } from 'react-dom'

import Style from 'nya-style'
import { NyaProvider } from 'react-nya-style'

import App from './App.jsx'

let nya = Style();

render((
	<NyaProvider nya={nya}>
		<App />
	</NyaProvider>
), document.querySelector("#root"))

CSS in JS

Creating some nya-css code.

let mainStyles = {
	borderRadius: 10,
	boxShadow: ["initial", .3],
	":hover":{
		boxShadow: "0 0 10 0 rgba(0,0,0,.5)"
	}
}

But how I can bind it with my App? rootStyle(). That is what you need.

import { rootStyle } from 'react-nya-style'
rootStyle(".main", styles);

rootStyle() add "styles" to the root(no context).

params:
  1. selector: String. Name for your styles
  2. styles: object. Styles for parsing

Binded styles

But what if I do not want to add style to global scope? saveStyle() is your answer.

import React from 'react'
import { saveStyle } from "react-nya-style"

let styles = {
	background: ["white", .3],
	color: ["black", .3]
	":hover":{
		background: "black",
		color: "white"
	}
}

const MyComponent = props=>(
	<div className="my_component">
		Hello The Universe!
	</div>
)
saveStyle(styles, "my_component");
export { MyComponent }

As you can see, we bind styles and name.

Then

Ok, Eugine. We did it. We used all functions. How I can use my styles?

Some code. Again...

import { rootStyle } from 'react-nya-style'
let OtherStyle = {
	".my_component": descr=>descr.load("my_component")
}
rootStyle(".other", OtherStyle);

That is all. You just load styles using descr.load() method.

Conclusion

Ok. Why I write this package and who should use it? React developers. Before this lib I was writing 2 things in each .jsx file.

  1. Component
  2. ComponentStyle

Then I exported them and imported them in other file. 10 times, 20 times. Oh, and also I always had root .js file, where I imported all root styles and was passing them to root object. Then I imported root from styles.js and was passing it to Style() function. So boring. This running between folders takes so much time. With react-nya-style I do not need root .js file, I just use rootStyle(). I do not need to export ComponentStyle, instead i use saveStyle()