1.0.8 • Published 2 years ago

@dzik/mentions v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Angular @Mentions Component forked from @flxng/mentions with some fixes and improvements

@dzik/mentions

Flexible, lightweight, easy-to-use, without external dependencies - Mentions component for Angular.

Docs and Demo

https://flxng.codeeve.com/#/mentions

Mentions GIF

Getting Started

Installation:

$ npm i @dzik/mentions

After importing the module the lib is ready to use:

import { MentionsModule } from '@dzik/mentions';

@NgModule({
  imports: [MentionsModule],
  declarations: [],
})
export class DemoModule {}

Usage

Check also Docs and Demo.

@Inputs

NameDescriptionTypeDefault
textInputElementReference to the text input element.HTMLTextAreaElementRequired
menuTemplateReference to the menu template (used to display the search results).TemplateRefRequired
getChoiceLabelA function that formats the selected choice once selected. The result (label) is also used as a choice identifier (e.g. when editing choices).(choice: any) => stringRequired
triggerCharacterThe character which will trigger the search.string@
searchRegexpThe regular expression that will match the search text after the trigger character. No match will hide the menu.RegExp/^\w*$/
closeMenuOnBlurWhether to close the menu when the host textInputElement loses focus.booleanfalse
selectedChoicesPre-set choices for edit text mode, or to select/mark choices from outside the mentions component.any[][]
tagCssClassThe CSS class to add to highlighted tags.string''

@Outputs

NameDescriptionOutput type
searchCalled on user input after entering trigger character. Emits search term to search by.string
menuShowCalled when the choices menu is shown.void
menuHideCalled when the choices menu is hidden.void
choiceSelectedCalled when a choice is selected.ChoiceWithIndices
choiceRemovedCalled when a choice is removed.ChoiceWithIndices
selectedChoicesChangeCalled when a choice is selected, removed, or if any of the choices' indices change.ChoiceWithIndices[]
tagClickCalled when the area over a tag is clicked.TagMouseEvent
tagMouseEnterCalled when the area over a tag is moused over.TagMouseEvent
tagMouseLeaveCalled when the area over the tag has the mouse removed from it.TagMouseEvent

Basic example

<div class="relative-block-container">
  <textarea cols="42"
            rows="6"
            #textareaRef
            placeholder="Enter '@' and start typing..."
            [(ngModel)]="text"></textarea>

  <flx-mentions [textInputElement]="textareaRef"
                [menuTemplate]="menuTemplate"
                [triggerCharacter]="'@'"
                [getChoiceLabel]="getChoiceLabel"
                [searchRegexp]="'^([-&.\\w]+ *){0,3}$'"
                (search)="loadChoices($event)"
                (selectedChoicesChange)="onSelectedChoicesChange($event)"
                (menuShow)="onMenuShow()"
                (menuHide)="onMenuHide()"></flx-mentions>

  <ng-template #menuTemplate
               let-selectChoice="selectChoice">
    <ul class="flx-selectable-list">
      <li *ngFor="let user of choices"
          class="flx-selectable-list-item"
          (click)="selectChoice(user)">
        <span title="{{user.name}}">{{user.name}}</span>
      </li>
    </ul>
  </ng-template>
</div>

More examples here.

Support

All suggestions and improvements are welcome and appreciated.

License

The MIT License.

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago