Skip to content

Commit f28923f

Browse files
authored
release v2.0.3 (#39)
* Fix version output variable in GitHub Actions workflow for package release (cherry picked from commit f6b58d0) * Add OnNullText and OnNullContent parameters to LocalTimeText component (cherry picked from commit f01e5a9) * Add OnNullText and OnNullContent parameters to LocalTimeText component usage examples (cherry picked from commit 61bca99)
1 parent a0727a9 commit f28923f

File tree

7 files changed

+87
-6
lines changed

7 files changed

+87
-6
lines changed

.github/workflows/release.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
package-build:
1717
runs-on: ubuntu-latest
1818
outputs:
19-
VERSION: ${{ steps.version.outputs.VERSION }}
19+
version: ${{ steps.version.outputs.semver }}
2020
steps:
2121
- name: Checkout repository
2222
uses: actions/checkout@v5
@@ -35,7 +35,7 @@ jobs:
3535

3636
- name: export version to env
3737
id: version
38-
run: echo "VERSION=${{ steps.nbgv.outputs.SemVer2 }}" >> $GITHUB_ENV
38+
run: echo "semver=${{ steps.nbgv.outputs.SemVer2 }}" >> "$GITHUB_OUTPUT"
3939

4040
- name: Restore dependencies
4141
run: dotnet restore --locked-mode
@@ -67,13 +67,13 @@ jobs:
6767
id: create_release
6868
uses: softprops/action-gh-release@v2
6969
with:
70-
name: ${{ needs.package-build.outputs.VERSION }}
71-
tag_name: ${{ needs.package-build.outputs.VERSION }}
70+
name: ${{ needs.package-build.outputs.version }}
71+
tag_name: ${{ needs.package-build.outputs.version }}
7272
target_commitish: ${{ github.ref }}
7373
generate_release_notes: true
7474
files: ./artifacts/*.nupkg
7575
# if hyphen contains in the tag name, it will be prerelease
76-
prerelease: ${{ contains(needs.package-build.outputs.VERSION, '-') }}
76+
prerelease: ${{ contains(needs.package-build.outputs.version, '-') }}
7777
env:
7878
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7979

docs/API.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Displays formatted local time text.
3636
| `Value` | `DateTimeOffset?` | - | UTC datetime to display |
3737
| `Format` | `string` | `"yyyy-MM-dd HH:mm:ss"` | Display format string |
3838
| `DisableTimeElement` | `bool` | `false` | Whether to wrap in `<time>` element |
39+
| `OnNullText` | `string?` | `null` | Text to display if `Value` is null |
40+
| `OnNullContent` | `RenderFragment?` | `null` | Content to display if `Value` is null |
3941

4042
### `LocalTime`
4143
Provides local time via render fragment with loading and error state support.

example/BlazorLocalTimeSample/Pages/Home.razor

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@
6969
<LocalTimeText Value="@DateTime.UtcNow" Format="yyyy-MM-dd HH:mm:ssK" />
7070
</div>
7171

72+
<p>
73+
If you want to specify what to display when the value is null, you can use the <code>OnNullText</code> or <code>OnNullContent</code> parameters.
74+
</p>
75+
76+
<pre><code class="language-razor">&lt;LocalTimeText Value="@@null" DisableTimeElement OnNullText="No date available" /&gt;</code></pre>
77+
78+
<div class="component-sample">
79+
<LocalTimeText Value="@null" DisableTimeElement OnNullText="No date available" />
80+
</div>
81+
7282
<p>
7383
Alternatively, you can use the <code>LocalTime</code> component to receive the converted value in the child content:
7484
</p>

src/BlazorLocalTime/Components/LocalTimeText.razor

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@
1111
@FormattedValue
1212
}
1313
}
14+
@if (Value == null)
15+
{
16+
if(OnNullContent != null)
17+
{
18+
@OnNullContent
19+
}
20+
else if(OnNullText != null)
21+
{
22+
@OnNullText
23+
}
24+
}

src/BlazorLocalTime/Components/LocalTimeText.razor.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ public sealed partial class LocalTimeText : ComponentBase, IDisposable
2525
[Parameter]
2626
public string Format { get; set; } = "yyyy-MM-dd HH:mm:ss";
2727

28+
/// <summary>
29+
/// Gets or sets the text to display when the value is null.
30+
/// </summary>
31+
[Parameter]
32+
public string? OnNullText { get; set; } = null;
33+
34+
/// <summary>
35+
/// Gets or sets the components to display when the value is null.
36+
/// </summary>
37+
[Parameter]
38+
public RenderFragment? OnNullContent { get; set; } = null;
39+
2840
/// <summary>
2941
/// Gets or sets whether to disable wrapping the output in an HTML &lt;time&gt; element.
3042
/// When false (default), generates a semantic &lt;time&gt; tag with ISO-8601 datetime attribute for accessibility.

tests/BlazorLocalTimeTest/Approvals/PublicApiCheckTest.Run.approved.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@
8383
[Microsoft.AspNetCore.Components.Parameter]
8484
public string Format { get; set; }
8585
[Microsoft.AspNetCore.Components.Parameter]
86+
public Microsoft.AspNetCore.Components.RenderFragment? OnNullContent { get; set; }
87+
[Microsoft.AspNetCore.Components.Parameter]
88+
public string? OnNullText { get; set; }
89+
[Microsoft.AspNetCore.Components.Parameter]
8690
public System.DateTimeOffset? Value { get; set; }
8791
protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder @__builder) { }
8892
public void Dispose() { }

tests/BlazorLocalTimeTest/LocalTimeTextTest.razor

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,47 @@
7070
// Should render without time element (default behavior)
7171
cut.MarkupMatches("2023-10-01 21:30:00");
7272
}
73-
73+
74+
[Fact]
75+
public void TestWithNullNoOptions()
76+
{
77+
Services.AddLocalTimeMockService();
78+
79+
DateTimeOffset? dt = null;
80+
81+
var cut = Render(@<LocalTimeText Value="dt" DisableTimeElement />
82+
);
83+
84+
// Should render nothing
85+
cut.MarkupMatches(string.Empty);
86+
}
87+
88+
[Fact]
89+
public void TestWithNullWithOptions()
90+
{
91+
Services.AddLocalTimeMockService();
92+
93+
DateTimeOffset? dt = null;
94+
95+
var cut = Render(@<LocalTimeText Value="dt" DisableTimeElement OnNullText="Nothing" />
96+
);
97+
98+
// Should render "Nothing"
99+
cut.MarkupMatches("Nothing");
100+
}
101+
102+
[Fact]
103+
public void TestWithNullWithOptions2()
104+
{
105+
Services.AddLocalTimeMockService();
106+
107+
DateTimeOffset? dt = null;
108+
109+
var cut = Render(@<LocalTimeText Value="dt" DisableTimeElement><OnNullContent><p>Nothing Value</p></OnNullContent></LocalTimeText>
110+
);
111+
112+
// Should render "Nothing Value"
113+
cut.MarkupMatches("<p>Nothing Value</p>");
114+
}
115+
74116
}

0 commit comments

Comments
 (0)