@synerise/ds-factors 0.27.1 → 0.27.3

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.
@@ -1,18 +1,15 @@
1
1
  import React from 'react';
2
2
  import ModalProxy from '@synerise/ds-modal';
3
3
  import Textarea from '@synerise/ds-input/dist/Textarea/Textarea';
4
-
5
4
  var TextModal = function TextModal(_ref) {
6
5
  var value = _ref.value,
7
- onApply = _ref.onApply,
8
- onCancel = _ref.onCancel,
9
- visible = _ref.visible,
10
- texts = _ref.texts;
11
-
6
+ onApply = _ref.onApply,
7
+ onCancel = _ref.onCancel,
8
+ visible = _ref.visible,
9
+ texts = _ref.texts;
12
10
  var _React$useState = React.useState('' || value),
13
- expandValue = _React$useState[0],
14
- setExpandValue = _React$useState[1];
15
-
11
+ expandValue = _React$useState[0],
12
+ setExpandValue = _React$useState[1];
16
13
  React.useEffect(function () {
17
14
  setExpandValue(value);
18
15
  }, [value]);
@@ -40,5 +37,4 @@ var TextModal = function TextModal(_ref) {
40
37
  }
41
38
  }));
42
39
  };
43
-
44
40
  export default TextModal;
package/dist/Factors.js CHANGED
@@ -1,15 +1,4 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
8
-
9
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
10
-
11
1
  import React, { useMemo } from 'react';
12
- import { useIntl } from 'react-intl';
13
2
  import { BookM, Calendar2M, DynamicKeyM, FormulaM, HashM, ListM, ShowM, TextM } from '@synerise/ds-icon';
14
3
  import * as S from './style/Factors.style';
15
4
  import FactorTypeSelector from './FactorTypeSelector/FactorTypeSelector';
@@ -21,6 +10,7 @@ import TextInput from './FactorValue/Text/Text';
21
10
  import ParameterInput from './FactorValue/Parameter/Parameter';
22
11
  import NumberInput from './FactorValue/Number/NumberInput';
23
12
  import DateRangeInput from './FactorValue/DateRange/DateRange';
13
+ import { useTexts } from './hooks/useTexts';
24
14
  export var factorTypes = {
25
15
  text: {
26
16
  icon: /*#__PURE__*/React.createElement(TextM, null),
@@ -67,386 +57,42 @@ export var factorTypes = {
67
57
  name: 'Date range',
68
58
  input: DateRangeInput
69
59
  }
70
- }; // eslint-disable-next-line @typescript-eslint/no-empty-function
71
-
60
+ };
61
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
72
62
  var NOOP = function NOOP() {};
73
-
74
63
  var Factors = function Factors(_ref) {
75
64
  var selectedFactorType = _ref.selectedFactorType,
76
- _ref$setSelectedFacto = _ref.setSelectedFactorType,
77
- setSelectedFactorType = _ref$setSelectedFacto === void 0 ? NOOP : _ref$setSelectedFacto,
78
- onChangeValue = _ref.onChangeValue,
79
- onParamsClick = _ref.onParamsClick,
80
- value = _ref.value,
81
- _ref$defaultFactorTyp = _ref.defaultFactorType,
82
- defaultFactorType = _ref$defaultFactorTyp === void 0 ? 'text' : _ref$defaultFactorTyp,
83
- _ref$textType = _ref.textType,
84
- textType = _ref$textType === void 0 ? 'Default' : _ref$textType,
85
- unavailableFactorTypes = _ref.unavailableFactorTypes,
86
- availableFactorTypes = _ref.availableFactorTypes,
87
- parameters = _ref.parameters,
88
- autocompleteText = _ref.autocompleteText,
89
- _ref$allowClear = _ref.allowClear,
90
- allowClear = _ref$allowClear === void 0 ? true : _ref$allowClear,
91
- _ref$withoutTypeSelec = _ref.withoutTypeSelector,
92
- withoutTypeSelector = _ref$withoutTypeSelec === void 0 ? false : _ref$withoutTypeSelec,
93
- texts = _ref.texts,
94
- formulaEditor = _ref.formulaEditor,
95
- opened = _ref.opened,
96
- loading = _ref.loading,
97
- factorKey = _ref.factorKey,
98
- preventAutoloadData = _ref.preventAutoloadData,
99
- onActivate = _ref.onActivate,
100
- onDeactivate = _ref.onDeactivate,
101
- getPopupContainerOverride = _ref.getPopupContainerOverride,
102
- error = _ref.error,
103
- inputProps = _ref.inputProps,
104
- readOnly = _ref.readOnly,
105
- getMenuEntryProps = _ref.getMenuEntryProps;
106
-
107
- var _useIntl = useIntl(),
108
- formatMessage = _useIntl.formatMessage;
109
-
110
- var text = useMemo(function () {
111
- return _objectSpread({
112
- dateRangePicker: {
113
- after: formatMessage({
114
- id: "DS.DATE-RANGE-PICKER.AFTER",
115
- defaultMessage: 'after'
116
- }),
117
- allTime: formatMessage({
118
- id: "DS.DATE-RANGE-PICKER.ALL-TIME",
119
- defaultMessage: 'Lifetime'
120
- }),
121
- apply: formatMessage({
122
- id: "DS.DATE-RANGE-PICKER.APPLY",
123
- defaultMessage: 'Apply'
124
- }),
125
- before: formatMessage({
126
- id: "DS.DATE-RANGE-PICKER.BEFORE",
127
- defaultMessage: 'before'
128
- }),
129
- clear: formatMessage({
130
- id: "DS.DATE-RANGE-PICKER.CLEAR",
131
- defaultMessage: 'Clear'
132
- }),
133
- clearRange: formatMessage({
134
- id: "DS.DATE-RANGE-PICKER.CLEAR-RANGE",
135
- defaultMessage: ' Clear range'
136
- }),
137
- copyRange: formatMessage({
138
- id: "DS.DATE-RANGE-PICKER.COPY-RANGE",
139
- defaultMessage: 'Copy range'
140
- }),
141
- custom: formatMessage({
142
- id: "DS.DATE-RANGE-PICKER.CUSTOM",
143
- defaultMessage: 'Custom'
144
- }),
145
- days: formatMessage({
146
- id: "DS.DATE-RANGE-PICKER.DAYS",
147
- defaultMessage: 'Days'
148
- }),
149
- emptyDateError: formatMessage({
150
- id: "DS.DATE-RANGE-PICKER.EMPTY-DATE-ERROR",
151
- defaultMessage: 'Date cannot be empty'
152
- }),
153
- endDate: formatMessage({
154
- id: "DS.DATE-RANGE-PICKER.END-DATE",
155
- defaultMessage: 'End date'
156
- }),
157
- endDatePlaceholder: formatMessage({
158
- id: "DS.DATE-RANGE-PICKER.END-DATE-PLACEHOLDER",
159
- defaultMessage: 'End date'
160
- }),
161
- filter: formatMessage({
162
- id: "DS.DATE-RANGE-PICKER.FILTER",
163
- defaultMessage: 'Date filter'
164
- }),
165
- hours: formatMessage({
166
- id: "DS.DATE-RANGE-PICKER.HOURS",
167
- defaultMessage: 'Hours'
168
- }),
169
- last3Months: formatMessage({
170
- id: "DS.DATE-RANGE-PICKER.LAST-3-MONTHS",
171
- defaultMessage: 'Last 3 months'
172
- }),
173
- last6Months: formatMessage({
174
- id: "DS.DATE-RANGE-PICKER.LAST-6-MONTHS",
175
- defaultMessage: 'Last 6 months'
176
- }),
177
- last7Days: formatMessage({
178
- id: "DS.DATE-RANGE-PICKER.LAST-7-DAYS",
179
- defaultMessage: 'Last 7 days'
180
- }),
181
- last: formatMessage({
182
- id: "DS.DATE-RANGE-PICKER.LAST",
183
- defaultMessage: 'Last'
184
- }),
185
- lastMonth: formatMessage({
186
- id: "DS.DATE-RANGE-PICKER.LAST-MONTH",
187
- defaultMessage: 'Last month'
188
- }),
189
- lastWeek: formatMessage({
190
- id: "DS.DATE-RANGE-PICKER.LAST-WEEK",
191
- defaultMessage: 'Last week'
192
- }),
193
- lastYear: formatMessage({
194
- id: "DS.DATE-RANGE-PICKER.LAST-YEAR",
195
- defaultMessage: 'Last year'
196
- }),
197
- minutes: formatMessage({
198
- id: "DS.DATE-RANGE-PICKER.MINUTES",
199
- defaultMessage: 'Minutes'
200
- }),
201
- months: formatMessage({
202
- id: "DS.DATE-RANGE-PICKER.MONTHS",
203
- defaultMessage: 'Months'
204
- }),
205
- more: formatMessage({
206
- id: "DS.DATE-RANGE-PICKER.MORE",
207
- defaultMessage: 'More'
208
- }),
209
- next3Months: formatMessage({
210
- id: "DS.DATE-RANGE-PICKER.NEXT-3-MONTHS",
211
- defaultMessage: 'Next 3 months'
212
- }),
213
- next6Months: formatMessage({
214
- id: "DS.DATE-RANGE-PICKER.NEXT-6-MONTHS",
215
- defaultMessage: 'Next 6 months'
216
- }),
217
- next7Days: formatMessage({
218
- id: "DS.DATE-RANGE-PICKER.NEXT-7-DAYS",
219
- defaultMessage: 'Next 7 days'
220
- }),
221
- next: formatMessage({
222
- id: "DS.DATE-RANGE-PICKER.NEXT",
223
- defaultMessage: 'Next'
224
- }),
225
- nextMonth: formatMessage({
226
- id: "DS.DATE-RANGE-PICKER.NEXT-MONTH",
227
- defaultMessage: 'Next month'
228
- }),
229
- nextWeek: formatMessage({
230
- id: "DS.DATE-RANGE-PICKER.NEXT-WEEK",
231
- defaultMessage: 'Next week'
232
- }),
233
- nextYear: formatMessage({
234
- id: "DS.DATE-RANGE-PICKER.NEXT-YEAR",
235
- defaultMessage: 'Next year'
236
- }),
237
- now: formatMessage({
238
- id: "DS.DATE-RANGE-PICKER.NOW",
239
- defaultMessage: 'Now'
240
- }),
241
- pasteRange: formatMessage({
242
- id: "DS.DATE-RANGE-PICKER.PASTE-RANGE",
243
- defaultMessage: 'Paste range'
244
- }),
245
- relativeDateRange: formatMessage({
246
- id: "DS.DATE-RANGE-PICKER.RELATIVE-DATE-RANGE",
247
- defaultMessage: 'Relative date range'
248
- }),
249
- remove: formatMessage({
250
- id: "DS.DATE-RANGE-PICKER.REMOVE",
251
- defaultMessage: 'Remove'
252
- }),
253
- savedFiltersTrigger: formatMessage({
254
- id: "DS.DATE-RANGE-PICKER.SAVED-FILTERS",
255
- defaultMessage: 'Saved filters'
256
- }),
257
- seconds: formatMessage({
258
- id: "DS.DATE-RANGE-PICKER.SECONDS",
259
- defaultMessage: 'Seconds'
260
- }),
261
- selectDate: formatMessage({
262
- id: "DS.DATE-RANGE-PICKER.SELECT-DATE",
263
- defaultMessage: 'Select date'
264
- }),
265
- selectTime: formatMessage({
266
- id: "DS.DATE-RANGE-PICKER.SELECT-TIME",
267
- defaultMessage: 'Select time'
268
- }),
269
- since: formatMessage({
270
- id: "DS.DATE-RANGE-PICKER.SINCE",
271
- defaultMessage: 'Since'
272
- }),
273
- startDate: formatMessage({
274
- id: "DS.DATE-RANGE-PICKER.START-DATE",
275
- defaultMessage: 'Start date'
276
- }),
277
- startDatePlaceholder: formatMessage({
278
- id: "DS.DATE-RANGE-PICKER.START-DATE-PLACEHOLDER",
279
- defaultMessage: 'Start date'
280
- }),
281
- thisMonth: formatMessage({
282
- id: "DS.DATE-RANGE-PICKER.THIS-MONTH",
283
- defaultMessage: 'This month'
284
- }),
285
- thisWeek: formatMessage({
286
- id: "DS.DATE-RANGE-PICKER.THIS-WEEK",
287
- defaultMessage: 'This week'
288
- }),
289
- timestampLast: formatMessage({
290
- id: "DS.DATE-RANGE-PICKER.TIMESTAMP-LAST",
291
- defaultMessage: 'Last'
292
- }),
293
- timestampNext: formatMessage({
294
- id: "DS.DATE-RANGE-PICKER.TIMESTAMP-NEXT",
295
- defaultMessage: 'Next'
296
- }),
297
- timestampTill: formatMessage({
298
- id: "DS.DATE-RANGE-PICKER.TIMESTAMP-TILL",
299
- defaultMessage: 'till'
300
- }),
301
- today: formatMessage({
302
- id: "DS.DATE-RANGE-PICKER.TODAY",
303
- defaultMessage: 'Today'
304
- }),
305
- tomorrow: formatMessage({
306
- id: "DS.DATE-RANGE-PICKER.TOMORROW",
307
- defaultMessage: 'Tomorrow'
308
- }),
309
- weeks: formatMessage({
310
- id: "DS.DATE-RANGE-PICKER.WEEKS",
311
- defaultMessage: 'Weeks'
312
- }),
313
- years: formatMessage({
314
- id: "DS.DATE-RANGE-PICKER.YEARS",
315
- defaultMessage: 'Years'
316
- }),
317
- yesterday: formatMessage({
318
- id: "DS.DATE-RANGE-PICKER.YESTERDAY",
319
- defaultMessage: 'Yesterday'
320
- }),
321
- range: formatMessage({
322
- id: "DS.DATE-RANGE-PICKER.RANGE",
323
- defaultMessage: 'Range'
324
- }),
325
- hour: formatMessage({
326
- id: "DS.DATE-RANGE-PICKER.HOUR",
327
- defaultMessage: 'Hour'
328
- })
329
- },
330
- datePicker: {
331
- apply: formatMessage({
332
- id: 'DS.FACTORS.DATE_PICKER.APPLY',
333
- defaultMessage: 'Apply'
334
- }),
335
- clearTooltip: formatMessage({
336
- id: 'DS.FACTORS.DATE_PICKER.CLEAR_TOOLTIP',
337
- defaultMessage: 'Clear'
338
- }),
339
- inputPlaceholder: formatMessage({
340
- id: 'DS.FACTORS.DATE_PICKER.INPUT_PLACEHOLDER',
341
- defaultMessage: 'Select date'
342
- }),
343
- now: formatMessage({
344
- id: 'DS.FACTORS.DATE_PICKER.NOW',
345
- defaultMessage: 'Now'
346
- })
347
- },
348
- dynamicKey: {
349
- keyPlaceholder: formatMessage({
350
- id: 'DS.FACTORS.DYNAMIC_KEY.KEY_PLACEHOLDER',
351
- defaultMessage: 'Key'
352
- }),
353
- valuePlaceholder: formatMessage({
354
- id: 'DS.FACTORS.DYNAMIC_KEY.VALUE_PLACEHOLDER',
355
- defaultMessage: 'Value'
356
- })
357
- },
358
- formula: {
359
- buttonPlaceholder: formatMessage({
360
- id: 'DS.FACTORS.FORMULA.BUTTON_PLACEHOLDER',
361
- defaultMessage: 'Formula'
362
- }),
363
- defaultName: formatMessage({
364
- id: 'DS.FACTORS.FORMULA.DEFAULT_NAME',
365
- defaultMessage: 'Formula'
366
- })
367
- },
368
- parameter: {
369
- searchPlaceholder: formatMessage({
370
- id: 'DS.FACTORS.PARAMETER.SEARCH_PLACEHOLDER',
371
- defaultMessage: 'Search'
372
- }),
373
- noResults: formatMessage({
374
- id: 'DS.FACTORS.PARAMETER.NO_RESULTS',
375
- defaultMessage: 'No results'
376
- }),
377
- loadingParameter: formatMessage({
378
- id: 'DS.FACTORS.PARAMETER.LOADING_PARAMETERS',
379
- defaultMessage: 'Loading parameters'
380
- }),
381
- showMore: formatMessage({
382
- id: 'DS.FACTORS.PARAMETER.SHOW_MORE',
383
- defaultMessage: 'Show more'
384
- }),
385
- recentItemsGroupName: formatMessage({
386
- id: 'DS.FACTORS.PARAMETER.RECENT',
387
- defaultMessage: 'Recent'
388
- }),
389
- allItemsGroupName: formatMessage({
390
- id: 'DS.FACTORS.PARAMETER.ALL',
391
- defaultMessage: 'All'
392
- })
393
- },
394
- valuePlaceholder: formatMessage({
395
- id: 'DS.FACTORS.VALUE_PLACEHOLDER',
396
- defaultMessage: 'Value'
397
- }),
398
- modalApply: formatMessage({
399
- id: 'DS.FACTORS.MODAL_APPLY',
400
- defaultMessage: 'Apply'
401
- }),
402
- modalCancel: formatMessage({
403
- id: 'DS.FACTORS.MODAL_CANCEL',
404
- defaultMessage: 'Cancel'
405
- }),
406
- modalTitle: formatMessage({
407
- id: 'DS.FACTORS.MODAL_TITLE',
408
- defaultMessage: 'Value'
409
- }),
410
- factorTypes: {
411
- text: formatMessage({
412
- id: 'DS.FACTORS.FACTOR_TYPES.TEXT',
413
- defaultMessage: 'Text'
414
- }),
415
- number: formatMessage({
416
- id: 'DS.FACTORS.FACTOR_TYPES.NUMBER',
417
- defaultMessage: 'Number'
418
- }),
419
- parameter: formatMessage({
420
- id: 'DS.FACTORS.FACTOR_TYPES.PARAMETER',
421
- defaultMessage: 'Parameter'
422
- }),
423
- contextParameter: formatMessage({
424
- id: 'DS.FACTORS.FACTOR_TYPES.CONTEXT_PARAMETER',
425
- defaultMessage: 'Context parameter'
426
- }),
427
- dynamicKey: formatMessage({
428
- id: 'DS.FACTORS.FACTOR_TYPES.DYNAMIC_KEY',
429
- defaultMessage: 'Dynamic key'
430
- }),
431
- formula: formatMessage({
432
- id: 'DS.FACTORS.FACTOR_TYPES.FORMULA',
433
- defaultMessage: 'Formula'
434
- }),
435
- array: formatMessage({
436
- id: 'DS.FACTORS.FACTOR_TYPES.ARRAY',
437
- defaultMessage: 'Array'
438
- }),
439
- date: formatMessage({
440
- id: 'DS.FACTORS.FACTOR_TYPES.DATE',
441
- defaultMessage: 'Date'
442
- }),
443
- dateRange: formatMessage({
444
- id: 'DS.FACTORS.FACTOR_TYPES.DATE_RANGE',
445
- defaultMessage: 'Date range'
446
- })
447
- }
448
- }, texts);
449
- }, [texts, formatMessage]);
65
+ _ref$setSelectedFacto = _ref.setSelectedFactorType,
66
+ setSelectedFactorType = _ref$setSelectedFacto === void 0 ? NOOP : _ref$setSelectedFacto,
67
+ onChangeValue = _ref.onChangeValue,
68
+ onParamsClick = _ref.onParamsClick,
69
+ value = _ref.value,
70
+ _ref$defaultFactorTyp = _ref.defaultFactorType,
71
+ defaultFactorType = _ref$defaultFactorTyp === void 0 ? 'text' : _ref$defaultFactorTyp,
72
+ _ref$textType = _ref.textType,
73
+ textType = _ref$textType === void 0 ? 'Default' : _ref$textType,
74
+ unavailableFactorTypes = _ref.unavailableFactorTypes,
75
+ availableFactorTypes = _ref.availableFactorTypes,
76
+ parameters = _ref.parameters,
77
+ autocompleteText = _ref.autocompleteText,
78
+ _ref$allowClear = _ref.allowClear,
79
+ allowClear = _ref$allowClear === void 0 ? true : _ref$allowClear,
80
+ _ref$withoutTypeSelec = _ref.withoutTypeSelector,
81
+ withoutTypeSelector = _ref$withoutTypeSelec === void 0 ? false : _ref$withoutTypeSelec,
82
+ texts = _ref.texts,
83
+ formulaEditor = _ref.formulaEditor,
84
+ opened = _ref.opened,
85
+ loading = _ref.loading,
86
+ factorKey = _ref.factorKey,
87
+ preventAutoloadData = _ref.preventAutoloadData,
88
+ onActivate = _ref.onActivate,
89
+ onDeactivate = _ref.onDeactivate,
90
+ getPopupContainerOverride = _ref.getPopupContainerOverride,
91
+ error = _ref.error,
92
+ inputProps = _ref.inputProps,
93
+ readOnly = _ref.readOnly,
94
+ getMenuEntryProps = _ref.getMenuEntryProps;
95
+ var allTexts = useTexts(texts);
450
96
  var factorType = useMemo(function () {
451
97
  return selectedFactorType || defaultFactorType;
452
98
  }, [selectedFactorType, defaultFactorType]);
@@ -459,7 +105,7 @@ var Factors = function Factors(_ref) {
459
105
  withoutTypeSelector: withoutTypeSelector,
460
106
  className: "ds-factors ds-factors-" + factorType
461
107
  }, !withoutTypeSelector && setSelectedFactorType && /*#__PURE__*/React.createElement(FactorTypeSelector, {
462
- texts: text.factorTypes,
108
+ texts: allTexts.factorTypes,
463
109
  selectedFactorType: factorType,
464
110
  setSelectedFactorType: setSelectedFactorType,
465
111
  selectedFactor: selectedFactor,
@@ -477,7 +123,7 @@ var Factors = function Factors(_ref) {
477
123
  autocompleteText: autocompleteText,
478
124
  withoutTypeSelector: withoutTypeSelector,
479
125
  formulaEditor: formulaEditor,
480
- texts: text,
126
+ texts: allTexts,
481
127
  opened: opened,
482
128
  inputProps: inputProps,
483
129
  loading: loading,
@@ -492,5 +138,4 @@ var Factors = function Factors(_ref) {
492
138
  getMenuEntryProps: getMenuEntryProps
493
139
  }));
494
140
  };
495
-
496
141
  export default Factors;
@@ -5,8 +5,9 @@ import type { MenuItemProps } from '@synerise/ds-menu';
5
5
  import type { AutoResizeProp } from '@synerise/ds-input';
6
6
  import type { InformationCardProps } from '@synerise/ds-information-card';
7
7
  import type { ListItemProps } from '@synerise/ds-list-item';
8
+ import type { LiteralStringUnion, DeepPartial } from '@synerise/ds-utils';
8
9
  export declare const ALL_FACTOR_TYPES: readonly ["text", "number", "parameter", "contextParameter", "dynamicKey", "formula", "array", "date", "dateRange"];
9
- export type FactorType = typeof ALL_FACTOR_TYPES[number] | string;
10
+ export type FactorType = LiteralStringUnion<typeof ALL_FACTOR_TYPES[number]>;
10
11
  export type DefinedFactorTypes = typeof ALL_FACTOR_TYPES[number];
11
12
  export type DynamicKeyValueType = {
12
13
  key: ReactText;
@@ -51,7 +52,7 @@ export type SelectedFactorType = {
51
52
  input: ElementType;
52
53
  };
53
54
  export type FactorsTexts = {
54
- dateRangePicker: Partial<DateRangeTexts>;
55
+ dateRangePicker: DateRangeTexts;
55
56
  datePicker: {
56
57
  apply: string;
57
58
  clearTooltip: string;
@@ -78,7 +79,7 @@ export type FactorsTexts = {
78
79
  modalApply: string;
79
80
  modalCancel: string;
80
81
  modalTitle: string;
81
- factorTypes?: {
82
+ factorTypes: {
82
83
  [k in DefinedFactorTypes]: string;
83
84
  };
84
85
  };
@@ -97,7 +98,7 @@ export type FactorsProps = {
97
98
  onDeactivate?: () => void;
98
99
  onChangeValue: (value: FactorValueType) => void;
99
100
  value: FactorValueType;
100
- textType?: 'autocomplete' | 'expansible' | 'default' | string;
101
+ textType?: LiteralStringUnion<'autocomplete' | 'expansible' | 'default'>;
101
102
  autoResize?: AutoResizeProp;
102
103
  autocompleteText?: {
103
104
  options: string[];
@@ -119,7 +120,7 @@ export type FactorsProps = {
119
120
  };
120
121
  onParamsClick?: () => void;
121
122
  formulaEditor?: ReactNode;
122
- texts?: Partial<FactorsTexts>;
123
+ texts?: DeepPartial<FactorsTexts>;
123
124
  opened?: boolean;
124
125
  allowClear?: boolean;
125
126
  loading?: boolean;
@@ -0,0 +1,3 @@
1
+ import { DeepPartial } from '@synerise/ds-utils';
2
+ import type { FactorsTexts } from '../Factors.types';
3
+ export declare const useTexts: (defaultTexts?: DeepPartial<FactorsTexts>) => FactorsTexts;
@@ -0,0 +1,131 @@
1
+ import { useMemo } from 'react';
2
+ import { useIntl } from 'react-intl';
3
+ import { merge } from 'lodash';
4
+ import { utils as dateRangePickerUtils } from '@synerise/ds-date-range-picker';
5
+ export var useTexts = function useTexts(defaultTexts) {
6
+ var intl = useIntl();
7
+ var texts = useMemo(function () {
8
+ return merge({
9
+ dateRangePicker: dateRangePickerUtils.getDefaultTexts(intl),
10
+ datePicker: {
11
+ apply: intl.formatMessage({
12
+ id: 'DS.FACTORS.DATE_PICKER.APPLY',
13
+ defaultMessage: 'Apply'
14
+ }),
15
+ clearTooltip: intl.formatMessage({
16
+ id: 'DS.FACTORS.DATE_PICKER.CLEAR_TOOLTIP',
17
+ defaultMessage: 'Clear'
18
+ }),
19
+ inputPlaceholder: intl.formatMessage({
20
+ id: 'DS.FACTORS.DATE_PICKER.INPUT_PLACEHOLDER',
21
+ defaultMessage: 'Select date'
22
+ }),
23
+ now: intl.formatMessage({
24
+ id: 'DS.FACTORS.DATE_PICKER.NOW',
25
+ defaultMessage: 'Now'
26
+ })
27
+ },
28
+ dynamicKey: {
29
+ keyPlaceholder: intl.formatMessage({
30
+ id: 'DS.FACTORS.DYNAMIC_KEY.KEY_PLACEHOLDER',
31
+ defaultMessage: 'Key'
32
+ }),
33
+ valuePlaceholder: intl.formatMessage({
34
+ id: 'DS.FACTORS.DYNAMIC_KEY.VALUE_PLACEHOLDER',
35
+ defaultMessage: 'Value'
36
+ })
37
+ },
38
+ formula: {
39
+ buttonPlaceholder: intl.formatMessage({
40
+ id: 'DS.FACTORS.FORMULA.BUTTON_PLACEHOLDER',
41
+ defaultMessage: 'Formula'
42
+ }),
43
+ defaultName: intl.formatMessage({
44
+ id: 'DS.FACTORS.FORMULA.DEFAULT_NAME',
45
+ defaultMessage: 'Formula'
46
+ })
47
+ },
48
+ parameter: {
49
+ searchPlaceholder: intl.formatMessage({
50
+ id: 'DS.FACTORS.PARAMETER.SEARCH_PLACEHOLDER',
51
+ defaultMessage: 'Search'
52
+ }),
53
+ noResults: intl.formatMessage({
54
+ id: 'DS.FACTORS.PARAMETER.NO_RESULTS',
55
+ defaultMessage: 'No results'
56
+ }),
57
+ loadingParameter: intl.formatMessage({
58
+ id: 'DS.FACTORS.PARAMETER.LOADING_PARAMETERS',
59
+ defaultMessage: 'Loading parameters'
60
+ }),
61
+ showMore: intl.formatMessage({
62
+ id: 'DS.FACTORS.PARAMETER.SHOW_MORE',
63
+ defaultMessage: 'Show more'
64
+ }),
65
+ recentItemsGroupName: intl.formatMessage({
66
+ id: 'DS.FACTORS.PARAMETER.RECENT',
67
+ defaultMessage: 'Recent'
68
+ }),
69
+ allItemsGroupName: intl.formatMessage({
70
+ id: 'DS.FACTORS.PARAMETER.ALL',
71
+ defaultMessage: 'All'
72
+ })
73
+ },
74
+ valuePlaceholder: intl.formatMessage({
75
+ id: 'DS.FACTORS.VALUE_PLACEHOLDER',
76
+ defaultMessage: 'Value'
77
+ }),
78
+ modalApply: intl.formatMessage({
79
+ id: 'DS.FACTORS.MODAL_APPLY',
80
+ defaultMessage: 'Apply'
81
+ }),
82
+ modalCancel: intl.formatMessage({
83
+ id: 'DS.FACTORS.MODAL_CANCEL',
84
+ defaultMessage: 'Cancel'
85
+ }),
86
+ modalTitle: intl.formatMessage({
87
+ id: 'DS.FACTORS.MODAL_TITLE',
88
+ defaultMessage: 'Value'
89
+ }),
90
+ factorTypes: {
91
+ text: intl.formatMessage({
92
+ id: 'DS.FACTORS.FACTOR_TYPES.TEXT',
93
+ defaultMessage: 'Text'
94
+ }),
95
+ number: intl.formatMessage({
96
+ id: 'DS.FACTORS.FACTOR_TYPES.NUMBER',
97
+ defaultMessage: 'Number'
98
+ }),
99
+ parameter: intl.formatMessage({
100
+ id: 'DS.FACTORS.FACTOR_TYPES.PARAMETER',
101
+ defaultMessage: 'Parameter'
102
+ }),
103
+ contextParameter: intl.formatMessage({
104
+ id: 'DS.FACTORS.FACTOR_TYPES.CONTEXT_PARAMETER',
105
+ defaultMessage: 'Context parameter'
106
+ }),
107
+ dynamicKey: intl.formatMessage({
108
+ id: 'DS.FACTORS.FACTOR_TYPES.DYNAMIC_KEY',
109
+ defaultMessage: 'Dynamic key'
110
+ }),
111
+ formula: intl.formatMessage({
112
+ id: 'DS.FACTORS.FACTOR_TYPES.FORMULA',
113
+ defaultMessage: 'Formula'
114
+ }),
115
+ array: intl.formatMessage({
116
+ id: 'DS.FACTORS.FACTOR_TYPES.ARRAY',
117
+ defaultMessage: 'Array'
118
+ }),
119
+ date: intl.formatMessage({
120
+ id: 'DS.FACTORS.FACTOR_TYPES.DATE',
121
+ defaultMessage: 'Date'
122
+ }),
123
+ dateRange: intl.formatMessage({
124
+ id: 'DS.FACTORS.FACTOR_TYPES.DATE_RANGE',
125
+ defaultMessage: 'Date range'
126
+ })
127
+ }
128
+ }, defaultTexts);
129
+ }, [defaultTexts, intl]);
130
+ return texts;
131
+ };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { default, factorTypes } from './Factors';
2
2
  export { ALL_FACTOR_TYPES } from './Factors.types';
3
- export type { FactorsProps, ParameterValueType, InputProps, FactorValueType } from './Factors.types';
3
+ export type { FactorsProps, ParameterValueType, ParameterItem, ParameterGroup, InputProps, FactorType, FactorValueType, DynamicKeyValueType, } from './Factors.types';