项目作者: loresoft

项目描述 :
Blazor Controls
高级语言: C#
项目地址: git://github.com/loresoft/LoreSoft.Blazor.Controls.git
创建时间: 2019-08-05T23:13:43Z
项目社区:https://github.com/loresoft/LoreSoft.Blazor.Controls

开源协议:MIT License

下载


Overview

The LoreSoft Blazor Controls project contains a collection of Blazor user controls.

Installing

The LoreSoft.Blazor.Controls library is available on nuget.org via package name LoreSoft.Blazor.Controls.

To install LoreSoft.Blazor.Controls, run the following command in the Package Manager Console

  1. Install-Package LoreSoft.Blazor.Controls

Setup

To use, you need to include the following CSS and JS files in your index.html (Blazor WebAssembly) or _Host.cshtml (Blazor Server).

In the head tag add the following CSS.

  1. <link rel="stylesheet" href="_content/LoreSoft.Blazor.Controls/BlazorControls.css" />

Typeahead Features

  • Searching data by supplying a search function
  • Template for search result, selected value, and footer
  • Debounce support for smoother search
  • Character limit before searching
  • Multiselect support
  • Built in form validation support

Typeahead Properties

Required

  • Value - Bind to Value in single selection mode. Mutually exclusive to Values property.
  • Values - Bind to Values in multiple selection mode. Mutually exclusive to Value property.
  • SearchMethod - The method used to return search result

Optional

  • AllowClear - Allow the selected value to be cleared
  • ConvertMethod - The method used to convert search result type to the value type
  • Debounce - Time to wait, in milliseconds, after last key press before starting a search
  • Items - The initial list of items to show when there isn’t any search text
  • MinimumLength - Minimum number of characters before starting a search
  • Placeholder - The placeholder text to show when nothing is selected

Templates

  • ResultTemplate - User defined template for displaying a result in the results list
  • SelectedTemplate - User defined template for displaying the selected item(s)
  • NoRecordsTemplate - Template for when no items are found
  • FooterTemplate - Template displayed at the end of the results list
  • LoadingTemplate - Template displayed while searching

Typeahead Examples

Basic Example

State selection dropdown. Bind to Value property for single selection mode.

  1. <Typeahead SearchMethod="@SearchState"
  2. Items="Data.StateList"
  3. @bind-Value="@SelectedState"
  4. Placeholder="State">
  5. <SelectedTemplate Context="state">
  6. @state.Name
  7. </SelectedTemplate>
  8. <ResultTemplate Context="state">
  9. @state.Name
  10. </ResultTemplate>
  11. </Typeahead>
  1. @code {
  2. public StateLocation SelectedState { get; set; }
  3. public Task<IEnumerable<StateLocation>> SearchState(string searchText)
  4. {
  5. var result = Data.StateList
  6. .Where(x => x.Name.ToLower().Contains(searchText.ToLower()))
  7. .ToList();
  8. return Task.FromResult<IEnumerable<StateLocation>>(result);
  9. }
  10. }

Multiselect Example

When you want to be able to select multiple results. Bind to the Values property. The target property must be type IList<T>.

  1. <Typeahead SearchMethod="@SearchPeople"
  2. Items="Data.PersonList"
  3. @bind-Values="@SelectedPeople"
  4. Placeholder="Owners">
  5. <SelectedTemplate Context="person">
  6. @person.FullName
  7. </SelectedTemplate>
  8. <ResultTemplate Context="person">
  9. @person.FullName
  10. </ResultTemplate>
  11. </Typeahead>
  1. @code {
  2. public IList<Person> SelectedPeople;
  3. public Task<IEnumerable<Person>> SearchPeople(string searchText)
  4. {
  5. var result = Data.PersonList
  6. .Where(x => x.FullName.ToLower().Contains(searchText.ToLower()))
  7. .ToList();
  8. return Task.FromResult<IEnumerable<Person>>(result);
  9. }
  10. }

Use Octokit to search for a GitHub repository.

  1. <Typeahead SearchMethod="@SearchGithub"
  2. @bind-Value="@SelectedRepository"
  3. Placeholder="Repository"
  4. MinimumLength="3">
  5. <SelectedTemplate Context="repo">
  6. @repo.FullName
  7. </SelectedTemplate>
  8. <ResultTemplate Context="repo">
  9. <div class="github-repository clearfix">
  10. <div class="github-avatar"><img src="@repo.Owner.AvatarUrl"></div>
  11. <div class="github-meta">
  12. <div class="github-title">@repo.FullName</div>
  13. <div class="github-description">@repo.Description</div>
  14. <div class="github-statistics">
  15. <div class="github-forks"><i class="fa fa-flash"></i> @repo.ForksCount Forks</div>
  16. <div class="github-stargazers"><i class="fa fa-star"></i> @repo.StargazersCount Stars</div>
  17. <div class="github-watchers"><i class="fa fa-eye"></i> @repo.SubscribersCount Watchers</div>
  18. </div>
  19. </div>
  20. </div>
  21. </ResultTemplate>
  22. </Typeahead>
  1. @inject IGitHubClient GitHubClient;
  2. @code {
  3. public Repository SelectedRepository { get; set; }
  4. public async Task<IEnumerable<Repository>> SearchGithub(string searchText)
  5. {
  6. var request = new SearchRepositoriesRequest(searchText);
  7. var result = await GitHubClient.Search.SearchRepo(request);
  8. return result.Items;
  9. }
  10. }