All Projects → lttb → Reshadow

lttb / Reshadow

Licence: mit
Markup and styles that feel right

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Reshadow

Scoped Style
A tiny css in js library 🚀
Stars: ✭ 129 (-62.39%)
Mutual labels:  preact, css-in-js
Filbert Js
A lightweight(~1kb) css-in-js framework
Stars: ✭ 167 (-51.31%)
Mutual labels:  preact, css-in-js
Omil
📝Webpack loader for Omi.js React.js and Rax.js components 基于 Omi.js,React.js 和 Rax.js 单文件组件的webpack模块加载器
Stars: ✭ 140 (-59.18%)
Mutual labels:  preact, shadow-dom
Nyancss
🌈 Write plain CSS while reaping benefits of CSS-in-JS
Stars: ✭ 544 (+58.6%)
Mutual labels:  preact, css-modules
linaria-styled
Zero-runtime CSS in JS library for building React components
Stars: ✭ 17 (-95.04%)
Mutual labels:  css-modules, css-in-js
Microsite
Do more with less JavaScript. Microsite is a smarter, performance-obsessed static site generator powered by Preact and Snowpack.
Stars: ✭ 632 (+84.26%)
Mutual labels:  preact, css-modules
Omi
Front End Cross-Frameworks Framework - 前端跨框架跨平台框架
Stars: ✭ 12,153 (+3443.15%)
Mutual labels:  preact, shadow-dom
Css In React
🍭 CSS in React - Learn the best CSS in JS frameworks by example
Stars: ✭ 101 (-70.55%)
Mutual labels:  css-in-js, css-modules
jess
If you like CSS, Less, Sass, and/or CSS modules, you're gonna want to star this repo.
Stars: ✭ 26 (-92.42%)
Mutual labels:  css-modules, css-in-js
macos-preact
macos-preact.now.sh
Stars: ✭ 1,019 (+197.08%)
Mutual labels:  preact, css-modules
Design System Utils
👩‍🎨 Access your design tokens with ease
Stars: ✭ 465 (+35.57%)
Mutual labels:  preact, css-in-js
11tyby
Simple 11ty setup using TypeScript, SASS, Preact with partial hydration, and other useful things. Aims to provide the DX of Gatsby, but using 11ty!
Stars: ✭ 38 (-88.92%)
Mutual labels:  preact, css-modules
Styled Breakpoints
Simple and powerful tool for creating breakpoints in styled components and emotion. 💅
Stars: ✭ 428 (+24.78%)
Mutual labels:  preact, css-in-js
Preact Boilerplate
🎸 Ready-to-rock Preact starter project, powered by Webpack.
Stars: ✭ 959 (+179.59%)
Mutual labels:  preact, css-modules
Css In Js 101
💈 CSS-in-JS 101: All you need to know
Stars: ✭ 252 (-26.53%)
Mutual labels:  css-in-js, css-modules
Goober
🥜 goober, a less than 1KB 🎉 css-in-js alternative with a familiar API
Stars: ✭ 2,317 (+575.51%)
Mutual labels:  preact, css-in-js
Styled Jsx
Full CSS support for JSX without compromises
Stars: ✭ 6,768 (+1873.18%)
Mutual labels:  css-in-js, shadow-dom
Moo Css
模块化面向对象的css写法规范策略。适用于大中小型C端项目样式开发,旨在提高开发和维护效率。
Stars: ✭ 79 (-76.97%)
Mutual labels:  css-in-js, css-modules
Jsxstyle
Inline style system for React and Preact
Stars: ✭ 1,990 (+480.17%)
Mutual labels:  preact, css-in-js
mediocre-pictures
Helping you take mediocre pictures, hands-free. 📷🙆🏻🙅🏾💁🏼📸
Stars: ✭ 16 (-95.34%)
Mutual labels:  preact, css-in-js

reshadow ⛱️

Github Actions Coverage Status branch npm version Babel Macro

Markup and styles that feel right.

Please check the reshadow.dev website to get more information and examples.

reshadow provides the Shadow DOM developer experience, but for the Virtual DOM with the Component way.

import React from 'react';
import styled, {css} from 'reshadow';

// Write styles:
const styles = css`
    button {
        width: 200px;
    }
    content {
        font-size: 14px;
    }
`;

export const Button = ({children, ...props}) => {
    // connect the styles to the markup:
    return styled(styles)(
        <button {...props}>
            <content as="span">{children}</content>
        </button>,
    );
};

This project has alpha status, so the API and the implementation could be changed.

Features

  • Get away from additional abstractions
    • Write isolated semantic styles for the Virtual DOM in a native like way
    • Match styles on the elements, components, and props. That's all you need
  • Compile-time styles processing and efficient runtime
  • Static styles extracting options
  • Static analysis
  • Combine the css-in-js and css-modules approaches or choose which fits you better
  • All the benefits of the PostCSS ecosystem
  • Interoperable. Use it with components in React, Preact, Vue, htm.

There are some examples on the Сodesandbox:

Benchmarks

There are also some css-in-js benchmarks, that are available on the codesandbox.

reshadow benchmarks

Docs

npm i --save reshadow

.babelrc

{"plugins": ["reshadow/babel"]}

Check the Setup page to get more details (including setup with Create React App)

Example

import React from 'react';
import styled from 'reshadow';
import {readableColor, rgba} from 'polished';

const Button = ({
    bgcolor = 'lightgray',
    size = 's',
    children,
    ...props
}) => styled`
    button {
        cursor: pointer;
        padding: 5px 10px;
        border-radius: 5px;
        border: 2px solid ${bgcolor};
        background-color: ${rgba(bgcolor, 0.7)};
        color: ${readableColor(bgcolor)};
        transition: background-color 0.5s;

        &:hover {
            background-color: ${rgba(bgcolor, 0.9)};
        }
    }

    /**
     * Match on the 'disabled' prop,
     * not the DOM attribute
     **/
    button[disabled] {
        opacity: 0.5;
        pointer-events: none;
    }

    /**
     * Match on the 'use:size' prop
     */
    button[use|size='s'] {
        font-size: 12px;
    }

    /* The 'use' namespace can be omitted */
    button[|size='m'] {
        font-size: 14px;
    }
`(
    /* use:size property would not pass to the DOM */
    <button {...props} use:size={size}>
        {children}
    </button>,
);
const Container = () => styled`
    Button + Button {
        margin-left: 10px;
    }
`(
    <div>
        <Button size="m" bgcolor="lightgray">
            lightgray
        </Button>
        <Button size="m" bgcolor="orange">
            orange
        </Button>
        <Button size="m" bgcolor="rebeccapurple">
            rebeccapurple
        </Button>
    </div>,
);

buttons

Usage

css-modules

Button/index.js

import React from 'react';
import styled from 'reshadow';

import styles from './styles.css';

export const Button = ({size, children}) => styled(styles)(
    <button use:size={size}>{children}</button>,
);

Button/styles.css

button {
    /* button styles */
}
button[|size='m'] {
    /* button styles for the size */
}

css-in-js

import React from 'react';
import styled, {css} from 'reshadow';

const anotherStyles = css`
    button[disabled] {
        /* disabled button styles */
    }
`;

export const Button = ({size, children}) => styled(
    props.another && anotherStyles,
)`
    button {
        /* button styles */
    }
    button[|size='m'] {
        /* button styles for the size */
    }
`(<button use:size={size}>{children}</button>);

Setup

Macro

With CRA 2 (Create React App) or babel-plugin-macros usage you can just use reshadow/macro out of the box.

import React from 'react';
import styled from 'reshadow/macro';

export const Button = ({children}) => styled`
    button {
        /* button styles */
    }
`(<button>{children}</button>);

Options (via babel-plugin-macros config) are the same as reshadow babel options, but with different defaults:

option default value
postcss true
files /.shadow.css$/

Babel

Add reshadow/babel to the plugin list.

babel.config.js

module.exports = {
    plugins: ['reshadow/babel'],
};

Options

option type default value description
postcss boolean | {plugins: Plugin[]} false Use PostCSS to process CSS code. You can add your custom PostCSS plugins (they should be sync)
files boolean | RegExp false Resolve and process css files imports that match to the RegExp
elementFallback boolean | string 'div' Use fallback for the custom elements

PostCSS

Add reshadow/postcss to the plugin list.

postcss.config.js

module.exports = {
    plugins: ['reshadow/postcss'],
};

Webpack

Use reshadow/webpack/loader to extract styles in separate files.

webpack.config.js

{
    test: /\.js$/,
    use: [
        'reshadow/webpack/loader',
        'babel-loader',
    ]
}

Linting

Use reshadow/eslint if you want to have more control about reshadow usage.

Rules:

Prettier

Use reshadow/prettier if you want to improve your Developer Experience with prettier.

prettier.config.js

module.exports = {
    plugins: ['reshadow/prettier'],
};

Special Thanks

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].