-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat(Region): add SelectProvince component #608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
56ccb6e
refactor: 调整暗黑主题字体颜色
ArgoZhang ee90e72
refactor: 移除可为空标记
ArgoZhang 5a86c05
refactor: 符合命名规范
ArgoZhang 19692df
refactor: 精简代码
ArgoZhang a11152e
refactor: 优化代码
ArgoZhang 77ee4dd
feat: 增加省选择组件
ArgoZhang c19e09d
refactor: 移动 InputId 到基类
ArgoZhang 5a7e058
chore: bump version 9.0.3
ArgoZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/components/BootstrapBlazor.Region/Components/SelectProvince.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| @namespace BootstrapBlazor.Components | ||
| @inherits SelectRegionBase | ||
| @attribute [JSModuleAutoLoader("./_content/BootstrapBlazor.Region/Components/SelectRegion.razor.js")] | ||
|
|
||
| @if (IsShowLabel) | ||
| { | ||
| <BootstrapLabel required="@Required" for="@InputId" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" /> | ||
| } | ||
| <div @attributes="AdditionalAttributes" id="@Id" class="@ClassString"> | ||
| <div class="dropdown-toggle" data-bs-toggle="bb.dropdown" data-bs-placement="@PlacementString" data-bs-offset="@OffsetString" data-bs-custom-class="@CustomClassString"> | ||
| <input type="text" id="@InputId" disabled="@Disabled" readonly placeholder="@PlaceHolder" class="@InputClassString" value="@CurrentValueAsString" /> | ||
| <span class="@AppendClassString"><i class="@DropdownIcon"></i></span> | ||
| </div> | ||
| @if (!IsDisabled) | ||
| { | ||
| <span class="@ClearClassString" @onclick="OnClearValue"><i class="@ClearIcon"></i></span> | ||
| } | ||
| <div class="dropdown-menu bb-region-body"> | ||
| <ul> | ||
| @foreach (var item in GetProvinces()) | ||
| { | ||
| <li class="@GetActiveClass(item)" @onclick="() => OnSelectProvince(item)">@item</li> | ||
| } | ||
| </ul> | ||
| </div> | ||
| </div> |
58 changes: 58 additions & 0 deletions
58
src/components/BootstrapBlazor.Region/Components/SelectProvince.razor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
| // Website: https://www.blazor.zone or https://argozhang.github.io/ | ||
|
|
||
| namespace BootstrapBlazor.Components; | ||
|
|
||
| /// <summary> | ||
| /// SelectProvince 组件 | ||
| /// </summary> | ||
| public partial class SelectProvince | ||
| { | ||
| /// <summary> | ||
| /// 获得/设置 是否可多选 默认 false 单选 | ||
| /// </summary> | ||
| [Parameter] | ||
| public bool IsMultiple { get; set; } | ||
|
|
||
| private string? ClassString => CssBuilder.Default("select bb-province") | ||
| .AddClass("disabled", IsDisabled) | ||
| .AddClassFromAttributes(AdditionalAttributes) | ||
| .Build(); | ||
|
|
||
| private readonly HashSet<string> _values = []; | ||
|
|
||
| private string? GetActiveClass(string item) => _values.Contains(item) || CurrentValue == item ? "active" : null; | ||
|
|
||
| private async Task OnClearValue() | ||
| { | ||
| if (IsMultiple) | ||
| { | ||
| _values.Clear(); | ||
| } | ||
| CurrentValue = ""; | ||
|
|
||
| if (OnClearAsync != null) | ||
| { | ||
| await OnClearAsync(); | ||
| } | ||
| } | ||
|
|
||
| private void OnSelectProvince(string item) | ||
| { | ||
| if (IsMultiple) | ||
| { | ||
| if (!_values.Remove(item)) | ||
| { | ||
| _values.Add(item); | ||
| } | ||
| CurrentValue = string.Join(",", _values); | ||
| } | ||
| else | ||
| { | ||
| CurrentValue = item; | ||
| } | ||
| } | ||
|
|
||
| private HashSet<string> GetProvinces() => RegionService.GetProvinces(); | ||
| } |
66 changes: 66 additions & 0 deletions
66
src/components/BootstrapBlazor.Region/Components/SelectProvince.razor.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| .bb-province { | ||
| position: relative; | ||
| } | ||
|
|
||
| .bb-province:not(.disabled):hover .form-select-append { | ||
| display: none; | ||
| } | ||
|
|
||
| .dropdown-menu { | ||
| --bs-dropdown-padding-y: 0; | ||
| --bb-region-body-color: #495057; | ||
| --bb-region-body-hover-bg-color: #e9ecef; | ||
| --bb-region-body-active-bg-color: #dee2e6; | ||
| --bb-region-body-hover-color: #000; | ||
| --bb-region-body-active-color: #000; | ||
| --bb-region-body-width: 400px; | ||
| --bb-region-body-padding: .5rem; | ||
| --bb-region-body-item-padding: 3px 12px; | ||
| --bb-region-body-gap: 5px; | ||
| } | ||
|
|
||
| .dropdown-menu ul { | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
|
|
||
| .dropdown-menu li { | ||
| list-style: none; | ||
| transition: background-color .3s linear, color .3s linear; | ||
| } | ||
|
|
||
| [data-bs-theme="dark"] .dropdown-menu { | ||
| --bb-region-body-color: #c0c4cc; | ||
| --bb-region-body-hover-color: #fff; | ||
| --bb-region-body-active-color: #fff; | ||
| --bb-region-body-hover-bg-color: #495057; | ||
| --bb-region-body-active-bg-color: #6c757d; | ||
| } | ||
|
|
||
| .bb-region-body { | ||
| padding: var(--bb-region-body-padding); | ||
| width: var(--bb-region-body-width); | ||
| } | ||
|
|
||
| .bb-region-body ul { | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| gap: var(--bb-region-body-gap); | ||
| } | ||
|
|
||
| .bb-region-body ul li { | ||
| padding: var(--bb-region-body-item-padding); | ||
| border-radius: var(--bs-border-radius); | ||
| color: var(--bb-region-body-color); | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .bb-region-body ul li:hover { | ||
| background-color: var(--bb-region-body-hover-bg-color); | ||
| color: var(--bb-region-body-hover-color); | ||
| } | ||
|
|
||
| .bb-region-body ul li.active { | ||
| background-color: var(--bb-region-body-active-bg-color); | ||
| color: var(--bb-region-body-active-color); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.