Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@primer/primitives
Advanced tools
Typography, spacing, and color primitives for Primer design system
This repo contains values for color, spacing, and typography primitives for use with Primer, GitHub's design system.
This repository is distributed on npm. After installing npm, you can install @primer/primitives
with this command.
npm install --save @primer/primitives
See Primitives documentation for more information on theming and using CSS variables.
Data is served from the dist/
folder:
dist/css
contains CSS files with values available as CSS variablesAll available imports:
/* size/typography */
@import '@primer/primitives/dist/css/base/size/size.css';
@import '@primer/primitives/dist/css/base/typography/typography.css';
@import '@primer/primitives/dist/css/functional/size/border.css';
@import '@primer/primitives/dist/css/functional/size/breakpoints.css';
@import '@primer/primitives/dist/css/functional/size/size.css';
@import '@primer/primitives/dist/css/functional/size/viewport.css';
@import '@primer/primitives/dist/css/functional/typography/typography.css';
/* color */
@import '@primer/primitives/dist/css/functional/themes/light.css';
@import '@primer/primitives/dist/css/functional/themes/light-tritanopia.css';
@import '@primer/primitives/dist/css/functional/themes/light-high-contrast.css';
@import '@primer/primitives/dist/css/functional/themes/light-colorblind.css';
@import '@primer/primitives/dist/css/functional/themes/dark.css';
@import '@primer/primitives/dist/css/functional/themes/dark-colorblind.css';
@import '@primer/primitives/dist/css/functional/themes/dark-dimmed.css';
@import '@primer/primitives/dist/css/functional/themes/dark-high-contrast.css';
@import '@primer/primitives/dist/css/functional/themes/dark-tritanopia.css';
Design token data is stored in the src/tokens directory. These tokens are compiled with style dictionary in scripts/buildTokens.ts.
To make working with tokens easier, we added some additional functionality on top of what style dictionary comes with:
We have two main color modes: light
and dark
. Additionally we have specific accessibility modes based on those, such as light high contrast
.
We added a way to create a mode by only including the changes from the main mode. We call this overrides
.
Overrides
are cerated in src/tokens/functional/color/[light|dark]/overrides/
and have to be added to themes.config.ts to work.
In the individual files, e.g. light.high-contrast.json5
you can now add tokens in the same structure as in any main file, e.g. primitives-light.json5
to replace them.
You can create color tokens that inherit a color but have a different alpha value by adding the alpha
property.
Note: The original alpha value will be replaced by your value. If you add alpha: 0.4
to a color, it doesn't matter if the color you reference has no alpha
or alpha: 0.7
, the new token will always have newly the defined value of alpha: 0.4
.
{
muted: {
$value: '{base.color.blue.3}',
alpha: 0.4, // the opacity value of the color === 40% opaque
$type: 'color',
},
}
In rare cases, you may need to create a color between two steps in the color scale, e.g. between gray.4
and gray.5
. A common example are interactive states, like hover
where a full step on the color scale would be to much. For those cases you can use the mix
property.
The mix
proeprty mixes the color it gets into the main color from the $value
attribute. The amount added is controlled by the weight
. A weight of 0.1
adds 10% of the color, and a weight of 0.75
adds 75%.
A mix
proprty must always have a color
and a weight
child. color
can be a hex
value or a reference to a valid color. The weight
property must receive a value between 0.0
and 1
.
{
control: {
$value: '{base.color.gray.4}', // main color
$type: 'color',
mix: {
color: '{base.color.gray.5}', // color to mix into the main color
weight: 0.2, // amount of the mix color that is added === 20% of gray.5 is mix into gray.4
},
},
}
According to the w3c design token specs, the $extensions
property is used for additional meta data.
For our Figma export we use the following meta data:
collection
the collection that the token is added to within Figmamode
the mode that the token is added to within the collection in Figmascopes
the scopes that are assigned to the token in Figma, the actual Figma compatible scopes
are retreive from an object in the figmaAttributes transformerCode example
bgColor: {
$value: '{borderColor.accent.muted}',
$type: 'color',
$extensions: {
'org.primer.figma': {
collection: 'pattern/mode',
mode: 'light',
scopes: ['bgColor'],
},
},
}
Token names have to be in camelCase or kebab-case and may only include letters, numbers and -
. This is enforced by the token validation (npm run lint:tokens
).
The only acception is the @
-hack. This is used when you want to have a default value and sub-values, e.g. bgColor.accent
and bgColor.accent.muted
.
In this case you can create the follwing structure. The @
will be removed from the name and act as the default value.
{
bgColor: {
accent: {
'@': {
// values for accent (default)
},
muted: {
// values for accent-muted
},
},
},
}
FAQs
Typography, spacing, and color primitives for Primer design system
The npm package @primer/primitives receives a total of 55,258 weekly downloads. As such, @primer/primitives popularity was classified as popular.
We found that @primer/primitives demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 14 open source maintainers 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.