From 0a6d75a14bfdc68c58e0b8a309f723fe4ed03c88 Mon Sep 17 00:00:00 2001 From: James Yeung Date: Sat, 19 Aug 2023 22:17:02 +0800 Subject: [PATCH] feat(module: statistic): add CultureInfo to support localization number format (#3299) --- components/statistic/Statistic.razor.cs | 14 ++++++-- .../Components/Statistic/doc/index.en-US.md | 35 ++++++++++--------- .../Components/Statistic/doc/index.zh-CN.md | 31 ++++++++-------- 3 files changed, 46 insertions(+), 34 deletions(-) diff --git a/components/statistic/Statistic.razor.cs b/components/statistic/Statistic.razor.cs index e92853f4..2c7d742b 100644 --- a/components/statistic/Statistic.razor.cs +++ b/components/statistic/Statistic.razor.cs @@ -7,12 +7,22 @@ namespace AntDesign { public partial class Statistic : StatisticComponentBase { - [Parameter] public string DecimalSeparator { get; set; } = "."; + [Parameter] public string DecimalSeparator { get; set; } - [Parameter] public string GroupSeparator { get; set; } = ","; + [Parameter] public string GroupSeparator { get; set; } [Parameter] public int Precision { get; set; } + [Parameter] public CultureInfo CultureInfo { get; set; } = LocaleProvider.CurrentLocale.CurrentCulture; + + protected override void OnInitialized() + { + DecimalSeparator ??= CultureInfo.NumberFormat.NumberDecimalSeparator; + GroupSeparator ??= CultureInfo.NumberFormat.NumberGroupSeparator; + + base.OnInitialized(); + } + private (string integerPart, string fractionalPart) SeparateDecimal() { decimal decimalValue; diff --git a/site/AntDesign.Docs/Demos/Components/Statistic/doc/index.en-US.md b/site/AntDesign.Docs/Demos/Components/Statistic/doc/index.en-US.md index ad9d38d1..d92f08dc 100644 --- a/site/AntDesign.Docs/Demos/Components/Statistic/doc/index.en-US.md +++ b/site/AntDesign.Docs/Demos/Components/Statistic/doc/index.en-US.md @@ -18,24 +18,25 @@ Display statistic number. | Property | Description | Type | Default | Version | | ---------------- | ----------------------------- | -------------------- | ------- | ------- | -| decimalSeparator | decimal separator | string | . | | -| formatter | customize value display logic | (value) => ReactNode | - | | -| groupSeparator | group separator | string | , | | -| precision | precision of input value | number | - | | -| prefix | prefix node of value | string \| ReactNode | - | | -| suffix | suffix node of value | string \| ReactNode | - | | -| title | Display title | string \| ReactNode | - | | -| value | Display value | string \| number | - | | -| valueStyle | Set value css style | CSSProperties | - | | +| CultureInfo | culture info for the number format | CultureInfo | CurrentCultureInfo | | +| DecimalSeparator | decimal separator | string | . | | +| Formatter | customize value display logic | (value) => ReactNode | - | | +| GroupSeparator | group separator | string | , | | +| Precision | precision of input value | number | - | | +| Prefix | prefix node of value | string \| ReactNode | - | | +| Suffix | suffix node of value | string \| ReactNode | - | | +| Title | Display title | string \| ReactNode | - | | +| Value | Display value | string \| number | - | | +| ValueStyle | Set value css style | CSSProperties | - | | -#### Statistic.Countdown +#### Countdown | Property | Description | Type | Default | Version | | --- | --- | --- | --- | --- | -| format | Format as [moment](http://momentjs.com/) | string | 'HH:mm:ss' | | -| onFinish | Trigger when time's up | () => void | - | | -| prefix | prefix node of value | string \| ReactNode | - | | -| suffix | suffix node of value | string \| ReactNode | - | | -| title | Display title | string \| ReactNode | - | | -| value | Set target countdown time | number \| moment | - | | -| valueStyle | Set value css style | CSSProperties | - | | +| Format | Format as [TimeSpan](https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/custom-timespan-format-strings?WT.mc_id=DT-MVP-5003987) | string | @"hh\:mm\:ss" | | +| OnFinish | Trigger when time's up | () => void | - | | +| Prefix | prefix node of value | string \| ReactNode | - | | +| Suffix | suffix node of value | string \| ReactNode | - | | +| Title | Display title | string \| ReactNode | - | | +| Value | Set target countdown time | number \| moment | - | | +| ValueStyle | Set value css style | CSSProperties | - | | diff --git a/site/AntDesign.Docs/Demos/Components/Statistic/doc/index.zh-CN.md b/site/AntDesign.Docs/Demos/Components/Statistic/doc/index.zh-CN.md index cdbf5e99..5a9a669d 100644 --- a/site/AntDesign.Docs/Demos/Components/Statistic/doc/index.zh-CN.md +++ b/site/AntDesign.Docs/Demos/Components/Statistic/doc/index.zh-CN.md @@ -19,23 +19,24 @@ cover: https://gw.alipayobjects.com/zos/antfincdn/rcBNhLBrKbE/Statistic.svg | 参数 | 说明 | 类型 | 默认值 | 版本 | | ---------------- | ---------------- | ---------------------------- | ------ | ---- | -| decimalSeparator | 设置小数点 | string | . | | -| groupSeparator | 设置千分位标识符 | string | , | | -| precision | 数值精度 | int | - | | -| prefix | 设置数值的前缀 | string\|RenderFragment | - | | -| suffix | 设置数值的后缀 | string\|RenderFragment | - | | -| title | 数值的标题 | string\|RenderFragment | - | | -| value | 数值内容 | decimal\|Datetime\|TimeSpan | - | | -| valueStyle | 设置数值的样式 | string | - | | +| CultureInfo | 用来获取数字格式的 CultureInfo 类 | CultureInfo | CurrentCultureInfo | | +| DecimalSeparator | 设置小数点 | string | . | | +| GroupSeparator | 设置千分位标识符 | string | , | | +| Precision | 数值精度 | int | - | | +| Prefix | 设置数值的前缀 | string\|RenderFragment | - | | +| Suffix | 设置数值的后缀 | string\|RenderFragment | - | | +| Title | 数值的标题 | string\|RenderFragment | - | | +| Value | 数值内容 | decimal\|Datetime\|TimeSpan | - | | +| ValueStyle | 设置数值的样式 | string | - | | #### Statistic.Countdown | 参数 | 说明 | 类型 | 默认值 | 版本 | | --- | --- | --- | --- | --- | -| format | 格式化倒计时展示,参考 [TimeSpan](https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/custom-timespan-format-strings?WT.mc_id=DT-MVP-5003987) | string | @"hh\:mm\:ss" | | -| onFinish | 倒计时完成时触发 | () => void | - | | -| prefix | 设置数值的前缀 | string \| RenderFragment | - | | -| suffix | 设置数值的后缀 | string \| RenderFragment | - | | -| title | 数值的标题 | string \| RenderFragment | - | | -| value | 数值内容 | Datetime \| TimeSpan | - | | -| valueStyle | 设置数值的样式 | string | - | | +| Format | 格式化倒计时展示,参考 [TimeSpan](https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/custom-timespan-format-strings?WT.mc_id=DT-MVP-5003987) | string | @"hh\:mm\:ss" | | +| OnFinish | 倒计时完成时触发 | () => void | - | | +| Prefix | 设置数值的前缀 | string \| RenderFragment | - | | +| Suffix | 设置数值的后缀 | string \| RenderFragment | - | | +| Title | 数值的标题 | string \| RenderFragment | - | | +| Value | 数值内容 | Datetime \| TimeSpan | - | | +| ValueStyle | 设置数值的样式 | string | - | |