From 8bbd792fddc9577ab09fae4e7ccd33277f25e081 Mon Sep 17 00:00:00 2001 From: pk Date: Tue, 4 Apr 2023 11:03:16 +0200 Subject: [PATCH] First version --- README.md | 2 +- package.json | 11 ++++++----- tp-element.js | 35 --------------------------------- tp-tabs.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 41 deletions(-) delete mode 100644 tp-element.js create mode 100644 tp-tabs.js diff --git a/README.md b/README.md index 1ab27b7..e98a830 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# tp-element +# tp-tabs diff --git a/package.json b/package.json index c39fdff..84933ff 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,19 @@ { - "name": "@tp/tp-element", - "version": "0.0.1", + "name": "@tp/tp-tabs", + "version": "1.0.0", "description": "", - "main": "tp-element.js", + "main": "tp-tabs.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", - "url": "https://gitea.codeblob.work/tp-elements/tp-element.git" + "url": "https://gitea.codeblob.work/tp-tabss/tp-tabs.git" }, "author": "trading_peter", "license": "Apache-2.0", "dependencies": { - "lit": "^2.2.0" + "lit": "^2.2.0", + "@tp/helpers": "^1.0.0" } } diff --git a/tp-element.js b/tp-element.js deleted file mode 100644 index 6a92a2f..0000000 --- a/tp-element.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -@license -Copyright (c) 2022 trading_peter -This program is available under Apache License Version 2.0 -*/ - -import { LitElement, html, css } from 'lit'; - -class TpElement extends LitElement { - static get styles() { - return [ - css` - :host { - display: block; - } - ` - ]; - } - - render() { - const { } = this; - - return html` - - `; - } - - static get properties() { - return { }; - } - - -} - -window.customElements.define('tp-element', TpElement); diff --git a/tp-tabs.js b/tp-tabs.js new file mode 100644 index 0000000..15ac1a7 --- /dev/null +++ b/tp-tabs.js @@ -0,0 +1,54 @@ +/** +@license +Copyright (c) 2023 trading_peter +This program is available under Apache License Version 2.0 +*/ + +import { closest } from '@tp/helpers'; +import { LitElement, html, css } from 'lit-element'; + +class TpTabs extends LitElement { + static get properties() { + return { + orientation: { type: String, reflect: true } + }; + } + + static get styles() { + return css` + :host([orientation="vertical"]) .tabs { + flex-direction: column; + } + .tabs { + display: flex; + flex-direction: row; + } + .tab { + cursor: pointer; + padding: 8px; + } + `; + } + + constructor() { + super(); + this.orientation = 'horizontal'; + } + + render() { + return html` +
+ +
+ `; + } + + selectTab(e) { + const tab = closest(e.target, '.tab'); + if (tab) { + this.dispatchEvent(new CustomEvent('tab-changed', { detail: tab })); + } + } +} + +customElements.define('tp-tabs', TpTabs);