jb-select 6.0.4 → 6.1.0
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 +10 -4
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.br +0 -0
- package/dist/index.cjs.js.gz +0 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -2
- package/dist/index.js.br +0 -0
- package/dist/index.js.gz +0 -0
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.br +0 -0
- package/dist/index.umd.js.gz +0 -0
- package/dist/index.umd.js.map +1 -1
- package/dist/jb-option/jb-option.d.ts +22 -0
- package/dist/jb-option/jb-option.d.ts.map +1 -0
- package/dist/jb-option/render.d.ts +2 -0
- package/dist/jb-option/render.d.ts.map +1 -0
- package/dist/jb-option/types.d.ts +5 -0
- package/dist/jb-option/types.d.ts.map +1 -0
- package/dist/jb-option-list/jb-option-list.d.ts +11 -0
- package/dist/jb-option-list/jb-option-list.d.ts.map +1 -0
- package/dist/jb-option-list/types.d.ts +6 -0
- package/dist/jb-option-list/types.d.ts.map +1 -0
- package/dist/jb-select.d.ts +60 -0
- package/dist/jb-select.d.ts.map +1 -0
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/jb-option/jb-option.d.ts +21 -0
- package/dist/lib/jb-option/render.d.ts +1 -0
- package/dist/lib/jb-option/types.d.ts +4 -0
- package/dist/lib/jb-option-list/jb-option-list.d.ts +10 -0
- package/dist/lib/jb-option-list/types.d.ts +5 -0
- package/dist/lib/jb-select.d.ts +59 -0
- package/dist/lib/types.d.ts +27 -0
- package/dist/types.d.ts +28 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/web-component/jb-select/lib/jb-select.d.ts +3 -0
- package/dist/web-component/jb-select/lib/types.d.ts +4 -1
- package/lib/global.d.ts +15 -0
- package/lib/jb-option/jb-option.ts +6 -2
- package/lib/jb-select.scss +1 -1
- package/lib/jb-select.ts +23 -8
- package/lib/types.ts +6 -3
- package/package.json +8 -4
- package/react/README.md +15 -55
- package/react/dist/JBOption.d.ts +19 -0
- package/react/dist/JBOptionList.d.ts +22 -0
- package/react/dist/JBSelect.d.ts +50 -0
- package/react/dist/events-hook.d.ts +16 -0
- package/react/dist/index.cjs.js +2 -122
- package/react/dist/index.cjs.js.map +1 -1
- package/react/dist/index.d.ts +3 -0
- package/react/dist/index.js +2 -118
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.umd.js +2 -125
- package/react/dist/index.umd.js.map +1 -1
- package/react/dist/lib/JBOption.d.ts +19 -0
- package/react/dist/lib/JBOptionList.d.ts +22 -0
- package/react/dist/lib/JBSelect.d.ts +48 -0
- package/react/dist/lib/events-hook.d.ts +16 -0
- package/react/dist/lib/index.d.ts +3 -0
- package/react/dist/web-component/jb-select/react/lib/JBSelect.d.ts +15 -5
- package/react/dist/web-component/jb-select/react/lib/events-hook.d.ts +16 -0
- package/react/lib/JBSelect.tsx +12 -24
- package/react/lib/events-hook.ts +24 -0
- package/react/package.json +1 -1
- package/react/tsconfig.json +3 -4
- package/dist/jb-select.cjs.js +0 -2
- package/dist/jb-select.cjs.js.br +0 -0
- package/dist/jb-select.cjs.js.gz +0 -0
- package/dist/jb-select.cjs.js.map +0 -1
- package/dist/jb-select.js +0 -2
- package/dist/jb-select.js.br +0 -0
- package/dist/jb-select.js.gz +0 -0
- package/dist/jb-select.js.map +0 -1
- package/dist/jb-select.umd.js +0 -2
- package/dist/jb-select.umd.js.br +0 -0
- package/dist/jb-select.umd.js.gz +0 -0
- package/dist/jb-select.umd.js.map +0 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type JBSelectWebComponent } from '../jb-select';
|
|
2
|
+
export declare class JBOptionWebComponent<TValue> extends HTMLElement {
|
|
3
|
+
#private;
|
|
4
|
+
get value(): TValue;
|
|
5
|
+
set value(value: TValue);
|
|
6
|
+
set selected(value: boolean);
|
|
7
|
+
get selected(): boolean;
|
|
8
|
+
get optionContent(): Node[];
|
|
9
|
+
get hidden(): boolean;
|
|
10
|
+
set hidden(value: boolean);
|
|
11
|
+
/**
|
|
12
|
+
* return text content of option (it used in search by default to filter option)
|
|
13
|
+
*/
|
|
14
|
+
get optionContentText(): string;
|
|
15
|
+
constructor();
|
|
16
|
+
connectedCallback(): void;
|
|
17
|
+
setSelectElement(element: JBSelectWebComponent): void;
|
|
18
|
+
disconnectedCallback(): void;
|
|
19
|
+
static get observedAttributes(): string[];
|
|
20
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function renderHTML(): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type OptionListCallbacks } from "./types";
|
|
2
|
+
export declare class JBOptionListWebComponent<TOption, TValue> extends HTMLElement {
|
|
3
|
+
#private;
|
|
4
|
+
get callbacks(): OptionListCallbacks<TOption, TValue>;
|
|
5
|
+
get optionList(): TOption[];
|
|
6
|
+
set optionList(value: TOption[]);
|
|
7
|
+
constructor();
|
|
8
|
+
connectedCallback(): void;
|
|
9
|
+
setCallback<T extends keyof OptionListCallbacks<TOption, TValue>>(key: T, callbackFn: OptionListCallbacks<TOption, TValue>[T]): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { JBSelectCallbacks, JBSelectElements, ValidationValue } from "./types";
|
|
2
|
+
import { ShowValidationErrorInput, ValidationHelper, type WithValidation } from "jb-validation";
|
|
3
|
+
import { JBFormInputStandards } from 'jb-form';
|
|
4
|
+
/**
|
|
5
|
+
* TValue is the type of value we extract from option
|
|
6
|
+
*/
|
|
7
|
+
export declare class JBSelectWebComponent<TValue = any> extends HTMLElement implements WithValidation<ValidationValue<TValue>>, JBFormInputStandards<TValue> {
|
|
8
|
+
#private;
|
|
9
|
+
static get formAssociated(): boolean;
|
|
10
|
+
callbacks: JBSelectCallbacks<TValue>;
|
|
11
|
+
elements: JBSelectElements;
|
|
12
|
+
get value(): TValue;
|
|
13
|
+
set value(value: TValue);
|
|
14
|
+
get textValue(): string;
|
|
15
|
+
set textValue(value: string);
|
|
16
|
+
get selectedOptionTitle(): string;
|
|
17
|
+
get placeholder(): string;
|
|
18
|
+
set placeholder(value: string);
|
|
19
|
+
get searchPlaceholder(): string;
|
|
20
|
+
set searchPlaceholder(value: string);
|
|
21
|
+
get isMobileDevice(): boolean;
|
|
22
|
+
get isOpen(): boolean;
|
|
23
|
+
get validation(): ValidationHelper<ValidationValue<TValue>>;
|
|
24
|
+
get disabled(): boolean;
|
|
25
|
+
set disabled(value: boolean);
|
|
26
|
+
set required(value: boolean);
|
|
27
|
+
get required(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* @description will determine if component trigger jb-validation mechanism automatically on user event or it just let user-developer handle validation mechanism by himself
|
|
30
|
+
*/
|
|
31
|
+
get isAutoValidationDisabled(): boolean;
|
|
32
|
+
get name(): string;
|
|
33
|
+
initialValue: TValue | null;
|
|
34
|
+
get isDirty(): boolean;
|
|
35
|
+
constructor();
|
|
36
|
+
connectedCallback(): void;
|
|
37
|
+
static get observedAttributes(): string[];
|
|
38
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
39
|
+
focus(): void;
|
|
40
|
+
blur(): void;
|
|
41
|
+
/**
|
|
42
|
+
* @description show given string as a error in message place
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
showValidationError(error: ShowValidationErrorInput | string): void;
|
|
46
|
+
clearValidationError(): void;
|
|
47
|
+
/**
|
|
48
|
+
* @public
|
|
49
|
+
* @description this method used to check for validity but doesn't show error to user and just return the result
|
|
50
|
+
* this method used by #internal of component
|
|
51
|
+
*/
|
|
52
|
+
checkValidity(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* @public
|
|
55
|
+
* @description this method used to check for validity and show error to user
|
|
56
|
+
*/
|
|
57
|
+
reportValidity(): boolean;
|
|
58
|
+
get validationMessage(): string;
|
|
59
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { JBOptionWebComponent } from "./jb-option/jb-option";
|
|
2
|
+
import type { EventTypeWithTarget } from "jb-core";
|
|
3
|
+
import type { JBSelectWebComponent } from "./jb-select";
|
|
4
|
+
export type JBSelectCallbacks<TValue> = {
|
|
5
|
+
getSelectedValueDOM?: (value: TValue, content: HTMLElement) => HTMLElement;
|
|
6
|
+
};
|
|
7
|
+
export type JBSelectElements = {
|
|
8
|
+
input: HTMLInputElement;
|
|
9
|
+
componentWrapper: HTMLDivElement;
|
|
10
|
+
selectedValueWrapper: HTMLDivElement;
|
|
11
|
+
messageBox: HTMLDivElement;
|
|
12
|
+
optionList: HTMLDivElement;
|
|
13
|
+
optionListWrapper: HTMLDivElement;
|
|
14
|
+
optionListSlot: HTMLSlotElement;
|
|
15
|
+
arrowIcon: HTMLDivElement;
|
|
16
|
+
label: {
|
|
17
|
+
wrapper: HTMLLabelElement;
|
|
18
|
+
text: HTMLSpanElement;
|
|
19
|
+
};
|
|
20
|
+
emptyListPlaceholder: HTMLDivElement;
|
|
21
|
+
};
|
|
22
|
+
export type ValidationValue<TValue> = {
|
|
23
|
+
selectedOption: JBOptionWebComponent<TValue> | null;
|
|
24
|
+
value: TValue | null;
|
|
25
|
+
inputtedText: string;
|
|
26
|
+
};
|
|
27
|
+
export type JBSelectEventType<TEvent> = EventTypeWithTarget<TEvent, JBSelectWebComponent>;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { JBOptionWebComponent } from "./jb-option/jb-option";
|
|
2
|
+
import type { EventTypeWithTarget } from "jb-core";
|
|
3
|
+
import type { JBSelectWebComponent } from "./jb-select";
|
|
4
|
+
export type JBSelectCallbacks<TValue> = {
|
|
5
|
+
getSelectedValueDOM?: (value: TValue, content: HTMLElement) => HTMLElement;
|
|
6
|
+
};
|
|
7
|
+
export type JBSelectElements = {
|
|
8
|
+
input: HTMLInputElement;
|
|
9
|
+
componentWrapper: HTMLDivElement;
|
|
10
|
+
selectedValueWrapper: HTMLDivElement;
|
|
11
|
+
messageBox: HTMLDivElement;
|
|
12
|
+
optionList: HTMLDivElement;
|
|
13
|
+
optionListWrapper: HTMLDivElement;
|
|
14
|
+
optionListSlot: HTMLSlotElement;
|
|
15
|
+
arrowIcon: HTMLDivElement;
|
|
16
|
+
label: {
|
|
17
|
+
wrapper: HTMLLabelElement;
|
|
18
|
+
text: HTMLSpanElement;
|
|
19
|
+
};
|
|
20
|
+
emptyListPlaceholder: HTMLDivElement;
|
|
21
|
+
};
|
|
22
|
+
export type ValidationValue<TValue> = {
|
|
23
|
+
selectedOption: JBOptionWebComponent<TValue> | null;
|
|
24
|
+
value: TValue | null;
|
|
25
|
+
inputtedText: string;
|
|
26
|
+
};
|
|
27
|
+
export type JBSelectEventType<TEvent> = EventTypeWithTarget<TEvent, JBSelectWebComponent>;
|
|
28
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,SAAS,CAAC;AACjD,OAAO,KAAI,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACvD,MAAM,MAAM,iBAAiB,CAAC,MAAM,IAAI;IACpC,mBAAmB,CAAC,EAAC,CAAC,KAAK,EAAC,MAAM,EAAC,OAAO,EAAC,WAAW,KAAK,WAAW,CAAC;CAC1E,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC3B,KAAK,EAAE,gBAAgB,CAAC;IACxB,gBAAgB,EAAE,cAAc,CAAC;IACjC,oBAAoB,EAAE,cAAc,CAAC;IACrC,UAAU,EAAC,cAAc,CAAC;IAC1B,UAAU,EAAE,cAAc,CAAC;IAC3B,iBAAiB,EAAE,cAAc,CAAC;IAClC,cAAc,EAAC,eAAe,CAAC;IAC/B,SAAS,EAAE,cAAc,CAAC;IAC1B,KAAK,EAAC;QACF,OAAO,EAAE,gBAAgB,CAAC;QAC1B,IAAI,EAAE,eAAe,CAAA;KACxB,CAAC;IACF,oBAAoB,EAAE,cAAc,CAAC;CACxC,CAAA;AACD,MAAM,MAAM,eAAe,CAAC,MAAM,IAAI;IAClC,cAAc,EAAC,oBAAoB,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACnD,KAAK,EAAC,MAAM,GAAG,IAAI,CAAC;IACpB,YAAY,EAAC,MAAM,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,iBAAiB,CAAC,MAAM,IAAI,mBAAmB,CAAC,MAAM,EAAC,oBAAoB,CAAC,CAAA"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { JBSelectCallbacks, JBSelectElements, ValidationValue } from "./types";
|
|
2
2
|
import { ShowValidationErrorInput, ValidationHelper, type WithValidation } from "jb-validation";
|
|
3
3
|
import { JBFormInputStandards } from 'jb-form';
|
|
4
|
+
/**
|
|
5
|
+
* TValue is the type of value we extract from option
|
|
6
|
+
*/
|
|
4
7
|
export declare class JBSelectWebComponent<TValue = any> extends HTMLElement implements WithValidation<ValidationValue<TValue>>, JBFormInputStandards<TValue> {
|
|
5
8
|
#private;
|
|
6
9
|
static get formAssociated(): boolean;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { JBOptionWebComponent } from "./jb-option/jb-option";
|
|
2
|
+
import type { EventTypeWithTarget } from "jb-core";
|
|
3
|
+
import type { JBSelectWebComponent } from "./jb-select";
|
|
2
4
|
export type JBSelectCallbacks<TValue> = {
|
|
3
5
|
getSelectedValueDOM?: (value: TValue, content: HTMLElement) => HTMLElement;
|
|
4
6
|
};
|
|
@@ -22,3 +24,4 @@ export type ValidationValue<TValue> = {
|
|
|
22
24
|
value: TValue | null;
|
|
23
25
|
inputtedText: string;
|
|
24
26
|
};
|
|
27
|
+
export type JBSelectEventType<TEvent> = EventTypeWithTarget<TEvent, JBSelectWebComponent>;
|
package/lib/global.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type FileStringModules = {
|
|
2
|
+
readonly default: string;
|
|
3
|
+
}
|
|
4
|
+
declare module '*.scss' {
|
|
5
|
+
const value: FileStringModules;
|
|
6
|
+
export default value;
|
|
7
|
+
}
|
|
8
|
+
declare module '*.html' {
|
|
9
|
+
const value: FileStringModules;
|
|
10
|
+
export default value.default;
|
|
11
|
+
}
|
|
12
|
+
declare module '*.svg' {
|
|
13
|
+
const value: string;
|
|
14
|
+
export default value;
|
|
15
|
+
}
|
|
@@ -4,6 +4,8 @@ import { renderHTML } from "./render";
|
|
|
4
4
|
import { JBOptionElements } from "./types";
|
|
5
5
|
|
|
6
6
|
//TODO: check for filter text to set visibility on mount
|
|
7
|
+
//TODO: add disable option (will be displayed but can not be select)
|
|
8
|
+
//TODO: add highlight to highlight the searched value
|
|
7
9
|
export class JBOptionWebComponent<TValue> extends HTMLElement {
|
|
8
10
|
|
|
9
11
|
#elements: JBOptionElements;
|
|
@@ -41,8 +43,10 @@ export class JBOptionWebComponent<TValue> extends HTMLElement {
|
|
|
41
43
|
this.#hidden = value;
|
|
42
44
|
if(value){
|
|
43
45
|
this.#elements.componentWrapper.classList.add('--hidden');
|
|
46
|
+
this.setAttribute("inert","");
|
|
44
47
|
}else{
|
|
45
48
|
this.#elements.componentWrapper.classList.remove('--hidden');
|
|
49
|
+
this.removeAttribute("inert");
|
|
46
50
|
}
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
@@ -73,8 +77,8 @@ export class JBOptionWebComponent<TValue> extends HTMLElement {
|
|
|
73
77
|
}
|
|
74
78
|
#onFilterChange(e: CustomEvent){
|
|
75
79
|
const {filterText} = e.detail;
|
|
76
|
-
const optionTextContent = this.optionContentText;
|
|
77
|
-
if(optionTextContent.includes(filterText)){
|
|
80
|
+
const optionTextContent = this.optionContentText.toLowerCase();
|
|
81
|
+
if(optionTextContent.includes(filterText.toLowerCase())){
|
|
78
82
|
this.hidden = false;
|
|
79
83
|
}else{
|
|
80
84
|
this.hidden = true;
|
package/lib/jb-select.scss
CHANGED
package/lib/jb-select.ts
CHANGED
|
@@ -5,13 +5,17 @@ import {
|
|
|
5
5
|
JBSelectElements,
|
|
6
6
|
ValidationValue,
|
|
7
7
|
} from "./types";
|
|
8
|
-
import {
|
|
9
|
-
import { isMobile } from "
|
|
8
|
+
import { ShowValidationErrorParameters, ValidationHelper, type ValidationItem, type ValidationResult, type WithValidation } from "jb-validation";
|
|
9
|
+
import { isMobile } from "jb-core";
|
|
10
10
|
import { JBFormInputStandards } from 'jb-form';
|
|
11
11
|
// eslint-disable-next-line no-duplicate-imports
|
|
12
12
|
import { JBOptionWebComponent } from "./jb-option/jb-option";
|
|
13
|
-
|
|
14
|
-
//
|
|
13
|
+
|
|
14
|
+
//TODO: add IncludeInputInList or freeSolo so user can select item that he wrote without even it exist in select list
|
|
15
|
+
//TODO: handleHomeEndKeys to move focus inside the popup with the Home and End keys.
|
|
16
|
+
/**
|
|
17
|
+
* TValue is the type of value we extract from option
|
|
18
|
+
*/
|
|
15
19
|
export class JBSelectWebComponent<TValue = any> extends HTMLElement implements WithValidation<ValidationValue<TValue>>, JBFormInputStandards<TValue> {
|
|
16
20
|
static get formAssociated() {
|
|
17
21
|
return true;
|
|
@@ -214,6 +218,7 @@ export class JBSelectWebComponent<TValue = any> extends HTMLElement implements W
|
|
|
214
218
|
"required",
|
|
215
219
|
"placeholder",
|
|
216
220
|
"search-placeholder",
|
|
221
|
+
"error",
|
|
217
222
|
];
|
|
218
223
|
}
|
|
219
224
|
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
|
@@ -249,6 +254,9 @@ export class JBSelectWebComponent<TValue = any> extends HTMLElement implements W
|
|
|
249
254
|
case "search-placeholder":
|
|
250
255
|
this.searchPlaceholder = value;
|
|
251
256
|
break;
|
|
257
|
+
case "error":
|
|
258
|
+
this.reportValidity();
|
|
259
|
+
break;
|
|
252
260
|
}
|
|
253
261
|
}
|
|
254
262
|
/**
|
|
@@ -527,7 +535,7 @@ export class JBSelectWebComponent<TValue = any> extends HTMLElement implements W
|
|
|
527
535
|
* @description show given string as a error in message place
|
|
528
536
|
* @public
|
|
529
537
|
*/
|
|
530
|
-
showValidationError(error:
|
|
538
|
+
showValidationError(error: ShowValidationErrorParameters | string) {
|
|
531
539
|
const message = typeof error == "string" ? error : error.message;
|
|
532
540
|
this.elements.messageBox.innerHTML = message;
|
|
533
541
|
this.elements.messageBox.classList.add("--error");
|
|
@@ -569,11 +577,18 @@ export class JBSelectWebComponent<TValue = any> extends HTMLElement implements W
|
|
|
569
577
|
return selectedOptionDom;
|
|
570
578
|
}
|
|
571
579
|
#getInsideValidation() {
|
|
572
|
-
const
|
|
580
|
+
const validationList: ValidationItem<ValidationValue<TValue>>[] = [];
|
|
581
|
+
if(this.getAttribute("error") !== null && this.getAttribute("error").trim().length > 0){
|
|
582
|
+
validationList.push({
|
|
583
|
+
validator: undefined,
|
|
584
|
+
message: this.getAttribute("error"),
|
|
585
|
+
stateType: "customError"
|
|
586
|
+
});
|
|
587
|
+
}
|
|
573
588
|
if (this.required) {
|
|
574
589
|
const label = this.getAttribute("label") || "";
|
|
575
590
|
const message = `${label} حتما باید انتخاب شود`;
|
|
576
|
-
|
|
591
|
+
validationList.push({
|
|
577
592
|
validator: ({ value }) => {
|
|
578
593
|
return value !== null && value !== undefined;
|
|
579
594
|
},
|
|
@@ -581,7 +596,7 @@ export class JBSelectWebComponent<TValue = any> extends HTMLElement implements W
|
|
|
581
596
|
stateType: "valueMissing"
|
|
582
597
|
});
|
|
583
598
|
}
|
|
584
|
-
return
|
|
599
|
+
return validationList;
|
|
585
600
|
}
|
|
586
601
|
//
|
|
587
602
|
#checkValidity(showError: boolean) {
|
package/lib/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { JBOptionWebComponent } from "./jb-option/jb-option";
|
|
2
|
+
import type {EventTypeWithTarget} from "jb-core";
|
|
3
|
+
import type{ JBSelectWebComponent } from "./jb-select";
|
|
3
4
|
export type JBSelectCallbacks<TValue> = {
|
|
4
5
|
getSelectedValueDOM?:(value:TValue,content:HTMLElement) => HTMLElement;
|
|
5
6
|
}
|
|
@@ -23,4 +24,6 @@ export type ValidationValue<TValue> = {
|
|
|
23
24
|
selectedOption:JBOptionWebComponent<TValue> | null,
|
|
24
25
|
value:TValue | null,
|
|
25
26
|
inputtedText:string
|
|
26
|
-
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type JBSelectEventType<TEvent> = EventTypeWithTarget<TEvent,JBSelectWebComponent>
|
package/package.json
CHANGED
|
@@ -10,9 +10,12 @@
|
|
|
10
10
|
"jb",
|
|
11
11
|
"jb-select",
|
|
12
12
|
"select",
|
|
13
|
-
"
|
|
13
|
+
"autocomplete",
|
|
14
|
+
"dropdown",
|
|
15
|
+
"web component",
|
|
16
|
+
"react component"
|
|
14
17
|
],
|
|
15
|
-
"version": "6.0
|
|
18
|
+
"version": "6.1.0",
|
|
16
19
|
"bugs": "https://github.com/javadbat/jb-select/issues",
|
|
17
20
|
"license": "MIT",
|
|
18
21
|
"files": [
|
|
@@ -23,14 +26,15 @@
|
|
|
23
26
|
"react/",
|
|
24
27
|
"react/dist/"
|
|
25
28
|
],
|
|
26
|
-
"types": "./dist/
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
27
30
|
"main": "index.js",
|
|
28
31
|
"repository": {
|
|
29
32
|
"type": "git",
|
|
30
33
|
"url": "git@github.com:javadbat/jb-select.git"
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
|
-
"jb-validation": ">=0.
|
|
36
|
+
"jb-validation": ">=0.4.0",
|
|
37
|
+
"jb-core":">=0.4.0"
|
|
34
38
|
},
|
|
35
39
|
"devDependencies": {
|
|
36
40
|
"jb-form":">=0.6.10"
|
package/react/README.md
CHANGED
|
@@ -19,7 +19,7 @@ import {JBSelect} from 'jb-select/react';
|
|
|
19
19
|
<JBSelect></JBSelect>
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
## label
|
|
23
23
|
use label property to describe your select component.
|
|
24
24
|
|
|
25
25
|
```jsx
|
|
@@ -120,7 +120,7 @@ render(){
|
|
|
120
120
|
}
|
|
121
121
|
```
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
## Add Icon or Any Element into box
|
|
124
124
|
|
|
125
125
|
sometimes you want to add icon into the select box before value box.
|
|
126
126
|
you can customize this entire section by adding a div or any other Tag with the `slot="start-section"`
|
|
@@ -135,56 +135,16 @@ like the example the below:
|
|
|
135
135
|
</JBSelect>
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
| --jb-select-list-max-height | max height of option list |
|
|
152
|
-
| --jb-select-border-bottom-width | width of border bottom |
|
|
153
|
-
| --jb-select-border-width | width of border |
|
|
154
|
-
| --jb-select-label-color | color of label default is `#1f1735` |
|
|
155
|
-
| --jb-input-label-font-size | label font size default is `0.8em` |
|
|
156
|
-
| --jb-input-label-font-weight | color of label defualt is `#1f1735` |
|
|
157
|
-
| --jb-select-option-color | change option text color |
|
|
158
|
-
| --jb-select-option-color-hover | change option text color on hover |
|
|
159
|
-
| --jb-select-option-background-color | background of options default is `transparent` |
|
|
160
|
-
| --jb-select-option-background-color-hover | background of options on mouse hover default is `#1073db` |
|
|
161
|
-
| --jb-select-input-color | color of input value |
|
|
162
|
-
| --jb-select-bgcolor-selected | set background color for selected status |
|
|
163
|
-
| --jb-select-selected-value-color | selected value text color default is `#1f1735` |
|
|
164
|
-
| --jb-select-selected-value-font-size | font-size of selected value default is `1.1rem` |
|
|
165
|
-
| --jb-select-message-color | message text color default is `#929292` |
|
|
166
|
-
| --jb-select-message-font-size | font size of message default is `0.7em` |
|
|
167
|
-
| --jb-select-message-font-weight | font weight of message box default is `normal` |
|
|
168
|
-
| --jb-select-placeholder-color | placeholder color default is `initial` |
|
|
169
|
-
| --jb-select-placeholder-font-size | placeholder font-size default is `1.1em` |
|
|
170
|
-
| --jb-select-height | jb-select box height |
|
|
171
|
-
| --jb-select-mobile-search-input-height | when user open select on mobile there is a search box input this var will set its height |
|
|
172
|
-
| --jb-select-mobile-item-list-margin | when user open select on mobile there is gap between search box & list that can be customized |
|
|
173
|
-
| --jb-select-list-padding | padding of opened list box default is `16px 0` |
|
|
174
|
-
| --jb-select-close-bg-color | close button bg-color default is `#1f1735` |
|
|
175
|
-
| --jb-select-close-x-color | close button x color default is `#fff` |
|
|
176
|
-
| --jb-select-close-bg-opacity | close button bg opacity default is `0.4` |
|
|
177
|
-
| --jb-select-mobile-input-bgcolor | background color search input when open in mobile |
|
|
178
|
-
| --jb-select-mobile-search-border-width | when user open select on mobile, search box can have its own border width config |
|
|
179
|
-
| --jb-select-mobile-search-border-color | when user open select on mobile, search box can have its own border color config |
|
|
180
|
-
| --jb-select-mobile-search-border-bottom-width | when user open select on mobile, search box can have its own border bottom width config |
|
|
181
|
-
| --jb-select-mobile-search-border-bottom-color | when user open select on mobile, search box can have its own border bottom color config |
|
|
182
|
-
| --jb-select-mobile-search-border-radius | when user open select on mobile, search box can have its own border radius |
|
|
183
|
-
| --jb-select-middle-div-height | separator line between input and list default is `0px` and hidden but you can cahange it |
|
|
184
|
-
| --jb-select-middle-div-color | change separator line color |
|
|
185
|
-
| --jb-select-middle-div-margin | change seprator line margin |
|
|
186
|
-
| --jb-select-middle-div-mobile-margin | change separator line margin in mobile modal |
|
|
187
|
-
| --jb-select-middle-div-radius | change separator line border-radius |
|
|
188
|
-
| --jb-select-list-scroll-color | list item scroll color default is `#c3c3c3` |
|
|
189
|
-
| --jb-select-list-scroll-border-radius | list item scroll border-radius default is `4px` |
|
|
190
|
-
| --jb-select-select-box-margin | margin of internal element called select box that wrapper display element of form in one box |
|
|
138
|
+
## validation
|
|
139
|
+
|
|
140
|
+
since select has a limited value options, validation have different story here. the only validation i really necessary here is required that indicate if user must select a value before he can move on. so pass `required` prop, then call `checkValidity` function like all other jb web component family. but if you need more customize validation just read [jb-validation](https://github.com/javadbat/jb-validation)
|
|
141
|
+
|
|
142
|
+
you can also set `error` attribute to pass error directly to the component
|
|
143
|
+
|
|
144
|
+
```jsx
|
|
145
|
+
<JBSelect error="your error message"></JBSelect>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## set custom style
|
|
149
|
+
|
|
150
|
+
please read [jb-select](https://github.com/javadbat/jb-select) custom style section.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
import { JBOptionWebComponent } from 'jb-select';
|
|
3
|
+
type TValue = any;
|
|
4
|
+
declare global {
|
|
5
|
+
namespace JSX {
|
|
6
|
+
interface IntrinsicElements {
|
|
7
|
+
'jb-option': JBOptionType;
|
|
8
|
+
}
|
|
9
|
+
interface JBOptionType extends React.DetailedHTMLProps<React.HTMLAttributes<JBOptionWebComponent<TValue>>, JBOptionWebComponent<TValue>> {
|
|
10
|
+
class?: string;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export declare const JBOption: React.ForwardRefExoticComponent<Omit<JBOptionProps<any>, "ref"> & React.RefAttributes<unknown>>;
|
|
15
|
+
type Props<TValue> = {
|
|
16
|
+
value: TValue;
|
|
17
|
+
};
|
|
18
|
+
export type JBOptionProps<TValue> = PropsWithChildren<JSX.JBOptionType & Props<TValue>>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { JBOptionListWebComponent } from 'jb-select';
|
|
3
|
+
type TOption = any;
|
|
4
|
+
type TValue = any;
|
|
5
|
+
declare global {
|
|
6
|
+
namespace JSX {
|
|
7
|
+
interface IntrinsicElements {
|
|
8
|
+
'jb-option-list': JBOptionListType;
|
|
9
|
+
}
|
|
10
|
+
interface JBOptionListType extends React.DetailedHTMLProps<React.HTMLAttributes<JBOptionListWebComponent<TOption, TValue>>, JBOptionListWebComponent<TOption, TValue>> {
|
|
11
|
+
class?: string;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export declare const JBOptionList: React.ForwardRefExoticComponent<JBOptionListProps<any, any> & React.RefAttributes<unknown>>;
|
|
16
|
+
export type JBOptionListProps<TOption, TValue> = {
|
|
17
|
+
optionList: TOption[];
|
|
18
|
+
getTitle?: (option: TOption) => string;
|
|
19
|
+
getValue?: (option: TOption) => TValue;
|
|
20
|
+
getContentDOM?: (option: TOption) => HTMLElement;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React, { CSSProperties } from 'react';
|
|
2
|
+
import 'jb-select';
|
|
3
|
+
import { JBSelectWebComponent } from 'jb-select';
|
|
4
|
+
import { EventProps } from './events-hook.js';
|
|
5
|
+
export type JBSelectEventType<T> = T & {
|
|
6
|
+
target: JBSelectWebComponent;
|
|
7
|
+
};
|
|
8
|
+
declare global {
|
|
9
|
+
namespace JSX {
|
|
10
|
+
interface IntrinsicElements {
|
|
11
|
+
'jb-select': JBSelectType;
|
|
12
|
+
}
|
|
13
|
+
interface JBSelectType extends React.DetailedHTMLProps<React.HTMLAttributes<JBSelectWebComponent>, JBSelectWebComponent> {
|
|
14
|
+
class?: string;
|
|
15
|
+
label?: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
required?: string | boolean;
|
|
18
|
+
message?: string;
|
|
19
|
+
tabindex?: string;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export declare const JBSelect: React.ForwardRefExoticComponent<EventProps & {
|
|
24
|
+
style?: CSSProperties;
|
|
25
|
+
label?: string;
|
|
26
|
+
getSelectedValueDOM?: (option: any) => HTMLElement;
|
|
27
|
+
value?: any;
|
|
28
|
+
required?: boolean;
|
|
29
|
+
message?: string;
|
|
30
|
+
placeholder?: string;
|
|
31
|
+
searchPlaceholder?: string;
|
|
32
|
+
className?: string;
|
|
33
|
+
children?: React.ReactNode;
|
|
34
|
+
name?: string;
|
|
35
|
+
error?: string;
|
|
36
|
+
} & React.RefAttributes<unknown>>;
|
|
37
|
+
export type Props = EventProps & {
|
|
38
|
+
style?: CSSProperties;
|
|
39
|
+
label?: string;
|
|
40
|
+
getSelectedValueDOM?: (option: any) => HTMLElement;
|
|
41
|
+
value?: any;
|
|
42
|
+
required?: boolean;
|
|
43
|
+
message?: string;
|
|
44
|
+
placeholder?: string;
|
|
45
|
+
searchPlaceholder?: string;
|
|
46
|
+
className?: string;
|
|
47
|
+
children?: React.ReactNode;
|
|
48
|
+
name?: string;
|
|
49
|
+
error?: string;
|
|
50
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
import type { JBSelectWebComponent, JBSelectEventType } from 'jb-select';
|
|
3
|
+
export type EventProps = {
|
|
4
|
+
/**
|
|
5
|
+
* when component loaded, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
6
|
+
*/
|
|
7
|
+
onLoad?: (e: JBSelectEventType<CustomEvent>) => void;
|
|
8
|
+
/**
|
|
9
|
+
* when all property set and ready to use, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
10
|
+
*/
|
|
11
|
+
onInit?: (e: JBSelectEventType<CustomEvent>) => void;
|
|
12
|
+
onChange?: (e: JBSelectEventType<Event>) => void;
|
|
13
|
+
onKeyUp?: (e: JBSelectEventType<KeyboardEvent>) => void;
|
|
14
|
+
onInput?: (e: JBSelectEventType<InputEvent>) => void;
|
|
15
|
+
};
|
|
16
|
+
export declare function useEvents(element: RefObject<JBSelectWebComponent>, props: EventProps): void;
|