@synerise/ds-format-picker 0.4.4 → 0.5.1
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.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.5.1](https://github.com/Synerise/synerise-design/compare/@synerise/ds-format-picker@0.5.0...@synerise/ds-format-picker@0.5.1) (2024-08-06)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @synerise/ds-format-picker
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [0.5.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-format-picker@0.4.4...@synerise/ds-format-picker@0.5.0) (2024-08-01)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* **format-picker:** add disabled and onFormattedValueChange props ([fb6c748](https://github.com/Synerise/synerise-design/commit/fb6c748e6a80e9ade59999066e9272d7acd3542d))
|
|
20
|
+
* **format-picker:** changes onSetDefault to optional prop ([9cec904](https://github.com/Synerise/synerise-design/commit/9cec904a3212eb5f8e64a16f0bd1964350a4aa7c))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
6
26
|
## [0.4.4](https://github.com/Synerise/synerise-design/compare/@synerise/ds-format-picker@0.4.3...@synerise/ds-format-picker@0.4.4) (2024-07-31)
|
|
7
27
|
|
|
8
28
|
**Note:** Version bump only for package @synerise/ds-format-picker
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
-
export type CurrencyType =
|
|
2
|
+
export type CurrencyType = string;
|
|
3
3
|
export type FormattingDataFormat = 'numeric' | 'percent' | 'cash';
|
|
4
4
|
export type FormattingValue = {
|
|
5
5
|
dataFormat: FormattingDataFormat;
|
|
@@ -35,8 +35,10 @@ export type FormatPickerProps = {
|
|
|
35
35
|
onUseSeparatorChange: (useSeparator: boolean) => void;
|
|
36
36
|
onCompactNumbersChange: (useCompact: boolean) => void;
|
|
37
37
|
onFixedLengthChange: (fixedLength: number) => void;
|
|
38
|
-
onSetDefault
|
|
38
|
+
onSetDefault?: () => void;
|
|
39
|
+
onFormattedValueChange?: (formattedValue: string) => void;
|
|
39
40
|
text?: Partial<FormatPickerTexts>;
|
|
40
41
|
currenciesConfig?: CurrencyConfig[];
|
|
41
42
|
buttonType?: string;
|
|
43
|
+
disabled?: boolean;
|
|
42
44
|
};
|
package/dist/FormatPicker.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FormatPickerProps } from './FomartPicker.types';
|
|
3
|
-
declare const FormatPicker: ({ onUseSeparatorChange, onFixedLengthChange, onDataFormatChange, onCurrencyChange, onCompactNumbersChange, onSetDefault, value, format, text, currenciesConfig, buttonType, }: FormatPickerProps) => React.JSX.Element;
|
|
3
|
+
declare const FormatPicker: ({ onUseSeparatorChange, onFixedLengthChange, onDataFormatChange, onCurrencyChange, onCompactNumbersChange, onSetDefault, onFormattedValueChange, value, format, text, currenciesConfig, buttonType, disabled, }: FormatPickerProps) => React.JSX.Element;
|
|
4
4
|
export default FormatPicker;
|
package/dist/FormatPicker.js
CHANGED
|
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
4
4
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
7
|
-
import React, { useMemo } from 'react';
|
|
7
|
+
import React, { useEffect, useMemo } from 'react';
|
|
8
8
|
import { useIntl } from 'react-intl';
|
|
9
9
|
import Button from '@synerise/ds-button';
|
|
10
10
|
import Dropdown from '@synerise/ds-dropdown';
|
|
@@ -19,12 +19,14 @@ var FormatPicker = function FormatPicker(_ref) {
|
|
|
19
19
|
onCurrencyChange = _ref.onCurrencyChange,
|
|
20
20
|
onCompactNumbersChange = _ref.onCompactNumbersChange,
|
|
21
21
|
onSetDefault = _ref.onSetDefault,
|
|
22
|
+
onFormattedValueChange = _ref.onFormattedValueChange,
|
|
22
23
|
value = _ref.value,
|
|
23
24
|
format = _ref.format,
|
|
24
25
|
text = _ref.text,
|
|
25
26
|
currenciesConfig = _ref.currenciesConfig,
|
|
26
27
|
_ref$buttonType = _ref.buttonType,
|
|
27
|
-
buttonType = _ref$buttonType === void 0 ? 'tertiary' : _ref$buttonType
|
|
28
|
+
buttonType = _ref$buttonType === void 0 ? 'tertiary' : _ref$buttonType,
|
|
29
|
+
disabled = _ref.disabled;
|
|
28
30
|
var intl = useIntl();
|
|
29
31
|
var texts = useMemo(function () {
|
|
30
32
|
return _objectSpread({
|
|
@@ -62,8 +64,19 @@ var FormatPicker = function FormatPicker(_ref) {
|
|
|
62
64
|
})
|
|
63
65
|
}, text);
|
|
64
66
|
}, [text, intl]);
|
|
67
|
+
var formattedValue = useMemo(function () {
|
|
68
|
+
return valueFormatter({
|
|
69
|
+
value: value,
|
|
70
|
+
formatting: format,
|
|
71
|
+
intl: intl
|
|
72
|
+
});
|
|
73
|
+
}, [value, format, intl]);
|
|
74
|
+
useEffect(function () {
|
|
75
|
+
onFormattedValueChange && onFormattedValueChange(formattedValue);
|
|
76
|
+
}, [formattedValue, onFormattedValueChange]);
|
|
65
77
|
return /*#__PURE__*/React.createElement(Dropdown, {
|
|
66
78
|
trigger: ['click'],
|
|
79
|
+
disabled: disabled,
|
|
67
80
|
overlay: /*#__PURE__*/React.createElement(FormatSettings, {
|
|
68
81
|
onCurrencyChange: onCurrencyChange,
|
|
69
82
|
onFixedLengthChange: onFixedLengthChange,
|
|
@@ -74,19 +87,17 @@ var FormatPicker = function FormatPicker(_ref) {
|
|
|
74
87
|
format: format,
|
|
75
88
|
value: value,
|
|
76
89
|
text: texts,
|
|
77
|
-
currenciesConfig: currenciesConfig
|
|
90
|
+
currenciesConfig: currenciesConfig,
|
|
91
|
+
disabled: disabled
|
|
78
92
|
}),
|
|
79
93
|
placement: "topCenter"
|
|
80
94
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
81
95
|
type: buttonType,
|
|
82
|
-
mode: "icon-label"
|
|
96
|
+
mode: "icon-label",
|
|
97
|
+
disabled: disabled
|
|
83
98
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
84
99
|
component: /*#__PURE__*/React.createElement(HashM, null)
|
|
85
|
-
}), texts.format + " " +
|
|
86
|
-
value: value,
|
|
87
|
-
formatting: format,
|
|
88
|
-
intl: intl
|
|
89
|
-
})));
|
|
100
|
+
}), texts.format + " " + formattedValue));
|
|
90
101
|
};
|
|
91
102
|
|
|
92
103
|
export default FormatPicker;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FormatSettingsProps } from './FormatSettings.types';
|
|
3
|
-
declare const FormatSettings: ({ onCompactNumbersChange, onCurrencyChange, onDataFormatChange, onFixedLengthChange, onUseSeparatorChange, onSetDefault, format, value, text, currenciesConfig, }: FormatSettingsProps) => React.JSX.Element;
|
|
3
|
+
declare const FormatSettings: ({ onCompactNumbersChange, onCurrencyChange, onDataFormatChange, onFixedLengthChange, onUseSeparatorChange, onSetDefault, format, value, text, currenciesConfig, disabled, }: FormatSettingsProps) => React.JSX.Element;
|
|
4
4
|
export default FormatSettings;
|
|
@@ -16,6 +16,19 @@ import Checkbox from '@synerise/ds-checkbox';
|
|
|
16
16
|
import Dropdown from '@synerise/ds-dropdown';
|
|
17
17
|
import * as S from './FormatSettings.styles';
|
|
18
18
|
import { valueFormatter } from '../utils/valueFormatter';
|
|
19
|
+
var DEFAULT_CURRENCIES_CONFIG = [{
|
|
20
|
+
currency: 'USD',
|
|
21
|
+
label: 'Dollar (US)'
|
|
22
|
+
}, {
|
|
23
|
+
currency: 'EUR',
|
|
24
|
+
label: 'Euro (EU)'
|
|
25
|
+
}, {
|
|
26
|
+
currency: 'PLN',
|
|
27
|
+
label: 'Złoty (PL)'
|
|
28
|
+
}, {
|
|
29
|
+
currency: 'JPY',
|
|
30
|
+
label: 'Yen (JP)'
|
|
31
|
+
}];
|
|
19
32
|
|
|
20
33
|
var getFormattingTypes = function getFormattingTypes(intl, text) {
|
|
21
34
|
return [{
|
|
@@ -33,22 +46,6 @@ var getFormattingTypes = function getFormattingTypes(intl, text) {
|
|
|
33
46
|
}];
|
|
34
47
|
};
|
|
35
48
|
|
|
36
|
-
var getCurrenciesConfig = function getCurrenciesConfig(currenciesConfig) {
|
|
37
|
-
return [{
|
|
38
|
-
currency: 'USD',
|
|
39
|
-
label: 'Dollar (US)'
|
|
40
|
-
}, {
|
|
41
|
-
currency: 'EUR',
|
|
42
|
-
label: 'Euro (EU)'
|
|
43
|
-
}, {
|
|
44
|
-
currency: 'PLN',
|
|
45
|
-
label: 'Złoty (PL)'
|
|
46
|
-
}, {
|
|
47
|
-
currency: 'JPY',
|
|
48
|
-
label: 'Yen (JP)'
|
|
49
|
-
}].concat(currenciesConfig);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
49
|
var FormatSettings = function FormatSettings(_ref) {
|
|
53
50
|
var onCompactNumbersChange = _ref.onCompactNumbersChange,
|
|
54
51
|
onCurrencyChange = _ref.onCurrencyChange,
|
|
@@ -59,7 +56,9 @@ var FormatSettings = function FormatSettings(_ref) {
|
|
|
59
56
|
format = _ref.format,
|
|
60
57
|
value = _ref.value,
|
|
61
58
|
text = _ref.text,
|
|
62
|
-
currenciesConfig = _ref.currenciesConfig
|
|
59
|
+
_ref$currenciesConfig = _ref.currenciesConfig,
|
|
60
|
+
currenciesConfig = _ref$currenciesConfig === void 0 ? DEFAULT_CURRENCIES_CONFIG : _ref$currenciesConfig,
|
|
61
|
+
disabled = _ref.disabled;
|
|
63
62
|
var intl = useIntl();
|
|
64
63
|
var handleDecreaseFixedLength = useCallback(function () {
|
|
65
64
|
if (format.fixedLength > 0) {
|
|
@@ -72,7 +71,7 @@ var FormatSettings = function FormatSettings(_ref) {
|
|
|
72
71
|
onFixedLengthChange(format.fixedLength + 1);
|
|
73
72
|
}, [onFixedLengthChange, format]);
|
|
74
73
|
var selectedCurrency = useMemo(function () {
|
|
75
|
-
return
|
|
74
|
+
return currenciesConfig.find(function (currency) {
|
|
76
75
|
return currency.currency === format.currency;
|
|
77
76
|
});
|
|
78
77
|
}, [currenciesConfig, format]);
|
|
@@ -96,7 +95,8 @@ var FormatSettings = function FormatSettings(_ref) {
|
|
|
96
95
|
"data-testid": "ds-format-picker-type-" + type.format,
|
|
97
96
|
onClick: function onClick() {
|
|
98
97
|
return onDataFormatChange(type.format);
|
|
99
|
-
}
|
|
98
|
+
},
|
|
99
|
+
disabled: disabled
|
|
100
100
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
101
101
|
component: type.icon
|
|
102
102
|
})));
|
|
@@ -105,18 +105,21 @@ var FormatSettings = function FormatSettings(_ref) {
|
|
|
105
105
|
}, /*#__PURE__*/React.createElement(S.FixedLengthButton, {
|
|
106
106
|
type: "secondary",
|
|
107
107
|
mode: "icon",
|
|
108
|
-
onClick: handleDecreaseFixedLength
|
|
108
|
+
onClick: handleDecreaseFixedLength,
|
|
109
|
+
disabled: disabled
|
|
109
110
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
110
111
|
component: /*#__PURE__*/React.createElement(CommaDecM, null)
|
|
111
112
|
})), /*#__PURE__*/React.createElement(S.FixedLengthButton, {
|
|
112
113
|
type: "secondary",
|
|
113
114
|
mode: "icon",
|
|
114
|
-
onClick: handleIncreaseFixedLength
|
|
115
|
+
onClick: handleIncreaseFixedLength,
|
|
116
|
+
disabled: disabled
|
|
115
117
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
116
118
|
component: /*#__PURE__*/React.createElement(CommaIncM, null)
|
|
117
119
|
})))), /*#__PURE__*/React.createElement(S.FormatOptions, null, format.dataFormat === 'cash' && /*#__PURE__*/React.createElement(Dropdown, {
|
|
118
120
|
trigger: ['click'],
|
|
119
|
-
|
|
121
|
+
disabled: disabled,
|
|
122
|
+
overlay: /*#__PURE__*/React.createElement(S.DropdownWrapper, null, currenciesConfig.map(function (_ref2) {
|
|
120
123
|
var currency = _ref2.currency,
|
|
121
124
|
label = _ref2.label;
|
|
122
125
|
return /*#__PURE__*/React.createElement(S.ListItem, {
|
|
@@ -141,15 +144,18 @@ var FormatSettings = function FormatSettings(_ref) {
|
|
|
141
144
|
onChange: function onChange(event) {
|
|
142
145
|
return onUseSeparatorChange(event.target.checked);
|
|
143
146
|
},
|
|
144
|
-
checked: format.useSeparator
|
|
147
|
+
checked: format.useSeparator,
|
|
148
|
+
disabled: disabled
|
|
145
149
|
}, text.useSeparator), /*#__PURE__*/React.createElement(Checkbox, {
|
|
146
150
|
onChange: function onChange(event) {
|
|
147
151
|
return onCompactNumbersChange(event.target.checked);
|
|
148
152
|
},
|
|
149
|
-
checked: format.compactNumbers
|
|
150
|
-
|
|
153
|
+
checked: format.compactNumbers,
|
|
154
|
+
disabled: disabled
|
|
155
|
+
}, text.compactNumbers))), onSetDefault && /*#__PURE__*/React.createElement(S.FormatFooter, null, /*#__PURE__*/React.createElement(Button, {
|
|
151
156
|
type: "ghost",
|
|
152
|
-
onClick: onSetDefault
|
|
157
|
+
onClick: onSetDefault,
|
|
158
|
+
disabled: disabled
|
|
153
159
|
}, text.setDefault)));
|
|
154
160
|
};
|
|
155
161
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-format-picker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "FormatPicker UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "Synerise/synerise-design",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"types": "dist/index.d.ts",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@synerise/ds-button": "^0.21.4",
|
|
37
|
-
"@synerise/ds-button-group": "^0.7.
|
|
38
|
-
"@synerise/ds-checkbox": "^0.12.
|
|
39
|
-
"@synerise/ds-dropdown": "^0.18.
|
|
37
|
+
"@synerise/ds-button-group": "^0.7.8",
|
|
38
|
+
"@synerise/ds-checkbox": "^0.12.4",
|
|
39
|
+
"@synerise/ds-dropdown": "^0.18.8",
|
|
40
40
|
"@synerise/ds-icon": "^0.64.1",
|
|
41
|
-
"@synerise/ds-list-item": "^0.4.
|
|
42
|
-
"@synerise/ds-radio": "^0.11.
|
|
41
|
+
"@synerise/ds-list-item": "^0.4.4",
|
|
42
|
+
"@synerise/ds-radio": "^0.11.76",
|
|
43
43
|
"@synerise/ds-tooltip": "^0.14.34",
|
|
44
44
|
"@synerise/ds-typography": "^0.15.1",
|
|
45
45
|
"@types/numeral": "^2.0.2",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"react": ">=16.9.0 <= 17.0.2",
|
|
53
53
|
"styled-components": "5.0.1"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "14a9cfb86e5d548d5511ed7cdb23088dcb8b9a2d"
|
|
56
56
|
}
|