Initial version
This commit is contained in:
parent
556941b24e
commit
aed3f7eda9
13
package-lock.json
generated
Normal file
13
package-lock.json
generated
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "@tp/tp-multi-toggle",
|
||||
"version": "0.0.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@tp/helpers": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://verdaccio.codeblob.work/@tp%2fhelpers/-/helpers-1.0.1.tgz",
|
||||
"integrity": "sha512-f6pDPw4QpjWnmVkYgOHjMXQXtGB4vbA45eZV9DjCF9OoCXsa+Pz32H2rLQRKbdpsfFllywOBI+GMGPYDJyrG/Q=="
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +1,19 @@
|
||||
{
|
||||
"name": "@tp/tp-element",
|
||||
"version": "0.0.1",
|
||||
"name": "@tp/tp-multi-toggle",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "tp-element.js",
|
||||
"main": "tp-multi-toggle.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-elements/tp-multi-toggle.git"
|
||||
},
|
||||
"author": "trading_peter",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@tp/helpers": "^1.0.1",
|
||||
"lit": "^2.2.0"
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
91
tp-multi-toggle.js
Normal file
91
tp-multi-toggle.js
Normal file
@ -0,0 +1,91 @@
|
||||
/**
|
||||
@license
|
||||
Copyright (c) 2022 trading_peter
|
||||
This program is available under Apache License Version 2.0
|
||||
*/
|
||||
|
||||
import { FormElement } from '@tp/helpers/form-element.js';
|
||||
import { LitElement, html, css } from 'lit';
|
||||
import { closest } from '@tp/helpers/closest.js';
|
||||
|
||||
class TpMultiToggle extends FormElement(LitElement) {
|
||||
static get styles() {
|
||||
return [
|
||||
css`
|
||||
:host {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
::slotted(tp-button) {
|
||||
border-radius: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
::slotted(tp-button:not([selected])) {
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
::slotted(tp-button:first-of-type) {
|
||||
border-radius: 4px 0 0 4px;
|
||||
}
|
||||
|
||||
::slotted(tp-button:last-of-type) {
|
||||
border-radius: 0 4px 4px 0;
|
||||
}
|
||||
|
||||
::slotted(tp-button:not(:last-of-type)) {
|
||||
margin-right: 1px;
|
||||
}
|
||||
`
|
||||
];
|
||||
}
|
||||
|
||||
render() {
|
||||
return html`
|
||||
<slot></slot>
|
||||
`;
|
||||
}
|
||||
|
||||
static get properties() {
|
||||
return {
|
||||
attr: { type: String },
|
||||
};
|
||||
}
|
||||
|
||||
get value() {
|
||||
const btn = this.querySelector('tp-button[selected]');
|
||||
|
||||
if (btn) {
|
||||
return btn.getAttribute(this.attr || 'id');
|
||||
}
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.boundClick = this.onClick.bind(this);
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this.addEventListener('click', this.boundClick);
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
this.removeEventListener('click', this.boundClick);
|
||||
}
|
||||
|
||||
onClick(e) {
|
||||
const btn = closest(e.target, 'tp-button', true);
|
||||
|
||||
if (btn) {
|
||||
this.querySelectorAll('tp-button').forEach(el => el.removeAttribute('selected'));
|
||||
btn.setAttribute('selected', '');
|
||||
this.dispatchEvent(new CustomEvent('selection-changed', { detail: this.value, bubbles: true, composed: true }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.customElements.define('to-multi-toggle', TpMultiToggle);
|
Loading…
Reference in New Issue
Block a user