@triptease/tt-navbar 0.0.2

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.
@@ -0,0 +1,27 @@
1
+ import { html, css, LitElement } from 'lit';
2
+ import { property } from 'lit/decorators.js';
3
+
4
+ export class TtNavbar extends LitElement {
5
+ static styles = css`
6
+ :host {
7
+ display: block;
8
+ padding: 25px;
9
+ color: var(--tt-navbar-text-color, #000);
10
+ }
11
+ `;
12
+
13
+ @property({ type: String }) header = 'Hey there';
14
+
15
+ @property({ type: Number }) counter = 5;
16
+
17
+ __increment() {
18
+ this.counter += 1;
19
+ }
20
+
21
+ render() {
22
+ return html`
23
+ <h2>${this.header} Nr. ${this.counter}!</h2>
24
+ <button @click=${this.__increment}>increment</button>
25
+ `;
26
+ }
27
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { TtNavbar } from './TtNavbar.js';
@@ -0,0 +1,3 @@
1
+ import { TtNavbar } from './TtNavbar.js';
2
+
3
+ window.customElements.define('tt-navbar', TtNavbar);
@@ -0,0 +1,60 @@
1
+ import { html, TemplateResult } from 'lit';
2
+ import '../src/tt-navbar.js';
3
+
4
+ export default {
5
+ title: 'TtNavbar',
6
+ component: 'tt-navbar',
7
+ argTypes: {
8
+ header: { control: 'text' },
9
+ counter: { control: 'number' },
10
+ textColor: { control: 'color' },
11
+ },
12
+ };
13
+
14
+ interface Story<T> {
15
+ (args: T): TemplateResult;
16
+ args?: Partial<T>;
17
+ argTypes?: Record<string, unknown>;
18
+ }
19
+
20
+ interface ArgTypes {
21
+ header?: string;
22
+ counter?: number;
23
+ textColor?: string;
24
+ slot?: TemplateResult;
25
+ }
26
+
27
+ const Template: Story<ArgTypes> = ({
28
+ header = 'Hello world',
29
+ counter = 5,
30
+ textColor,
31
+ slot,
32
+ }: ArgTypes) => html`
33
+ <tt-navbar
34
+ style="--tt-navbar-text-color: ${textColor || 'black'}"
35
+ .header=${header}
36
+ .counter=${counter}
37
+ >
38
+ ${slot}
39
+ </tt-navbar>
40
+ `;
41
+
42
+ export const Regular = Template.bind({});
43
+
44
+ export const CustomHeader = Template.bind({});
45
+ CustomHeader.args = {
46
+ header: 'My header',
47
+ };
48
+
49
+ export const CustomCounter = Template.bind({});
50
+ CustomCounter.args = {
51
+ counter: 123456,
52
+ };
53
+
54
+ export const SlottedContent = Template.bind({});
55
+ SlottedContent.args = {
56
+ slot: html`<p>Slotted content</p>`,
57
+ };
58
+ SlottedContent.argTypes = {
59
+ slot: { table: { disable: true } },
60
+ };
@@ -0,0 +1,32 @@
1
+ import { html } from 'lit';
2
+ import { fixture, expect } from '@open-wc/testing';
3
+ import { TtNavbar } from '../src/TtNavbar.js';
4
+ import '../src/tt-navbar.js';
5
+
6
+ describe('TtNavbar', () => {
7
+ it('has a default header "Hey there" and counter 5', async () => {
8
+ const el = await fixture<TtNavbar>(html`<tt-navbar></tt-navbar>`);
9
+
10
+ expect(el.header).to.equal('Hey there');
11
+ expect(el.counter).to.equal(5);
12
+ });
13
+
14
+ it('increases the counter on button click', async () => {
15
+ const el = await fixture<TtNavbar>(html`<tt-navbar></tt-navbar>`);
16
+ el.shadowRoot!.querySelector('button')!.click();
17
+
18
+ expect(el.counter).to.equal(6);
19
+ });
20
+
21
+ it('can override the header via attribute', async () => {
22
+ const el = await fixture<TtNavbar>(html`<tt-navbar header="attribute header"></tt-navbar>`);
23
+
24
+ expect(el.header).to.equal('attribute header');
25
+ });
26
+
27
+ it('passes the a11y audit', async () => {
28
+ const el = await fixture<TtNavbar>(html`<tt-navbar></tt-navbar>`);
29
+
30
+ await expect(el).shadowDom.to.be.accessible();
31
+ });
32
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2021",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "noEmitOnError": true,
7
+ "lib": ["es2021", "dom", "DOM.Iterable"],
8
+ "strict": true,
9
+ "esModuleInterop": false,
10
+ "allowSyntheticDefaultImports": true,
11
+ "experimentalDecorators": true,
12
+ "importHelpers": true,
13
+ "outDir": "dist",
14
+ "sourceMap": true,
15
+ "inlineSources": true,
16
+ "rootDir": "./",
17
+ "declaration": true,
18
+ "incremental": true,
19
+ "skipLibCheck": true
20
+ },
21
+ "include": ["**/*.ts"]
22
+ }
@@ -0,0 +1,27 @@
1
+ // import { hmrPlugin, presets } from '@open-wc/dev-server-hmr';
2
+
3
+ /** Use Hot Module replacement by adding --hmr to the start command */
4
+ const hmr = process.argv.includes('--hmr');
5
+
6
+ export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
7
+ open: '/demo/',
8
+ /** Use regular watch mode if HMR is not enabled. */
9
+ watch: !hmr,
10
+ /** Resolve bare module imports */
11
+ nodeResolve: {
12
+ exportConditions: ['browser', 'development'],
13
+ },
14
+
15
+ /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
16
+ // esbuildTarget: 'auto'
17
+
18
+ /** Set appIndex to enable SPA routing */
19
+ // appIndex: 'demo/index.html',
20
+
21
+ plugins: [
22
+ /** Use Hot Module Replacement by uncommenting. Requires @open-wc/dev-server-hmr plugin */
23
+ // hmr && hmrPlugin({ exclude: ['**/*/node_modules/**/*'], presets: [presets.lit] }),
24
+ ],
25
+
26
+ // See documentation for all available options
27
+ });
@@ -0,0 +1,41 @@
1
+ // import { playwrightLauncher } from '@web/test-runner-playwright';
2
+
3
+ const filteredLogs = ['Running in dev mode', 'Lit is in dev mode'];
4
+
5
+ export default /** @type {import("@web/test-runner").TestRunnerConfig} */ ({
6
+ /** Test files to run */
7
+ files: 'dist/test/**/*.test.js',
8
+
9
+ /** Resolve bare module imports */
10
+ nodeResolve: {
11
+ exportConditions: ['browser', 'development'],
12
+ },
13
+
14
+ /** Filter out lit dev mode logs */
15
+ filterBrowserLogs(log) {
16
+ for (const arg of log.args) {
17
+ if (typeof arg === 'string' && filteredLogs.some(l => arg.includes(l))) {
18
+ return false;
19
+ }
20
+ }
21
+ return true;
22
+ },
23
+
24
+ /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
25
+ // esbuildTarget: 'auto',
26
+
27
+ /** Amount of browsers to run concurrently */
28
+ // concurrentBrowsers: 2,
29
+
30
+ /** Amount of test files per browser to test concurrently */
31
+ // concurrency: 1,
32
+
33
+ /** Browsers to run tests on */
34
+ // browsers: [
35
+ // playwrightLauncher({ product: 'chromium' }),
36
+ // playwrightLauncher({ product: 'firefox' }),
37
+ // playwrightLauncher({ product: 'webkit' }),
38
+ // ],
39
+
40
+ // See documentation for all available options
41
+ });