diff --git a/src/AntBlazor.Docs/Pages/Tag.razor b/src/AntBlazor.Docs/Pages/Tag.razor new file mode 100644 index 000000000..34ea20f18 --- /dev/null +++ b/src/AntBlazor.Docs/Pages/Tag.razor @@ -0,0 +1,35 @@ +@page "/tag" + + +

Basic Tag

+Tag 1 + + Link + +Tag 2 +Prevent Default + + +
+
+

Checkable Tag

+Tag1 +Tag2 +Tag3 + +@code { + public void onClose() + { + + } + + public void preventDefault(MouseEventArgs e) + { + + } + + private void checkChange(bool e) + { + + } +} diff --git a/src/AntBlazor.Docs/Shared/MainLayout.razor b/src/AntBlazor.Docs/Shared/MainLayout.razor index f2437c698..1d02be7db 100644 --- a/src/AntBlazor.Docs/Shared/MainLayout.razor +++ b/src/AntBlazor.Docs/Shared/MainLayout.razor @@ -47,6 +47,11 @@ Avatar + + + Tag + + diff --git a/src/AntBlazor/AntBlazor.xml b/src/AntBlazor/AntBlazor.xml index a3b898056..f6ee130ea 100644 --- a/src/AntBlazor/AntBlazor.xml +++ b/src/AntBlazor/AntBlazor.xml @@ -138,5 +138,10 @@ + + + 'default' | 'closeable' | 'checkable' + + diff --git a/src/AntBlazor/Components/AntCheckbox/AntCheckbox.razor b/src/AntBlazor/Components/AntCheckbox/AntCheckbox.razor new file mode 100644 index 000000000..1d064e959 --- /dev/null +++ b/src/AntBlazor/Components/AntCheckbox/AntCheckbox.razor @@ -0,0 +1,25 @@ +@namespace AntBlazor +@inherits AntCheckboxBase + + +
+ + + + + +
+ +@code { + +} diff --git a/src/AntBlazor/Components/AntCheckbox/AntCheckboxBase.cs b/src/AntBlazor/Components/AntCheckbox/AntCheckboxBase.cs new file mode 100644 index 000000000..a4381e59a --- /dev/null +++ b/src/AntBlazor/Components/AntCheckbox/AntCheckboxBase.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components; + +namespace AntBlazor +{ + public class AntCheckboxBase : AntInputComponentBase + { + [Parameter] + public RenderFragment ChildContent { get; set; } + + [Parameter] + public EventCallback checkedChange { get; set; } + + [Parameter] + public string value { get; set; } + + [Parameter] + public bool autoFocus { get; set; } + + [Parameter] + public bool disabled { get; set; } + + [Parameter] + public bool indeterminate { get; set; } + + [Parameter] + public bool @checked { get; set; } + + protected Action onChange; + + protected Func onTouched; + + protected ElementReference inputElement; + + protected ElementReference contentElement; + + protected Dictionary inputAttributes { get; set; } + + protected async Task innerCheckedChange(bool @checked) + { + if (!this.disabled) + { + this.@checked = @checked; + this.onChange(this.@checked); + await this.checkedChange.InvokeAsync(this.@checked); + //if (this.checkboxWrapperComponent) + //{ + // this.nzCheckboxWrapperComponent.onChange(); + //} + } + } + + protected void updateAutoFocus() + { + if (this.autoFocus) + { + inputAttributes.Add("autofocus", "autofocus"); + } + else + { + inputAttributes.Remove("autofocus"); + } + } + + protected void writeValue(bool value) + { + this.@checked = value; + } + + protected void registerOnChange(Action fn) + { + if (fn != null) + { + this.onChange = fn; + } + } + + protected void registerOnTouched(Func fn) + { + if (fn != null) + { + this.onTouched = fn; + } + } + + protected void setDisabledState(bool isDisabled) + { + this.disabled = isDisabled; + } + } +} \ No newline at end of file diff --git a/src/AntBlazor/Components/AntTag/AntTag.razor b/src/AntBlazor/Components/AntTag/AntTag.razor new file mode 100644 index 000000000..86b342c36 --- /dev/null +++ b/src/AntBlazor/Components/AntTag/AntTag.razor @@ -0,0 +1,103 @@ +@namespace AntBlazor +@using System.Text.RegularExpressions +@inherits AntDomComponentBase + +@if (!closed) +{ +
+ @ChildContent + @if (mode == "closeable") + { + + } +
+} + +@code { + +[Parameter] public RenderFragment ChildContent { get; set; } + +/// +/// 'default' | 'closeable' | 'checkable' +/// +[Parameter] +public string mode { get; set; } = "default"; + +[Parameter] +public string color { get; set; } + +[Parameter] +public bool closable { get; set; } + +[Parameter] +public bool visible { get; set; } = true; + +[Parameter] +public bool @checked { get; set; } + +[Parameter] +public bool noAnimation { get; set; } + +[Parameter] +public EventCallback afterClose { get; set; } + +[Parameter] +public EventCallback onClose { get; set; } + +[Parameter] +public EventCallback checkedChange { get; set; } + +bool presetColor = false; +bool closed = false; + + +protected override Task OnInitializedAsync() +{ + this.updateClassMap(); + return base.OnInitializedAsync(); +} + +protected override void OnParametersSet() +{ + this.updateClassMap(); + base.OnParametersSet(); +} + +private bool isPresetColor(string color) +{ + if (string.IsNullOrEmpty(color)) + { + return false; + } + + return Regex.IsMatch(color, "^(pink|red|yellow|orange|cyan|green|blue|purple|geekblue|magenta|volcano|gold|lime)(-inverse)?$"); +} + +private void updateClassMap() +{ + this.presetColor = this.isPresetColor(this.color); + string prefix = "ant-tag"; + this.ClassMapper.Clear().Add(prefix) + .If($"{prefix}-has-color", () => !string.IsNullOrEmpty(color) && !presetColor) + .If($"{prefix}-${color}", () => presetColor) + .If($"{prefix}-checkable", () => mode == "checkable") + .If($"{prefix}-checkable-checked", () => @checked) + ; +} + +private async Task updateCheckedStatus() +{ + if (mode == "checkable") + { + this.@checked = !this.@checked; + await this.checkedChange.InvokeAsync(this.@checked); + this.updateClassMap(); + } +} + +private async Task closeTag(MouseEventArgs e) +{ + await this.onClose.InvokeAsync(e); + this.closed = true; +} +}