Skip to content

Instantly share code, notes, and snippets.

View jpzwarte's full-sized avatar

Jeroen Zwartepoorte jpzwarte

View GitHub Profile
@jpzwarte
jpzwarte / focus-key-controller.ts
Created May 21, 2021 09:19
Lit2 controllers for keyboard interaction
import { ListKeyController, ListKeyControllerOption } from './list-key-controller';
export interface FocusableOption extends ListKeyControllerOption {
/** Focuses the `FocusableOption`. */
focus(): void;
}
export class FocusKeyController<T> extends ListKeyController<FocusableOption & T> {
setActiveItem(index: number): void {
super.setActiveItem(index);
<dna-popover
onPopoverChange={(event: CustomEvent<boolean>) => this.onPopoverChange(event)}
id={this.popoverId}
placement="right"
>
<dna-shell-menu-popover label={this.label}>
<dna-portal ref={(el: HTMLDnaPortalElement) => (this.portalElement = el)}>
<slot></slot>
</dna-portal>
</dna-shell-menu-popover>
  • input in shadow dom workaround
  • <form> API is not very DX, add helpers to make it more friendly:
    • register custom control events
    • value/getValue @Prop/@Method?
    • validation
export type Orientation = 'horizontal' | 'vertical';

export interface FormControl {

My stencil + storybook setup

  1. Setup your stencil project as usual
  2. Add storybook: npx -p @storybook/cli sb init --type react (we use react so you can use JSX inside your stories)
  3. Add required deps: npm add @babel/plugin-syntax-import-meta @open-wc/webpack-import-meta-loader webpack-merge -D
  4. preview.js:
import { defineCustomElements } from "../dist/esm/loader";
constructor(@Inject(DOCUMENT) private document: any) {
this.style = this.document.createElement('style');
this.style.id = 'theme';
this.document.head.appendChild(this.style);
}
initialize(): Promise<void> {
this._theme = 'magister';
import { convertMenuPositionToConnectedPositions, MenuPositionValue } from './menu-position';
import { ConnectedPosition } from '@angular/cdk/overlay';
interface TestPosition {
side: MenuPositionValue,
align: MenuPositionValue,
positions: ConnectedPosition[]
}
const POSITIONS: TestPosition[] = [
// webpack.vendor.js
module.exports = {
entry: {
vendor: [
'angular',
'jquery',
'jquery-ui/ui/position'
]
},
externals: {
module.exports = {
extends: 'eslint:recommended',
env: {
node: true
},
parserOptions: {
ecmaVersion: 6
},
rules: {
'array-callback-return': 'error',
$bleh: (
color: red
);
$blah: (
color: $blue-dark,
font: 700 20px $font-header,
line-height: 10px
);
<div id="grid"></div>