@antscorp/antsomi-ui 2.0.59 → 2.0.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ export declare const EllipsisMiddle: React.FC<{
3
+ suffixCount: number;
4
+ children: string;
5
+ tooltip?: string;
6
+ style?: React.CSSProperties;
7
+ }>;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Typography } from 'antd';
3
+ export const EllipsisMiddle = ({ suffixCount, children, tooltip = false, style }) => {
4
+ if (children.length <= suffixCount)
5
+ return _jsx(Typography.Text, { style: style, children: children });
6
+ const start = children.slice(0, children.length - suffixCount);
7
+ const suffix = children.slice(-suffixCount);
8
+ return (_jsx(Typography.Text, { style: style, ellipsis: { tooltip: tooltip ? _jsx("bdo", { dir: "ltr", children: tooltip }) : false, suffix }, children: start }));
9
+ };
@@ -1 +1,2 @@
1
1
  export { Typography } from './Text';
2
+ export { EllipsisMiddle } from './EllipsisMiddle';
@@ -1 +1,2 @@
1
1
  export { Typography } from './Text';
2
+ export { EllipsisMiddle } from './EllipsisMiddle';
@@ -6,7 +6,7 @@ export { Radio, RadioGroupSub, RadioButton } from './Radio';
6
6
  export { Space } from './Space';
7
7
  export { Tag } from './Tag';
8
8
  export { Tooltip } from './Tooltip';
9
- export { Typography } from './Typography';
9
+ export { Typography, EllipsisMiddle } from './Typography';
10
10
  export { Checkbox } from './Checkbox';
11
11
  export { message } from './Message';
12
12
  export { Segmented } from './Segmented';
@@ -6,7 +6,7 @@ export { Radio, RadioGroupSub, RadioButton } from './Radio';
6
6
  export { Space } from './Space';
7
7
  export { Tag } from './Tag';
8
8
  export { Tooltip } from './Tooltip';
9
- export { Typography } from './Typography';
9
+ export { Typography, EllipsisMiddle } from './Typography';
10
10
  export { Checkbox } from './Checkbox';
11
11
  export { message } from './Message';
12
12
  export { Segmented } from './Segmented';
@@ -1,20 +1,23 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
2
  // Libraries
3
3
  import { useEffect, useState } from 'react';
4
4
  import { translate, translations } from '@antscorp/antsomi-locales';
5
5
  // Components
6
6
  import { FormatDatetime, FormatNumber, } from './components';
7
7
  import { EditIcon } from '../../icons';
8
- import { Button, Text } from '../../atoms';
8
+ import { Button, EllipsisMiddle, Typography } from '../../atoms';
9
9
  // Utils
10
10
  import { formatDatetimeDF, formatNumberDF } from './utils';
11
11
  // Constants
12
12
  import { DATE_TIME_EXAMPLE, DATETIME_SETTINGS_DEFAULT, NUMBER_SETTINGS_DEFAULT, NUMBER_EXAMPLE, } from './constants';
13
+ // Json
14
+ import Currencies from './currencies.json';
13
15
  export const DisplayFormatSettings = props => {
14
16
  const { infos, url, displayFormatType, formatSettings, dynamicContentType, onSettingsChange, disabled, ...rest } = props;
15
17
  const [settings, setSettings] = useState(formatSettings ??
16
18
  (displayFormatType === 'datetime' ? DATETIME_SETTINGS_DEFAULT : NUMBER_SETTINGS_DEFAULT));
17
19
  const [showDetailEdit, setShowDetailEdit] = useState(false);
20
+ const [prefixSymbol, setPrefixSymbol] = useState(undefined);
18
21
  useEffect(() => {
19
22
  setSettings(displayFormatType === 'datetime' ? DATETIME_SETTINGS_DEFAULT : NUMBER_SETTINGS_DEFAULT);
20
23
  }, [displayFormatType]);
@@ -22,6 +25,14 @@ export const DisplayFormatSettings = props => {
22
25
  if (Object.keys(formatSettings).length > 0) {
23
26
  setSettings(formatSettings);
24
27
  }
28
+ if (displayFormatType === 'currency' &&
29
+ formatSettings.prefixType === 'symbol' &&
30
+ Currencies[formatSettings.currencyCode].symbolOnLeft) {
31
+ setPrefixSymbol(Currencies[formatSettings.currencyCode].symbol);
32
+ }
33
+ else {
34
+ setPrefixSymbol(undefined);
35
+ }
25
36
  }, [formatSettings]);
26
37
  const handleChangeFormat = (updatedSettings) => {
27
38
  if (onSettingsChange) {
@@ -43,15 +54,40 @@ export const DisplayFormatSettings = props => {
43
54
  if (displayFormatType === 'datetime') {
44
55
  formatDFValue = formatDatetimeDF(DATE_TIME_EXAMPLE, settings);
45
56
  }
46
- return (_jsxs("div", { className: "ants-flex ants-flex-wrap ants-items-center ants-mt-1 ants-gap-2 ant-flex-row", style: { display: 'flex', alignItems: 'end', gap: '8px', marginBottom: '5px' }, ...rest, children: [_jsx(Text, { size: 11, className: "ants-flex", color: "#7F7F7F", dangerouslySetInnerHTML: {
47
- __html: `${translate(translations._ACT_PREVIEW)}: &nbsp;<bdo dir='ltr'>${formatDFValue}</bdo>`,
48
- } }), _jsx(Button, { disabled: disabled, size: "small", icon: _jsx(EditIcon, { width: 16, height: 16, color: "#005EB8" }), className: "ants-border-none", style: {
49
- marginTop: '1px',
50
- backgroundColor: showDetailEdit ? '#DEEFFE' : 'transparent',
51
- border: 'none',
52
- boxShadow: 'none',
53
- borderRadius: '5px',
54
- }, onClick: () => setShowDetailEdit(prevShow => !prevShow) })] }));
57
+ return (_jsxs("div", { className: "ants-flex ants-items-center ant-flex-row", style: {
58
+ display: 'flex',
59
+ alignItems: 'center',
60
+ marginBottom: '5px',
61
+ flexShrink: 0,
62
+ width: '100%',
63
+ flexWrap: 'nowrap',
64
+ marginTop: '5px',
65
+ }, ...rest, children: [_jsxs(Typography.Text, { className: "ants-flex", style: {
66
+ color: '#7F7F7F',
67
+ fontSize: '11px',
68
+ whiteSpace: 'nowrap',
69
+ maxWidth: '100%',
70
+ }, children: [translate(translations._ACT_PREVIEW), ": \u00A0"] }), prefixSymbol && (_jsx("bdo", { dir: "ltr", style: { color: '#7F7F7F', fontSize: '11px' }, children: prefixSymbol })), _jsxs("div", { style: { display: 'inline-flex', maxWidth: '100%', alignItems: 'center' }, dir: "ltr", children: [_jsx(EllipsisMiddle, { style: {
71
+ color: '#7F7F7F',
72
+ fontSize: '11px',
73
+ whiteSpace: 'nowrap',
74
+ flexShrink: 0,
75
+ width: displayFormatType === 'datetime'
76
+ ? '100%'
77
+ : `calc(100% - (2px + ${translate(translations._ACT_PREVIEW).length * 0.35}px))`,
78
+ flexGrow: 1,
79
+ maxWidth: displayFormatType === 'datetime'
80
+ ? '100%'
81
+ : prefixSymbol
82
+ ? `calc(99% - (${prefixSymbol.length * 0.1}px + 1px))`
83
+ : `calc(100% - 2.5px)`,
84
+ }, suffixCount: 7, tooltip: prefixSymbol ? `${prefixSymbol}${formatDFValue}` : formatDFValue, children: formatDFValue }), _jsx(Button, { disabled: disabled, size: "small", icon: _jsx(EditIcon, { width: 16, height: 16, color: "#005EB8" }), className: "ants-border-none", style: {
85
+ backgroundColor: showDetailEdit ? '#DEEFFE' : 'transparent',
86
+ border: 'none',
87
+ boxShadow: 'none',
88
+ borderRadius: '5px',
89
+ flexShrink: 0,
90
+ }, onClick: () => setShowDetailEdit(prevShow => !prevShow) })] })] }));
55
91
  };
56
92
  const renderFormatSetting = () => {
57
93
  switch (displayFormatType) {
@@ -112,18 +112,18 @@ export const FormatNumber = (props) => {
112
112
  ...settingValues,
113
113
  isCompact: checked,
114
114
  });
115
- }, children: t(translations.dynamicContent.modal.label.formNumberDisplayFormat.compact) }) }), _jsx(Form.Item, { label: decimalPlacesLabel, style: { marginBottom: 12 }, colon: false, labelCol: { span: 10 }, wrapperCol: { span: 14 }, children: _jsxs("div", { style: { display: 'flex', marginLeft: '55px', gap: '15px' }, children: [_jsx(Button, { style: { border: 'none', boxShadow: 'none', borderRadius: '5px' }, disabled: decimalPlaces <= 0, onClick: () => onChangeSettingsHandle({
115
+ }, children: translate(translations._TITL_EDIT_NUMBER_COMPACT) }) }), _jsx(Form.Item, { label: decimalPlacesLabel, style: { marginBottom: 12 }, colon: false, labelCol: { span: 12 }, wrapperCol: { span: 12 }, children: _jsxs("div", { style: { display: 'flex', marginLeft: '55px', gap: '15px' }, children: [_jsx(Button, { style: { border: 'none', boxShadow: 'none', borderRadius: '5px' }, disabled: decimalPlaces <= 0, onClick: () => onChangeSettingsHandle({
116
116
  ...settingValues,
117
117
  decimalPlaces: decimalPlaces - 1,
118
118
  }), size: "small", icon: _jsx(DecreaseDecimalIcon, { color: "#005EB8", style: { padding: '2px' } }) }), _jsx(Button, { style: { border: 'none', boxShadow: 'none', borderRadius: '5px' }, onClick: () => onChangeSettingsHandle({
119
119
  ...settingValues,
120
120
  decimalPlaces: decimalPlaces + 1,
121
- }), size: "small", icon: _jsx(IncreaseDecimalIcon, { color: "#005EB8", style: { padding: '2px' } }) })] }) }), _jsx(Form.Item, { label: _jsxs(_Fragment, { children: [_jsx("span", { style: { marginRight: '6px' }, children: translate(translations._DISPLAY_GROUPING) }), _jsx(Tooltip, { placement: "top", title: t(translations.dynamicContent.modal.label.formNumberDisplayFormat
122
- .groupingIconTooltipTitle), style: { marginLeft: 4, opacity: 0.4 }, children: _jsx(ViewDetailsInformationIcon, { size: 14 }) })] }), colon: false, labelCol: { span: 10 }, wrapperCol: { span: 14 }, children: _jsx(Select, { style: { width: 100 }, value: grouping, onChange: value => onChangeSettingsHandle({
121
+ }),
122
+ // disabled={decimalPlaces >= 100}
123
+ size: "small", icon: _jsx(IncreaseDecimalIcon, { color: "#005EB8", style: { padding: '2px' } }) })] }) }), _jsx(Form.Item, { label: _jsxs(_Fragment, { children: [_jsx("span", { style: { marginRight: '6px' }, children: translate(translations._DISPLAY_GROUPING) }), _jsx(Tooltip, { placement: "top", title: translate(translations._TOOLTIP__DISPLAY_DECIMAL), style: { marginLeft: 4, opacity: 0.4 }, children: _jsx(ViewDetailsInformationIcon, { size: 14 }) })] }), colon: false, labelCol: { span: 10 }, wrapperCol: { span: 14 }, children: _jsx(Select, { style: { width: 100 }, value: grouping, onChange: value => onChangeSettingsHandle({
123
124
  ...settingValues,
124
125
  grouping: value,
125
- }), options: listGroupingSeparatorOptions }) }), _jsx(Form.Item, { label: _jsxs(_Fragment, { children: [_jsx("span", { style: { marginRight: '6px' }, children: translate(translations._DISPLAY_DECIMAL) }), _jsx(Tooltip, { placement: "top", title: t(translations.dynamicContent.modal.label.formNumberDisplayFormat
126
- .decimalIconTooltipTitle), style: { marginLeft: 4, opacity: 0.4 }, children: _jsx(ViewDetailsInformationIcon, { size: 14 }) })] }), labelCol: { span: 10 }, wrapperCol: { span: 14 }, colon: false, children: _jsx(Select, { style: { width: 100 }, value: decimal, onChange: value => onChangeSettingsHandle({
126
+ }), options: listGroupingSeparatorOptions }) }), _jsx(Form.Item, { label: _jsxs(_Fragment, { children: [_jsx("span", { style: { marginRight: '6px' }, children: translate(translations._DISPLAY_DECIMAL) }), _jsx(Tooltip, { placement: "top", title: translate(translations._TOOLTIP__DISPLAY_GROUPING), style: { marginLeft: 4, opacity: 0.4 }, children: _jsx(ViewDetailsInformationIcon, { size: 14 }) })] }), labelCol: { span: 10 }, wrapperCol: { span: 14 }, colon: false, children: _jsx(Select, { style: { width: 100 }, value: decimal, onChange: value => onChangeSettingsHandle({
127
127
  ...settingValues,
128
128
  decimal: value,
129
129
  }), options: listDecimalSeparatorOptions }) })] }));
@@ -149,3 +149,24 @@ export declare const DYNAMIC_CONTENT_DF_FORMAT_TYPE: {
149
149
  number: string;
150
150
  datetime: string;
151
151
  };
152
+ export declare const TYPE_FORMAT_OPTIONS: {
153
+ SHORT: string;
154
+ MEDIUM: string;
155
+ LONG: string;
156
+ };
157
+ export declare const DATE_FORMAT_LIST_TEST: {
158
+ [x: string]: {
159
+ [x: string]: {
160
+ label: string;
161
+ value: string;
162
+ };
163
+ };
164
+ };
165
+ export declare const TIME_FORMAT_LIST_TEST: {
166
+ [x: string]: {
167
+ [x: string]: {
168
+ label: string;
169
+ value: string;
170
+ };
171
+ };
172
+ };
@@ -239,3 +239,68 @@ export const DYNAMIC_CONTENT_DF_FORMAT_TYPE = {
239
239
  number: 'number',
240
240
  datetime: 'datetime',
241
241
  };
242
+ export const TYPE_FORMAT_OPTIONS = {
243
+ SHORT: 'short',
244
+ MEDIUM: 'medium',
245
+ LONG: 'long',
246
+ };
247
+ export const DATE_FORMAT_LIST_TEST = {
248
+ [DATE_FORMAT_OPTIONS[0].value]: {
249
+ [TYPE_FORMAT_OPTIONS.SHORT]: {
250
+ label: translate(translations._DATE_SHORT_FORMAT1),
251
+ value: 'MM/DD/YYYY',
252
+ },
253
+ [TYPE_FORMAT_OPTIONS.MEDIUM]: {
254
+ label: translate(translations._DATE_MEDIUM_FORMAT1),
255
+ value: 'MMM DD, YYYY',
256
+ },
257
+ [TYPE_FORMAT_OPTIONS.LONG]: {
258
+ label: translate(translations._DATE_LONG_FORMAT1),
259
+ value: 'MMMM DD, YYYY',
260
+ },
261
+ },
262
+ [DATE_FORMAT_OPTIONS[1].value]: {
263
+ [TYPE_FORMAT_OPTIONS.SHORT]: {
264
+ label: translate(translations._DATE_SHORT_FORMAT2),
265
+ value: 'DD/MM/YYYY',
266
+ },
267
+ [TYPE_FORMAT_OPTIONS.MEDIUM]: {
268
+ label: translate(translations._DATE_MEDIUM_FORMAT2),
269
+ value: 'DD MMM, YYYY',
270
+ },
271
+ [TYPE_FORMAT_OPTIONS.LONG]: {
272
+ label: translate(translations._DATE_LONG_FORMAT2),
273
+ value: 'DD MMMM, YYYY',
274
+ },
275
+ },
276
+ };
277
+ export const TIME_FORMAT_LIST_TEST = {
278
+ [TIME_FORMAT_OPTIONS[0].value]: {
279
+ [TYPE_FORMAT_OPTIONS.SHORT]: {
280
+ label: translate(translations._TIME_SHORT_FOTMAT1),
281
+ value: 'h:mm A',
282
+ },
283
+ [TYPE_FORMAT_OPTIONS.MEDIUM]: {
284
+ label: translate(translations._TIME_MEDIUM_FORMAT1),
285
+ value: 'h:mm:ss A',
286
+ },
287
+ [TYPE_FORMAT_OPTIONS.LONG]: {
288
+ label: translate(translations._TIME_LONG_FORMAT1),
289
+ value: 'h:mm:ss A [GMT]',
290
+ },
291
+ },
292
+ [TIME_FORMAT_OPTIONS[1].value]: {
293
+ [TYPE_FORMAT_OPTIONS.SHORT]: {
294
+ label: translate(translations._TIME_SHORT_FOTMAT2),
295
+ value: 'H:mm',
296
+ },
297
+ [TYPE_FORMAT_OPTIONS.MEDIUM]: {
298
+ label: translate(translations._TIME_MEDIUM_FORMAT2),
299
+ value: 'H:mm:ss',
300
+ },
301
+ [TYPE_FORMAT_OPTIONS.LONG]: {
302
+ label: translate(translations._TIME_LONG_FORMAT2),
303
+ value: 'H:mm:ss [GMT]',
304
+ },
305
+ },
306
+ };
@@ -1,9 +1,9 @@
1
1
  /* eslint-disable prefer-regex-literals */
2
2
  // Libraries
3
3
  import dayjs from 'dayjs';
4
- import currencyFormatter from 'currency-formatter';
5
4
  import { has, get, set } from 'lodash';
6
5
  import 'dayjs/locale/vi';
6
+ import BigNumber from 'bignumber.js';
7
7
  // Json
8
8
  import Currencies from './currencies.json';
9
9
  // Constants
@@ -114,12 +114,15 @@ export function formatNumberDF(number, fType, fOptions = {
114
114
  });
115
115
  let formatedCompactNumber;
116
116
  if (item) {
117
- const compactNumber = (number / item.value).toFixed(decimalPlaces).replace(rx, '$1');
117
+ const bigNum = new BigNumber(number);
118
+ const divisor = new BigNumber(item.value);
119
+ const numString = bigNum.div(divisor).toFixed(decimalPlaces);
120
+ const [integerPart, decimalPart] = numString.split('.');
121
+ const formattedInteger = new Intl.NumberFormat('en-US').format(Number(integerPart));
118
122
  formatedCompactNumber =
119
- currencyFormatter.format(Number(compactNumber), {
120
- decimal,
121
- precision: decimalPlaces,
122
- }) + item.symbol;
123
+ formattedInteger.replace(/,/g, grouping !== 'none' ? grouping || '' : '') +
124
+ (decimalPart ? decimal + decimalPart : '') +
125
+ item.symbol;
123
126
  }
124
127
  else {
125
128
  formatedCompactNumber = '0';
@@ -128,11 +131,13 @@ export function formatNumberDF(number, fType, fOptions = {
128
131
  result.textNumberFormated = formatedCompactNumber;
129
132
  }
130
133
  else {
131
- result.textNumberFormated = currencyFormatter.format(number, {
132
- thousand: grouping === 'none' ? '' : grouping,
133
- decimal,
134
- precision: decimalPlaces,
135
- });
134
+ const bigNum = new BigNumber(number);
135
+ const numString = bigNum.toFixed(decimalPlaces);
136
+ const [integerPart, decimalPart] = numString.split('.');
137
+ const formattedInteger = new Intl.NumberFormat('en-US').format(Number(integerPart));
138
+ result.textNumberFormated =
139
+ formattedInteger.replace(/,/g, grouping !== 'none' ? grouping || '' : '') +
140
+ (decimalPart ? decimal + decimalPart : '');
136
141
  }
137
142
  switch (fType) {
138
143
  case 'percentage':
@@ -167,7 +172,7 @@ export function formatNumberDF(number, fType, fOptions = {
167
172
  let html = result.textNumberFormated;
168
173
  if (result.hasSymbol) {
169
174
  if (result.symbolOnLeft) {
170
- html = `${result.symbol}${html}`;
175
+ html = `${html}`;
171
176
  }
172
177
  else {
173
178
  html = `${html}${result.symbol}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "2.0.59",
3
+ "version": "2.0.60",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",
@@ -64,6 +64,7 @@
64
64
  "@antscorp/antsomi-locales": "1.0.49",
65
65
  "@antscorp/image-editor": "1.0.2",
66
66
  "@antscorp/processing-notification": "^1.0.3",
67
+ "bignumber.js": "9.1.2",
67
68
  "@dnd-kit/core": "^6.1.0",
68
69
  "@dnd-kit/modifiers": "^7.0.0",
69
70
  "@dnd-kit/sortable": "^8.0.0",