Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output reference replaces partial value #873

Closed
lukasoppermann opened this issue Sep 16, 2022 · 4 comments
Closed

Output reference replaces partial value #873

lukasoppermann opened this issue Sep 16, 2022 · 4 comments

Comments

@lukasoppermann
Copy link
Contributor

lukasoppermann commented Sep 16, 2022

Hey,

I have a custom alpha transformer that applies an alpha value to the hex value, e.g #000000#00000066 if the alpha property is set to .4.

The problem is, that I also want outputReferences. The output I get is:

--color-black: var(--base-black)66;

I assume the issue is that SD replaces any matching part in a string. This is probably so that partial replaces work, but this creates an issue with value transformations.

Is there a way to solve this without a custom format?
Can I disable references for a token in a transformer?
Or could this be fixed to not replace partial hex values?

CC: @dbanksdesign @chazzmoney

@lukasoppermann
Copy link
Contributor Author

If it is hard to improve the matching, how about allowing transformers to add a noReference flag to a token, so that the reference function can ignore this token.

@pascalduez
Copy link
Contributor

Hello,
same issue here.
I guess it's the combination of outputReferences and transitive values.

{
  spacing: {
    '1x': {
      type: 'dimension',
      value: '{size.scale}',
      modify: {
        type: 'scale',
        amount: 1,
      },
    },
    '2x': {
      type: 'dimension',
      value: '{size.scale}',
      modify: {
        type: 'scale',
        amount: 2,
      },
    },
 [...]
StyleDictionary.registerTransform({
  name: 'dimension/css',
  type: 'value',
  transitive: true,
  matcher: token =>
    token.type === 'dimension' && token.modify?.type === 'scale',
  transformer: token => {
    [...]
    return token.value * token.modify.amount;
  },
});
  --spacing-56x: 22var(--size-scale);
  --spacing-20x: 80px;
  --spacing-16x: 6var(--size-scale);
  --spacing-7x: 28px;
  --spacing-6x: 2var(--size-scale);
  --spacing-2x: 8px;
  --spacing-1x: var(--size-scale);

Since size.scale is 4px it replace every 4px occurrences.

Maybe I'm over engineering it after all 😅

@pascalduez
Copy link
Contributor

Same issue as #819 I guess

@jorenbroekema
Copy link
Collaborator

#974 duplicate of this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants