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

Artur/eng 7937 create frosted uicolors package #226

Merged
merged 5 commits into from
Jan 13, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/frosted-ui-colors/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/node_modules/
/types
.DS_Store
/*.css
index.js
index.mjs
8 changes: 8 additions & 0 deletions packages/frosted-ui-colors/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/src/
/scripts/
.gitignore
tsconfig.json
rollup.config.js
yarn.lock
pnpm.lock
package-lock.json
22 changes: 22 additions & 0 deletions packages/frosted-ui-colors/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2021 Radix
Copyright (c) 2025 Whop

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 17 additions & 0 deletions packages/frosted-ui-colors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Frosted UI Colors

**A gorgeous, accessible color system used by Whop.**

---

## Documentation

For full documentation, visit [storybook.whop.dev](https://storybook.whop.dev/?path=/docs/guides-3-color--docs).

## Installation

`pnpm add @frosted-ui/colors`

## Acknowledgments

Frosted UI is heavily based on [Radix Colors](https://www.radix-ui.com/colors).
34 changes: 34 additions & 0 deletions packages/frosted-ui-colors/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@frosted-ui/colors",
"private": false,
"version": "0.0.0",
"license": "MIT",
"description": "Frosted UI Colors",
"main": "index.js",
"module": "index.mjs",
"types": "types/index.d.ts",
"scripts": {
"build": "pnpm clean && pnpm install && pnpm rollup -c && pnpm build-css-modules",
"build-css-modules": "node ./scripts/build-css-modules.js",
"prepublishOnly": "pnpm build",
"postpublish": "pnpm clean",
"clean": "rm -f *.css index.js index.mjs",
"release": "turbo-module publish"
},
"keywords": [
"frosted-ui",
"colors"
],
"sideEffects": false,
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@rollup/plugin-typescript": "^8.2.1",
"@types/node": "^15.0.3",
"@whop-sdk/turbo-module": "^0.0.5",
"rollup": "^2.48.0",
"tslib": "^2.2.0",
"typescript": "^4.2.4"
}
}
21 changes: 21 additions & 0 deletions packages/frosted-ui-colors/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// rollup.config.js
import typescript from '@rollup/plugin-typescript'

export default {
input: 'src/index.ts',
output: [
{
file: 'index.js',
format: 'cjs',
},
{
file: 'index.mjs',
format: 'es',
},
],
plugins: [
typescript({
tsconfig: './tsconfig.json',
}),
],
}
64 changes: 64 additions & 0 deletions packages/frosted-ui-colors/scripts/build-css-modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const path = require('path');
const allColorScales = require('../index');

const outputDir = require('../tsconfig.json').compilerOptions.outDir;

const supportsP3AtRule = '@supports (color: color(display-p3 1 1 1))';
const matchesP3MediaRule = '@media (color-gamut: p3)';

Object.keys(allColorScales)
.filter((key) => !key.includes('P3'))
.forEach((key) => {
let selector = ':root, .light, .light-theme';

if (key === 'blackA' || key === 'whiteA') {
selector = ':root';
}

if (key.includes('Dark')) {
selector = '.dark, .dark-theme';
}

const srgbValues = Object.entries(allColorScales).find(
([name]) => name === key,
)[1];

const srgbCssProperties = Object.entries(srgbValues)
.map(([name, value]) => [toCssCasing(name), value])
.map(([name, value]) => ` --${name}: ${value};`)
.join('\n');

const srgbCssRule = `${selector} {\n${srgbCssProperties}\n}`;

const p3Values = Object.entries(allColorScales).find(
([name]) => name === key + 'P3' || name === key.replace(/.$/, 'P3A'),
)[1];

const p3CssProperties = Object.entries(p3Values)
.map(([name, value]) => [toCssCasing(name), value])
.map(([name, value]) => ` --${name}: ${value};`)
.join('\n');

let p3CssRule = ` ${selector} {\n${p3CssProperties}\n }`;
p3CssRule = ` ${matchesP3MediaRule} {\n${p3CssRule}\n }`;
p3CssRule = `${supportsP3AtRule} {\n${p3CssRule}\n}`;

fs.writeFileSync(
path.join(outputDir, toFileName(key) + '.css'),
`${srgbCssRule}\n\n${p3CssRule}`,
);
});

function toCssCasing(str) {
return str
.replace(/([a-z])(\d)/, '$1-$2')
.replace(/([A-Z])/g, '-$1')
.toLowerCase();
}

function toFileName(str) {
return toCssCasing(str).replace(/-a$/, '-alpha');
}
29 changes: 29 additions & 0 deletions packages/frosted-ui-colors/src/blackA.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export const blackA = {
blackA1: "rgba(0, 0, 0, 0.05)",
blackA2: "rgba(0, 0, 0, 0.1)",
blackA3: "rgba(0, 0, 0, 0.15)",
blackA4: "rgba(0, 0, 0, 0.2)",
blackA5: "rgba(0, 0, 0, 0.3)",
blackA6: "rgba(0, 0, 0, 0.4)",
blackA7: "rgba(0, 0, 0, 0.5)",
blackA8: "rgba(0, 0, 0, 0.6)",
blackA9: "rgba(0, 0, 0, 0.7)",
blackA10: "rgba(0, 0, 0, 0.8)",
blackA11: "rgba(0, 0, 0, 0.9)",
blackA12: "rgba(0, 0, 0, 0.95)",
};

export const blackP3A = {
blackA1: "color(display-p3 0 0 0 / 0.05)",
blackA2: "color(display-p3 0 0 0 / 0.1)",
blackA3: "color(display-p3 0 0 0 / 0.15)",
blackA4: "color(display-p3 0 0 0 / 0.2)",
blackA5: "color(display-p3 0 0 0 / 0.3)",
blackA6: "color(display-p3 0 0 0 / 0.4)",
blackA7: "color(display-p3 0 0 0 / 0.5)",
blackA8: "color(display-p3 0 0 0 / 0.6)",
blackA9: "color(display-p3 0 0 0 / 0.7)",
blackA10: "color(display-p3 0 0 0 / 0.8)",
blackA11: "color(display-p3 0 0 0 / 0.9)",
blackA12: "color(display-p3 0 0 0 / 0.95)",
};
Loading
Loading