@northlight/ui 2.30.0 → 2.31.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.
@@ -4240,18 +4240,22 @@ interface CreatableSelectDropdownProps<T extends string = string> extends Compon
4240
4240
  declare const CreatableSelectDropdown: <T extends string = string>({ standardOptions, initialPlaceholder, addOptionPlaceholder, creationOption, onOptionChange, variant, defaultValue, value, menuPlacement, ...restProps }: CreatableSelectDropdownProps<T>) => JSX.Element;
4241
4241
 
4242
4242
  type ComboPickerValue = {
4243
- input: number;
4243
+ input?: number;
4244
4244
  option: ComboPickerOption;
4245
4245
  };
4246
4246
  type ComboPickerOption = {
4247
4247
  label: string;
4248
4248
  value: string;
4249
4249
  };
4250
- interface ComboPickerProps extends Omit<NumberInputProps, 'value'> {
4250
+ interface ComboPickerProps extends Omit<FormattedNumberInputProps, 'value' | 'onChange'> {
4251
4251
  options: ComboPickerOption[];
4252
4252
  value?: ComboPickerValue;
4253
4253
  onChange?: (value: ComboPickerValue) => void;
4254
4254
  defaultOption?: ComboPickerOption;
4255
+ precision?: number;
4256
+ formatPreset?: FormattedNumberInputPreset;
4257
+ isDisabled?: boolean;
4258
+ isReadOnly?: boolean;
4255
4259
  }
4256
4260
  interface ComboPickerFieldProps extends ComboPickerProps {
4257
4261
  name: string;
@@ -4267,7 +4271,7 @@ interface ComboPickerFieldProps extends ComboPickerProps {
4267
4271
  * @see ComboPickerField
4268
4272
  * @see {@link https://northlight.dev/reference/combo-picker}
4269
4273
  */
4270
- declare const ComboPicker: ({ onChange, options, size, value, placeholder, isDisabled, ...rest }: ComboPickerProps) => JSX.Element;
4274
+ declare const ComboPicker: ({ onChange, options, size, value, placeholder, precision, formatPreset, isDisabled, isReadOnly, ...rest }: ComboPickerProps) => JSX.Element;
4271
4275
 
4272
4276
  /**
4273
4277
  * The <ComboPicker /> component wrapped in a <Field />
@@ -4276,13 +4280,51 @@ declare const ComboPicker: ({ onChange, options, size, value, placeholder, isDis
4276
4280
  * @see {@link https://northlight.dev/reference/combo-picker}
4277
4281
  *
4278
4282
  * @example (Example)
4279
- * ##Fill in your information:
4283
+ * ##Default number format preset(EU) with default decimals(2):
4284
+ * (?
4285
+ * <Form initialValues={{"budget": {input: 123456789.123, option:{label: 'EUR', value: 'eur'}}}}>
4286
+ * <ComboPickerField
4287
+ * label="Budget"
4288
+ * name="budget"
4289
+ * placeholder="Amount"
4290
+ * options={ [
4291
+ * { label: 'USD', value: 'usd' },
4292
+ * { label: 'EUR', value: 'eur' },
4293
+ * { label: 'SEK', value: 'sek' },
4294
+ * ] }
4295
+ * />
4296
+ * </Form>
4297
+ *
4298
+ * ?)
4299
+ * <br />
4300
+ * ##US number format preset with three decimals as Disabled:
4301
+ * (?
4302
+ * <Form initialValues={{"budget": {input: 123456789.1234, option:{label: 'USD', value: 'usd'}}}}>
4303
+ * <ComboPickerField
4304
+ * label="Budget"
4305
+ * name="budget"
4306
+ * precision={ 3 }
4307
+ * isDisabled={true}
4308
+ * formatPreset='us'
4309
+ * options={ [
4310
+ * { label: 'USD', value: 'usd' },
4311
+ * { label: 'EUR', value: 'eur' },
4312
+ * { label: 'SEK', value: 'sek' },
4313
+ * ] }
4314
+ * />
4315
+ * </Form>
4316
+ *
4317
+ * ?)
4318
+ * <br />
4319
+ * ##NOR number format preset with four decimals as ReadOnly:
4280
4320
  * (?
4281
- * <Form initialValues={{"budget": {input: 195, option:{label: 'SEK', value: 'sek'}}}}>
4321
+ * <Form initialValues={{"budget": {input: 123456789.1234, option:{label: 'SEK', value: 'sek'}}}}>
4282
4322
  * <ComboPickerField
4283
4323
  * label="Budget"
4284
4324
  * name="budget"
4285
- * precision={ 2 }
4325
+ * precision={ 4 }
4326
+ * isReadOnly={true}
4327
+ * formatPreset='nor'
4286
4328
  * options={ [
4287
4329
  * { label: 'USD', value: 'usd' },
4288
4330
  * { label: 'EUR', value: 'eur' },
@@ -14276,27 +14276,33 @@ const ComboPicker = (_a) => {
14276
14276
  size,
14277
14277
  value,
14278
14278
  placeholder,
14279
- isDisabled
14279
+ precision,
14280
+ formatPreset,
14281
+ isDisabled,
14282
+ isReadOnly
14280
14283
  } = _b, rest = __objRest$1(_b, [
14281
14284
  "onChange",
14282
14285
  "options",
14283
14286
  "size",
14284
14287
  "value",
14285
14288
  "placeholder",
14286
- "isDisabled"
14289
+ "precision",
14290
+ "formatPreset",
14291
+ "isDisabled",
14292
+ "isReadOnly"
14287
14293
  ]);
14294
+ var _a2;
14288
14295
  const { isOpen, onToggle, onClose } = useDisclosure();
14289
- const [inputValue, setInputValue] = useState(value ? value.input : 0);
14290
- const [selectOption, setSelectOption] = useState(value ? value.option : options[0]);
14296
+ const [inputValue, setInputValue] = useState(value == null ? void 0 : value.input);
14297
+ const [selectOption, setSelectOption] = useState((_a2 = value == null ? void 0 : value.option) != null ? _a2 : options[0]);
14291
14298
  const [enableSelectInput, setEnableSelectInput] = useState(false);
14292
14299
  const buttonRef = useRef();
14293
14300
  const selectRef = useRef();
14301
+ const getNewValue = (option, input) => input ? { input: Number(input), option } : { option };
14294
14302
  const handleInputChange = (newInputvalue) => {
14295
- setInputValue(Number(newInputvalue));
14296
- onChange == null ? void 0 : onChange({
14297
- input: Number(newInputvalue),
14298
- option: selectOption
14299
- });
14303
+ const newValue = getNewValue(selectOption, newInputvalue.floatValue);
14304
+ setInputValue(newValue.input);
14305
+ onChange == null ? void 0 : onChange(newValue);
14300
14306
  };
14301
14307
  const handleSelectClose = () => {
14302
14308
  if (buttonRef.current) {
@@ -14308,10 +14314,7 @@ const ComboPicker = (_a) => {
14308
14314
  const handleSelectChange = (selectedOption) => {
14309
14315
  if (selectedOption) {
14310
14316
  setSelectOption(selectedOption);
14311
- onChange == null ? void 0 : onChange({
14312
- input: inputValue,
14313
- option: selectedOption
14314
- });
14317
+ onChange == null ? void 0 : onChange(getNewValue(selectedOption, inputValue));
14315
14318
  handleSelectClose();
14316
14319
  }
14317
14320
  };
@@ -14326,17 +14329,19 @@ const ComboPicker = (_a) => {
14326
14329
  selectRef.current.focus();
14327
14330
  }
14328
14331
  }, [enableSelectInput]);
14329
- return /* @__PURE__ */ React.createElement(InputGroup, { size }, /* @__PURE__ */ React.createElement(
14330
- NumberInput,
14332
+ return /* @__PURE__ */ React.createElement(InputGroup, null, /* @__PURE__ */ React.createElement(
14333
+ FormattedNumberInput,
14331
14334
  __spreadValues$1({
14332
14335
  width: "100%",
14333
- overflow: "hidden",
14334
14336
  onChange: handleInputChange,
14335
14337
  defaultValue: inputValue,
14336
14338
  placeholder,
14337
- isDisabled
14338
- }, rest),
14339
- /* @__PURE__ */ React.createElement(NumberInputField$1, null)
14339
+ size,
14340
+ numberOfDecimals: precision,
14341
+ preset: formatPreset,
14342
+ disabled: isDisabled,
14343
+ readOnly: isReadOnly
14344
+ }, rest)
14340
14345
  ), /* @__PURE__ */ React.createElement(
14341
14346
  InputRightElement,
14342
14347
  {