Giter Club home page Giter Club logo

stylable's Introduction

Stand With Ukraine

Stylable CSS for Components

Build Status

Stylable enables you to write reusable, highly-performant components. Each component exposes a style API that maps its internal parts so you can reuse components across teams without sacrificing stylability.

  • Scopes styles to components so they don't "leak" and clash with other styles.
  • Enables custom pseudo-classes and pseudo-elements that abstract the internal structure of a component. These can then be styled externally.
  • Cuts down on the resulting CSS bundles using "rule-shaking" and other optimizations

At build time, the preprocessor converts the Stylable CSS into a minimal, flat, static, valid vanilla CSS that works cross-browser.

Learn more in our Documentation Center.

Installation

There are two options for installing Stylable:

For details on both options, see Install & Configure.

Demos

Repository Structure

This repository is a mono-repo containing multiple packages that together comprise the Stylable ecosystem. It uses NPM workspaces to manage the various packages and their dependencies.

Core & Internals

Package Name Published Name Latest Version Description
core @stylable/core npm version Core CSS preprocessor
runtime @stylable/runtime npm version Runtime browser code
optimizer @stylable/optimizer npm version Production mode optimizer
module-utils @stylable/module-utils npm version Stylable CommonJS module generator
custom-value @stylable/custom-value npm version Stylable custom build-time values

Tooling & Utilities

Package Name Published Name Latest Version Description
cli @stylable/cli npm version Used for managing Stylable stylesheets in a project
create-stylable-app create-stylable-app npm version Boilerplate generator CLI
schema-extract @stylable/schema-extract npm version JSON Schema convertor for Stylable stylesheets
language-service @stylable/language-service npm version Language service protocol provider, business logic for the stylable-intelligence extension
build-tools @stylable/build-tools npm version A collection of tools used during build-time by our webpack and rollup plugins

Integrations

Package Name Published Name Latest Version Description
jest @stylable/jest npm version Jest Stylable processor plugin
node @stylable/node npm version require hook and Node module factory
webpack-extensions @stylable/webpack-extensions npm version Experimental features for webpack integration
webpack-plugin @stylable/webpack-plugin npm version webpack (^5.30.0) integration plugin
experimental-loader @stylable/experimental-loader npm version experimental webpack loader - not recommended for production use
rollup-plugin @stylable/rollup-plugin npm version Rollup (v2.x) integration plugin
esbuild @stylable/esbuild npm version esbuild integration plugin

Test-kits

Package Name Published Name Latest Version Description
e2e-test-kit @stylable/e2e-test-kit npm version webpack project runner used for E2E testing
dom-test-kit @stylable/dom-test-kit npm version Stylable DOM related testing utils
core-test-kit @stylable/core-test-kit npm version Utilities used for testing core Stylable operations (processing and transformations)

External Packages

Package Name Description
stylable-intelligence VSCode extension providing language services for Stylable

Contributing

Read our contributing guidelines for details on our code of conduct, and the process for submitting pull requests.

License

Copyright (c) 2017 Wix.com Ltd. All Rights Reserved. Use of this source code is governed by a MIT license.

stylable's People

Contributors

0xflotus avatar alexk0ch avatar amitdahan avatar annielr avatar arnonkehat avatar avivahl avatar barak007 avatar deduckproject avatar denysdovhan avatar dependabot-preview[bot] avatar dependabot[bot] avatar dvdovenko avatar gaxze avatar gendeld avatar hadarge avatar idoros avatar mykolavlasov avatar nadavwix avatar oleksiik-uxd avatar petershershov avatar qballer avatar ranyitz avatar rashellekosib avatar scott-macd avatar talh78 avatar tempit avatar tomrav avatar tzachbon avatar wtfil avatar yurynix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stylable's Issues

pseudo-state custom mapping

Need a way to define custom mapping in order to support none stylable libs:

CSS API:

/* example-custom.css */
.root{
    -sb-states: toggled(".on"), loading("[data-spinner]");
}
.root:toggled { color:red; }
.root:loading { color:green; }

CSS OUTPUT:

/* namespaced to example-custom */
.root.on { color:red; }
.root[data-spinner] { color:green; }

Output CSS format in docs is not clear

Currently docs CSS output is declaring that the selectors shown are "scoped" or event "scoped to *". I'm not sure it's clear and it get confusing in some examples that involves multiple stylesheets.

I think we should switch back to putting @namespace "X" in every example and show the actual CSS output.

Create handling for :hover for touch devices

Problem:

  • :hover handling on mobile is bad (hover is activated on touch, but doesn't get deactivated until you touch something else), so we need to disable hover on mobile
  • :active on mobile provides the same functionality as :hover on desktop. So it is preferred that we remap :hover to :active on mobile, unless :active is explicitly specified by the user.

Proposed solution:

  • When encountering :hover in CSS, auto-create a media query, something along the lines:
@media (hover: none) {
    .root:hover {
           /* reset the rules */
    }
    .root:active {
        /* put original hover rules here */
    }
}
  • Do the above unless there is also a :active selector present for the same selector. In that case, just reset/remove the hover.

output clean namespace

At the moment any namespace is composed of @namespace + file content hash.

  • add hash only in cases of conflict and we can use a simple counter instead of hash
  • use filename as default @namespace

In case of CSS standalone export we can generate better or configurable namespace, but its not in our short term goals.

feat: expose debugging information for dev-time

  • variable source comment next to resolved values

    include a comment in target CSS (available in browser CSS dev tools) that will indicate the source of values that are derived from variables. (should include a file path, as well as a variable name)

  • variable override (in var source location)

    enable overriding variables (in their source location), in order to allow real-time debugging of their effects

  • file separators between CSS rulesets

    in developer tools expose file separators at relevant component bounds

Error messages are vague

Received the following error due to a missing underscore in a "value" function. E.g the import was named color_Main_Text but was used as value(color_MainText).

screen shot 2017-07-24 at 12 57 45

documentation examples using "Button" need to be changed

we'd like to use something that doesn't have a native HTML counterpart

  • stylable-basics for example.

Per @idoros we can use Gallery built this way:

.root {
    -st-states: empty, inTransition;
}
.navBtn {
    -st-states: previous, next;
}
.mainImage {
    -st-states: shown;
}
.thumb {
    -st-states: previous, current, next;
} 

Export whole theme as single variable

Exporting of multiple variables from theme is not that easy
Right now exporting of multiple variables looks like this

:import(@theme) {                                                                                                                                                                                                                             
  -sb-named: inputBorder, borderRadiusInput, fontSizeSmall, lineHeightNormal, fontFamily, textMain, backgroundHover                                                                                                                           
} 

Using * or any other character for bulk export (like in es import statement)

:import(@theme) {                                                                                                                                                                                                                             
  -sb-theme: myTheme                                                                                                                          
} 

Component.stylesheet moves to Component.prototype.render.stylesheet

Hi!
I reciently updated the stylabale from 0.0.12 to 1.0.2 and static property stylesheet from component moved to it render function

I think it related to different wrapping approach.
In new version you wraps the render which replaced with new react component and this new component has the stylesheet as static property, but as subsequence this property accessible from via render

Just to clarify:
0.0.12

@SBComponent(styles)
class A extends React.Component<{}, {}> {}

A.stylesheet.get('class-name')

1.0.2

@SBComponent(styles)
class A extends React.Component<{}, {}> {}

A.prototype.render.stylesheet.get('class-name')

Custom Pseudo-Class with Parameters

CustomTag:customState(val) {}

Transform to:

.root CustomTag_root[data-CustomTag-customState="val"]

Usage example:

.myForm::field:name(title):empty{
    background:blue;
}

create readme.md for stylable/runtime

Sections:

about:

this is what is imported instead of css...

  • small size

api:

-root
-get
-csStates

manual integration:

if not using stylable-react-component you should...

manual creation

for projects without stylable-integration
for tests

handle string value in mixin param

    -sb-mixin: mix(300, xxx); /* ["300", "xxx"] */
    -sb-mixin: mix(300, "xxx"); /* ["300", "xxx"] */
    -sb-mixin: mix(300, "xx,x"); /* ["300", "xx,x"] */
    -sb-mixin: mix(300, "\"xxx\""); /* ["300", "\"xxx\""] */

Mixin reference should describe how mixins are defined

Currently, looking at mixins reference page one cannot find how are they defined and parametrized (mixins with parethesis). Variants page gets this right, both usage and definition are described well. Would be nice to have the same structure for mixins page, too.

Install Configure and Build Guide

Install, Configure and Build

Install it for a project

npm install stylable

best practices for WebPack or other popular build tool with React
(Then other options - clean project w/ no build and/or no React)

Stylesheet file
Component file

Import stylesheet into component file

What part of library has been loaded into runtime. Don't want to bring parser and other stuff into client-side. Different between working at build time or runtime. We recommend build time but then need WebPack or other build tool. Must be decided while users working cuz depends on what has to be imported. (Maybe some debugging options can give.)

Don't have to provide source maps for CSS. Cuz everything is compiled down to CSS. Debug mode could give you comments on where the rules came from.

Add to feature list: Debug comments added to CSS - where did styling come from to produce CSS. Configure how you want CSS outputted. Removed for production -

Good to have "create app" instruction

npm stylable - what will user get?

  • boilerplate

Specificity document - transpiler switch to show specificity or comment to show specificity

List of 50 components
CSS mixin of how something looks - UI kit to provide mixins and enable writing your own
some containers need component

Provide instructions for writing own mixins or CSS or JS

TUTORIAL

2 component files

Document css.ts file - used for only internal use. not documenting JavaScript API

generateSVGURL - mixin

vbox, hbox, grid - will be mixins
But more complex layouts have to be components
Component is needed only if logic needed to build it.

StylableReact - POC

Create component file as .tsx - social-button.tsx
Create a css file - social-button.css (social-button.css.ts)

For each component have a different CSS file. Associate component with CSS file in the component ts file.

Styling social button from the outside:
Add a className in tsx file.

In CSS for

insert mixin in the position it is declared

  • rules are added at the position that the -st-mixin is declared
  • appended selectors are added directly after the rule-set that the mixin was applied to
  • multiple mixins are applied according to the order that they are specified in

CSS API:

.a{
    color:red;
    -st-mixin: golden;
    background:white;
}
.a:hover{
    background:white;
}

CSS OUTPUT:

.a{
    color:red;
    color:gold; /* added by golden */
    background:black; /* added by golden */
    background:white;
}
.a:hover{
    color:gold; /* added by golden */
    background:black; /* added by golden */
}
.a:hover{
    background:white;
}

Definitely Stylable

Definitely stylable

Use custom selectors, global selector and custom pseudo-classes mapping to describe style interfaces for components that were not originally build with Stylable.

Example

For a BEM toggle button with icon component:

<button class="btn"> /* potentially contain `.btn--toggled` class */
    <span class="btn__icon">
    <span class="btn__label">
<button>

Interface stylesheet

A separate "interface" stylesheet can help describe a way to style it:

/* external-toggle-button.css */
.root {/* ToDo: way to override root selector */
    -st-states: toggled(".btn--toggled");
}
:--icon :global(.btn__icon);
:--label :global(.btn__label);

Usage

Use like any other Stylable stylesheet to style:

CSS api:

:import {
    -st-from: "./external-toggle-button.css";
    -st-default: ToggleBtn;
}
.my-btn{ 
    -st-extends: ToggleBtn;
    background: red;
}
.my-btn:toggled {
    background: green;
}
.my-btn::label {
    font-size: 20px;
}

CSS output:

.my-btn { 
    background: red;
}
.my-btn.btn--toggled {
    background: green;
}
.my-btn .btn__label {
    font-size: 20px;
}

// add more cases... missing real-world CSS usage

Separate variant and CSS mixin docs

Currently docs reference for variant contains two topics.

  • Variant as as syntax: not automatically outputted to CSS
  • Mix CSS classes using -st-extends and -st-mixin

definitely-stylable page

This page isn't clear to me.

How does external-toggle-button.css get wired up to the BEM component?
(I assume an import, but docs shouldn't leave me guessing).

It appears that a custom property :--icon and :--label are set up as
"aliases" for things inside the BEM component, but then are never
used, so I don't really get to understand the full use.

(unless .my-btn::label is styling the BEM label rather than an HTML
element, in which case PLEASE let's not confuse people by hijacking
HTML elements as class names).

And if external-toggle-button.css needs to :import the BEM component from
www.thirdparty.com/BEM.html, why don't we just do -sb-named: btn__icon
as icon, btn__label as my-label rather than set up custom properties?

odd vars declaration

It looks to odd when you have to create a instance (which is not used anywhere) to declare the vars

new Stylesheet({                                                                                                                                                                                                                            
    ':vars': theme,                                                                                                                                                                                                                           
    '@namespace': '@theme'                                                                                                                                                                                                                    
})
Stylesheet.context.attach() 

I suggest to create static method in context instead

Stylesheet.context.addVars('@theme', theme) 

Support file:// protocol in StylableResolver

VsCode and doc managers in general use file:// protocol to provide paths, Stylable resolver crashes on this.
Hacking this from the outside is hard (no success yet), since you need to pass it a MinimalFS that has readFileSync which gets used in different contexts. So I can't pass it an FS that adds (or removes) file:// prefix.

support identical selectors

At the moment selectors with same value are merged:

.a { color:green; }
.b { color:red; }
.a { background:purple; }

will invalidly transform to:

.a { color:green; background:purple; }
.b { color:red; }

consider adding support for `import * as`

Import currently allow default and named imports.
allow something like:

@st-import * as Everything from "./a";

Equal to in JS:

import * as Everything from "./a";

Where Everything is the reference to the entire module's contents.

Need to understand how access the exports in CSS:

.some-cls{
    -st-extends:Everything.something; /* doesn't look good in CSS */
}

Live feedback from presentation

sb seems like the wrong prefix: st, core, style, wix etc looks better.
stylesheet.context.attach is a bad name. Should be named something like renderCSS. In other words, something which implies that this is the function which renders the CSS to the DOM.

use ifndef to namespace of styleable.

Nested classes with mixin does not work

I have a class and a selector:

.blue {
    -st-mixin: MyMixin(1, 2, 3);
}
.blue.small {
    -st-mixin: MyMixin(4, 5, 6);
}

that I want to bring into the class using nested classes:

.blue {
    -st-mixin: MyMixin(1, 2, 3);
    &.small {
        -st-mixin: MyMixin(4, 5, 6);
    }
}

The generated CSS does not activate the mixin with (4, 5, 6) when the small class is also applied (It applies the original, (1, 2, 3) mixin)

support multiple selectors in createClassSubsetRoot

source:

.a { 1 }
.a:hover { 2 }
.a, .b, .a .c { 3 }

.x {
    -st-mixin: a;
}

target:

.a { 1 }
.a:hover { 2 }
.a, .b, .a .c { 3 }

.x { 1 } 
.x:hover { 2 } 
.x, .x .c { 3 } /* .b is removed since its not part of the mixin '.a' */

.x, .x .c { 3 } - not outputted today - bug

Slider readme - fix code examples

All code examples in this document need to be rewritten along with whoever actually develops the component.

@abumami Please work on this ASAP, so we also have a proper example in the documentation

@maksymc FYI. who is the dev working on this? where did you get the current example code?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.