Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
postcss-cva
Advanced tools
A postcss plugin that generates cva functions based on comments
The CVA function is an excellent atomic tool function, refer to https://cva.style/docs
For example. A cva
function consists of 4
parts: base
,variants
,compoundVariants
,defaultVariants
import { cva } from 'class-variance-authority'
// ⬇️ base
const button = cva(['font-semibold', 'border', 'rounded'], {
// ⬇️ variants
variants: {
intent: {
primary: ['bg-blue-500', 'text-white', 'border-transparent', 'hover:bg-blue-600'],
secondary: ['bg-white', 'text-gray-800', 'border-gray-400', 'hover:bg-gray-100']
},
size: {
small: ['text-sm', 'py-1', 'px-2'],
medium: ['text-base', 'py-2', 'px-4']
}
},
// ⬇️ compoundVariants
compoundVariants: [
{
intent: 'primary',
size: 'medium',
class: 'uppercase'
}
],
// ⬇️ defaultVariants
defaultVariants: {
intent: 'primary',
size: 'medium'
}
})
button()
// => "font-semibold border rounded bg-blue-500 text-white border-transparent hover:bg-blue-600 text-base py-2 px-4 uppercase"
button({ intent: 'secondary', size: 'small' })
// => "font-semibold border rounded bg-white text-gray-800 border-gray-400 hover:bg-gray-100 text-sm py-1 px-2"
This plugin has been integrated internally in
icestack
, no need to install and register.
npm i -D postcss-cva
yarn add -D postcss-cva
pnpm add -D postcss-cva
module.exports = {
plugins: {
// options
'postcss-cva': {},
// 'postcss-cva': {
//
// },
}
}
For example, in this plugin
type="primary"
is called query
, ["shadow-sm"]
is called params
The same
query
will be merged withparams
together
/* @meta path="button" */
.btn {
/* @b */
}
.btn-primary {
/* @v type="primary" */
}
.btn-xs {
/* @v size="xs" */
}
.uppercase {
/* @cv type="primary" size="xs" */
}
/* @dv type="primary" */
/* @gb ["rounded"] */
/* @gv type="primary" ["shadow-sm"] */
/* @gcv type="primary" size="xs" ["p-1"] */
will generate:
import { cva, VariantProps } from 'class-variance-authority'
// @b and @gb
const index = cva(['btn', 'rounded'], {
variants: {
// @v type="primary" and @dv type="primary"
type: {
primary: ['btn-primary', 'shadow-sm']
},
// @v size="xs"
size: {
xs: ['btn-xs']
}
},
// @cv type="primary" size="xs" and @gcv type="primary" size="xs" ["p-1"]
compoundVariants: [
{
class: ['uppercase', 'p-1'],
type: ['primary'],
size: ['xs']
}
],
// @dv type="primary"
defaultVariants: {
type: 'primary'
}
})
export type Props = VariantProps<typeof index>
export default index
keyword | param | type | description |
---|---|---|---|
@b | base | node | add current node selector to base |
@v | variants | node | add current node selector to variants |
@cv | compoundVariants | node | add current node selector to compoundVariants |
@dv | defaultVariants | global | define defaultVariants |
@gb | base | global | define base |
@gv | variants | global | define variants |
@gcv | compoundVariants | global | define defaultVariants |
@meta | meta | global | define metadata |
@meta
query:
/* @meta path="{your-cva-filepath}" format="ts/js" */
You can use the
js
variables to dynamically generate functions
Get the last class node in the current selector and add it to the corresponding results
It will not be calculated based on the defined position. It can be defined anywhere. The one defined later will overwrite the one defined before.
Type: string
Default: cva
The location of the output directory
Type: string
Default: class-variance-authority
From which package to import the cva function
Type: boolean
Default: false
Type: string
Default: process.cwd()
Type: js
| ts
Default: ts
Type: string
Default: ''
Type: boolean
Default: true
remove all @xx
comment
Type: String | RegExp | Array[...String|RegExp]
A valid picomatch pattern, or array of patterns. If options.include is omitted or has zero length, filter will return true by default. Otherwise, an ID must match one or more of the picomatch patterns, and must not match any of the options.exclude patterns.
Note that picomatch patterns are very similar to minimatch patterns, and in most use cases, they are interchangeable. If you have more specific pattern matching needs, you can view this comparison table to learn more about where the libraries differ.
MIT License © 2023-PRESENT sonofmagic
FAQs
generate cva functions by css comment
The npm package postcss-cva receives a total of 6 weekly downloads. As such, postcss-cva popularity was classified as not popular.
We found that postcss-cva demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.