Navigation
Page Navigation Macros and Markers Macro Types Adding Custom Macros Standard Macros Flow/Layout Macros [flex $] [fl-center] [grid $] [gr.cols-fit $] and [gr.cols-fill $] [hide] [invis] Component Macros [$color $] [$compact] [$flat], [$fill], [$outline] [$title] and [$subtitle]
Site Navigation

Macros and Markers

Windstorm uses macros to customize elements. Many of the built in macros are shorthands for common css tweaks, similar to libraries like tailwind, but instead of defining hundreds of rules ahead of time and needing a build step to reduce them down, the macros just take arguments generate the necessary styling at runtime so that the core library doesn't need a special step to reduce its size. Despite generating information at runtime, windstorm is incredibly fast and plays nicely with other libraries and frameworks.

Markers are customizations that change the presentation of an element in a substantial way (themes, making anchors look like buttons, etc.). Markers have no macro definition because they are maintained in regular css.

Macro Types

Windstorm has 3 kinds of macros that can be used:

  • normal macros that are just text, hypens, and dots ([\w\-\.]+)
  • component customization macros are prefixed with $
  • css custom properties (varaibles) that are prefixed with @

Internally there are slight differences in how each of these are processed.

  • If no definition is found for a normal macro, windstorm will log an error into the console.
  • If no definition is found for component macros, no error is logged.
  • CSS variables do not attempt to find a macro.

Adding Custom Macros

Windstorm supports adding custom macros through abuse of css that is loaded before the script begins processing the page. Custom macros will do string interpolation on the definitions (except in the default argument def), so macros can build on top of other macros. In order to prevent accidental recursion all macros must be defined before they are used in another macros definition.

For custom macros to be processed, a <link> or <style> tag must have the ws-root attribute on it. Those tags can contain any normal css declarations, with macros only being built from any .ws-style declarations.

<style ws-root>
    /* ignored by windstorm, still applies as normal css */
    div { font: Courier New; }

    /*
    macro names need to start with "--" so that the browser sees them as
    custom css properties and doesn't throw them away. The "--" is removed
    automatically to buld the macros and check their names.
    */
    .ws-root {
        /* creates a macro named "cool-text" */
        --cool-text:
            /* use strings for standard css properties */
            "color: teal"
            /* macro syntax works for custom macros defs \o/ */
            [b 1px solid teal]
            /* variables too */
            [@color teal]
        ;
        --cooler-text:
            /* $ is the argument to the macro, and can have a default value */
            $="@primary"
            /* use "{$}" to put the argument somewhere */
            [t.c {$}]
            /* argument can be used in string interpolation */
            "background-color: {$}-ripple"
        ;
    }
</style>
<script src="{windstorm}"></script>

<div ws-x="[cool-text]">Teal border, blue text</div>
<div ws-x="[cooler-text @secondary]">Green border, blue text, sick background</div>

Standard Macros

The standard macros are just macros that map to specific css properties. These can be used to customize any regular elements, or add more style to any of the components that ship with windstorm.

Macro CSS Properties
[area $] grid-area
[b $] border
[b.c $] border-color
[b.s $] border-style
[b.w $] border-width
[b.b $] border-bottom
[b.b.c $] border-bottom-color
[b.b.s $] border-bottom-style
[b.b.w $] border-bottom-width
[b.t $] border-top
[b.t.c $] border-top-color
[b.t.s $] border-top-style
[b.t.w $] border-top-width
[b.l $] border-left
[b.l.c $] border-left-color
[b.l.s $] border-left-style
[b.l.w $] border-left-width
[b.r $] border-right
[b.r.c $] border-right-color
[b.r.s $] border-right-style
[b.r.w $] border-right-width
[b.x $] border-left
border-right
[b.x.c $] border-left-color
border-right-color
[b.x.s $] border-left-style
border-right-style
[b.x.w $] border-left-width
border-right-width
[b.y $] border-top
border-bottom
[b.y.c $] border-top-color
border-bottom-color
[b.y.s $] border-top-style
border-bottom-style
[b.y.w $] border-top-width
border-bottom-width
[bg $] background
[bg.att $] background-attachment
[bg.c $] background-color
[bg.img $] background-image
[bg.rep $] background-repeat
[bg.pos $] background-position
[bg.sz $] background-size
[c $] color
[col $] grid-column
[cur $] cursor
[disp $] display
[fl.basis $] flex-basis
[fl.cross $] align-items
[fl.dir $] flex-direction
[fl.flow $] flex-flow
[fl.grow $] flex-grow
[fl.main $] justify-content
[fl.shrink $] flex-shrink
[fl.size $] flex
[fl.wr $] flex-wrap
[font $] font-family
[gap $] gap
[gap.row $] row-gap
[gap.col $] column-gap
[gr.area $] grid-template-areas
[gr.cols $] grid-template-columns
[gr.cols.a $] grid-auto-columns
[gr.flow $] grid-auto-flow
[gr.rows $] grid-template-rows
[gr.rows.a $] grid-auto-rows
[h $] height
[h.min $] min-height
[h.max $] max-height
[inset $] top
left
bottom
right
[inset.x $] left
right
[inset.y $] top
bottom
[m $] margin
[m.b $] margin-bottom
[m.l $] margin-left
[m.r $] margin-right
[m.t $] margin-top
[m.x $] margin-left
margin-right
[m.y $] margin-bottom
margin-top
[o $] opacity
[outln $] outline
[over $] overflow
[over.x $] overflow-x
[over.y $] overflow-y
[p $] padding
[p.b $] padding-bottom
[p.l $] padding-left
[p.r $] padding-right
[p.t $] padding-top
[p.x $] padding-left
padding-right
[p.y $] padding-top
padding-bottom
[pos $] position
[r $] border-radius
[r.b $] border-bottom-left-radius
border-bottom-right-radius
[r.bl $] border-bottom-left-radius
[r.br $] border-bottom-right-radius
[r.l $] border-top-left-radius
border-bottom-left-radius
[r.r $] border-top-right-radius
border-bottom-right-radius
[r.t $] border-top-left-radius
border-top-right-radius
[r.tl $] border-top-left-radius
[r.tr $] border-top-right-radius
[row $] grid-row
[sel $] user-select
[self.cross $] align-self
[self.main $] justify-self
[sh.box $] box-shadow
[sh.text $] text-shadow
[t.a $] text-align
[t.br $] word-break
[t.c $] color
[t.dec $] text-decoration
[t.lh $] line-height
[t.over $] text-overflow
[t.sz $] font-size
[t.tf $] text-transform
[t.ws $] white-space
[t.wt $] font-weight
[tf $] transform
[tf.o $] transform-origin
[tf.p $] perspective
[tr $] transition
[vis $] visibility
[w $] width
[w.min $] min-width
[w.max $] max-width
[x $] left
[-x $] right
[y $] top
[-y $] bottom
[z $] z-index

Flow/Layout Macros

[flex $]

Makes an element use flexbox for layout. The argument is optional and will specify the flex-direction. Will use column direction by default.

[fl-center]

Makes a flex display element center the content horizontally and vertically.

[grid $]

Makes an element use css grid for layout. The argument is optional and will specify the grid-direction. Will use row layout by default.

[gr.cols-fit $] and [gr.cols-fill $]

Convenience macros that use the auto-fit and auto-fill properties of repeating grid columns combined with minmax. The argument to the macro is inserted into the css repeat(<fit>, minmax($)).

[hide]

Hides an element and removes it from the layout calculations (uses display: none).

[invis]

Hides an element but does not remove it from the layout (uses visibility: hidden).

Component Macros

Windstorm uses macros prefixed with "$" to specify component customizations. These macros can be written and used as normal, but are intended for use with components because they set multiple properties, many of which aren't used by regular elements.

[$color $]

Sets the color scheme for a component. Expects a color variable like @primary.

[$compact]

Reduces the padding on buttons. Useful for putting them into adornment areas.

[$flat], [$fill], [$outline]

Changes how the border and fill of a component look. Flat components have no background or borders, fill have no borders but a filled background, and outline has no background but visible borders.

[$title] and [$subtitle]

Used to adjust the size and style of text in things like the ws-titlebar.