Skip to content
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

Typography Component Implementation #89

Merged
merged 3 commits into from
Sep 26, 2024
Merged
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public partial class Index
- [Toggle](#toggle)
- [Tooltip](#tooltip)
- [Tree](#tree)
- [Typography](#typography)
- [Upload](#upload)
- [Form Validation](#form-validation)
- [Workflow](#workflow)
Expand Down Expand Up @@ -1328,6 +1329,12 @@ treeNodes.Add("sample-child-2", new TreeNode()
tree.TreeModel = treeNodes;
```

## Typography
```razor
<Typography Format="TypographyFormat.Label" TextColor="TypographyColor.Std" TextDecoration="TextDecoration.None">Label, Std, None</Typography>
<Typography Bold="true" Format="TypographyFormat.Code_Lg" TextColor="TypographyColor.Contrast" TextDecoration="TextDecoration.Line_Through">Bold, Code_Lg, Contrast, Line_Through</Typography>
```

## Upload

```razor
Expand Down
34 changes: 34 additions & 0 deletions SiemensIXBlazor.Tests/TypographyTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// -----------------------------------------------------------------------
// SPDX-FileCopyrightText: 2024 Siemens AG
//
// SPDX-License-Identifier: MIT
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
// -----------------------------------------------------------------------

using Bunit;
using Microsoft.AspNetCore.Components;
using SiemensIXBlazor.Components;
using SiemensIXBlazor.Enums.Typography;

namespace SiemensIXBlazor.Tests;
public class TypographyTest : TestContextBase
{
[Fact]
public void TypographyRendersCorrectly()
{
// Arrange
var cut = RenderComponent<Typography>(
("Id", "testId"),
("Format", TypographyFormat.Body_Xs),
("Bold", true),
("TextColor", TypographyColor.Alarm),
("TextDecoration", TextDecoration.Line_Through),
("ChildContent", (RenderFragment)(builder => builder.AddMarkupContent(0, "Test content")))
);

// Assert
cut.MarkupMatches("<ix-typography id=\"testId\" bold format=\"body-xs\" text-color=\"alarm\" text-decoration=\"line-through\">Test content</ix-typography>");
}
}
26 changes: 26 additions & 0 deletions SiemensIXBlazor/Components/Typography/Typography.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@* -----------------------------------------------------------------------
// SPDX-FileCopyrightText: 2024 Siemens AG
//
// SPDX-License-Identifier: MIT
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
// -----------------------------------------------------------------------
*@

@using SiemensIXBlazor.Enums.Typography;
@using SiemensIXBlazor.Helpers;

@namespace SiemensIXBlazor.Components
@inherits IXBaseComponent

<ix-typography @attributes="UserAttributes"
id="@Id"
style="@Style"
class="@Class"
bold="@Bold"
format="@((Format != null) ? EnumParser<TypographyFormat>.ParseEnumToString(Format)?.Replace('_', '-') : "")"
text-color="@((TextColor != null) ? EnumParser<TypographyColor>.ParseEnumToString(TextColor)?.Replace('_', '-') : "")"
text-decoration="@((TextDecoration != null) ? EnumParser<TextDecoration>.ParseEnumToString(TextDecoration)?.Replace('_', '-') : "")">
@ChildContent
</ix-typography>
28 changes: 28 additions & 0 deletions SiemensIXBlazor/Components/Typography/Typography.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// -----------------------------------------------------------------------
// SPDX-FileCopyrightText: 2024 Siemens AG
//
// SPDX-License-Identifier: MIT
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
// -----------------------------------------------------------------------

using Microsoft.AspNetCore.Components;
using SiemensIXBlazor.Enums.Typography;
namespace SiemensIXBlazor.Components;

public partial class Typography
{
[Parameter]
public string? Id { get; set; } = string.Empty;
[Parameter]
public bool Bold { get; set; } = false;
[Parameter]
public TypographyFormat? Format { get; set; }
[Parameter]
public TypographyColor? TextColor { get; set; }
[Parameter]
public TextDecoration? TextDecoration { get; set; } = Enums.Typography.TextDecoration.None;
[Parameter]
public RenderFragment? ChildContent { get; set; }
}
17 changes: 17 additions & 0 deletions SiemensIXBlazor/Enums/Typography/TextDecoration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// -----------------------------------------------------------------------
// SPDX-FileCopyrightText: 2024 Siemens AG
//
// SPDX-License-Identifier: MIT
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
// -----------------------------------------------------------------------

namespace SiemensIXBlazor.Enums.Typography;

public enum TextDecoration
{
None,
Underline,
Line_Through
}
23 changes: 23 additions & 0 deletions SiemensIXBlazor/Enums/Typography/TypographyColor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// -----------------------------------------------------------------------
// SPDX-FileCopyrightText: 2024 Siemens AG
//
// SPDX-License-Identifier: MIT
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
// -----------------------------------------------------------------------

namespace SiemensIXBlazor.Enums.Typography;

public enum TypographyColor
{
Alarm,
Contrast,
Inv_Contrast,
Inv_Soft,
Inv_Std,
Inv_Weak,
Soft,
Std,
Weak
}
37 changes: 37 additions & 0 deletions SiemensIXBlazor/Enums/Typography/TypographyFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// -----------------------------------------------------------------------
// SPDX-FileCopyrightText: 2024 Siemens AG
//
// SPDX-License-Identifier: MIT
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
// -----------------------------------------------------------------------

namespace SiemensIXBlazor.Enums.Typography;

public enum TypographyFormat
{
H1,
H2,
H3,
H4,
H5,
H6,
Body,
Body_Xs,
Body_Sm,
Body_Lg,
Code,
Code_Sm,
Code_Lg,
Display,
Display_Xs,
Display_Sm,
Display_Lg,
Display_Xl,
Display_Xxl,
Label,
Label_Xs,
Label_Sm,
Label_Lg
}
Loading