-
Notifications
You must be signed in to change notification settings - Fork 22
Library Controllers for Developers
File lib/DirController.ts
Discovers and reports the host element's closest dir
,
even across shadow roots. Does not observe DOM changes.
see https://caniuse.com/css-dir-pseudo
File: elements/rh-secondary-nav/rh-secondary-nav.ts
Importing the controller
import { DirController } from '../../lib/DirController.js';
Adding the controller
#dir = new DirController(this);
Using the controller
const navClasses = { rtl: this.#dir.dir === 'rtl' };
...
return html`
<nav part="nav" class="${classMap(navClasses)}">
...
File lib/ScreenSizeController.ts
Used to determine the current size of the screen inside of a component.
Includes the following breakpoints:
- Mobile
- Mobile Portrait
- Mobile Landscape
- Tablet Portrait
- Tablet Landscape
- Desktop Small
- Desktop Large
These are determined by using the following matchMedia query
screen and (max-width: ${exampleBreakpoint})
where exampleBreakpoint
is replaced depending on the breakpoint being used (ex. mobile uses tabletPortraitBreakpoint
). These breakpoint values can be found in tokens.js
.
rh-secondary-nav-menu.ts
// Importing the controller
import { ScreenSizeController } from '../../lib/ScreenSizeController.js';
. . .
// Creating the private screenSize controller in the element
#screenSize = new ScreenSizeController(this);
. . .
// Creating a private state variable for the component to use for styling / logic.
@observed
@state() private _compact = false;
. . .
// This hooks into the ScreenSizeController to tell the component that when it matches tabletLandscape to change the compact variable.
protected screenSize = new ScreenSizeController(this, 'tabletLandscape', {
onChange: matches => {
this._compact = !matches;
}
});
Questions? Please contact [email protected]. Please review our Code of Conduct