Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
26 changes: 25 additions & 1 deletion packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2727,9 +2727,33 @@ export class Clerk implements ClerkInterface {
};

#initOptions = (options?: ClerkOptions): ClerkOptions => {
let processedOptions = options ? { ...options } : {};

// Extract cssLayerName from baseTheme if present and move it to appearance level
if (
processedOptions.appearance &&
typeof processedOptions.appearance === 'object' &&
'baseTheme' in processedOptions.appearance
) {
const appearance = processedOptions.appearance;
const { cssLayerName: cssLayerNameFromBaseTheme, ...baseThemeWithoutCssLayer } = appearance.baseTheme;

// Use existing cssLayerName at appearance level, or fall back to one from baseTheme
const finalCssLayerName = appearance.cssLayerName || cssLayerNameFromBaseTheme;

processedOptions = {
...processedOptions,
appearance: {
...appearance,
baseTheme: baseThemeWithoutCssLayer,
...(finalCssLayerName && { cssLayerName: finalCssLayerName }),
},
};
}

return {
...defaultOptions,
...options,
...processedOptions,
allowedRedirectOrigins: createAllowedRedirectOrigins(
options?.allowedRedirectOrigins,
this.frontendApi,
Expand Down
5 changes: 4 additions & 1 deletion packages/themes/src/createTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ interface CreateClerkThemeParams extends DeepPartial<Theme> {

export const experimental_createTheme = (appearance: Appearance<CreateClerkThemeParams>): BaseTheme => {
// Placeholder method that might hande more transformations in the future
return { ...appearance, __type: 'prebuilt_appearance' };
return {
...appearance,
__type: 'prebuilt_appearance',
};
};
1 change: 1 addition & 0 deletions packages/themes/src/themes/shadcn.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { experimental_createTheme } from '../createTheme';

export const shadcn = experimental_createTheme({
cssLayerName: 'components',

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we know shadcn is using TW, we can specify the cssLayerName to be defined within components, relying on TW layer order specified.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cssLayerName: 'components',
cssLayerName: 'clerk-components',

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this to be components as this is the layer name tailwind uses. Which removes the need for them to need to specify the layer order. We can only do this because we know if they are using shadcn, that TW is used and they have a components layer already defined.

variables: {
colorBackground: 'var(--card)',
colorDanger: 'var(--destructive)',
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/appearance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ export type Variables = {
};

export type BaseThemeTaggedType = { __type: 'prebuilt_appearance' };
export type BaseTheme = BaseThemeTaggedType;
export type BaseTheme = BaseThemeTaggedType & { cssLayerName?: string };

export type Theme = {
/**
Expand Down