@northlight/ui 2.26.1 → 2.27.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 +7 -72
- package/dist/es/northlight.js +103 -59
- package/dist/es/northlight.js.map +1 -1
- package/dist/umd/northlight.cjs +102 -58
- 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
|
@@ -9997,7 +9997,15 @@
|
|
|
9997
9997
|
}
|
|
9998
9998
|
return a;
|
|
9999
9999
|
};
|
|
10000
|
-
const
|
|
10000
|
+
const mapEditableVariantsToButtonSubmitVariants = {
|
|
10001
|
+
brand: "brand",
|
|
10002
|
+
default: "success"
|
|
10003
|
+
};
|
|
10004
|
+
const mapEditableVariantsToButtonCancelVariants = {
|
|
10005
|
+
brand: "ghost",
|
|
10006
|
+
default: "danger"
|
|
10007
|
+
};
|
|
10008
|
+
const EditableControls = ({ size, variant = "default" }) => {
|
|
10001
10009
|
const {
|
|
10002
10010
|
getSubmitButtonProps,
|
|
10003
10011
|
getCancelButtonProps
|
|
@@ -10009,7 +10017,7 @@
|
|
|
10009
10017
|
__spreadValues$O({
|
|
10010
10018
|
"aria-label": "Cancel",
|
|
10011
10019
|
sx: button,
|
|
10012
|
-
variant:
|
|
10020
|
+
variant: mapEditableVariantsToButtonCancelVariants[variant]
|
|
10013
10021
|
}, getCancelButtonProps()),
|
|
10014
10022
|
/* @__PURE__ */ React.createElement(Icon$1, { sx: icon, as: icons.XCloseSolid })
|
|
10015
10023
|
), /* @__PURE__ */ React.createElement(
|
|
@@ -10017,7 +10025,7 @@
|
|
|
10017
10025
|
__spreadValues$O({
|
|
10018
10026
|
"aria-label": "Save",
|
|
10019
10027
|
sx: button,
|
|
10020
|
-
variant:
|
|
10028
|
+
variant: mapEditableVariantsToButtonSubmitVariants[variant]
|
|
10021
10029
|
}, getSubmitButtonProps()),
|
|
10022
10030
|
/* @__PURE__ */ React.createElement(Icon$1, { sx: icon, as: icons.CheckDuo })
|
|
10023
10031
|
)) : /* @__PURE__ */ React.createElement(
|
|
@@ -10065,12 +10073,14 @@
|
|
|
10065
10073
|
size = "md",
|
|
10066
10074
|
value: inputValue,
|
|
10067
10075
|
onSubmit,
|
|
10068
|
-
leftItem
|
|
10076
|
+
leftItem,
|
|
10077
|
+
variant = "default"
|
|
10069
10078
|
} = _b, rest = __objRest$E(_b, [
|
|
10070
10079
|
"size",
|
|
10071
10080
|
"value",
|
|
10072
10081
|
"onSubmit",
|
|
10073
|
-
"leftItem"
|
|
10082
|
+
"leftItem",
|
|
10083
|
+
"variant"
|
|
10074
10084
|
]);
|
|
10075
10085
|
const [value, setValue] = React.useState(inputValue);
|
|
10076
10086
|
const { input, preview } = react.useMultiStyleConfig("EditableText", { size, value });
|
|
@@ -10099,7 +10109,7 @@
|
|
|
10099
10109
|
size,
|
|
10100
10110
|
sx: input
|
|
10101
10111
|
}
|
|
10102
|
-
), /* @__PURE__ */ React.createElement(react.InputRightElement, { sx: { width: "min-content" } }, /* @__PURE__ */ React.createElement(EditableControls, { size })))
|
|
10112
|
+
), /* @__PURE__ */ React.createElement(react.InputRightElement, { sx: { width: "min-content" } }, /* @__PURE__ */ React.createElement(EditableControls, { size, variant })))
|
|
10103
10113
|
);
|
|
10104
10114
|
};
|
|
10105
10115
|
|
|
@@ -13840,10 +13850,28 @@
|
|
|
13840
13850
|
}
|
|
13841
13851
|
return target;
|
|
13842
13852
|
};
|
|
13853
|
+
const { Option: ChakraOption } = chakraReactSelect.chakraComponents;
|
|
13843
13854
|
const customComponents = {
|
|
13844
13855
|
Option: (_a) => {
|
|
13845
13856
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
13846
|
-
return /* @__PURE__ */ React.createElement(
|
|
13857
|
+
return /* @__PURE__ */ React.createElement(ChakraOption, __spreadValues$1({}, props), props.data.isCreation && /* @__PURE__ */ React.createElement(
|
|
13858
|
+
react.Flex,
|
|
13859
|
+
{
|
|
13860
|
+
mr: 3,
|
|
13861
|
+
width: 1.5,
|
|
13862
|
+
mb: 0.5,
|
|
13863
|
+
justifyContent: "center",
|
|
13864
|
+
alignItems: "center"
|
|
13865
|
+
},
|
|
13866
|
+
/* @__PURE__ */ React.createElement(Icon$1, { as: icons.PlusSolid, color: "brand" })
|
|
13867
|
+
), !props.data.isCreation && /* @__PURE__ */ React.createElement(react.Box, { mr: 3, width: 1.5 }), /* @__PURE__ */ React.createElement(
|
|
13868
|
+
react.Text,
|
|
13869
|
+
{
|
|
13870
|
+
color: props.data.isCreation ? "text.brand" : "text.default",
|
|
13871
|
+
fontWeight: props.data.isCreation ? "semibold" : "normal"
|
|
13872
|
+
},
|
|
13873
|
+
children
|
|
13874
|
+
));
|
|
13847
13875
|
}
|
|
13848
13876
|
};
|
|
13849
13877
|
|
|
@@ -13866,70 +13894,67 @@
|
|
|
13866
13894
|
return a;
|
|
13867
13895
|
};
|
|
13868
13896
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
13897
|
+
const CREATION_OPTION_VALUE = "add_field";
|
|
13869
13898
|
const CreatableSelectDropdown = ({
|
|
13870
13899
|
standardOptions,
|
|
13871
13900
|
initialPlaceholder = "Select or create...",
|
|
13872
|
-
addOptionPlaceholder = "
|
|
13901
|
+
addOptionPlaceholder = "Select or create...",
|
|
13873
13902
|
creationOption = {
|
|
13874
|
-
label: "Add
|
|
13875
|
-
value:
|
|
13903
|
+
label: "Add field",
|
|
13904
|
+
value: CREATION_OPTION_VALUE,
|
|
13876
13905
|
isCreation: true
|
|
13877
13906
|
},
|
|
13878
13907
|
onOptionChange,
|
|
13879
|
-
width = "100%",
|
|
13880
13908
|
variant = "outline",
|
|
13881
13909
|
defaultValue,
|
|
13882
13910
|
value,
|
|
13883
13911
|
menuPlacement = "bottom"
|
|
13884
13912
|
}) => {
|
|
13885
|
-
const
|
|
13886
|
-
|
|
13887
|
-
|
|
13888
|
-
|
|
13889
|
-
|
|
13890
|
-
}
|
|
13891
|
-
if (!ramda.isNil(defaultValue)) {
|
|
13892
|
-
return (_b = standardOptions.find((option) => option.value === defaultValue)) != null ? _b : null;
|
|
13893
|
-
}
|
|
13894
|
-
return null;
|
|
13895
|
-
},
|
|
13896
|
-
[value]
|
|
13897
|
-
);
|
|
13898
|
-
const [selectedOption, setSelectedOption] = React.useState(initialSelectedOption);
|
|
13899
|
-
const [newOptionText, setNewOptionText] = React.useState("");
|
|
13913
|
+
const [selectedOption, setSelectedOption] = React.useState(() => {
|
|
13914
|
+
var _a, _b;
|
|
13915
|
+
const targetValue = (_a = value != null ? value : defaultValue) != null ? _a : null;
|
|
13916
|
+
return targetValue ? (_b = standardOptions.find((option) => option.value === targetValue)) != null ? _b : null : null;
|
|
13917
|
+
});
|
|
13900
13918
|
const [newOptionPlaceholder, setNewOptionPlaceholder] = React.useState(initialPlaceholder);
|
|
13901
13919
|
const [createdOptions, setCreatedOptions] = React.useState([]);
|
|
13920
|
+
const [createNewOption, setCreateNewOption] = React.useState(false);
|
|
13921
|
+
const [addFieldInputValue, setAddFieldInputValue] = React.useState("");
|
|
13902
13922
|
function isCreationOption(option) {
|
|
13903
13923
|
return option && typeof option.isCreation === "boolean";
|
|
13904
13924
|
}
|
|
13905
13925
|
const ref = React.useRef(null);
|
|
13906
|
-
|
|
13907
|
-
|
|
13908
|
-
|
|
13909
|
-
|
|
13910
|
-
|
|
13911
|
-
setNewOptionPlaceholder(initialPlaceholder);
|
|
13912
|
-
}
|
|
13926
|
+
const checkIfNewOptionTextExistsInOptions = (string, options) => ramda.any((option) => ramda.toLower(option.value) === string, options);
|
|
13927
|
+
const handleCreateOption = (newOptionTextString) => {
|
|
13928
|
+
setCreateNewOption(true);
|
|
13929
|
+
if (ramda.isEmpty(ramda.trim(newOptionTextString))) {
|
|
13930
|
+
return;
|
|
13913
13931
|
}
|
|
13914
|
-
|
|
13915
|
-
|
|
13916
|
-
|
|
13917
|
-
|
|
13918
|
-
|
|
13919
|
-
|
|
13920
|
-
|
|
13921
|
-
|
|
13922
|
-
|
|
13923
|
-
|
|
13932
|
+
const newOptionTextLower = ramda.toLower(newOptionTextString);
|
|
13933
|
+
const newOptionExistsInStandardOptions = checkIfNewOptionTextExistsInOptions(newOptionTextLower, standardOptions);
|
|
13934
|
+
const newOptionExistsInCreatedOptions = checkIfNewOptionTextExistsInOptions(
|
|
13935
|
+
newOptionTextLower,
|
|
13936
|
+
createdOptions
|
|
13937
|
+
);
|
|
13938
|
+
if (!newOptionExistsInCreatedOptions && !newOptionExistsInStandardOptions) {
|
|
13939
|
+
const newOption = {
|
|
13940
|
+
label: newOptionTextString,
|
|
13941
|
+
value: newOptionTextString
|
|
13942
|
+
};
|
|
13943
|
+
setCreatedOptions((currentCreatedOptions) => [
|
|
13944
|
+
...currentCreatedOptions,
|
|
13945
|
+
newOption
|
|
13946
|
+
]);
|
|
13924
13947
|
setSelectedOption(newOption);
|
|
13925
13948
|
onOptionChange(newOption);
|
|
13926
13949
|
}
|
|
13927
|
-
setNewOptionText("");
|
|
13928
13950
|
setNewOptionPlaceholder(initialPlaceholder);
|
|
13929
13951
|
};
|
|
13930
13952
|
const handleChange = (newValue, _actionMeta) => {
|
|
13931
13953
|
const option = newValue;
|
|
13932
|
-
if (
|
|
13954
|
+
if (newValue == null ? void 0 : newValue.isCreation) {
|
|
13955
|
+
setCreateNewOption(true);
|
|
13956
|
+
}
|
|
13957
|
+
if (option == null) {
|
|
13933
13958
|
return;
|
|
13934
13959
|
}
|
|
13935
13960
|
if (isCreationOption(option)) {
|
|
@@ -13937,14 +13962,10 @@
|
|
|
13937
13962
|
} else {
|
|
13938
13963
|
setNewOptionPlaceholder(initialPlaceholder);
|
|
13939
13964
|
}
|
|
13940
|
-
|
|
13941
|
-
|
|
13942
|
-
};
|
|
13943
|
-
const handleKeyDown = (event) => {
|
|
13944
|
-
if (event.key === "Enter" && newOptionText) {
|
|
13945
|
-
handleCreateOption();
|
|
13946
|
-
event.preventDefault();
|
|
13965
|
+
if (option.value !== CREATION_OPTION_VALUE) {
|
|
13966
|
+
setSelectedOption(option);
|
|
13947
13967
|
}
|
|
13968
|
+
onOptionChange(option);
|
|
13948
13969
|
};
|
|
13949
13970
|
const combinedOptions = [...standardOptions, ...createdOptions];
|
|
13950
13971
|
const customOptions = [
|
|
@@ -13953,13 +13974,36 @@
|
|
|
13953
13974
|
}),
|
|
13954
13975
|
...combinedOptions
|
|
13955
13976
|
];
|
|
13956
|
-
return /* @__PURE__ */ React.createElement(react.Box, { ref }, /* @__PURE__ */ React.createElement(
|
|
13977
|
+
return /* @__PURE__ */ React.createElement(react.Box, { ref, w: "sm", maxW: "full" }, createNewOption && /* @__PURE__ */ React.createElement(
|
|
13978
|
+
EditableText,
|
|
13979
|
+
{
|
|
13980
|
+
value: addFieldInputValue,
|
|
13981
|
+
startWithEditView: true,
|
|
13982
|
+
onChange: (v) => {
|
|
13983
|
+
setAddFieldInputValue(v);
|
|
13984
|
+
},
|
|
13985
|
+
submitOnBlur: false,
|
|
13986
|
+
onCancel: () => {
|
|
13987
|
+
setAddFieldInputValue("");
|
|
13988
|
+
setCreateNewOption(false);
|
|
13989
|
+
},
|
|
13990
|
+
onSubmit: (v) => {
|
|
13991
|
+
handleCreateOption(v);
|
|
13992
|
+
setCreateNewOption(false);
|
|
13993
|
+
},
|
|
13994
|
+
variant: "brand",
|
|
13995
|
+
sx: {
|
|
13996
|
+
minWidth: "100%",
|
|
13997
|
+
width: "100%"
|
|
13998
|
+
}
|
|
13999
|
+
}
|
|
14000
|
+
), !createNewOption && /* @__PURE__ */ React.createElement(
|
|
13957
14001
|
chakraReactSelect.CreatableSelect,
|
|
13958
14002
|
{
|
|
13959
14003
|
menuPlacement,
|
|
13960
14004
|
chakraStyles: __spreadProps(__spreadValues({}, customSelectStyles), {
|
|
13961
14005
|
container: (provided) => __spreadProps(__spreadValues({}, provided), {
|
|
13962
|
-
width
|
|
14006
|
+
width: "100%"
|
|
13963
14007
|
}),
|
|
13964
14008
|
option: (provided, { isSelected }) => __spreadValues(__spreadValues({}, provided), isSelected && {
|
|
13965
14009
|
color: "black"
|
|
@@ -13970,11 +14014,11 @@
|
|
|
13970
14014
|
value: selectedOption,
|
|
13971
14015
|
onChange: handleChange,
|
|
13972
14016
|
isMulti: false,
|
|
13973
|
-
|
|
13974
|
-
|
|
13975
|
-
|
|
14017
|
+
onCreateOption: (v) => {
|
|
14018
|
+
setCreateNewOption(true);
|
|
14019
|
+
setAddFieldInputValue(v);
|
|
14020
|
+
},
|
|
13976
14021
|
placeholder: newOptionPlaceholder,
|
|
13977
|
-
inputValue: newOptionText,
|
|
13978
14022
|
useBasicStyles: true,
|
|
13979
14023
|
variant
|
|
13980
14024
|
}
|