structure adjustment

This commit is contained in:
2023-04-18 17:23:09 +08:00
parent af78bf0381
commit 22dbcf8db2
25 changed files with 519 additions and 138 deletions

View File

@ -1,4 +1,4 @@
import { Grid, createElement, setTooltip, setTooltipNext, createIcon, createCheckbox, createRadiobox, createPopup, showAlert, showConfirm } from "../../ui";
import { Grid, createElement, setTooltip, createIcon, createCheckbox, createRadiobox, createPopup, showAlert, showConfirm } from "../../ui";
import { r, nullOrEmpty, formatUrl, isEmail, isPhone } from "../../utility";
import { createBox } from "./lib";
import Contact from "./contact";
@ -90,16 +90,39 @@ class CustomerCommunication {
element.dispatchEvent(new Event('change'));
}
/**
* @param {boolean} flag
*/
set loading(flag) {
if (this.#container == null) {
return;
}
this.#enter.disabled = flag;
this.#container.querySelector('.customer-name>.ui-input').disabled = flag;
this.#container.querySelector('.button-send-message').disabled = flag;
this.#container.querySelector('.button-edit-contacts').disabled = flag;
this.#container.querySelector('.button-edit-followers').disabled = flag;
}
get text() { return this.#enter?.value }
set text(s) {
const element = this.#enter;
if (element != null) {
element.value = s
s = String(nullOrEmpty(s) ? 0 : val.length) + '/3000';
s = String(nullOrEmpty(s) ? 0 : val.length) + '/' + String(this.#option.maxLength);
this.#container.querySelector('.message-bar .prompt-count').innerText = s;
}
}
get customerName() { return this.#container.querySelector('.customer-name>.ui-input')?.value }
set customerName(name) {
const element = this.#container.querySelector('.customer-name>.ui-input');
if (element == null) {
return;
}
element.value = name;
}
get contacts() {
return [...this.#contacts.children].map(el => {
const span = el.querySelector('span');
@ -303,7 +326,10 @@ class CustomerCommunication {
}
const container = createBox(
createElement('div', null,
createElement('div', div => div.innerText = r('messages', 'Customer Communication')),
createElement('div', div => {
div.className = 'title-module';
div.innerText = option.title ?? r('messages', 'Customer Communication');
}),
createElement('div', div => {
div.className = 'title-company';
if (nullOrEmpty(option.companyName)) {
@ -323,15 +349,16 @@ class CustomerCommunication {
// followers
this.#followers = this.#createFollowers(container, option);
// enter box
const enter = createElement('textarea');
const enter = createElement('textarea', 'ui-text');
enter.placeholder = r('typeMessage', 'Enter Message Here');
enter.maxLength = 3000;
option.maxLength ??= 3000;
enter.maxLength = option.maxLength;
// if (readonly === true) {
// enter.disabled = true;
// }
enter.addEventListener('input', () => {
const val = this.#enter.value;
const s = String(nullOrEmpty(val) ? 0 : val.length) + '/3000';
const s = String(nullOrEmpty(val) ? 0 : val.length) + '/' + String(option.maxLength);
this.#container.querySelector('.message-bar .prompt-count').innerText = s;
});
this.#enter = enter;
@ -344,6 +371,15 @@ class CustomerCommunication {
},
enter,
createElement('div', div => div.style.textAlign = 'right',
createElement('div', div => {
div.className = 'customer-name';
if (option.customerNameVisible !== true) {
div.style.display = 'none';
}
},
createElement('span', span => span.innerText = r('nameColon', 'Name:')),
createElement('input', 'ui-input')
),
createElement('div', 'prompt-count'),
createElement('button', button => {
button.className = 'roundbtn button-send-message';
@ -992,10 +1028,12 @@ class CustomerCommunication {
load(data, contacts, followers) {
const children = [];
if (data?.length > 0) {
contacts ??= this.#data.contacts;
followers ??= this.#data.allfollowers;
for (let comm of data) {
const div = createElement('div', 'item-div');
let name;
if (comm.IsReply) {
if (comm.IsReply && contacts?.length > 0) {
const c = isEmail(comm.Sender) ?
contacts.find(c => c.Email === comm.Sender) :
contacts.find(c => c.MobilePhone === comm.Sender);

View File

@ -17,7 +17,7 @@ class InternalComment {
const element = this.#enter;
if (element != null) {
element.value = s
s = String(nullOrEmpty(s) ? 0 : val.length) + '/3000';
s = String(nullOrEmpty(s) ? 0 : val.length) + '/' + String(this.#option.maxLength);
this.#container.querySelector('.message-bar .prompt-count').innerText = s;
}
}
@ -38,17 +38,20 @@ class InternalComment {
create() {
const container = createBox(
createElement('div', null,
createElement('div', div => div.innerText = r('internalComments', 'Internal Comments'))
createElement('div', div => {
div.className = 'title-module';
div.innerText = r('internalComments', 'Internal Comments');
})
), []
);
const readonly = this.#option.readonly;
// enter box
const enter = createElement('textarea');
const enter = createElement('textarea', 'ui-text');
enter.placeholder = r('typeComment', 'Enter Comment Here');
enter.maxLength = 3000;
enter.maxLength = this.#option.maxLength ??= 3000;
enter.addEventListener('input', () => {
const val = this.#enter.value;
const s = String(nullOrEmpty(val) ? 0 : val.length) + '/3000';
const s = String(nullOrEmpty(val) ? 0 : val.length) + '/' + String(this.#option.maxLength);
this.#container.querySelector('.message-bar .prompt-count').innerText = s;
});
if (readonly === true) {

View File

@ -1,5 +1,3 @@
@import '../../../css/variables/definition.scss';
.popup-mask .wrapper-edit-method {
width: 100%;
@ -46,11 +44,12 @@
}
}
&.disabled {
&.disabled,
&:disabled {
fill: lightgray;
background-color: transparent !important;
&:hover {
&:hover>svg {
opacity: unset;
}
}
@ -95,7 +94,7 @@
line-height: 24px;
display: flex;
align-items: center;
font-size: 1.2em;
font-size: var(--font-larger-size);
>div {
flex: 1 1 auto;
@ -186,7 +185,7 @@
>span {
// flex: 1 1 auto;
color: var(--strong-color);
font-size: var(--font-larger-size);
font-size: var(--font-size);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
@ -216,6 +215,8 @@
border: none;
height: 70px;
resize: none;
font-size: var(--font-smaller-size);
font-family: var(--font-family);
&:focus,
&:focus-visible {
@ -226,9 +227,26 @@
>div {
padding: 0 10px 10px;
>.customer-name {
float: left;
>span {
font-size: var(--font-smaller-size);
}
>.ui-input {
margin-left: 4px;
width: 150px;
border-top: none;
border-left: none;
border-right: none;
}
}
>.prompt-count {
display: inline-block;
color: var(--light-color);
font-size: var(--font-smaller-size);
}
}
}
@ -246,7 +264,7 @@
white-space: normal;
word-break: break-word;
overflow: hidden;
font-size: .8125rem;
font-size: var(--font-size);
color: #333;
display: flex;
flex-direction: column;
@ -257,6 +275,7 @@
.item-poster {
font-weight: bold;
font-size: var(--font-size);
align-self: flex-start;
.tooltip-wrapper>.tooltip-content {
@ -293,7 +312,7 @@
margin-top: 3px;
font-weight: bold;
margin-right: -12px;
font-size: 10px;
font-size: .625rem;
float: right;
}
}
@ -301,7 +320,7 @@
.item-time {
align-self: flex-end;
color: #aaa;
font-size: .7rem;
font-size: .6875rem;
}
&.item-other {

View File

@ -1,6 +1,7 @@
import "../css/ui.scss";
import './ui/css/variables/definition.scss';
import './ui/css/common.scss';
import { createElement } from "./functions";
import { createIcon, resolveIcon } from "./ui/icon";
import { createIcon, changeIcon, resolveIcon } from "./ui/icon";
import { createCheckbox, createRadiobox, resolveCheckbox } from "./ui/checkbox";
import { setTooltip, resolveTooltip } from "./ui/tooltip";
import Dropdown from "./ui/dropdown";
@ -12,6 +13,7 @@ export {
createElement,
// icon
createIcon,
changeIcon,
resolveIcon,
// checkbox
createCheckbox,

View File

@ -1,3 +1,4 @@
import './css/checkbox.scss';
import { createElement } from "../functions";
import { createIcon } from "./icon";

51
lib/ui/css/checkbox.scss Normal file
View File

@ -0,0 +1,51 @@
@import './functions/checkbox.scss';
.checkbox-image {
>input[type="checkbox"] {
display: none;
&:checked {
&~.checked {
display: inline;
}
&~.unchecked {
display: none;
}
}
}
>.checked {
display: none;
}
>.unchecked {
display: inline;
}
}
.checkbox-wrapper {
display: inline-flex;
align-items: center;
padding: 0 8px;
height: 36px;
@include check-box();
.check-box-inner {
flex: 0 0 auto;
&+* {
flex: 1 1 auto;
font-weight: 400;
font-size: var(--font-size);
padding-left: 8px;
padding-right: 6px;
align-self: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
color: var(--color);
}
}
}

29
lib/ui/css/common.scss Normal file
View File

@ -0,0 +1,29 @@
.ui-text,
.ui-input {
font-size: var(--font-size);
font-family: var(--font-family);
border: 1px solid var(--box-color);
border-radius: var(--border-radius);
transition: border-color .2s;
&:focus,
&:focus-visible {
outline: none;
}
&:focus,
&:hover {
border-color: var(--focus-color);
}
&:disabled {
border-color: var(--disabled-box-color);
color: var(--disabled-color);
background-color: var(--disabled-bg-color);
}
}
.ui-input {
text-indent: var(--text-indent);
line-height: var(--line-height);
}

271
lib/ui/css/dropdown.scss Normal file
View File

@ -0,0 +1,271 @@
@import './functions/func.scss';
$headerHeight: 26px;
$caretWidth: 26px;
$dropItemHeight: 30px;
$scrollBarSize: 4px;
$searchBarHeight: 36px;
$searchInputHeight: 26px;
$searchIconSize: 13px;
$listMaxHeight: 210px;
.drop-wrapper {
display: inline-block;
border: none;
border-radius: unset;
user-select: none;
position: relative;
>.drop-header {
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
background-color: var(--bg-color);
display: flex;
height: $headerHeight;
transition: border-color .2s;
&:focus,
&:hover {
border-color: var(--focus-color);
// box-shadow: 0 0 3px 1px rgba(0, 0, 0, .2);
}
&:focus,
&:focus-visible {
outline: none;
}
/*>.drop-select-container {
flex: 1 1 auto;
overflow-x: auto;
white-space: nowrap;
display: flex;
flex-direction: row;
@include scrollbar();
&::-webkit-scrollbar {
height: $scrollBarSize;
}
&::-webkit-scrollbar-thumb {
border-radius: var(--border-radius);
}
>span {
display: inline-block;
margin: 2px;
padding: 0 2px;
border: 1px solid lightgray;
height: 20px;
line-height: 20px;
background-color: white;
font-size: $tinySize;
border-radius: var(--border-radius);
cursor: pointer;
position: relative;
>svg {
display: none;
width: 8px;
height: 20px;
fill: white;
vertical-align: top;
}
&:hover {
border-color: #1890ff;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
background-color: #1890ff;
color: white;
>svg {
display: inline-block;
margin-left: 3px;
padding: 0 2px;
}
}
}
>label {
flex: 1 1 auto;
min-width: 40px;
cursor: pointer;
outline: none;
line-height: $headerHeight;
padding: 0 4px;
font-weight: 400;
font-size: var(--font-smaller-size);
color: var(--color);
}
}*/
>.drop-text {
flex: 1 1 auto;
cursor: pointer;
font-size: var(--font-size);
// line-height: $headerHeight;
padding: 0 6px;
overflow: hidden;
text-overflow: ellipsis;
border: none;
outline: none;
white-space: nowrap;
}
>input.drop-text {
cursor: initial;
&::placeholder {
font-size: var(--font-smaller-size);
font-style: italic;
}
}
>.drop-caret {
flex: 0 0 auto;
width: $caretWidth;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
&::after {
display: block;
content: '';
border-top: 4px solid;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
height: 0;
width: 0;
}
}
&.disabled {
border-color: var(--disabled-bg-color);
color: var(--disabled-color);
&:focus {
border-color: var(--disabled-bg-color);
// box-shadow: none;
}
>.drop-text,
>.drop-caret {
cursor: default;
}
}
}
>.drop-box {
position: absolute;
visibility: hidden;
opacity: 0;
transform: scaleY(0);
transform-origin: top;
background-color: var(--bg-color);
top: calc($headerHeight + 2px);
z-index: 2;
transition: transform 120ms ease, opacity 120ms ease, visibility 120ms ease;
width: calc(100% + 2px);
box-sizing: border-box;
/*border: 1px solid var(--border-color);
border-top-width: 0;*/
box-shadow: 0 3px 6px -4px rgba(0, 0, 0, .12), 0 6px 16px 0 rgba(0, 0, 0, .08), 0 9px 28px 8px rgba(0, 0, 0, .05);
left: -1px;
&.slide-up {
/*border-top-width: 1px;
border-bottom-width: 0;*/
transform-origin: bottom;
top: unset;
bottom: calc($headerHeight + 2px);
}
&.active {
visibility: visible;
opacity: 1;
transform: scaleY(1);
}
>.drop-search {
box-sizing: border-box;
height: $searchBarHeight;
line-height: $searchBarHeight;
padding: 0 8px;
position: relative;
display: flex;
align-items: center;
>input[type="text"] {
box-sizing: border-box;
width: 100%;
height: $searchInputHeight;
outline: none;
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding: 0 6px 0 22px;
color: var(--color);
transition: border-color .2s;
&:hover,
&:focus {
border-color: var(--focus-color);
}
// &:focus {
// box-shadow: 0 0 3px 1px rgba(0, 0, 0, .2);
// }
&::placeholder {
font-style: italic;
}
}
>svg {
position: absolute;
left: 14px;
width: $searchIconSize;
height: 100%;
cursor: text;
}
}
>.drop-list {
margin: 0;
padding: 0;
list-style: none;
max-height: $listMaxHeight;
overflow-y: auto;
font-size: var(--font-size);
@include scrollbar();
&.filtered>li:first-child {
background-color: var(--hover-bg-color);
}
>li {
// display: flex;
// align-items: center;
line-height: $dropItemHeight;
height: $dropItemHeight;
padding: 0 10px;
cursor: pointer;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
&:hover,
&.selected {
background-color: var(--hover-bg-color);
}
>.checkbox-wrapper {
height: $dropItemHeight;
display: flex;
}
}
}
}
}

View File

@ -0,0 +1,68 @@
@mixin check-box() {
.check-box-inner {
position: relative;
display: inline-block;
padding: 0;
width: 14px;
height: 14px;
background-color: #fff;
border: 1px solid var(--box-color);
user-select: none;
border-radius: 2px;
transition: all .2s;
cursor: pointer;
>svg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
fill: #fff;
transform: scale(0);
opacity: 0;
transition: all .08s cubic-bezier(.78, .14, .15, .86);
}
}
&.radiobox-wrapper {
.check-box-inner {
box-sizing: border-box;
border-radius: 8px;
width: 16px;
height: 16px;
}
}
>input[type="checkbox"],
>input[type="radio"] {
display: none;
&:checked+.check-box-inner {
border-color: var(--link-color);
background-color: var(--link-color);
>svg {
transform: scale(1);
opacity: 1;
}
}
&:disabled {
&+.check-box-inner {
border-color: var(--disabled-box-color);
cursor: default;
}
&:checked+.check-box-inner {
border-color: var(--disabled-box-color);
background-color: var(--disabled-box-color);
}
&~span {
color: var(--disabled-box-color);
cursor: default;
}
}
}
}

View File

@ -0,0 +1,18 @@
@mixin inset($top, $right, $bottom, $left) {
top: $top;
right: $right;
bottom: $bottom;
left: $left;
}
@mixin scrollbar() {
&::-webkit-scrollbar {
width: 8px;
height: 8px;
}
&::-webkit-scrollbar-thumb {
background-color: rgba(168, 168, 168, 0.9);
border-radius: 4px;
}
}

378
lib/ui/css/grid.scss Normal file
View File

@ -0,0 +1,378 @@
@import './functions/func.scss';
.grid {
position: relative;
box-sizing: border-box;
display: flex;
flex-direction: column;
overflow: visible;
& {
--hover-bg-color: lightyellow;
--header-border-color: #adaba9;
--header-bg-color: #fafafa;
--header-fore-color: #000;
--cell-border-color: #f0f0f0;
--cell-fore-color: #333;
--dark-border-color: #666;
--split-border-color: #b3b3b3;
--dragger-bg-color: #fff;
--dragger-cursor-color: #333;
--row-bg-color: #fff;
--row-active-bg-color: #fafafa;
--row-selected-bg-color: #e6f2fb;
--text-disabled-color: gray;
--row-height: 36px;
--header-line-height: 26px;
--text-indent: 8px;
--loading-size: 40px;
--loading-border-radius: 20px;
--arrow-size: 4px;
--split-width: 8px;
--dragger-size: 20px;
--dragger-opacity: .6;
--dragger-cursor-size: 4px;
--dragger-cursor-pos: -4px;
--dragger-cursor-opacity: .3;
--header-padding: 4px 12px 4px 8px;
--spacing-s: 4px;
--spacing-cell: 6px 4px 6px 8px;
}
&:focus,
&:focus-visible {
outline: none;
}
&,
input[type="text"],
textarea,
.drop-wrapper>.drop-header>.drop-text,
.drop-wrapper>.drop-box>.drop-list {
font-size: var(--font-size);
font-family: var(--font-family);
}
>.grid-sizer {
position: absolute;
white-space: nowrap;
font-weight: bold;
visibility: hidden;
}
>.grid-header {
width: 100%;
min-width: 100%;
margin: 0;
border-bottom: 1px solid var(--header-border-color);
background-color: var(--header-bg-color);
color: var(--header-fore-color);
user-select: none;
border-collapse: collapse;
border-spacing: 0;
table-layout: fixed;
position: relative;
tr {
position: relative;
>th {
padding: 0;
margin: 0;
word-wrap: break-word;
white-space: normal;
position: relative;
>div {
line-height: var(--header-line-height);
min-height: var(--row-height);
display: flex;
align-items: center;
padding: var(--header-padding);
box-sizing: border-box;
// overflow-x: hidden;
>span {
overflow: hidden;
}
}
>.arrow {
width: 0;
height: 0;
top: 50%;
margin-top: calc(0px - var(--arrow-size) / 2);
right: calc(var(--arrow-size) / 2);
position: absolute;
&.asc {
border-bottom: var(--arrow-size) solid var(--dark-border-color);
}
&.desc {
border-top: var(--arrow-size) solid var(--dark-border-color);
}
&.asc,
&.desc {
border-left: var(--arrow-size) solid transparent;
border-right: var(--arrow-size) solid transparent;
}
}
>.spliter {
position: absolute;
height: 100%;
top: 0;
right: calc(0px - var(--split-width) /2);
width: var(--split-width);
cursor: ew-resize;
z-index: 1;
&::after {
content: '';
height: 100%;
width: 1px;
display: block;
margin: 0 auto;
transition: background-color .12s ease;
}
&:hover::after {
background-color: var(--split-border-color);
}
}
>.dragger {
position: absolute;
left: 0;
top: 0;
min-width: var(--dragger-size);
height: 100%;
background-color: var(--dragger-bg-color);
opacity: var(--dragger-opacity);
display: none;
}
>.dragger-cursor {
position: absolute;
top: 0;
height: 100%;
border: 1px solid var(--dragger-cursor-color);
box-sizing: border-box;
margin-left: 0;
opacity: var(--dragger-cursor-opacity);
display: none;
transition: left .12s ease;
&::before {
top: -1px;
border-top: var(--dragger-cursor-size) solid;
}
&::after {
bottom: -1px;
border-bottom: var(--dragger-cursor-size) solid;
}
&::before,
&::after {
content: '';
position: absolute;
left: var(--dragger-cursor-pos);
border-left: var(--dragger-cursor-size) solid transparent;
border-right: var(--dragger-cursor-size) solid transparent;
}
}
}
}
}
>.grid-body {
flex: 1 1 auto;
overflow: auto;
color: var(--cell-fore-color);
@include scrollbar();
.grid-body-content {
position: absolute;
min-width: 100%;
table-layout: fixed;
border-collapse: collapse;
border-spacing: 0;
>.grid-row {
line-height: var(--line-height);
white-space: nowrap;
background-color: var(--row-bg-color);
border-bottom: 1px solid var(--cell-border-color);
box-sizing: border-box;
&:hover {
background-color: var(--row-active-bg-color);
}
&.selected {
background-color: var(--row-selected-bg-color);
}
>td {
padding: 0;
>span {
padding: var(--spacing-cell);
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: pre;
}
>input[type="text"],
>textarea {
border: none;
box-sizing: border-box;
width: 100%;
padding: 0;
&:focus,
&:focus-visible {
outline: none;
}
&:disabled {
color: var(--text-disabled-color);
}
}
>input[type="text"] {
height: var(--row-height);
text-indent: var(--text-indent);
}
>textarea {
resize: none;
line-height: var(--line-height);
display: block;
padding: var(--spacing-cell);
white-space: nowrap;
@include scrollbar();
}
.checkbox-wrapper {
display: flex;
justify-content: center;
.check-box-inner {
&,
>svg {
transition: none;
}
}
}
.drop-wrapper {
height: var(--row-height);
width: 100%;
display: flex;
flex-direction: column;
>.drop-header {
border: none;
height: 100%;
>.drop-text {
padding: var(--spacing-cell);
}
}
>.drop-box {
top: calc(var(--row-height) + 2px);
&.slide-up {
top: unset;
bottom: calc(var(--row-height) + 2px);
}
}
}
.col-icon {
display: flex;
cursor: pointer;
justify-content: center;
align-items: center;
position: relative;
>svg {
width: 16px;
height: 16px;
fill: var(--primary-color);
transition: opacity .12s ease;
}
&:hover>svg {
opacity: .4;
}
&.disabled {
cursor: unset;
>svg {
fill: var(--header-border-color);
opacity: unset;
}
}
}
}
}
}
.grid-hover-holder {
box-sizing: border-box;
position: absolute;
line-height: var(--line-height);
padding: var(--spacing-cell);
background-color: var(--hover-bg-color);
white-space: pre;
display: flex;
align-items: center;
visibility: hidden;
opacity: 0;
transition: visibility 0s linear .12s, opacity .12s ease;
&.active {
visibility: visible;
opacity: 1;
}
}
}
>.grid-loading {
position: absolute;
@include inset(0, 0, 0, 0);
visibility: hidden;
opacity: 0;
transition: visibility 0s linear .12s, opacity .12s ease;
background-color: var(--loading-bg-color);
display: flex;
justify-content: center;
align-items: center;
z-index: 1;
>div {
background-color: var(--loading-fore-color);
border-radius: var(--loading-border-radius);
>svg {
width: var(--loading-size);
height: var(--loading-size);
padding: 20px;
animation: loading-spinner 1.2s infinite linear;
}
}
}
}

297
lib/ui/css/popup.scss Normal file
View File

@ -0,0 +1,297 @@
@import './functions/func.scss';
$headerLineHeight: 24px;
$buttonHeight: 28px;
.popup-mask {
position: fixed;
@include inset(0, 0, 0, 0);
background-color: rgba(0 0 0 /20%);
display: flex;
justify-content: center;
align-items: center;
opacity: 0;
z-index: 200;
transition: opacity .12s ease;
& {
--corner-radius: 6px;
--loading-size: 20px;
--loading-border-radius: 10px;
}
&.popup-active .popup-container {
transform: scale(1.1);
}
&.popup-transparent {
right: unset;
bottom: unset;
}
.popup-container {
min-width: 400px;
max-width: 800px;
background-color: var(--bg-color);
border-radius: var(--corner-radius);
box-shadow: 0 2px 8px rgba(0 0 0 /11%);
transition: opacity .12s ease, transform .12s ease;
position: absolute;
display: flex;
flex-direction: column;
.popup-header {
flex: 0 0 auto;
padding: 10px 12px 6px;
border-radius: var(--corner-radius) var(--corner-radius) 0 0;
line-height: $headerLineHeight;
user-select: none;
background-color: var(--title-bg-color);
color: var(--title-color);
display: flex;
align-items: center;
>div {
flex: 1 1 auto;
font-size: 1rem;
}
>.popup-header-title {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
>svg {
flex: 0 0 auto;
width: $headerLineHeight;
height: $headerLineHeight;
fill: var(--title-color);
padding: 4px;
cursor: pointer;
box-sizing: border-box;
transition: opacity .12s ease;
&:hover {
opacity: .8;
}
}
}
.popup-body {
margin: 6px 10px;
flex: 1 1 auto;
line-height: $headerLineHeight;
position: relative;
min-height: 100px;
>.popup-loading {
position: absolute;
@include inset(0, 0, -46px, 0);
visibility: hidden;
opacity: 0;
transition: visibility 0s linear .12s, opacity .12s ease;
background-color: var(--loading-bg-color);
display: flex;
justify-content: center;
align-items: center;
z-index: 1;
>div {
background-color: var(--loading-fore-color);
border-radius: var(--loading-border-radius);
>svg {
width: var(--loading-size);
height: var(--loading-size);
padding: 20px;
animation: loading-spinner 1.2s infinite linear;
}
}
}
>.message-wrapper {
display: flex;
margin: 10px;
>svg {
width: 40px;
height: 40px;
&+span {
padding-left: 16px;
}
}
}
.setting-wrapper {
--line-height: 28px;
>.setting-item {
display: flex;
align-items: center;
line-height: var(--line-height);
margin: 4px 0;
>.setting-label {
flex: 0 0 auto;
width: 120px;
text-align: right;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
padding-right: 10px;
&.setting-required::after {
content: '*';
color: var(--red-color);
font-weight: bold;
}
&+* {
flex: 1 1 auto;
margin-right: 10px;
box-sizing: border-box;
height: var(--line-height);
line-height: var(--line-height);
}
&+input[type="text"],
&+input[type="email"],
&+input[type="tel"],
&+textarea {
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
text-indent: var(--text-indent);
transition: border-color .12s ease;
&:hover {
border-color: var(--focus-color);
}
&:focus,
&:focus-visible {
outline: none;
}
}
&+.drop-wrapper>.drop-header>.drop-text {
font-size: 12px;
}
&+.checkbox-wrapper {
padding: 0;
}
}
}
}
}
.popup-footer {
flex: 0 0 auto;
display: flex;
align-items: center;
justify-content: flex-end;
padding: 4px 10px 16px 2px;
.popup-button {
margin-left: 12px;
border: none;
height: $buttonHeight;
line-height: $buttonHeight;
color: var(--title-color);
border-radius: var(--corner-radius);
padding: 0 16px;
box-sizing: border-box;
min-width: 70px;
text-align: center;
cursor: pointer;
user-select: none;
background-color: var(--title-bg-color);
transition: opacity .12s ease;
&:hover {
opacity: .8;
}
&:focus,
&:focus-visible {
outline: none;
}
}
}
.popup-border {
position: absolute;
&.popup-border-left,
&.popup-border-right {
width: 6px;
height: 100%;
top: 0;
cursor: ew-resize;
}
&.popup-border-top,
&.popup-border-bottom {
width: 100%;
height: 6px;
left: 0;
cursor: ns-resize;
}
&.popup-border-top-left,
&.popup-border-top-right,
&.popup-border-bottom-right,
&.popup-border-bottom-left {
width: 8px;
height: 8px;
}
&.popup-border-top-left,
&.popup-border-bottom-right {
cursor: nwse-resize;
}
&.popup-border-top-right,
&.popup-border-bottom-left {
cursor: nesw-resize;
}
&.popup-border-left,
&.popup-border-top-left,
&.popup-border-bottom-left {
left: -4px;
}
&.popup-border-right,
&.popup-border-top-right,
&.popup-border-bottom-right {
right: -4px;
}
&.popup-border-top,
&.popup-border-top-left,
&.popup-border-top-right {
top: -4px;
}
&.popup-border-bottom,
&.popup-border-bottom-right,
&.popup-border-bottom-left {
bottom: -4px;
}
}
&.popup-collapse {
min-height: 40px;
min-width: 160px;
.popup-body,
.popup-footer,
.popup-border {
display: none;
}
}
}
}

51
lib/ui/css/tooltip.scss Normal file
View File

@ -0,0 +1,51 @@
.tooltip-color {
background-color: #fff;
color: #323130;
border-color: rgba(204, 204, 204, .8);
outline: none;
}
.tooltip-wrapper {
position: absolute;
word-wrap: break-word;
height: auto;
text-align: left;
z-index: 250;
min-width: 45px;
max-width: 480px;
min-height: 32px;
border-radius: 2px;
box-shadow: 0 3.2px 7.2px 0 rgba(0, 0, 0, .13), 0 0.6px 1.8px 0 rgba(0, 0, 0, .11);
transition: visibility 0s linear 120ms, opacity 120ms ease;
>.tooltip-pointer {
box-sizing: border-box;
box-shadow: 0 5px 15px 2px rgba(0, 0, 0, .3);
border: 1px solid #fff;
z-index: -1;
width: 16px;
height: 16px;
position: absolute;
left: calc(50% - 8px);
bottom: -8px;
transform: rotate(-45deg);
transform-origin: center;
}
>.tooltip-curtain {
position: absolute;
width: 100%;
height: 100%;
z-index: -1;
}
>.tooltip-content {
font-size: var(--font-smaller-size);
line-height: 1rem;
white-space: normal;
overflow: hidden;
margin: 8px;
height: calc(100% - 16px);
user-select: none;
}
}

View File

@ -0,0 +1,38 @@
// animation
@keyframes loading-spinner {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(359deg);
}
}
:root {
--color: #201f1e;
--red-color: red;
--bg-color: #fff;
--title-color: #fff;
--title-bg-color: rgb(68, 114, 196);
--border-color: #d9d9d9;
--focus-color: #666;
--disabled-bg-color: #e9e9e9;
--disabled-color: #aaa;
--box-color: #999898;
--disabled-box-color: #d9d9d9;
--hover-bg-color: #eee;
--link-color: #1890ff;
--primary-color: rgb(123, 28, 33);
--loading-bg-color: hsla(0, 0%, 100%, .4);
--loading-fore-color: rgba(0, 0, 0, .2);
--border-radius: 2px;
--text-indent: 4px;
--line-height: 24px;
--font-size: .8125rem; // 13px
--font-smaller-size: .75rem; // 12px
--font-larger-size: .875rem; // 14px
--font-family: "Franklin Gothic Book", "San Francisco", "Segoe UI", "Open Sans", "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei UI", sans-serif;
}

View File

@ -1,4 +1,5 @@
// import { r, global, contains, isPositive, nullOrEmpty } from "../utility";
import './css/dropdown.scss';
import { r } from "../utility/lgres";
import { contains, nullOrEmpty } from "../utility/strings";
import { global, isPositive } from "../utility";

View File

@ -1,3 +1,4 @@
import '../css/grid.scss';
import { global, isPositive, isMobile, throttle, truncate } from "../../utility";
import { r } from "../../utility/lgres";
import { createElement } from "../../functions";

1
lib/ui/icon.d.ts vendored
View File

@ -1,2 +1,3 @@
export function createIcon(type: string, id: string, style?: { [key: string]: string }): SVGSVGElement
export function changeIcon(svg: SVGSVGElement, type: string, id: string): SVGSVGElement
export function resolveIcon(container: HTMLElement): HTMLElement

View File

@ -9,6 +9,13 @@ function createUse(type, id) {
return use;
}
function changeIcon(svg, type, id) {
if (svg instanceof HTMLElement) {
svg.replaceChildren(createUse(type, id));
}
return svg;
}
function createIcon(type, id, style) {
const svg = document.createElementNS(svgns, 'svg');
svg.appendChild(createUse(type, id));
@ -34,5 +41,6 @@ function resolveIcon(container) {
export {
createIcon,
changeIcon,
resolveIcon
}

View File

@ -13,15 +13,25 @@
const ui = window['lib-ui'];
document.querySelector('#button-popup').addEventListener('click', () => {
const popup = ui.createPopup('title', 'content',
{
text: 'Loading', trigger: p => {
p.loading = true;
setTimeout(() => p.loading = false, 1000);
return false;
}
},
{ text: 'OK' });
const popup = new ui.Popup({
title: 'title long title, looooooong title, looooooooooooooooooooooooong ~',
content: 'content',
mask: false,
resizable: true,
collapsable: true,
minWidth: 210,
minHeight: 200,
buttons: [
{
text: 'Loading', trigger: p => {
p.loading = true;
setTimeout(() => p.loading = false, 1000);
return false;
}
},
{ text: 'OK' }
]
});
popup.show();
});
</script>
@ -30,5 +40,10 @@
--title-bg-color: lightgray;
--title-color: #333;
}
.popup-mask .popup-container {
min-width: 210px;
min-height: 200px;
max-width: unset;
}
</style>
</div>

View File

@ -1,11 +1,37 @@
import "../../css/popup.scss";
import "./css/popup.scss";
import { r } from "../utility/lgres";
import { nullOrEmpty } from "../utility/strings";
import { global } from "../utility";
import { createElement } from "../functions";
import { r, nullOrEmpty } from "../utility";
import { createIcon } from "./icon";
import { createIcon, changeIcon } from "./icon";
const ResizeMods = {
right: 1,
bottom: 2,
left: 4,
top: 8,
bottomRight: 2 | 1,
bottomLeft: 2 | 4,
topRight: 8 | 1,
topLeft: 8 | 4
}
// const Cursors = {
// [ResizeMods.right]: 'ew-resize',
// [ResizeMods.bottom]: 'ns-resize',
// [ResizeMods.bottomRight]: 'nwse-resize',
// [ResizeMods.left]: 'ew-resize',
// [ResizeMods.bottomLeft]: 'nesw-resize',
// [ResizeMods.top]: 'ns-resize',
// [ResizeMods.topRight]: 'nesw-resize',
// [ResizeMods.topLeft]: 'nwse-resize'
// }
class Popup {
#mask;
#option;
#bounds;
// #cursor;
constructor(opts = {}) {
this.#option = opts;
@ -13,8 +39,47 @@ class Popup {
get container() { return this.#mask.querySelector('.popup-container') }
get rect() {
const container = this.container;
if (container == null) {
return null;
}
const style = global.getComputedStyle(container);
return {
left: style.left,
top: style.top,
width: style.width,
height: style.height
};
}
set rect(r) {
const container = this.container;
if (container == null) {
return;
}
const css = [];
if (!isNaN(r.left)) {
css.push(`left: ${r.left}px`);
}
if (!isNaN(r.top)) {
css.push(`top: ${r.top}px`);
}
if (!isNaN(r.width) && r.width > 0) {
css.push(`width: ${r.width}px`);
}
if (!isNaN(r.height) && r.height > 0) {
css.push(`height: ${r.height}px`);
}
if (css.length > 0) {
container.style.cssText += css.join('; ');
}
}
create() {
const mask = createElement('div', 'popup-mask');
if (this.#option.mask === false) {
mask.classList.add('popup-transparent');
}
const container = createElement('div', 'popup-container');
const close = () => {
mask.classList.add('popup-active');
@ -30,7 +95,10 @@ class Popup {
header.className = 'popup-header';
let title = this.#option.title;
if (!(title instanceof HTMLElement)) {
title = createElement('div', t => t.innerText = title);
title = createElement('div', t => {
t.className = 'popup-header-title';
t.innerText = title;
});
}
header.appendChild(title);
const move = title.querySelector('.popup-move') ?? title;
@ -46,6 +114,27 @@ class Popup {
mask.removeEventListener('mousemove', move, { passive: false });
});
});
if (this.#option.collapsable === true) {
const collapse = createIcon('fa-regular', 'compress-alt');
collapse.classList.add('icon-expand');
collapse.addEventListener('click', () => {
if (container.classList.contains('popup-collapse')) {
const bounds = this.#bounds;
if (bounds != null) {
container.style.cssText += `width: ${bounds.width}; height: ${bounds.height}`;
}
container.classList.remove('popup-collapse');
changeIcon(collapse, 'fa-regular', 'compress-alt');
} else {
const rect = this.rect;
this.#bounds = rect;
container.style.cssText += `left: ${rect.left}; top: ${rect.top}; width: 160px; height: 40px`;
container.classList.add('popup-collapse');
changeIcon(collapse, 'fa-regular', 'expand-alt');
}
});
header.appendChild(collapse);
}
const cancel = createIcon('fa-regular', 'times');
cancel.addEventListener('click', () => close());
header.appendChild(cancel);
@ -79,6 +168,43 @@ class Popup {
}))
);
}
// resizable
if (this.#option.resizable === true) {
container.append(
createElement('layer', layer => {
layer.className = 'popup-border popup-border-right';
layer.addEventListener('mousedown', e => this.#resize(ResizeMods.right, e));
}),
createElement('layer', layer => {
layer.className = 'popup-border popup-border-bottom';
layer.addEventListener('mousedown', e => this.#resize(ResizeMods.bottom, e));
}),
createElement('layer', layer => {
layer.className = 'popup-border popup-border-left';
layer.addEventListener('mousedown', e => this.#resize(ResizeMods.left, e));
}),
createElement('layer', layer => {
layer.className = 'popup-border popup-border-top';
layer.addEventListener('mousedown', e => this.#resize(ResizeMods.top, e));
}),
createElement('layer', layer => {
layer.className = 'popup-border popup-border-bottom-right';
layer.addEventListener('mousedown', e => this.#resize(ResizeMods.bottomRight, e));
}),
createElement('layer', layer => {
layer.className = 'popup-border popup-border-bottom-left';
layer.addEventListener('mousedown', e => this.#resize(ResizeMods.bottomLeft, e));
}),
createElement('layer', layer => {
layer.className = 'popup-border popup-border-top-left';
layer.addEventListener('mousedown', e => this.#resize(ResizeMods.topLeft, e));
}),
createElement('layer', layer => {
layer.className = 'popup-border popup-border-top-right';
layer.addEventListener('mousedown', e => this.#resize(ResizeMods.topRight, e));
})
)
}
mask.appendChild(container);
this.#mask = mask;
return mask;
@ -90,6 +216,12 @@ class Popup {
}
let mask = this.#mask ?? this.create();
parent.appendChild(mask);
if (this.#option.mask === false) {
// calculator position
const container = this.container;
container.style.left = String((parent.offsetWidth - container.offsetWidth) / 2) + 'px';
container.style.top = String((parent.offsetHeight - container.offsetHeight) / 2) + 'px';
}
return new Promise(resolve => {
setTimeout(() => {
mask.style.opacity = 1
@ -112,6 +244,79 @@ class Popup {
loading.style.opacity = 1;
}
}
#resize(mod, e) {
const container = this.container;
const option = this.#option;
if (typeof option.onResizeStarted === 'function') {
option.onResizeStarted.call(this);
}
const mask = this.#mask;
// this.#cursor = mask.style.cursor;
// mask.style.cursor = Cursors[mod];
const originalX = e.clientX;
const originalY = e.clientY;
const original = {
width: container.offsetWidth,
height: container.offsetHeight,
left: container.offsetLeft,
top: container.offsetTop
};
const minWidth = option.minWidth ?? 200;
const minHeight = option.minHeight ?? 200;
const move = e => {
const offsetX = e.clientX - originalX;
const offsetY = e.clientY - originalY;
let width = original.width;
let height = original.height;
let x = original.left;
let y = original.top;
if ((mod & ResizeMods.right) === ResizeMods.right) {
width += offsetX;
if (width < minWidth) {
width = minWidth;
}
}
if ((mod & ResizeMods.bottom) === ResizeMods.bottom) {
height += offsetY;
if (height < minHeight) {
height = minHeight;
}
}
if ((mod & ResizeMods.left) === ResizeMods.left) {
width -= offsetX;
if (width < minWidth) {
width = minWidth;
x = originalX + original.width - minWidth;
} else {
x += offsetX;
}
}
if ((mod & ResizeMods.top) === ResizeMods.top) {
height -= offsetY;
if (height < minHeight) {
height = minHeight;
y = originalY + original.height - minHeight;
} else {
y += offsetY;
}
}
if (typeof option.onResizing === 'function') {
option.onResizing.call(this, x, y, width, height);
} else {
container.style.cssText += `left: ${x}px; top: ${y}px; width: ${width}px; height: ${height}px`;
}
}
const parent = option.mask === false ? mask.parentElement : mask;
parent.addEventListener('mousemove', move, { passive: false });
parent.addEventListener('mouseup', () => {
parent.removeEventListener('mousemove', move, { passive: false });
// mask.style.cursor = this.#cursor;
if (typeof option.onResizeEnded === 'function') {
option.onResizeEnded.call(this);
}
});
}
}
export default Popup;

View File

@ -1,3 +1,4 @@
import './css/tooltip.scss';
import { createElement } from "../functions";
// import { global } from "../utility";

View File

@ -46,7 +46,7 @@ function formatUrl(msg) {
}
for (let r of rs) {
msg = msg.replaceAll(r, '<a target="_blank" href="' + r + '"><svg><use xlink:href="' + ((typeof consts !== 'undefined' && consts.path) ?? '') + 'fonts/fa-regular.svg#link"></use></svg></a>');
msg = msg.replaceAll(r, '<a target="_blank" href="' + r + '"><svg><use xlink:href="' + ((typeof consts !== 'undefined' && consts.path) || '') + 'fonts/fa-regular.svg#link"></use></svg></a>');
}
}