-
Notifications
You must be signed in to change notification settings - Fork 0
Adhoc theme #77
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
base: main
Are you sure you want to change the base?
Adhoc theme #77
Conversation
…nd interactive color picker
…system preference detection
… self-hosted styles
…ast in theme system
…ted Material Design 3 color palette
| color-scheme: light dark; | ||
| --light-color: #ffcfb8; | ||
| --dark-color: #113134; | ||
| --md-primary: #ea6a00; |
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.
material design variables originally set
| sans-serif; | ||
| top: 20px; | ||
| right: 20px; | ||
| background: var(--md-surface-container-high); |
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.
surface container higher so it's more visible https://m3.material.io/blog/tone-based-surface-color-m3
| </main> | ||
|
|
||
| <script> | ||
| function hexToRgb(hex) { |
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.
picks a hex but needs to convert to rgb in order to do math on it
| const hsl = rgbToHsl(rgb.r, rgb.g, rgb.b); | ||
| // Generate tonal palette (MD3 approach) | ||
| const lightness = hsl.l; |
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.
use lightness for md3 conversion https://m3.material.io/styles/color/system/how-the-system-works
| outlinedHover: `hsla(${hsl.h}, ${hsl.s}%, ${lightness + 40}%, 0.08)`, | ||
| // If primary lightness > 60%, uses dark text (same hue at 20% lightness) | ||
| // Otherwise uses white text | ||
| onPrimary: primaryL > 60 ? `hsl(${hsl.h}, ${hsl.s}%, 20%)` : '#ffffff' |
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.
ensure that color is still visible
| applyTheme(colorPicker.value); | ||
| // Re-apply theme when system color scheme changes | ||
| window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { |
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.
ensure that theme is still updated
| X-XSS-Protection = "1; mode=block" | ||
| X-Content-Type-Options = "nosniff" | ||
| Content-Security-Policy = "default-src 'self'; style-src 'unsafe-inline';" | ||
| Content-Security-Policy = "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline';" |
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.
allow scripts to run inline; may use a different framework so this is easier to do on the page
| function generateColorScheme(baseColor) { | ||
| const rgb = hexToRgb(baseColor); | ||
| const hsl = rgbToHsl(rgb.r, rgb.g, rgb.b); |
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.
Probably more complicated (but easier if you can include a library), but OKLCH is better for lightness manipulations than HSL: https://evilmartians.com/chronicles/oklch-in-css-why-quit-rgb-hsl
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.
ooh this is helpful
Goals
Questions
Todo
In progress