Skip to content

feat(clerk-js): Update color logic utils to support CSS variable usage #6187

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

Open
wants to merge 73 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
652cfe6
refactor(clerk-js): Update color logic utils
alexcarpenter Jun 24, 2025
8198e12
checkpoint
alexcarpenter Jun 24, 2025
283f322
refactor color utilities
alexcarpenter Jun 24, 2025
33a32dd
remove eslint-disable usage
alexcarpenter Jun 24, 2025
7cb8d8a
Enhance sandbox styles and color utilities
alexcarpenter Jun 24, 2025
5898f2b
Update colorOptionToHslaScale.ts
alexcarpenter Jun 24, 2025
7db3449
creat unified colors interface to manage modern and legacy support
alexcarpenter Jun 24, 2025
719ee2a
reorganize colors folder
alexcarpenter Jun 24, 2025
c1a3174
extract constants and cache
alexcarpenter Jun 25, 2025
df764fc
add tests
alexcarpenter Jun 25, 2025
87419bd
Delete performance.ts
alexcarpenter Jun 25, 2025
6f1d280
Update app.ts
alexcarpenter Jun 25, 2025
18f15aa
revert sandbox changes
alexcarpenter Jun 25, 2025
b7dcccc
Merge branch 'main' into alexcarpenter/user-2201-add-color-mix-utilities
alexcarpenter Jun 25, 2025
8ea0357
add temp changelog
alexcarpenter Jun 25, 2025
3d22bb9
Merge branch 'main' into alexcarpenter/user-2201-add-color-mix-utilities
alexcarpenter Jun 26, 2025
417d0e5
fix missing import
alexcarpenter Jun 26, 2025
ca6e8e4
refactor: use unknown vs any
alexcarpenter Jun 26, 2025
cf99453
refactor prefixAndStringifyScale types
alexcarpenter Jun 26, 2025
8d60397
Update packages/clerk-js/src/ui/utils/colors/README.md
alexcarpenter Jun 26, 2025
f56fbd4
remove features list
alexcarpenter Jun 26, 2025
ccba2f5
Merge branch 'alexcarpenter/user-2201-add-color-mix-utilities' of git…
alexcarpenter Jun 26, 2025
96a1456
remove perf benefits
alexcarpenter Jun 26, 2025
5273a82
🔪 README
alexcarpenter Jun 26, 2025
da7235b
remove getCacheStats
alexcarpenter Jun 26, 2025
9834559
remove duplicate file
alexcarpenter Jun 26, 2025
abd06ce
remove relative color support for makeTransparent as color-mix handle…
alexcarpenter Jun 26, 2025
41299da
update description
alexcarpenter Jun 26, 2025
0c7e07b
improve description
alexcarpenter Jun 26, 2025
6e7c566
remove comment
alexcarpenter Jun 26, 2025
107c583
cleanup
alexcarpenter Jun 26, 2025
5fcf1ee
remove export
alexcarpenter Jun 26, 2025
facce98
make consistent
alexcarpenter Jun 26, 2025
e51268c
refactor toHSLA and toTransparent usage
alexcarpenter Jun 26, 2025
8d581a9
remove
alexcarpenter Jun 26, 2025
a3ef27b
bring back getCacheStats
alexcarpenter Jun 26, 2025
488f2b9
refactor cache and hasModernColorSupport
alexcarpenter Jun 26, 2025
3189c48
use hasModernColorSupport
alexcarpenter Jun 26, 2025
91a9800
use constants
alexcarpenter Jun 26, 2025
b31b45b
handle feedback
alexcarpenter Jun 26, 2025
9b86c9e
refactor
alexcarpenter Jun 26, 2025
1ae5c97
add legacy tests
alexcarpenter Jun 26, 2025
f200029
rename and consolidate scale generation
alexcarpenter Jun 26, 2025
065445c
feedback
alexcarpenter Jun 26, 2025
79ccc92
rename
alexcarpenter Jun 26, 2025
d21c353
extract color generation functions
alexcarpenter Jun 26, 2025
441a41c
remove memoization
alexcarpenter Jun 26, 2025
2a0bdd2
rename and add js doc comments
alexcarpenter Jun 26, 2025
0ab897c
reduce lookups
alexcarpenter Jun 27, 2025
0a6be7f
reduce lookups
alexcarpenter Jun 27, 2025
7522f71
revert
alexcarpenter Jun 27, 2025
ad7bf32
fix adjustForLightness usage
alexcarpenter Jun 27, 2025
d081f27
add resolveCssVariable funtionality
alexcarpenter Jun 27, 2025
20900a1
fix legacy scale generation
alexcarpenter Jun 27, 2025
50eb9a1
feedback
alexcarpenter Jun 27, 2025
4c1dcce
remove css var from error
alexcarpenter Jun 27, 2025
1a735d2
add docs
alexcarpenter Jun 27, 2025
59f007e
revert
alexcarpenter Jun 27, 2025
d2f01e8
refactor to support composite feature checks
alexcarpenter Jun 27, 2025
fe8b6de
fix spec
alexcarpenter Jun 27, 2025
cde9e6b
Update bundlewatch.config.json
alexcarpenter Jun 27, 2025
88414a2
Update bundlewatch.config.json
alexcarpenter Jun 27, 2025
8a667ad
Merge branch 'main' into alexcarpenter/user-2201-add-color-mix-utilities
alexcarpenter Jun 27, 2025
aff50d2
Update packages/clerk-js/src/ui/utils/colors/README.md
alexcarpenter Jun 27, 2025
9feee93
Update packages/clerk-js/src/ui/utils/colors/README.md
alexcarpenter Jun 27, 2025
7faf80a
Update packages/clerk-js/src/ui/utils/colors/index.ts
alexcarpenter Jun 27, 2025
709a9f7
Update packages/clerk-js/src/ui/utils/colors/modern.ts
alexcarpenter Jun 27, 2025
7741bec
Update packages/clerk-js/src/ui/utils/colors/modern.ts
alexcarpenter Jun 27, 2025
c1af115
Update packages/clerk-js/src/ui/utils/colors/index.ts
alexcarpenter Jun 27, 2025
7081c7b
handle feedback
alexcarpenter Jun 27, 2025
619f2ff
fix css supports usage
alexcarpenter Jun 27, 2025
97e6456
fix adjustForLightness usage
alexcarpenter Jun 27, 2025
ecee31a
Merge branch 'main' into alexcarpenter/user-2201-add-color-mix-utilities
alexcarpenter Jun 27, 2025
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
5 changes: 5 additions & 0 deletions .changeset/chubby-parts-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': minor
---

TODO
4 changes: 2 additions & 2 deletions packages/clerk-js/bundlewatch.config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"files": [
{ "path": "./dist/clerk.js", "maxSize": "612kB" },
{ "path": "./dist/clerk.js", "maxSize": "613.2kB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "72.2KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "115KB" },
{ "path": "./dist/clerk.headless*.js", "maxSize": "55KB" },
{ "path": "./dist/ui-common*.js", "maxSize": "110KB" },
{ "path": "./dist/ui-common*.js", "maxSize": "110.6KB" },
{ "path": "./dist/vendors*.js", "maxSize": "40.2KB" },
{ "path": "./dist/coinbase*.js", "maxSize": "38KB" },
{ "path": "./dist/createorganization*.js", "maxSize": "5KB" },
Expand Down
49 changes: 24 additions & 25 deletions packages/clerk-js/src/ui/customizables/parseVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,47 @@ import type { Theme } from '@clerk/types';

import { spaceScaleKeys } from '../foundations/sizes';
import type { fontSizes, fontWeights } from '../foundations/typography';
import { colorOptionToHslaAlphaScale, colorOptionToHslaLightnessScale } from '../utils/colorOptionToHslaScale';
import { colors } from '../utils/colors';
import { colorOptionToThemedAlphaScale, colorOptionToThemedLightnessScale } from '../utils/colors/scales';
import { fromEntries } from '../utils/fromEntries';
import { removeUndefinedProps } from '../utils/removeUndefinedProps';

export const createColorScales = (theme: Theme) => {
const variables = theme.variables || {};

const primaryScale = colorOptionToHslaLightnessScale(variables.colorPrimary, 'primary');
const primaryAlphaScale = colorOptionToHslaAlphaScale(primaryScale?.primary500, 'primaryAlpha');
const dangerScale = colorOptionToHslaLightnessScale(variables.colorDanger, 'danger');
const dangerAlphaScale = colorOptionToHslaAlphaScale(dangerScale?.danger500, 'dangerAlpha');
const successScale = colorOptionToHslaLightnessScale(variables.colorSuccess, 'success');
const successAlphaScale = colorOptionToHslaAlphaScale(successScale?.success500, 'successAlpha');
const warningScale = colorOptionToHslaLightnessScale(variables.colorWarning, 'warning');
const warningAlphaScale = colorOptionToHslaAlphaScale(warningScale?.warning500, 'warningAlpha');
const dangerScale = colorOptionToThemedLightnessScale(variables.colorDanger, 'danger');
const primaryScale = colorOptionToThemedLightnessScale(variables.colorPrimary, 'primary');
const successScale = colorOptionToThemedLightnessScale(variables.colorSuccess, 'success');
const warningScale = colorOptionToThemedLightnessScale(variables.colorWarning, 'warning');

const dangerAlphaScale = colorOptionToThemedAlphaScale(dangerScale?.danger500, 'dangerAlpha');
const neutralAlphaScale = colorOptionToThemedAlphaScale(variables.colorNeutral, 'neutralAlpha');
const primaryAlphaScale = colorOptionToThemedAlphaScale(primaryScale?.primary500, 'primaryAlpha');
const successAlphaScale = colorOptionToThemedAlphaScale(successScale?.success500, 'successAlpha');
const warningAlphaScale = colorOptionToThemedAlphaScale(warningScale?.warning500, 'warningAlpha');

return removeUndefinedProps({
...primaryScale,
...primaryAlphaScale,
...dangerScale,
...dangerAlphaScale,
...primaryScale,
...successScale,
...successAlphaScale,
...warningScale,
...dangerAlphaScale,
...neutralAlphaScale,
...primaryAlphaScale,
...successAlphaScale,
...warningAlphaScale,
...colorOptionToHslaAlphaScale(variables.colorNeutral, 'neutralAlpha'),
primaryHover: colors.adjustForLightness(primaryScale?.primary500),
colorTextOnPrimaryBackground: toHSLA(variables.colorTextOnPrimaryBackground),
colorText: toHSLA(variables.colorText),
colorTextSecondary: toHSLA(variables.colorTextSecondary) || colors.makeTransparent(variables.colorText, 0.35),
colorInputText: toHSLA(variables.colorInputText),
colorBackground: toHSLA(variables.colorBackground),
colorInputBackground: toHSLA(variables.colorInputBackground),
colorShimmer: toHSLA(variables.colorShimmer),
colorTextOnPrimaryBackground: colors.toHslaString(variables.colorTextOnPrimaryBackground),
colorText: colors.toHslaString(variables.colorText),
colorTextSecondary:
colors.toHslaString(variables.colorTextSecondary) || colors.makeTransparent(variables.colorText, 35),
colorInputText: colors.toHslaString(variables.colorInputText),
colorBackground: colors.toHslaString(variables.colorBackground),
colorInputBackground: colors.toHslaString(variables.colorInputBackground),
colorShimmer: colors.toHslaString(variables.colorShimmer),
});
};

export const toHSLA = (str: string | undefined) => {
return str ? colors.toHslaString(str) : undefined;
};

export const createRadiiUnits = (theme: Theme) => {
const { borderRadius } = theme.variables || {};
if (borderRadius === undefined) {
Expand Down
10 changes: 5 additions & 5 deletions packages/clerk-js/src/ui/foundations/colors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { colorOptionToHslaAlphaScale } from '../utils/colorOptionToHslaScale';
import { colorOptionToThemedAlphaScale } from '../utils/colors/scales';

export const whiteAlpha = Object.freeze({
whiteAlpha25: 'hsla(0, 0%, 100%, 0.02)',
Expand Down Expand Up @@ -65,7 +65,7 @@ export const colors = Object.freeze({
primary900: '#1B171C',
primaryHover: '#3B3C45', //primary 500 adjusted for lightness
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
...colorOptionToHslaAlphaScale('#2F3037', 'primaryAlpha')!,
...colorOptionToThemedAlphaScale('#2F3037', 'primaryAlpha')!,
danger50: '#FEF2F2',
danger100: '#FEE5E5',
danger200: '#FECACA',
Expand All @@ -78,7 +78,7 @@ export const colors = Object.freeze({
danger900: '#7F1D1D',
danger950: '#450A0A',
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
...colorOptionToHslaAlphaScale('#EF4444', 'dangerAlpha')!,
...colorOptionToThemedAlphaScale('#EF4444', 'dangerAlpha')!,
warning50: '#FFF6ED',
warning100: '#FFEBD5',
warning200: '#FED1AA',
Expand All @@ -91,7 +91,7 @@ export const colors = Object.freeze({
warning900: '#7C2912',
warning950: '#431207',
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
...colorOptionToHslaAlphaScale('#F36B16', 'warningAlpha')!,
...colorOptionToThemedAlphaScale('#F36B16', 'warningAlpha')!,
success50: '#F0FDF2',
success100: '#DCFCE2',
success200: '#BBF7C6',
Expand All @@ -104,5 +104,5 @@ export const colors = Object.freeze({
success900: '#145323',
success950: '#052E0F',
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
...colorOptionToHslaAlphaScale('#22C543', 'successAlpha')!,
...colorOptionToThemedAlphaScale('#22C543', 'successAlpha')!,
} as const);
36 changes: 0 additions & 36 deletions packages/clerk-js/src/ui/utils/__tests__/colors.test.ts

This file was deleted.

42 changes: 42 additions & 0 deletions packages/clerk-js/src/ui/utils/__tests__/cssSupports.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { clearCache, cssSupports } from '../cssSupports';

// Mock CSS.supports
const originalCSSSupports = CSS.supports;

beforeAll(() => {
CSS.supports = jest.fn(feature => {
if (feature === 'color: hsl(from white h s l)') return true;
if (feature === 'color: color-mix(in srgb, white, black)') return false;
return false;
});
});

afterAll(() => {
CSS.supports = originalCSSSupports;
});

beforeEach(() => {
clearCache();
(CSS.supports as jest.Mock).mockClear();
});

describe('cssSupports', () => {
test('relativeColorSyntax should return true when supported', () => {
expect(cssSupports.relativeColorSyntax()).toBe(true);
});

test('colorMix should return false when not supported', () => {
expect(cssSupports.colorMix()).toBe(false);
});

test('modernColor should return true when at least one feature is supported', () => {
expect(cssSupports.modernColor()).toBe(true);
});

test('caching works correctly', () => {
cssSupports.relativeColorSyntax();
expect(CSS.supports).toHaveBeenCalledTimes(1);
cssSupports.relativeColorSyntax();
expect(CSS.supports).toHaveBeenCalledTimes(1); // Should not call again due to caching
});
});
161 changes: 0 additions & 161 deletions packages/clerk-js/src/ui/utils/colorOptionToHslaScale.ts

This file was deleted.

Loading
Loading