Skip to content

Commit d0d86c7

Browse files
committed
Improve component props docs
1 parent f84477e commit d0d86c7

33 files changed

+407
-2059
lines changed

lib/components/grid/types.ts

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export type GridProps<
4040
* Additional props to be passed to the cell-rendering component.
4141
* Grid will automatically re-render cells when values in this object change.
4242
*
43-
* ⚠️ This object must not contain either an `index` or `style` prop.
43+
* ⚠️ This object must not contain `ariaAttributes`, `index`, or `style` props.
4444
*/
4545
cellProps: ExcludeForbiddenKeys<CellProps>;
4646

@@ -96,7 +96,43 @@ export type GridProps<
9696
*
9797
* ⚠️ The `useGridRef` and `useGridCallbackRef` hooks are exported for convenience use in TypeScript projects.
9898
*/
99-
gridRef?: Ref<GridImperativeAPI>;
99+
gridRef?: Ref<{
100+
get element(): HTMLDivElement | null;
101+
102+
scrollToCell({
103+
behavior,
104+
columnAlign,
105+
columnIndex,
106+
rowAlign,
107+
rowIndex
108+
}: {
109+
behavior?: "auto" | "instant" | "smooth";
110+
columnAlign?: "auto" | "center" | "end" | "smart" | "start";
111+
columnIndex: number;
112+
rowAlign?: "auto" | "center" | "end" | "smart" | "start";
113+
rowIndex: number;
114+
}): void;
115+
116+
scrollToColumn({
117+
align,
118+
behavior,
119+
index
120+
}: {
121+
align?: "auto" | "center" | "end" | "smart" | "start";
122+
behavior?: "auto" | "instant" | "smooth";
123+
index: number;
124+
}): void;
125+
126+
scrollToRow({
127+
align,
128+
behavior,
129+
index
130+
}: {
131+
align?: "auto" | "center" | "end" | "smart" | "start";
132+
behavior?: "auto" | "instant" | "smooth";
133+
index: number;
134+
}): void;
135+
}>;
100136

101137
/**
102138
* Callback notified when the range of rendered cells changes.
@@ -167,55 +203,21 @@ export type CellComponent<CellProps extends object> =
167203
export type CellComponentProps<CellProps extends object = object> =
168204
ComponentProps<CellComponent<CellProps>>;
169205

206+
export type GridImperativeAPI<CellProps extends object> = NonNullable<
207+
GridProps<CellProps>["gridRef"]
208+
>;
209+
210+
export type OnCellsRendered = NonNullable<GridProps<object>["onCellsRendered"]>;
211+
170212
export type ScrollState = {
171213
prevScrollTop: number;
172214
scrollTop: number;
173215
};
174216

175-
export type OnCellsRendered = NonNullable<GridProps<object>["onCellsRendered"]>;
176-
177217
export type CachedBounds = Map<
178218
number,
179219
{
180220
height: number;
181221
scrollTop: number;
182222
}
183223
>;
184-
185-
export type GridImperativeAPI = {
186-
get element(): HTMLDivElement | null;
187-
188-
scrollToCell({
189-
behavior,
190-
columnAlign,
191-
columnIndex,
192-
rowAlign,
193-
rowIndex
194-
}: {
195-
behavior?: "auto" | "instant" | "smooth";
196-
columnAlign?: "auto" | "center" | "end" | "smart" | "start";
197-
columnIndex: number;
198-
rowAlign?: "auto" | "center" | "end" | "smart" | "start";
199-
rowIndex: number;
200-
}): void;
201-
202-
scrollToColumn({
203-
align,
204-
behavior,
205-
index
206-
}: {
207-
align?: "auto" | "center" | "end" | "smart" | "start";
208-
behavior?: "auto" | "instant" | "smooth";
209-
index: number;
210-
}): void;
211-
212-
scrollToRow({
213-
align,
214-
behavior,
215-
index
216-
}: {
217-
align?: "auto" | "center" | "end" | "smart" | "start";
218-
behavior?: "auto" | "instant" | "smooth";
219-
index: number;
220-
}): void;
221-
};

lib/components/list/types.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,32 @@ export type ListProps<
4747
*
4848
* ⚠️ The `useListRef` and `useListCallbackRef` hooks are exported for convenience use in TypeScript projects.
4949
*/
50-
listRef?: Ref<ListImperativeAPI>;
50+
listRef?: Ref<{
51+
/**
52+
* Get root HTMLElement for List or null if it is not mounted.
53+
*
54+
* @return HTMLDivElement | null
55+
*/
56+
get element(): HTMLDivElement | null;
57+
58+
/**
59+
* Scroll to the specified row.
60+
*/
61+
scrollToRow(config: {
62+
/**
63+
* How to align the row within the list.
64+
*/
65+
align?: "auto" | "center" | "end" | "smart" | "start";
66+
/**
67+
* Scrolling behavior.
68+
*/
69+
behavior?: "auto" | "instant" | "smooth";
70+
/**
71+
* Index of row to scroll to.
72+
*/
73+
index: number;
74+
}): void;
75+
}>;
5176

5277
/**
5378
* Callback notified when the List's outermost HTMLElement resizes.
@@ -117,7 +142,7 @@ export type ListProps<
117142
* Additional props to be passed to the row-rendering component.
118143
* List will automatically re-render rows when values in this object change.
119144
*
120-
* ⚠️ This object must not contain either an `index` or `style` prop.
145+
* ⚠️ This object must not contain `ariaAttributes`, `index`, or `style` props.
121146
*/
122147
rowProps: ExcludeForbiddenKeys<RowProps>;
123148

@@ -144,24 +169,14 @@ export type RowComponentProps<RowProps extends object = object> =
144169

145170
export type OnRowsRendered = NonNullable<ListProps<object>["onRowsRendered"]>;
146171

172+
export type ListImperativeAPI<RowProps extends object> = NonNullable<
173+
ListProps<RowProps>["listRef"]
174+
>;
175+
147176
export type CachedBounds = Map<
148177
number,
149178
{
150179
height: number;
151180
scrollTop: number;
152181
}
153182
>;
154-
155-
export type ListImperativeAPI = {
156-
get element(): HTMLDivElement | null;
157-
158-
scrollToRow({
159-
align,
160-
behavior,
161-
index
162-
}: {
163-
align?: "auto" | "center" | "end" | "smart" | "start";
164-
behavior?: "auto" | "instant" | "smooth";
165-
index: number;
166-
}): void;
167-
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
"build:docs": "TARGET=docs vite build",
2525
"build:lib": "TARGET=lib vite build",
2626
"compile": "pnpm run compile:code-snippets && pnpm run compile:docs",
27-
"compile:code-snippets": "node --loader ts-node/esm ./scripts/code-snippets/run.ts",
28-
"compile:docs": "node --loader ts-node/esm ./scripts/docs/run.ts",
27+
"compile:code-snippets": "node --loader ts-node/esm ./scripts/compile-code-snippets.ts",
28+
"compile:docs": "node --loader ts-node/esm ./scripts/compile-docs.ts",
2929
"lint": "eslint .",
3030
"prerelease": "rm -rf dist && pnpm run build:lib",
3131
"prettier": "prettier --write \"**/*.{css,html,js,json,jsx,ts,tsx}\"",

public/generated/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/generated/code-snippets/GridImperativeAPIjson

Lines changed: 3 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)