Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

<MudGrid>
<MudItem xs="12" sm="8" Class="d-flex flex-column gap-8 align-center justify-center">
<MudCodeViewer Class="mud-width-full" Code="@_code" Editable="@_editable" />
<MudCodeViewer Class="mud-width-full" Code="@_code" Editable="@_editable" ShowLineNumbers="@_showLineNumbers" />
</MudItem>

<MudItem xs="12" sm="4">
<MudSwitchM3 @bind-Value="@_editable" Label="Editable" Color="Color.Secondary" />
<MudStack Spacing="2">
<MudSwitchM3 @bind-Value="@_editable" Label="Editable" Color="Color.Secondary"/>
<MudSwitchM3 @bind-Value="@_showLineNumbers" Label="Line Numbers" Color="Color.Secondary"/>
</MudStack>
</MudItem>
</MudGrid>


@code {
private bool _editable = true;
private bool _showLineNumbers = false;
private string _code = """
// This is a sample code as string parameter.
public class MudCodeViewer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</code>
</pre>

<textarea @ref="_textAreaRef" class="mud-codeviewer-textarea" @bind="Code" @oninput="OnInput"
<textarea @ref="_textAreaRef" class="@TextAreaClass" @bind="Code" @oninput="OnInput"
spellcheck="false" autocomplete="off" autocorrect="off" autocapitalize="off"></textarea>
</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ public MudCodeViewer()
.AddClass($"language-{_language.Value.ToDescriptionString()}", !_showLineNumbers.Value)
.Build();

/// <summary>
/// Gets the CSS class string used for the textarea element based on the line number display settings.
/// </summary>
private string TextAreaClass => new CssBuilder()
.AddClass("mud-codeviewer-textarea")
.AddClass("line-numbers", _showLineNumbers.Value)
.Build();

/// <summary>
/// Gets or sets the code snippet to be displayed or processed by the component.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ pre[class*=language-].line-numbers{position:relative;padding-left:3.8em;counter-
font: inherit;
padding: 16px;
}

.mud-codeviewer-textarea.line-numbers {
padding-left: 3.8em
}