tw-react-components 0.0.147 → 0.0.149
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/index.cjs.js +10 -7
- package/index.esm.js +10 -7
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -1275,7 +1275,7 @@ const SelectInput = react.forwardRef((_a, ref) => {
|
|
|
1275
1275
|
const [open, setOpen] = react.useState(false);
|
|
1276
1276
|
const [searchValue, setSearchValue] = react.useState('');
|
|
1277
1277
|
const pureItems = react.useMemo(() => items.flatMap((item) => (item.group ? item.items : [item])), [items]);
|
|
1278
|
-
const selectedItems = react.useMemo(() => value
|
|
1278
|
+
const selectedItems = react.useMemo(() => isNotNullOrUndefined(value)
|
|
1279
1279
|
? !multiple
|
|
1280
1280
|
? pureItems.find((item) => selectPredicate(item.value, value))
|
|
1281
1281
|
? [pureItems.find((item) => selectPredicate(item.value, value))]
|
|
@@ -1315,7 +1315,7 @@ const SelectInput = react.forwardRef((_a, ref) => {
|
|
|
1315
1315
|
}
|
|
1316
1316
|
}
|
|
1317
1317
|
else if (multiple) {
|
|
1318
|
-
if (selectedMap[id]) {
|
|
1318
|
+
if (isNotNullOrUndefined(selectedMap[id])) {
|
|
1319
1319
|
onChange === null || onChange === void 0 ? void 0 : onChange(selectedItems.filter((item) => item.id !== id).map((item) => item.value));
|
|
1320
1320
|
}
|
|
1321
1321
|
else {
|
|
@@ -1341,15 +1341,18 @@ const SelectInput = react.forwardRef((_a, ref) => {
|
|
|
1341
1341
|
const ItemComponent = multiple ? DropdownMenu.CheckboxItem : DropdownMenu.RadioItem;
|
|
1342
1342
|
const RenderOption = react.useCallback((option) => {
|
|
1343
1343
|
return (jsxRuntime.jsx(ItemComponent, { className: cn('w-full cursor-pointer hover:bg-slate-200 dark:hover:bg-slate-700', {
|
|
1344
|
-
'bg-slate-200 dark:bg-slate-700': selectedMap[option.id],
|
|
1345
|
-
}), value: String(option.id), checked:
|
|
1344
|
+
'bg-slate-200 dark:bg-slate-700': isNotNullOrUndefined(selectedMap[option.id]),
|
|
1345
|
+
}), value: String(option.id), checked: isNotNullOrUndefined(selectedMap[option.id]), onSelect: (event) => {
|
|
1346
1346
|
multiple && event.preventDefault();
|
|
1347
1347
|
handleOnSelect(option.id);
|
|
1348
|
-
}, children: jsxRuntime.jsx("span", { children: renderItem(option,
|
|
1348
|
+
}, children: jsxRuntime.jsx("span", { children: renderItem(option, isNotNullOrUndefined(selectedMap[option.id])) }) }));
|
|
1349
1349
|
}, [ItemComponent, handleOnSelect, multiple, renderItem, selectedMap]);
|
|
1350
1350
|
return (jsxRuntime.jsxs(DropdownMenu, { open: open, onOpenChange: setOpen, children: [jsxRuntime.jsx(DropdownMenu.Trigger, { className: cn('w-full', className), children: jsxRuntime.jsx(TextInput, Object.assign({ className: "[&>div>*]:cursor-pointer", inputClassName: "text-left" }, props, { value: text !== null && text !== void 0 ? text : '', clearable: clearable && !!selectedItems.length, onClear: handleOnClear, suffixIcon: lucideReact.ChevronDownIcon, onSuffixIconClick: () => setOpen((open) => !open), ref: ref, readOnly: true })) }), jsxRuntime.jsxs(DropdownMenu.Content, { className: "flex max-h-80 w-[calc(var(--radix-popper-anchor-width))] flex-col overflow-hidden", children: [search && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(TextInput, { value: searchValue, placeholder: "Search...", size: props.size, onChange: handleOnSearchValueChange, clearable: !!searchValue.length, onClear: clearSearchValue }), jsxRuntime.jsx(DropdownMenu.Separator, { className: "w-full" })] })), filteredItems.length === 0 &&
|
|
1351
1351
|
(allowAddition && searchValue ? (jsxRuntime.jsxs("button", { className: "rounded bg-slate-100 py-1.5 text-center hover:bg-slate-200 dark:bg-slate-900/30 dark:hover:bg-slate-700/30", onClick: handleOnAddItemClicked, children: ["Add '", searchValue, "'"] })) : (jsxRuntime.jsx("div", { className: "py-1.5 text-center text-slate-500", children: "No items." }))), jsxRuntime.jsx(GroupComponent, { className: "flex flex-col gap-1 overflow-auto", value: !multiple && selectedItems.length ? String(selectedItems[0].id) : undefined, children: filteredItems.map((item, index) => item.group ? (jsxRuntime.jsxs(Flex, { className: "gap-1", direction: "column", fullWidth: true, children: [jsxRuntime.jsx(DropdownMenu.Label, { className: "sticky top-0 z-[51] w-full rounded-md border bg-white py-1 dark:bg-slate-900", children: item.label }), item.items.map((subItem) => (jsxRuntime.jsx(RenderOption, Object.assign({}, subItem), subItem.id))), index < filteredItems.length - 1 && (jsxRuntime.jsx("div", { className: "mb-1 h-px w-full bg-slate-200 dark:bg-slate-700" }))] }, item.id)) : (jsxRuntime.jsx(RenderOption, Object.assign({}, item), item.id))) })] })] }));
|
|
1352
1352
|
});
|
|
1353
|
+
function isNotNullOrUndefined(value) {
|
|
1354
|
+
return value !== null && value !== undefined;
|
|
1355
|
+
}
|
|
1353
1356
|
|
|
1354
1357
|
const FileInput = react.forwardRef((_a, ref) => {
|
|
1355
1358
|
var { className, value, onChange, onFileChange, accept } = _a, props = __rest(_a, ["className", "value", "onChange", "onFileChange", "accept"]);
|
|
@@ -1594,7 +1597,7 @@ function DataTable({ className, columns, rows, sorting, pagination, actions = []
|
|
|
1594
1597
|
: undefined, children: [column.header, sorting &&
|
|
1595
1598
|
!column.noSorting &&
|
|
1596
1599
|
(((_b = sorting.sorting) === null || _b === void 0 ? void 0 : _b.field) !== column.field ? (jsxRuntime.jsx(lucideReact.ArrowUpDownIcon, { className: "absolute top-1/2 float-right ml-1 hidden h-4 w-4 -translate-y-1/2 group-hover:inline-block" })) : ((_c = sorting.sorting) === null || _c === void 0 ? void 0 : _c.direction) === 'asc' ? (jsxRuntime.jsx(lucideReact.SortAscIcon, { className: "absolute top-1/2 float-right ml-1 inline-block h-4 w-4 -translate-y-1/2" })) : (jsxRuntime.jsx(lucideReact.SortDescIcon, { className: "absolute top-1/2 float-right ml-1 inline-block h-4 w-4 -translate-y-1/2" })))] }, columnIndex));
|
|
1597
|
-
}), actions.filter((action) => !action.hide).length > 0 &&
|
|
1600
|
+
}), actions.filter((action) => rows.some((item) => { var _a; return typeof action.hide === 'boolean' ? !action.hide : !((_a = action.hide) === null || _a === void 0 ? void 0 : _a.call(action, item)); })).length > 0 && jsxRuntime.jsx(Table.HeadCell, { align: "center", children: "Actions" })] }) }), jsxRuntime.jsxs(Table.Body, { className: "relative", children: [isLoading && (jsxRuntime.jsx(Table.Row, { children: jsxRuntime.jsx(Table.Cell, { className: cn('z-10 h-full w-full p-0', {
|
|
1598
1601
|
absolute: rows.length,
|
|
1599
1602
|
}), colSpan: columnsLength, children: jsxRuntime.jsx(Spinner, { className: "bg-white/50 py-4 dark:bg-slate-700/50" }) }) })), !isLoading && !rows.length && (jsxRuntime.jsx(Table.Row, { children: jsxRuntime.jsx(Table.Cell, { colSpan: columnsLength, children: jsxRuntime.jsx(Flex, { className: "text-slate-500", justify: "center", children: noDataMessage !== null && noDataMessage !== void 0 ? noDataMessage : 'No data' }) }) })), rows.map((item, rowIndex) => [
|
|
1600
1603
|
jsxRuntime.jsxs(Table.Row, { className: cn({
|
|
@@ -1602,7 +1605,7 @@ function DataTable({ className, columns, rows, sorting, pagination, actions = []
|
|
|
1602
1605
|
}, rowClassName === null || rowClassName === void 0 ? void 0 : rowClassName(item, rowIndex)), onClick: handleRowClicked(item, rowIndex), children: [rowExtraContent && (jsxRuntime.jsx(Table.Cell, { className: "w-min", align: "center", children: jsxRuntime.jsx(ExpandButton, { folded: !expandedRows[rowExtraContent.idGetter(item)], foldComponent: lucideReact.MinusIcon, unfoldComponent: lucideReact.PlusIcon, onClick: handleExpandRow(rowExtraContent.idGetter(item)) }) })), _columns.map((column, columnIndex) => {
|
|
1603
1606
|
var _a, _b, _c;
|
|
1604
1607
|
return (jsxRuntime.jsx(Table.Cell, { className: column.className, align: (_a = column.align) !== null && _a !== void 0 ? _a : 'left', children: (_c = (_b = column.render) === null || _b === void 0 ? void 0 : _b.call(column, item, rowIndex)) !== null && _c !== void 0 ? _c : defaultRender(item, column.field) }, columnIndex));
|
|
1605
|
-
}), actions.filter((action) => !action.hide).length > 0 && (jsxRuntime.jsx(Table.Cell, { className: "py-3", children: jsxRuntime.jsx(Flex, { align: "center", justify: "center", children: actions
|
|
1608
|
+
}), actions.filter((action) => { var _a; return typeof action.hide === 'boolean' ? !action.hide : !((_a = action.hide) === null || _a === void 0 ? void 0 : _a.call(action, item)); }).length > 0 && (jsxRuntime.jsx(Table.Cell, { className: "py-3", children: jsxRuntime.jsx(Flex, { align: "center", justify: "center", children: actions
|
|
1606
1609
|
.filter((action) => { var _a; return typeof action.hide === 'boolean' ? !action.hide : !((_a = action.hide) === null || _a === void 0 ? void 0 : _a.call(action, item)); })
|
|
1607
1610
|
.map((action, actionIndex) => {
|
|
1608
1611
|
var _a;
|
package/index.esm.js
CHANGED
|
@@ -1247,7 +1247,7 @@ const SelectInput = forwardRef((_a, ref) => {
|
|
|
1247
1247
|
const [open, setOpen] = useState(false);
|
|
1248
1248
|
const [searchValue, setSearchValue] = useState('');
|
|
1249
1249
|
const pureItems = useMemo(() => items.flatMap((item) => (item.group ? item.items : [item])), [items]);
|
|
1250
|
-
const selectedItems = useMemo(() => value
|
|
1250
|
+
const selectedItems = useMemo(() => isNotNullOrUndefined(value)
|
|
1251
1251
|
? !multiple
|
|
1252
1252
|
? pureItems.find((item) => selectPredicate(item.value, value))
|
|
1253
1253
|
? [pureItems.find((item) => selectPredicate(item.value, value))]
|
|
@@ -1287,7 +1287,7 @@ const SelectInput = forwardRef((_a, ref) => {
|
|
|
1287
1287
|
}
|
|
1288
1288
|
}
|
|
1289
1289
|
else if (multiple) {
|
|
1290
|
-
if (selectedMap[id]) {
|
|
1290
|
+
if (isNotNullOrUndefined(selectedMap[id])) {
|
|
1291
1291
|
onChange === null || onChange === void 0 ? void 0 : onChange(selectedItems.filter((item) => item.id !== id).map((item) => item.value));
|
|
1292
1292
|
}
|
|
1293
1293
|
else {
|
|
@@ -1313,15 +1313,18 @@ const SelectInput = forwardRef((_a, ref) => {
|
|
|
1313
1313
|
const ItemComponent = multiple ? DropdownMenu.CheckboxItem : DropdownMenu.RadioItem;
|
|
1314
1314
|
const RenderOption = useCallback((option) => {
|
|
1315
1315
|
return (jsx(ItemComponent, { className: cn('w-full cursor-pointer hover:bg-slate-200 dark:hover:bg-slate-700', {
|
|
1316
|
-
'bg-slate-200 dark:bg-slate-700': selectedMap[option.id],
|
|
1317
|
-
}), value: String(option.id), checked:
|
|
1316
|
+
'bg-slate-200 dark:bg-slate-700': isNotNullOrUndefined(selectedMap[option.id]),
|
|
1317
|
+
}), value: String(option.id), checked: isNotNullOrUndefined(selectedMap[option.id]), onSelect: (event) => {
|
|
1318
1318
|
multiple && event.preventDefault();
|
|
1319
1319
|
handleOnSelect(option.id);
|
|
1320
|
-
}, children: jsx("span", { children: renderItem(option,
|
|
1320
|
+
}, children: jsx("span", { children: renderItem(option, isNotNullOrUndefined(selectedMap[option.id])) }) }));
|
|
1321
1321
|
}, [ItemComponent, handleOnSelect, multiple, renderItem, selectedMap]);
|
|
1322
1322
|
return (jsxs(DropdownMenu, { open: open, onOpenChange: setOpen, children: [jsx(DropdownMenu.Trigger, { className: cn('w-full', className), children: jsx(TextInput, Object.assign({ className: "[&>div>*]:cursor-pointer", inputClassName: "text-left" }, props, { value: text !== null && text !== void 0 ? text : '', clearable: clearable && !!selectedItems.length, onClear: handleOnClear, suffixIcon: ChevronDownIcon, onSuffixIconClick: () => setOpen((open) => !open), ref: ref, readOnly: true })) }), jsxs(DropdownMenu.Content, { className: "flex max-h-80 w-[calc(var(--radix-popper-anchor-width))] flex-col overflow-hidden", children: [search && (jsxs(Fragment, { children: [jsx(TextInput, { value: searchValue, placeholder: "Search...", size: props.size, onChange: handleOnSearchValueChange, clearable: !!searchValue.length, onClear: clearSearchValue }), jsx(DropdownMenu.Separator, { className: "w-full" })] })), filteredItems.length === 0 &&
|
|
1323
1323
|
(allowAddition && searchValue ? (jsxs("button", { className: "rounded bg-slate-100 py-1.5 text-center hover:bg-slate-200 dark:bg-slate-900/30 dark:hover:bg-slate-700/30", onClick: handleOnAddItemClicked, children: ["Add '", searchValue, "'"] })) : (jsx("div", { className: "py-1.5 text-center text-slate-500", children: "No items." }))), jsx(GroupComponent, { className: "flex flex-col gap-1 overflow-auto", value: !multiple && selectedItems.length ? String(selectedItems[0].id) : undefined, children: filteredItems.map((item, index) => item.group ? (jsxs(Flex, { className: "gap-1", direction: "column", fullWidth: true, children: [jsx(DropdownMenu.Label, { className: "sticky top-0 z-[51] w-full rounded-md border bg-white py-1 dark:bg-slate-900", children: item.label }), item.items.map((subItem) => (jsx(RenderOption, Object.assign({}, subItem), subItem.id))), index < filteredItems.length - 1 && (jsx("div", { className: "mb-1 h-px w-full bg-slate-200 dark:bg-slate-700" }))] }, item.id)) : (jsx(RenderOption, Object.assign({}, item), item.id))) })] })] }));
|
|
1324
1324
|
});
|
|
1325
|
+
function isNotNullOrUndefined(value) {
|
|
1326
|
+
return value !== null && value !== undefined;
|
|
1327
|
+
}
|
|
1325
1328
|
|
|
1326
1329
|
const FileInput = forwardRef((_a, ref) => {
|
|
1327
1330
|
var { className, value, onChange, onFileChange, accept } = _a, props = __rest(_a, ["className", "value", "onChange", "onFileChange", "accept"]);
|
|
@@ -1566,7 +1569,7 @@ function DataTable({ className, columns, rows, sorting, pagination, actions = []
|
|
|
1566
1569
|
: undefined, children: [column.header, sorting &&
|
|
1567
1570
|
!column.noSorting &&
|
|
1568
1571
|
(((_b = sorting.sorting) === null || _b === void 0 ? void 0 : _b.field) !== column.field ? (jsx(ArrowUpDownIcon, { className: "absolute top-1/2 float-right ml-1 hidden h-4 w-4 -translate-y-1/2 group-hover:inline-block" })) : ((_c = sorting.sorting) === null || _c === void 0 ? void 0 : _c.direction) === 'asc' ? (jsx(SortAscIcon, { className: "absolute top-1/2 float-right ml-1 inline-block h-4 w-4 -translate-y-1/2" })) : (jsx(SortDescIcon, { className: "absolute top-1/2 float-right ml-1 inline-block h-4 w-4 -translate-y-1/2" })))] }, columnIndex));
|
|
1569
|
-
}), actions.filter((action) => !action.hide).length > 0 &&
|
|
1572
|
+
}), actions.filter((action) => rows.some((item) => { var _a; return typeof action.hide === 'boolean' ? !action.hide : !((_a = action.hide) === null || _a === void 0 ? void 0 : _a.call(action, item)); })).length > 0 && jsx(Table.HeadCell, { align: "center", children: "Actions" })] }) }), jsxs(Table.Body, { className: "relative", children: [isLoading && (jsx(Table.Row, { children: jsx(Table.Cell, { className: cn('z-10 h-full w-full p-0', {
|
|
1570
1573
|
absolute: rows.length,
|
|
1571
1574
|
}), colSpan: columnsLength, children: jsx(Spinner, { className: "bg-white/50 py-4 dark:bg-slate-700/50" }) }) })), !isLoading && !rows.length && (jsx(Table.Row, { children: jsx(Table.Cell, { colSpan: columnsLength, children: jsx(Flex, { className: "text-slate-500", justify: "center", children: noDataMessage !== null && noDataMessage !== void 0 ? noDataMessage : 'No data' }) }) })), rows.map((item, rowIndex) => [
|
|
1572
1575
|
jsxs(Table.Row, { className: cn({
|
|
@@ -1574,7 +1577,7 @@ function DataTable({ className, columns, rows, sorting, pagination, actions = []
|
|
|
1574
1577
|
}, rowClassName === null || rowClassName === void 0 ? void 0 : rowClassName(item, rowIndex)), onClick: handleRowClicked(item, rowIndex), children: [rowExtraContent && (jsx(Table.Cell, { className: "w-min", align: "center", children: jsx(ExpandButton, { folded: !expandedRows[rowExtraContent.idGetter(item)], foldComponent: MinusIcon, unfoldComponent: PlusIcon, onClick: handleExpandRow(rowExtraContent.idGetter(item)) }) })), _columns.map((column, columnIndex) => {
|
|
1575
1578
|
var _a, _b, _c;
|
|
1576
1579
|
return (jsx(Table.Cell, { className: column.className, align: (_a = column.align) !== null && _a !== void 0 ? _a : 'left', children: (_c = (_b = column.render) === null || _b === void 0 ? void 0 : _b.call(column, item, rowIndex)) !== null && _c !== void 0 ? _c : defaultRender(item, column.field) }, columnIndex));
|
|
1577
|
-
}), actions.filter((action) => !action.hide).length > 0 && (jsx(Table.Cell, { className: "py-3", children: jsx(Flex, { align: "center", justify: "center", children: actions
|
|
1580
|
+
}), actions.filter((action) => { var _a; return typeof action.hide === 'boolean' ? !action.hide : !((_a = action.hide) === null || _a === void 0 ? void 0 : _a.call(action, item)); }).length > 0 && (jsx(Table.Cell, { className: "py-3", children: jsx(Flex, { align: "center", justify: "center", children: actions
|
|
1578
1581
|
.filter((action) => { var _a; return typeof action.hide === 'boolean' ? !action.hide : !((_a = action.hide) === null || _a === void 0 ? void 0 : _a.call(action, item)); })
|
|
1579
1582
|
.map((action, actionIndex) => {
|
|
1580
1583
|
var _a;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tw-react-components",
|
|
3
3
|
"description": "A set of React components build with TailwindCSS to make a nice dashboard.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.149",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://bacali95.github.io/tw-react-components",
|
|
7
7
|
"author": {
|