Comments (3)
https://amzn.github.io/style-dictionary/#/formats?id=cssvariables you'll probably want to use options.outputReferences
set to true
from style-dictionary.
@jorenbroekema I tried following @dbanksdesign guidance for issue #261 to convert this
{
"data-background": {
"voilet-50": {
"type": "group";
"background-color": {
"value": "{mode-colors.default.background-color}",
"type": "color",
"$extensions": {
"studio.tokens": {
"modify": {
"type": "mix",
"value": "{mix-in}",
"space": "lch",
"color": "#ffffff"
}
}
}
},
"alt-background-color": {
"value": "{mode-colors.default.alt-background-color}",
"type": "color"
},
"background-on-color": {
"value": "{text-dark}",
"type": "color",
}
}
}
}
to the following css:
[data-background=“violet-50”] {
--background: var(—mode-colors.violet-50.background-color);
--background-alt: var(—mode-colors.violet-50.alt-background-color);
--background-on-color: var(—text-dark);
}
I know there is more formatting to do to get my desired results, but I am getting the folllowing error:
"Build error: Cannot read properties of undefined (reading 'reduce')."
See console logs for more info."
when using the following code in the Style-Dictionary Configurator:
import StyleDictionary from 'style-dictionary';
import { formattedVariables } from 'style-dictionary/utils';
import { fileHeader } from 'style-dictionary/utils';
import { registerTransforms } from '@tokens-studio/sd-transforms';
// sd-transforms, 2nd parameter for options can be added
// See docs: https://github.com/tokens-studio/sd-transforms
registerTransforms(StyleDictionary);
const groups = ["font-style", "color-theme", "data-background"];
StyleDictionary.registerTransform({
name: "attribute/group",
type: 'attribute',
matcher: function(prop) {
return groups.includes(prop.path.slice(0,2).join('-'));
},
transformer: function(prop) {
return {
// Brittle logic, the group is the 3rd level of the object path
group: true,
groupName: prop.path.slice(0,3).join('-')
}
}
});
StyleDictionary.registerFilter({
name: 'core-filter',
matcher: (token) => token.filePath.endsWith('core.json')
});
StyleDictionary.registerFilter({
name: 'base-filter',
matcher: (token) => token.filePath.endsWith('base.json')
});
StyleDictionary.registerFilter({
name: 'background-filter',
matcher: (token) => token.filePath.endsWith('base.json')
});
StyleDictionary.registerTransform({
name: 'css/boolean-to-display',
type: 'value',
transformer: (token, _, options) => {
const tokenType = options.usesDtcg ? token.$type : token.type;
const tokenValue = options.usesDtcg ? token.$value : token.value;
if (tokenType === 'boolean') {
return tokenValue === 'true' ? 'block' : 'hidden';
}
return tokenValue;
}
});
// Custom CSS format that is basically a copy of the built-in,
// except for the fact that we pass formatting options -> commentPosition
StyleDictionary.registerFormat({
name: 'custom/css/variables',
formatter: async function ({ dictionary, options = {}, file }) {
const selector = options.selector ? options.selector : `:root`;
const { outputReferences, outputReferenceFallbacks, usesDtcg } = options;
const header = await fileHeader({ file });
return (
header +
`${selector} {\n` +
formattedVariables({
format: 'css',
dictionary,
outputReferences,
outputReferenceFallbacks,
usesDtcg,
formatting: {
commentPosition: 'above'
}
}) +
`\n}\n`
);
},
});
StyleDictionary.registerFormat({
name: 'css/group',
formatter: function(dictionary, config) {
const groupMap = dictionary.allProperties.reduce(function(prev,curr) {
if (!prev[curr.attributes.groupName]) {
prev[curr.attributes.groupName] = [];
}
prev[curr.attributes.groupName].push(curr);
return prev;
},{});
return Object.keys(groupMap).map(function(key) {
let props = groupMap[key];
return `.${key} {
${props.map(function(prop) {
return ` ${prop.name}: ${prop.value};`
}).join('\n')}
}`
}).join('\n\n');
}
});
Any ideas how to get the results I am looking for or how to solve the error?
from style-dictionary.
The dictionary.allProperties
and dictionary.properties
were deprecated in v3, and removed in v4 in favor of dictionary.allTokens
and dictionary.tokens
https://style-dictionary-v4.netlify.app/version-4/migration/#removed-deprecated-features
from style-dictionary.
Related Issues (20)
- Allow references in metadata for transitive transforms
- Remove reliances (transforms, formats) on CTI token hierarchy (e.g. color/hsl-4)
- Token partially transformed HOT 1
- zsh: command not found: style-dictionary HOT 2
- Style Dictionary crashes with generic error "Name must be a string" when there is a design token without a name HOT 3
- Numeric asset values are quoted HOT 3
- Error with /var/ when using style-dictionary in a Lambda function HOT 1
- RangeError: Maximum call stack size exceeded HOT 2
- DTCG format does not support outputReferences? HOT 2
- Compose UI Multiplatform support HOT 2
- Bug: formatter css/variables outputReferenceFallback does not create Fallback value HOT 1
- Regression in transitive transform from version 3.9.0 HOT 5
- Format errors in some Android transforms? (Style Dictionary + `sd-transforms`) HOT 10
- Token Structure Documentation HOT 1
- How to access FormatterArguments types, etc. HOT 5
- Some `buildPath` checks only consider `/` as a separator
- Modifiers are not removed while overriding variables HOT 3
- Issue with code formatting / line endings HOT 2
- Can I use getReference or somehow get access to the reference token inside of a transformer? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from style-dictionary.