Added default styles(White/Dark) theme

This commit is contained in:
Макс Овсяников 2022-10-31 19:32:59 +03:00
parent bb22c0dc85
commit 04b3bb23b1
7 changed files with 84 additions and 41 deletions

View File

@ -350,7 +350,7 @@ export class DropDown {
* @description Рендер елементов в селекте. * @description Рендер елементов в селекте.
*/ */
#render(select) { #render(select) {
const { styles, multiselect, searchMode, multiselectTag } = this.#options; const { styles, multiselect, searchMode, multiselectTag, darkTheme } = this.#options;
const random = Math.random().toString(36).substring(2, 10); const random = Math.random().toString(36).substring(2, 10);
if (select || (select && styles)) { if (select || (select && styles)) {
@ -362,16 +362,15 @@ export class DropDown {
const ulList = document.createElement('ul'); const ulList = document.createElement('ul');
const intputSearch = createInputSearch(random); const intputSearch = createInputSearch(random);
this.random = random;
const nativSelect = createNativeSelect(); const nativSelect = createNativeSelect();
this.random = random;
ulList.classList.add('list');
if (searchMode) { if (searchMode) {
ulList.appendChild(intputSearch); ulList.appendChild(intputSearch);
} }
ulList.classList.add('list');
if (styles) { if (styles) {
const { list } = styles; const { list } = styles;
customStylesFormat(list, ulList); customStylesFormat(list, ulList);
@ -426,9 +425,33 @@ export class DropDown {
return item; return item;
}); });
if (darkTheme == false) {
this.checkTheme();
}
this.#addOptionsBehaviour(); this.#addOptionsBehaviour();
} }
checkTheme() {
const { darkTheme } = this.#options;
const select = this.#element.querySelector('.cg-select');
const caret = this.#element.querySelector('.caret');
const list = this.#element.querySelector('ul.list');
const listItem = this.#element.querySelectorAll('.list__item');
console.log(list);
if (darkTheme == false) {
select.classList.add('selectWhite');
caret.classList.add('caretWhite');
list.classList.add('listWhite');
} else if (darkTheme == true || !darkTheme) {
return;
} else {
throw new Error('Styles error or invalid value entered!');
}
}
/** /**
* Приватный метод рендера экземпляра класса DropDown * Приватный метод рендера экземпляра класса DropDown
*@protected *@protected

View File

@ -42,6 +42,7 @@ export function createBreadcrumb(data, title, index, id) {
} }
svgIcon.addEventListener('click', (event) => { svgIcon.addEventListener('click', (event) => {
event.preventDefault();
event.stopPropagation(); event.stopPropagation();
nativOptionMultiple(nativOption, title, false); nativOptionMultiple(nativOption, title, false);

View File

@ -5,6 +5,7 @@ const dropdown = new DropDown({
selector: '.cg-dropdown_one', selector: '.cg-dropdown_one',
placeholder: 'Выберите авто', placeholder: 'Выберите авто',
lable: 'Выбор лучшего авто!', lable: 'Выбор лучшего авто!',
darkTheme: false,
items: [ items: [
'BMW', 'BMW',
{ {
@ -15,6 +16,8 @@ const dropdown = new DropDown({
'Mersedes', 'Mersedes',
'MAN', 'MAN',
'Ferari', 'Ferari',
'Ferari',
'Ferari',
], ],
styles: { styles: {
lable: { lable: {
@ -23,7 +26,8 @@ const dropdown = new DropDown({
borderRadius: '5px', borderRadius: '5px',
}, },
}, },
// multiselect: true, multiselect: true,
multiselectTag: true,
}); });
// ------------------------------URL-------------------- // ------------------------------URL--------------------
@ -92,6 +96,7 @@ const dropdownBtn = new DropDown({
selector: '.cg-dropdown_usedBtn', selector: '.cg-dropdown_usedBtn',
placeholder: 'Выберите авто', placeholder: 'Выберите авто',
searchMode: true, searchMode: true,
darkTheme: true,
items: [ items: [
'BMW', 'BMW',
{ {

View File

@ -1,4 +1,7 @@
@import 'src/style/nativSelect.scss'; @import 'src/style/nativSelect.scss';
@import './scrolbar.scss';
@import './whiteTheme.scss';
@import './svgStyle.scss';
* { * {
font-size: 14px; font-size: 14px;
@ -166,28 +169,6 @@ input[type='checkbox'] {
margin: 0 5px 0 0; margin: 0 5px 0 0;
} }
// --------SVG--------
.svg-icon {
width: 16px;
margin-left: 3px;
background-color: #bebebc;
border-radius: 5px;
cursor: pointer;
transition: 1s;
&:hover {
transition: 1s;
background-color: #ffffff;
}
}
.svg-icon path {
color: black;
stroke: currentcolor;
transition: 0.2s;
stroke-width: 0.5;
}
.label { .label {
color: white; color: white;
} }
@ -220,19 +201,6 @@ input[type='checkbox'] {
display: none; display: none;
} }
// ------SCROLLBAR------
::-webkit-scrollbar {
width: 10px;
}
::-webkit-scrollbar-track {
background-color: #d1d1d19d;
}
::-webkit-scrollbar-thumb {
background-color: #4d4d4d;
}
@media (max-width: 425px) { @media (max-width: 425px) {
.list { .list {
display: none !important; display: none !important;

12
src/style/scrolbar.scss Normal file
View File

@ -0,0 +1,12 @@
// ------SCROLLBAR------
::-webkit-scrollbar {
width: 10px;
}
::-webkit-scrollbar-track {
background-color: #d1d1d19d;
}
::-webkit-scrollbar-thumb {
background-color: #4d4d4d;
}

21
src/style/svgStyle.scss Normal file
View File

@ -0,0 +1,21 @@
// --------SVG--------
.svg-icon {
width: 16px;
margin-left: 3px;
background-color: #bebebc;
border-radius: 5px;
cursor: pointer;
transition: 1s;
&:hover {
transition: 1s;
background-color: #ffffff;
}
}
.svg-icon path {
color: black;
stroke: currentcolor;
transition: 0.2s;
stroke-width: 0.5;
}

13
src/style/whiteTheme.scss Normal file
View File

@ -0,0 +1,13 @@
.selectWhite {
color: black !important;
background: rgb(248, 248, 248) !important;
}
.caretWhite {
border-top: 6px solid black !important;
}
.listWhite {
color: black !important;
background-color: white !important;
}