Compare commits

...

2 Commits

Author SHA1 Message Date
MaxOvs19
45df42825f Fixed description and layout 2023-03-03 14:54:11 +03:00
MaxOvs19
5fc17c7c2d Fixed bugs 2023-03-02 19:45:03 +03:00
6 changed files with 281 additions and 180 deletions

View File

@ -43,7 +43,7 @@
</ul>
<a href="index.html" class="title">Home</a>
<a href="/index.html" class="title" style="margin-left: 15px"
>Go to CGSelect</a
>Example</a
>
</div>
<div class="table-cell" id="tsd-widgets">

View File

@ -1,5 +1,5 @@
// @import '/src/main.scss';
@import './src/constructor/constructor.scss';
@import "./src/constructor/constructor.scss";
* {
font-size: 14px;
@ -55,7 +55,7 @@
h1 {
font-size: 57px;
color: white;
font-family: 'Times New Roman', Times, serif;
font-family: "Times New Roman", Times, serif;
margin: 40px 0 12px 0;
}
@ -255,10 +255,29 @@ pre {
}
}
.stylesTheme {
width: 100% !important;
}
.example-select_title {
font-size: 14px;
height: 40px;
}
.type {
display: none;
}
.row {
flex-direction: column;
.col {
width: 100%;
}
}
pre {
overflow-x: auto !important;
}
}
.version {

View File

@ -250,7 +250,7 @@
<h5 style="margin: 20px 0 5px; text-align: center">Example:</h5>
<div class="row">
<div class="row type">
<h6>For JS</h6>
<h6>For TS</h6>
</div>
@ -291,7 +291,7 @@
</code>
</div>
<h6>CSS</h6>
<code style="display: block; width: 44%">
<code style="display: block; width: 44%" class="stylesTheme">
<pre>
.headTestClass {
background-color: <span class="code__string">#8297ff</span>;
@ -420,6 +420,52 @@
</code>
</div>
<div class="example-select">
<h1 class="example-select_title">Use callbacks</h1>
<div class="layout-select">
<div class="col">
<p style="color: white;">When using a callback, you can pass in the first parameter such values as: <span class="code__string">open, close, select, clear</span>.
<br>The second parameter is a function in which there are two parameters: <span class="code__string">state</span> and <span class="code__string">value</span>.
<br>The output of the value can be seen in the browser console.
</p>
</div>
<button class="cg-dropdown cg-dropdown_callback"></button>
</div>
<button type="button" class="check-code" id="callback">View code</button>
<code id="codeCallback">
<pre>
<span class="code__keyword">const</span> <span class="code__var">dropdown</span> = <span class="code__keyword">new</span> <span class="code__class">CGSelect</span>({
selector: <span class="code__string">'.cg-dropdown_categories',</span>
placeholder: <span class="code__string">'Choose a car',</span>
searchMode: <span class="code__keyword">true,</span>
items: [
<span class="code__string">'BMW',</span>
{
id: <span class="code__string">'213sade',</span>
title: <span class="code__string">'Opel',</span>
value: 1,
},
<span class="code__string">'Mersedes',</span>
<span class="code__string">'MAN',</span>
<span class="code__string">'Ferari',</span>
],
styles: {
head: {
width: <span class="code__string">'830px',</span>
},
list: {
width: <span class="code__string">'824px',</span>
},
},
multiselect: <span class="code__keyword">true,</span>
multiselectTag: <span class="code__keyword">true,</span>
});
</pre>
</code>
</div>
<div class="example-select">
<h1 class="example-select_title">Button control</h1>
<div style="margin-bottom: 15px">

242
index.js
View File

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

View File

@ -1,44 +1,45 @@
import CGSelect from 'cg-select';
import CGSelect from "cg-select";
const body = new CGSelect({
selector: '.body',
placeholder: 'Select element to style',
items: ['head', 'list', 'placeholder', 'caret', 'search'],
selector: ".body",
placeholder: "Select element to style",
items: ["head", "list", "placeholder", "caret", "search"],
});
let head = '';
let list = '';
let placeholder = '';
let caret = '';
let valueSelect = '';
let head = "";
let list = "";
let placeholder = "";
let caret = "";
let valueSelect = "";
let search = "";
const textarea = document.querySelector('#styles');
const renderBtn = document.querySelector('.render');
const textarea = document.querySelector("#styles");
const renderBtn = document.querySelector(".render");
body.on('select', (e, value) => {
body.on("select", (e, value) => {
valueSelect = value;
textarea.value = '';
textarea.removeAttribute('disabled');
textarea.value = "";
textarea.removeAttribute("disabled");
getValueSelect(valueSelect);
});
function getValueSelect(value) {
textarea.onkeyup = function () {
switch (value) {
case 'head':
case "head":
// ввод стилей
head = textarea.value;
break;
case 'list':
case "list":
list = textarea.value;
break;
case 'placeholder':
case "placeholder":
placeholder = textarea.value;
break;
case 'caret':
case "caret":
caret = textarea.value;
break;
case 'search':
case "search":
search = textarea.value;
break;
@ -48,36 +49,36 @@ function getValueSelect(value) {
};
}
renderBtn.addEventListener('click', () => {
renderBtn.addEventListener("click", () => {
const select = new CGSelect({
selector: '.select',
placeholder: 'Choose a car',
label: 'Exemple select',
selector: ".select",
placeholder: "Choose a car",
items: [
'BMW',
"BMW",
{
id: '213sade',
title: 'Opel',
id: "213sade",
title: "Opel",
value: 1,
},
'Mersedes',
'MAN',
'Ferari',
"Mersedes",
"MAN",
"Ferari",
],
searchMode: true,
multiselect: true,
multiselectTag: true,
});
const drop = document.querySelector('.select');
let headSelect = drop.querySelector('.cg-select');
let listSelect = drop.querySelector('.list');
let placeholderSelect = drop.querySelector('.selected');
let caretSelect = drop.querySelector('.caret');
let searchSelect = drop.querySelector('.inputSearch');
headSelect.setAttribute('style', head);
listSelect.setAttribute('style', list);
placeholderSelect.setAttribute('style', placeholder);
caretSelect.setAttribute('style', caret);
searchSelect.setAttribute('style', search);
const drop = document.querySelector(".select");
let headSelect = drop.querySelector(".cg-select");
let listSelect = drop.querySelector(".list");
let placeholderSelect = drop.querySelector(".selected");
let caretSelect = drop.querySelector(".caret");
let searchSelect = drop.querySelector(".inputSearch");
headSelect.setAttribute("style", head);
listSelect.setAttribute("style", list);
placeholderSelect.setAttribute("style", placeholder);
caretSelect.setAttribute("style", caret);
searchSelect.setAttribute("style", search);
});

View File

@ -1,48 +1,55 @@
const firstBtn = document.getElementById('first');
const codeFirst = document.getElementById('codeFirst');
const firstBtn = document.getElementById("first");
const codeFirst = document.getElementById("codeFirst");
const secondBtn = document.getElementById('second');
const codeSecond = document.getElementById('codeSecond');
const secondBtn = document.getElementById("second");
const codeSecond = document.getElementById("codeSecond");
const thirdBtn = document.getElementById('third');
const codeThird = document.getElementById('codeThird');
const thirdBtn = document.getElementById("third");
const codeThird = document.getElementById("codeThird");
const fourthBtn = document.getElementById('fourth');
const codeFourth = document.getElementById('codeFourth');
const fourthBtn = document.getElementById("fourth");
const codeFourth = document.getElementById("codeFourth");
const fifthBtn = document.getElementById('fifth');
const codeFifth = document.getElementById('codeFifth');
const fifthBtn = document.getElementById("fifth");
const codeFifth = document.getElementById("codeFifth");
const six = document.getElementById('six');
const codeSix = document.getElementById('codeSix');
const six = document.getElementById("six");
const codeSix = document.getElementById("codeSix");
const Native = document.getElementById('Native');
const codeNative = document.getElementById('codeNative');
const Native = document.getElementById("Native");
const codeNative = document.getElementById("codeNative");
firstBtn.addEventListener('click', () => {
codeFirst.classList.toggle('active');
const callback = document.getElementById("callback");
const codeCallback = document.getElementById("codeCallback");
firstBtn.addEventListener("click", () => {
codeFirst.classList.toggle("active");
});
secondBtn.addEventListener('click', () => {
codeSecond.classList.toggle('active');
secondBtn.addEventListener("click", () => {
codeSecond.classList.toggle("active");
});
thirdBtn.addEventListener('click', () => {
codeThird.classList.toggle('active');
thirdBtn.addEventListener("click", () => {
codeThird.classList.toggle("active");
});
fourthBtn.addEventListener('click', () => {
codeFourth.classList.toggle('active');
fourthBtn.addEventListener("click", () => {
codeFourth.classList.toggle("active");
});
fifthBtn.addEventListener('click', () => {
codeFifth.classList.toggle('active');
fifthBtn.addEventListener("click", () => {
codeFifth.classList.toggle("active");
});
six.addEventListener('click', () => {
codeSix.classList.toggle('active');
six.addEventListener("click", () => {
codeSix.classList.toggle("active");
});
Native.addEventListener('click', () => {
codeNative.classList.toggle('active');
Native.addEventListener("click", () => {
codeNative.classList.toggle("active");
});
callback.addEventListener("click", () => {
codeCallback.classList.toggle("active");
});