Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
get scss from design tokens json file using style dictionary

I want to get the scss rules for design tokens from a json file provided by the design team. I used style dictionary and managed to get the base design tokens, but there are few tokens that use entire objects as value.

This is an example of design token (received from the design team) that I want to transform to scss:

{
"fontFamilies": {
    "inter": {
      "value": "Inter",
      "type": "fontFamilies"
    }
  },
 "fontWeights": {
    "inter-0": {
      "value": "Regular",
      "type": "fontWeights"
    },
  },
"fontSize": {
    "10": {
      "value": "72",
      "type": "fontSizes"
    }
  },
"Display-2xl": {
    "Regular": {
      "value": {
        "fontFamily": "{fontFamilies.inter.value}",
        "fontWeight": "{fontWeights.inter-0.value}",
        "fontSize": "$fontSize.10",
      },
      "type": "typography"
    },
}

Note: the simple tokens are successfully transformed. Style dictionary output looks like this:

$font-families-inter: Inter;
$font-weights-inter-0: Regular;
$font-size-10: 72;
$display-2xl-regular: [object Object];

Is it possible to use style dictionary and output these rules for tokens like display-2xl-regular?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The value has the be the last thing in the leaf node.

This:

{
"fontFamilies": {
    "inter": {
      "value": "Inter",
      "type": "fontFamilies"
    }
  },
 "fontWeights": {
    "inter-0": {
      "value": "Regular",
      "type": "fontWeights"
    }
  },
"fontSize": {
    "10": {
      "value": "72",
      "type": "fontSizes"
    }
  },
  "Display-2xl": {
    "Regular": {
      "type": "typography",
      "fontFamily": {
        "value": "{fontFamilies.inter.value}"
      },
      "fontWeight": {
        "value": "{fontWeights.inter-0.value}"
      },
      "fontSize": {
        "value": "{fontSize.10}"
      }
    }
  }
}
    

Will get you:

$font-families-inter: Inter;
$font-weights-inter-0: Regular;
$font-size-10: 72;
$display-2xl-regular-font-family: Inter;
$display-2xl-regular-font-weight: Regular;
$display-2xl-regular-font-size: 72;

Also, a heads up Style Dictionary will add a prefix typically.

Try playing around in div.riot's Style Dictionary playground. I created an example here.

You can also get away with this is you want a value at the at the parent.

  "Display-2xl": {
    " ": { // Has to be a space. This comment also will break json
     value: "PARENT VALUE"
    },
    "Regular": {
      "type": "typography",
      "fontFamily": {
        "value": "{fontFamilies.inter.value}"
      },
      "fontWeight": {
        "value": "{fontWeights.inter-0.value}"
      },
      "fontSize": {
        "value": "{fontSize.10}"
      }
    }
  }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda