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
Conversation
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 | ||
/> | ||
); | ||
}; |
There was a problem hiding this comment.
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
const GlobalStyles: FunctionComponent = () => { | ||
const Tokens = useOdysseyDesignTokens(); | ||
|
||
return ( | ||
<MuiGlobalStyles | ||
styles={svgStyles(Tokens)} | ||
/> | ||
); | ||
}; |
There was a problem hiding this comment.
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
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) { |
There was a problem hiding this comment.
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
// 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', | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
There was a problem hiding this comment.
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
const mergedTokens = { ...Tokens, ...tokensOverride }; | ||
|
||
// Odyssey 1.x does not export their theme, but we can recreate it | ||
const baseOdysseyTheme = createOdysseyMuiTheme({ | ||
odysseyTokens: mergedTokens, | ||
}); | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
"@okta/odyssey-design-tokens": "1.9.1", | ||
"@okta/odyssey-react-mui": "1.9.1", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's a change in Odyssey 1.5.0 https://github.com/okta/odyssey/blob/main/CHANGELOG.md#150-2023-10-27
/> | ||
); | ||
const GlobalStyles: FunctionComponent = () => { | ||
const Tokens = useOdysseyDesignTokens(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: capitalization?
const Tokens = useOdysseyDesignTokens(); | |
const tokens = useOdysseyDesignTokens(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
const mergedTokens = { ...Tokens, ...tokensOverride }; | ||
|
||
// Odyssey 1.x does not export their theme, but we can recreate it | ||
const baseOdysseyTheme = createOdysseyMuiTheme({ | ||
odysseyTokens: mergedTokens, | ||
}); | ||
|
There was a problem hiding this comment.
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?
* Odyssey 1.x Palette Generation using Brand Colors
* Odyssey 1.x Palette Generation using Brand Colors
Description:
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 thebrandColors.primaryColor
config option1.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 vialeonardo.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 definitionstheme.tokens
intoOdysseyProvider
'sdesignTokensOverride
, otherwise token overrides are not accessible via theuseOdysseyDesignTokens
hookPR 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: