Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(coral-tokens): adding coral tokens package (#11)
* fix: removing defaultCollection * feat(coral-tokens): adding style dictionary packages * feat(coral-tokens): adding shades tokens + lightness variables * feat(coral-tokens): adding color custom transform for shades * feat(coral-tokens): adding transform model * feat(coral-tokens): adding shades transform to custom transforms index * feat(coral-tokens): generation coral-tokens package * fix: update actions version * fix(coral-tokens): fix formatting issues * fix(coral-angular): ignoring generated files from linting * fix: removing wrong dependency * fix: updating yarn.lock
- Loading branch information
1 parent
107573e
commit f4343d1
Showing
17 changed files
with
443 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
packages/coral-angular/src/lib/generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"projectType": "application", | ||
"sourceRoot": "packages/coral-tokens/src", | ||
"targets": { | ||
"build": { | ||
"executor": "@nxkit/style-dictionary:build", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/packages/coral-tokens", | ||
"styleDictionaryConfig": "packages/coral-tokens/style-dictionary.config.ts", | ||
"tsConfig": "packages/coral-tokens/tsconfig.json", | ||
"customTransforms": "packages/coral-tokens/src/extensions/transforms/index.ts" | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["packages/coral-tokens/**/*.{js,ts}"] | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { CustomTransformsBuilder } from '@nxkit/style-dictionary'; | ||
import { ShadesTransform } from './shades-transform/transform'; | ||
|
||
const customTransformsBuilder: CustomTransformsBuilder = () => { | ||
return { | ||
[ShadesTransform.name]: ShadesTransform.transform, | ||
}; | ||
}; | ||
|
||
export default customTransformsBuilder; |
26 changes: 26 additions & 0 deletions
26
packages/coral-tokens/src/extensions/transforms/shades-transform/color-transform.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// #NOTE: https://github.com/amzn/style-dictionary/tree/main/examples/advanced/transitive-transforms | ||
|
||
import * as chroma from 'chroma-js'; | ||
|
||
const setHslColor = (color: chroma.Color, lightness: number) => { | ||
const [h, s] = color.hsl(); | ||
return chroma(h, s, lightness / 100, 'hsl'); | ||
}; | ||
|
||
export const colorTransform = (token) => { | ||
const { value, modify = [] } = token; | ||
let color = chroma(value); | ||
|
||
// iterate over the modify array (see tokens/color.json) | ||
// and apply each modification in order | ||
modify.forEach(({ type, amount }) => { | ||
// modifier type must match a method name in chromajs | ||
// https://gka.github.io/chroma.js/ | ||
// chroma methods can be chained, so each time we override the color variable | ||
// we can still call other chroma methods, similar to | ||
// chroma(value).brighten(1).darken(1).hex(); | ||
color = setHslColor(color, amount); | ||
}); | ||
|
||
return color.hex(); | ||
}; |
14 changes: 14 additions & 0 deletions
14
packages/coral-tokens/src/extensions/transforms/shades-transform/transform.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { CustomTransform } from '../transform.model'; | ||
import { colorTransform } from './color-transform'; | ||
|
||
export const ShadesTransform: CustomTransform = { | ||
name: 'shades-transform', | ||
transform: { | ||
type: `value`, | ||
// only transforms that have transitive: true will be applied to tokens | ||
// that alias/reference other tokens | ||
transitive: true, | ||
matcher: (token) => token?.attributes?.category === 'color' && token.modify, | ||
transformer: colorTransform, | ||
}, | ||
}; |
6 changes: 6 additions & 0 deletions
6
packages/coral-tokens/src/extensions/transforms/transform.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Transform } from 'style-dictionary'; | ||
|
||
export interface CustomTransform { | ||
name: string; | ||
transform: Transform; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
{ | ||
"color": { | ||
"primary": { | ||
"0": { | ||
"value": "#751aff" | ||
}, | ||
"10": { | ||
"value": "{color.primary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.1}" | ||
} | ||
] | ||
}, | ||
"20": { | ||
"value": "{color.primary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.2}" | ||
} | ||
] | ||
}, | ||
"30": { | ||
"value": "{color.primary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.3}" | ||
} | ||
] | ||
}, | ||
"40": { | ||
"value": "{color.primary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.4}" | ||
} | ||
] | ||
}, | ||
"50": { | ||
"value": "{color.primary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.5}" | ||
} | ||
] | ||
}, | ||
"60": { | ||
"value": "{color.primary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.6}" | ||
} | ||
] | ||
} | ||
}, | ||
"secondary": { | ||
"0": { | ||
"value": "#ff751a" | ||
}, | ||
"10": { | ||
"value": "{color.secondary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.1}" | ||
} | ||
] | ||
}, | ||
"20": { | ||
"value": "{color.secondary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.2}" | ||
} | ||
] | ||
}, | ||
"30": { | ||
"value": "{color.secondary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.3}" | ||
} | ||
] | ||
}, | ||
"40": { | ||
"value": "{color.secondary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.4}" | ||
} | ||
] | ||
}, | ||
"50": { | ||
"value": "{color.secondary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.5}" | ||
} | ||
] | ||
}, | ||
"60": { | ||
"value": "{color.secondary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.6}" | ||
} | ||
] | ||
} | ||
}, | ||
"tertiary": { | ||
"0": { | ||
"value": "#1aff94" | ||
}, | ||
"10": { | ||
"value": "{color.tertiary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.1}" | ||
} | ||
] | ||
}, | ||
"20": { | ||
"value": "{color.tertiary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.2}" | ||
} | ||
] | ||
}, | ||
"30": { | ||
"value": "{color.tertiary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.3}" | ||
} | ||
] | ||
}, | ||
"40": { | ||
"value": "{color.tertiary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.4}" | ||
} | ||
] | ||
}, | ||
"50": { | ||
"value": "{color.tertiary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.5}" | ||
} | ||
] | ||
}, | ||
"60": { | ||
"value": "{color.tertiary.0}", | ||
"modify": [ | ||
{ | ||
"type": "set", | ||
"amount": "{lightness.6}" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"lightness": [55, 50, 45, 40, 35, 30, 25, 20] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Config } from 'style-dictionary'; | ||
|
||
const config: Config = { | ||
source: ['src/tokens/**/*.json'], | ||
platforms: { | ||
scss: { | ||
transformGroup: 'scss', | ||
buildPath: 'scss/', | ||
transforms: [ | ||
`attribute/cti`, | ||
`name/cti/kebab`, | ||
`shades-transform`, | ||
`color/hex`, | ||
], | ||
files: [ | ||
{ | ||
destination: '_variables.scss', | ||
format: 'scss/variables', | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"sourceMap": false, | ||
"outDir": "../../dist/out-tsc", | ||
"allowJs": true, | ||
"types": ["node"] | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.js", "style-dictionary.config.ts"] | ||
} |
Oops, something went wrong.