Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-kallavus committed Oct 17, 2023
1 parent 064c642 commit 8fd44cc
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions next-docs/public/examples/table/ExpandableCheckboxes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Example = () => {
const [selected, setSelected] = useState<{ [key: string]: boolean }>({});

const columnShift = (depth: number) => {
const shiftMap: { [key: number]: string } = [
const shiftMap: { [key: number]: string } = [
'ps-0',
'ps-[25px]',
'ps-[50px]',
Expand All @@ -30,15 +30,15 @@ const Example = () => {
const checkIfSelected = (id: string, canExpand: boolean, rowsById: { [key: string]: boolean }) => {
return canExpand
? Object.keys(rowsById)
.filter((rowId) => rowId.indexOf(id) === 0 && rowId !== id)
.every((rowId) => selected[rowId] === true)
.filter((rowId) => rowId.indexOf(id) === 0 && rowId !== id)
.every((rowId) => selected[rowId] === true)
: selected[id] === true;
}

const checkIfIndeterminate = (id: string, rowsById: { [key: string]: boolean }) => {
const matches = Object.keys(rowsById)
const matches = Object.keys(rowsById)
.filter((rowId) => rowId.indexOf(id) === 0 && rowId !== id);
return !matches.every((rowId) => selected[rowId] === true) && matches.some((rowId) => selected[rowId] === true);
return !matches.every((rowId) => selected[rowId] === true) && matches.some((rowId) => selected[rowId] === true);
}

const columnsInitial = [
Expand All @@ -57,7 +57,7 @@ const Example = () => {
<div className="flex items-center gap-x-1">
<div className="flex items-center h-full">
<Checkbox
id={ PREFIX && PREFIX.length ? `${PREFIX}_root` : 'root'}
id={PREFIX && PREFIX.length ? `${PREFIX}_root` : 'root'}
checked={(Object.keys(rowsById).length === Object.keys(selected).length)}
indeterminate={!!Object.keys(selected).length && Object.keys(selected).length < Object.keys(rowsById).length}
onClick={(e: any) => { e.stopPropagation() }}
Expand All @@ -69,28 +69,28 @@ const Example = () => {
</div>
),
Cell: ({ row, rowsById }: any) => (
<div className={mergeClassnames(
"flex items-center gap-x-1",
columnShift(row.depth),
)}
onClick={(e) => {
if ((e.target as unknown as HTMLElement).tagName === 'SPAN') e.stopPropagation();
}}
>
<div className="flex items-center h-full">
<Checkbox
id={ PREFIX && PREFIX.length ? `${PREFIX}_${row.id}` : row.id}
checked={checkIfSelected(row.id, row.canExpand, rowsById)}
indeterminate={checkIfIndeterminate(row.id, rowsById)}
onClick={(e: any) => e.stopPropagation()}
/>
</div>
{ row.canExpand ? (
<span {...row.getToggleRowExpandedProps()}>
{row.isExpanded ? 'πŸ‘‡' : 'πŸ‘‰'}
</span>
) : null }
<div className={mergeClassnames(
"flex items-center gap-x-1",
columnShift(row.depth),
)}
onClick={(e) => {
if ((e.target as unknown as HTMLElement).tagName === 'SPAN') e.stopPropagation();
}}
>
<div className="flex items-center h-full">
<Checkbox
id={PREFIX && PREFIX.length ? `${PREFIX}_${row.id}` : row.id}
checked={checkIfSelected(row.id, row.canExpand, rowsById)}
indeterminate={checkIfIndeterminate(row.id, rowsById)}
onClick={(e: any) => e.stopPropagation()}
/>
</div>
{row.canExpand ? (
<span {...row.getToggleRowExpandedProps()}>
{row.isExpanded ? 'πŸ‘‡' : 'πŸ‘‰'}
</span>
) : null}
</div>
)
},
],
Expand Down Expand Up @@ -301,10 +301,10 @@ const Example = () => {
useCheckbox={true}
expandedByDefault={true}
getOnRowSelect={() => (rows: any) => {
setSelected(rows.reduce((acc: {[key: string]: boolean}, item: any) => {
acc[`${item.id}`] = true;
return acc;
}, {})
setSelected(rows.reduce((acc: { [key: string]: boolean }, item: any) => {
acc[`${item.id}`] = true;
return acc;
}, {})
);
}}
/>
Expand Down

0 comments on commit 8fd44cc

Please sign in to comment.