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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-08-27 08:13:36 +02:00
|
|
|
import {css, html, LitElement} from "@lion/core";
|
2021-08-25 23:35:06 +02:00
|
|
|
import {Et2Widget} from "../Et2Widget/Et2Widget";
|
2021-09-03 19:20:53 +02:00
|
|
|
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;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
`,
|
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()
|
|
|
|
{
|
|
|
|
return html`
|
2021-09-03 22:44:52 +02:00
|
|
|
<div ${this.id ? html`id="${this.id}"` : ''}>
|
2021-09-02 17:39:17 +02:00
|
|
|
<slot></slot>
|
2021-08-10 23:02:52 +02:00
|
|
|
</div> `;
|
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)
|
|
|
|
{
|
|
|
|
var pairs = _values.data.split(/,/g);
|
|
|
|
for(var i = 0; i < pairs.length; ++i)
|
|
|
|
{
|
|
|
|
var name_value = pairs[i].split(':');
|
|
|
|
jQuery(_nodes[0]).attr('data-' + name_value[0], name_value[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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);
|