2021-08-10 23:02:52 +02:00
|
|
|
/**
|
|
|
|
* EGroupware eTemplate2 - Box widget
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link https://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2022-10-07 17:07:29 +02:00
|
|
|
import {classMap, css, html, LitElement} from "@lion/core";
|
2022-05-06 19:57:53 +02:00
|
|
|
import {Et2Widget} from "../../Et2Widget/Et2Widget";
|
|
|
|
import {et2_IDetachedDOM} from "../../et2_core_interfaces";
|
2021-08-10 23:02:52 +02:00
|
|
|
|
2021-09-03 19:20:53 +02:00
|
|
|
export class Et2Box extends Et2Widget(LitElement) implements et2_IDetachedDOM
|
2021-08-10 23:02:52 +02:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
static get styles()
|
|
|
|
{
|
|
|
|
return [
|
2021-09-15 22:59:31 +02:00
|
|
|
...super.styles,
|
2021-08-13 23:26:18 +02:00
|
|
|
css`
|
2021-08-10 23:02:52 +02:00
|
|
|
:host {
|
2021-08-13 23:26:18 +02:00
|
|
|
display: block;
|
2021-08-10 23:02:52 +02:00
|
|
|
}
|
|
|
|
:host > div {
|
|
|
|
display: flex;
|
|
|
|
flex-wrap: nowrap;
|
2021-09-17 17:16:58 +02:00
|
|
|
justify-content: flex-start;
|
2021-08-10 23:02:52 +02:00
|
|
|
align-items: stretch;
|
2021-12-14 16:55:34 +01:00
|
|
|
gap: 5px;
|
2022-03-21 16:21:46 +01:00
|
|
|
height: 100%;
|
2021-09-02 17:39:17 +02:00
|
|
|
}
|
2022-01-25 12:43:37 +01:00
|
|
|
:host([align="right"]) > div {
|
|
|
|
justify-content: flex-end;
|
|
|
|
}
|
|
|
|
:host([align="left"]) > div {
|
|
|
|
justify-content: flex-start;
|
|
|
|
}
|
2022-11-25 19:18:12 +01:00
|
|
|
:host([align="center"]) > div {
|
|
|
|
justify-content: center;
|
|
|
|
}
|
2021-09-02 17:39:17 +02:00
|
|
|
/* CSS for child elements */
|
2021-08-10 23:02:52 +02:00
|
|
|
::slotted(*) {
|
2022-04-22 23:21:46 +02:00
|
|
|
flex: 1 1 auto;
|
2021-09-02 17:39:17 +02:00
|
|
|
}
|
2022-04-08 21:03:20 +02:00
|
|
|
::slotted(img),::slotted(et2-image) {
|
2021-12-09 17:26:58 +01:00
|
|
|
/* Stop images from growing. In general we want them to stay */
|
|
|
|
flex-grow: 0;
|
|
|
|
}
|
2021-09-02 17:39:17 +02:00
|
|
|
::slotted([align="left"]) {
|
|
|
|
margin-right: auto;
|
2021-09-13 19:57:23 +02:00
|
|
|
order: -1;
|
2021-09-02 17:39:17 +02:00
|
|
|
}
|
|
|
|
::slotted([align="right"]) {
|
|
|
|
margin-left: auto;
|
2021-09-13 19:57:23 +02:00
|
|
|
order: 1;
|
2021-09-02 17:39:17 +02:00
|
|
|
}
|
2022-10-07 17:07:29 +02:00
|
|
|
|
|
|
|
/* work around for chromium print bug, see render() */
|
|
|
|
:host > .no-print-gap {
|
|
|
|
gap: 0px;
|
|
|
|
}
|
2021-09-02 17:39:17 +02:00
|
|
|
`,
|
2021-08-13 23:26:18 +02:00
|
|
|
];
|
|
|
|
}
|
2021-08-10 23:02:52 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
render()
|
|
|
|
{
|
2022-10-07 17:07:29 +02:00
|
|
|
/**
|
|
|
|
* Work around Chromium bug
|
|
|
|
* https://bugs.chromium.org/p/chromium/issues/detail?id=1161709
|
|
|
|
*
|
|
|
|
* Printing with gap on empty element gives huge print output
|
|
|
|
*/
|
|
|
|
let noGap = false;
|
|
|
|
if(this.querySelectorAll(":scope > :not([disabled])").length == 0)
|
|
|
|
{
|
|
|
|
noGap = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
return html`
|
2022-10-07 17:07:29 +02:00
|
|
|
<div part="base" ${this.id ? html`id="${this.id}"` : ''} class=${classMap({
|
|
|
|
"no-print-gap": noGap
|
2022-12-05 17:39:08 +01:00
|
|
|
})}>
|
2021-09-02 17:39:17 +02:00
|
|
|
<slot></slot>
|
2021-08-10 23:02:52 +02:00
|
|
|
</div> `;
|
2022-10-07 17:07:29 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
2021-08-10 23:02:52 +02:00
|
|
|
|
2021-08-19 01:41:23 +02:00
|
|
|
set_label(new_label)
|
|
|
|
{
|
|
|
|
// Boxes don't have labels
|
|
|
|
}
|
|
|
|
|
|
|
|
_createNamespace() : boolean
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2021-09-03 19:20:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Code for implementing et2_IDetachedDOM
|
|
|
|
*
|
|
|
|
* Individual widgets are detected and handled by the grid, but the interface is needed for this to happen
|
|
|
|
*
|
|
|
|
* @param {array} _attrs array to add further attributes to
|
|
|
|
*/
|
|
|
|
getDetachedAttributes(_attrs)
|
|
|
|
{
|
|
|
|
_attrs.push('data');
|
|
|
|
}
|
|
|
|
|
|
|
|
getDetachedNodes()
|
|
|
|
{
|
|
|
|
return [this.getDOMNode()];
|
|
|
|
}
|
|
|
|
|
|
|
|
setDetachedAttributes(_nodes, _values)
|
|
|
|
{
|
|
|
|
if(_values.data)
|
|
|
|
{
|
2022-11-24 19:50:36 +01:00
|
|
|
this.data = _values.data;
|
2021-09-03 19:20:53 +02:00
|
|
|
}
|
|
|
|
}
|
2021-08-10 23:02:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define("et2-box", Et2Box);
|
|
|
|
|
|
|
|
export class Et2HBox extends Et2Box
|
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
static get styles()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
...super.styles,
|
|
|
|
css`
|
2021-08-10 23:02:52 +02:00
|
|
|
:host > div {
|
|
|
|
flex-direction: row;
|
2021-09-03 22:44:52 +02:00
|
|
|
}`
|
2021-08-13 23:26:18 +02:00
|
|
|
];
|
|
|
|
}
|
2021-08-10 23:02:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define("et2-hbox", Et2HBox);
|
|
|
|
|
|
|
|
export class Et2VBox extends Et2Box
|
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
static get styles()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
...super.styles,
|
|
|
|
css`
|
2021-08-10 23:02:52 +02:00
|
|
|
:host > div {
|
|
|
|
flex-direction: column;
|
2022-04-25 18:39:46 +02:00
|
|
|
}
|
|
|
|
/* CSS for child elements */
|
|
|
|
::slotted(*) {
|
|
|
|
/* Stop children from growing vertically. In general we want them to stay their "normal" height */
|
|
|
|
flex-grow: 0;
|
|
|
|
}
|
|
|
|
`
|
2021-08-13 23:26:18 +02:00
|
|
|
];
|
|
|
|
}
|
2021-08-10 23:02:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define("et2-vbox", Et2VBox);
|