@basis-ng/primitives 0.0.1-alpha.4 → 0.0.1-alpha.6
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/core/components/select/select-content.component.d.ts +24 -7
- package/core/components/select/select-option.component.d.ts +22 -0
- package/core/components/select/select.component.d.ts +65 -16
- package/fesm2022/basis-ng-primitives.mjs +175 -40
- package/fesm2022/basis-ng-primitives.mjs.map +1 -1
- package/package.json +1 -1
- package/public-api.d.ts +2 -0
|
@@ -1,39 +1,56 @@
|
|
|
1
|
+
import { CdkListbox } from '@angular/cdk/listbox';
|
|
1
2
|
import { ElementRef } from '@angular/core';
|
|
3
|
+
import { SelectOptionComponent } from './select-option.component';
|
|
2
4
|
import * as i0 from "@angular/core";
|
|
3
5
|
import * as i1 from "@angular/cdk/listbox";
|
|
4
6
|
/**
|
|
5
7
|
* Component representing the content of a select dropdown.
|
|
6
|
-
*
|
|
8
|
+
* This component integrates with Angular CDK Listbox to manage options and their selection.
|
|
7
9
|
*/
|
|
8
10
|
export declare class SelectContentComponent {
|
|
9
11
|
/**
|
|
10
12
|
* Signal representing the selected values in the listbox.
|
|
13
|
+
* This is an array of strings corresponding to the selected option values.
|
|
11
14
|
*/
|
|
12
15
|
readonly value: import("@angular/core").WritableSignal<string[]>;
|
|
13
16
|
/**
|
|
14
|
-
* Signal representing the content of the selected option.
|
|
17
|
+
* Signal representing the content of the selected option(s).
|
|
18
|
+
* This is a string that can be used to display the selected option(s).
|
|
15
19
|
*/
|
|
16
20
|
readonly content: import("@angular/core").WritableSignal<string>;
|
|
17
21
|
/**
|
|
18
22
|
* Event emitter triggered when the dropdown should close.
|
|
23
|
+
* This is used to notify the parent component to close the dropdown.
|
|
19
24
|
*/
|
|
20
25
|
closeEmitter: import("@angular/core").OutputEmitterRef<void>;
|
|
21
26
|
/**
|
|
22
27
|
* Reference to the host element of the component.
|
|
28
|
+
* This provides access to the DOM element of the dropdown content.
|
|
23
29
|
*/
|
|
24
30
|
el: ElementRef<any>;
|
|
25
31
|
/**
|
|
26
32
|
* Input for setting the maximum height of the dropdown.
|
|
27
|
-
* Defaults to '300px'.
|
|
33
|
+
* Defaults to '300px'. This controls the vertical size of the dropdown.
|
|
28
34
|
*/
|
|
29
35
|
readonly maxHeight: import("@angular/core").InputSignal<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Reference to the CDK Listbox directive.
|
|
38
|
+
* This is used to manage the options and their selection state.
|
|
39
|
+
*/
|
|
40
|
+
listBox: CdkListbox<any>;
|
|
41
|
+
/**
|
|
42
|
+
* Reference to the list of options in the dropdown.
|
|
43
|
+
* This is a collection of `SelectOptionComponent` instances representing the available options.
|
|
44
|
+
*/
|
|
45
|
+
readonly options: import("@angular/core").Signal<readonly SelectOptionComponent[]>;
|
|
30
46
|
/**
|
|
31
47
|
* Handles changes to the selected value in the listbox.
|
|
32
|
-
*
|
|
48
|
+
* This method updates the `value` signal, emits the `closeEmitter` event,
|
|
49
|
+
* and ensures the parent component is notified of the selection change.
|
|
33
50
|
*
|
|
34
|
-
* @param
|
|
51
|
+
* @param value - The new array of selected values.
|
|
35
52
|
*/
|
|
36
|
-
handleValueChange(
|
|
53
|
+
handleValueChange(value: string[]): void;
|
|
37
54
|
static ɵfac: i0.ɵɵFactoryDeclaration<SelectContentComponent, never>;
|
|
38
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<SelectContentComponent, "ul[b-select-content]", never, { "maxHeight": { "alias": "maxHeight"; "required": false; "isSignal": true; }; }, { "closeEmitter": "closeEmitter"; },
|
|
55
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<SelectContentComponent, "ul[b-select-content]", never, { "maxHeight": { "alias": "maxHeight"; "required": false; "isSignal": true; }; }, { "closeEmitter": "closeEmitter"; }, ["options"], ["*"], true, [{ directive: typeof i1.CdkListbox; inputs: { "cdkListboxValue": "cdkListboxValue"; }; outputs: { "cdkListboxValueChange": "cdkListboxValueChange"; }; }]>;
|
|
39
56
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CdkOption } from '@angular/cdk/listbox';
|
|
2
|
+
import { ElementRef } from '@angular/core';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
import * as i1 from "@angular/cdk/listbox";
|
|
5
|
+
/**
|
|
6
|
+
* Component representing an individual option in a select dropdown.
|
|
7
|
+
* This component integrates with Angular CDK Option to manage the option's state and behavior.
|
|
8
|
+
*/
|
|
9
|
+
export declare class SelectOptionComponent {
|
|
10
|
+
/**
|
|
11
|
+
* The `ElementRef` of the select option.
|
|
12
|
+
* This provides direct access to the DOM element of the option.
|
|
13
|
+
*/
|
|
14
|
+
el: ElementRef<any>;
|
|
15
|
+
/**
|
|
16
|
+
* The `CdkOption` instance associated with this select option.
|
|
17
|
+
* This provides methods and properties for managing the option's state, such as selection and value.
|
|
18
|
+
*/
|
|
19
|
+
option: CdkOption<any>;
|
|
20
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SelectOptionComponent, never>;
|
|
21
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<SelectOptionComponent, "li[b-select-option]", never, {}, {}, never, ["*"], true, [{ directive: typeof i1.CdkOption; inputs: { "cdkOption": "value"; }; outputs: {}; }]>;
|
|
22
|
+
}
|
|
@@ -1,36 +1,37 @@
|
|
|
1
|
+
import { OnInit } from '@angular/core';
|
|
1
2
|
import { SelectContentComponent } from './select-content.component';
|
|
2
3
|
import { Button } from '../button/button.component';
|
|
4
|
+
import { ControlValueAccessor } from '@angular/forms';
|
|
3
5
|
import * as i0 from "@angular/core";
|
|
4
6
|
/**
|
|
5
7
|
* Component representing a custom select dropdown.
|
|
6
|
-
*
|
|
8
|
+
* This component provides a button to toggle the dropdown and displays the selected option(s).
|
|
7
9
|
*/
|
|
8
|
-
export declare class SelectComponent {
|
|
10
|
+
export declare class SelectComponent implements OnInit, ControlValueAccessor {
|
|
9
11
|
/**
|
|
10
12
|
* Placeholder text displayed when no option is selected.
|
|
11
13
|
* Defaults to 'Select an option'.
|
|
12
14
|
*/
|
|
13
15
|
readonly placeholder: import("@angular/core").InputSignal<string>;
|
|
14
16
|
/**
|
|
15
|
-
* Signal indicating whether the dropdown is open.
|
|
17
|
+
* Signal indicating whether the dropdown is currently open.
|
|
16
18
|
*/
|
|
17
19
|
readonly isOpen: import("@angular/core").WritableSignal<boolean>;
|
|
18
20
|
/**
|
|
19
21
|
* Reference to the button element used to toggle the dropdown.
|
|
22
|
+
* This is used for managing focus and interactions.
|
|
20
23
|
*/
|
|
21
24
|
readonly button: import("@angular/core").Signal<Button | undefined>;
|
|
22
25
|
/**
|
|
23
26
|
* Reference to the content component of the dropdown.
|
|
27
|
+
* This contains the list of selectable options.
|
|
24
28
|
*/
|
|
25
|
-
readonly
|
|
29
|
+
readonly selectContent: import("@angular/core").Signal<SelectContentComponent | undefined>;
|
|
26
30
|
/**
|
|
27
31
|
* Computed signal representing the selected values from the dropdown.
|
|
32
|
+
* This is linked to the value of the `SelectContentComponent`.
|
|
28
33
|
*/
|
|
29
|
-
readonly value: import("@angular/core").
|
|
30
|
-
/**
|
|
31
|
-
* Computed signal representing the content of the selected option.
|
|
32
|
-
*/
|
|
33
|
-
readonly content: import("@angular/core").Signal<string | undefined>;
|
|
34
|
+
readonly value: import("@angular/core").WritableSignal<string[] | undefined>;
|
|
34
35
|
/**
|
|
35
36
|
* Input for setting the maximum width of the dropdown.
|
|
36
37
|
* Defaults to '100%'.
|
|
@@ -38,29 +39,77 @@ export declare class SelectComponent {
|
|
|
38
39
|
readonly maxWidth: import("@angular/core").InputSignal<string>;
|
|
39
40
|
/**
|
|
40
41
|
* Computed signal for the width of the button element.
|
|
42
|
+
* This is used to set the width of the dropdown overlay.
|
|
41
43
|
*/
|
|
42
44
|
readonly buttonWidth: import("@angular/core").Signal<any>;
|
|
43
|
-
/**
|
|
44
|
-
* Model indicating whether the select component is invalid.
|
|
45
|
-
*/
|
|
46
|
-
readonly invalid: import("@angular/core").ModelSignal<boolean>;
|
|
47
45
|
/**
|
|
48
46
|
* Model indicating whether the select component is disabled.
|
|
47
|
+
* When disabled, the dropdown cannot be opened or interacted with.
|
|
49
48
|
*/
|
|
50
49
|
readonly disabled: import("@angular/core").ModelSignal<boolean>;
|
|
51
|
-
constructor();
|
|
52
50
|
/**
|
|
53
|
-
*
|
|
51
|
+
* Computed signal representing the options available in the dropdown.
|
|
52
|
+
* This retrieves the options from the `SelectContentComponent`.
|
|
53
|
+
*/
|
|
54
|
+
readonly options: import("@angular/core").Signal<readonly import("@basis-ng/primitives").SelectOptionComponent[] | undefined>;
|
|
55
|
+
/**
|
|
56
|
+
* Computed signal representing the content of the selected option(s).
|
|
57
|
+
* If no option is selected, it returns the placeholder text.
|
|
58
|
+
*/
|
|
59
|
+
readonly content: import("@angular/core").Signal<string | undefined>;
|
|
60
|
+
/**
|
|
61
|
+
* Lifecycle hook that is called after the component is initialized.
|
|
62
|
+
* It sets up the necessary subscriptions for handling value changes.
|
|
63
|
+
*/
|
|
64
|
+
ngOnInit(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Subscribes to the `closeEmitter` of the `SelectContentComponent` to handle
|
|
67
|
+
* changes to the selected value. This ensures the dropdown closes and the
|
|
68
|
+
* value is propagated to Angular Forms.
|
|
54
69
|
*/
|
|
55
70
|
handleSelectedValueChange(): void;
|
|
56
71
|
/**
|
|
57
72
|
* Opens the dropdown and focuses the listbox.
|
|
73
|
+
* This method sets the `isOpen` signal to `true` and ensures the listbox gains focus.
|
|
58
74
|
*/
|
|
59
75
|
open(): void;
|
|
60
76
|
/**
|
|
61
77
|
* Closes the dropdown and focuses the button.
|
|
78
|
+
* This method sets the `isOpen` signal to `false` and ensures the button regains focus.
|
|
62
79
|
*/
|
|
63
80
|
close(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Callback function to propagate changes to the model.
|
|
83
|
+
* This is called whenever the value changes.
|
|
84
|
+
*/
|
|
85
|
+
private onChange;
|
|
86
|
+
/**
|
|
87
|
+
* Callback function to mark the component as touched.
|
|
88
|
+
* This is called when the component loses focus.
|
|
89
|
+
*/
|
|
90
|
+
private onTouched;
|
|
91
|
+
/**
|
|
92
|
+
* Writes a new value to the component.
|
|
93
|
+
* This method is called by Angular Forms to update the value of the select component.
|
|
94
|
+
* @param value - The new value to set.
|
|
95
|
+
*/
|
|
96
|
+
writeValue(value: string[]): void;
|
|
97
|
+
/**
|
|
98
|
+
* Registers a callback function to be called when the value changes.
|
|
99
|
+
* @param fn - The callback function.
|
|
100
|
+
*/
|
|
101
|
+
registerOnChange(fn: (value: string[]) => void): void;
|
|
102
|
+
/**
|
|
103
|
+
* Registers a callback function to be called when the component is touched.
|
|
104
|
+
* @param fn - The callback function.
|
|
105
|
+
*/
|
|
106
|
+
registerOnTouched(fn: () => void): void;
|
|
107
|
+
/**
|
|
108
|
+
* Sets the disabled state of the component.
|
|
109
|
+
* This method is called by Angular Forms to enable or disable the component.
|
|
110
|
+
* @param isDisabled - A boolean indicating whether the component should be disabled.
|
|
111
|
+
*/
|
|
112
|
+
setDisabledState(isDisabled: boolean): void;
|
|
64
113
|
static ɵfac: i0.ɵɵFactoryDeclaration<SelectComponent, never>;
|
|
65
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<SelectComponent, "b-select", never, { "placeholder": { "alias": "placeholder"; "required": false; "isSignal": true; }; "maxWidth": { "alias": "maxWidth"; "required": false; "isSignal": true; }; "
|
|
114
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<SelectComponent, "b-select", never, { "placeholder": { "alias": "placeholder"; "required": false; "isSignal": true; }; "maxWidth": { "alias": "maxWidth"; "required": false; "isSignal": true; }; "disabled": { "alias": "disabled"; "required": false; "isSignal": true; }; }, { "disabled": "disabledChange"; }, ["selectContent"], ["*"], true, never>;
|
|
66
115
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { signal, inject, RendererFactory2, Injectable, input, Component, ElementRef, TemplateRef, Directive, computed, model, output, contentChildren, viewChild, Renderer2, effect, HostListener, contentChild, afterNextRender, afterRenderEffect
|
|
2
|
+
import { signal, inject, RendererFactory2, Injectable, input, Component, ElementRef, TemplateRef, Directive, computed, model, output, contentChildren, viewChild, Renderer2, effect, HostListener, contentChild, linkedSignal, forwardRef, afterNextRender, afterRenderEffect } from '@angular/core';
|
|
3
3
|
import { NgStyle, NgClass, CommonModule } from '@angular/common';
|
|
4
4
|
import { DomSanitizer } from '@angular/platform-browser';
|
|
5
5
|
import { icons, createElement } from 'lucide';
|
|
6
|
-
import { NgModel, ControlContainer } from '@angular/forms';
|
|
6
|
+
import { NgModel, NG_VALUE_ACCESSOR, ControlContainer } from '@angular/forms';
|
|
7
7
|
import { CdkConnectedOverlay, CdkOverlayOrigin } from '@angular/cdk/overlay';
|
|
8
8
|
import * as i1 from '@angular/cdk/listbox';
|
|
9
|
-
import { CdkListbox } from '@angular/cdk/listbox';
|
|
9
|
+
import { CdkOption, CdkListbox } from '@angular/cdk/listbox';
|
|
10
10
|
import * as i1$1 from '@angular/cdk/drag-drop';
|
|
11
11
|
import { CdkDrag, CdkDragHandle, CdkDropList, CdkDropListGroup } from '@angular/cdk/drag-drop';
|
|
12
12
|
import * as i1$2 from '@angular/cdk/menu';
|
|
@@ -537,46 +537,92 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.7", ngImpor
|
|
|
537
537
|
}]
|
|
538
538
|
}] });
|
|
539
539
|
|
|
540
|
+
/**
|
|
541
|
+
* Component representing an individual option in a select dropdown.
|
|
542
|
+
* This component integrates with Angular CDK Option to manage the option's state and behavior.
|
|
543
|
+
*/
|
|
544
|
+
class SelectOptionComponent {
|
|
545
|
+
/**
|
|
546
|
+
* The `ElementRef` of the select option.
|
|
547
|
+
* This provides direct access to the DOM element of the option.
|
|
548
|
+
*/
|
|
549
|
+
el = inject(ElementRef);
|
|
550
|
+
/**
|
|
551
|
+
* The `CdkOption` instance associated with this select option.
|
|
552
|
+
* This provides methods and properties for managing the option's state, such as selection and value.
|
|
553
|
+
*/
|
|
554
|
+
option = inject(CdkOption);
|
|
555
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.7", ngImport: i0, type: SelectOptionComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
556
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.7", type: SelectOptionComponent, isStandalone: true, selector: "li[b-select-option]", hostDirectives: [{ directive: i1.CdkOption, inputs: ["cdkOption", "value"] }], ngImport: i0, template: `<ng-content />`, isInline: true });
|
|
557
|
+
}
|
|
558
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.7", ngImport: i0, type: SelectOptionComponent, decorators: [{
|
|
559
|
+
type: Component,
|
|
560
|
+
args: [{
|
|
561
|
+
selector: 'li[b-select-option]',
|
|
562
|
+
imports: [],
|
|
563
|
+
template: `<ng-content />`,
|
|
564
|
+
hostDirectives: [
|
|
565
|
+
{
|
|
566
|
+
directive: CdkOption,
|
|
567
|
+
inputs: ['cdkOption: value'],
|
|
568
|
+
},
|
|
569
|
+
],
|
|
570
|
+
}]
|
|
571
|
+
}] });
|
|
572
|
+
|
|
540
573
|
/**
|
|
541
574
|
* Component representing the content of a select dropdown.
|
|
542
|
-
*
|
|
575
|
+
* This component integrates with Angular CDK Listbox to manage options and their selection.
|
|
543
576
|
*/
|
|
544
577
|
class SelectContentComponent {
|
|
545
578
|
/**
|
|
546
579
|
* Signal representing the selected values in the listbox.
|
|
580
|
+
* This is an array of strings corresponding to the selected option values.
|
|
547
581
|
*/
|
|
548
582
|
value = signal([]);
|
|
549
583
|
/**
|
|
550
|
-
* Signal representing the content of the selected option.
|
|
584
|
+
* Signal representing the content of the selected option(s).
|
|
585
|
+
* This is a string that can be used to display the selected option(s).
|
|
551
586
|
*/
|
|
552
587
|
content = signal('');
|
|
553
588
|
/**
|
|
554
589
|
* Event emitter triggered when the dropdown should close.
|
|
590
|
+
* This is used to notify the parent component to close the dropdown.
|
|
555
591
|
*/
|
|
556
592
|
closeEmitter = output();
|
|
557
593
|
/**
|
|
558
594
|
* Reference to the host element of the component.
|
|
595
|
+
* This provides access to the DOM element of the dropdown content.
|
|
559
596
|
*/
|
|
560
597
|
el = inject(ElementRef);
|
|
561
598
|
/**
|
|
562
599
|
* Input for setting the maximum height of the dropdown.
|
|
563
|
-
* Defaults to '300px'.
|
|
600
|
+
* Defaults to '300px'. This controls the vertical size of the dropdown.
|
|
564
601
|
*/
|
|
565
602
|
maxHeight = input('300px');
|
|
603
|
+
/**
|
|
604
|
+
* Reference to the CDK Listbox directive.
|
|
605
|
+
* This is used to manage the options and their selection state.
|
|
606
|
+
*/
|
|
607
|
+
listBox = inject(CdkListbox);
|
|
608
|
+
/**
|
|
609
|
+
* Reference to the list of options in the dropdown.
|
|
610
|
+
* This is a collection of `SelectOptionComponent` instances representing the available options.
|
|
611
|
+
*/
|
|
612
|
+
options = contentChildren(SelectOptionComponent);
|
|
566
613
|
/**
|
|
567
614
|
* Handles changes to the selected value in the listbox.
|
|
568
|
-
*
|
|
615
|
+
* This method updates the `value` signal, emits the `closeEmitter` event,
|
|
616
|
+
* and ensures the parent component is notified of the selection change.
|
|
569
617
|
*
|
|
570
|
-
* @param
|
|
618
|
+
* @param value - The new array of selected values.
|
|
571
619
|
*/
|
|
572
|
-
handleValueChange(
|
|
573
|
-
|
|
574
|
-
this.content.set($event.option.element.innerText);
|
|
575
|
-
this.value.set(value.length === 0 || (value.length === 1 && value[0] === '') ? [] : value);
|
|
620
|
+
handleValueChange(value) {
|
|
621
|
+
this.value.set(value);
|
|
576
622
|
this.closeEmitter.emit();
|
|
577
623
|
}
|
|
578
624
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.7", ngImport: i0, type: SelectContentComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
579
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.
|
|
625
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "19.2.7", type: SelectContentComponent, isStandalone: true, selector: "ul[b-select-content]", inputs: { maxHeight: { classPropertyName: "maxHeight", publicName: "maxHeight", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { closeEmitter: "closeEmitter" }, host: { listeners: { "cdkListboxValueChange": "handleValueChange($event.value)" }, properties: { "cdkListboxValue": "value()", "style.max-height": "maxHeight()" } }, queries: [{ propertyName: "options", predicate: SelectOptionComponent, isSignal: true }], hostDirectives: [{ directive: i1.CdkListbox, inputs: ["cdkListboxValue", "cdkListboxValue"], outputs: ["cdkListboxValueChange", "cdkListboxValueChange"] }], ngImport: i0, template: `<ng-content />`, isInline: true });
|
|
580
626
|
}
|
|
581
627
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.7", ngImport: i0, type: SelectContentComponent, decorators: [{
|
|
582
628
|
type: Component,
|
|
@@ -593,7 +639,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.7", ngImpor
|
|
|
593
639
|
],
|
|
594
640
|
host: {
|
|
595
641
|
'[cdkListboxValue]': 'value()',
|
|
596
|
-
'(cdkListboxValueChange)': 'handleValueChange($event)',
|
|
642
|
+
'(cdkListboxValueChange)': 'handleValueChange($event.value)',
|
|
597
643
|
'[style.max-height]': 'maxHeight()',
|
|
598
644
|
},
|
|
599
645
|
}]
|
|
@@ -601,7 +647,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.7", ngImpor
|
|
|
601
647
|
|
|
602
648
|
/**
|
|
603
649
|
* Component representing a custom select dropdown.
|
|
604
|
-
*
|
|
650
|
+
* This component provides a button to toggle the dropdown and displays the selected option(s).
|
|
605
651
|
*/
|
|
606
652
|
class SelectComponent {
|
|
607
653
|
/**
|
|
@@ -610,25 +656,24 @@ class SelectComponent {
|
|
|
610
656
|
*/
|
|
611
657
|
placeholder = input('Select an option');
|
|
612
658
|
/**
|
|
613
|
-
* Signal indicating whether the dropdown is open.
|
|
659
|
+
* Signal indicating whether the dropdown is currently open.
|
|
614
660
|
*/
|
|
615
661
|
isOpen = signal(false);
|
|
616
662
|
/**
|
|
617
663
|
* Reference to the button element used to toggle the dropdown.
|
|
664
|
+
* This is used for managing focus and interactions.
|
|
618
665
|
*/
|
|
619
666
|
button = viewChild(Button);
|
|
620
667
|
/**
|
|
621
668
|
* Reference to the content component of the dropdown.
|
|
669
|
+
* This contains the list of selectable options.
|
|
622
670
|
*/
|
|
623
|
-
|
|
671
|
+
selectContent = contentChild(SelectContentComponent);
|
|
624
672
|
/**
|
|
625
673
|
* Computed signal representing the selected values from the dropdown.
|
|
674
|
+
* This is linked to the value of the `SelectContentComponent`.
|
|
626
675
|
*/
|
|
627
|
-
value =
|
|
628
|
-
/**
|
|
629
|
-
* Computed signal representing the content of the selected option.
|
|
630
|
-
*/
|
|
631
|
-
content = computed(() => this.listBox()?.content());
|
|
676
|
+
value = linkedSignal(() => this.selectContent()?.value());
|
|
632
677
|
/**
|
|
633
678
|
* Input for setting the maximum width of the dropdown.
|
|
634
679
|
* Defaults to '100%'.
|
|
@@ -636,44 +681,128 @@ class SelectComponent {
|
|
|
636
681
|
maxWidth = input('100%');
|
|
637
682
|
/**
|
|
638
683
|
* Computed signal for the width of the button element.
|
|
684
|
+
* This is used to set the width of the dropdown overlay.
|
|
639
685
|
*/
|
|
640
686
|
buttonWidth = computed(() => this.button()?.el.nativeElement.offsetWidth);
|
|
641
|
-
/**
|
|
642
|
-
* Model indicating whether the select component is invalid.
|
|
643
|
-
*/
|
|
644
|
-
invalid = model(false);
|
|
645
687
|
/**
|
|
646
688
|
* Model indicating whether the select component is disabled.
|
|
689
|
+
* When disabled, the dropdown cannot be opened or interacted with.
|
|
647
690
|
*/
|
|
648
691
|
disabled = model(false);
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
692
|
+
/**
|
|
693
|
+
* Computed signal representing the options available in the dropdown.
|
|
694
|
+
* This retrieves the options from the `SelectContentComponent`.
|
|
695
|
+
*/
|
|
696
|
+
options = computed(() => this.selectContent()?.options());
|
|
697
|
+
/**
|
|
698
|
+
* Computed signal representing the content of the selected option(s).
|
|
699
|
+
* If no option is selected, it returns the placeholder text.
|
|
700
|
+
*/
|
|
701
|
+
content = computed(() => {
|
|
702
|
+
const selected = this.value();
|
|
703
|
+
if (selected && selected.length > 0) {
|
|
704
|
+
return this.options()?.reduce((acc, option) => {
|
|
705
|
+
if (selected.includes(option.option.value)) {
|
|
706
|
+
return acc
|
|
707
|
+
? acc + ', ' + option.el.nativeElement.innerText
|
|
708
|
+
: option.el.nativeElement.innerText;
|
|
709
|
+
}
|
|
710
|
+
return acc;
|
|
711
|
+
}, '');
|
|
712
|
+
}
|
|
713
|
+
else {
|
|
714
|
+
return this.placeholder();
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
/**
|
|
718
|
+
* Lifecycle hook that is called after the component is initialized.
|
|
719
|
+
* It sets up the necessary subscriptions for handling value changes.
|
|
720
|
+
*/
|
|
721
|
+
ngOnInit() {
|
|
722
|
+
this.handleSelectedValueChange();
|
|
654
723
|
}
|
|
655
724
|
/**
|
|
656
|
-
*
|
|
725
|
+
* Subscribes to the `closeEmitter` of the `SelectContentComponent` to handle
|
|
726
|
+
* changes to the selected value. This ensures the dropdown closes and the
|
|
727
|
+
* value is propagated to Angular Forms.
|
|
657
728
|
*/
|
|
658
729
|
handleSelectedValueChange() {
|
|
659
|
-
this.
|
|
730
|
+
this.selectContent()?.closeEmitter.subscribe(() => {
|
|
731
|
+
this.onChange(this.value()); // Notify Angular Forms about the change
|
|
732
|
+
this.onTouched(); // Mark the component as touched
|
|
733
|
+
this.close(); // Close the dropdown
|
|
734
|
+
});
|
|
660
735
|
}
|
|
661
736
|
/**
|
|
662
737
|
* Opens the dropdown and focuses the listbox.
|
|
738
|
+
* This method sets the `isOpen` signal to `true` and ensures the listbox gains focus.
|
|
663
739
|
*/
|
|
664
740
|
open() {
|
|
665
741
|
this.isOpen.set(true);
|
|
666
|
-
setTimeout(() => this.
|
|
742
|
+
setTimeout(() => this.selectContent()?.el.nativeElement.focus(), 0);
|
|
667
743
|
}
|
|
668
744
|
/**
|
|
669
745
|
* Closes the dropdown and focuses the button.
|
|
746
|
+
* This method sets the `isOpen` signal to `false` and ensures the button regains focus.
|
|
670
747
|
*/
|
|
671
748
|
close() {
|
|
672
749
|
setTimeout(() => this.button()?.el.nativeElement.focus(), 0);
|
|
673
750
|
this.isOpen.set(false);
|
|
674
751
|
}
|
|
752
|
+
// Control Value Accessor methods
|
|
753
|
+
/**
|
|
754
|
+
* Callback function to propagate changes to the model.
|
|
755
|
+
* This is called whenever the value changes.
|
|
756
|
+
*/
|
|
757
|
+
onChange = () => undefined;
|
|
758
|
+
/**
|
|
759
|
+
* Callback function to mark the component as touched.
|
|
760
|
+
* This is called when the component loses focus.
|
|
761
|
+
*/
|
|
762
|
+
onTouched = () => undefined;
|
|
763
|
+
/**
|
|
764
|
+
* Writes a new value to the component.
|
|
765
|
+
* This method is called by Angular Forms to update the value of the select component.
|
|
766
|
+
* @param value - The new value to set.
|
|
767
|
+
*/
|
|
768
|
+
writeValue(value) {
|
|
769
|
+
if (value) {
|
|
770
|
+
value.forEach(value => {
|
|
771
|
+
this.selectContent()?.listBox?.selectValue(value);
|
|
772
|
+
});
|
|
773
|
+
this.value.set(value);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Registers a callback function to be called when the value changes.
|
|
778
|
+
* @param fn - The callback function.
|
|
779
|
+
*/
|
|
780
|
+
registerOnChange(fn) {
|
|
781
|
+
this.onChange = fn;
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Registers a callback function to be called when the component is touched.
|
|
785
|
+
* @param fn - The callback function.
|
|
786
|
+
*/
|
|
787
|
+
registerOnTouched(fn) {
|
|
788
|
+
this.onTouched = fn;
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* Sets the disabled state of the component.
|
|
792
|
+
* This method is called by Angular Forms to enable or disable the component.
|
|
793
|
+
* @param isDisabled - A boolean indicating whether the component should be disabled.
|
|
794
|
+
*/
|
|
795
|
+
setDisabledState(isDisabled) {
|
|
796
|
+
this.disabled.set(isDisabled);
|
|
797
|
+
}
|
|
675
798
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.7", ngImport: i0, type: SelectComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
676
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "19.2.7", type: SelectComponent, isStandalone: true, selector: "b-select", inputs: { placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, maxWidth: { classPropertyName: "maxWidth", publicName: "maxWidth", isSignal: true, isRequired: false, transformFunction: null },
|
|
799
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "19.2.7", type: SelectComponent, isStandalone: true, selector: "b-select", inputs: { placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, maxWidth: { classPropertyName: "maxWidth", publicName: "maxWidth", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { disabled: "disabledChange" }, host: { properties: { "style.max-width": "maxWidth()", "class.disabled": "disabled()" } }, providers: [
|
|
800
|
+
{
|
|
801
|
+
provide: NG_VALUE_ACCESSOR,
|
|
802
|
+
useExisting: forwardRef(() => SelectComponent),
|
|
803
|
+
multi: true,
|
|
804
|
+
},
|
|
805
|
+
], queries: [{ propertyName: "selectContent", first: true, predicate: SelectContentComponent, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "button", first: true, predicate: Button, descendants: true, isSignal: true }], ngImport: i0, template: ` <button
|
|
677
806
|
b-button
|
|
678
807
|
variant="outlined"
|
|
679
808
|
(click)="isOpen() ? close() : open()"
|
|
@@ -682,7 +811,7 @@ class SelectComponent {
|
|
|
682
811
|
cdkOverlayOrigin
|
|
683
812
|
[activeEnabled]="false"
|
|
684
813
|
#trigger="cdkOverlayOrigin">
|
|
685
|
-
{{
|
|
814
|
+
{{ content() }}
|
|
686
815
|
<i b-icon icon="ChevronDown" [size]="20"></i>
|
|
687
816
|
</button>
|
|
688
817
|
<ng-template
|
|
@@ -727,7 +856,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.7", ngImpor
|
|
|
727
856
|
cdkOverlayOrigin
|
|
728
857
|
[activeEnabled]="false"
|
|
729
858
|
#trigger="cdkOverlayOrigin">
|
|
730
|
-
{{
|
|
859
|
+
{{ content() }}
|
|
731
860
|
<i b-icon icon="ChevronDown" [size]="20"></i>
|
|
732
861
|
</button>
|
|
733
862
|
<ng-template
|
|
@@ -759,11 +888,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.7", ngImpor
|
|
|
759
888
|
</ng-template>`,
|
|
760
889
|
host: {
|
|
761
890
|
'[style.max-width]': 'maxWidth()',
|
|
762
|
-
'[class.ng-invalid]': 'invalid()',
|
|
763
891
|
'[class.disabled]': 'disabled()',
|
|
764
892
|
},
|
|
893
|
+
providers: [
|
|
894
|
+
{
|
|
895
|
+
provide: NG_VALUE_ACCESSOR,
|
|
896
|
+
useExisting: forwardRef(() => SelectComponent),
|
|
897
|
+
multi: true,
|
|
898
|
+
},
|
|
899
|
+
],
|
|
765
900
|
}]
|
|
766
|
-
}]
|
|
901
|
+
}] });
|
|
767
902
|
|
|
768
903
|
class Option {
|
|
769
904
|
/**
|
|
@@ -2568,5 +2703,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.7", ngImpor
|
|
|
2568
2703
|
* Generated bundle index. Do not edit.
|
|
2569
2704
|
*/
|
|
2570
2705
|
|
|
2571
|
-
export { Alert, AttachedBox, Badge, BottomSheet, Button, ButtonGroup, Checkbox, ColorPicker, Icon, InViewportDirective, InViewportService, Input, InputGroup, Label, LazyContentDirective, Menu, MenuItemCheckboxComponent, MenuItemComponent, MenuItemRadioComponent, MenuLabel, MenuTrigger, Option, Range, ResponsiveService, Row, RowItem, Search, SelectComponent, SideSheet, Spinner, Switch, Tab, Table, Tabs, Textarea, ThemeService, TooltipComponent, Tree, TreeNode };
|
|
2706
|
+
export { Alert, AttachedBox, Badge, BottomSheet, Button, ButtonGroup, Checkbox, ColorPicker, Icon, InViewportDirective, InViewportService, Input, InputGroup, Label, LazyContentDirective, Menu, MenuItemCheckboxComponent, MenuItemComponent, MenuItemRadioComponent, MenuLabel, MenuTrigger, Option, Range, ResponsiveService, Row, RowItem, Search, SelectComponent, SelectContentComponent, SelectOptionComponent, SideSheet, Spinner, Switch, Tab, Table, Tabs, Textarea, ThemeService, TooltipComponent, Tree, TreeNode };
|
|
2572
2707
|
//# sourceMappingURL=basis-ng-primitives.mjs.map
|