Skip to content

Commit

Permalink
添加 SettingsButton
Browse files Browse the repository at this point in the history
  • Loading branch information
wherewhere committed Jun 6, 2024
1 parent 53ebfba commit d77af37
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 175 deletions.
6 changes: 6 additions & 0 deletions Wherlog/Controls/MarkdownSection.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
transform: translateX(0);
}

::deep pre code {
display: block;
overflow-x: auto;
padding: 1em;
}

::deep figcaption {
color: var(--neutral-foreground-hint);
font-size: 0.875em;
Expand Down
8 changes: 4 additions & 4 deletions Wherlog/Controls/PostCard.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
setElements(elements[i]);
}
function setElements(element) {
if (typeof element === 'undefined' || element === null) {
if (!(element instanceof Element)) {
return;
}
if (element?.className) {
element.className = 'hljs-' + element.className;
}
const className = [];
element.classList.forEach(x => className.push('hljs-' + x));
element.className = className.join(' ');
const numberOfElements = +element?.children.length;
for (let i = 0; i < numberOfElements; i++) {
setElements(element.children[i]);
Expand Down
22 changes: 22 additions & 0 deletions Wherlog/Controls/SettingsButton.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@inherits SettingsCardBase

<div class="@ClassValue" style="@Style">
<FluentCard
onclick="@OnClick"
AreaRestricted="false"
Style="padding: var(--settings-button-padding);">
<div class="content-grid">
<SettingsPresenter
Icon="@Icon"
Header="@Header"
Description="@Description"
ActionContent="@ActionContent" />
@if (ActionIcon != null)
{
<div class="action-icon-holder">
@ActionIcon
</div>
}
</div>
</FluentCard>
</div>
31 changes: 31 additions & 0 deletions Wherlog/Controls/SettingsButton.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.FluentUI.AspNetCore.Components.Utilities;

namespace Wherlog.Controls
{
public partial class SettingsButton : SettingsCardBase
{
protected override string ClassValue => new CssBuilder(Class)
.AddClass("settings-button")
.Build();

/// <summary>
/// Gets or sets the icon that is shown when IsClickEnabled is set to true.
/// </summary>
[Parameter]
public RenderFragment ActionIcon { get; set; }

/// <summary>
/// Gets or sets the tooltip of the ActionIcon.
/// </summary>
[Parameter]
public string ActionIconToolTip { get; set; } = "More";

/// <summary>
/// Command executed when the user clicks on the button.
/// </summary>
[Parameter]
public EventCallback<MouseEventArgs> OnClick { get; set; }
}
}
18 changes: 18 additions & 0 deletions Wherlog/Controls/SettingsButton.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
* {
--settings-button-padding: 16px 0 16px 16px;
}

::deep div.content-grid {
display: flex;
justify-content: space-between;
align-items: center;
}

::deep div.action-icon-holder {
width: 32px;
height: auto;
display: flex;
justify-content: center;
align-items: center;
margin: 0 8px;
}
14 changes: 10 additions & 4 deletions Wherlog/Controls/SettingsCard.razor
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
@inherits FluentComponentBase
@using Microsoft.FluentUI.AspNetCore.Components.Utilities
@inherits SettingsCardBase

<div class="@ClassValue" style="@Style">
<FluentCard AreaRestricted="false" Style="padding: var(--settings-card-padding);">
<SettingsPresenter
Icon="@Icon"
Header="@Header"
Description="@Description"
ActionContent="@ActionContent"
ActionIcon="@ActionIcon"
ActionIconToolTip="@ActionIconToolTip"/>
ActionContent="@ActionContent"/>
</FluentCard>
</div>

@code
{
protected override string ClassValue => new CssBuilder(Class)
.AddClass("settings-card")
.Build();
}
77 changes: 0 additions & 77 deletions Wherlog/Controls/SettingsCard.razor.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using Microsoft.AspNetCore.Components;
using Microsoft.FluentUI.AspNetCore.Components;
using Microsoft.FluentUI.AspNetCore.Components.Utilities;

namespace Wherlog.Controls
{
public partial class SettingsExpander : FluentComponentBase
public abstract class SettingsCardBase : FluentComponentBase
{
private string ClassValue => new CssBuilder(Class)
.AddClass("settings-expander")
.Build();
protected abstract string ClassValue { get; }

/// <summary>
/// Gets or sets the Header.
Expand All @@ -22,12 +19,6 @@ public partial class SettingsExpander : FluentComponentBase
[Parameter]
public RenderFragment Description { get; set; }

/// <summary>
/// Gets or sets the content of a ContentControl.
/// </summary>
[Parameter]
public RenderFragment Content { get; set; }

/// <summary>
/// Gets or sets the icon on the left.
/// </summary>
Expand All @@ -39,11 +30,5 @@ public partial class SettingsExpander : FluentComponentBase
/// </summary>
[Parameter]
public RenderFragment ActionContent { get; set; }

/// <summary>
/// Gets or sets the alignment of the Content.
/// </summary>
[Parameter]
public ContentAlignment ContentAlignment { get; set; }
}
}
16 changes: 15 additions & 1 deletion Wherlog/Controls/SettingsExpander.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@inherits FluentComponentBase
@using Microsoft.FluentUI.AspNetCore.Components.Utilities
@inherits SettingsCardBase

<div class="@ClassValue" style="@Style">
<FluentAccordion>
Expand All @@ -13,3 +14,16 @@
</FluentAccordionItem>
</FluentAccordion>
</div>

@code
{
protected override string ClassValue => new CssBuilder(Class)
.AddClass("settings-expander")
.Build();

/// <summary>
/// Gets or sets the content of a ContentControl.
/// </summary>
[Parameter]
public RenderFragment Content { get; set; }
}
10 changes: 9 additions & 1 deletion Wherlog/Controls/SettingsPresenter.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@inherits FluentComponentBase
@using Microsoft.FluentUI.AspNetCore.Components.Utilities
@inherits SettingsCardBase

<div class="@ClassValue" style="@Style">
<div class="header-root">
Expand Down Expand Up @@ -26,3 +27,10 @@
</div>
}
</div>

@code
{
protected override string ClassValue => new CssBuilder(Class)
.AddClass("settings-presenter")
.Build();
}
49 changes: 0 additions & 49 deletions Wherlog/Controls/SettingsPresenter.razor.cs

This file was deleted.

Loading

0 comments on commit d77af37

Please sign in to comment.