@coveord/plasma-mantine
Version:
A Plasma flavoured Mantine theme
52 lines (51 loc) • 1.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "useControlledList", {
enumerable: true,
get: function() {
return useControlledList;
}
});
var _sliced_to_array = require("@swc/helpers/_/_sliced_to_array");
var _to_consumable_array = require("@swc/helpers/_/_to_consumable_array");
var _hooks = require("@mantine/hooks");
var useControlledList = function(param) {
var defaultValue = param.defaultValue, value = param.value, onChange = param.onChange;
var _useUncontrolled = _sliced_to_array._((0, _hooks.useUncontrolled)({
value: value,
defaultValue: defaultValue,
finalValue: [],
onChange: onChange
}), 2), values = _useUncontrolled[0], handleChange = _useUncontrolled[1];
var remove = function(index) {
var newValues = values.filter(function(_, i) {
return i !== index;
});
handleChange === null || handleChange === void 0 ? void 0 : handleChange(newValues);
};
var append = function(item) {
var newValues = _to_consumable_array._(values).concat([
item
]);
handleChange === null || handleChange === void 0 ? void 0 : handleChange(newValues);
};
var reorder = function(param) {
var from = param.from, to = param.to;
var newValues = _to_consumable_array._(values);
var item = values[from];
newValues.splice(from, 1);
newValues.splice(to, 0, item);
handleChange === null || handleChange === void 0 ? void 0 : handleChange(newValues);
};
return [
values,
{
remove: remove,
append: append,
reorder: reorder
}
];
};
//# sourceMappingURL=useControlledList.js.map