cg-select/README.md

180 lines
5.3 KiB
Markdown
Raw Normal View History

2022-11-14 12:23:18 +03:00
# CG-SELECT
2022-10-13 14:11:52 +03:00
2023-04-24 20:24:32 +03:00
## version ~ 0.3.12
2022-11-09 15:37:42 +03:00
2023-04-20 12:26:06 +03:00
<a href="https://git.itguild.info/apuc/cg-select/src/branch/master/READMERU.md">ЧИТАТЬ НА РУССКОМ</a>
2023-03-20 20:25:14 +03:00
2023-01-19 19:41:04 +03:00
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.
2022-11-09 15:35:15 +03:00
2023-01-19 19:41:04 +03:00
### The ability to customize basic elements, such as:
2022-11-14 12:23:18 +03:00
2023-01-19 19:41:04 +03:00
- Select button.
- List with select elements.
2022-11-14 12:23:18 +03:00
- Placeholder.
2023-01-19 19:41:04 +03:00
- In the multiselect mode, customization of chips (selected elements) is available.
- Label of the element (if it was specified).
- Switch themes from dark to light.
2023-02-09 16:47:55 +03:00
- The documentation also lists all the elements for catatomization using CSS.
2022-11-09 15:35:15 +03:00
2022-10-26 15:34:40 +03:00
## Installation
2022-11-14 12:23:18 +03:00
2023-04-17 17:09:57 +03:00
#### NPM
2022-12-20 20:11:58 +03:00
```
2022-12-20 20:08:47 +03:00
npm i cg-select
2022-12-20 20:11:58 +03:00
```
2022-11-14 12:23:18 +03:00
2023-04-17 17:09:57 +03:00
#### CDN
```
<script src="https://cdn.itguild.info/items/cg-select/latest/main.js"></script>
```
2022-10-26 15:34:40 +03:00
## Usage
2022-11-14 12:23:18 +03:00
2023-01-19 19:41:04 +03:00
### To create a component, you need:
2022-11-09 15:35:15 +03:00
2023-01-19 19:41:04 +03:00
1. Create a regular button element.
2. Give it the cg-dropdown class.
2022-11-14 12:23:18 +03:00
2022-11-09 15:35:15 +03:00
```
<button class="cg-dropdown"></button>
```
2022-11-14 12:23:18 +03:00
2023-01-19 19:41:04 +03:00
3. Give it a **unique class**, e.g. (cg-dropdown_categories).
2022-11-14 12:23:18 +03:00
2022-11-09 15:35:15 +03:00
```
<button class="cg-dropdown cg-dropdown_categories"></button>
```
2022-11-14 12:23:18 +03:00
2023-01-19 19:41:04 +03:00
4. Create a new instance of the class (new CGSelect)
5. Pass all desired settings as an object
2022-11-09 15:35:15 +03:00
2023-01-19 19:41:04 +03:00
#### All options for creating and managing are in the documentation, section "CGSelect class constructor".
2022-11-09 15:35:15 +03:00
2023-01-19 19:41:04 +03:00
### An example of creating a regular select.
2022-11-09 15:35:15 +03:00
```javascript
2023-01-24 20:10:53 +03:00
import CGSelect from 'cg-select';
2022-11-09 15:35:15 +03:00
2023-01-18 19:40:24 +03:00
const dropdown = new CGSelect({
2022-11-14 12:23:18 +03:00
selector: '.cg-dropdown_selector',
placeholder: 'Выберите авто',
items: [
'BMW',
{
id: '213sade',
title: 'Opel',
value: 1,
},
'Mersedes',
'MAN',
'Ferari',
],
2022-11-09 15:35:15 +03:00
});
```
2022-12-20 20:04:47 +03:00
2023-04-24 20:24:32 +03:00
### 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>
);
};
```
2023-04-25 12:33:26 +03:00
### 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>
```
2023-01-19 19:41:04 +03:00
## Example of different selects
2022-12-20 20:04:47 +03:00
2023-03-20 20:25:14 +03:00
<a href="https://cg-select.itguild.info/">View live example</a>
2022-11-09 15:35:15 +03:00
2023-02-07 17:43:01 +03:00
Built-in themes are also available: dark, white. To apply them, specify the theme attribute in the select settings and pass one of the values into it dark or white.
2023-01-19 19:41:04 +03:00
All documentation on CG-SELECT is located in the folder of the same name. The documentation describes all methods and variables, there are also examples of passing settings to select. You can also open it on the page with an example, or follow the link below.
2022-11-14 13:37:18 +03:00
2023-03-20 20:25:14 +03:00
<a href="https://cg-select.itguild.info/up_/documentation/index.html">Documentation</a>
2023-02-09 16:47:55 +03:00
2022-10-26 15:34:40 +03:00
## Contributing
2022-11-14 12:23:18 +03:00
2022-10-26 15:34:40 +03:00
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D
2022-11-14 12:23:18 +03:00
2022-12-23 15:36:11 +03:00
## Compatibility
2023-04-20 12:15:51 +03:00
2023-01-19 19:41:04 +03:00
| Application Compatibility | JS | React | Angular | Vue |
| ------------------------- | :----------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------: | :---------------------------------------------------------------------: |
2023-04-25 12:40:13 +03:00
| 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. | The select is initiated inside the `useEffect() `hook | not yet available | The select is initiated inside the `mounted() `hook |
2022-12-23 15:36:11 +03:00
2022-10-26 15:34:40 +03:00
## History
2022-11-14 12:23:18 +03:00
2023-01-19 19:41:04 +03:00
16.12.2022 - release version 0.1.0!
2023-01-23 15:26:23 +03:00
20.01.2023 - upgrade to version 0.2.1
2023-04-06 15:14:30 +03:00
06.03.2023 - upgrade to version 0.3.0