@northlight/ui 2.31.0 → 2.31.2

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.
@@ -30,7 +30,7 @@ import * as react_select_dist_declarations_src_types from 'react-select/dist/dec
30
30
  import * as _chakra_ui_switch_dist_switch from '@chakra-ui/switch/dist/switch';
31
31
  import * as _chakra_ui_textarea_dist_textarea from '@chakra-ui/textarea/dist/textarea';
32
32
  import { Props as Props$1 } from 'react-input-mask';
33
- import { NumericFormatProps } from 'react-number-format';
33
+ import { NumericFormatProps, NumberFormatValues, SourceInfo } from 'react-number-format';
34
34
  import { Schema } from 'joi';
35
35
  import { UseClickableProps } from '@chakra-ui/clickable';
36
36
  import { Variant } from 'chakra-react-select/dist/types/types';
@@ -3234,7 +3234,7 @@ interface TextFieldProps extends Omit<InputProps, 'onChange'>, InputFieldProps {
3234
3234
  formatter?: TextInputFormatter;
3235
3235
  validate?: RegisterOptions;
3236
3236
  direction?: StackDirection;
3237
- onChange?: (e: React.ChangeEvent<HTMLInputElement> | string) => void;
3237
+ onChange?: (e: React__default.ChangeEvent<HTMLInputElement> | string) => void;
3238
3238
  }
3239
3239
  type MaskedTextInputProps = InputProps & Props$1 & {
3240
3240
  maskPlaceholder?: string;
@@ -3250,13 +3250,13 @@ interface FormattedNumberInputProps extends Omit<NumericFormatProps, 'onChange'
3250
3250
  /** Changes thousand and decimal separators */
3251
3251
  preset?: FormattedNumberInputPreset;
3252
3252
  /** Gives you back an object, see https://s-yadav.github.io/react-number-format/docs/quirks */
3253
- onChange?: NumericFormatProps['onValueChange'];
3253
+ onChange?: (values: NumberFormatValues, sourceInfo?: SourceInfo) => void;
3254
3254
  /** Will format number UI as percentage, but return as decimal value */
3255
3255
  isPercentage?: boolean;
3256
3256
  /** Will round up and restrict number of decimals */
3257
3257
  numberOfDecimals?: number;
3258
- inputLeftElement?: React.ReactNode;
3259
- inputRightElement?: React.ReactNode;
3258
+ inputLeftElement?: React__default.ReactNode;
3259
+ inputRightElement?: React__default.ReactNode;
3260
3260
  }
3261
3261
  interface FormattedNumberInputFieldProps extends FormattedNumberInputProps {
3262
3262
  name: string;
@@ -3307,7 +3307,7 @@ interface FormattedNumberInputFieldProps extends FormattedNumberInputProps {
3307
3307
  ?)
3308
3308
 
3309
3309
  */
3310
- declare const FormattedNumberInput: ({ preset, isPercentage, onChange, value, numberOfDecimals, max, min, inputLeftElement, inputRightElement, ...rest }: FormattedNumberInputProps) => JSX.Element;
3310
+ declare const FormattedNumberInput: ({ preset, isPercentage, onChange, value: valueProp, numberOfDecimals, max, min, inputLeftElement, inputRightElement, onBlur, ...rest }: FormattedNumberInputProps) => JSX.Element;
3311
3311
 
3312
3312
  /**
3313
3313
  * The formatted number input component wrapped in a <Field />
@@ -3411,19 +3411,18 @@ interface OurTooltipProps extends TooltipProps {
3411
3411
  * (?
3412
3412
  * <HStack>
3413
3413
  * <Tooltip
3414
+ * hasIcon={ true }
3414
3415
  * description="Here’s a regular tooltip with some with icon
3415
3416
  * inside of it that’s supposed to be substantially large.">
3416
3417
  * <Badge>ICON</Badge>
3417
3418
  * </Tooltip>
3418
3419
  * <Tooltip
3419
- * hasIcon={ false }
3420
3420
  * description="Here’s a regular tooltip with some text without icon
3421
3421
  * inside of it that’s supposed to be substantially large."
3422
3422
  * >
3423
3423
  * <Badge>NOICON</Badge>
3424
3424
  * </Tooltip>
3425
3425
  * <Tooltip
3426
- * hasIcon={ false }
3427
3426
  * description={
3428
3427
  * <Box>
3429
3428
  * <Text>
@@ -3454,12 +3453,14 @@ interface OurTooltipProps extends TooltipProps {
3454
3453
  * <HStack>
3455
3454
  * <VStack>
3456
3455
  * <Tooltip
3456
+ * hasIcon={ true }
3457
3457
  * variant="success"
3458
3458
  * description="This is a successful message"
3459
3459
  * >
3460
3460
  * <Badge colorScheme="green">Success</Badge>
3461
3461
  * </Tooltip>
3462
3462
  * <Tooltip
3463
+ * hasIcon={ true }
3463
3464
  * variant="success"
3464
3465
  * title="Please check fields"
3465
3466
  * description="This is a successful message with a title and an icon
@@ -3470,12 +3471,14 @@ interface OurTooltipProps extends TooltipProps {
3470
3471
  * </VStack>
3471
3472
  * <VStack>
3472
3473
  * <Tooltip
3474
+ * hasIcon={ true }
3473
3475
  * variant="info"
3474
3476
  * description="This is an informative text"
3475
3477
  * >
3476
3478
  * <Badge colorScheme="blue">Info</Badge>
3477
3479
  * </Tooltip>
3478
3480
  * <Tooltip
3481
+ * hasIcon={ true }
3479
3482
  * variant="info"
3480
3483
  * title="Please check fields"
3481
3484
  * description="This is an informative text with a title and an icon
@@ -3486,12 +3489,14 @@ interface OurTooltipProps extends TooltipProps {
3486
3489
  * </VStack>
3487
3490
  * <VStack>
3488
3491
  * <Tooltip
3492
+ * hasIcon={ true }
3489
3493
  * variant="warning"
3490
3494
  * description="This is a warning"
3491
3495
  * >
3492
3496
  * <Badge colorScheme="yellow">Warning</Badge>
3493
3497
  * </Tooltip>
3494
3498
  * <Tooltip
3499
+ * hasIcon={ true }
3495
3500
  * variant="warning"
3496
3501
  * title="Please check fields"
3497
3502
  * description="This is a warning with a title and an icon
@@ -3502,12 +3507,14 @@ interface OurTooltipProps extends TooltipProps {
3502
3507
  * </VStack>
3503
3508
  * <VStack>
3504
3509
  * <Tooltip
3510
+ * hasIcon={ true }
3505
3511
  * variant="danger"
3506
3512
  * description="This is an error message"
3507
3513
  * >
3508
3514
  * <Badge colorScheme="red">Error</Badge>
3509
3515
  * </Tooltip>
3510
3516
  * <Tooltip
3517
+ * hasIcon={ true }
3511
3518
  * variant="danger"
3512
3519
  * title="Please check fields"
3513
3520
  * description="This is an error message with a title and an icon
@@ -3518,11 +3525,13 @@ interface OurTooltipProps extends TooltipProps {
3518
3525
  * </VStack>
3519
3526
  * <VStack>
3520
3527
  * <Tooltip
3528
+ * hasIcon={ true }
3521
3529
  * variant="ai"
3522
3530
  * description="This is an AI message">
3523
3531
  * <Badge colorScheme="teal" variant="subtle">AI</Badge>
3524
3532
  * </Tooltip>
3525
3533
  * <Tooltip
3534
+ * hasIcon={ true }
3526
3535
  * variant="ai"
3527
3536
  * title="Please check fields"
3528
3537
  * description="This is an AI message with a title and an icon
@@ -3533,11 +3542,13 @@ interface OurTooltipProps extends TooltipProps {
3533
3542
  * </VStack>
3534
3543
  * <VStack>
3535
3544
  * <Tooltip
3545
+ * hasIcon={ true }
3536
3546
  * variant="ghost"
3537
3547
  * description="This is an clean message">
3538
3548
  * <Badge>Ghost</Badge>
3539
3549
  * </Tooltip>
3540
3550
  * <Tooltip
3551
+ * hasIcon={ true }
3541
3552
  * variant="ghost"
3542
3553
  * title="Please check fields"
3543
3554
  * description="This is an clean message with a title and an icon
@@ -4240,7 +4251,7 @@ interface CreatableSelectDropdownProps<T extends string = string> extends Compon
4240
4251
  declare const CreatableSelectDropdown: <T extends string = string>({ standardOptions, initialPlaceholder, addOptionPlaceholder, creationOption, onOptionChange, variant, defaultValue, value, menuPlacement, ...restProps }: CreatableSelectDropdownProps<T>) => JSX.Element;
4241
4252
 
4242
4253
  type ComboPickerValue = {
4243
- input: number;
4254
+ input?: number;
4244
4255
  option: ComboPickerOption;
4245
4256
  };
4246
4257
  type ComboPickerOption = {
@@ -4256,6 +4267,7 @@ interface ComboPickerProps extends Omit<FormattedNumberInputProps, 'value' | 'on
4256
4267
  formatPreset?: FormattedNumberInputPreset;
4257
4268
  isDisabled?: boolean;
4258
4269
  isReadOnly?: boolean;
4270
+ defaultToZeroIfEmpty?: boolean;
4259
4271
  }
4260
4272
  interface ComboPickerFieldProps extends ComboPickerProps {
4261
4273
  name: string;
@@ -4271,7 +4283,7 @@ interface ComboPickerFieldProps extends ComboPickerProps {
4271
4283
  * @see ComboPickerField
4272
4284
  * @see {@link https://northlight.dev/reference/combo-picker}
4273
4285
  */
4274
- declare const ComboPicker: ({ onChange, options, size, value, placeholder, precision, formatPreset, isDisabled, isReadOnly, ...rest }: ComboPickerProps) => JSX.Element;
4286
+ declare const ComboPicker: ({ onChange, options, size, value: valueProp, placeholder, precision, formatPreset, isDisabled, isReadOnly, defaultToZeroIfEmpty, max, min, ...rest }: ComboPickerProps) => JSX.Element;
4275
4287
 
4276
4288
  /**
4277
4289
  * The <ComboPicker /> component wrapped in a <Field />
@@ -4286,6 +4298,7 @@ declare const ComboPicker: ({ onChange, options, size, value, placeholder, preci
4286
4298
  * <ComboPickerField
4287
4299
  * label="Budget"
4288
4300
  * name="budget"
4301
+ * placeholder="Amount"
4289
4302
  * options={ [
4290
4303
  * { label: 'USD', value: 'usd' },
4291
4304
  * { label: 'EUR', value: 'eur' },
@@ -38,7 +38,7 @@ export * from '@dnd-kit/modifiers';
38
38
  import { VariableSizeList, VariableSizeGrid } from 'react-window';
39
39
  import AutoSizer from 'react-virtualized-auto-sizer';
40
40
  import AvatarEditor from 'react-avatar-editor';
41
- import { NumericFormat } from 'react-number-format';
41
+ import { NumericFormat, numericFormatter } from 'react-number-format';
42
42
  import InputMask from 'react-input-mask';
43
43
  import { uniqBy } from 'yafu';
44
44
 
@@ -4805,10 +4805,13 @@ const Tooltip$1 = {
4805
4805
  }),
4806
4806
  variants: {
4807
4807
  default: ({ theme: { colors: color } }) => ({
4808
- bgColor: "bg.tertiary.default",
4809
- color: color.text.inverted,
4810
- [$arrowBg.variable]: color.bg.tertiary.default,
4811
- [$arrowBorder.variable]: color.bg.tertiary.default
4808
+ color: color.text.default,
4809
+ bgColor: color.bg.base,
4810
+ borderWidth: "xs",
4811
+ borderColor: color.border.default,
4812
+ borderStyle: "solid",
4813
+ [$arrowBg.variable]: color.bg.base,
4814
+ [$arrowBorder.variable]: color.border.default
4812
4815
  }),
4813
4816
  success: ({ theme: { colors: color } }) => ({
4814
4817
  color: "text.over.success",
@@ -7810,7 +7813,7 @@ const Tooltip = (_a) => {
7810
7813
  hasArrow = true,
7811
7814
  title = "",
7812
7815
  description = "",
7813
- hasIcon = "true"
7816
+ hasIcon = false
7814
7817
  } = _b, rest = __objRest$18(_b, [
7815
7818
  "variant",
7816
7819
  "hasArrow",
@@ -7825,7 +7828,7 @@ const Tooltip = (_a) => {
7825
7828
  {
7826
7829
  variant: "14",
7827
7830
  sx: {
7828
- color: !variant || variant === "ai" || variant === "default" ? "text.inverted" : void 0
7831
+ color: !variant || variant === "ai" ? "text.inverted" : "text.default"
7829
7832
  }
7830
7833
  },
7831
7834
  description
@@ -13053,12 +13056,13 @@ const FormattedNumberInput = (_a) => {
13053
13056
  preset = "eu",
13054
13057
  isPercentage = false,
13055
13058
  onChange = identity,
13056
- value,
13059
+ value: valueProp,
13057
13060
  numberOfDecimals = 2,
13058
13061
  max = Infinity,
13059
13062
  min = -Infinity,
13060
13063
  inputLeftElement,
13061
- inputRightElement
13064
+ inputRightElement,
13065
+ onBlur
13062
13066
  } = _b, rest = __objRest$g(_b, [
13063
13067
  "preset",
13064
13068
  "isPercentage",
@@ -13068,27 +13072,37 @@ const FormattedNumberInput = (_a) => {
13068
13072
  "max",
13069
13073
  "min",
13070
13074
  "inputLeftElement",
13071
- "inputRightElement"
13075
+ "inputRightElement",
13076
+ "onBlur"
13072
13077
  ]);
13078
+ const [valueState, setValueState] = useState(valueProp);
13079
+ const isControlled = typeof valueProp !== "undefined";
13080
+ const value = isControlled ? valueProp : valueState;
13073
13081
  const props = presetMap[preset];
13074
- const [v, setV] = useState(value);
13082
+ const getNumberFormatValues = (number) => ({
13083
+ floatValue: number,
13084
+ formattedValue: numericFormatter(number.toString(), props),
13085
+ value: number.toString()
13086
+ });
13075
13087
  const validateRange = () => {
13076
- if (isNil(v))
13088
+ if (isNil(value))
13077
13089
  return;
13078
- const vNum = typeof v === "string" ? parseFloat(v) : v;
13090
+ const vNum = typeof value === "string" ? parseFloat(value) : value;
13079
13091
  const factor = isPercentage ? 100 : 1;
13080
13092
  if (vNum * factor > max) {
13081
13093
  const newValue = roundToPrecision(max / factor, numberOfDecimals);
13082
- setV(newValue);
13094
+ setValueState(newValue);
13095
+ onChange(getNumberFormatValues(newValue));
13083
13096
  }
13084
13097
  if (vNum * factor < min) {
13085
13098
  const newValue = roundToPrecision(min / factor, numberOfDecimals);
13086
- setV(newValue);
13099
+ setValueState(newValue);
13100
+ onChange(getNumberFormatValues(newValue));
13087
13101
  }
13088
13102
  };
13089
13103
  const onValueChangeHandler = (values, sourceInfo) => {
13090
13104
  const newFloatValue = values.floatValue && isPercentage ? roundToPrecision(values.floatValue / 100, numberOfDecimals) : values.floatValue;
13091
- setV(newFloatValue);
13105
+ setValueState(newFloatValue);
13092
13106
  onChange(
13093
13107
  __spreadProps$3(__spreadValues$k({}, values), {
13094
13108
  floatValue: newFloatValue
@@ -13096,6 +13110,9 @@ const FormattedNumberInput = (_a) => {
13096
13110
  sourceInfo
13097
13111
  );
13098
13112
  };
13113
+ useEffect(() => {
13114
+ validateRange();
13115
+ }, [value]);
13099
13116
  return /* @__PURE__ */ React.createElement(
13100
13117
  InputGroupWrapper,
13101
13118
  {
@@ -13107,10 +13124,13 @@ const FormattedNumberInput = (_a) => {
13107
13124
  __spreadValues$k(__spreadValues$k({
13108
13125
  allowLeadingZeros: true,
13109
13126
  customInput: Input$1,
13110
- onBlur: validateRange,
13127
+ onBlur: (e) => {
13128
+ onBlur == null ? void 0 : onBlur(e);
13129
+ validateRange();
13130
+ },
13111
13131
  onValueChange: onValueChangeHandler,
13112
13132
  decimalScale: numberOfDecimals,
13113
- value: isPercentage ? roundToPrecision(parseFloat(`${v != null ? v : 0}`) * 100, numberOfDecimals) : v,
13133
+ value: isPercentage ? roundToPrecision(parseFloat(`${value != null ? value : 0}`) * 100, numberOfDecimals) : value,
13114
13134
  suffix: isPercentage ? "%" : ""
13115
13135
  }, props), rest)
13116
13136
  )
@@ -14274,12 +14294,15 @@ const ComboPicker = (_a) => {
14274
14294
  onChange,
14275
14295
  options,
14276
14296
  size,
14277
- value,
14297
+ value: valueProp,
14278
14298
  placeholder,
14279
14299
  precision,
14280
14300
  formatPreset,
14281
14301
  isDisabled,
14282
- isReadOnly
14302
+ isReadOnly,
14303
+ defaultToZeroIfEmpty = true,
14304
+ max = Infinity,
14305
+ min = -Infinity
14283
14306
  } = _b, rest = __objRest$1(_b, [
14284
14307
  "onChange",
14285
14308
  "options",
@@ -14289,20 +14312,27 @@ const ComboPicker = (_a) => {
14289
14312
  "precision",
14290
14313
  "formatPreset",
14291
14314
  "isDisabled",
14292
- "isReadOnly"
14315
+ "isReadOnly",
14316
+ "defaultToZeroIfEmpty",
14317
+ "max",
14318
+ "min"
14293
14319
  ]);
14320
+ var _a2;
14294
14321
  const { isOpen, onToggle, onClose } = useDisclosure();
14295
- const [inputValue, setInputValue] = useState(value ? value.input : 0);
14296
- const [selectOption, setSelectOption] = useState(value ? value.option : options[0]);
14322
+ const [inputValueState, setInputValueState] = useState(valueProp == null ? void 0 : valueProp.input);
14323
+ const [selectOptionState, setselectOptionState] = useState((_a2 = valueProp == null ? void 0 : valueProp.option) != null ? _a2 : options[0]);
14297
14324
  const [enableSelectInput, setEnableSelectInput] = useState(false);
14325
+ const isInputValueControlled = typeof (valueProp == null ? void 0 : valueProp.input) !== "undefined";
14326
+ const inputValue = isInputValueControlled ? valueProp.input : inputValueState;
14327
+ const isOptionControlled = typeof (valueProp == null ? void 0 : valueProp.option) !== "undefined";
14328
+ const selectOption = isOptionControlled ? valueProp.option : selectOptionState;
14298
14329
  const buttonRef = useRef();
14299
14330
  const selectRef = useRef();
14331
+ const getNewValue = (option, input) => is(Number, input) ? { input: Number(input), option } : { option };
14300
14332
  const handleInputChange = (newInputvalue) => {
14301
- setInputValue(Number(newInputvalue.floatValue));
14302
- onChange == null ? void 0 : onChange({
14303
- input: Number(newInputvalue.floatValue),
14304
- option: selectOption
14305
- });
14333
+ const newValue = getNewValue(selectOption, newInputvalue);
14334
+ setInputValueState(newValue.input);
14335
+ onChange == null ? void 0 : onChange(newValue);
14306
14336
  };
14307
14337
  const handleSelectClose = () => {
14308
14338
  if (buttonRef.current) {
@@ -14313,12 +14343,11 @@ const ComboPicker = (_a) => {
14313
14343
  };
14314
14344
  const handleSelectChange = (selectedOption) => {
14315
14345
  if (selectedOption) {
14316
- setSelectOption(selectedOption);
14317
- onChange == null ? void 0 : onChange({
14318
- input: inputValue,
14319
- option: selectedOption
14320
- });
14321
- handleSelectClose();
14346
+ setselectOptionState(selectedOption);
14347
+ onChange == null ? void 0 : onChange(getNewValue(selectedOption, inputValue));
14348
+ if (isOpen) {
14349
+ handleSelectClose();
14350
+ }
14322
14351
  }
14323
14352
  };
14324
14353
  const handleSelectToggle = () => {
@@ -14332,18 +14361,25 @@ const ComboPicker = (_a) => {
14332
14361
  selectRef.current.focus();
14333
14362
  }
14334
14363
  }, [enableSelectInput]);
14364
+ useEffect(() => {
14365
+ if (!is(Number, inputValue) && defaultToZeroIfEmpty) {
14366
+ handleInputChange(clamp(min, max, 0));
14367
+ }
14368
+ }, [valueProp == null ? void 0 : valueProp.input]);
14335
14369
  return /* @__PURE__ */ React.createElement(InputGroup, null, /* @__PURE__ */ React.createElement(
14336
14370
  FormattedNumberInput,
14337
14371
  __spreadValues$1({
14338
14372
  width: "100%",
14339
- onChange: handleInputChange,
14340
- defaultValue: inputValue,
14373
+ onChange: (values) => handleInputChange(values.floatValue),
14374
+ value: inputValue,
14341
14375
  placeholder,
14342
14376
  size,
14343
14377
  numberOfDecimals: precision,
14344
14378
  preset: formatPreset,
14345
14379
  disabled: isDisabled,
14346
- readOnly: isReadOnly
14380
+ readOnly: isReadOnly,
14381
+ min,
14382
+ max
14347
14383
  }, rest)
14348
14384
  ), /* @__PURE__ */ React.createElement(
14349
14385
  InputRightElement,