The m3e-theme component is a non-visual element used to apply dynamic color, expressive motion,
density, and strong focus indicators to nested, theme-aware elements.
npm i @m3e/theme
This section outlines usage examples and configuration guidance for the components in this package.
Use the color attribute to specify a HEX color from which to derive color palettes. This will set
CSS custom properties that reflect the standard Material Design 3 color palettes. For example,
--md-sys-color-primary is set to the primary color.
<m3e-theme color="#4285F4"> <!-- Swatches omitted for brevity --> </m3e-theme>
Themes support three color schemes: light, dark, and auto (default). Use
the scheme attribute to specify the color scheme.
When auto is used, the theme dynamically responds to system preferences by monitoring the media
queries (prefers-color-scheme: light) and (prefers-color-scheme: dark), selecting the
appropriate color scheme based on the user's environment.
<m3e-theme color="#4285F4" scheme="dark"> <!-- Swatches omitted for brevity --> </m3e-theme>
Use the density attribute to control layout compactness across density-aware components within a
theme. It adjusts spacing, padding, and sizing to achieve a more compact or more spacious visual rhythm.
-3 (most compact) to +1 (most spacious)0
When a theme is initialized with a density value, it sets the system token
--md-sys-density-scale to reflect that value. This token is used by density-aware components to
adjust their internal layout metrics.
The following example demonstrates how m3e-button responds to theme-level density adjustments. A
medium-sized button is shown, which supports a minimum density of -2. Note that densities
-3 and -2 produce identical layout behavior for this size, as values below the
supported threshold are clamped to -2.
<m3e-theme density="-3"> <!-- Buttons omitted for brevity --> </m3e-theme> <!-- Additional densities omitted for brevity -->
Themes support two motion schemes: standard (default) and expressive. These schemes
define how components animate across the system, using spring-based physics to guide spatial and effect
transitions. Use the motion attribute to control the motion scheme.
The following example illustrates how the m3e-switch adapts to the motion scheme. Note the spring
effect when clicking the expressive example.
<m3e-theme motion="standard"> <!-- Switch omitted for brevity --> </m3e-theme> <m3e-theme motion="expressive"> <!-- Switch omitted for brevity --> </m3e-theme>
By default, themes are not given an ARIA role, indicating that they are treated as neutral, non-semantic elements in the accessibility tree unless explicitly referenced or annotated.
This package uses JavaScript Modules. To use it directly in a browser without a bundler, use a module script similar to the following.
<script type="module" src="/node_modules/@m3e/theme/dist/index.js"></script>
In addition, you must use an import map to include dependencies.
<script type="importmap">
{
"imports": {
"lit": "https://cdn.jsdelivr.net/npm/lit@3.3.0/+esm",
"@m3e/core": "/node_modules/@m3e/core/dist/index.js"
}
}
</script>
For production, use index.min.js for faster load times.
This package includes a Custom Elements Manifest (custom-elements.json), which
documents the properties, attributes, slots, events and CSS custom properties of each component.
You can explore the API below, or integrate the manifest into your own tooling.