Skip to content

Instantly share code, notes, and snippets.

@fstbraz
fstbraz / tsconfig.json
Created September 1, 2022 13:53
inclusieve-web-components-11
{
"compilerOptions": {
...
"outDir": "./lib",
...
},
...
}
@fstbraz
fstbraz / package.json
Last active September 5, 2022 10:13
inclusive-web-components-10
{
"name": "my-lib",
"version": "0.0.1",
"description": "My Lib description",
"files": [
"lib/**/*"
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
@fstbraz
fstbraz / cards.ts
Created August 31, 2022 15:09
cross-framework-web-components-8
...
import { css, html, LitElement } from 'lit';
import { sharedStyles } from './shared/style';
const componentStyle = css`
.cards > ul {
list-style: none;
margin: 0;
padding: 0;
@fstbraz
fstbraz / cards.ts
Created August 31, 2022 15:03
cross-framework-web-components-8
...
import { html, LitElement } from 'lit';
import { repeat } from 'lit/directives/repeat.js';
@customElement('cards-images')
export class Cards extends LitElement {
...
render() {
@fstbraz
fstbraz / cards.ts
Created August 31, 2022 15:00
cross-framework-web-components-6
...
import { customElement, property } from 'lit/decorators.js';
@customElement('cards-images')
export class Cards extends LitElement {
@property({ type: Array }) cards!: CardConfig[];
}
@fstbraz
fstbraz / cards.ts
Last active August 31, 2022 15:02
cross-framework-web-components-6
...
import { LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
@customElement('cards-images')
export class Cards extends LitElement {}
@fstbraz
fstbraz / card.spec.ts
Last active August 31, 2022 14:58
cross-framework-web-components-6
...
describe('Card Component', () => {
...
it('it renders the image', () => {
const image = el.shadowRoot?.querySelector('img');
expect(image).to.exist;
expect(image?.alt).to.equal(card.altText);
expect(image?.src).to.equal(card.image);
@fstbraz
fstbraz / card.spec.ts
Last active August 31, 2022 15:04
cross-framework-web-components-5
...
import { assert, expect, fixture, html } from '@open-wc/testing';
describe('Card Component', () => {
...
beforeEach(async () => {
el = await fixture<Card>(html` <card-image .card=${card}></card-image> `);
});
@fstbraz
fstbraz / card.spec.ts
Last active August 31, 2022 15:12
cross-framework-web-components-4
import { Card } from './card';
describe('Card Component', () => {
let el: Card;
const card = {
altText: 'Je suis a image',
ctaText: 'Click me',
image: 'http://example.com/image/',
@fstbraz
fstbraz / card.ts
Created August 30, 2022 21:18
cross-framework-web-components-4
...
@customElement('card-image')
export class Card extends LitElement {
...
@query('#card-link') cardLinkEl!: HTMLAnchorElement;
render() {
return html`
<li class="card">
<div class="img">