Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vanilla-extract/dynamic

Package Overview
Dependencies
Maintainers
4
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vanilla-extract/dynamic - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

LICENSE

0

dist/declarations/src/assignInlineVars.d.ts

@@ -0,0 +0,0 @@ import { Contract, MapLeafNodes } from '@vanilla-extract/private';

export { assignInlineVars } from './assignInlineVars';
export { setElementVars } from './setElementVars';
import { Contract, MapLeafNodes } from '@vanilla-extract/private';
export declare function setElementVars(element: HTMLElement, vars: Record<string, string>): void;
export declare function setElementVars<ThemeContract extends Contract>(element: HTMLElement, contract: ThemeContract, tokens: MapLeafNodes<ThemeContract, string>): void;

13

package.json
{
"name": "@vanilla-extract/dynamic",
"version": "2.0.0",
"version": "2.0.1",
"description": "Zero-runtime Stylesheets-in-TypeScript",

@@ -8,2 +8,9 @@ "sideEffects": false,

"module": "dist/vanilla-extract-dynamic.esm.js",
"exports": {
"./package.json": "./package.json",
".": {
"module": "./dist/vanilla-extract-dynamic.esm.js",
"default": "./dist/vanilla-extract-dynamic.cjs.js"
}
},
"files": [

@@ -20,3 +27,3 @@ "/dist"

"dependencies": {
"@vanilla-extract/private": "^1.0.0"
"@vanilla-extract/private": "^1.0.2"
},

@@ -26,2 +33,2 @@ "devDependencies": {

}
}
}

@@ -59,3 +59,3 @@ # 🧁 vanilla-extract

> 💡 These `.css.ts` files will be evaluated at build time. None of the code in these files will be included in your final bundle. Think of it as using TypeScript as your preprocessor instead of Sass, Less, etc.
> 💡 Once you've [configured your build tooling,](#setup) these `.css.ts` files will be evaluated at build time. None of the code in these files will be included in your final bundle. Think of it as using TypeScript as your preprocessor instead of Sass, Less, etc.

@@ -78,3 +78,3 @@ **Then consume them in your markup.**

Want to work at a higher level while maximising style re-use? Check out 🍨 [Sprinkles](https://github.com/seek-oss/vanilla-extract/tree/master/packages/sprinkles), our official zero-runtime atomic CSS framework, built on top of vanilla-extract.
Want to work at a higher level while maximising style re-use? Check out 🍨 [Sprinkles](https://vanilla-extract.style/documentation/sprinkles-api), our official zero-runtime atomic CSS framework, built on top of vanilla-extract.

@@ -88,9 +88,11 @@ ---

- [Snowpack](#snowpack)
- [Next.js](#nextjs)
- [Gatsby](#gatsby)
- [Test environments](#test-environments)
- [Configuration](#configuration)
- [identifiers](#identifiers)
- [Styling API](#styling-api)
- [style](#style)
- [styleVariants](#styleVariants)
- [styleVariants](#stylevariants)
- [globalStyle](#globalstyle)
- [composeStyles](#composestyles)
- [createTheme](#createtheme)

@@ -106,2 +108,4 @@ - [createGlobalTheme](#createglobaltheme)

- [globalKeyframes](#globalkeyframes)
- [Recipes API](#recipes-api)
- [recipe](#recipe)
- [Dynamic API](#dynamic-api)

@@ -126,15 +130,9 @@ - [assignInlineVars](#assigninlinevars)

```bash
npm install @vanilla-extract/css @vanilla-extract/babel-plugin @vanilla-extract/webpack-plugin
npm install @vanilla-extract/css @vanilla-extract/webpack-plugin
```
2. Add the [Babel](https://babeljs.io) plugin.
2. Add the [webpack](https://webpack.js.org) plugin.
```json
{
"plugins": ["@vanilla-extract/babel-plugin"]
}
```
> 💡 This plugin accepts an optional [configuration object](#configuration).
3. Add the [webpack](https://webpack.js.org) plugin.
```js

@@ -183,2 +181,14 @@ const { VanillaExtractPlugin } = require('@vanilla-extract/webpack-plugin');

3. If you'd like automatic debuggable identifiers, you can add the [Babel](https://babeljs.io) plugin.
```bash
$ npm install @vanilla-extract/babel-plugin
```
```json
{
"plugins": ["@vanilla-extract/babel-plugin"]
}
```
### esbuild

@@ -194,2 +204,4 @@

> 💡 This plugin accepts an optional [configuration object](#configuration).
```js

@@ -248,4 +260,2 @@ const { vanillaExtractPlugin } = require('@vanilla-extract/esbuild-plugin');

> Warning: Currently the Vite plugin doesn't rebuild files when dependent files change, e.g. updating `theme.css.ts` should rebuild `styles.css.ts` which imports `theme.css.ts`. This is a limitation in the Vite Plugin API that will hopefully be resolved soon. You can track the Vite issue here: https://github.com/vitejs/vite/issues/3216
1. Install the dependencies.

@@ -259,2 +269,4 @@

> 💡 This plugin accepts an optional [configuration object](#configuration).
```js

@@ -281,2 +293,4 @@ import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';

> 💡 This plugin accepts an optional [configuration object](#configuration).
```js

@@ -291,2 +305,57 @@ // snowpack.config.json

### Next.js
1. Install the dependencies.
```bash
npm install @vanilla-extract/css @vanilla-extract/babel-plugin @vanilla-extract/next-plugin
```
2. If you don't have a `next.config.js` file in the root of your project, create one. Add the [Next.js](https://nextjs.org) plugin to your `next.config.js` file.
> 💡 This plugin accepts an optional [configuration object](#configuration).
```js
const {
createVanillaExtractPlugin
} = require('@vanilla-extract/next-plugin');
const withVanillaExtract = createVanillaExtractPlugin();
/** @type {import('next').NextConfig} */
const nextConfig = {};
module.exports = withVanillaExtract(nextConfig);
```
If required, this plugin can be composed with other plugins.
```js
const {
createVanillaExtractPlugin
} = require('@vanilla-extract/next-plugin');
const withVanillaExtract = createVanillaExtractPlugin();
const withMDX = require('@next/mdx')({
extension: /\.mdx$/
});
/** @type {import('next').NextConfig} */
const nextConfig = {};
module.exports = withVanillaExtract(withMDX(nextConfig));
```
3. (Optional) If you want to automatically generate debug IDs during development, you can add the [Babel](https://babeljs.io) plugin. Note that this step will cause Next.js to switch from [SWC](https://github.com/swc-project/swc) to Babel, increasing build times. This may or may not be an issue depending on the size of your project.
> Note: While optional for Next.js, the Babel plugin is still required when trying to run `.css.ts` files in Node for unit testing since the files are no longer being processed by a bundler.
If you don't have a `.babelrc` file in the root of your project, create one. Add the Babel plugin to your `.babelrc` file, ensuring that you're also including `"next/babel"` in your `presets` array.
```json
{
"presets": ["next/babel"],
"plugins": ["@vanilla-extract/babel-plugin"]
}
```
### Gatsby

@@ -321,3 +390,13 @@

### Configuration
#### identifiers
Different formatting of identifiers (e.g. class names, keyframes, CSS Vars, etc) can be configured by selecting from the following options:
- `short` identifiers are a 7+ character hash. e.g. `hnw5tz3`
- `debug` identifiers contain human readable prefixes representing the owning filename and a potential rule level debug name. e.g. `myfile_mystyle_hnw5tz3`
Each integration will set a default value based on the configuration options passed to the bundler.
---

@@ -390,8 +469,48 @@

> 💡 To improve maintainability, each `style` block can only target a single element. To enforce this, all selectors must target the `&` character which is a reference to the current element. For example, `'&:hover:not(:active)'` is considered valid, while `'& > a'` and ``[`& ${childClass}`]`` are not.
> 💡 To improve maintainability, each style block can only target a single element. To enforce this, all selectors must target the “&” character which is a reference to the current element.
>
>If you want to target another scoped class then it should be defined within the `style` block of that class instead. For example, ``[`& ${childClass}`]`` is invalid since it targets `${childClass}`, so it should instead be defined in the `style` block for `childClass`.
> For example, `'&:hover:not(:active)'` and `` [`${parentClass} &`] `` are considered valid, while `'& a[href]'` and `` [`& ${childClass}`] `` are not.
>
>If you want to globally target child nodes within the current element (e.g. `'& > a'`), you should use [`globalStyle`](#globalstyle) instead.
> If you want to target another scoped class then it should be defined within the style block of that class instead.
>
> For example, `` [`& ${childClass}`] `` is invalid since it doesn’t target “&”, so it should instead be defined in the style block for `childClass`.
>
> If you want to globally target child nodes within the current element (e.g. `'& a[href]'`), you should use [`globalStyle`](#globalstyle) instead.
Multiple styles can be composed into a single rule by providing an array of styles.
```ts
import { style } from '@vanilla-extract/css';
const base = style({ padding: 12 });
export const primary = style([
base,
{ background: 'blue' }
]);
export const secondary = style([
base,
{ background: 'aqua' }
]);
```
When composed styles are used in selectors, they are assigned an additional class if required so they can be uniquely identified. When selectors are processed internally, the composed classes are removed, only leaving behind the unique identifier classes. This allows you to treat them as if they were a single class within vanilla-extract selectors.
```ts
import {
style,
globalStyle,
} from '@vanilla-extract/css';
const background = style({ background: 'mintcream' });
const padding = style({ padding: 12 });
export const container = style([background, padding]);
globalStyle(`${container} *`, {
boxSizing: 'border-box'
});
```
### styleVariants

@@ -412,2 +531,15 @@

Multiple styles can be composed into a single rule by providing an array of styles.
```ts
import { styleVariants } from '@vanilla-extract/css';
const base = style({ padding: 12 });
export const variant = styleVariants({
primary: [base, { background: 'blue' }],
secondary: [base, { background: 'aqua' }],
});
```
You can also transform the values by providing a map function as the second argument.

@@ -418,11 +550,13 @@

const spaceScale = {
small: 4,
medium: 8,
large: 16
};
const base = style({ padding: 12 });
export const padding = styleVariants(spaceScale, (space) => ({
padding: space
}));
const backgrounds = {
primary: 'blue',
secondary: 'aqua'
} as const;
export const variant = styleVariants(
backgrounds,
(background) => [base, { background }]
);
```

@@ -445,3 +579,3 @@

```ts
import { globalStyle } from '@vanilla-extract/css';
import { style, globalStyle } from '@vanilla-extract/css';

@@ -455,46 +589,2 @@ export const parentClass = style({});

### composeStyles
Combines multiple styles into a single class string, while also deduplicating and removing unnecessary spaces.
```ts
import { style, composeStyles } from '@vanilla-extract/css';
const button = style({
padding: 12,
borderRadius: 8
});
export const primaryButton = composeStyles(
button,
style({ background: 'coral' })
);
export const secondaryButton = composeStyles(
button,
style({ background: 'peachpuff' })
);
```
> 💡 Styles can also be provided in shallow and deeply nested arrays, similar to [classnames.](https://github.com/JedWatson/classnames)
When style compositions are used in selectors, they are assigned an additional class so they can be uniquely identified. When selectors are processed internally, the composed classes are removed, only leaving behind the unique identifier classes. This allows you to treat them as if they were a single class within vanilla-extract selectors.
```ts
import {
style,
globalStyle,
composeStyles
} from '@vanilla-extract/css';
const background = style({ background: 'mintcream' });
const padding = style({ padding: 12 });
export const container = composeStyles(background, padding);
globalStyle(`${container} *`, {
boxSizing: 'border-box'
});
```
### createTheme

@@ -504,2 +594,4 @@

**Ensure this function is called within a `.css.ts` context, otherwise variable names will be mismatched between files.**
```ts

@@ -552,2 +644,4 @@ // theme.css.ts

**Ensure this function is called within a `.css.ts` context, otherwise variable names will be mismatched between files.**
```ts

@@ -570,7 +664,36 @@ // theme.css.ts

If you want to implement an existing theme contract, you can pass it as the second argument.
```ts
// theme.css.ts
import {
createThemeContract,
createGlobalTheme
} from '@vanilla-extract/css';
export const vars = createThemeContract({
color: {
brand: null
},
font: {
body: null
}
});
createGlobalTheme(':root', vars, {
color: {
brand: 'blue'
},
font: {
body: 'arial'
}
});
```
### createThemeContract
Creates a contract for themes to implement.
Creates a contract of locally scoped variable names for themes to implement.
**Ensure this function is called within a `.css.ts` context, otherwise variable names will be mismatched between themes.**
**Ensure this function is called within a `.css.ts` context, otherwise variable names will be mismatched between files.**

@@ -615,2 +738,71 @@ > 💡 This is useful if you want to split your themes into different bundles. In this case, your themes would be defined in separate files, but we'll keep this example simple.

### createGlobalThemeContract
Creates a contract of globally scoped variable names for themes to implement.
> 💡 This is useful if you want to make your theme contract available to non-JavaScript environments.
```ts
// themes.css.ts
import {
createGlobalThemeContract,
createGlobalTheme
} from '@vanilla-extract/css';
export const vars = createGlobalThemeContract({
color: {
brand: 'color-brand'
},
font: {
body: 'font-body'
}
});
createGlobalTheme(':root', vars, {
color: {
brand: 'blue'
},
font: {
body: 'arial'
}
});
```
You can also provide a map function as the second argument which has access to the value and the object path.
For example, you can automatically prefix all variable names.
```ts
// themes.css.ts
import { createGlobalThemeContract } from '@vanilla-extract/css';
export const vars = createGlobalThemeContract({
color: {
brand: 'color-brand'
},
font: {
body: 'font-body'
}
}, (value) => `prefix-${value}`);
```
You can also use the map function to automatically generate names from the object path, joining keys with a hyphen.
```ts
// themes.css.ts
import { createGlobalThemeContract } from '@vanilla-extract/css';
export const vars = createGlobalThemeContract({
color: {
brand: null
},
font: {
body: null
}
}, (_value, path) => `prefix-${path.join('-')}`);
```
### assignVars

@@ -750,4 +942,4 @@

const rotate = keyframes({
'0%': { rotate: '0deg' },
'100%': { rotate: '360deg' },
'0%': { transform: 'rotate(0deg)' },
'100%': { transform: 'rotate(360deg)' }
});

@@ -768,4 +960,4 @@

globalKeyframes('rotate', {
'0%': { rotate: '0deg' },
'100%': { rotate: '360deg' },
'0%': { transform: 'rotate(0deg)' },
'100%': { transform: 'rotate(360deg)' }
});

@@ -778,5 +970,113 @@

## Recipes API
Create multi-variant styles with a type-safe runtime API, heavily inspired by [Stitches.](https://stitches.dev)
As with the rest of vanilla-extract, all styles are generated at build time.
```bash
$ npm install @vanilla-extract/recipes
```
### recipe
Creates a multi-variant style function that can be used at runtime or statically in `.css.ts` files.
Accepts an optional set of `base` styles, `variants`, `compoundVariants` and `defaultVariants`.
```ts
import { recipe } from '@vanilla-extract/recipes';
export const button = recipe({
base: {
borderRadius: 6
},
variants: {
color: {
neutral: { background: 'whitesmoke' },
brand: { background: 'blueviolet' },
accent: { background: 'slateblue' }
},
size: {
small: { padding: 12 },
medium: { padding: 16 },
large: { padding: 24 }
},
rounded: {
true: { borderRadius: 999 }
}
},
// Applied when multiple variants are set at once
compoundVariants: [
{
variants: {
color: 'neutral',
size: 'large'
},
style: {
background: 'ghostwhite'
}
}
],
defaultVariants: {
color: 'accent',
size: 'medium'
}
});
```
With this recipe configured, you can now use it in your templates.
```ts
import { button } from './button.css.ts';
document.write(`
<button class="${button({
color: 'accent',
size: 'large',
rounded: true
})}">
Hello world
</button>
`);
```
Your recipe configuration can also make use of existing variables, classes and styles.
For example, you can pass in the result of your [`sprinkles`](https://vanilla-extract.style/documentation/sprinkles-api) function directly.
```ts
import { recipe } from '@vanilla-extract/recipes';
import { reset } from './reset.css.ts';
import { sprinkles } from './sprinkles.css.ts';
export const button = recipe({
base: [reset, sprinkles({ borderRadius: 'round' })],
variants: {
color: {
neutral: sprinkles({ background: 'neutral' }),
brand: sprinkles({ background: 'brand' }),
accent: sprinkles({ background: 'accent' })
},
size: {
small: sprinkles({ padding: 'small' }),
medium: sprinkles({ padding: 'medium' }),
large: sprinkles({ padding: 'large' })
}
},
defaultVariants: {
color: 'accent',
size: 'medium'
}
});
```
## Dynamic API
We also provide a lightweight standalone package to support dynamic runtime theming.
Dynamically update theme variables at runtime.

@@ -783,0 +1083,0 @@ ```bash

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc