-
Функция disabled
+
Function disabled
-
Вы согласны на обработку данных
+
+ You agree to the processing of data
-
Посмотреть код
+
View code
const dropdown = new CGSelect ({
selector: '.cg-dropdown_checkboxDisable',
- placeholder: 'Выберите авто',
+ placeholder: 'Choose a car',
searchMode: true,
items: [
'BMW',
@@ -349,6 +352,7 @@
maxWidth: '500px ',
},
},
+ multiselect: true,
});
diff --git a/example/index.js b/example/index.js
index bab818b..c4a86d0 100644
--- a/example/index.js
+++ b/example/index.js
@@ -4,8 +4,8 @@ import './example';
// ------------------------------Обычный селект--------------------
const dropdown = new CGSelect({
selector: '.cg-dropdown_one',
- placeholder: 'Выберите авто',
- lable: 'EXAMPLE',
+ placeholder: 'Choose a car',
+ label: 'EXAMPLE',
items: [
'BMW',
{
@@ -25,17 +25,16 @@ const dropdown = new CGSelect({
width: '824px',
},
},
- // multiselect: true,
});
-// dropdown.on('select', function (e) {
-// console.log(`this state: ${e}`);
-// });
+dropdown.on('clear', function (e) {
+ console.log(`this state: ${e}`);
+});
// ------------------------------NativeSelect-----------------------
const dropdownNativeSelect = new CGSelect({
selector: '.cg-dropdown_selectNative',
- placeholder: 'Выберите авто',
+ placeholder: 'Choose a car',
nativeSelectMode: true,
items: [
'BMW',
@@ -58,12 +57,13 @@ const dropdownNativeSelect = new CGSelect({
width: '824px',
},
},
+ theme: 'dark',
});
// ------------------------------listDisplayMode--------------------
const dropdownlistDisplayMode = new CGSelect({
selector: '.cg-dropdown_listDisplayMode',
- placeholder: 'Выберите авто',
+ placeholder: 'Choose a car',
listDisplayMode: true,
items: [
'BMW',
@@ -89,7 +89,7 @@ const dropdownlistDisplayMode = new CGSelect({
// --------------------------------Категории--------------------------
const dropdown4 = new CGSelect({
selector: '.cg-dropdown_categories',
- placeholder: 'Выберите регион',
+ placeholder: 'Choose region',
searchMode: true,
items: [
{
@@ -134,7 +134,7 @@ const dropdown4 = new CGSelect({
//----------------управление с помощью кнопок----------------------------------
const dropdownBtn = new CGSelect({
selector: '.cg-dropdown_usedBtn',
- placeholder: 'Выберите авто',
+ placeholder: 'Choose a car',
searchMode: true,
items: [
'BMW',
@@ -181,7 +181,7 @@ dropdownBtn.buttonControl(buttonClose, 'close');
//-------------------------Функция Disabled----------------------------------
const dropdownDisabled = new CGSelect({
selector: '.cg-dropdown_checkboxDisable',
- placeholder: 'Выберите авто',
+ placeholder: 'Choose a car',
searchMode: true,
items: [
'BMW',
diff --git a/index.js b/index.js
index d3c8b2f..cae98de 100644
--- a/index.js
+++ b/index.js
@@ -1,3 +1,3 @@
-import { CGSelect } from './src/cg-select';
+import { CGSelect } from './src/cg-select.ts';
export default CGSelect;
diff --git a/package-lock.json b/package-lock.json
index 4e802d2..1665717 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "cg-select",
- "version": "0.2.31",
+ "version": "0.2.32",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "cg-select",
- "version": "0.2.31",
+ "version": "0.2.32",
"license": "ISC",
"dependencies": {
"@parcel/optimizer-css": "^2.8.0",
diff --git a/package.json b/package.json
index db6d8d1..648f3b4 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "cg-select",
- "version": "0.2.31",
+ "version": "0.2.32",
"description": "Feature rich Select control for React/JS with multiselect, autocomplete and styling",
"author": {
"name": "CraftGroup",
diff --git a/src/cg-select.ts b/src/cg-select.ts
index c0c567e..d760654 100644
--- a/src/cg-select.ts
+++ b/src/cg-select.ts
@@ -16,7 +16,7 @@ import {
nativeOptionMultiple,
nativeOptionOrdinary,
} from './components/utils/utils';
-import { IDataItem, ISelectedItems } from './components/utils/urils.interface';
+import { IDataItem, ISelectedItems } from './components/utils/utils.interface';
import { ICgSelect, IStyle } from './interfaces/cg-select.interface';
import { IItems } from './interfaces/items.interface';
@@ -32,7 +32,6 @@ import { changeTheme } from './components/theme/theme';
* @author Ovsyanikov Maxim
*/
export class CGSelect implements ICgSelect {
- // Select settings
selector?: string;
selected?: string;
placeholder?: string;
@@ -43,7 +42,7 @@ export class CGSelect implements ICgSelect {
nativeSelectMode?: boolean;
listDisplayMode?: boolean;
language?: string;
- lable?: string;
+ label?: string;
styles?: IStyle;
event?: string;
url?: string;
@@ -74,7 +73,7 @@ export class CGSelect implements ICgSelect {
* Variable for carriage control.
* @type {Element | null | undefined}
*/
- private caret: Element | null | undefined;
+ private carriage: Element | null | undefined;
/**
* Transferred categories.
* @type {string}
@@ -94,7 +93,7 @@ export class CGSelect implements ICgSelect {
* Button, to control the select.
* @type {Element | null}
*/
- private btnCntr?: Element | null;
+ private buttonAction?: Element | null;
/**
* @param {ICgSelect} setting Object accepting select settings.
@@ -105,7 +104,7 @@ export class CGSelect implements ICgSelect {
* selector: 'Unique selector',
selected: 'Selected item',
placeholder: '...',
- lable: '...'
+ label: '...'
items: [string|number|object],
theme: string,
searchMode: true/false,
@@ -119,9 +118,9 @@ export class CGSelect implements ICgSelect {
},
list: {...},
chips: {...},
- caret: {...},
+ carriage: {...},
placeholder: {...},
- lable: {..},
+ label: {..},
},
event: '...',
url: 'http/...',
@@ -191,7 +190,7 @@ export class CGSelect implements ICgSelect {
searchMode,
language,
styles,
- lable,
+ label,
event,
selected,
placeholder,
@@ -210,7 +209,7 @@ export class CGSelect implements ICgSelect {
this.nativeSelectMode = nativeSelectMode;
this.listDisplayMode = listDisplayMode;
this.styles = styles;
- this.lable = lable;
+ this.label = label;
this.event = event;
this.selected = selected;
this.placeholder = placeholder;
@@ -231,14 +230,14 @@ export class CGSelect implements ICgSelect {
return;
}
- if (this.lable) {
- const lableItem = document.createElement('h1');
- const textLable = document.createTextNode(this.lable);
+ if (this.label) {
+ const labelItem = document.createElement('h1');
+ const textLabel = document.createTextNode(this.label);
- lableItem.appendChild(textLable);
- lableItem.classList.add('label');
+ labelItem.appendChild(textLabel);
+ labelItem.classList.add('label');
- this.element!.insertAdjacentElement('beforebegin', lableItem);
+ this.element!.insertAdjacentElement('beforebegin', labelItem);
}
items.forEach((dataItem: any, index: number) => {
@@ -354,7 +353,7 @@ export class CGSelect implements ICgSelect {
});
this.list = this.element!.querySelector('.list');
- this.caret = this.element!.querySelector('.caret');
+ this.carriage = this.element!.querySelector('.caret');
if (this.theme) {
changeTheme(this.element!, this.theme!);
@@ -466,10 +465,6 @@ export class CGSelect implements ICgSelect {
* @method initEvent
*/
private initEvent() {
- if (!this.event) {
- return;
- }
-
if (this.event) {
if (this.event === 'mouseenter') {
this.element!.addEventListener(this.event, () => {
@@ -491,10 +486,10 @@ export class CGSelect implements ICgSelect {
private open(oneClick?: boolean): void {
if (oneClick === true) {
this.list!.classList.add('open');
- this.caret!.classList.add('caret_rotate');
+ this.carriage!.classList.add('caret_rotate');
} else {
this.list!.classList.toggle('open');
- this.caret!.classList.toggle('caret_rotate');
+ this.carriage!.classList.toggle('caret_rotate');
}
}
@@ -505,7 +500,7 @@ export class CGSelect implements ICgSelect {
*/
private close(): void {
this.list?.classList.remove('open');
- this.caret?.classList.remove('caret_rotate');
+ this.carriage?.classList.remove('caret_rotate');
}
/**
@@ -519,7 +514,7 @@ export class CGSelect implements ICgSelect {
document.addEventListener('click', (e) => {
const withinBoundaries = e.composedPath().includes(dropdown!);
if (!withinBoundaries) {
- if (this.btnCntr) {
+ if (this.buttonAction) {
return;
} else {
this.close();
@@ -771,7 +766,7 @@ export class CGSelect implements ICgSelect {
* @returns {HTMLElement} returns a reference to the selected HTML element.
* @method getElement
*/
- public getElement(numberItem: number): IItems[] | string[] | any {
+ public getElement(numberItem: number): IItems[] | any {
if (numberItem > this.items.length) {
return;
}
@@ -815,7 +810,7 @@ export class CGSelect implements ICgSelect {
return;
}
- this.btnCntr = button!;
+ this.buttonAction = button!;
button.addEventListener('click', () => {
if (method.toLowerCase() === 'open') {
this.open(true);
@@ -945,6 +940,15 @@ export class CGSelect implements ICgSelect {
});
callback(state);
break;
+ case 'clear':
+ this.element!.addEventListener('click', () => {
+ const svgIcon = this.element?.querySelector('.svg-icon');
+ svgIcon?.addEventListener('click', () => {
+ console.log('list:clear', svgIcon.classList.contains('svg-clear'));
+ });
+ });
+ callback(state);
+ break;
}
}
}
diff --git a/src/components/theme/theme.ts b/src/components/theme/theme.ts
index 6904a94..cf2e58b 100644
--- a/src/components/theme/theme.ts
+++ b/src/components/theme/theme.ts
@@ -4,27 +4,31 @@ export function changeTheme(element: Element, theme: string) {
const list = element!.querySelector('ul.list');
const search = element!.querySelector('.inputSearch');
const path = element.querySelectorAll('.pathWhite');
+ const nativeSelect = element.querySelector('.nativeSelect');
- switch (theme) {
+ select!.classList.remove('classicSelect');
+ list!.classList.remove('classicList');
+ path.forEach((elem) => {
+ elem.classList.remove('pathBlack');
+ elem.classList.remove('pathWhite');
+ });
+
+ switch (theme.toLowerCase()) {
case 'dark':
- select!.classList.remove('classicSelect');
select!.classList.add('selectDark');
list!.classList.add('listDark');
- list!.classList.remove('classicList');
+ nativeSelect?.classList.add('listDark');
path.forEach((elem) => {
- elem.classList.remove('pathBlack');
elem.classList.add('pathWhite');
});
break;
case 'white':
- select!.classList.remove('classicSelect');
select!.classList.add('selectWhite');
caret!.classList.add('caretWhite');
list!.classList.add('listWhite');
- list!.classList.remove('classicList');
+ nativeSelect?.classList.add('listWhite');
path.forEach((elem) => {
elem.classList.add('pathBlack');
- elem.classList.remove('pathWhite');
});
if (search!) {
diff --git a/src/components/utils/urils.interface.ts b/src/components/utils/utils.interface.ts
similarity index 100%
rename from src/components/utils/urils.interface.ts
rename to src/components/utils/utils.interface.ts
diff --git a/src/components/utils/utils.ts b/src/components/utils/utils.ts
index b98cc95..ab6780a 100644
--- a/src/components/utils/utils.ts
+++ b/src/components/utils/utils.ts
@@ -4,7 +4,7 @@
*/
import { IStyle } from 'interfaces/cg-select.interface';
import { IItems } from 'interfaces/items.interface';
-import { ISelectedItems } from './urils.interface';
+import { ISelectedItems } from './utils.interface';
/**
* Converting each item obtained from the Items field;
@@ -143,7 +143,9 @@ export function clearSelect(select: HTMLElement, element: Element, dataSelectTex
select!.appendChild(svgIcon);
- svgIcon.addEventListener('click', () => {
+ svgIcon.addEventListener('click', (e) => {
+ e.preventDefault();
+ e.stopPropagation();
select!.innerText = '';
nativeOption.forEach((option) => {
diff --git a/src/images/logoCG2.ico b/src/images/logoCG2.ico
new file mode 100644
index 0000000..7c73de7
Binary files /dev/null and b/src/images/logoCG2.ico differ
diff --git a/src/interfaces/cg-select.interface.ts b/src/interfaces/cg-select.interface.ts
index 0e68c24..403b1a6 100644
--- a/src/interfaces/cg-select.interface.ts
+++ b/src/interfaces/cg-select.interface.ts
@@ -27,7 +27,7 @@ export interface ICgSelect {
items?: IItems[] | string[] | any;
/**
* An optional parameter responsible for switching between different themes, the classic theme is set by default.
- * @type {string}
+ * @type {string} values: dark, white
*/
theme?: string;
/**
@@ -61,7 +61,7 @@ export interface ICgSelect {
* An optional parameter that adds a lable before the select.
* @type {string}
*/
- lable?: string;
+ label?: string;
/**
* An optional parameter that is responsible for customizing the select elements,
* objects with CSS properties for customizable elements are passed to it.