diff --git a/README.md b/README.md index 1ab27b7..cc397d7 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# tp-element +# tp-checkbox diff --git a/package.json b/package.json index c39fdff..57d9745 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { - "name": "@tp/tp-element", - "version": "0.0.1", + "name": "@tp/tp-checkbox", + "version": "1.0.0", "description": "", - "main": "tp-element.js", + "main": "tp-checkbox.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-checkbox.git" }, "author": "trading_peter", "license": "Apache-2.0", diff --git a/tp-checkbox.js b/tp-checkbox.js new file mode 100644 index 0000000..cf9e3e0 --- /dev/null +++ b/tp-checkbox.js @@ -0,0 +1,107 @@ +/** +@license +Copyright (c) 2022 trading_peter +This program is available under Apache License Version 2.0 +*/ + +import '@tp/tp-icon/tp-icon.js'; +import { FormElement } from '@tp/helpers/form-element'; +import { ControlState } from '@tp/helpers/control-state'; +import { Inert } from '@tp/helpers/inert'; +import { LitElement, html, css, svg } from 'lit'; + +class TpCheckbox extends Inert(ControlState(FormElement(LitElement))) { + static get styles() { + return [ + css` + :host { + display: block; + cursor: pointer; + } + + [hidden] { + display: none; + } + + .box { + display: flex; + align-items: center; + justify-content: center; + border: solid 2px #000; + background: #fff; + border-radius: 2px; + width: var(--tp-checkbox-width, 18px); + height: var(--tp-checkbox-height, 18px); + } + + tp-icon { + --tp-icon-width: var(--tp-checkbox-width, 18px); + --tp-icon-height: var(--tp-checkbox-height, 18px); + } + + .wrap { + display: flex; + align-items: center; + } + + .label { + margin-left: 8px; + } + ` + ]; + } + + render() { + const { checked } = this; + + return html` +