@lemonadejs/dropdown 3.0.12 → 3.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # LemonadeJS Dropdown
2
+
3
+ [Official website and documentation is here](https://lemonadejs.net/components/dropdown)
4
+
5
+ Compatible with Vanilla JavaScript, LemonadeJS, React, Vue or Angular.
6
+
7
+ The LemonadeJS Dropdown is a versatile solution for efficient option management. It is a framework-agnostic JavaScript plugin designed for seamless integration with Vue, React, and Angular. This feature-rich dropdown incorporates autocomplete for swift selections, grouping for organized options, and lazy loading for optimized performance, contributing to a smooth and improved user experience.
8
+
9
+ ## Features
10
+
11
+ - Lightweight: The JavaScript Dropdown is only about 2 KBytes;
12
+ - Integration: It can be used as a standalone library or integrated with any modern framework;
13
+
14
+ ## Getting Started
15
+
16
+ You can install using NPM or using directly from a CDN.
17
+
18
+ ### npm Installation
19
+
20
+ To install it in your project using npm, run the following command:
21
+
22
+ ```bash
23
+ $ npm install @lemonadejs/dropdown
24
+ ```
25
+
26
+ ### CDN
27
+
28
+ To use Dropdown via a CDN, include the following script tags in your HTML file:
29
+
30
+ ```html
31
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lemonadejs/dist/lemonade.min.js"></script>
32
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@lemonadejs/dropdown/dist/index.min.js"></script>
33
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lemonadejs/dropdown/dist/style.min.css" />
34
+ ```
35
+
36
+ ### Usage
37
+
38
+ Quick example with Lemonade
39
+
40
+ ```javascript
41
+ import Dropdown from '@lemonadejs/dropdown';
42
+ import '@lemonadejs/dropdown/dist/style.css'
43
+ import '@lemonadejs/modal/dist/style.css';
44
+
45
+ export default function App() {
46
+ const self = this;
47
+
48
+ self.data = [
49
+ { text: "Red", value: 1 },
50
+ { text: "Blue", value: 2 },
51
+ { text: "Green", value: 3 },
52
+ { text: "Yellow", value: 4 },
53
+ { text: "Purple", value: 5 },
54
+ { text: "Gray", value: 6 },
55
+ ]
56
+
57
+ return `<div>
58
+ <Dropdown :data="self.data" :value="1" />
59
+ </div>`
60
+ }
61
+ ```
62
+
63
+ ### Settings
64
+
65
+ | Attribute | Description |
66
+ |-----------|-------------|
67
+ | data: Item[] | An array of options to be displayed. Each item should follow the structure defined in the 'Item Details' section. |
68
+ | multiple?: boolean | If provided, enables the multiple selection mode, allowing users to select more than one option simultaneously. |
69
+ | autocomplete?: boolean | If provided, enables the autocomplete feature, displaying an input field that allows users to filter and quickly find options in the Dropdown. |
70
+ | value?: string | Represents the current value or selected option in the Dropdown. |
71
+ | type?: string | Specifies the type of display the Dropdown will use. It can be "searchbar" for a search bar interface, "picker" for a selection picker, or "default" for the default dropdown appearance. |
72
+
73
+ ### Item Details
74
+
75
+ | Attribute | Description |
76
+ | --------- | ----------- |
77
+ | value?: number or string | Represents the identifier or unique value associated with the option. |
78
+ | group?: string | Indicates the group to which the option belongs, allowing for segregation and organization. |
79
+ | text?: string | Displays the label or text associated with the option. |
80
+ | image?: string | Specifies the image URL to be displayed alongside the option. |
81
+
82
+ ## License
83
+
84
+ The [LemonadeJS](https://lemonadejs.net) LemonadeJS Dropdown is released under the MIT.
85
+
86
+ ## Other Tools
87
+
88
+ - [jSuites](https://jsuites.net/v4/)
89
+ - [Jspreadsheet Data Grid](https://jspreadsheet.com)
package/dist/index.d.ts CHANGED
@@ -42,15 +42,15 @@ declare namespace Dropdown {
42
42
  /** Placeholder text for the dropdown */
43
43
  placeholder?: string;
44
44
  /** Event handler for value changes */
45
- onchange?: (el: HTMLElement, obj: object, oldValue: string, newValue: string) => void;
45
+ onchange?: (obj: object, newValue: string|number) => void;
46
46
  /** Event handler for when the dropdown is ready */
47
- onload?: (el: HTMLElement, obj: object, data: any, val: any) => void;
47
+ onload?: (obj: object) => void;
48
48
  /** Event handler for when the dropdown opens */
49
- onopen?: (el: HTMLElement) => void;
49
+ onopen?: (obj: object) => void;
50
50
  /** Event handler for when the dropdown closes */
51
- onclose?: (el: HTMLElement) => void;
51
+ onclose?: (obj: object) => void;
52
52
  /** Event handler for when a new option is added to the dropdown */
53
- oninsert?: (obj: object, item: Item, newItem: Item) => void;
53
+ oninsert?: (obj: object, item: Item) => void;
54
54
  /** Event handler for just before a new option is added to the dropdown */
55
55
  onbeforeinsert?: (obj: object, item: Item) => void;
56
56
  /** Event handler for before a search on autocomplete is performed */
package/dist/index.js CHANGED
@@ -238,6 +238,9 @@ if (!Modal && typeof (require) === 'function') {
238
238
  // Lazy loading global instance
239
239
  let lazyloading = null;
240
240
 
241
+ let onload = self.load;
242
+ let onchange = self.onchange;
243
+
241
244
  const setData = function() {
242
245
  // Estimate width
243
246
  let width = self.width;
@@ -392,6 +395,11 @@ if (!Modal && typeof (require) === 'function') {
392
395
 
393
396
  // Update label
394
397
  updateLabel();
398
+
399
+ // Component onchange
400
+ if (typeof(onchange) === 'function') {
401
+ onchange(self, self.value);
402
+ }
395
403
  }
396
404
 
397
405
  const getValue = function() {
@@ -427,6 +435,10 @@ if (!Modal && typeof (require) === 'function') {
427
435
  self.value = getValue();
428
436
  // Identify the new state of the dropdown
429
437
  self.state = false;
438
+
439
+ if (typeof(self.onclose) === 'function') {
440
+ self.onclose(self);
441
+ }
430
442
  }
431
443
 
432
444
  const onopen = function() {
@@ -452,6 +464,10 @@ if (!Modal && typeof (require) === 'function') {
452
464
  // Focus on the item
453
465
  self.input.focus();
454
466
  }
467
+
468
+ if (typeof(self.onopen) === 'function') {
469
+ self.onopen(self);
470
+ }
455
471
  }
456
472
 
457
473
  self.search = function() {
@@ -619,6 +635,10 @@ if (!Modal && typeof (require) === 'function') {
619
635
  e.stopImmediatePropagation();
620
636
  }
621
637
  });
638
+
639
+ if (typeof(onload) === 'function') {
640
+ onload(self);
641
+ }
622
642
  }
623
643
 
624
644
  self.onchange = function(prop) {
@@ -633,7 +653,7 @@ if (!Modal && typeof (require) === 'function') {
633
653
  }
634
654
  }
635
655
 
636
- return `<div class="lm-dropdown" data-type="{{self.type}}" data-state="{{self.state}}">
656
+ return `<div class="lm-dropdown" data-type="{{self.type}}" data-state="{{self.state}}" :value="self.value">
637
657
  <div class="lm-dropdown-header">
638
658
  <div class="lm-dropdown-input" oninput="self.search" onfocus="self.open" onclick="self.click" placeholder="{{self.placeholder}}" :ref="self.input" tabindex="0"></div>
639
659
  <button onclick="self.close" class="lm-dropdown-done">Done</button>
package/package.json CHANGED
@@ -15,9 +15,9 @@
15
15
  ],
16
16
  "dependencies": {
17
17
  "lemonadejs": "^4.0.7",
18
- "@lemonadejs/modal": "^2.4.6"
18
+ "@lemonadejs/modal": "^2.4.9"
19
19
  },
20
20
  "main": "dist/index.js",
21
21
  "types": "dist/index.d.ts",
22
- "version": "3.0.12"
22
+ "version": "3.0.13"
23
23
  }