Skip to content

Commit 1b56406

Browse files
MayueCifMayuecapdiem
authored
feat:update masab 0.5 (masastack#146)
* feat:update blazor version (masastack#139) Co-authored-by: Mayue <mayue@lonsid.cn> * 🐛 fix(PageTabs): enable stopPropgation and preventDefault at close click event * 🐛 fix: sldier bug in pageTabs * feat:update blazor 0.5 rc2 Co-authored-by: Mayue <mayue@lonsid.cn> Co-authored-by: capdiem <capdiem@live.com>
1 parent 912b988 commit 1b56406

File tree

11 files changed

+46
-41
lines changed

11 files changed

+46
-41
lines changed

Masa.Blazor.Pro/Data/App/ECommerce/Dto/BasketItemDto.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public class BasketItemDto
44
{
5-
public BasketItemDto(int id, string name, string company, float score, int qty, string delivery,
5+
public BasketItemDto(int id, string name, string company, float score, uint qty, string delivery,
66
string offers, decimal price, string pictureFileName, bool freeShipping)
77
{
88
Id = id;
@@ -25,7 +25,7 @@ public BasketItemDto(int id, string name, string company, float score, int qty,
2525

2626
public float Score { get; set; }
2727

28-
public int Qty { get; set; }
28+
public uint Qty { get; set; }
2929

3030
public string Delivery { get; set; } = default!;
3131

Masa.Blazor.Pro/Global/Config/GlobalConfig.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Masa.Blazor.Pro.Global;
1+
using System.Globalization;
2+
3+
namespace Masa.Blazor.Pro.Global;
24

35
public class GlobalConfig
46
{
@@ -26,16 +28,16 @@ public class GlobalConfig
2628

2729
public static string FavoriteCookieKey { get; set; } = "GlobalConfig_Favorite";
2830

29-
public I18nConfig? I18nConfig { get; set; }
31+
public I18n? I18n { get; set; }
3032

31-
public string? Language
33+
public CultureInfo? Culture
3234
{
33-
get => I18nConfig?.Language;
35+
get => I18n?.Culture;
3436
set
3537
{
36-
if (I18nConfig is not null)
38+
if (I18n is not null)
3739
{
38-
I18nConfig.Language = value;
40+
I18n.SetCulture(value);
3941
OnLanguageChanged?.Invoke();
4042
}
4143
}
@@ -104,10 +106,10 @@ public NavModel? CurrentNav
104106

105107
#endregion
106108

107-
public GlobalConfig(CookieStorage cookieStorage, I18nConfig i18nConfig, IHttpContextAccessor httpContextAccessor)
109+
public GlobalConfig(CookieStorage cookieStorage, I18n i18n, IHttpContextAccessor httpContextAccessor)
108110
{
109111
_cookieStorage = cookieStorage;
110-
I18nConfig = i18nConfig;
112+
I18n = i18n;
111113
if (httpContextAccessor.HttpContext is not null) Initialization(httpContextAccessor.HttpContext.Request.Cookies);
112114
}
113115

Masa.Blazor.Pro/Global/ServiceCollectionExtensions.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
public static class ServiceCollectionExtensions
44
{
55
public static IServiceCollection AddGlobalForServer(this IServiceCollection services)
6-
{
7-
services.AddMasaI18nForServer("wwwroot/i18n");
6+
{
87
var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? throw new Exception("Get the assembly root directory exception!");
98
services.AddNav(Path.Combine(basePath, $"wwwroot/nav/nav.json"));
109
services.AddScoped<GlobalConfig>();
@@ -13,8 +12,7 @@ public static IServiceCollection AddGlobalForServer(this IServiceCollection serv
1312
}
1413

1514
public static async Task<IServiceCollection> AddGlobalForWasmAsync(this IServiceCollection services, string baseUri)
16-
{
17-
await services.AddMasaI18nForWasmAsync(Path.Combine(baseUri, $"i18n"));
15+
{
1816
using var httpclient = new HttpClient();
1917
var navList = await httpclient.GetFromJsonAsync<List<NavModel>>(Path.Combine(baseUri, $"nav/nav.json")) ?? throw new Exception("please configure the Navigation!");
2018
services.AddNav(navList);

Masa.Blazor.Pro/Masa.Blazor.Pro.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Masa.Blazor" Version="0.4.0" />
15+
<PackageReference Include="Masa.Blazor" Version="0.5.0-rc.2" />
1616
</ItemGroup>
1717

1818
<ItemGroup>
1919
<Content Update="wwwroot\i18n\en-US.json">
2020
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2121
</Content>
22-
<Content Update="wwwroot\i18n\languageConfig.json">
22+
<Content Update="wwwroot\i18n\supportedCultures.json">
2323
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2424
</Content>
2525
<Content Update="wwwroot\i18n\zh-CN.json">

Masa.Blazor.Pro/Pages/App/ECommerce/Order/Cart.razor

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
<MRating class="mb-1" Readonly Value="context.Score" Size=20 Color="remind" BackgroundColor="remind" Dense></MRating>
1919
<div class="mt-3 d-flex align-center justify-start">
2020
<span class="text-caption mr-2">Qty: </span>
21-
<div style="width:100px;">
22-
<MTextField HideDetails="true" Type="number" Outlined Dense @bind-Value="@context.Qty" OnInput="(e)=>{ context.Qty=e<0?0:e; }" TValue="int"></MTextField>
23-
</div>
21+
<MTextField FullWidth=false Style="width:100px;max-width: 150px;" HideDetails="true" Type="number" TValue="uint" Outlined Dense @bind-Value="@context.Qty" NumberProps="@(prop=> { prop.Min = 0; prop.Max = 99; prop.Step =1; })"></MTextField>
2422
</div>
2523
</div>
2624
<div class="flex-grow-1 d-flex flex-column justify-end">

Masa.Blazor.Pro/Program.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@
66
builder.Services.AddServerSideBlazor();
77
builder.Services.AddMasaBlazor(builder =>
88
{
9-
builder.UseTheme(option =>
10-
{
11-
option.Primary = "#4318FF";
12-
option.Accent = "#4318FF";
13-
}
14-
);
15-
});
9+
builder.Theme.Primary = "#4318FF";
10+
builder.Theme.Accent = "#4318FF";
11+
}).AddI18nForServer("wwwroot/i18n");
1612
builder.Services.AddHttpContextAccessor();
1713
builder.Services.AddGlobalForServer();
1814

Masa.Blazor.Pro/Shared/Language.razor

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@inject GlobalConfig GlobalConfig;
1+
@using System.Globalization
2+
@inject GlobalConfig GlobalConfig;
23
@inject I18n I18n
34

45
<MMenu OffsetY Bottom>
@@ -9,14 +10,14 @@
910
</ActivatorContent>
1011
<ChildContent>
1112
<MList Class="py-0">
12-
<MListItemGroup ActiveClass="primary" Value="GlobalConfig.Language">
13-
@foreach (var (language, map) in I18n.Languages)
13+
<MListItemGroup ActiveClass="primary" Value="GlobalConfig.Culture?.Name">
14+
@foreach (var culture in I18n.SupportedCultures)
1415
{
15-
<MListItem OnClick="()=> OnLanguageChange(language)" Value="(StringNumber)language">
16+
<MListItem OnClick="()=> OnLanguageChange(culture)" Value="(StringNumber)culture.Name">
1617
<ItemContent>
1718
<MListItemContent>
1819
<span Class="@(context.Active?"white--text":"neutral-lighten-4--text") text-btn">
19-
@map.GetValueOrDefault("$Text")
20+
@culture.NativeName
2021
</span>
2122
</MListItemContent>
2223
</ItemContent>
@@ -28,9 +29,9 @@
2829
</MMenu>
2930

3031
@code {
31-
void OnLanguageChange(string language)
32+
void OnLanguageChange(CultureInfo culture)
3233
{
33-
I18n.SetLang(language);
34-
GlobalConfig.Language = language;
34+
I18n.SetCulture(culture);
35+
GlobalConfig.Culture = culture;
3536
}
3637
}

Masa.Blazor.Pro/Shared/PageTabs.razor

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55

66
<MPageTabs Value="NavHelper.PageTabItems.FindIndex(tab => tab.Url == GlobalConfig.CurrentNav?.Href)" Class="px-6 pagetabs" Items="NavHelper.PageTabItems">
77
<TabContent>
8-
<MTab Value="NavHelper.PageTabItems.FindIndex(tab=> tab.Url==context.Item.Url)" Href="@context.Item.Url" @attributes="@context.Attrs" class="px-6 rounded-t-xl m-page_tab"
9-
ActiveClass="m-page_tab_active" IsActive=context.IsActive Ripple="false">
8+
<MTab Value="@NavHelper.PageTabItems.FindIndex(tab => string.Equals(tab.AbsolutePath, context.Item.AbsolutePath, StringComparison.InvariantCultureIgnoreCase))"
9+
Href="@context.Item.Url"
10+
Class="px-6 rounded-t-xl m-page_tab"
11+
ActiveClass="m-page_tab_active"
12+
IsActive=context.IsActive
13+
Ripple="false"
14+
@attributes="@context.Attrs">
1015
<MIcon Size=20>@context.Item.Icon</MIcon>
11-
<span class="mx-2 text-capitalize @(context.IsActive ?"neutral--text":"")" style="min-width:46px;">@T(context.Item.Name)</span>
16+
<span class="mx-2 text-capitalize @(context.IsActive ? "neutral--text" : "")" style="min-width:46px;">@T(context.Item.Name)</span>
1217
@if (context.Item.Closable)
1318
{
14-
<MIcon Size=16 OnClick="context.Close">mdi-close</MIcon>
19+
<MIcon Size=16 OnClick="context.Close" OnClickStopPropagation OnClickPreventDefault>mdi-close</MIcon>
1520
}
1621
</MTab>
1722
</TabContent>
@@ -39,4 +44,5 @@
3944
GlobalConfig.OnLanguageChanged -= base.StateHasChanged;
4045
GlobalConfig.OnCurrentNavChanged -= base.StateHasChanged;
4146
}
42-
}
47+
48+
}

Masa.Blazor.Pro/_Imports.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
@using Masa.Blazor.Pro.Shared
1111
@using BlazorComponent
1212
@using BlazorComponent.I18n
13-
@using BlazorComponent.Components
1413
@using Masa.Blazor.Pro.Pages
1514
@using Masa.Blazor.Pro.Global
1615
@using Masa.Blazor.Pro.Data

Masa.Blazor.Pro/wwwroot/css/masa-blazor-pro.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,11 @@
649649
min-width: 0px !important;
650650
}
651651

652+
.m-page-tabs .m-slide-group__next.m-slide-group__next--disabled {
653+
flex: none !important;
654+
min-width: 0px !important;
655+
}
656+
652657
/* pagetabs */
653658
/*组件样式全局修改end*/
654659
/*shop*/
@@ -1046,7 +1051,7 @@ tr:hover {
10461051
border-bottom-left-radius: 20px !important;
10471052
border-bottom-right-radius: 20px !important;
10481053
height: 36px;
1049-
padding-left: 16px;
1054+
padding: 0 16px;
10501055
}
10511056

10521057
.m-page-tabs .m-tab:before {

0 commit comments

Comments
 (0)