Compare commits
49 Commits
635deb6878
...
master
Author | SHA1 | Date | |
---|---|---|---|
9ed0cb3124 | |||
5abd09f9d5 | |||
d5bbec2b7f | |||
49478b316c | |||
5c17582f43 | |||
92e1cfbe93 | |||
8fe132d7d1 | |||
6f4a7d23db | |||
75eed30d19 | |||
2f69e4fbbf | |||
913f9b1879 | |||
9b056cd0df | |||
a92ec260ac | |||
3c5be8445f | |||
da1a41daaa | |||
71df31eda9 | |||
37bb4d148b | |||
798024d05c | |||
f8e76ba5ec | |||
72fdcb6c0b | |||
b2c1abf54e | |||
e89a20593c | |||
570c7f5512 | |||
197a5f25c8 | |||
70fc08523e | |||
b0b02bc105 | |||
4df0bb1897 | |||
11473e288a | |||
3b56254919 | |||
136a6bc6e5 | |||
03269cc99f | |||
d8993da744 | |||
864783aaf8 | |||
0a44732782 | |||
970d84b131 | |||
6416a42781 | |||
0fff32cbed | |||
6cb388d959 | |||
815d92f71d | |||
c30b8faf09 | |||
2a53537df2 | |||
c25d983a02 | |||
fc67642d10 | |||
827b684fd3 | |||
fdb3c73588 | |||
22e9b7692c | |||
dafbe807da | |||
461578abe7 | |||
e1055e171a |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
.parcel-cache
|
.parcel-cache
|
||||||
|
test
|
||||||
|
|
||||||
|
30
CHANGELOG.md
30
CHANGELOG.md
@ -60,6 +60,34 @@ Tested in JS and React. Errors in work in React applications are revealed.
|
|||||||
- Fixed bugs.
|
- Fixed bugs.
|
||||||
- Changed structure.
|
- Changed structure.
|
||||||
|
|
||||||
### 00.03.2023 - update 0.2.6
|
### 01.03.2023 - update 0.2.6
|
||||||
|
|
||||||
- Added new theme creation mode.
|
- Added new theme creation mode.
|
||||||
|
|
||||||
|
### 01.03.2023 - update 0.2.7
|
||||||
|
|
||||||
|
- Switch to new webpack project builder.
|
||||||
|
|
||||||
|
##### 04.03.2023 - fix 0.2.71
|
||||||
|
|
||||||
|
- Select import fixed.
|
||||||
|
|
||||||
|
### 06.03.2023 - update 0.3.0
|
||||||
|
|
||||||
|
- Completely redesigned assembly to webpack and completed the transition to a new platform.
|
||||||
|
- Assembly bugs fixed
|
||||||
|
|
||||||
|
##### 04.03.2023 - fix 0.3.1
|
||||||
|
|
||||||
|
- Fixed import select.
|
||||||
|
|
||||||
|
##### 04.03.2023 - fix 0.3.12
|
||||||
|
|
||||||
|
- Optimized code.
|
||||||
|
- Added error messages when using public methods.
|
||||||
|
|
||||||
|
### 04.10.2023 - update 0.3.2
|
||||||
|
|
||||||
|
- Added the ability to set the name attribute for further sending data to the server. (\*nameSelect: string)
|
||||||
|
- Added a function to POST a request to the server when selecting an item. (\*getRequestUrl: string)
|
||||||
|
- Optimized code.
|
||||||
|
92
README.md
92
README.md
@ -1,8 +1,8 @@
|
|||||||
# CG-SELECT
|
# CG-SELECT
|
||||||
|
|
||||||
## version ~ 0.2.6
|
## version ~ 0.3.2
|
||||||
|
|
||||||
<a href="https://github.com/apuc/cg-select/blob/main/READMERU.md">ЧИТАТЬ НА РУССКОМ</a>
|
<a href="https://git.itguild.info/apuc/cg-select/src/branch/master/READMERU.md">ЧИТАТЬ НА РУССКОМ</a>
|
||||||
|
|
||||||
This component allows you to create a custom select. It offers more flexible customization and use of select.
|
This component allows you to create a custom select. It offers more flexible customization and use of select.
|
||||||
Customization, multi-selection and live search by elements are available.
|
Customization, multi-selection and live search by elements are available.
|
||||||
@ -19,10 +19,22 @@ Customization, multi-selection and live search by elements are available.
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
#### NPM
|
||||||
|
|
||||||
```
|
```
|
||||||
npm i cg-select
|
npm i cg-select
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### CDN
|
||||||
|
|
||||||
|
```
|
||||||
|
<script src="https://cdn.itguild.info/items/cg-select/latest/main.js"></script>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### PHP
|
||||||
|
|
||||||
|
Repository: <a href="https://git.itguild.info/apuc/php-cg-select-v2">PHP cg-select package integration</a>
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### To create a component, you need:
|
### To create a component, you need:
|
||||||
@ -67,6 +79,74 @@ const dropdown = new CGSelect({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### An example of initialization a CGSelect in React.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import CGSelect from 'cg-select';
|
||||||
|
|
||||||
|
const App = () => {
|
||||||
|
useEffect(() => {
|
||||||
|
const drop = new CGSelect({
|
||||||
|
selector: '.cg-dropdown_selector',
|
||||||
|
placeholder: 'Выберите авто',
|
||||||
|
items: [
|
||||||
|
'BMW',
|
||||||
|
{
|
||||||
|
id: '213sade',
|
||||||
|
title: 'Opel',
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
'Mersedes',
|
||||||
|
'MAN',
|
||||||
|
'Ferari',
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="App">
|
||||||
|
<button className="cg-dropdown cg-dropdown_selector"></button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### An example of initialization a CGSelect in Vue.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<button class="cg-dropdown cg-dropdown_selector"></button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import CGSelect from "cg-select";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
mounted() {
|
||||||
|
const drop = new CGSelect({
|
||||||
|
selector: ".cg-dropdown_selector",
|
||||||
|
placeholder: "Выберите авто",
|
||||||
|
items: [
|
||||||
|
"BMW",
|
||||||
|
{
|
||||||
|
id: "213sade",
|
||||||
|
title: "Opel",
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
"Mersedes",
|
||||||
|
"MAN",
|
||||||
|
"Ferari",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
console.log(drop);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
## Example of different selects
|
## Example of different selects
|
||||||
|
|
||||||
<a href="https://cg-select.itguild.info/">View live example</a>
|
<a href="https://cg-select.itguild.info/">View live example</a>
|
||||||
@ -87,13 +167,17 @@ All documentation on CG-SELECT is located in the folder of the same name. The do
|
|||||||
|
|
||||||
## Compatibility
|
## Compatibility
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| Application Compatibility | JS | React | Angular | Vue |
|
| Application Compatibility | JS | React | Angular | Vue |
|
||||||
| ------------------------- | :----------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------: | :---------------------------------------------------------------------: |
|
| ------------------------- | :----------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------: | :---------------------------------------------------------------------: |
|
||||||
| CG-SELECT |  |   |  |  |
|
| CG-SELECT | <img src="src/images/yes.png"></img> | <img src="src/images/yes.png"></img> | </img> <img src="src/images/no.png"></img> | </img> <img src="src/images/yes.png"></img> |
|
||||||
| Comment | Tested in Js applications and it works. | Works only with a crutch in the form `setTimeout()` | not yet available | not yet available |
|
| Comment | Tested in Js applications and it works. | The select is initiated inside the `useEffect() `hook | not yet available | The select is initiated inside the `mounted() `hook |
|
||||||
|
|
||||||
## History
|
## History
|
||||||
|
|
||||||
16.12.2022 - release version 0.1.0!
|
16.12.2022 - release version 0.1.0!
|
||||||
|
|
||||||
20.01.2023 - upgrade to version 0.2.1
|
20.01.2023 - upgrade to version 0.2.1
|
||||||
|
|
||||||
|
06.03.2023 - upgrade to version 0.3.0
|
||||||
|
90
READMERU.md
90
READMERU.md
@ -1,8 +1,8 @@
|
|||||||
# CG-SELECT
|
# CG-SELECT
|
||||||
|
|
||||||
## Версия ~ 0.2.6
|
## Версия ~ 0.3.2
|
||||||
|
|
||||||
<a href="https://github.com/apuc/cg-select/blob/main/README.md">English README</a>
|
<a href="https://git.itguild.info/apuc/cg-select/src/branch/master/README.md">English README</a>
|
||||||
|
|
||||||
Этот компонент позволяет вам создать пользовательский Select. Он предлагает более гибкую настройку и использование select.
|
Этот компонент позволяет вам создать пользовательский Select. Он предлагает более гибкую настройку и использование select.
|
||||||
Доступна кастомизация, multi-selection, живой поиск по элементам и многое другое.
|
Доступна кастомизация, multi-selection, живой поиск по элементам и многое другое.
|
||||||
@ -19,10 +19,22 @@
|
|||||||
|
|
||||||
## Установка
|
## Установка
|
||||||
|
|
||||||
|
#### NPM
|
||||||
|
|
||||||
```
|
```
|
||||||
npm i cg-select
|
npm i cg-select
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### CDN
|
||||||
|
|
||||||
|
```
|
||||||
|
<script src="https://cdn.itguild.info/items/cg-select/latest/main.js"></script>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### PHP
|
||||||
|
|
||||||
|
Репозиторий: <a href="https://git.itguild.info/apuc/php-cg-select-v2">Интеграция пакета cg-select для PHP</a>
|
||||||
|
|
||||||
## Использование
|
## Использование
|
||||||
|
|
||||||
### Для создания компонента необходимо:
|
### Для создания компонента необходимо:
|
||||||
@ -68,6 +80,74 @@ const dropdown = new CGSelect({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Пример инициализации CGSelect в React.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import CGSelect from 'cg-select';
|
||||||
|
|
||||||
|
const App = () => {
|
||||||
|
useEffect(() => {
|
||||||
|
const drop = new CGSelect({
|
||||||
|
selector: '.cg-dropdown_selector',
|
||||||
|
placeholder: 'Выберите авто',
|
||||||
|
items: [
|
||||||
|
'BMW',
|
||||||
|
{
|
||||||
|
id: '213sade',
|
||||||
|
title: 'Opel',
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
'Mersedes',
|
||||||
|
'MAN',
|
||||||
|
'Ferari',
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="App">
|
||||||
|
<button className="cg-dropdown cg-dropdown_selector"></button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### Пример инициализации CGSelect в Vue.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<button class="cg-dropdown cg-dropdown_selector"></button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import CGSelect from "cg-select";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
mounted() {
|
||||||
|
const drop = new CGSelect({
|
||||||
|
selector: ".cg-dropdown_selector",
|
||||||
|
placeholder: "Выберите авто",
|
||||||
|
items: [
|
||||||
|
"BMW",
|
||||||
|
{
|
||||||
|
id: "213sade",
|
||||||
|
title: "Opel",
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
"Mersedes",
|
||||||
|
"MAN",
|
||||||
|
"Ferari",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
console.log(drop);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
## Примеры различных вариантов выбора.
|
## Примеры различных вариантов выбора.
|
||||||
|
|
||||||
<a href="https://cg-select.itguild.info/">Рабочий пример</a>
|
<a href="https://cg-select.itguild.info/">Рабочий пример</a>
|
||||||
@ -88,11 +168,13 @@ const dropdown = new CGSelect({
|
|||||||
|
|
||||||
| Совместимость в приложениях | JS | React | Angular | Vue |
|
| Совместимость в приложениях | JS | React | Angular | Vue |
|
||||||
| --------------------------- | :----------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------: | :---------------------------------------------------------------------: |
|
| --------------------------- | :----------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------: | :---------------------------------------------------------------------: |
|
||||||
| CG-SELECT |  |   |  |  |
|
| CG-SELECT | <img src="src/images/yes.png"></img> | <img src="src/images/yes.png"></img> | <img src="src/images/no.png"></img> | <img src="src/images/yes.png"></img> |
|
||||||
| Комментарий | Протестировано в Js приложениях | Работает только с костылем в виде `setTimeout()` | пока недоступно | пока недоступно |
|
| Комментарий | Протестировано в Js приложениях | Инициация селекта происходит внутри хука `useEffect()` | пока недоступно | Инициация селекта происходит внутри хука `mounted()` |
|
||||||
|
|
||||||
## История
|
## История
|
||||||
|
|
||||||
16.12.2022 - release version 0.1.0!
|
16.12.2022 - release version 0.1.0!
|
||||||
|
|
||||||
20.01.2023 - upgrade to version 0.2.1
|
20.01.2023 - upgrade to version 0.2.1
|
||||||
|
|
||||||
|
06.03.2023 - upgrade to version 0.3.0
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="#version--0231" id="version--0231" style="color: inherit; text-decoration: none">
|
<a href="#version--0231" id="version--0231" style="color: inherit; text-decoration: none">
|
||||||
<h2>version ~ 0.2.6</h2>
|
<h2>version ~ 0.3.12</h2>
|
||||||
</a>
|
</a>
|
||||||
<p>
|
<p>
|
||||||
This component allows you to create a custom select. It offers more flexible
|
This component allows you to create a custom select. It offers more flexible
|
||||||
|
2
index.js
2
index.js
@ -1,3 +1,3 @@
|
|||||||
import { CGSelect } from './src/cg-select';
|
import CGSelect from './src/cg-select';
|
||||||
|
|
||||||
export default CGSelect;
|
export default CGSelect;
|
||||||
|
13622
package-lock.json
generated
13622
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
39
package.json
39
package.json
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "cg-select",
|
"name": "cg-select",
|
||||||
"version": "0.2.6",
|
"version": "0.3.2",
|
||||||
"source": "index.js",
|
"source": "index.js",
|
||||||
"main": "dist/index.js",
|
"main": "dist/main.js",
|
||||||
"description": "Feature rich Select control for React/JS with multiselect, autocomplete and styling",
|
"description": "Feature rich Select control for React/JS with multiselect, autocomplete and styling",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "CraftGroup",
|
"name": "CraftGroup",
|
||||||
@ -10,10 +10,9 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://cg-select.itguild.info",
|
"homepage": "https://cg-select.itguild.info",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"watch": "parcel watch",
|
"start": "npx webpack-dev-server --mode development",
|
||||||
"build": "parcel build",
|
"dev": "npx webpack --mode development",
|
||||||
"deploy": "gh-pages -d dist",
|
"build": "npx webpack --mode production"
|
||||||
"predeploy": "npm run build"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -24,17 +23,25 @@
|
|||||||
"url": "https://github.com/apuc/cg-select/issues"
|
"url": "https://github.com/apuc/cg-select/issues"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@parcel/transformer-sass": "^2.7.0",
|
"@babel/core": "^7.21.4",
|
||||||
"jsdoc": "^4.0.0",
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
||||||
"parcel": "^2.7.0",
|
"@babel/preset-env": "^7.21.4",
|
||||||
"prettier": "^2.7.1"
|
"@babel/preset-typescript": "^7.21.4",
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@parcel/optimizer-css": "^2.8.0",
|
|
||||||
"@types/prettier": "^2.7.2",
|
"@types/prettier": "^2.7.2",
|
||||||
"gh-pages": "^4.0.0",
|
"babel-loader": "^9.1.2",
|
||||||
"typedoc": "^0.23.24",
|
"css-loader": "^6.7.3",
|
||||||
"typescript": "^4.9.4"
|
"html-webpack-plugin": "^5.5.0",
|
||||||
|
"jsdoc": "^4.0.0",
|
||||||
|
"prettier": "^2.7.1",
|
||||||
|
"sass": "^1.60.0",
|
||||||
|
"sass-loader": "^13.2.2",
|
||||||
|
"style-loader": "^3.3.2",
|
||||||
|
"ts-loader": "^9.4.2",
|
||||||
|
"typedoc": "^0.23.28",
|
||||||
|
"typescript": "^5.0.2",
|
||||||
|
"webpack": "^5.77.0",
|
||||||
|
"webpack-cli": "^5.1.4",
|
||||||
|
"webpack-dev-server": "^4.13.2"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"select",
|
"select",
|
||||||
|
104
src/cg-select.ts
104
src/cg-select.ts
@ -32,7 +32,7 @@ import { CustomTheme, CustomThemeJson } from 'components/theme/theme.interface';
|
|||||||
* @description This class implements the functionality of a custom select, with customization capabilities.
|
* @description This class implements the functionality of a custom select, with customization capabilities.
|
||||||
* @author Ovsyanikov Maxim
|
* @author Ovsyanikov Maxim
|
||||||
*/
|
*/
|
||||||
export class CGSelect implements ICgSelect {
|
export default class CGSelect implements ICgSelect {
|
||||||
selector?: string;
|
selector?: string;
|
||||||
selected?: string;
|
selected?: string;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
@ -46,6 +46,8 @@ export class CGSelect implements ICgSelect {
|
|||||||
label?: string;
|
label?: string;
|
||||||
styles?: IStyle;
|
styles?: IStyle;
|
||||||
event?: string;
|
event?: string;
|
||||||
|
nameSelect?: string;
|
||||||
|
getRequestUrl?: string;
|
||||||
url?: string;
|
url?: string;
|
||||||
multiselect?: boolean;
|
multiselect?: boolean;
|
||||||
multiselectTag?: boolean;
|
multiselectTag?: boolean;
|
||||||
@ -95,6 +97,11 @@ export class CGSelect implements ICgSelect {
|
|||||||
* @type {Element | null}
|
* @type {Element | null}
|
||||||
*/
|
*/
|
||||||
private buttonAction?: Element | null;
|
private buttonAction?: Element | null;
|
||||||
|
/**
|
||||||
|
* Array for request
|
||||||
|
* @type {IItems}
|
||||||
|
*/
|
||||||
|
private forUrlSelectedItems: IItems[] = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ICgSelect} setting Object accepting select settings.
|
* @param {ICgSelect} setting Object accepting select settings.
|
||||||
@ -113,6 +120,8 @@ export class CGSelect implements ICgSelect {
|
|||||||
nativeSelectMode: true/false,
|
nativeSelectMode: true/false,
|
||||||
listDisplayMode: true/false,
|
listDisplayMode: true/false,
|
||||||
language: 'ru/en',
|
language: 'ru/en',
|
||||||
|
nameSelect: "titleYouSelect";
|
||||||
|
getRequestUrl: "/endpoint/123";
|
||||||
styles: {
|
styles: {
|
||||||
head: {
|
head: {
|
||||||
background: '...',
|
background: '...',
|
||||||
@ -130,10 +139,14 @@ export class CGSelect implements ICgSelect {
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
constructor(setting: ICgSelect) {
|
constructor(setting: ICgSelect) {
|
||||||
this.init(setting);
|
if (setting) {
|
||||||
this.render();
|
this.init(setting);
|
||||||
this.closeSelectClick();
|
this.render();
|
||||||
this.initEvent();
|
this.closeSelectClick();
|
||||||
|
this.initEvent();
|
||||||
|
} else {
|
||||||
|
throw new Error('Specify settings!');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Getters
|
//Getters
|
||||||
@ -193,6 +206,8 @@ export class CGSelect implements ICgSelect {
|
|||||||
styles,
|
styles,
|
||||||
label,
|
label,
|
||||||
event,
|
event,
|
||||||
|
nameSelect,
|
||||||
|
getRequestUrl,
|
||||||
selected,
|
selected,
|
||||||
placeholder,
|
placeholder,
|
||||||
theme,
|
theme,
|
||||||
@ -212,6 +227,8 @@ export class CGSelect implements ICgSelect {
|
|||||||
this.styles = styles;
|
this.styles = styles;
|
||||||
this.label = label;
|
this.label = label;
|
||||||
this.event = event;
|
this.event = event;
|
||||||
|
this.nameSelect = nameSelect;
|
||||||
|
this.getRequestUrl = getRequestUrl;
|
||||||
this.selected = selected;
|
this.selected = selected;
|
||||||
this.placeholder = placeholder;
|
this.placeholder = placeholder;
|
||||||
this.theme = theme;
|
this.theme = theme;
|
||||||
@ -279,7 +296,7 @@ export class CGSelect implements ICgSelect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ulList = document.createElement('ul');
|
const ulList = document.createElement('ul');
|
||||||
const nativeSelect = createNativeSelect();
|
const nativeSelect = createNativeSelect(this.nameSelect);
|
||||||
|
|
||||||
let inputSearch: HTMLInputElement;
|
let inputSearch: HTMLInputElement;
|
||||||
let textNode: Text;
|
let textNode: Text;
|
||||||
@ -380,7 +397,7 @@ export class CGSelect implements ICgSelect {
|
|||||||
const response = await fetch(this.url!);
|
const response = await fetch(this.url!);
|
||||||
const dataUrl = await response.json();
|
const dataUrl = await response.json();
|
||||||
|
|
||||||
const nativeSelect = createNativeSelect();
|
const nativeSelect = createNativeSelect(this.nameSelect!);
|
||||||
|
|
||||||
dataUrl.forEach((dataItem: IItems, index: number) => {
|
dataUrl.forEach((dataItem: IItems, index: number) => {
|
||||||
const item = {
|
const item = {
|
||||||
@ -609,6 +626,17 @@ export class CGSelect implements ICgSelect {
|
|||||||
select!.innerText = this.selectedItems.join(',');
|
select!.innerText = this.selectedItems.join(',');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.getRequestUrl!) {
|
||||||
|
this.forUrlSelectedItems.push(item);
|
||||||
|
fetch(this.getRequestUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json;charset=utf-8',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(this.forUrlSelectedItems),
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.multiselectTag) {
|
if (this.multiselectTag) {
|
||||||
const tagItem = document.getElementById(`tag-${index}-${item.id}`);
|
const tagItem = document.getElementById(`tag-${index}-${item.id}`);
|
||||||
@ -618,6 +646,17 @@ export class CGSelect implements ICgSelect {
|
|||||||
if (Array.isArray(this.selectedItems)) {
|
if (Array.isArray(this.selectedItems)) {
|
||||||
this.selectedItems.splice(checkIndex, 1);
|
this.selectedItems.splice(checkIndex, 1);
|
||||||
this.indexes.splice(checkIndex, 1);
|
this.indexes.splice(checkIndex, 1);
|
||||||
|
|
||||||
|
if (this.getRequestUrl! && this.forUrlSelectedItems.length > 0) {
|
||||||
|
this.forUrlSelectedItems.splice(checkIndex, 1);
|
||||||
|
fetch(this.getRequestUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json;charset=utf-8',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(this.forUrlSelectedItems),
|
||||||
|
});
|
||||||
|
}
|
||||||
nativeOptionMultiple(nativeOption, item.title, false);
|
nativeOptionMultiple(nativeOption, item.title, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -644,6 +683,16 @@ export class CGSelect implements ICgSelect {
|
|||||||
option.classList.remove('active');
|
option.classList.remove('active');
|
||||||
});
|
});
|
||||||
option.classList.add('active');
|
option.classList.add('active');
|
||||||
|
|
||||||
|
if (this.getRequestUrl!) {
|
||||||
|
fetch(this.getRequestUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json;charset=utf-8',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(item),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearSelect(select!, this.element!, selectedItemsClear);
|
clearSelect(select!, this.element!, selectedItemsClear);
|
||||||
@ -660,7 +709,7 @@ export class CGSelect implements ICgSelect {
|
|||||||
private selectMode(nativeSelectMode: boolean) {
|
private selectMode(nativeSelectMode: boolean) {
|
||||||
let win = window.outerWidth;
|
let win = window.outerWidth;
|
||||||
|
|
||||||
if (nativeSelectMode === true) {
|
if (nativeSelectMode) {
|
||||||
const select = this.element!.querySelector('.cg-select');
|
const select = this.element!.querySelector('.cg-select');
|
||||||
const list = this.element!.querySelector('.list');
|
const list = this.element!.querySelector('.list');
|
||||||
const nativeSelect = this.element!.querySelector('.nativeSelect');
|
const nativeSelect = this.element!.querySelector('.nativeSelect');
|
||||||
@ -792,11 +841,12 @@ export class CGSelect implements ICgSelect {
|
|||||||
const textNoRezult = this.element!.querySelector('.noRezult');
|
const textNoRezult = this.element!.querySelector('.noRezult');
|
||||||
const textNode = document.createTextNode(textInListSearch);
|
const textNode = document.createTextNode(textInListSearch);
|
||||||
|
|
||||||
search!.setAttribute('placeholder', placeholder);
|
|
||||||
search!.setAttribute('placeholder', placeholder);
|
search!.setAttribute('placeholder', placeholder);
|
||||||
|
|
||||||
textNoRezult!.textContent = '';
|
textNoRezult!.textContent = '';
|
||||||
textNoRezult!.appendChild(textNode);
|
textNoRezult!.appendChild(textNode);
|
||||||
|
} else {
|
||||||
|
throw new Error('You cannot change the language if it is not enabled searchMode!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -807,20 +857,21 @@ export class CGSelect implements ICgSelect {
|
|||||||
* @method buttonControl
|
* @method buttonControl
|
||||||
*/
|
*/
|
||||||
public buttonControl(button: Element, method: string) {
|
public buttonControl(button: Element, method: string) {
|
||||||
if (this.listDisplayMode) {
|
if (!this.listDisplayMode) {
|
||||||
return;
|
this.buttonAction = button!;
|
||||||
|
button.addEventListener('click', () => {
|
||||||
|
switch (method.toLowerCase()) {
|
||||||
|
case 'open':
|
||||||
|
this.open(true);
|
||||||
|
break;
|
||||||
|
case 'close':
|
||||||
|
this.close();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw new Error('Sheet display enabled in listDisplayMode!');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.buttonAction = button!;
|
|
||||||
button.addEventListener('click', () => {
|
|
||||||
if (method.toLowerCase() === 'open') {
|
|
||||||
this.open(true);
|
|
||||||
} else if (method.toLowerCase() === 'close') {
|
|
||||||
this.close();
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -832,7 +883,7 @@ export class CGSelect implements ICgSelect {
|
|||||||
const select = this.element!.querySelector('.cg-select');
|
const select = this.element!.querySelector('.cg-select');
|
||||||
const nativeSelect = this.element!.querySelector('.nativeSelect');
|
const nativeSelect = this.element!.querySelector('.nativeSelect');
|
||||||
|
|
||||||
if (value === true) {
|
if (value) {
|
||||||
this.element!.setAttribute('disabled', 'true');
|
this.element!.setAttribute('disabled', 'true');
|
||||||
nativeSelect!.setAttribute('disabled', 'true');
|
nativeSelect!.setAttribute('disabled', 'true');
|
||||||
select!.classList.add('disabled');
|
select!.classList.add('disabled');
|
||||||
@ -871,10 +922,8 @@ export class CGSelect implements ICgSelect {
|
|||||||
*/
|
*/
|
||||||
public deleteItem(index: number) {
|
public deleteItem(index: number) {
|
||||||
if (this.category) {
|
if (this.category) {
|
||||||
console.log('can`t add item to category');
|
throw new Error('Unable to remove item from category!');
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const item = this.items[index];
|
const item = this.items[index];
|
||||||
|
|
||||||
this.items.splice(index, 1);
|
this.items.splice(index, 1);
|
||||||
@ -897,8 +946,7 @@ export class CGSelect implements ICgSelect {
|
|||||||
*/
|
*/
|
||||||
public selectIndex(index: number) {
|
public selectIndex(index: number) {
|
||||||
if (this.category) {
|
if (this.category) {
|
||||||
console.log('can`t add item to category');
|
throw new Error('Unable to select item from category!');
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = this.element!.querySelectorAll('.list__item') as NodeListOf<HTMLElement>;
|
const options = this.element!.querySelectorAll('.list__item') as NodeListOf<HTMLElement>;
|
||||||
|
@ -5,10 +5,14 @@ import { ICreateBreadCrumb } from './create-element.interface';
|
|||||||
* The method that creates the native select.
|
* The method that creates the native select.
|
||||||
* @returns {HTMLSelectElement} Returns the created native select.
|
* @returns {HTMLSelectElement} Returns the created native select.
|
||||||
*/
|
*/
|
||||||
export function createNativeSelect(): HTMLSelectElement {
|
export function createNativeSelect(nameSelect: string | undefined): HTMLSelectElement {
|
||||||
const nativeSelect = document.createElement('select');
|
const nativeSelect = document.createElement('select');
|
||||||
|
|
||||||
nativeSelect.setAttribute('name', 'dataSelect');
|
if (nameSelect == undefined) {
|
||||||
|
nativeSelect.setAttribute('name', 'CgSelect');
|
||||||
|
} else {
|
||||||
|
nativeSelect.setAttribute('name', nameSelect!);
|
||||||
|
}
|
||||||
nativeSelect.classList.add('nativeSelect');
|
nativeSelect.classList.add('nativeSelect');
|
||||||
return nativeSelect;
|
return nativeSelect;
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,18 @@ export interface ICgSelect {
|
|||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
event?: string;
|
event?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional parameter responsible for the native select attribute.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
nameSelect?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional parameter responsible for the sending address when selected in the select.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
getRequestUrl?: string;
|
||||||
/**
|
/**
|
||||||
* Required parameter (if no other way to get data (items) is specified),
|
* Required parameter (if no other way to get data (items) is specified),
|
||||||
* data that comes from the backend in the format { id: "", title: "", value: ""}.
|
* data that comes from the backend in the format { id: "", title: "", value: ""}.
|
||||||
|
@ -6,18 +6,14 @@
|
|||||||
/* Modules */
|
/* Modules */
|
||||||
"module": "commonjs" /* Specify what module code is generated. */,
|
"module": "commonjs" /* Specify what module code is generated. */,
|
||||||
"rootDir": "./" /* Specify the root folder within your source files. */,
|
"rootDir": "./" /* Specify the root folder within your source files. */,
|
||||||
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
||||||
"baseUrl": "./src" /* Specify the base directory to resolve non-relative module names. */,
|
"baseUrl": "./src" /* Specify the base directory to resolve non-relative module names. */,
|
||||||
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
|
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
|
||||||
"allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */,
|
"allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */,
|
||||||
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
||||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||||
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
||||||
|
"moduleResolution": "node",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
|
|
||||||
/* Completeness */
|
|
||||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
||||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
50
webpack.config.js
Normal file
50
webpack.config.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
const path = require('path');
|
||||||
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: './index.js',
|
||||||
|
output: {
|
||||||
|
path: path.resolve(__dirname, 'dist'),
|
||||||
|
filename: 'main.js',
|
||||||
|
clean: true,
|
||||||
|
library: 'CGSelect',
|
||||||
|
libraryTarget: 'umd',
|
||||||
|
},
|
||||||
|
// devServer: {
|
||||||
|
// open: true,
|
||||||
|
// port: 5500,
|
||||||
|
// },
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.tsx?$/,
|
||||||
|
use: 'ts-loader',
|
||||||
|
exclude: /node_modules/,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.s[ac]ss$/i,
|
||||||
|
use: ['style-loader', 'css-loader', 'sass-loader'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.(?:js|mjs|cjs)$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
use: {
|
||||||
|
loader: 'babel-loader',
|
||||||
|
options: {
|
||||||
|
presets: [['@babel/preset-env', { targets: 'defaults' }]],
|
||||||
|
plugins: ['@babel/plugin-proposal-class-properties'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
extensions: ['.tsx', '.ts', '.js'],
|
||||||
|
},
|
||||||
|
// plugins: [
|
||||||
|
// new HtmlWebpackPlugin({
|
||||||
|
// template: path.resolve(__dirname, './test/index.html'),
|
||||||
|
// filename: 'index.html',
|
||||||
|
// }),
|
||||||
|
// ],
|
||||||
|
};
|
Reference in New Issue
Block a user