@aglyn/shared-ui-theme 1.0.0-beta.143 → 1.0.0-beta.144
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -3
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,7 +1,63 @@
|
|
|
1
1
|
# @aglyn/shared-ui-theme
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Material UI theming layer the Aglyn packages share: a responsive theme factory, the console and site default themes, a provider that renders a site's stored theme document as a MUI theme with light and dark schemes, Emotion cache helpers, and WCAG contrast utilities. It is mainly a dependency of the renderer, Besigner and the other `@aglyn/shared-ui-*` packages; the utilities are usable in any MUI app.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> Beta. Published from the Aglyn monorepo under the `beta` dist-tag; APIs can change between beta releases.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
npm install @aglyn/shared-ui-theme@beta
|
|
10
|
+
|
|
11
|
+
Peer dependencies: `react`, `@mui/material`, `@mui/system`, `@mui/utils`, `@mui/types` and `@mui/styles`. `@emotion/react` and `@emotion/cache` are regular dependencies.
|
|
12
|
+
|
|
13
|
+
## What's in it
|
|
14
|
+
|
|
15
|
+
From the root entry:
|
|
16
|
+
|
|
17
|
+
- **Theme factory.** `createResponsiveTheme({ themeOptions, responsiveFontSizesOptions? })` runs `createTheme`, derives shades for the extra palette colors, repairs derived shades that miss AA contrast, and applies `responsiveFontSizes` across every breakpoint. `createResponsiveCssVarTheme(light, dark, options?)` combines two themes into one CSS-variables theme switched by class.
|
|
18
|
+
- **MUI module augmentation.** Importing the package extends MUI's types with the palette additions these themes use (`tertiary`, `surface`, `tint`), extra typography variants such as `displayXl`, and the matching component `color` overrides. It also re-exports a selection of MUI types and helpers (`Theme`, `ThemeOptions`, `SxProps`, `darkScrollbar`, `visuallyHidden`).
|
|
19
|
+
- **Default themes.** `consoleThemeLight` / `consoleThemeDark` / `consoleThemeCssVar` / `getConsoleTheme(mode)` and `tenantThemeLight` / `tenantThemeDark`, with their `ThemeOptions` (`consoleOptions`, `tenantOptions` and the dark variants). `siteFallbackTheme(host, scheme)` and `siteBaseOptions(host, scheme)` pick between them for a host.
|
|
20
|
+
- **Host theme.** A `HostTheme` (the type lives in `@aglyn/shared-data-types`) is a site's theme customization as plain data. `hostThemeToThemeOptions(theme, scheme)` converts it to `ThemeOptions`; `sanitizeHostTheme`, `mergeThemeOptions`, `hasHostTheme` and `getGoogleFontsUrl` support it. `HostThemeProvider` renders children under it, taking `theme`, a required `fallback` theme or `[light, dark]` pair, `baseOptions`, and `initialMode` / `initialDeviceMode` so a server render can choose the scheme before hydration.
|
|
21
|
+
- **Light/dark mode.** `createWithThemeProvider({ theme })` returns a higher-order component that provides the theme and mode state; `useThemeMode()` reads and toggles it. The choice is stored in the `theme-color-mode` cookie (`COOKIE_THEME_KEY`).
|
|
22
|
+
- **Emotion.** `createEmotionCache`, `CacheProvider`, `createLayeredEmotionCache`, `createWithEmotionClientCache`, and the constants `EMOTION_CACHE_KEY`, `APP_EMOTION_CACHE_OPTIONS`, `MUI_CSS_LAYER_NAME`.
|
|
23
|
+
- **Contrast.** `contrastRatio`, `relativeLuminance`, `meetsContrast`, `accessibleShade`, `accentTextColor`, `accentFillColor`, `auditPaletteContrast`, with `AA_TEXT_CONTRAST` (4.5) and `AA_NON_TEXT_CONTRAST` (3).
|
|
24
|
+
- **Small helpers.** `mergeSxProps` / `useMergeSxProps`, `generateComponentClassKeys`, `FontFamily`, `buildFontFamilyList`.
|
|
25
|
+
|
|
26
|
+
By subpath only: `util/theme-editor-fields` and `util/theme-editor-defaults` (the field vocabulary and readers/writers a theme editor uses over a `HostTheme`), `util/theme-mode-cookie`, `util/color-scheme-hint` and `util/scheme-route-segment` (server-side resolution of the visitor's scheme).
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import {
|
|
32
|
+
contrastRatio,
|
|
33
|
+
createResponsiveTheme,
|
|
34
|
+
createWithThemeProvider,
|
|
35
|
+
} from '@aglyn/shared-ui-theme'
|
|
36
|
+
|
|
37
|
+
const light = createResponsiveTheme({
|
|
38
|
+
themeOptions: { palette: { primary: { main: '#1565c0' } } },
|
|
39
|
+
})
|
|
40
|
+
const dark = createResponsiveTheme({
|
|
41
|
+
themeOptions: { palette: { mode: 'dark', primary: { main: '#90caf9' } } },
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const withTheme = createWithThemeProvider({ theme: [light, dark] })
|
|
45
|
+
|
|
46
|
+
export const App = withTheme(function App() {
|
|
47
|
+
return <main>Hello</main>
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
contrastRatio('#ffffff', '#1565c0') // a number; 4.5 or more passes AA for text
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { parseThemeModeCookie } from '@aglyn/shared-ui-theme/util/theme-mode-cookie'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## How it fits
|
|
58
|
+
|
|
59
|
+
A `shared` UI package. It depends on `@aglyn/shared-data-types`, `@aglyn/shared-util-tools` and `@aglyn/shared-util-vendor`. `@aglyn/shared-ui-jsx`, `@aglyn/shared-ui-jsx-forms`, `@aglyn/shared-ui-next`, the node renderer and Besigner build on it. Shared packages are generic: they import only other shared packages and hold no plugin's domain.
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
Apache-2.0. Source: https://github.com/aglyn/aglyn/tree/main/libs/shared/ui/theme
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/shared-ui-theme",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.144",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/shared-data-types": "1.0.0-beta.
|
|
29
|
-
"@aglyn/shared-util-tools": "1.0.0-beta.
|
|
30
|
-
"@aglyn/shared-util-vendor": "1.0.0-beta.
|
|
28
|
+
"@aglyn/shared-data-types": "1.0.0-beta.144",
|
|
29
|
+
"@aglyn/shared-util-tools": "1.0.0-beta.144",
|
|
30
|
+
"@aglyn/shared-util-vendor": "1.0.0-beta.144",
|
|
31
31
|
"@emotion/cache": "^11.14.0",
|
|
32
32
|
"@emotion/react": "11.14.0",
|
|
33
33
|
"@swc/helpers": "0.5.23",
|