Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@formativesolutions/styles
Advanced tools
A collection of CSS-in-JS styling utilities used across the Formative Solutions ecosystem.
A collection of CSS-in-JS styling utilities used across the Formative Solutions ecosystem.
Install from NPM with
$ npm install --save @formativesolutions/styles
flexContainer
MixinThe 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(),
});
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)
});
@formativesolutions/styles is made available under the GNU General Public License v3.
Copyright (C) 2022 Formative Solutions
FAQs
A collection of CSS-in-JS styling utilities used across the Formative Solutions ecosystem.
The npm package @formativesolutions/styles receives a total of 3 weekly downloads. As such, @formativesolutions/styles popularity was classified as not popular.
We found that @formativesolutions/styles demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.