Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make loading cell able to render a loading skeleton #832

Merged
merged 4 commits into from
Dec 28, 2023

Conversation

jassmith
Copy link
Contributor

No description provided.

import { GridCellKind, type LoadingCell } from "../internal/data-grid/data-grid-types.js";
import type { InternalCellRenderer } from "./cell-types.js";

function getRandomNumber(x: number, y: number): number {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would add a function comment saying it maps two number pseudo-randomly to the range [-1, 1] since that's not immediately clear.

@@ -313,6 +313,8 @@ export interface BaseGridCell {
/** @category Cells */
export interface LoadingCell extends BaseGridCell {
readonly kind: GridCellKind.Loading;
readonly skeletonWidth?: number;
readonly skeletonVariability?: number;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think instead of skeletonVariability, skeletonWidth should either be a static number or a dynamic (col: number, row: number) => number, so it can left up to developer to be pseudo-random or deterministic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callback seems not needed as you get that information inside getCellContent. The variability is just there to make it easier to achieve semi-organic skeletons without writing your own randomizer. I just didn't want it to be the obvious fallback that people use Math.random() which is rather slow.

}

const hpad = theme.cellHorizontalPadding;
const rectHeight = 18;
Copy link
Collaborator

@LukasMasuch LukasMasuch Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the 18 here based on the current defaults for line height & font size? In that case, could it be calculated from whatever is defined in the theme?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There wasn't a good option I could think of really. Using the cell height - 2*cellVerticalPadding is probably the most consistent method, but it is likely to look bad for some people. The only other things I could think to do were to make it configurable as a theme param, make it configurable as a cell param, or to make it parse the font param (which is a really bad idea).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've attempting to strike a better balance in the recent commit

packages/core/src/cells/loading-cell.tsx Show resolved Hide resolved
Copy link
Collaborator

@LukasMasuch LukasMasuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@jassmith jassmith merged commit 1a651b8 into 6.0.0 Dec 28, 2023
6 checks passed
@jassmith jassmith deleted the jason/loading-skeleton branch December 28, 2023 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants