Skip to content

Commit

Permalink
feat: add tailwind config helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
lilingxi01 committed Dec 19, 2023
1 parent 358ca13 commit 7b568de
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
Binary file modified bun.lockb
Binary file not shown.
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "radix-colors-tailwind",
"version": "0.0.1",
"version": "0.1.0",
"main": "dist/index.ts",
"type": "module",
"files": [
"dist"
],
"scripts": {
"prod": "bun generator/index.ts",
"prod": "rm -R dist && bun build src/index.ts --target bun --outfile ./dist/index.js && bun generator/index.ts",
"lint": "eslint generator/*"
},
"devDependencies": {
Expand All @@ -18,8 +18,5 @@
"eslint": "^8.32.0",
"bun-types": "latest",
"typescript": "^5.0.0"
},
"peerDependencies": {
"tailwindcss": ">=3.0.0 || insiders"
}
}
48 changes: 48 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
type RadixColorsTransformedFamily = {
1: string;
2: string;
3: string;
4: string;
5: string;
6: string;
7: string;
8: string;
9: string;
10: string;
11: string;
12: string;
};

export function transformRadixColors(familyName: string): RadixColorsTransformedFamily {
return Array.from({ length: 12 }, (_, i) => i + 1).reduce((acc, number) => {
return {
...acc,
[number]: `rgb(var(--radix-rgb-${familyName}-${number}) / <alpha-value>)`,
};
}, {} as RadixColorsTransformedFamily);
}

type RadixColorsTransformedWithAlphaFamily = RadixColorsTransformedFamily & {
a1: string;
a2: string;
a3: string;
a4: string;
a5: string;
a6: string;
a7: string;
a8: string;
a9: string;
a10: string;
a11: string;
a12: string;
};

export function transformRadixColorsWithAlpha(familyName: string): RadixColorsTransformedWithAlphaFamily {
return Array.from({ length: 12 }, (_, i) => i + 1).reduce((acc, number) => {
return {
...acc,
[number]: `rgb(var(--radix-rgb-${familyName}-${number}) / <alpha-value>)`,
[`a${number}`]: `rgb(var(--radix-rgb-${familyName}-a${number}))`,
};
}, {} as RadixColorsTransformedWithAlphaFamily);
}

0 comments on commit 7b568de

Please sign in to comment.