simp-select 1.0.16 → 1.0.18
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 +59 -55
- package/dist/demo/index.html +8 -7
- package/dist/simpleSelect.d.ts +9 -0
- package/dist/simpleSelect.js +1 -1
- package/dist/simpleSelectItem.d.ts +3 -0
- package/dist/simpleSelectItemDOM.d.ts +1 -0
- package/dist/style.css +1 -1
- package/dist/types/item.types.d.ts +6 -0
- package/dist/types/simpleSelect.types.d.ts +2 -1
- package/docs/index.html +1355 -0
- package/docs/style.css +29 -0
- package/package.json +1 -1
- package/src/const/simpleSelection.const.ts +3 -1
- package/src/demo/index.html +27 -6
- package/src/simpleSelect.ts +13 -0
- package/src/simpleSelectItem.ts +27 -3
- package/src/simpleSelectItemDOM.ts +25 -6
- package/src/style.css +4 -1
- package/src/types/item.types.ts +7 -0
- package/src/types/simpleSelect.types.ts +3 -1
package/docs/style.css
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
.container {
|
2
|
+
max-width: 800px;
|
3
|
+
margin: 50px auto;
|
4
|
+
}
|
5
|
+
.items {
|
6
|
+
display: flex;
|
7
|
+
flex-wrap: wrap;
|
8
|
+
justify-content: center;
|
9
|
+
gap: 10px;
|
10
|
+
margin: 20px auto;
|
11
|
+
}
|
12
|
+
.item {
|
13
|
+
display: block;
|
14
|
+
width: 350px;
|
15
|
+
}
|
16
|
+
.item_full {
|
17
|
+
display: block;
|
18
|
+
width: 700px;
|
19
|
+
}
|
20
|
+
|
21
|
+
.code {
|
22
|
+
padding: 10px;
|
23
|
+
background-color: #c7c7c7;
|
24
|
+
}
|
25
|
+
|
26
|
+
.description {
|
27
|
+
font-size: 18px;
|
28
|
+
font-weight: bold;
|
29
|
+
}
|
package/package.json
CHANGED
@@ -7,7 +7,7 @@ export const simpleSelectLocale: ISimpleSelectLocale = {
|
|
7
7
|
selected: 'Selected:',
|
8
8
|
all: 'all',
|
9
9
|
ok: 'Ok',
|
10
|
-
|
10
|
+
cancel: 'Cancel',
|
11
11
|
selectAll: 'Select all',
|
12
12
|
resetAll: 'Reset all',
|
13
13
|
};
|
@@ -19,6 +19,8 @@ export const simpleSelectionOptions: ISimpleSelectOptions = {
|
|
19
19
|
countShowSelected: 3,
|
20
20
|
isOnlyPlaceholder: false,
|
21
21
|
|
22
|
+
historyMaxSize: 0,
|
23
|
+
|
22
24
|
isRemoveTop: false,
|
23
25
|
|
24
26
|
isConfirmInMulti: false,
|
package/src/demo/index.html
CHANGED
@@ -45,6 +45,26 @@
|
|
45
45
|
<div id="app"></div>
|
46
46
|
|
47
47
|
<div class="items">
|
48
|
+
<div class="item">
|
49
|
+
<select
|
50
|
+
multiple
|
51
|
+
data-simple-placeholder="custom width float"
|
52
|
+
data-simple-float-width="1000"
|
53
|
+
>
|
54
|
+
<option value="custom-1">custom float 1</option>
|
55
|
+
<option value="custom-2">custom float 2</option>
|
56
|
+
</select>
|
57
|
+
</div>
|
58
|
+
<div class="item">
|
59
|
+
<select
|
60
|
+
multiple
|
61
|
+
data-simple-placeholder="none float"
|
62
|
+
data-simple-float-none="true"
|
63
|
+
>
|
64
|
+
<option value="custom-none-1">none float 1</option>
|
65
|
+
<option value="custom-none-2">none float 2</option>
|
66
|
+
</select>
|
67
|
+
</div>
|
48
68
|
<div class="item">
|
49
69
|
<select id="select_first"
|
50
70
|
|
@@ -279,12 +299,13 @@
|
|
279
299
|
// // detectNative: () => {
|
280
300
|
// // return false;
|
281
301
|
// // },
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
302
|
+
historyMaxSize: 2,
|
303
|
+
callbackChangeSelect: (e, that) => {
|
304
|
+
console.group();
|
305
|
+
// console.log(e);
|
306
|
+
console.log(that.history);
|
307
|
+
console.groupEnd();
|
308
|
+
},
|
288
309
|
|
289
310
|
// isUp: true,
|
290
311
|
// sepChars: ',',
|
package/src/simpleSelect.ts
CHANGED
@@ -79,6 +79,19 @@ export default class SimpleSelect {
|
|
79
79
|
createMethods(select: SimpleSelectItem) {
|
80
80
|
const self = this;
|
81
81
|
return {
|
82
|
+
getHistory: () => select.history,
|
83
|
+
getHistoryLast: () => {
|
84
|
+
if (select.history.length) {
|
85
|
+
return select.history[select.history.length - 1];
|
86
|
+
}
|
87
|
+
return null;
|
88
|
+
},
|
89
|
+
getHistoryFirst: () => {
|
90
|
+
if (select.history.length) {
|
91
|
+
return select.history[0];
|
92
|
+
}
|
93
|
+
return null;
|
94
|
+
},
|
82
95
|
getNativeSelect: () => select.getSelect(),
|
83
96
|
reload() {
|
84
97
|
self.rebuild(select);
|
package/src/simpleSelectItem.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { IItemLocalOptions, ISimpleSelectOptions } from './types/simpleSelect.types';
|
2
|
-
import { IOptionItems } from './types/item.types';
|
2
|
+
import { IHistoryItem, IOptionItems } from './types/item.types';
|
3
3
|
import {
|
4
4
|
compareObj,
|
5
5
|
getCreateListItem,
|
@@ -27,6 +27,8 @@ export class SimpleSelectItem extends SimpleSelectItemDOM {
|
|
27
27
|
|
28
28
|
timeoutDebounceId: NodeJS.Timeout | null = null;
|
29
29
|
|
30
|
+
history: IHistoryItem[] = [];
|
31
|
+
|
30
32
|
constructor(select: HTMLSelectElement, options: ISimpleSelectOptions, localOptions: IItemLocalOptions) {
|
31
33
|
super(select, options, localOptions);
|
32
34
|
|
@@ -189,7 +191,12 @@ export class SimpleSelectItem extends SimpleSelectItemDOM {
|
|
189
191
|
if (!option || option.disabled) {
|
190
192
|
return;
|
191
193
|
}
|
192
|
-
|
194
|
+
const isSelected = item.dataset[toCamelCase('sel-opt-checked')] === 'true';
|
195
|
+
|
196
|
+
if (isSelected !== option.selected) {
|
197
|
+
this.addHistory(option, isSelected);
|
198
|
+
}
|
199
|
+
option.selected = isSelected;
|
193
200
|
});
|
194
201
|
this.state.setState('isOpen', false);
|
195
202
|
this.triggerInit();
|
@@ -255,6 +262,20 @@ export class SimpleSelectItem extends SimpleSelectItemDOM {
|
|
255
262
|
}
|
256
263
|
}
|
257
264
|
|
265
|
+
addHistory(option: HTMLOptionElement, isCheck: boolean) {
|
266
|
+
if (this.options.historyMaxSize > 0) {
|
267
|
+
this.history.push({
|
268
|
+
value: option.value,
|
269
|
+
text: option.innerHTML,
|
270
|
+
selected: isCheck,
|
271
|
+
indexOption: option.index,
|
272
|
+
});
|
273
|
+
if (this.history.length > this.options.historyMaxSize) {
|
274
|
+
this.history = this.history.slice(this.history.length - this.options.historyMaxSize);
|
275
|
+
}
|
276
|
+
}
|
277
|
+
}
|
278
|
+
|
258
279
|
changeClickItem(item: HTMLLIElement) {
|
259
280
|
if (item) {
|
260
281
|
const pos = Number(item.dataset[toCamelCase('sel-position')]) || 0;
|
@@ -264,7 +285,9 @@ export class SimpleSelectItem extends SimpleSelectItemDOM {
|
|
264
285
|
if (this.options.isConfirmInMulti || this.isFloatWidth) {
|
265
286
|
this.changeClickItemDom(item);
|
266
287
|
} else {
|
267
|
-
|
288
|
+
const nextSelected = !option.selected;
|
289
|
+
option.selected = nextSelected;
|
290
|
+
this.addHistory(option, nextSelected);
|
268
291
|
this.changeClickItemDom(item);
|
269
292
|
this.createList();
|
270
293
|
this.multiDebounceChange();
|
@@ -272,6 +295,7 @@ export class SimpleSelectItem extends SimpleSelectItemDOM {
|
|
272
295
|
} else {
|
273
296
|
// option.selected = !option.selected;
|
274
297
|
option.selected = true;
|
298
|
+
this.addHistory(option, true);
|
275
299
|
this.createList();
|
276
300
|
this.state.setState('isOpen', false);
|
277
301
|
this.triggerInit();
|
@@ -55,6 +55,8 @@ export class SimpleSelectItemDOM {
|
|
55
55
|
|
56
56
|
elemTitle!: HTMLDivElement; // not native
|
57
57
|
|
58
|
+
confirmWrap: HTMLElement | null = null; // not native
|
59
|
+
|
58
60
|
confirmOk: HTMLButtonElement | null = null; // not native
|
59
61
|
|
60
62
|
confirmNo: HTMLButtonElement | null = null; // not native
|
@@ -171,6 +173,17 @@ export class SimpleSelectItemDOM {
|
|
171
173
|
this.options.isRemoveTop = ifTrueDataAttr(this.$select.getAttribute('data-simple-remove-top'));
|
172
174
|
}
|
173
175
|
|
176
|
+
if (this.$select.hasAttribute('data-simple-float-none')) {
|
177
|
+
this.isFloatWidth = false;
|
178
|
+
this.options.floatWidth = 0;
|
179
|
+
}
|
180
|
+
if (this.$select.hasAttribute('data-simple-float-width')) {
|
181
|
+
const newWidth = Number(this.$select.dataset[toCamelCase('simple-float-width')]);
|
182
|
+
if (newWidth) {
|
183
|
+
this.options.floatWidth = newWidth;
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
174
187
|
if (this.$select.hasAttribute('data-simple-always-open')) {
|
175
188
|
this.options.isAlwaysOpen = ifTrueDataAttr(this.$select.getAttribute('data-simple-always-open'));
|
176
189
|
|
@@ -202,8 +215,14 @@ export class SimpleSelectItemDOM {
|
|
202
215
|
const cls = getClass('float', true);
|
203
216
|
if (val) {
|
204
217
|
this.elemWrap.classList.add(cls);
|
218
|
+
if (!document.body.classList.contains(this.bodyOpenClass) && this.state.getState('isOpen')) {
|
219
|
+
document.body.classList.add(this.bodyOpenClass);
|
220
|
+
}
|
205
221
|
} else {
|
206
222
|
this.elemWrap.classList.remove(cls);
|
223
|
+
if (document.body.classList.contains(this.bodyOpenClass)) {
|
224
|
+
document.body.classList.remove(this.bodyOpenClass);
|
225
|
+
}
|
207
226
|
}
|
208
227
|
});
|
209
228
|
}
|
@@ -369,16 +388,16 @@ export class SimpleSelectItemDOM {
|
|
369
388
|
}
|
370
389
|
|
371
390
|
private createIsConfirmInMultiHTML() {
|
372
|
-
|
391
|
+
this.confirmWrap = document.createElement('div');
|
373
392
|
|
374
393
|
const classesItem = getClass('bottom_control');
|
375
394
|
this.confirmOk = createButton();
|
376
395
|
this.confirmNo = createButton();
|
377
|
-
|
378
|
-
|
396
|
+
this.confirmWrap.appendChild(this.confirmOk);
|
397
|
+
this.confirmWrap.appendChild(this.confirmNo);
|
379
398
|
|
380
399
|
this.confirmOk.innerHTML = this.options.locale.ok;
|
381
|
-
this.confirmNo.innerHTML = this.options.locale.
|
400
|
+
this.confirmNo.innerHTML = this.options.locale.cancel;
|
382
401
|
|
383
402
|
this.confirmOk.className = `${classesItem} ${getClass('ok', true, classesItem)}`;
|
384
403
|
this.confirmNo.className = `${classesItem} ${getClass('no', true, classesItem)}`;
|
@@ -387,9 +406,9 @@ export class SimpleSelectItemDOM {
|
|
387
406
|
if (!this.options.isConfirmInMulti) {
|
388
407
|
classes += ` ${getClass('hide', true, classes)}`;
|
389
408
|
}
|
390
|
-
|
409
|
+
this.confirmWrap.className = classes;
|
391
410
|
|
392
|
-
this.elemDropDown?.appendChild(
|
411
|
+
this.elemDropDown?.appendChild(this.confirmWrap);
|
393
412
|
}
|
394
413
|
|
395
414
|
private createTitleHTML() {
|
package/src/style.css
CHANGED
@@ -324,7 +324,10 @@
|
|
324
324
|
bottom: 0;
|
325
325
|
}
|
326
326
|
.SimpleSel__bottom_controls--hide {
|
327
|
-
display: none
|
327
|
+
display: none;
|
328
|
+
}
|
329
|
+
.SimpleSel--float .SimpleSel__bottom_controls--hide{
|
330
|
+
display: flex;
|
328
331
|
}
|
329
332
|
.SimpleSel__bottom_control--hide {
|
330
333
|
display: none;
|
package/src/types/item.types.ts
CHANGED
@@ -24,3 +24,10 @@ export interface ICreateLiReturn {
|
|
24
24
|
}
|
25
25
|
|
26
26
|
export type selectorType = string | HTMLSelectElement | NodeListOf<HTMLSelectElement> | HTMLSelectElement[];
|
27
|
+
|
28
|
+
export interface IHistoryItem {
|
29
|
+
value: string;
|
30
|
+
text: string;
|
31
|
+
selected: boolean;
|
32
|
+
indexOption: number;
|
33
|
+
}
|
@@ -7,7 +7,7 @@ export interface ISimpleSelectLocale {
|
|
7
7
|
selected: string;
|
8
8
|
all: string;
|
9
9
|
ok: string;
|
10
|
-
|
10
|
+
cancel: string;
|
11
11
|
|
12
12
|
resetAll: string;
|
13
13
|
selectAll: string;
|
@@ -32,6 +32,8 @@ export interface ISimpleSelectOptions {
|
|
32
32
|
|
33
33
|
sepChars: string;
|
34
34
|
|
35
|
+
historyMaxSize: number;
|
36
|
+
|
35
37
|
selectAll: boolean;
|
36
38
|
selectAllAfterClose: boolean;
|
37
39
|
resetAll: boolean;
|