0.0.13 • Published 17 days ago

cssx-framework v0.0.13

Weekly downloads
-
License
ISC
Repository
-
Last release
17 days ago

Overview

CSSX is a web UI framework with file-path routing. You've heard of CSS-in-JS, and CSS pre/post-processors like SASS, LESS, and Tailwind - but now get ready for a whole new world of CSS driven development, with CSSX!

Why?

I built CSS because I thought it was an entertaining idea and would parallel the million JS frameworks that exist. It doesn't really have a purpose except to entertain and see if it was possible.

Getting Started

From the terminal, run npx create-cssx@latest or npm create cssx@latest, and follow the prompts to set up a basic template. From there run (npm | yarn | pnpm | bun) install > (npm | yarn | pnpm | bun) start to spin up the local dev environment.

Folder Structure

As CSSX is a file-path route based framework, the default template expects each page to be a .cssx file within a ./routes directory. This can be updated by changing the directory path passed into the generateRoutes() function in the app.js file.

Any mixins or shared components that are setup can be stored however you like, and then referenced as imports (@import '{relative_path_to_file}';) relative to the calling file.

Code Structure

Overview

.cssx files have roughly the same format as a standard .css file, but with some additional functions like mixins in order to provide functionality for shared component styling.

To render elements on the page, simply write the CSS you require, but include the element tag in the specificity of the class (ie. div.root would render a div element with the class root). Any element attributes you wish to include can be added in the same format as CSS variables nested within the class definition.

In order to define nested elements, just nest the CSS class definitions under the appropriate parent, like you would structure regular CSS.

eg.

div.root {
    color: red;
    --title: Div Title;
    --text: Some text;

    button {
        border-radius: 8px;
        color: blue;
        --onclick: alert('Button clicked!');
        --text: Click me;
        --type: button;
    }
}

would become =>

<div class="root" title="Div Title">
    Some text
    <button onclick="alert('Button clicked!')" type="button">
        Click me
    </button>
</div>

with the stylesheet

div.root {
    color: red;

    button {
        border-radius: 8px;
        color: blue;
    }
}

Mixins / Shared Components

Mixins can be defined with the syntax below:

@mixin mixinName($param1: defaultValue1, $param2: defaultValue2) {
    ...
}

and referenced as an @include statement: @include mixinName(); (For brevity, the parentheses can be omitted if empty @include mixinName;)

Mixin parameters can be overridden when including in a component, but if defining overrides then all parameters must be defined - ie. either define all of them, or leave them empty. If not all parameters are to be overridden, then the value default can be used as a placeholder: @include mixinName(default, overrideValue);

A mixin can either be defined as a full component, with the element definition at the top level:

@mixin standardButton($backgroundColor: lightgreen, $hoverColor: lightblue, $class: example, $borderRadius: 6px, $type: button) {
    button {
        background-color: $backgroundColor;
        --borderRadius: $borderRadius;
        --class: $class;
        --type: $type;

        &:hover {
            background-color: $hoverColor;
        }
    }
}

div.root {
    @include standardButton;
}

or just as the nested styles / attributes / children, depending how you wish to interact with them

@mixin standardButton($backgroundColor: lightgreen, $hoverColor: lightblue, $class: example, $borderRadius: 6px, $type: button) {
    background-color: $backgroundColor;
    --borderRadius: $borderRadius;
    --class: $class;
    --type: $type;

    &:hover {
        background-color: $hoverColor;
    }
}

div.root {
    button {
        @include standardButton;
    }
}
0.0.13

17 days ago

0.0.10

18 days ago

0.0.11

18 days ago

0.0.12

17 days ago

0.0.9

19 days ago

0.0.8

21 days ago

0.0.5

21 days ago

0.0.7

21 days ago

0.0.6

21 days ago

0.0.4

22 days ago

0.0.3

22 days ago

0.0.2

23 days ago

0.0.1

23 days ago