All Projects β†’ quarkly β†’ Atomize

quarkly / Atomize

Licence: mit
library for creating atomic react components

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Atomize

Styled Breakpoints
Simple and powerful tool for creating breakpoints in styled components and emotion. πŸ’…
Stars: ✭ 428 (+692.59%)
Mutual labels:  styled-components, css-in-js
Postjss
Use the power of PostCSS in compiling with JSS
Stars: ✭ 40 (-25.93%)
Mutual labels:  styled-components, css-in-js
Design System Utils
πŸ‘©β€πŸŽ¨ Access your design tokens with ease
Stars: ✭ 465 (+761.11%)
Mutual labels:  styled-components, css-in-js
Css In Js Benchmarks
Stars: ✭ 360 (+566.67%)
Mutual labels:  styled-components, css-in-js
Styled System
β¬’ Style props for rapid UI development
Stars: ✭ 7,126 (+13096.3%)
Mutual labels:  styled-components, css-in-js
Glamorous
DEPRECATED: πŸ’„ Maintainable CSS with React
Stars: ✭ 3,681 (+6716.67%)
Mutual labels:  styled-components, css-in-js
Styled Theming
Create themes for your app using styled-components
Stars: ✭ 1,067 (+1875.93%)
Mutual labels:  styled-components, css-in-js
satchel
The little bag of CSS-in-JS superpowers
Stars: ✭ 14 (-74.07%)
Mutual labels:  styled-components, css-in-js
Styled Tools
Useful interpolated functions for CSS-in-JS
Stars: ✭ 761 (+1309.26%)
Mutual labels:  styled-components, css-in-js
Design System
Priceline.com Design System
Stars: ✭ 604 (+1018.52%)
Mutual labels:  styled-components, css-in-js
Reactackle
Open-source components library built with React and Styled-Components.
Stars: ✭ 278 (+414.81%)
Mutual labels:  styled-components, css-in-js
Cattous
CSS in JSX for lazy developers, built using styled-components and styled-system
Stars: ✭ 38 (-29.63%)
Mutual labels:  styled-components, css-in-js
Vscode Stylelint
A Visual Studio Code extension to lint CSS/SCSS/Less with stylelint
Stars: ✭ 260 (+381.48%)
Mutual labels:  styled-components, css-in-js
Twin.macro
πŸ¦Ήβ€β™‚οΈ Twin blends the magic of Tailwind with the flexibility of css-in-js (emotion, styled-components, stitches and goober) at build time.
Stars: ✭ 5,137 (+9412.96%)
Mutual labels:  styled-components, css-in-js
react-native-css-in-js-benchmarks
CSS in JS Benchmarks for React Native
Stars: ✭ 46 (-14.81%)
Mutual labels:  styled-components, css-in-js
React Redux Saga Boilerplate
Starter kit with react-router, react-helmet, redux, redux-saga and styled-components
Stars: ✭ 535 (+890.74%)
Mutual labels:  styled-components, css-in-js
mugiwara
fast minimal CSS-in-JS created to reduce size of CSS injected
Stars: ✭ 11 (-79.63%)
Mutual labels:  styled-components, css-in-js
styled-components-docs-zh
πŸ’… styled-components δΈ­ζ–‡ζ–‡ζ‘£ηΏ»θ―‘ πŸ‡ζŒη»­ζ–½ε·₯δΈ­
Stars: ✭ 160 (+196.3%)
Mutual labels:  styled-components, css-in-js
Glamorous Native
React Native component styling solvedπŸ’„
Stars: ✭ 566 (+948.15%)
Mutual labels:  styled-components, css-in-js
Polished
A lightweight toolset for writing styles in JavaScript ✨
Stars: ✭ 7,074 (+13000%)
Mutual labels:  styled-components, css-in-js

quarkly atomize

@quarkly/atomize

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].