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

@quarkly/atomize

v1.1.0

Published

Library for creating atomic react components

Downloads

353

Readme

Atomize is a library for creating atomic react components. Inspired by tachyons and styled-system.

CI Coverage Version MIT License

Features

  • Create components that support atomic CSS and themes
  • Set styles for specific media breakpoints
  • Use variables from the theme in composite CSS properties
  • Support for hover and any other pseudo-classes
  • Short aliases for each property

General Resources

Demo

Install and Usage

Before you start working with Atomize, you need to set up dependencies:

npm i @quarkly/atomize styled-components

Atomize serves as a wrapper around a styled-component and has a similar API.

Just call the method using the name of the required element:

import atomize from '@quarkly/atomize';
 
const Box = atomize.div();

As a result, we get the React component that can take any CSS in the form of properties.

<Box backgroundColor="red" />

The React inheritance mechanism is also provided:

const MyComponent = ({ className }) => {
    // some logic here
    return <div className={ className } />;
};

const Box = atomize(MyComponent);

Advanced Usage

Aliases

You can use the system of alias properties to make it easier to use. For example, bgc === backgroundColor.

<Box bgc="red" />

To see the full list of properties and aliases, follow this link.

You can also disable aliases for the specific component if you need. Just pass an object with the configuration where set "useAliases: false".

const Box = atomize.div({ useAliases: false })

Themes

By default, Atomize components do not include a theme and you need to set up dependencies:

npm i @quarkly/theme

Quarkly themes are based on CSS variables. The key feature is that variables from themes can be reused both in props and themes. You don’t have to use additional abstractions, like template functions, and no additional editing is needed.

To use variables from a theme, just add your theme to an application with a Theme component, describe the property in the theme and call this property using the prefix "--".

You can also use it in the theme itself:

import Theme from "@quarkly/theme";

const theme = {
    color: {
        dark: "#212121"
    },
    border: {
        dark: "1px solid --color-dark"
    }
};

export const MyBox = () => (
    <Theme theme={ theme }>
        <Box
            width="100px"
            height="100px"

            border="--border-dark"
            color="--color-dark"
        />
    </Theme>
);

Shorter syntax is used for colors in the JSX markup:

<Box color="--dark" />

Breakpoints

Themes have breakpoints for working with media expressions.

Any property can be prefixed with a breakpoint key name.

import Theme from "@quarkly/theme";
 
const theme = {
    breakpoints: {
        sm: [{ type: "min-width", value: 576 }],
        md: [{ type: "min-width", value: 768 }],
        lg: [{ type: "min-width", value: 992 }]
    },
    color: {
        'dark-mobile': "#424242",
        'dark-tablet': "#212121"
    }
};

export const MyBox = () => (
    <Theme theme={ theme }>
        <Box
            width="100px"
            height="100px"

            color="--dark-mobile"
            md-color="--dark-tablet"
        />
    </Theme>
);

Effects

Just pass an object with the configuration to a component when creating it:

const Button = atomize.button({
    effects: {
        hover: ":hover",
        focus: ":focus",
        active: ":active",
        disabled: ":disabled"
    }
});

The key is the prefix in the name of the property, and the value is a CSS selector. This is the same way we implemented pseudo-classes.

For example, if you specify the hover prefix for any CSS property, it will be applied to a certain effect:

<MySuperButton
    bgc="red"
    hover-bgc="yellow"
    focus-bgc="blue"
/>

You can also combine effects with media expressions:

<Box
    md-hover-bgc="yellow"
    lg-hover-bgc="blue"
/>

Quarkly Widgets

The second purpose of Atomize is to create widgets in Quarkly based on custom React components.

Just wrap your component in Atomize and describe its configuration so that Quarkly can understand which properties can be interactively edited.

You do not need to add a Theme to your component when you use it in Quarkly. All the variables from the project will be automatically available in your component.

The configuration fields for the component look like this:

  • effects – defines browser pseudo-classes (hover, focus, etc.)
  • description – component description that will appear when you mouse over its name
  • propInfo – configuration of controls that will be displayed on the right panel
export default atomize(Box)(
    {
        effects: {
            hover: ":hover"
        },
        description: {
            en: "Awesome box component"
        },
        propInfo: {
            someProp: {
                control: "input"
            },
        },
    },
    {
        someProp: "Hello World!"
    }
);

Possible control options:

  • input
  • select
  • color
  • font
  • shadow
  • transition
  • transform
  • filter
  • background
  • checkbox-icon
  • radio-icon
  • radio-group
  • checkbox

Common properties

To specify the props to be displayed on the right panel, use this template:

  • description – tooltip text based on localization language
  • control – control type (from the list above). It is a required property
  • category – name for your category in the right panel; if there is no category with this name, it will be created automatically
  • weight – control width. The range of values is from 0 to 1, which equals from 0 to 100% of the right panel width. It is possible to show several controls in one line
someProp: {
    description: { en: "Your text" },
    control: "input",
    category: 'Main',
    weight: 1
}

Radio-icon

Returns a string with the checked value.

Property "checkedValue" describes the name for the selected option:

checkedValue: "valueName"

Checkbox-icon

Returns a string with the checked value.

Property "checkedValue" describes the name for the selected option.

Property "icon" describes the system name for the icon:

checkedValue: "valueName",
icon: "iconName"

Select and radio-group

Returns a string with the selected value.

Property "variants" contains a list of available options:

variants: ['one', 'two', 'three']

Font

Returns a string with a font styles.

italic normal 400 1em/1.5 --fontFamily-googleRoboto

Color

Returns a string with a variable or custom value in #HEX or RGBA.

Background

Returns a string with a variable or custom color in #HEX or RGBA and image or gradient styles if they were defined.

// gradient styles
#000000 repeating-linear-gradient(90deg,rgba(255,255,255,0) 0%,rgba(0,0,0,1) 100%)

// or image styles
--color-dark url(image.png) center/contain no-repeat fixed border-box

Transition, transform, shadow and filter

Returns a string with a property styles.

API Reference

atomize

import atomize from '@quarkly/atomize';

Default export. This is a wrapper around styled from styled-components.

getTransfrom

import { getTransform } from '@quarkly/atomize;

Method that returns a function by name to transform the value.

getTransform(name: string): function
  • name - method name for a transform

transformVar

import { transformVar } from '@quarkly/atomize;

Transform of CSS variables

transformVar(key: string, value: string): string;

splitCSSRule

import { splitCSSRule } from '@quarkly/atomize;

Breaks the CSS string into an array of rules.

splitCSSRule<T>(rule: T, separator?: string): Array<T>

themeDefault

Default theme for using CSS variables and defining breakpoints.

import { themeDefault } from '@quarkly/atomize;

dict

import { dict } from '@quarkly/atomize;

Dictionary for defining configuration of CSS rules

type CSSRule = {
    alias: string;
    type: Array<string> | string;
    <key>: string;
}
  • alias - name abbreviation
  • type - CSS value type

aliasesDict

import { aliasesDict } from '@quarkly/atomize;

Dictionary of abbreviations generated from dict

type Alias =  Omit<CSSRule, "alias"> & {
    name: string;
    <key>: string;
}

Docs

TODOS

  • [ ] Code refactoring to TypeScript
  • [ ] Auto sync with "can i use" and "emmet"
  • [ ] Comprehensive documentation

License

Licensed under MIT.