@northlight/ui 2.31.1 → 2.32.0
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/dist/es/northlight.d.ts +24 -10
- package/dist/es/northlight.js +87 -33
- package/dist/es/northlight.js.map +1 -1
- package/dist/umd/northlight.cjs +85 -30
- package/dist/umd/northlight.cjs.map +1 -1
- package/dist/umd/northlight.min.cjs +3 -3
- package/dist/umd/northlight.min.cjs.map +1 -1
- package/package.json +2 -2
package/dist/umd/northlight.cjs
CHANGED
|
@@ -458,6 +458,21 @@
|
|
|
458
458
|
|
|
459
459
|
const clamp = (minValue, maxValue, value) => Math.min(Math.max(value, minValue), maxValue);
|
|
460
460
|
|
|
461
|
+
const availableColorSchemes = ramda.keys(ramda.omit(["mono"], tokens.palette));
|
|
462
|
+
const djb2Hash = (str, colors) => {
|
|
463
|
+
let hash = 5381;
|
|
464
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
465
|
+
const char = str.charCodeAt(i);
|
|
466
|
+
hash = (hash << 5) + hash + char;
|
|
467
|
+
hash &= hash;
|
|
468
|
+
}
|
|
469
|
+
return Math.abs(hash) % colors.length;
|
|
470
|
+
};
|
|
471
|
+
const getConsistentRandomColorFromString = (str, colors = availableColorSchemes) => {
|
|
472
|
+
const index = djb2Hash(str, colors);
|
|
473
|
+
return colors[index];
|
|
474
|
+
};
|
|
475
|
+
|
|
461
476
|
const useResizeWidth = ({
|
|
462
477
|
stationaryEdge = "left",
|
|
463
478
|
minWidthPx = 0,
|
|
@@ -4767,10 +4782,13 @@
|
|
|
4767
4782
|
}),
|
|
4768
4783
|
variants: {
|
|
4769
4784
|
default: ({ theme: { colors: color } }) => ({
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4785
|
+
color: color.text.default,
|
|
4786
|
+
bgColor: color.bg.base,
|
|
4787
|
+
borderWidth: "xs",
|
|
4788
|
+
borderColor: color.border.default,
|
|
4789
|
+
borderStyle: "solid",
|
|
4790
|
+
[$arrowBg.variable]: color.bg.base,
|
|
4791
|
+
[$arrowBorder.variable]: color.border.default
|
|
4774
4792
|
}),
|
|
4775
4793
|
success: ({ theme: { colors: color } }) => ({
|
|
4776
4794
|
color: "text.over.success",
|
|
@@ -7772,7 +7790,7 @@
|
|
|
7772
7790
|
hasArrow = true,
|
|
7773
7791
|
title = "",
|
|
7774
7792
|
description = "",
|
|
7775
|
-
hasIcon =
|
|
7793
|
+
hasIcon = false
|
|
7776
7794
|
} = _b, rest = __objRest$18(_b, [
|
|
7777
7795
|
"variant",
|
|
7778
7796
|
"hasArrow",
|
|
@@ -7787,7 +7805,7 @@
|
|
|
7787
7805
|
{
|
|
7788
7806
|
variant: "14",
|
|
7789
7807
|
sx: {
|
|
7790
|
-
color: !variant || variant === "ai"
|
|
7808
|
+
color: !variant || variant === "ai" ? "text.inverted" : "text.default"
|
|
7791
7809
|
}
|
|
7792
7810
|
},
|
|
7793
7811
|
description
|
|
@@ -13015,12 +13033,13 @@
|
|
|
13015
13033
|
preset = "eu",
|
|
13016
13034
|
isPercentage = false,
|
|
13017
13035
|
onChange = ramda.identity,
|
|
13018
|
-
value,
|
|
13036
|
+
value: valueProp,
|
|
13019
13037
|
numberOfDecimals = 2,
|
|
13020
13038
|
max = Infinity,
|
|
13021
13039
|
min = -Infinity,
|
|
13022
13040
|
inputLeftElement,
|
|
13023
|
-
inputRightElement
|
|
13041
|
+
inputRightElement,
|
|
13042
|
+
onBlur
|
|
13024
13043
|
} = _b, rest = __objRest$g(_b, [
|
|
13025
13044
|
"preset",
|
|
13026
13045
|
"isPercentage",
|
|
@@ -13030,27 +13049,37 @@
|
|
|
13030
13049
|
"max",
|
|
13031
13050
|
"min",
|
|
13032
13051
|
"inputLeftElement",
|
|
13033
|
-
"inputRightElement"
|
|
13052
|
+
"inputRightElement",
|
|
13053
|
+
"onBlur"
|
|
13034
13054
|
]);
|
|
13055
|
+
const [valueState, setValueState] = React.useState(valueProp);
|
|
13056
|
+
const isControlled = typeof valueProp !== "undefined";
|
|
13057
|
+
const value = isControlled ? valueProp : valueState;
|
|
13035
13058
|
const props = presetMap[preset];
|
|
13036
|
-
const
|
|
13059
|
+
const getNumberFormatValues = (number) => ({
|
|
13060
|
+
floatValue: number,
|
|
13061
|
+
formattedValue: reactNumberFormat.numericFormatter(number.toString(), props),
|
|
13062
|
+
value: number.toString()
|
|
13063
|
+
});
|
|
13037
13064
|
const validateRange = () => {
|
|
13038
|
-
if (ramda.isNil(
|
|
13065
|
+
if (ramda.isNil(value))
|
|
13039
13066
|
return;
|
|
13040
|
-
const vNum = typeof
|
|
13067
|
+
const vNum = typeof value === "string" ? parseFloat(value) : value;
|
|
13041
13068
|
const factor = isPercentage ? 100 : 1;
|
|
13042
13069
|
if (vNum * factor > max) {
|
|
13043
13070
|
const newValue = roundToPrecision(max / factor, numberOfDecimals);
|
|
13044
|
-
|
|
13071
|
+
setValueState(newValue);
|
|
13072
|
+
onChange(getNumberFormatValues(newValue));
|
|
13045
13073
|
}
|
|
13046
13074
|
if (vNum * factor < min) {
|
|
13047
13075
|
const newValue = roundToPrecision(min / factor, numberOfDecimals);
|
|
13048
|
-
|
|
13076
|
+
setValueState(newValue);
|
|
13077
|
+
onChange(getNumberFormatValues(newValue));
|
|
13049
13078
|
}
|
|
13050
13079
|
};
|
|
13051
13080
|
const onValueChangeHandler = (values, sourceInfo) => {
|
|
13052
13081
|
const newFloatValue = values.floatValue && isPercentage ? roundToPrecision(values.floatValue / 100, numberOfDecimals) : values.floatValue;
|
|
13053
|
-
|
|
13082
|
+
setValueState(newFloatValue);
|
|
13054
13083
|
onChange(
|
|
13055
13084
|
__spreadProps$3(__spreadValues$k({}, values), {
|
|
13056
13085
|
floatValue: newFloatValue
|
|
@@ -13058,6 +13087,9 @@
|
|
|
13058
13087
|
sourceInfo
|
|
13059
13088
|
);
|
|
13060
13089
|
};
|
|
13090
|
+
React.useEffect(() => {
|
|
13091
|
+
validateRange();
|
|
13092
|
+
}, [value]);
|
|
13061
13093
|
return /* @__PURE__ */ React.createElement(
|
|
13062
13094
|
InputGroupWrapper,
|
|
13063
13095
|
{
|
|
@@ -13069,10 +13101,13 @@
|
|
|
13069
13101
|
__spreadValues$k(__spreadValues$k({
|
|
13070
13102
|
allowLeadingZeros: true,
|
|
13071
13103
|
customInput: react.Input,
|
|
13072
|
-
onBlur:
|
|
13104
|
+
onBlur: (e) => {
|
|
13105
|
+
onBlur == null ? void 0 : onBlur(e);
|
|
13106
|
+
validateRange();
|
|
13107
|
+
},
|
|
13073
13108
|
onValueChange: onValueChangeHandler,
|
|
13074
13109
|
decimalScale: numberOfDecimals,
|
|
13075
|
-
value: isPercentage ? roundToPrecision(parseFloat(`${
|
|
13110
|
+
value: isPercentage ? roundToPrecision(parseFloat(`${value != null ? value : 0}`) * 100, numberOfDecimals) : value,
|
|
13076
13111
|
suffix: isPercentage ? "%" : ""
|
|
13077
13112
|
}, props), rest)
|
|
13078
13113
|
)
|
|
@@ -14236,12 +14271,15 @@
|
|
|
14236
14271
|
onChange,
|
|
14237
14272
|
options,
|
|
14238
14273
|
size,
|
|
14239
|
-
value,
|
|
14274
|
+
value: valueProp,
|
|
14240
14275
|
placeholder,
|
|
14241
14276
|
precision,
|
|
14242
14277
|
formatPreset,
|
|
14243
14278
|
isDisabled,
|
|
14244
|
-
isReadOnly
|
|
14279
|
+
isReadOnly,
|
|
14280
|
+
defaultToZeroIfEmpty = true,
|
|
14281
|
+
max = Infinity,
|
|
14282
|
+
min = -Infinity
|
|
14245
14283
|
} = _b, rest = __objRest$1(_b, [
|
|
14246
14284
|
"onChange",
|
|
14247
14285
|
"options",
|
|
@@ -14251,19 +14289,26 @@
|
|
|
14251
14289
|
"precision",
|
|
14252
14290
|
"formatPreset",
|
|
14253
14291
|
"isDisabled",
|
|
14254
|
-
"isReadOnly"
|
|
14292
|
+
"isReadOnly",
|
|
14293
|
+
"defaultToZeroIfEmpty",
|
|
14294
|
+
"max",
|
|
14295
|
+
"min"
|
|
14255
14296
|
]);
|
|
14256
14297
|
var _a2;
|
|
14257
14298
|
const { isOpen, onToggle, onClose } = react.useDisclosure();
|
|
14258
|
-
const [
|
|
14259
|
-
const [
|
|
14299
|
+
const [inputValueState, setInputValueState] = React.useState(valueProp == null ? void 0 : valueProp.input);
|
|
14300
|
+
const [selectOptionState, setselectOptionState] = React.useState((_a2 = valueProp == null ? void 0 : valueProp.option) != null ? _a2 : options[0]);
|
|
14260
14301
|
const [enableSelectInput, setEnableSelectInput] = React.useState(false);
|
|
14302
|
+
const isInputValueControlled = typeof (valueProp == null ? void 0 : valueProp.input) !== "undefined";
|
|
14303
|
+
const inputValue = isInputValueControlled ? valueProp.input : inputValueState;
|
|
14304
|
+
const isOptionControlled = typeof (valueProp == null ? void 0 : valueProp.option) !== "undefined";
|
|
14305
|
+
const selectOption = isOptionControlled ? valueProp.option : selectOptionState;
|
|
14261
14306
|
const buttonRef = React.useRef();
|
|
14262
14307
|
const selectRef = React.useRef();
|
|
14263
|
-
const getNewValue = (option, input) => input ? { input: Number(input), option } : { option };
|
|
14308
|
+
const getNewValue = (option, input) => ramda.is(Number, input) ? { input: Number(input), option } : { option };
|
|
14264
14309
|
const handleInputChange = (newInputvalue) => {
|
|
14265
|
-
const newValue = getNewValue(selectOption, newInputvalue
|
|
14266
|
-
|
|
14310
|
+
const newValue = getNewValue(selectOption, newInputvalue);
|
|
14311
|
+
setInputValueState(newValue.input);
|
|
14267
14312
|
onChange == null ? void 0 : onChange(newValue);
|
|
14268
14313
|
};
|
|
14269
14314
|
const handleSelectClose = () => {
|
|
@@ -14275,9 +14320,11 @@
|
|
|
14275
14320
|
};
|
|
14276
14321
|
const handleSelectChange = (selectedOption) => {
|
|
14277
14322
|
if (selectedOption) {
|
|
14278
|
-
|
|
14323
|
+
setselectOptionState(selectedOption);
|
|
14279
14324
|
onChange == null ? void 0 : onChange(getNewValue(selectedOption, inputValue));
|
|
14280
|
-
|
|
14325
|
+
if (isOpen) {
|
|
14326
|
+
handleSelectClose();
|
|
14327
|
+
}
|
|
14281
14328
|
}
|
|
14282
14329
|
};
|
|
14283
14330
|
const handleSelectToggle = () => {
|
|
@@ -14291,18 +14338,25 @@
|
|
|
14291
14338
|
selectRef.current.focus();
|
|
14292
14339
|
}
|
|
14293
14340
|
}, [enableSelectInput]);
|
|
14341
|
+
React.useEffect(() => {
|
|
14342
|
+
if (!ramda.is(Number, inputValue) && defaultToZeroIfEmpty) {
|
|
14343
|
+
handleInputChange(clamp(min, max, 0));
|
|
14344
|
+
}
|
|
14345
|
+
}, [valueProp == null ? void 0 : valueProp.input]);
|
|
14294
14346
|
return /* @__PURE__ */ React.createElement(react.InputGroup, null, /* @__PURE__ */ React.createElement(
|
|
14295
14347
|
FormattedNumberInput,
|
|
14296
14348
|
__spreadValues$1({
|
|
14297
14349
|
width: "100%",
|
|
14298
|
-
onChange: handleInputChange,
|
|
14299
|
-
|
|
14350
|
+
onChange: (values) => handleInputChange(values.floatValue),
|
|
14351
|
+
value: inputValue,
|
|
14300
14352
|
placeholder,
|
|
14301
14353
|
size,
|
|
14302
14354
|
numberOfDecimals: precision,
|
|
14303
14355
|
preset: formatPreset,
|
|
14304
14356
|
disabled: isDisabled,
|
|
14305
|
-
readOnly: isReadOnly
|
|
14357
|
+
readOnly: isReadOnly,
|
|
14358
|
+
min,
|
|
14359
|
+
max
|
|
14306
14360
|
}, rest)
|
|
14307
14361
|
), /* @__PURE__ */ React.createElement(
|
|
14308
14362
|
react.InputRightElement,
|
|
@@ -15265,6 +15319,7 @@
|
|
|
15265
15319
|
exports.clamp = clamp;
|
|
15266
15320
|
exports.createDebounceFunctionInstance = createDebounceFunctionInstance;
|
|
15267
15321
|
exports.getChildrenWithProps = getChildrenWithProps;
|
|
15322
|
+
exports.getConsistentRandomColorFromString = getConsistentRandomColorFromString;
|
|
15268
15323
|
exports.getContrastColor = getContrastColor;
|
|
15269
15324
|
exports.getFieldError = getFieldError;
|
|
15270
15325
|
exports.getInitials = getInitials;
|