Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
xaota committed Jun 17, 2021
1 parent b5df539 commit f45deeb
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 38 deletions.
4 changes: 2 additions & 2 deletions components/button-tooltip-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ const style = css`
width: 100%;
}`;

const attributes = {
const attributes = {
text(root, value) { updateChildrenAttribute(root, 'ui-button-icon', 'text', value) },
mode(root, value) { updateChildrenAttribute(root, 'ui-button-icon', 'mode', value) },
content(root, value) { updateChildrenAttribute(root, 'ui-tooltip', 'content', value) },
x(root, value) { updateChildrenAttribute(root, 'ui-tooltip', 'x', value) },
y(root, value) { updateChildrenAttribute(root, 'ui-tooltip', 'y', value) }
}
const properties = {
const properties = {
disabled(root, value) { updateChildrenAttribute(root, 'ui-button', 'disabled', value) }
}

Expand Down
1 change: 1 addition & 0 deletions components/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const style = css`
slot {
display: block;
position: relative;
font-family: var(--font);
}
:slotted(*) {
Expand Down
5 changes: 5 additions & 0 deletions components/caption.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ const style = css`
}
:host([left]) {
text-align: left;
}
:host([no-wrap]) {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}`;

const attributes = {}
Expand Down
4 changes: 3 additions & 1 deletion components/copyright.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Component, { html, css } from '../script/Component.js';
// eslint-disable-next-line no-unused-vars
import UIText from './text.js';

const style = css`
:host {
Expand All @@ -16,7 +18,7 @@ const properties = {}
static template = html`
<template>
<style>${style}</style>
&copy; <slot></slot>
<ui-text>&copy; <slot></slot></ui-text>
</template>`;

/** Создание компонента {UIText} @constructor
Expand Down
50 changes: 50 additions & 0 deletions components/fab-tooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import Component, { html, css } from '../script/Component.js';
import { updateChildrenAttribute } from '../script/DOM.js';
/* eslint-disable no-unused-vars */
import UIFAB from './fab.js';
import UITooltip from './tooltip.js';
/* eslint-enable no-unused-vars */

const attributes = {
/** */
content(root, value) { updateChildrenAttribute(root, 'ui-tooltip', 'content', value) },
/** */
x(root, value) { updateChildrenAttribute(root, 'ui-tooltip', 'x', value) },
/** */
y(root, value) { updateChildrenAttribute(root, 'ui-tooltip', 'y', value) }
}

const properties = {
/** */
disabled(root, value) { updateChildrenAttribute(root, 'ui-button', 'disabled', value) }
}

const style = css`
:host {
display: block;
}
slot {
display: block;
}`;

/** FABTooltip {UIFABTooltip} @class @ui @component <ui-fb-tooltip />
* Floating Action Button with tooltip
*/
export default class UIFABTooltip extends Component {
static template = html`
<template>
<style>${style}</style>
<ui-tooltip><ui-fab><slot></slot></ui-fab></ui-tooltip>
</template>`;

/** Создание элемента в DOM (DOM доступен) / mount @lifecycle
* @param {ShadowRoot} node корневой узел элемента
* @return {UIFABTooltip} @this текущий компонент
*/
mount(node) {
super.mount(node, attributes, properties);
return this;
}
}

Component.init(UIFABTooltip, 'ui-fab-tooltip', { attributes, properties });
4 changes: 3 additions & 1 deletion components/fab.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Component, { html, css } from '../script/Component.js';
// eslint-disable-next-line no-unused-vars
import UIIcon from './icon.js';

const style = css`
Expand Down Expand Up @@ -69,7 +70,8 @@ const properties = {}
* @return {Component} @this {UIFAB} текущий компонент
*/
mount(node) {
return super.mount(node, attributes, properties);
super.mount(node, attributes, properties);
return this;
}
}

Expand Down
1 change: 1 addition & 0 deletions components/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const properties = {};
const style = css`
:host {
display: block;
text-align: center;
}
slot {
display: block;
Expand Down
36 changes: 26 additions & 10 deletions components/numeric-amount.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,8 @@ export const CURRENCIES = {
const attributes = {
/** / label */
label(root, value) {
const label = value?.toUpperCase() || '';
const html = (CURRENCIES[label] || label)?.trim() || '';
let data = html;
if (html.startsWith('&#') && html.slice(-1) === ';') {
const temp = document.createElement('span');
temp.innerHTML = html;
data = temp.textContent;
};
updateChildrenAttribute(root, 'ui-numeric', 'label', data);
const label = currency(value);
updateChildrenAttribute(root, 'ui-numeric', 'label', label);
},
/** / precision */
precision(root, value) { updateChildrenAttribute(root, 'ui-numeric', 'precision', value) }
Expand All @@ -41,9 +34,19 @@ const style = css`
static template = html`
<template>
<style>${style}</style>
<ui-numeric><slot></slot></ui-numeric>
<ui-numeric precision="2"><slot></slot></ui-numeric>
</template>`;

/** Создание компонента {UINumericAmount} @constructor
* @param {number} amount сумма
* @param {string} currency валюта
*/
constructor(amount, currency) {
super();
if (amount !== undefined) this.innerText = amount.toString();
if (currency) this.label = currency;
}

/** Создание элемента в DOM (DOM доступен) / mount @lifecycle
* @param {ShadowRoot} node корневой узел элемента
* @return {UINumericAmount} @this текущий компонент
Expand All @@ -54,3 +57,16 @@ const style = css`
}

Component.init(UINumericAmount, 'ui-numeric-amount', { attributes, properties });

/** Знак валюты / currency @export */
export function currency(value) {
const label = value?.toUpperCase() || '';
const html = (CURRENCIES[label] || label)?.trim() || '';
let data = html;
if (html.startsWith('&#') && html.slice(-1) === ';') {
const temp = document.createElement('span');
temp.innerHTML = html;
data = temp.textContent;
};
return data;
}
8 changes: 8 additions & 0 deletions components/numeric-percent.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ const style = css`
<ui-numeric label="%"><slot></slot></ui-numeric>
</template>`;

/** Создание компонента {UINumericPercent} @constructor
* @param {number} value устанавливаемое значение
*/
constructor(value) {
super();
if (value !== undefined) this.innerText = value;
}

/** Создание элемента в DOM (DOM доступен) / mount @lifecycle
* @param {ShadowRoot} node корневой узел элемента
* @return {UINumericPercent} @this текущий компонент
Expand Down
15 changes: 9 additions & 6 deletions components/numeric.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ const style = css`

/** Создание компонента {UINumeric} @constructor
* @param {number} value устанавливаемое значение
* @param {string} label устанавливаемое значение
*/
constructor(value) {
constructor(value, label) {
super();
if (value === undefined) return;
this.innerText = value;
if (value !== undefined) this.innerText = value;
if (label) this.label = label;
}

/** Создание элемента в DOM (DOM доступен) / mount @lifecycle
Expand Down Expand Up @@ -81,15 +82,16 @@ Component.init(UINumeric, 'ui-numeric', { attributes, properties });
* @param {number} [precision=2] точность (знаков после запятой)
* @param {string} [thousand=' '] разделитель разрядов
* @param {string} [decimal=','] разделитель дробной части
* @param {boolean} showPositiveSign показывать знак + (если число положительное)
* @return {string} форматированное число
*/
export function numeric(value, precision = 2, thousand = '.', decimal = ',') {
export function numeric(value, precision = 2, thousand = '.', decimal = ',', showPositiveSign = false) {
/** @type {number} */
const data = Number.parseFloat(value);
if (Number.isNaN(data)) return '';

/** @type {string} */
const integerReverse = Math.trunc(precision > 0 ? data : Math.round(data)).toString().split('').reverse().join('');
const integerReverse = Math.abs(Math.trunc(precision > 0 ? data : Math.round(data))).toString().split('').reverse().join('');

/** @type {string} */
const integer = [...(integerReverse.matchAll(/\d{1,3}/g))]
Expand All @@ -99,5 +101,6 @@ Component.init(UINumeric, 'ui-numeric', { attributes, properties });

const fraction = precision > 0 ? Math.round(data * Math.pow(10, precision)).toString().slice(-precision) : '';

return precision > 0 ? integer + decimal + fraction : integer;
const string = precision > 0 ? integer + decimal + fraction.padEnd(precision, '0') : integer;
return (value < 0 ? '-' : showPositiveSign ? '+' : '') + string;
}
4 changes: 4 additions & 0 deletions components/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const style = css`
background: var(--background-panel);
}
:host([center]) {
text-align: center;
}
div.root {
display: flex;
flex-direction: column;
Expand Down
12 changes: 6 additions & 6 deletions components/showcase-item.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Component, { html, css } from '../script/Component.js';
import { updateChildrenText } from '../script/DOM.js';
// eslint-disable-next-line no-unused-vars
import UIIcon from './icon.js';

const attributes = {
/** / icon */
icon(root, value) { updateChildrenText(root, 'ui-icon', value) }
};
const properties = {};
Expand All @@ -15,6 +17,7 @@ const style = css`
padding: 0.4em;
cursor: pointer;
position: relative;
box-sizing: border-box;
}
:host(:hover) {
border-color: var(--color-edge-accent);
Expand All @@ -24,6 +27,9 @@ const style = css`
height: 100%;
text-align: center;
}
:host(:empty) slot {
min-width: 1rem;
}
ui-icon {
position: absolute;
top: 50%;
Expand All @@ -48,12 +54,6 @@ const style = css`
<ui-icon></ui-icon>
</template>`;

/** Создание компонента {UIShowCase} @constructor
*/
constructor() {
super();
}

/** Создание элемента в DOM (DOM доступен) / mount @lifecycle
* @param {ShadowRoot} node корневой узел элемента
* @return {UIShowCase} @this текущий компонент
Expand Down
5 changes: 4 additions & 1 deletion components/showcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const style = css`
justify-content: space-around;
align-items: stretch;
flex-wrap: wrap;
row-gap: var(--padding-showcase, 1rem);
gap: var(--padding-showcase, 1rem);
}
:host([align="left"]) slot {
justify-content: left;
}`;

/** Витрина {Showcase} @class @ui @component <ui-showcase />
Expand Down
5 changes: 4 additions & 1 deletion components/statistic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const attributes = {
icon(root, value) { updateChildrenText(root, 'ui-icon', value); },

/** / caption */
caption(root, value) { updateChildrenText(root, 'p', value); }
caption(root, value) { updateChildrenText(root, 'p', value); },

/** / mode */
mode() {}
};
const properties = {};

Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xaota/ui",
"version": "0.9.0",
"version": "0.10.0",
"description": "",
"main": "./index.js",
"exports": {
Expand All @@ -19,11 +19,12 @@
"url": "git+https://github.com/xaota/ui.git"
},
"keywords": [
"api",
"storage",
"javascript",
"browser",
"es-module"
"es-module",
"native",
"web-components",
"ui"
],
"author": "xaota",
"license": "Unlicense",
Expand Down
10 changes: 6 additions & 4 deletions script/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const state = Symbol('state');
event = detail !== null || (!event.type && event.includes('-'))
? new CustomEvent(event, { detail, ...options })
: typeof event === 'object' ? event : new Event(event);
return this.dispatchEvent(event);
this.dispatchEvent(event);
return this;
}

/** connectedCallback */
Expand All @@ -50,7 +51,8 @@ const state = Symbol('state');
if (this.shadowRoot.firstChild) return; // ! loaded @TODO: перенос узла

const template = this.constructor.template.content.cloneNode(true);
this.ready(template).attach(template);
this.ready(template)
this.attach(template);
this[state] = 'attached';
this.mount(this.shadowRoot);
this[state] = 'mounted';
Expand Down Expand Up @@ -93,8 +95,8 @@ const state = Symbol('state');
return this;
}

/** render */
render(node) { // перерендеринг компонента, если требуется
/** перерендеринг компонента, если требуется / render */
render(node) {
return this;
}

Expand Down
3 changes: 1 addition & 2 deletions script/DOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@
} while (self instanceof HTMLSlotElement);

const value = self?.nodeValue;
if (!value) return;

if (value === undefined || value === null) return;
return value.trim();
}

Expand Down

0 comments on commit f45deeb

Please sign in to comment.