Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: InseeFrLab/onyxia-ui
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.2.7
Choose a base ref
...
head repository: InseeFrLab/onyxia-ui
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.3.0
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 17, 2025

  1. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Zylphrex Tony Xiao
    Copy the full SHA
    eab317c View commit details
  2. Bump version

    garronej committed Mar 17, 2025
    Copy the full SHA
    3d6ffac View commit details
Showing with 26 additions and 8 deletions.
  1. +1 −1 package.json
  2. +25 −7 src/lib/theme.ts
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "onyxia-ui",
"version": "6.2.7",
"version": "6.3.0",
"description": "The Onyxia UI toolkit",
"repository": {
"type": "git",
32 changes: 25 additions & 7 deletions src/lib/theme.ts
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ export type ParamsOfCreateThemeFactory<
ColorUseCases extends ColorUseCasesBase,
CustomTypographyVariantName extends string,
> = {
palette?: Palette;
palette?: Palette | ((params: { isDarkModeEnabled: boolean }) => Palette);
isReactStrictModeEnabled?: boolean;
getTypographyDesc?: GetTypographyDesc<CustomTypographyVariantName>;
createColorUseCases?: CreateColorUseCase<Palette, ColorUseCases>;
@@ -76,7 +76,8 @@ export function createThemeFactory<
>,
) {
const {
palette = defaultPalette as NonNullable<(typeof params)["palette"]>,
//palette_params = defaultPalette as NonNullable<(typeof params)["palette"]>,
palette: palette_params,
createColorUseCases = createDefaultColorUseCases as unknown as NonNullable<
(typeof params)["createColorUseCases"]
>,
@@ -88,6 +89,20 @@ export function createThemeFactory<
getIconSizeInPx = defaultGetIconSizeInPx,
} = params;

const getPalette = (params: { isDarkModeEnabled: boolean }): Palette => {
if (palette_params === undefined) {
return defaultPalette as Palette;
}

const { isDarkModeEnabled } = params;

if (typeof palette_params === "function") {
return palette_params({ isDarkModeEnabled });
}

return palette_params;
};

function createTheme(params: {
isDarkModeEnabled: boolean;
windowInnerWidth: number;
@@ -99,18 +114,21 @@ export function createThemeFactory<
windowInnerWidth,
rootFontSizePx,
});
const useCases = createColorUseCases({
palette,
isDarkModeEnabled,
});

const getPalette_memoized = memoize((isDarkModeEnabled: boolean) =>
getPalette({ isDarkModeEnabled }),
);

const getUseCases_memoized = memoize((isDarkModeEnabled: boolean) =>
createColorUseCases({
palette,
palette: getPalette_memoized(isDarkModeEnabled),
isDarkModeEnabled,
}),
);

const palette = getPalette_memoized(isDarkModeEnabled);
const useCases = getUseCases_memoized(isDarkModeEnabled);

const spacing = (factorOrExplicitNumberOfPx: number | `${number}px`) =>
spacingConfig({
factorOrExplicitNumberOfPx,