@synerise/ds-completed-within 0.3.15 → 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,43 @@
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-completed-within@0.5.0...@synerise/ds-completed-within@0.5.1) (2022-05-13)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **completed-within:** fixes clearing tooltip ([b9e0520](https://github.com/Synerise/synerise-design/commit/b9e05208d75069b03e9671981ea061f0e6183c99))
12
+ * **completed-within:** fixes maxValues in btn label ([46c73ad](https://github.com/Synerise/synerise-design/commit/46c73ad326737bd355ba949fcfeceb58b0035d3e))
13
+
14
+
15
+
16
+
17
+
18
+ # [0.5.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-completed-within@0.4.0...@synerise/ds-completed-within@0.5.0) (2022-04-29)
19
+
20
+
21
+ ### Features
22
+
23
+ * **completed-within:** adds maxValue prop ([cc20e27](https://github.com/Synerise/synerise-design/commit/cc20e2788e2840a9d78bd51cb43a1928fb64e958))
24
+ * **completed-within:** adds tooltip for trigger button ([694812e](https://github.com/Synerise/synerise-design/commit/694812e9179e79c8f8fa4d12054d2704d7abcab3))
25
+ * **completed-within:** replace || by ?? in maxValue ([d36c970](https://github.com/Synerise/synerise-design/commit/d36c970832fcc835881a15a0d013b5c5225c4c72))
26
+
27
+
28
+
29
+
30
+
31
+ # [0.4.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-completed-within@0.3.15...@synerise/ds-completed-within@0.4.0) (2022-04-05)
32
+
33
+
34
+ ### Features
35
+
36
+ * **completed-within:** adds placeholder nad tooltip props ([22976de](https://github.com/Synerise/synerise-design/commit/22976deac9012e1654b86ad745da7207e664ad88))
37
+ * **completed-within:** adds placeholder prop ([6aa6e91](https://github.com/Synerise/synerise-design/commit/6aa6e91cb9fae233d6c2e1cf447fd91082c67686))
38
+
39
+
40
+
41
+
42
+
6
43
  ## [0.3.15](https://github.com/Synerise/synerise-design/compare/@synerise/ds-completed-within@0.3.14...@synerise/ds-completed-within@0.3.15) (2022-03-30)
7
44
 
8
45
  **Note:** Version bump only for package @synerise/ds-completed-within
package/README.md CHANGED
@@ -29,12 +29,15 @@ import CompletedWithin from '@synerise/ds-completed-within'
29
29
 
30
30
  ## API
31
31
 
32
- | Property | Description | Type | Default |
33
- | --- | --- | --- | --- |
34
- | text | Custom labels and tooltips | CompletedWithinTexts | - |
35
- | value | Selected value | PeriodValue | { value: undefined, period: 'YEARS'} |
36
- | onSetValue | Function called when user has closed the settings with set value, and period | (value: PeriodValue) => void | - |
37
- | periods | Custom list of periods | CustomPeriod[] | - |
32
+ | Property | Description | Type | Default |
33
+ | --- | --- | --- | --- |
34
+ | text | Custom labels and tooltips | CompletedWithinTexts | - |
35
+ | value | Selected value | PeriodValue | { value: undefined, period: 'YEARS'} |
36
+ | maxValue | Max value | PeriodValue[value] | Number.MAX_SAFE_INTEGER |
37
+ | onSetValue | Function called when user has closed the settings with set value, and period | (value: PeriodValue) => void | - |
38
+ | periods | Custom list of periods | CustomPeriod[] | - |
39
+ | placeholder | Trigger button label | string | - |
40
+ | tooltip | Content of tooltip | string | - |
38
41
 
39
42
  ### CompletedWithinTexts
40
43
 
@@ -12,13 +12,15 @@ import Tooltip from '@synerise/ds-tooltip';
12
12
  import Settings from './Settings/Settings';
13
13
  import * as S from './CompleteWithin.styles';
14
14
  export var DEFAULT_PERIODS = ['SECONDS', 'MINUTES', 'HOURS', 'DAYS', 'MONTHS', 'YEARS'];
15
- var DEFAULT_PERIOD = 'DAYS';
16
15
 
17
16
  var CompletedWithin = function CompletedWithin(_ref) {
18
17
  var value = _ref.value,
18
+ maxValue = _ref.maxValue,
19
19
  onSetValue = _ref.onSetValue,
20
20
  text = _ref.text,
21
- periods = _ref.periods;
21
+ periods = _ref.periods,
22
+ placeholder = _ref.placeholder,
23
+ tooltip = _ref.tooltip;
22
24
  var intl = useIntl();
23
25
  var texts = React.useMemo(function () {
24
26
  return _objectSpread({
@@ -60,21 +62,33 @@ var CompletedWithin = function CompletedWithin(_ref) {
60
62
  innerValue = _React$useState[0],
61
63
  setInnerValue = _React$useState[1];
62
64
 
63
- var _React$useState2 = React.useState(value.period || DEFAULT_PERIOD),
65
+ var _React$useState2 = React.useState(value.period),
64
66
  innerPeriod = _React$useState2[0],
65
67
  setInnerPeriod = _React$useState2[1];
66
68
 
69
+ var _React$useState3 = React.useState(false),
70
+ tooltipVisible = _React$useState3[0],
71
+ setTooltipVisible = _React$useState3[1];
72
+
73
+ var _React$useState4 = React.useState(false),
74
+ settingsVisible = _React$useState4[0],
75
+ setSettingsVisible = _React$useState4[1];
76
+
67
77
  var hasValue = React.useMemo(function () {
68
78
  return value.value !== undefined && value.value > 0;
69
79
  }, [value]);
70
80
  var handleVisibleChange = React.useCallback(function (visible) {
81
+ setSettingsVisible(visible);
82
+ setTooltipVisible(false);
83
+
71
84
  if (!visible && innerValue && innerPeriod) {
85
+ var newValue = maxValue && maxValue < innerValue ? maxValue : innerValue;
72
86
  onSetValue({
73
- value: Number(innerValue),
87
+ value: Number(newValue),
74
88
  period: innerPeriod
75
89
  });
76
90
  }
77
- }, [innerPeriod, innerValue, onSetValue]);
91
+ }, [innerPeriod, innerValue, maxValue, onSetValue]);
78
92
  var handleClear = React.useCallback(function () {
79
93
  setInnerPeriod(undefined);
80
94
  setInnerValue(undefined);
@@ -84,24 +98,25 @@ var CompletedWithin = function CompletedWithin(_ref) {
84
98
  });
85
99
  }, [onSetValue]);
86
100
  var triggerMode = React.useMemo(function () {
87
- if (!hasValue) return 'single-icon';
88
- return 'icon-label';
89
- }, [hasValue]);
101
+ if (hasValue || placeholder) return 'icon-label';
102
+ return 'single-icon';
103
+ }, [hasValue, placeholder]);
90
104
  var triggerLabel = React.useMemo(function () {
91
105
  var _getPeriods$find;
92
106
 
93
- return hasValue && texts.completedLabel + " " + value.value + " " + ((_getPeriods$find = getPeriods.find(function (singlePeriod) {
107
+ return hasValue ? texts.completedLabel + " " + value.value + " " + ((_getPeriods$find = getPeriods.find(function (singlePeriod) {
94
108
  return singlePeriod.value === value.period;
95
- })) == null ? void 0 : _getPeriods$find.label);
96
- }, [getPeriods, hasValue, texts, value]);
109
+ })) == null ? void 0 : _getPeriods$find.label) : placeholder;
110
+ }, [getPeriods, hasValue, texts, value, placeholder]);
97
111
  return /*#__PURE__*/React.createElement(S.CompletedWithinWrapper, {
98
112
  withValue: hasValue
99
113
  }, /*#__PURE__*/React.createElement(Dropdown, {
100
114
  overlay: /*#__PURE__*/React.createElement(Settings, {
101
115
  value: {
102
- value: Number(innerValue),
116
+ value: innerValue !== undefined ? Number(innerValue) : undefined,
103
117
  period: innerPeriod
104
118
  },
119
+ maxValue: maxValue,
105
120
  onValueChange: setInnerValue,
106
121
  onPeriodChange: setInnerPeriod,
107
122
  text: texts,
@@ -110,13 +125,19 @@ var CompletedWithin = function CompletedWithin(_ref) {
110
125
  trigger: ['click'],
111
126
  onVisibleChange: handleVisibleChange,
112
127
  placement: "topLeft"
128
+ }, /*#__PURE__*/React.createElement(Tooltip, {
129
+ type: "largeSimple",
130
+ description: tooltip,
131
+ trigger: ['hover'],
132
+ onVisibleChange: setTooltipVisible,
133
+ visible: !settingsVisible && tooltipVisible
113
134
  }, /*#__PURE__*/React.createElement(S.TriggerButton, {
114
135
  className: "ds-completed-within",
115
136
  type: "tertiary",
116
137
  mode: triggerMode
117
138
  }, /*#__PURE__*/React.createElement(Icon, {
118
139
  component: /*#__PURE__*/React.createElement(ClockM, null)
119
- }), triggerLabel)), hasValue && /*#__PURE__*/React.createElement(Tooltip, {
140
+ }), triggerLabel))), hasValue && /*#__PURE__*/React.createElement(Tooltip, {
120
141
  title: texts.clear
121
142
  }, /*#__PURE__*/React.createElement(S.ClearButton, {
122
143
  mode: "single-icon",
@@ -17,6 +17,9 @@ export declare type PeriodValue = {
17
17
  export declare type CompletedWithinProps = {
18
18
  text?: CompletedWithinTexts;
19
19
  value: PeriodValue;
20
+ maxValue?: PeriodValue['value'];
20
21
  onSetValue: (value: PeriodValue) => void;
21
22
  periods?: CustomPeriod[];
23
+ placeholder?: string | undefined;
24
+ tooltip?: string;
22
25
  };
@@ -9,7 +9,8 @@ var Settings = function Settings(_ref) {
9
9
  text = _ref.text,
10
10
  onPeriodChange = _ref.onPeriodChange,
11
11
  onValueChange = _ref.onValueChange,
12
- periods = _ref.periods;
12
+ periods = _ref.periods,
13
+ maxValue = _ref.maxValue;
13
14
  return /*#__PURE__*/React.createElement(S.Settings, null, /*#__PURE__*/React.createElement(InputGroup, {
14
15
  size: "default",
15
16
  label: text.header,
@@ -20,7 +21,8 @@ var Settings = function Settings(_ref) {
20
21
  raw: true,
21
22
  value: value.value,
22
23
  onChange: onValueChange,
23
- min: 0
24
+ min: 0,
25
+ max: maxValue != null ? maxValue : Number.MAX_SAFE_INTEGER
24
26
  }), /*#__PURE__*/React.createElement(Select, {
25
27
  size: 'default',
26
28
  value: value.period,
@@ -1,11 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import InputNumber from '@synerise/ds-input-number';
3
- import { CompletedWithinProps, CompletedWithinTexts, CustomPeriod, Period } from '../CompletedWithin.types';
3
+ import { CompletedWithinProps, CompletedWithinTexts, CustomPeriod, Period, PeriodValue } from '../CompletedWithin.types';
4
4
  declare type InputProps = React.ComponentProps<typeof InputNumber>;
5
5
  export declare type SettingsProps = Omit<CompletedWithinProps, 'onClear' | 'onSetValue' | 'periods' | 'text'> & {
6
6
  onValueChange: InputProps['onChange'];
7
7
  onPeriodChange: (period: Period) => void;
8
8
  periods: CustomPeriod[];
9
9
  text: CompletedWithinTexts;
10
+ maxValue: PeriodValue['value'];
10
11
  };
11
12
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-completed-within",
3
- "version": "0.3.15",
3
+ "version": "0.5.1",
4
4
  "description": "CompletedWithin UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -33,7 +33,7 @@
33
33
  "types": "dist/index.d.ts",
34
34
  "dependencies": {
35
35
  "@synerise/ds-button": "^0.17.2",
36
- "@synerise/ds-dropdown": "^0.17.15",
36
+ "@synerise/ds-dropdown": "^0.17.17",
37
37
  "@synerise/ds-icon": "^0.49.0",
38
38
  "@synerise/ds-input-number": "^0.3.45",
39
39
  "@synerise/ds-select": "^0.14.11",
@@ -43,5 +43,5 @@
43
43
  "@synerise/ds-core": "*",
44
44
  "react": ">=16.9.0 < 17.0.0"
45
45
  },
46
- "gitHead": "93d7c60a7fe73188d715fd52b9701f81fcb4e60a"
46
+ "gitHead": "25e5737ebe9d4319de963b369bc281651872887c"
47
47
  }