Popularity
1.7
Growing
Activity
6.4
-
57
3
6

Description

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.

Monthly Downloads: 0
Programming language: JavaScript
License: MIT License
Latest version: v1.0.8

atomize-by-quarkly alternatives and similar libraries

Based on the "Responsive" category.
Alternatively, view atomize-by-quarkly alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of atomize-by-quarkly or a related project?

Add another 'Responsive' Library

README

@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]((https://styled-components.com/docs/api#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 all licence references and agreements mentioned in the atomize-by-quarkly README section above are relevant to that project's source code only.