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-proton

v1.0.3

Published

Build continuous responsive react websites.

Downloads

3

Readme

react-proton

react-proton is designed for you to build continuous and discret responsive websites. That means you are able to deduce every attribute from a changing continuous value, e.g. the screen size (it could also be any other, like time of the day in minutes).

Live Demo

react-proton-example

Protons and Electrons

The Proton is the core of your application. It keeps the current value you are interested in and everytime it changes, all Electrons are notified. Electrons can be given react-styles with values:

  1. as known constant values: fontSize: 10
  2. as discret relative to breakpoints: fontSize: { m: 10, l: 20 }
  3. as interpolation expression: fontSize: [10, 20]

Show me some code

index.js

import React from 'react';
import { Proton, ProtonProvider } from 'react-proton';
import MyComponent from './MyComponent';

// uses default for proton constructor
// protonNameMin = 'xxs',
// breakpoints = {xs: 280, s: 340, m: 576, l: 768, xl: 992, xxl: 1200}
const proton = new Proton(); 
        
const updateSize = () => proton.setSize(window.innerWidth)
window.addEventListener('resize', updateSize);
updateSize();

ReactDOM.render(
    <ProtonProvider proton={proton}>
        <MyComponent />
    </ProtonProvider>,
    document.getElementById('root')
);

MyComponent.js

import React from 'react';
import { Electron } from 'react-proton';

class MyComponent extends React.Component {

    cols = {
        // default 100%
        m: 1/2, // 50%
        l: 1/3, // 33%
        xl: 1/4 // 25%
    };

    // const values as in react
    electron1Style = {
        color: 'red'
    };

    // discret values for each breakpoint
    electron2Style = {
        padding: {
            m: '20px',
            // implicitly `l: '20px'` from "m"
            xl: '40px'
        }
    };

    // continuous values relative to min and max breakpoint with unit
    electron3Style = {
        // a value between 10-20 relative from min breakpoint (10) to max breakpoint (20)
        fontSize: [10, 20, 'pt'],

        // color interpolation
        color: ['#111', '#333333']
    };
    
    // or everything mixed
    electron4Style = {
        ...this.electron1Style,
        ...this.electron2Style,
        ...this.electron3Style,
    };

    render() {
        return (
            <div>
                <Electron cols={this.cols} style={electron1Style}>Electron 1</Electron>
                <Electron cols={this.cols} style={electron2Style}>Electron 2</Electron>
                <Electron cols={this.cols} style={electron3Style}>Electron 3</Electron>
                <Electron cols={this.cols} style={electron4Style}>Electron 4</Electron>
            </div>
        );
    }
}

export default MyComponent;

Roadmap

✔ Implement Proton, Electron and simple style interpolation.

protonStyle interpolation should understand units, colors and functions.

... add Neutron to seperate responsibility.

Maybe

  • Neutron for style-interpolation
  • Electron for responsibility (short-hand Neutron for width attribute)

To be discussed...

... Ability to define many Protons to deduce from many values

e.g.

  • screenProton deduced from window.innerWidth: make page responsive
  • minutesOfDayProton deduced from date.getHours() * 60 + date.getMinutes(): our awesome page should be bright in the morning and getting darker in the afternoon
  • mainContentProton deduced from "width of main div": user can change width of menu and we want main content to be responsive to its available width

... Investigate/do seperate discrete and continuous deduction components

e.g. ComponentA needs high accuracy and operates on continuous value, while ComponentB does not and only needs to be triggered, when breakpoint changes.

ideas:

  • composite pattern compiles Neutrons and split them into continuous and discrete deduction components