-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: add theme.state opacity tokens and split theme types #4917
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: @adrcotfas/refactor/tokens_colors
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| import { baseTheme } from './base'; | ||
| import { tokens } from '../tokens'; | ||
| import { buildScheme } from '../tokens/sys/color/roles'; | ||
| import { defaultState } from '../tokens/sys/state'; | ||
| import type { Theme } from '../types'; | ||
|
|
||
| export const DarkTheme: Theme = { | ||
| ...baseTheme, | ||
| dark: true, | ||
| mode: 'adaptive', | ||
| colors: buildScheme(tokens.md.ref.palette, tokens.md.ref, { mode: 'dark' }), | ||
| state: defaultState, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| import { baseTheme } from './base'; | ||
| import { tokens } from '../tokens'; | ||
| import { buildScheme } from '../tokens/sys/color/roles'; | ||
| import { defaultState } from '../tokens/sys/state'; | ||
| import type { Theme } from '../types'; | ||
|
|
||
| export const LightTheme: Theme = { | ||
| ...baseTheme, | ||
| dark: false, | ||
| colors: buildScheme(tokens.md.ref.palette, tokens.md.ref, { mode: 'light' }), | ||
| state: defaultState, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import type { ThemeState } from '../../types'; | ||
| import { tokens } from '../index'; | ||
|
|
||
| const { stateOpacity } = tokens.md.ref; | ||
|
|
||
| export const defaultState: ThemeState = { | ||
| opacity: { | ||
| hovered: stateOpacity.hovered, | ||
| focused: stateOpacity.focused, | ||
| pressed: stateOpacity.pressed, | ||
| dragged: stateOpacity.dragged, | ||
| disabled: stateOpacity.disabled, | ||
| enabled: stateOpacity.enabled, | ||
| }, | ||
| }; | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import type { ElevationColors } from './elevation'; | ||
|
|
||
| export type ThemeColors = { | ||
| primary: string; | ||
| primaryContainer: string; | ||
| secondary: string; | ||
| secondaryContainer: string; | ||
| tertiary: string; | ||
| tertiaryContainer: string; | ||
| surface: string; | ||
| surfaceDim: string; | ||
| surfaceBright: string; | ||
| surfaceContainerLowest: string; | ||
| surfaceContainerLow: string; | ||
| surfaceContainer: string; | ||
| surfaceContainerHigh: string; | ||
| surfaceContainerHighest: string; | ||
| surfaceVariant: string; | ||
| background: string; | ||
| error: string; | ||
| errorContainer: string; | ||
| onPrimary: string; | ||
| onPrimaryContainer: string; | ||
| onSecondary: string; | ||
| onSecondaryContainer: string; | ||
| onTertiary: string; | ||
| onTertiaryContainer: string; | ||
| onSurface: string; | ||
| onSurfaceVariant: string; | ||
| onError: string; | ||
| onErrorContainer: string; | ||
| onBackground: string; | ||
| outline: string; | ||
| outlineVariant: string; | ||
| inverseSurface: string; | ||
| inverseOnSurface: string; | ||
| inversePrimary: string; | ||
| primaryFixed: string; | ||
| primaryFixedDim: string; | ||
| onPrimaryFixed: string; | ||
| onPrimaryFixedVariant: string; | ||
| secondaryFixed: string; | ||
| secondaryFixedDim: string; | ||
| onSecondaryFixed: string; | ||
| onSecondaryFixedVariant: string; | ||
| tertiaryFixed: string; | ||
| tertiaryFixedDim: string; | ||
| onTertiaryFixed: string; | ||
| onTertiaryFixedVariant: string; | ||
| shadow: string; | ||
| scrim: string; | ||
| /** Pre-computed state layer color at press opacity (0.10). | ||
| * Used for ripple effects. Avoids runtime alpha manipulation | ||
| * which is incompatible with PlatformColor on Android. | ||
| * TODO: revisit after https://github.com/facebook/react-native/pull/56395 | ||
| * @see https://m3.material.io/foundations/interaction/states/state-layers */ | ||
| stateLayerPressed: string; | ||
| elevation: ElevationColors; | ||
| }; |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,14 @@ | ||||||||||
| export type Elevation = 0 | 1 | 2 | 3 | 4 | 5; | ||||||||||
|
|
||||||||||
| export enum ElevationLevels { | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use enums. Use union types. Treat TypeScript as a linter and avoid TypeScript-specific constructs. This has been the direction TypeScript is also going where the syntax is aligned with JS syntax. Enums also increase bundle size, more verbose requiring an import where just typing a string will suffice with union types, and don't really provide any advantages. We should set |
||||||||||
| 'level0', | ||||||||||
| 'level1', | ||||||||||
| 'level2', | ||||||||||
| 'level3', | ||||||||||
| 'level4', | ||||||||||
| 'level5', | ||||||||||
| } | ||||||||||
|
|
||||||||||
| export type ElevationColors = { | ||||||||||
| [key in keyof typeof ElevationLevels]: string; | ||||||||||
| }; | ||||||||||
|
Comment on lines
+12
to
+14
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simpler code would be to do this
Suggested change
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export * from './color'; | ||
| export * from './elevation'; | ||
| export * from './navigation'; | ||
| export * from './state'; | ||
| export * from './theme'; | ||
| export * from './typography'; | ||
| export * from './utils'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| export type NavigationTheme = { | ||
| dark: boolean; | ||
| colors: { | ||
| primary: string; | ||
| background: string; | ||
| card: string; | ||
| text: string; | ||
| border: string; | ||
| notification: string; | ||
| }; | ||
| }; |
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.
Don't think this makes sense to expose
enabledas a public API to customize. There shouldn't be a different opacity for enabled components other than 1.