@helsevestikt/hviktor-angular 0.0.11 → 0.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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { EventEmitter, AfterViewInit, OnChanges } from '@angular/core';
|
|
3
|
-
import { FormGroup, ReactiveFormsModule } from '@angular/forms';
|
|
2
|
+
import { EventEmitter, AfterViewInit, OnChanges, OnInit, OnDestroy } from '@angular/core';
|
|
3
|
+
import { FormGroup, ValidatorFn, ReactiveFormsModule } from '@angular/forms';
|
|
4
|
+
import { Placement } from '@floating-ui/dom';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Alert provides users with information that is especially important for them to see and understand.
|
|
@@ -463,6 +464,11 @@ declare class HviErrorSummary {
|
|
|
463
464
|
static ɵcmp: i0.ɵɵComponentDeclaration<HviErrorSummary, "hvi-error-summary", never, { "heading": { "alias": "heading"; "required": false; }; "headingLevel": { "alias": "headingLevel"; "required": false; }; "errors": { "alias": "errors"; "required": false; }; "form": { "alias": "form"; "required": false; }; "messages": { "alias": "messages"; "required": false; }; "idMap": { "alias": "idMap"; "required": false; }; "errorPriority": { "alias": "errorPriority"; "required": false; }; "headingId": { "alias": "headingId"; "required": false; }; "showWhen": { "alias": "showWhen"; "required": false; }; }, {}, never, never, true, never>;
|
|
464
465
|
}
|
|
465
466
|
|
|
467
|
+
declare function fieldObserver(fieldElement: HTMLElement | null): (() => void) | undefined;
|
|
468
|
+
declare const isElement: (node: Node) => node is Element;
|
|
469
|
+
declare const isLabel: (node: Node) => node is HTMLLabelElement;
|
|
470
|
+
declare const isInputLike: (node: unknown) => node is HTMLInputElement;
|
|
471
|
+
|
|
466
472
|
/**
|
|
467
473
|
* Decorative affix container displayed alongside a text input.
|
|
468
474
|
*
|
|
@@ -547,11 +553,6 @@ declare class HviField implements AfterViewInit {
|
|
|
547
553
|
static ɵcmp: i0.ɵɵComponentDeclaration<HviField, "hvi-field", never, { "position": { "alias": "position"; "required": false; }; }, {}, never, ["*"], true, never>;
|
|
548
554
|
}
|
|
549
555
|
|
|
550
|
-
declare function fieldObserver(fieldElement: HTMLElement | null): (() => void) | undefined;
|
|
551
|
-
declare const isElement: (node: Node) => node is Element;
|
|
552
|
-
declare const isLabel: (node: Node) => node is HTMLLabelElement;
|
|
553
|
-
declare const isInputLike: (node: unknown) => node is HTMLInputElement;
|
|
554
|
-
|
|
555
556
|
/**
|
|
556
557
|
* Fieldset is used to group and label fields that naturally belong together, such as date fields or address fields.
|
|
557
558
|
* The component helps organize information, make forms more manageable, and improve accessibility for screen readers.
|
|
@@ -585,7 +586,9 @@ declare class HviFieldset {
|
|
|
585
586
|
|
|
586
587
|
type HviAriaRole = 'switch' | 'button' | 'checkbox' | 'radio' | 'textbox' | 'searchbox' | string;
|
|
587
588
|
declare class HviInput {
|
|
589
|
+
/** Supported input types */
|
|
588
590
|
type?: 'number' | 'hidden' | 'color' | 'checkbox' | 'date' | 'datetime-local' | 'email' | 'file' | 'month' | 'password' | 'radio' | 'search' | 'tel' | 'text' | 'time' | 'url' | 'week';
|
|
591
|
+
/** Set size attribute on input element */
|
|
589
592
|
size?: number;
|
|
590
593
|
/** Set role, e.g. `switch` when `checkbox` or `radio` */
|
|
591
594
|
role?: HviAriaRole;
|
|
@@ -653,6 +656,150 @@ declare class HviControlInvalid {
|
|
|
653
656
|
static ɵdir: i0.ɵɵDirectiveDeclaration<HviControlInvalid, "[hviControlInvalid]", never, {}, {}, never, never, true, never>;
|
|
654
657
|
}
|
|
655
658
|
|
|
659
|
+
/**
|
|
660
|
+
* A bundle that pairs a validator function with its error key and message.
|
|
661
|
+
* This enables defining validation rules and messages in one place.
|
|
662
|
+
*/
|
|
663
|
+
interface HviValidatorBundle {
|
|
664
|
+
/** The Angular validator function */
|
|
665
|
+
validator: ValidatorFn;
|
|
666
|
+
/** The error key (e.g., 'required', 'minlength') */
|
|
667
|
+
key: string;
|
|
668
|
+
/** The user-facing error message */
|
|
669
|
+
message: string;
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Result of processing validator bundles - ready to use with FormControl and hviValidationMessage.
|
|
673
|
+
*/
|
|
674
|
+
interface HviValidatorConfig {
|
|
675
|
+
/** Array of validator functions to pass to FormControl */
|
|
676
|
+
validators: ValidatorFn[];
|
|
677
|
+
/** Messages object to pass to hviValidationMessage */
|
|
678
|
+
messages: HviValidationMessages;
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Extracts validators and messages from an array of validator bundles.
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* ```ts
|
|
685
|
+
* const config = hviValidators([
|
|
686
|
+
* hviRequired('Fornavn er påkrevd'),
|
|
687
|
+
* hviMinLength(2, 'Fornavn må være minst 2 tegn'),
|
|
688
|
+
* ]);
|
|
689
|
+
*
|
|
690
|
+
* form = new FormGroup({
|
|
691
|
+
* firstName: new FormControl('', config.validators),
|
|
692
|
+
* });
|
|
693
|
+
*
|
|
694
|
+
* // In template: [messages]="config.messages"
|
|
695
|
+
* ```
|
|
696
|
+
*/
|
|
697
|
+
declare function hviValidators(bundles: HviValidatorBundle[]): HviValidatorConfig;
|
|
698
|
+
/**
|
|
699
|
+
* Extracts only the validator functions from bundles.
|
|
700
|
+
* Useful when you need just the validators for a FormControl.
|
|
701
|
+
*/
|
|
702
|
+
declare function hviExtractValidators(bundles: HviValidatorBundle[]): ValidatorFn[];
|
|
703
|
+
/**
|
|
704
|
+
* Extracts only the messages from bundles.
|
|
705
|
+
* Useful when you need just the messages object.
|
|
706
|
+
*/
|
|
707
|
+
declare function hviExtractMessages(bundles: HviValidatorBundle[]): HviValidationMessages;
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* Creates a required validator bundle.
|
|
711
|
+
*
|
|
712
|
+
* @example
|
|
713
|
+
* ```ts
|
|
714
|
+
* hviRequired('Dette feltet er påkrevd')
|
|
715
|
+
* ```
|
|
716
|
+
*/
|
|
717
|
+
declare function hviRequired(message: string): HviValidatorBundle;
|
|
718
|
+
/**
|
|
719
|
+
* Creates a requiredTrue validator bundle (for checkboxes that must be checked).
|
|
720
|
+
*
|
|
721
|
+
* @example
|
|
722
|
+
* ```ts
|
|
723
|
+
* hviRequiredTrue('Du må godta vilkårene')
|
|
724
|
+
* ```
|
|
725
|
+
*/
|
|
726
|
+
declare function hviRequiredTrue(message: string): HviValidatorBundle;
|
|
727
|
+
/**
|
|
728
|
+
* Creates a minLength validator bundle.
|
|
729
|
+
*
|
|
730
|
+
* @example
|
|
731
|
+
* ```ts
|
|
732
|
+
* hviMinLength(2, 'Må være minst 2 tegn')
|
|
733
|
+
* ```
|
|
734
|
+
*/
|
|
735
|
+
declare function hviMinLength(length: number, message: string): HviValidatorBundle;
|
|
736
|
+
/**
|
|
737
|
+
* Creates a maxLength validator bundle.
|
|
738
|
+
*
|
|
739
|
+
* @example
|
|
740
|
+
* ```ts
|
|
741
|
+
* hviMaxLength(100, 'Kan ikke være mer enn 100 tegn')
|
|
742
|
+
* ```
|
|
743
|
+
*/
|
|
744
|
+
declare function hviMaxLength(length: number, message: string): HviValidatorBundle;
|
|
745
|
+
/**
|
|
746
|
+
* Creates an email validator bundle.
|
|
747
|
+
*
|
|
748
|
+
* @example
|
|
749
|
+
* ```ts
|
|
750
|
+
* hviEmail('Ugyldig e-postadresse')
|
|
751
|
+
* ```
|
|
752
|
+
*/
|
|
753
|
+
declare function hviEmail(message: string): HviValidatorBundle;
|
|
754
|
+
/**
|
|
755
|
+
* Creates a pattern validator bundle.
|
|
756
|
+
*
|
|
757
|
+
* @example
|
|
758
|
+
* ```ts
|
|
759
|
+
* hviPattern(/^\d+$/, 'Kan kun inneholde tall')
|
|
760
|
+
* ```
|
|
761
|
+
*/
|
|
762
|
+
declare function hviPattern(pattern: string | RegExp, message: string): HviValidatorBundle;
|
|
763
|
+
/**
|
|
764
|
+
* Creates a min value validator bundle.
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* ```ts
|
|
768
|
+
* hviMin(0, 'Må være minst 0')
|
|
769
|
+
* ```
|
|
770
|
+
*/
|
|
771
|
+
declare function hviMin(min: number, message: string): HviValidatorBundle;
|
|
772
|
+
/**
|
|
773
|
+
* Creates a max value validator bundle.
|
|
774
|
+
*
|
|
775
|
+
* @example
|
|
776
|
+
* ```ts
|
|
777
|
+
* hviMax(100, 'Kan ikke være mer enn 100')
|
|
778
|
+
* ```
|
|
779
|
+
*/
|
|
780
|
+
declare function hviMax(max: number, message: string): HviValidatorBundle;
|
|
781
|
+
/**
|
|
782
|
+
* Creates a custom validator bundle with a specified error key.
|
|
783
|
+
* Use this for custom validators or validators not covered by the built-in functions.
|
|
784
|
+
*
|
|
785
|
+
* @example
|
|
786
|
+
* ```ts
|
|
787
|
+
* // Custom validator that checks if value matches a specific format
|
|
788
|
+
* const norwegianPhoneValidator: ValidatorFn = (control) => {
|
|
789
|
+
* const valid = /^(\+47)?\d{8}$/.test(control.value);
|
|
790
|
+
* return valid ? null : { norwegianPhone: true };
|
|
791
|
+
* };
|
|
792
|
+
*
|
|
793
|
+
* hviCustom('norwegianPhone', norwegianPhoneValidator, 'Ugyldig norsk telefonnummer')
|
|
794
|
+
* ```
|
|
795
|
+
*/
|
|
796
|
+
declare function hviCustom(key: string, validator: ValidatorFn, message: string): HviValidatorBundle;
|
|
797
|
+
/**
|
|
798
|
+
* Creates a nullValidator bundle (always valid, useful for conditional validation).
|
|
799
|
+
* Note: This validator always passes, so the message will never be shown.
|
|
800
|
+
*/
|
|
801
|
+
declare function hviNullValidator(): HviValidatorBundle;
|
|
802
|
+
|
|
656
803
|
declare const HviFieldKit: readonly [typeof HviField, typeof HviFieldValidation, typeof HviFieldDescription, typeof HviFieldOptional, typeof HviFieldAffix, typeof HviFieldAffixes];
|
|
657
804
|
declare const HviValidationKit: readonly [typeof ReactiveFormsModule, typeof HviForm, typeof HviControlInvalid, typeof HviValidationMessage];
|
|
658
805
|
declare const HviForms: readonly [typeof ReactiveFormsModule, typeof HviForm, typeof HviControlInvalid, typeof HviValidationMessage, typeof HviField, typeof HviFieldValidation, typeof HviFieldDescription, typeof HviFieldOptional, typeof HviFieldAffix, typeof HviFieldAffixes, typeof HviInput, typeof HviFieldset, typeof HviErrorSummary];
|
|
@@ -774,6 +921,53 @@ declare class HviParagraph {
|
|
|
774
921
|
static ɵdir: i0.ɵɵDirectiveDeclaration<HviParagraph, "p[hviParagraph]", never, { "variant": { "alias": "variant"; "required": false; }; "size": { "alias": "size"; "required": false; }; }, {}, never, never, true, never>;
|
|
775
922
|
}
|
|
776
923
|
|
|
924
|
+
/**
|
|
925
|
+
* @summary
|
|
926
|
+
* Popover vises over andre elementer i grensesnittet og er koblet til et spesifikt element.
|
|
927
|
+
* Den brukes til å vise tilleggsinformasjon, interaktive elementer eller korte forklaringer uten å navigere bort fra siden.
|
|
928
|
+
*
|
|
929
|
+
* @example
|
|
930
|
+
* ```html
|
|
931
|
+
* <button hviButton popovertarget="popover1">Open popover</button>
|
|
932
|
+
* <hvi-popover id="popover1"> Popover content </hvi-popover>
|
|
933
|
+
* ```
|
|
934
|
+
*
|
|
935
|
+
* @see {@link https://designsystemet.no/en/components/docs/popover/code}
|
|
936
|
+
*/
|
|
937
|
+
declare class HviPopover implements OnInit, OnDestroy {
|
|
938
|
+
private el;
|
|
939
|
+
private cleanupAutoUpdate?;
|
|
940
|
+
private boundHandleClick?;
|
|
941
|
+
private boundHandleKeydown?;
|
|
942
|
+
/** Popover type - 'manual' krever manuell lukking, 'auto' lukkes ved klikk utenfor */
|
|
943
|
+
type: 'auto' | 'manual' | 'hint';
|
|
944
|
+
/** Visuell variant */
|
|
945
|
+
variant: 'default' | 'tinted';
|
|
946
|
+
/** Farge-tema */
|
|
947
|
+
color: 'neutral' | 'danger' | 'info' | 'success' | 'warning';
|
|
948
|
+
/** Plassering av popover relativt til trigger */
|
|
949
|
+
placement: Placement;
|
|
950
|
+
/** Aktiver automatisk repositjonering hvis det ikke er plass */
|
|
951
|
+
autoPlacement: boolean;
|
|
952
|
+
/** Event når popover åpnes */
|
|
953
|
+
opened: EventEmitter<void>;
|
|
954
|
+
/** Event når popover lukkes */
|
|
955
|
+
closed: EventEmitter<void>;
|
|
956
|
+
private get popoverElement();
|
|
957
|
+
private get triggerElement();
|
|
958
|
+
ngOnInit(): void;
|
|
959
|
+
ngOnDestroy(): void;
|
|
960
|
+
private setupEventListeners;
|
|
961
|
+
private removeEventListeners;
|
|
962
|
+
private handleBeforeToggle;
|
|
963
|
+
private handleToggle;
|
|
964
|
+
private updatePosition;
|
|
965
|
+
private startAutoUpdate;
|
|
966
|
+
private stopAutoUpdate;
|
|
967
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<HviPopover, never>;
|
|
968
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<HviPopover, "hvi-popover", never, { "type": { "alias": "type"; "required": false; }; "variant": { "alias": "variant"; "required": false; }; "color": { "alias": "color"; "required": false; }; "placement": { "alias": "placement"; "required": false; }; "autoPlacement": { "alias": "autoPlacement"; "required": false; }; }, { "opened": "opened"; "closed": "closed"; }, never, ["*"], true, never>;
|
|
969
|
+
}
|
|
970
|
+
|
|
777
971
|
/**
|
|
778
972
|
* @summary
|
|
779
973
|
* Tag is a label that can be used to categorize items or communicate progress, status, or process. Tags can provide users with a quicker overview of content.
|
|
@@ -796,5 +990,5 @@ declare class HviTag {
|
|
|
796
990
|
static ɵcmp: i0.ɵɵComponentDeclaration<HviTag, "hvi-tag", never, { "variant": { "alias": "variant"; "required": false; }; "size": { "alias": "size"; "required": false; }; "color": { "alias": "color"; "required": false; }; }, {}, never, ["*"], true, never>;
|
|
797
991
|
}
|
|
798
992
|
|
|
799
|
-
export { HviAlert, HviAvatar, HviBadge, HviBadgePosition, HviBreadcrumbs, HviButton, HviCard, HviCardBlock, HviChipButton, HviChipLabel, HviControlInvalid, HviDetails, HviDetailsContent, HviDetailsSummary, HviDialog, HviDialogBlock, HviDivider, HviErrorSummary, HviField, HviFieldAffix, HviFieldAffixes, HviFieldDescription, HviFieldKit, HviFieldOptional, HviFieldValidation, HviFieldset, HviForm, HviForms, HviHeading, HviIcon, HviInput, HviLabel, HviLink, HviList, HviParagraph, HviTag, HviValidationKit, HviValidationMessage, fieldObserver, isElement, isInputLike, isLabel };
|
|
800
|
-
export type { HviErrorSummaryItem, HviErrorSummaryMessages, HviValidationMessages };
|
|
993
|
+
export { HviAlert, HviAvatar, HviBadge, HviBadgePosition, HviBreadcrumbs, HviButton, HviCard, HviCardBlock, HviChipButton, HviChipLabel, HviControlInvalid, HviDetails, HviDetailsContent, HviDetailsSummary, HviDialog, HviDialogBlock, HviDivider, HviErrorSummary, HviField, HviFieldAffix, HviFieldAffixes, HviFieldDescription, HviFieldKit, HviFieldOptional, HviFieldValidation, HviFieldset, HviForm, HviForms, HviHeading, HviIcon, HviInput, HviLabel, HviLink, HviList, HviParagraph, HviPopover, HviTag, HviValidationKit, HviValidationMessage, fieldObserver, hviCustom, hviEmail, hviExtractMessages, hviExtractValidators, hviMax, hviMaxLength, hviMin, hviMinLength, hviNullValidator, hviPattern, hviRequired, hviRequiredTrue, hviValidators, isElement, isInputLike, isLabel };
|
|
994
|
+
export type { HviErrorSummaryItem, HviErrorSummaryMessages, HviValidationMessages, HviValidatorBundle, HviValidatorConfig };
|