Skip to content

Commit

Permalink
docs changes
Browse files Browse the repository at this point in the history
  • Loading branch information
webloopbox committed Oct 24, 2024
1 parent 048d113 commit 3ba8486
Show file tree
Hide file tree
Showing 20 changed files with 243 additions and 162 deletions.
2 changes: 1 addition & 1 deletion reactgrid/lib/cellTemplates/NumberCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const NumberCell: FC<NumberCellProps> = ({
if ((!isEditMode && numberKeys.includes(e.key)) || (allowSeparators && numberSeparators.includes(e.key))) {
setCurrentValue("");
setEditMode(true);
} else if (!isEditMode && !ctx.isCellSelected && (e.key === "Enter" || e.key === "F2")) {
} else if (!isEditMode && !ctx.isSelected && (e.key === "Enter" || e.key === "F2")) {
e.stopPropagation();
setCurrentValue(initialValueStr || "0");
setEditMode(true);
Expand Down
2 changes: 1 addition & 1 deletion reactgrid/lib/cellTemplates/TextCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const TextCell: FC<TextCellProps> = ({ text: initialText, onTextChanged,
e.stopPropagation();
setCurrentValue("");
setEditMode(true);
} else if (!isEditMode && !ctx.isCellSelected && (e.key === "Enter" || e.key === "F2")) {
} else if (!isEditMode && !ctx.isSelected && (e.key === "Enter" || e.key === "F2")) {
e.stopPropagation();
setCurrentValue(initialText || "");
setEditMode(true);
Expand Down
10 changes: 5 additions & 5 deletions reactgrid/lib/components/CellContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface CellContextProviderProps {
realRowIndex: number;
realColumnIndex: number;
cell: Cell;
isCellSelected: boolean;
isSelected: boolean;
isFocused: boolean;
rowSpan?: number;
colSpan?: number;
Expand All @@ -22,7 +22,7 @@ interface CellContextProviderProps {
export const CellContext = createContext<CellContextType>({
realRowIndex: -1,
realColumnIndex: -1,
isCellSelected: false,
isSelected: false,
isFocused: false,
containerStyle: {},
});
Expand All @@ -47,7 +47,7 @@ export const CellContextProvider = memo(
colSpan,
getCellOffset = () => ({}),
cell,
isCellSelected,
isSelected,
isFocused,
}: CellContextProviderProps) => {
const { Template, props } = cell;
Expand All @@ -57,7 +57,7 @@ export const CellContextProvider = memo(
value={{
realRowIndex,
realColumnIndex,
isCellSelected,
isSelected,
isFocused,
containerStyle: {
...(rowSpan && {
Expand All @@ -80,7 +80,7 @@ export const CellContextProvider = memo(
return (
!next.shouldRenderReorderedCells &&
deepCompare(prev.cell, next.cell) &&
prev.isCellSelected === next.isCellSelected &&
prev.isSelected === next.isSelected &&
prev.isFocused === next.isFocused &&
prev.getCellOffset === next.getCellOffset
);
Expand Down
2 changes: 1 addition & 1 deletion reactgrid/lib/components/Pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const PaneGridContent: React.FC<PaneGridContentProps> = React.memo(
realColumnIndex={realColumnIndex}
getCellOffset={memoizedGetCellOffset}
shouldRenderReorderedCells={shouldRenderReorderedCells}
isCellSelected={isCellSelected}
isSelected={isCellSelected}
isFocused={isFocused}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion reactgrid/lib/types/PublicModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export type CellContextType = {
containerStyle: React.CSSProperties;

/** Checks if the cell is selected */
isCellSelected: boolean;
isSelected: boolean;

/** Checks if the cell is focused */
isFocused: boolean;
Expand Down
1 change: 0 additions & 1 deletion reactgrid/lib/types/RGTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type Padding = {
export interface RGTheme {
gap: {
width: React.CSSProperties["width"];
/** Changes grid's background color for the gap to appear colored */
color: React.CSSProperties["color"];
};
paneContainer: {
Expand Down
13 changes: 3 additions & 10 deletions website/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ body {
}

.react-grid-sample2 {
background: linear-gradient(to bottom, #ffffff 80%, transparent 80%), url(../public/static/noise-texture-2.webp);
background: linear-gradient(to bottom, #ffffff 80%, transparent 80%), url(../public/static/noise-texture-2.webp);
}

/* override daisyui theme */
Expand All @@ -50,10 +50,7 @@ body {
}

/* override nextra banner background on dark mode */
:is(
html[class~="dark"]
.dark\:nx-bg-\[linear-gradient\(1deg\,\#383838\,\#212121\)\]
) {
:is(html[class~="dark"] .dark\:nx-bg-\[linear-gradient\(1deg\,\#383838\,\#212121\)\]) {
background-image: none !important;
}

Expand All @@ -74,10 +71,6 @@ body {
background-image: url(../public/static/noise-texture-2.webp);
}

.LiveCode input[type="date"]::-webkit-calendar-picker-indicator {
filter: invert(1);
}

#cc-main {
/** Change font **/
--cc-font-family: Roboto;
Expand Down Expand Up @@ -166,4 +159,4 @@ body {
body {
@apply bg-background text-foreground;
}
}
}
11 changes: 11 additions & 0 deletions website/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Footer } from "@/components/footer";
import "vanilla-cookieconsent/dist/cookieconsent.css";
import CookieConsentComponent from "../components/cookie-consent";
import GoogleAnalytics from "@/components/google-analytics";
import Script from "next/script";

const dm_sans = DM_Sans({
subsets: ["latin"],
Expand Down Expand Up @@ -44,6 +45,16 @@ export default function RootLayout({
return (
<html lang="en" className={`${dm_mono.variable} ${dm_sans.variable}`}>
<body>
<Script id="">
{`
if (!window.localStorage.getItem("theme_default")) {
window.localStorage.setItem("theme", "light");
window.localStorage.setItem("theme_default", "light");
document.documentElement.classList.add("light");
document.documentElement.classList.remove("dark");
}
`}
</Script>
<GoogleAnalytics />
<Header>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const ReactGridExample = () => {
const updatePerson = (id, key, newValue) => {
setPeople((prev) => {
return prev.map((p) => (p.id !== id ? p : { ...p, [key]: newValue }));
return prev.map((p) => (p.id === id ? { ...p, [key]: newValue } : p));
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const ReactGridExample = () => {

const updatePerson = (id, key, newValue) => {
setPeople((prev) => {
return prev.map((p) => (p._id !== id ? p : { ...p, [key]: newValue }));
return prev.map((p) => (p.id === id ? { ...p, [key]: newValue } : p));
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const ReactGridExample = () => {
const updatePerson = (id, key, newValue) => {
setPeople((prev) => {
return prev.map((p) => (p.id !== id ? p : { ...p, [key]: newValue }));
return prev.map((p) => (p.id === id ? { ...p, [key]: newValue } : p));
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const ReactGridExample = () => {
const updatePerson = (id, key, newValue) => {
setPeople((prev) => {
return prev.map((p) => (p.id !== id ? p : { ...p, [key]: newValue }));
return prev.map((p) => (p.id === id ? { ...p, [key]: newValue } : p));
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const ReactGridExample = () => {
const updatePerson = (id, key, newValue) => {
setPeople((prev) => {
return prev.map((p) => (p.id !== id ? p : { ...p, [key]: newValue }));
return prev.map((p) => (p.id === id ? { ...p, [key]: newValue } : p));
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const ReactGridExample = () => {
const updatePerson = (id, key, newValue) => {
setPeople((prev) => {
return prev.map((p) => (p.id !== id ? p : { ...p, [key]: newValue }));
return prev.map((p) => (p.id === id ? { ...p, [key]: newValue } : p));
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ const generateCells = (categories: Category[], updateCategories: UpdateCategoryF
}));
};
// Spanned cells index
const spannedCellsIdx = [
{ rowIndex: 2, colIndex: 1, rowSpan: 2 },
{ rowIndex: 2, colIndex: 2, rowSpan: 2 },
Expand All @@ -107,7 +106,8 @@ const generateCells = (categories: Category[], updateCategories: UpdateCategoryF
const getSpan = (rowIndex: number, colIndex: number) => {
const spannedCell = spannedCellsIdx.find((cell) => cell.rowIndex === rowIndex && cell.colIndex === colIndex);
return spannedCell ? { rowSpan: spannedCell.rowSpan } : {};
if(!spannedCell) return null;
return { rowSpan: spannedCell.rowSpan };
};
const generateRowCells = (rowIndex: number, category: Category): Cell[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,65 @@ const getColumns = (): ColumnDef[] => [
{ colIndex: 3, width: 220, title: "Company" },
];
const handleRowReorder = (
peopleData: Person[],
selectedRowIndexes: number[],
destinationRowIdx: number,
updatePerson: (id: string, key: string, newValue: number) => void
) => {
const prevPeopleData = [...peopleData].sort((a, b) => a.position - b.position);
// Adjust the destination index to account for the header row
const adjustedDestinationIdx = destinationRowIdx - 1;
const adjustedSelectedRowIdxs = selectedRowIndexes.map((rowIdx) => rowIdx - 1);
const isReorderingUpwards = adjustedSelectedRowIdxs.some((rowIdx) => rowIdx > adjustedDestinationIdx);
adjustedSelectedRowIdxs.forEach((rowIdx, index) => {
if (adjustedDestinationIdx === 0) {
prevPeopleData[rowIdx].position = prevPeopleData[adjustedDestinationIdx].position / 2 + index * 0.0001;
} else if (adjustedDestinationIdx === peopleData.length - 1) {
prevPeopleData[rowIdx].position = prevPeopleData[adjustedDestinationIdx].position + 1 + index * 0.0001;
} else if (isReorderingUpwards) {
prevPeopleData[rowIdx].position =
(prevPeopleData[adjustedDestinationIdx].position + prevPeopleData[adjustedDestinationIdx - 1].position) / 2 +
index * 0.0001;
} else {
prevPeopleData[rowIdx].position =
(prevPeopleData[adjustedDestinationIdx].position + prevPeopleData[adjustedDestinationIdx + 1].position) / 2 +
index * 0.0001;
}
});
prevPeopleData.forEach((row) => {
updatePerson(row.id, "position", row.position);
});
};
const handleColumnReorder = (
selectedColIndexes: number[],
destinationColIdx: number,
setColumns: React.Dispatch<React.SetStateAction<ColumnDef[]>>
) => {
setColumns((prevColumns) => {
// Filter out the selected columns and unselected columns
const selectedColumns = prevColumns.filter((_, index) => selectedColIndexes.includes(index));
const unselectedColumns = prevColumns.filter((_, index) => !selectedColIndexes.includes(index));
// Adjust the destination index based on the direction of the reorder
const adjustedDestinationColIdx =
selectedColIndexes[0] > destinationColIdx ? destinationColIdx : destinationColIdx - selectedColumns.length + 1;
// Create the new columns array with reordered columns
const newColumns = [
...unselectedColumns.slice(0, adjustedDestinationColIdx),
...selectedColumns,
...unselectedColumns.slice(adjustedDestinationColIdx),
];
return newColumns;
});
};
type UpdatePerson = <T>(id: string, key: string, newValue: T) => void;
Expand Down Expand Up @@ -204,7 +263,7 @@ const ReactGridExample = () => {
const updatePerson = (id, key, newValue) => {
setPeople((prev) => {
return prev.map((p) => (p.id !== id ? p : { ...p, [key]: newValue }));
return prev.map((p) => (p.id === id ? { ...p, [key]: newValue } : p));
});
};
Expand All @@ -231,66 +290,6 @@ const ReactGridExample = () => {
);
};
const handleRowReorder = (
peopleData: Person[],
selectedRowIndexes: number[],
destinationRowIdx: number,
updatePerson: (id: string, key: string, newValue: number) => void
) => {
const prevPeopleData = [...peopleData].sort((a, b) => a.position - b.position);
// Adjust the destination index to account for the header row
const adjustedDestinationIdx = destinationRowIdx - 1;
const adjustedSelectedRowIdxs = selectedRowIndexes.map((rowIdx) => rowIdx - 1);
const isReorderingUpwards = adjustedSelectedRowIdxs.some((rowIdx) => rowIdx > adjustedDestinationIdx);
adjustedSelectedRowIdxs.forEach((rowIdx, index) => {
if (adjustedDestinationIdx === 0) {
prevPeopleData[rowIdx].position = prevPeopleData[adjustedDestinationIdx].position / 2 + index * 0.0001;
} else if (adjustedDestinationIdx === peopleData.length - 1) {
prevPeopleData[rowIdx].position = prevPeopleData[adjustedDestinationIdx].position + 1 + index * 0.0001;
} else if (isReorderingUpwards) {
prevPeopleData[rowIdx].position =
(prevPeopleData[adjustedDestinationIdx].position + prevPeopleData[adjustedDestinationIdx - 1].position) / 2 +
index * 0.0001;
} else {
prevPeopleData[rowIdx].position =
(prevPeopleData[adjustedDestinationIdx].position + prevPeopleData[adjustedDestinationIdx + 1].position) / 2 +
index * 0.0001;
}
});
prevPeopleData.forEach((row) => {
updatePerson(row.id, "position", row.position);
});
};
const handleColumnReorder = (
selectedColIndexes: number[],
destinationColIdx: number,
setColumns: React.Dispatch<React.SetStateAction<ColumnDef[]>>
) => {
setColumns((prevColumns) => {
// Filter out the selected columns and unselected columns
const selectedColumns = prevColumns.filter((_, index) => selectedColIndexes.includes(index));
const unselectedColumns = prevColumns.filter((_, index) => !selectedColIndexes.includes(index));
// Adjust the destination index based on the direction of the reorder
const adjustedDestinationColIdx =
selectedColIndexes[0] > destinationColIdx ? destinationColIdx : destinationColIdx - selectedColumns.length + 1;
// Create the new columns array with reordered columns
const newColumns = [
...unselectedColumns.slice(0, adjustedDestinationColIdx),
...selectedColumns,
...unselectedColumns.slice(adjustedDestinationColIdx),
];
return newColumns;
});
};
render(<ReactGridExample />, document.getElementById("root"));
`}
/>
Loading

0 comments on commit 3ba8486

Please sign in to comment.