npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@formativesolutions/styles

v1.0.2

Published

A collection of CSS-in-JS styling utilities used across the Formative Solutions ecosystem.

Downloads

4

Readme

Formative Solutions - Coloirs

A collection of CSS-in-JS styling utilities used across the Formative Solutions ecosystem.

Find @formativesolutions/styles on NPM.

Table of Contents

Installation

Install from NPM with

$ npm install --save @formativesolutions/styles

Basic Usage

flexContainer Mixin

The flexContainer CSS-in-JS mixin in used to quickly and easily create flexboxes (typically within Emotion-style style definitions) and comes with a number of fully-typed configuration options:

const flexboxStyles: SerializedStyles = css({
    ...flexContainer({
        direction: "row",
        bothAxis: "space-between",
    }),
    // other random styles for your flexbox container:
    width: "70%",
    backgroundColor: "orange",
});

The configuration options for this mixin are as follows (note that these are not technically the exact types used to define the configuration options, but rather a simplified version of the real thing.):

type FlexContainerConfiguration = {
    direction?: "row" | "row-reverse" | "column" | "column-reverse",
    wrap?: boolean,
    mainAxis?: FlexAlignmentOption,
    crossAxis?: FlexAlignmentOption,
    bothAxis?: FlexAlignmentOptions,
};
type FlexAlignmentOptions = "start" | "center" | "end" | "stretch" | "space-around" | "space-between" | "space-evenly";

As you may have noticed, each of these fields are optional. If not provided, these are the default values for each field:

const defaults: FlexContainerConfiguration = {
    direction: "column",
    wrap: false,
    mainAxis: "center",
    crossAxis: "center",
    bothAxis: "center",
};

Because of these default values, the flexContainer mixin can be used to very quickly and easily create a container that centers its content!

const flexboxStyles: SerializedStyles = css({
    ...flexContainer(),
});

Color Mapping

The color mapping functions and types from this package allow you to automate and typecheck the process of maintaining named colors throughout your code - all while using CSS variables!

First, I typically create a colors.ts file in an appropriate place in my codebase, and populate it with the following template:

export type Color =
    | "FOREGROUND"
    | "BACKGROUND"
    | "BADASS";

export const RAW_COLORS: ColorMap<Color> = {
    FOREGROUND: "#000",
    BACKGROUND: "#FFF",
    BADASS: "#BADA55",
};

export const COLORS: ColorMap<Color> = createColorToCSSVariableNameMap(RAW_COLORS);

And then the following code can be put wherever you store your global style definitions (or wherever you want the above styles scoped to):

const COLOR_VARIABLE_DEFINITIONS: Record<string, string> =
    generateColorDefinitionsCSSObject(RAW_COLORS);

const styles: SerializedStyles = css({
    ":root": {
        ...COLOR_VARIABLE_DEFINITIONS,
    },
});

Tada! Now, you can use the following style of accessing your colors wherever you like in your codebase!

import { COLORS } from "./wherever/you/put/the/COLORS/constant.ts";

const myStyles: SerializedStyles = css({
    borderColor: COLORS.FOREGROUND, // => border-color: var(--foreground)
    backgroundColor: COLORS.BADASS, // => background-colors: var(--badass)
    color: COLORS.BACKGROUND, // => color: var(--background)
});

License

@formativesolutions/styles is made available under the GNU General Public License v3.

Copyright (C) 2022 Formative Solutions