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

Updated Palette Generation #3481

Merged
merged 11 commits into from Dec 12, 2023
Merged

Conversation

trevoring-okta
Copy link
Contributor

@trevoring-okta trevoring-okta commented Dec 6, 2023

Description:

  • Odyssey 1.x expanded their palette to include 10 different hues rather than the original 5(?)
  • Uses Adobe's leonardo-contrast-colors package (same tool Odyssey used to generate their palettes for 1.x) to generate a WCAG-friendly palette that matches Odyssey's required contrast ratios based on the brandColors.primaryColorconfig option
    • Pinned on Leonardo 1.0.0-alpha.13 because that is the last stable version. Also, Leonardo does not have proper TS support for their main API, so we had to define types via leonardo.d.ts. These types were taken from a PR that has been merged into Leonardo but for some reason not been published to NPM. Ideally this will get published soon and we can bump the package and remove the type definitions
  • Also starts passing customer-defined tokens that can be passed in custom code editor via theme.tokens into OdysseyProvider's designTokensOverride, otherwise token overrides are not accessible via the useOdysseyDesignTokens hook

PR Checklist

Issue:

Reviewers:

Screenshot/Video:

Switching from Odyssey 1.x default palette to custom green palette

Screen.Recording.2023-12-06.at.11.54.30.AM.mov

Downstream Monolith Build:

Comment on lines 19 to 33
export const AppIcon: FunctionComponent = () => {
const Tokens = useOdysseyDesignTokens();

return (
<AppsIcon
sx={{
color: Tokens.PalettePrimaryMain,
width: '16px',
height: '16px',
}}
titleAccess={loc('icon.title.application', 'login')}
aria-hidden
/>
);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated custom icons that Denys added to use token overrides instead of theme.palette. We're trying to remove all uses of theme in favor of tokens

Comment on lines 42 to 50
const GlobalStyles: FunctionComponent = () => {
const Tokens = useOdysseyDesignTokens();

return (
<MuiGlobalStyles
styles={svgStyles(Tokens)}
/>
);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See other comment about moving all uses of theme to use tokens when possible

Comment on lines -130 to -139
if (customTokens) {
if (customTokens.PalettePrimaryMain) {
const p = generatePalette(customTokens.PalettePrimaryMain);
set(theme, 'palette.primary.lighter', customTokens.PalettePrimaryLighter ?? p.lighter);
set(theme, 'palette.primary.light', customTokens.PalettePrimaryLight ?? p.light);
set(theme, 'palette.primary.main', customTokens.PalettePrimaryMain ?? p.main);
set(theme, 'palette.primary.dark', customTokens.PalettePrimaryDark ?? p.dark);
set(theme, 'palette.primary.contrastText', p.contrastText);
}
if (customTokens.PaletteDangerMain) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was some miscommunication with the pre-1.x implementation of palette generation. We thought we should be generating palettes whenever the customer passed in token overrides for any of the Main hues but @alexdahl-okta clarified that palette generation should only be via brandColors.primaryColor

Comment on lines -199 to -241
// ruleset with :focus-visible pseudo-selector break entire ruleset in
// ie11 because its not supported. re-define the :hover rule separately
// again so the ruleset is applied in ie11
MuiButton: {
styleOverrides: {
root: ({ ownerState, theme: t }) => ({
...(ownerState.variant === 'primary' && {
'&:hover': {
backgroundColor: t.palette.primary.dark,
},
}),
...(ownerState.variant === 'secondary' && {
'&:hover': {
backgroundColor: t.palette.primary.lighter,
borderColor: t.palette.primary.light,
color: t.palette.primary.main,
},
}),
...(ownerState.variant === 'floating' && {
'&:hover': {
backgroundColor: 'rgba(29, 29, 33, 0.1)',
borderColor: 'transparent',
},
}),
// OKTA-657762 - remove this when odyssey fix is done
textTransform: 'none',
}),
},
},
// ruleset with :focus-visible pseudo-selector break entire ruleset in
// ie11 because its not supported. re-define the :hover rule separately
// again so the ruleset is applied in ie11
MuiIconButton: {
styleOverrides: {
root: {
'&:hover': {
backgroundColor: 'rgba(29, 29, 33, 0.1)',
borderColor: 'transparent',
},
},
},
},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These overrides were for IE11 breaking changes that existed in the 0.x Odyssey version that we used to be pinned on. Since we have bumped to 1.x, these DNE anymore

Comment on lines +116 to +122
const mergedTokens = { ...Tokens, ...tokensOverride };

// Odyssey 1.x does not export their theme, but we can recreate it
const baseOdysseyTheme = createOdysseyMuiTheme({
odysseyTokens: mergedTokens,
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One niche thing to note: palette generation is now limited to the design tokens layer and will not apply at the base MUI theming layer (the base MUI theme appears in code via theme.palette.*). This is fine because even though Odyssey does create a MUI theming layer via this createOdysseyMuiTheme call, they use their design tokens to achieve essentially all of their styling.

TLDR: If the customer begins seeing any styling that can be traced to the base MUI theme layer, there's probably something wrong and the styling is just a fallback

Copy link
Contributor

Choose a reason for hiding this comment

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

Would a bug like that be fixed in SIW or ODS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That scenario would probably be fixed in SIW and would be a case where the SIW dev decided to use the base MUI theme API rather than the Odyssey useOdysseyDesignTokens hook

chroma.contrast(color, WHITE_HEX) >= 4.5 ? WHITE_HEX : BLACK_HEX
);
// Odyssey-defined contrast ratios for their WCAG-friendly palettes
const ODYSSEY_RATIOS = [1.1, 1.31, 1.61, 2.22, 3.32, 4.5, 4.95, 8.72, 11.73, 14.94];
Copy link
Contributor

Choose a reason for hiding this comment

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

Where are these numbers coming from? Odyssey source code/document?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah these numbers have been specifically defined by Odyssey and design

Comment on lines +50 to +51
"@okta/odyssey-design-tokens": "1.9.1",
"@okta/odyssey-react-mui": "1.9.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

You're intentionally pinning to the exact semver?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I decided to pin exactly because even though Odyssey promised no breaking changes they have still been having some breaking changes. For example, the OdysseyProvider API was broken for a few versions and only just got fixed at this 1.9.1 update

Copy link
Contributor

Choose a reason for hiding this comment

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

These VRT screenshots are really useful. Is the background color of secondary button changing due to palette generation or a separate change in Odyssey?

Copy link
Contributor

Choose a reason for hiding this comment

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

/>
);
const GlobalStyles: FunctionComponent = () => {
const Tokens = useOdysseyDesignTokens();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: capitalization?

Suggested change
const Tokens = useOdysseyDesignTokens();
const tokens = useOdysseyDesignTokens();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've been using capital T for all uses of useOdyssyeDesignTokens() in the codebase to mimic how Odyssey imports their tokens: https://github.com/okta/odyssey/blob/782475cc222069f0417b08cb40ed57d298903b1d/packages/odyssey-react-mui/src/theme/createOdysseyMuiTheme.ts#L14C1-L14C55

The capital T feels like it signals to the dev that these tokens are from ultimately from an import rather than something like a prop, but if this violates some syntax I don't mind switching all of the naming to use lowercase T

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope not a blocker. Just pointing it out because TitleCase is usually reserved for classes, types, interface, and enums(?), i.e., wanted to prevent ambiguity or confusion.

Comment on lines +116 to +122
const mergedTokens = { ...Tokens, ...tokensOverride };

// Odyssey 1.x does not export their theme, but we can recreate it
const baseOdysseyTheme = createOdysseyMuiTheme({
odysseyTokens: mergedTokens,
});

Copy link
Contributor

Choose a reason for hiding this comment

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

Would a bug like that be fixed in SIW or ODS?

@trevoring-okta trevoring-okta merged commit 4fbf37b into odyssey-1.x Dec 12, 2023
trevoring-okta added a commit that referenced this pull request Feb 12, 2024
* Odyssey 1.x Palette Generation using Brand Colors
trevoring-okta added a commit that referenced this pull request Feb 13, 2024
* Odyssey 1.x Palette Generation using Brand Colors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants