Skip to content

Commit

Permalink
Merge pull request #63 from pureblazor/icon-and-theme-refactor
Browse files Browse the repository at this point in the history
Icon and theme refactor
  • Loading branch information
codymullins authored May 3, 2024
2 parents 290944d + f9749ce commit ffba13c
Show file tree
Hide file tree
Showing 68 changed files with 1,143 additions and 496 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.12.1
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<PackageVersion Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Authorization" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Components" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.4" />
Expand Down
6 changes: 4 additions & 2 deletions css.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash
# file: css.sh

./tailwindcss-macos-arm64 -c src/Pure.Blazor.Components/tailwind.config.js -i src/Pure.Blazor.Components/wwwroot/app.css -o src/Pure.Blazor.Components/wwwroot/pureblazor.css
source ~/.zshrc
nvm use
npm install tailwindcss@next @tailwindcss/vite@next
npx @tailwindcss/cli@next -i src/Pure.Blazor.Components/tailwind.css -o src/Pure.Blazor.Components/wwwroot/pureblazor.css --watch
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Pure.Blazor.Components.Buttons;
using Pure.Blazor.Components.Common;
using Pure.Blazor.Components.Dialogs;
using Pure.Blazor.Components.Feedback;
using Pure.Blazor.Components.Primitives;

namespace Pure.Blazor.Components.AspNetCore;

public static class HostApplicationBuilderExtensions
{
public static IHostApplicationBuilder AddPureBlazorComponents(this IHostApplicationBuilder builder)
public static IHostApplicationBuilder AddPureBlazorComponents(this IHostApplicationBuilder builder,
IPureTheme? theme = null)
{
// javascript
builder.Services.AddScoped<IElementUtils, ElementUtils>();
Expand All @@ -17,6 +21,13 @@ public static IHostApplicationBuilder AddPureBlazorComponents(this IHostApplicat
builder.Services.AddScoped<AlertService>();
builder.Services.AddScoped<DialogService>();

builder.Services.AddCascadingValue(sp =>
{
theme ??= new DefaultTheme();
var source = new CascadingValueSource<IPureTheme>(theme, isFixed: true);
return source;
});

return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>PureBlazor Icons</Title>
<Version>0.21</Version>
<PackageId>PureBlazor.Components.Icons</PackageId>
<Description>Blazor Icons</Description>
<PackageProjectUrl>https://pureblazor.com</PackageProjectUrl>
<RepositoryUrl>https://github.com/pureblazor/components</RepositoryUrl>
<PackageTags>blazor, icons, maui, ssr, wasm, tailwind, tailwindcss, heroicons, pureblazor</PackageTags>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageReleaseNotes>Component Library Updates</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Company>PureBlazor</Company>
<Authors>codymullins</Authors>
<Copyright>Copyright 2024 PureBlazor</Copyright>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Pure.Blazor.Components.Primitives\Pure.Blazor.Components.Primitives.csproj"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Pure.Blazor.Components.Common;
using Pure.Blazor.Components.Primitives;

namespace Pure.Blazor.Components.Icons;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Pure.Blazor.Components.Icons;

public enum PureIcons
{
IconCheck,
IconNone,
IconSpin,
IconOpenCircle,
IconChevronDoubleLeft,
Expand Down Expand Up @@ -39,5 +39,6 @@ public enum PureIcons
IconCheckCircle,
IconFile,
IconFolder,
IconFolderOpen
IconFolderOpen,
IconCheck
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Pure.Blazor.Components.Common;
namespace Pure.Blazor.Components.Primitives;

public enum Accent
{
Expand All @@ -7,4 +7,4 @@ public enum Accent
Success,
Danger,
Warning,
}
}
7 changes: 7 additions & 0 deletions src/Pure.Blazor.Components.Primitives/ButtonDefaults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Pure.Blazor.Components.Primitives;

public class ButtonDefaults
{
public Effect PressEffect { get; set; }
public Effect HoverEffect { get; set; }
}
56 changes: 56 additions & 0 deletions src/Pure.Blazor.Components.Primitives/ComponentStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace Pure.Blazor.Components.Primitives;

public class ComponentStyle
{
private readonly IReadOnlyDictionary<Accent, string> accents;
private readonly IReadOnlyDictionary<PureVariant, Dictionary<Accent, string>> variants;
private readonly IReadOnlyDictionary<PureSize, string> sizes;

public ComponentStyle(string baseStyle,
IReadOnlyDictionary<Accent, string>? accents,
IReadOnlyDictionary<PureVariant, Dictionary<Accent, string>>? variants,
IReadOnlyDictionary<PureSize, string>? sizes)
{
this.accents = accents ?? new Dictionary<Accent, string>();
this.variants = variants ?? new Dictionary<PureVariant, Dictionary<Accent, string>>();
this.sizes = sizes ?? new Dictionary<PureSize, string>();
Base = baseStyle;
}

/// <summary>
/// Basic style applied to the outer container of the component.
/// </summary>
public string Base { get; set; }

/// <summary>
/// Optional advanced style for the outer container of the component.
/// Not all components with an outer container have this, only if the outer container requires Accent or Variant
/// modifications.
/// </summary>
public ComponentStyle? OuterContainer { get; set; }

/// <summary>
/// Optional advanced style for the inner container of the component. Not all components have an inner container.
/// </summary>
public ComponentStyle? InnerContainer { get; set; }

public string Accent(Accent accent)
{
return accents.TryGetValue(accent, out var value) ? value : string.Empty;
}

public string Variant(PureVariant variant, Accent accent)
{
if (variants.TryGetValue(variant, out var value) && value.TryGetValue(accent, out var style))
{
return style;
}

return string.Empty; // or return a default style
}

public string Size(PureSize size)
{
return sizes.TryGetValue(size, out var value) ? value : string.Empty;
}
}
33 changes: 33 additions & 0 deletions src/Pure.Blazor.Components.Primitives/Effect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace Pure.Blazor.Components.Primitives;

/// <summary>
/// Animation effects that can be applied to any component that supports it.
/// </summary>
public enum Effect
{
/// <summary>
/// Unset effect. Default values will be inherited from ancestors.
/// </summary>
Unset,

/// <summary>
/// Explicitly indicates no effect.
/// </summary>
None,

// what's the best name here?
Jiggle,

/// <summary>
/// Fade in and out effect.
/// </summary>
Pulse,

/// <summary>
///
/// </summary>
Ping

// TODO: https://github.com/pureblazor/components/issues/57
//Ripple,
}
19 changes: 19 additions & 0 deletions src/Pure.Blazor.Components.Primitives/IPureTheme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Pure.Blazor.Components.Primitives;

public interface IPureTheme
{
public ButtonDefaults ButtonDefaults { get; set; }
public IStylePrioritizer StylePrioritizer { get; set; }
public Dictionary<string, ComponentStyle> Styles { get; set; }

public ComponentStyle GetStyle(Type type)
{
return GetStyleByName(type.Name);
}

public ComponentStyle GetStyleByName(string name)
{
// TODO: decide if we want this to be an exceptional event
return Styles.GetValueOrDefault(name) ?? new ComponentStyle("", null, null, null);
}
}
6 changes: 6 additions & 0 deletions src/Pure.Blazor.Components.Primitives/IStylePrioritizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Pure.Blazor.Components.Primitives;

public interface IStylePrioritizer
{
public string PrioritizeStyles(string style1, string style2);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>PureBlazor Icons</Title>
<Version>0.21</Version>
<PackageId>PureBlazor.Components.Primitives</PackageId>
<Description>PureBlazor.Components.Primitives</Description>
<PackageProjectUrl>https://pureblazor.com</PackageProjectUrl>
<RepositoryUrl>https://github.com/pureblazor/components</RepositoryUrl>
<PackageTags>blazor, icons, maui, ssr, wasm, tailwind, tailwindcss, heroicons, pureblazor</PackageTags>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageReleaseNotes>Component Library Updates</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Company>PureBlazor</Company>
<Authors>codymullins</Authors>
<Copyright>Copyright 2024 PureBlazor</Copyright>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components"/>
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions src/Pure.Blazor.Components.Primitives/PureAlign.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Pure.Blazor.Components.Primitives;

public enum PureAlign
{
Start,
Center,
End
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Pure.Blazor.Components.Common;
namespace Pure.Blazor.Components.Primitives;

public enum PureAnimate
{
None,
Default,
Spin
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.AspNetCore.Components;
using Pure.Blazor.Components.Buttons;
using Microsoft.AspNetCore.Components;

namespace Pure.Blazor.Components.Common;
namespace Pure.Blazor.Components.Primitives;

public class PureComponent : ComponentBase
{
Expand All @@ -11,8 +10,6 @@ protected override void OnParametersSet()
BuildCss();
}

[CascadingParameter] public ThemeProvider? ThemeProvider { get; set; } = new();

/// <summary>
/// Add additional css classes to this component
/// </summary>
Expand All @@ -29,7 +26,7 @@ protected override void OnParametersSet()
/// The current theme styles
/// </summary>
[CascadingParameter]
public PureTheme PureTheme { get; set; } = new();
public required IPureTheme PureTheme { get; set; }

[Parameter] public RenderFragment? ChildContent { get; set; }

Expand All @@ -45,6 +42,13 @@ protected virtual void BuildCss()
{
}

/// <summary>
/// Gets the component style from the theme for the specific type of component.
/// </summary>
protected ComponentStyle Css => PureTheme.GetStyle(GetType());

protected ComponentStyle CssStyle(string name) => PureTheme.GetStyleByName(name);

/// <summary>
/// Applies the style based on the theme settings.
///
Expand All @@ -65,9 +69,9 @@ protected virtual string ApplyStyle(string? style)
return Styles ?? "";
}

if (ThemeProvider?.StylePrioritizer != null && Styles != null)
if (PureTheme?.StylePrioritizer != null && Styles != null)
{
return ThemeProvider.StylePrioritizer.PrioritizeStyles(style, Styles);
return PureTheme.StylePrioritizer.PrioritizeStyles(style, Styles);
}

return $"{style} {Styles}";
Expand Down
10 changes: 10 additions & 0 deletions src/Pure.Blazor.Components.Primitives/PureSize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Pure.Blazor.Components.Primitives;

public enum PureSize
{
ExtraSmall,
Small,
Medium,
Large,
ExtraLarge
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Pure.Blazor.Components.Display;
namespace Pure.Blazor.Components.Primitives;

public enum PureVariant
{
Default,
Outline,
Subtle
}
}
Loading

0 comments on commit ffba13c

Please sign in to comment.