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

feat(coral-tokens): adding coral tokens package #11

Merged
merged 13 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
jobs:
ci:
name: Nx Cloud - Main Job
uses: nrwl/ci/.github/workflows/nx-cloud-main.yml@v0.7
uses: nrwl/ci/.github/workflows/nx-cloud-main.yml@v0.8.1
with:
number-of-agents: 3
init-commands: |
Expand All @@ -27,7 +27,7 @@ jobs:

agents:
name: Nx Cloud - Agents
uses: nrwl/ci/.github/workflows/nx-cloud-agents.yml@v0.7
uses: nrwl/ci/.github/workflows/nx-cloud-agents.yml@v0.8.1
with:
number-of-agents: 3

Expand Down
3 changes: 0 additions & 3 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
}
}
},
"cli": {
"defaultCollection": "@nxext/stencil"
},
"targetDefaults": {
"build": {
"dependsOn": ["^build"]
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@nrwl/web": "14.7.13",
"@nrwl/workspace": "14.7.13",
"@nxext/stencil": "^14.0.6",
"@nxkit/style-dictionary": "^0.0.4",
"@stencil/angular-output-target": "^0.4.0",
"@stencil/core": "2.17.1",
"@stencil/react-output-target": "^0.3.1",
Expand All @@ -49,6 +50,7 @@
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"babel-jest": "27.4.1",
"chroma-js": "^2.4.2",
"cypress": "^10.7.0",
"eslint": "~8.15.0",
"eslint-config-prettier": "8.1.0",
Expand All @@ -70,6 +72,7 @@
"prettier": "^2.6.2",
"puppeteer": "^15.5.0",
"react-test-renderer": "18.2.0",
"style-dictionary": "^3.7.1",
"ts-jest": "27.1.5",
"ts-node": "10.9.1",
"tsconfig-paths-webpack-plugin": "4.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/coral-angular/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages/coral-angular/src/lib/generated
3 changes: 2 additions & 1 deletion packages/coral-angular/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"lintFilePatterns": [
"packages/coral-angular/**/*.ts",
"packages/coral-angular/**/*.html"
]
],
"ignorePath": "packages/coral-angular/.eslintignore"
}
}
},
Expand Down
18 changes: 18 additions & 0 deletions packages/coral-tokens/.eslintrc.json
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": {}
}
]
}
25 changes: 25 additions & 0 deletions packages/coral-tokens/project.json
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": []
}
10 changes: 10 additions & 0 deletions packages/coral-tokens/src/extensions/transforms/index.ts
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;
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();
};
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,
},
};
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;
}
181 changes: 181 additions & 0 deletions packages/coral-tokens/src/tokens/color/shades.json
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}"
}
]
}
}
}
}
3 changes: 3 additions & 0 deletions packages/coral-tokens/src/tokens/lightness.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"lightness": [55, 50, 45, 40, 35, 30, 25, 20]
}
25 changes: 25 additions & 0 deletions packages/coral-tokens/style-dictionary.config.ts
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;
10 changes: 10 additions & 0 deletions packages/coral-tokens/tsconfig.json
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"]
}