Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.DS_Store
node_modules/
dist/
.nuxt/
npm-debug.log*
.eslintcache
Expand Down
32 changes: 31 additions & 1 deletion @kiva/kv-tokens/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,40 @@ The package contains

## Using the Design Definitions

### With JavaScript

```js
const designTokens = require("@kiva/kv-tokens/primitives.json");

const primaryTextColor = designTokens.colors.theme.DEFAULT.text.primary;
const primaryTextColor = designTokens.colors.theme.DEFAULT.text.primary.value;
```

### With SCSS

```scss
@import "./node_modules/@kiva/kv-tokens/dist/scss/_variables";

body {
background-color: $colors-theme-default-background-primary;
color: $colors-theme-default-text-primary;
font-size: #{$font-sizes-base-lg}px;
}
```

### With CSS Custom Properties

```html
<link
rel="stylesheet"
href="./node_modules/@kiva/kv-tokens/dist/css/variables.css"
/>
<style>
body {
background-color: var(--colors-theme-default-background-primary);
color: var(--colors-theme-default-text-primary);
font-size: calc(var(--font-sizes-base-lg) * 1px);
}
</style>
```

## Using the Tailwind Preset
Expand Down
36 changes: 35 additions & 1 deletion @kiva/kv-tokens/configs/kivaColors.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const buildCSSVarsFromTokens = (theme) => {

const properties = Object.keys(theme[category]);
properties.forEach((property) => {
customProperties[`--${twPrefix}-${property}`] = hexToRGB(theme[category][property]);
customProperties[`--${twPrefix}-${property}`] = hexToRGB(theme[category][property].value);
});
});
return customProperties;
Expand Down Expand Up @@ -78,8 +78,42 @@ const buildColorChoices = (themeProperty) => {
return property;
};

/**
* Reshapes an object from
* {
* brand: {
* 100: {
* value: "somehex"
* },
* 200: {
* value: "somehex"
* }
* ...
* }
* }
*
* to
*
* {
* brand: {
* 100: "somehex",
* 200: "somehex"
* ...
* }
* }
*/

const buildTailwindColorObjectFromTokens = (tokenGroup) => {
const ret = {};
Object.keys(tokenGroup).forEach((group) => {
ret[group] = tokenGroup[group].value;
});
return ret;
};

module.exports = {
buildColorChoices,
buildTailwindColorObjectFromTokens,
defaultTheme,
darkTheme,
darkGreenTheme,
Expand Down
Loading