2023-01-18 19:40:24 +03:00
|
|
|
|
import { CGSelect } from '../src/cg-select';
|
2022-12-28 20:35:00 +03:00
|
|
|
|
import './example';
|
|
|
|
|
|
|
|
|
|
// ------------------------------Обычный селект--------------------
|
2023-01-17 20:21:43 +03:00
|
|
|
|
const dropdown = new CGSelect({
|
|
|
|
|
selector: '.cg-dropdown_one',
|
2023-02-06 15:24:36 +03:00
|
|
|
|
placeholder: 'Choose a car',
|
|
|
|
|
label: 'EXAMPLE',
|
2022-12-28 20:35:00 +03:00
|
|
|
|
items: [
|
|
|
|
|
'BMW',
|
|
|
|
|
{
|
|
|
|
|
id: '213sade',
|
|
|
|
|
title: 'Opel',
|
|
|
|
|
value: 1,
|
|
|
|
|
},
|
|
|
|
|
'Mersedes',
|
|
|
|
|
'MAN',
|
|
|
|
|
'Ferari',
|
|
|
|
|
],
|
|
|
|
|
styles: {
|
|
|
|
|
head: {
|
|
|
|
|
width: '830px',
|
|
|
|
|
},
|
|
|
|
|
list: {
|
|
|
|
|
width: '824px',
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-01-30 17:57:13 +03:00
|
|
|
|
});
|
|
|
|
|
|
2023-02-06 15:24:36 +03:00
|
|
|
|
dropdown.on('clear', function (e) {
|
|
|
|
|
console.log(`this state: ${e}`);
|
|
|
|
|
});
|
2022-12-28 20:35:00 +03:00
|
|
|
|
|
2023-01-17 20:21:43 +03:00
|
|
|
|
// ------------------------------NativeSelect-----------------------
|
|
|
|
|
const dropdownNativeSelect = new CGSelect({
|
|
|
|
|
selector: '.cg-dropdown_selectNative',
|
2023-02-06 15:24:36 +03:00
|
|
|
|
placeholder: 'Choose a car',
|
2023-01-17 20:21:43 +03:00
|
|
|
|
nativeSelectMode: true,
|
2022-12-28 20:35:00 +03:00
|
|
|
|
items: [
|
|
|
|
|
'BMW',
|
|
|
|
|
{
|
|
|
|
|
id: '213sade',
|
|
|
|
|
title: 'Opel',
|
|
|
|
|
value: 1,
|
|
|
|
|
},
|
|
|
|
|
'Mersedes',
|
|
|
|
|
'MAN',
|
|
|
|
|
'Ferari',
|
2023-01-17 20:21:43 +03:00
|
|
|
|
'Kamaz',
|
|
|
|
|
'Ural',
|
2022-12-28 20:35:00 +03:00
|
|
|
|
],
|
|
|
|
|
styles: {
|
|
|
|
|
head: {
|
|
|
|
|
width: '830px',
|
|
|
|
|
},
|
|
|
|
|
list: {
|
|
|
|
|
width: '824px',
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-02-08 15:03:36 +03:00
|
|
|
|
theme: 'dark',
|
2022-12-28 20:35:00 +03:00
|
|
|
|
});
|
|
|
|
|
|
2023-01-17 20:21:43 +03:00
|
|
|
|
// ------------------------------listDisplayMode--------------------
|
|
|
|
|
const dropdownlistDisplayMode = new CGSelect({
|
|
|
|
|
selector: '.cg-dropdown_listDisplayMode',
|
2023-02-06 15:24:36 +03:00
|
|
|
|
placeholder: 'Choose a car',
|
2023-01-17 20:21:43 +03:00
|
|
|
|
listDisplayMode: true,
|
|
|
|
|
items: [
|
|
|
|
|
'BMW',
|
|
|
|
|
{
|
|
|
|
|
id: '213sade',
|
|
|
|
|
title: 'Opel',
|
|
|
|
|
value: 1,
|
|
|
|
|
},
|
|
|
|
|
'Mersedes',
|
|
|
|
|
'MAN',
|
|
|
|
|
'Ferari',
|
|
|
|
|
],
|
2022-12-28 20:35:00 +03:00
|
|
|
|
styles: {
|
|
|
|
|
head: {
|
|
|
|
|
width: '830px',
|
|
|
|
|
},
|
|
|
|
|
list: {
|
|
|
|
|
width: '824px',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// --------------------------------Категории--------------------------
|
2023-01-17 20:21:43 +03:00
|
|
|
|
const dropdown4 = new CGSelect({
|
2022-12-28 20:35:00 +03:00
|
|
|
|
selector: '.cg-dropdown_categories',
|
2023-02-08 15:03:36 +03:00
|
|
|
|
placeholder: 'Choose region',
|
2022-12-28 20:35:00 +03:00
|
|
|
|
searchMode: true,
|
|
|
|
|
items: [
|
|
|
|
|
{
|
|
|
|
|
category: 'Russia',
|
|
|
|
|
categoryItems: [
|
|
|
|
|
{
|
|
|
|
|
id: '28qwds',
|
|
|
|
|
title: 'Москва',
|
|
|
|
|
value: 0,
|
|
|
|
|
},
|
|
|
|
|
,
|
|
|
|
|
'Ростов-на-дону',
|
|
|
|
|
'Саратов',
|
|
|
|
|
'Волгоград',
|
|
|
|
|
'Донецк',
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
category: 'USA',
|
|
|
|
|
categoryItems: ['Alabama', 'Texas', 'Colorado', 'Klirens', 'Los-Angeles'],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
category: 'France',
|
|
|
|
|
categoryItems: ['Paris'],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
styles: {
|
|
|
|
|
head: {
|
|
|
|
|
width: '830px',
|
|
|
|
|
},
|
|
|
|
|
list: {
|
|
|
|
|
width: '824px',
|
|
|
|
|
},
|
|
|
|
|
placeholder: {
|
|
|
|
|
maxWidth: '500px ',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
multiselect: true,
|
|
|
|
|
multiselectTag: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//----------------управление с помощью кнопок----------------------------------
|
2023-01-17 20:21:43 +03:00
|
|
|
|
const dropdownBtn = new CGSelect({
|
2022-12-28 20:35:00 +03:00
|
|
|
|
selector: '.cg-dropdown_usedBtn',
|
2023-02-06 15:24:36 +03:00
|
|
|
|
placeholder: 'Choose a car',
|
2022-12-28 20:35:00 +03:00
|
|
|
|
searchMode: true,
|
|
|
|
|
items: [
|
|
|
|
|
'BMW',
|
|
|
|
|
{
|
|
|
|
|
id: '213sade',
|
|
|
|
|
title: 'Opel',
|
|
|
|
|
value: 1,
|
|
|
|
|
},
|
|
|
|
|
'Mersedes',
|
|
|
|
|
'MAN',
|
|
|
|
|
'max',
|
|
|
|
|
],
|
|
|
|
|
styles: {
|
|
|
|
|
head: {
|
|
|
|
|
width: '830px',
|
|
|
|
|
color: 'black',
|
|
|
|
|
backgroundColor: 'rgb(176 223 167)',
|
|
|
|
|
},
|
|
|
|
|
list: {
|
|
|
|
|
width: '824px',
|
|
|
|
|
color: 'black',
|
|
|
|
|
backgroundColor: 'rgb(176 223 167)',
|
|
|
|
|
},
|
|
|
|
|
caret: {
|
|
|
|
|
borderTop: '6px solid black',
|
|
|
|
|
},
|
|
|
|
|
search: {
|
|
|
|
|
backgroundColor: '#d7ffff',
|
|
|
|
|
borderRadius: '5px',
|
|
|
|
|
borderBottom: 'none',
|
|
|
|
|
width: '95%',
|
|
|
|
|
color: 'black',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
multiselect: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const buttonOpen = document.querySelector('.button__open');
|
|
|
|
|
const buttonClose = document.querySelector('.button__close');
|
|
|
|
|
|
|
|
|
|
dropdownBtn.buttonControl(buttonOpen, 'open');
|
|
|
|
|
dropdownBtn.buttonControl(buttonClose, 'close');
|
|
|
|
|
|
|
|
|
|
//-------------------------Функция Disabled----------------------------------
|
2023-01-17 20:21:43 +03:00
|
|
|
|
const dropdownDisabled = new CGSelect({
|
2022-12-28 20:35:00 +03:00
|
|
|
|
selector: '.cg-dropdown_checkboxDisable',
|
2023-02-06 15:24:36 +03:00
|
|
|
|
placeholder: 'Choose a car',
|
2022-12-28 20:35:00 +03:00
|
|
|
|
searchMode: true,
|
|
|
|
|
items: [
|
|
|
|
|
'BMW',
|
|
|
|
|
{
|
|
|
|
|
id: '213sade',
|
|
|
|
|
title: 'Opel',
|
|
|
|
|
value: 1,
|
|
|
|
|
},
|
|
|
|
|
'Mersedes',
|
|
|
|
|
'MAN',
|
|
|
|
|
'max',
|
|
|
|
|
],
|
|
|
|
|
styles: {
|
|
|
|
|
head: {
|
|
|
|
|
width: '830px',
|
|
|
|
|
},
|
|
|
|
|
list: {
|
|
|
|
|
width: '824px',
|
|
|
|
|
},
|
|
|
|
|
placeholder: {
|
|
|
|
|
maxWidth: '500px ',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
multiselect: true,
|
|
|
|
|
});
|
|
|
|
|
dropdownDisabled.disabled(true);
|
|
|
|
|
let chbox = document.getElementById('checkboxDisable');
|
|
|
|
|
|
|
|
|
|
chbox.addEventListener('click', () => {
|
|
|
|
|
if (chbox.checked == true) {
|
|
|
|
|
dropdownDisabled.disabled(false);
|
|
|
|
|
} else {
|
|
|
|
|
dropdownDisabled.disabled(true);
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-01-17 20:21:43 +03:00
|
|
|
|
|
|
|
|
|
// ------------------------------URL--------------------
|
|
|
|
|
const dropdown3 = new CGSelect({
|
|
|
|
|
selector: '.cg-dropdown_three',
|
|
|
|
|
placeholder: 'URL',
|
|
|
|
|
url: 'https://jsonplaceholder.typicode.com/todos',
|
|
|
|
|
searchMode: true,
|
|
|
|
|
darkTheme: false,
|
|
|
|
|
language: 'ru',
|
|
|
|
|
styles: {
|
|
|
|
|
head: {
|
|
|
|
|
width: '830px',
|
|
|
|
|
},
|
|
|
|
|
list: {
|
|
|
|
|
width: '824px',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
multiselect: true,
|
|
|
|
|
});
|