Skip to content

Commit 906f1a5

Browse files
authored
fix up storybook (#214)
* Fix storybook up a bit * Fix build
1 parent eb06922 commit 906f1a5

23 files changed

+2462
-58
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { STORY_RENDERED } from "@storybook/core-events";
2+
import { addons } from "@storybook/addons";
3+
4+
let hasExpanded = false;
5+
6+
addons.register("expand-all", api => {
7+
const emitter = addons.getChannel();
8+
9+
emitter.on(STORY_RENDERED, () => {
10+
if (!hasExpanded) {
11+
setTimeout(api.expandAll); // Calling on the next tick after storyRendered seems to work reliably.
12+
hasExpanded = true;
13+
}
14+
});
15+
});

.storybook/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require("path");
22

33
module.exports = {
44
stories: ["../**/*.stories.tsx"],
5-
addons: ["@storybook/addon-links", "@storybook/addon-controls"],
5+
addons: ["@storybook/addon-links", "@storybook/addon-controls", "./addons/expand-all/register.js"],
66
devtool: "source-map",
77
webpackFinal: async (config, { configType }) => {
88
config.module.rules.push({

.storybook/manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ addons.setConfig({
2020
initialActive: "sidebar",
2121
sidebar: {
2222
showRoots: true,
23-
collapsedRoots: ["Subcomponents"],
23+
collapsedRoots: ["Subcomponents", "TestCases"],
2424
},
2525
toolbar: {
2626
title: { hidden: false },

.storybook/preview.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { addParameters } from "@storybook/react";
33
addParameters({
44
options: {
55
showRoots: true,
6-
storySort: (a, b) => a[1].id.localeCompare(b[1].id, undefined, { numeric: true }),
6+
storySort: (a, b) => {
7+
return a[1].name.localeCompare(b[1].name, undefined, { numeric: true });
8+
},
79
},
810
});
911

1012
export const parameters = {
11-
layout: 'fullscreen',
12-
};
13+
layout: "fullscreen",
14+
};

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Data Grid is agnostic about the way you load/store/generate/mutate your data. Wh
115115

116116
**Does it do sorting, searching, and filtering?**
117117

118-
Search is included. You provide the trigger, we do the search. [Example](https://glideapps.github.io/glide-data-grid/?path=/story/dataeditor--built-in-search) in our storybook.
118+
Search is included. You provide the trigger, we do the search. [Example](https://glideapps.github.io/glide-data-grid/?path=/story/glide-data-grid-docs--search) in our storybook.
119119

120120
Filtering and sorting are something you would have to implement with your data source. There are hooks for adding column header menus if you want that.
121121

@@ -127,7 +127,7 @@ Yes!
127127

128128
**Can I render my own cells?**
129129

130-
Yes, but the renderer has to use HTML Canvas. [Simple example](https://glideapps.github.io/glide-data-grid/?path=/story/dataeditor--draw-custom-cells) in our Storybook.
130+
Yes, but the renderer has to use HTML Canvas. [Simple example](https://glideapps.github.io/glide-data-grid/?path=/story/glide-data-grid-dataeditor-demos--draw-custom-cells) in our Storybook.
131131

132132
**Why does Data Grid use HTML Canvas?**
133133

packages/cells/src/cell.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const SimpleThemeWrapper: React.FC = p => {
3434
};
3535

3636
export default {
37-
title: "Extra Cells",
37+
title: "Extra Packages/Cells",
3838

3939
decorators: [
4040
(Story: React.ComponentType) => (

packages/core/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Data Grid is agnostic about the way you load/store/generate/mutate your data. Wh
115115

116116
**Does it do sorting, searching, and filtering?**
117117

118-
Search is included. You provide the trigger, we do the search. [Example](https://glideapps.github.io/glide-data-grid/?path=/story/dataeditor--built-in-search) in our storybook.
118+
Search is included. You provide the trigger, we do the search. [Example](https://glideapps.github.io/glide-data-grid/?path=/story/glide-data-grid-docs--search) in our storybook.
119119

120120
Filtering and sorting are something you would have to implement with your data source. There are hooks for adding column header menus if you want that.
121121

@@ -127,7 +127,7 @@ Yes!
127127

128128
**Can I render my own cells?**
129129

130-
Yes, but the renderer has to use HTML Canvas. [Simple example](https://glideapps.github.io/glide-data-grid/?path=/story/dataeditor--draw-custom-cells) in our Storybook.
130+
Yes, but the renderer has to use HTML Canvas. [Simple example](https://glideapps.github.io/glide-data-grid/?path=/story/glide-data-grid-dataeditor-demos--draw-custom-cells) in our Storybook.
131131

132132
**Why does Data Grid use HTML Canvas?**
133133

packages/core/src/data-editor/data-editor-beautiful.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function lossyCopyData<T extends EditableGridCell>(source: EditableGridCell, tar
101101
}
102102

103103
export default {
104-
title: "DataEditor",
104+
title: "Glide-Data-Grid/DataEditor Demos",
105105

106106
decorators: [
107107
(Story: React.ComponentType) => (

packages/core/src/data-editor/data-editor-repros.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import DataEditorContainer from "../data-editor-container/data-grid-container";
1010
import styled from "styled-components";
1111

1212
export default {
13-
title: "DataEditor/TestCases/Bugs",
13+
title: "Tests/TestCases/Bugs",
1414

1515
decorators: [
1616
(fn: StoryFn<React.ReactElement | null>, context: StoryContext) => (

packages/core/src/data-editor/data-editor.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { DataEditor } from "./data-editor";
1717
import DataEditorContainer from "../data-editor-container/data-grid-container";
1818

1919
export default {
20-
title: "DataEditor/TestCases",
20+
title: "Tests/TestCases",
2121

2222
decorators: [
2323
(fn: StoryFn<React.ReactElement | null>, context: StoryContext) => (

packages/core/src/data-grid/data-grid-render.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,11 @@ function drawCells(
11491149
lastToken = undefined;
11501150
}
11511151

1152+
if (theme.textDark !== outerTheme.textDark) {
1153+
if (typeof lastToken === "function") lastToken({ ctx });
1154+
lastToken = undefined;
1155+
}
1156+
11521157
if (highlighted || rowDisabled) {
11531158
if (rowDisabled) {
11541159
fill = blend(theme.bgHeader, fill);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import * as React from "react";
2+
3+
import { SimpleThemeWrapper } from "../stories/story-utils";
4+
import { DocWrapper, Marked } from "./doc-wrapper";
5+
6+
export default {
7+
title: "Glide-Data-Grid/Docs",
8+
decorators: [
9+
(Story: React.ComponentType) => (
10+
<SimpleThemeWrapper>
11+
<Story />
12+
</SimpleThemeWrapper>
13+
),
14+
],
15+
};
16+
17+
export const FAQ: React.VFC = () => {
18+
return (
19+
<DocWrapper>
20+
<Marked>
21+
{`
22+
# FAQ
23+
24+
### Nothing shows up? It crashes when I edit a cell?
25+
26+
Please read the [Prerequisites section in the docs](https://github.com/glideapps/glide-data-grid/blob/main/packages/core/API.md).
27+
28+
### Does it work with screen readers and other a11y tools?
29+
30+
Yes. Unfortunately none of the primary developers are accessibility users so there are likely flaws in the implementation we are not aware of. Bug reports welcome!
31+
32+
### Does it support my data source?
33+
34+
Yes.
35+
36+
Data Grid is agnostic about the way you load/store/generate/mutate your data. What it requires is that you tell it which columns you have, how many rows, and to give it a function it can call to get the data for a cell in a specific row and column.
37+
38+
### Does it do sorting?
39+
40+
Yes through the [glide-data-grid-source](https://www.npmjs.com/package/@glideapps/glide-data-grid-source) package.
41+
42+
### Does it do search?
43+
44+
Yes, built in! There are examples in the storybook.
45+
46+
### Can it filter?
47+
48+
Nothing built in yet. It is planned for the \`glide-data-grid-source\`.
49+
50+
### Can it do frozen columns?
51+
52+
Yes
53+
54+
### Can I render my own cells?
55+
56+
Yes
57+
58+
`}
59+
</Marked>
60+
</DocWrapper>
61+
);
62+
};
63+
(FAQ as any).storyName = "00. FAQ";
64+
(FAQ as any).parameters = {
65+
options: {
66+
showPanel: false,
67+
},
68+
};

packages/core/src/docs/getting-started.stories.tsx renamed to packages/core/src/docs/01-getting-started.stories.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { SimpleThemeWrapper } from "../stories/story-utils";
77
import { DocWrapper, Highlight, Marked, Wrapper } from "./doc-wrapper";
88

99
export default {
10-
title: "Docs",
10+
title: "Glide-Data-Grid/Docs",
1111
decorators: [
1212
(Story: React.ComponentType) => (
1313
<SimpleThemeWrapper>
@@ -174,9 +174,7 @@ export const GettingStarted: React.VFC = () => {
174174
{`
175175
# Getting Started
176176
177-
> You can do this!
178-
179-
Let's build a very simply data grid, first we need some data. Let's start with something hard coded.`}
177+
Glide data grid is a powerful but flexible library requiring very few concepts required to get started. The grid will need data, columns, and a \`getCellContent\` callback to convert our data into cells on demand. Because the callback is used, there is no need to pre-format the data in any particular way, so long as it can be transformed into a cell. This example uses a flat array of objects.`}
180178
</Marked>
181179
<Highlight>
182180
{`
@@ -193,7 +191,7 @@ const data = [
193191
</Highlight>
194192
<Marked>
195193
{`
196-
We will also need some columns`}
194+
The columns of the data grid may contain many options, including icons, menus, theme overrides, however at their most basic they only require a \`title\` and an \`id\`. The id is technically optional but it is best not to omit it.`}
197195
</Marked>
198196
<Highlight>
199197
{`
@@ -219,9 +217,9 @@ const columns: GridColumn[] = [
219217
</Highlight>
220218
<Marked>
221219
{`
222-
Each of our columns will automatically size based on its contents. If we want to we can fix the size of some columns by setting the width parameter.
220+
Each column will automatically size based on its contents. If desired the sise of each column can be overridden by setting the width parameter.
223221
224-
Lastly we need a data fetch callback. This callback should be memoized using \`React.useCallback\` or be a static function.`}
222+
Finally the data grid requires a cell fetch callback. This callback should be memoized using \`React.useCallback\` or be a static function.`}
225223
</Marked>
226224
<Highlight>
227225
{`
@@ -242,7 +240,9 @@ const getContent = React.useCallback((cell: readonly [number, number]): GridCell
242240
</Highlight>
243241
<Marked>
244242
{`
245-
Ok let's put it all together!`}
243+
> Avoid excessive changes to the identity of the \`getCellContent\` callback as the grid will re-render from scratch every time it changes.
244+
245+
That is all the basic requirements put together. Because the grid is a self-contained scrollable region a container is provided for simple hard coded sizing. Reactive sizing is also possible but requires a bit of css ignored here.`}
246246
</Marked>
247247
<Highlight>
248248
{`
@@ -256,11 +256,9 @@ return <DataEditorContainer width={900} height={200}>
256256
</Wrapper>
257257
<Marked>
258258
{`
259-
Great job!
260-
261259
# Going further
262260
263-
There is so much more we can do. Just to list a few
261+
There is so much more that can be done:
264262
265263
- Header icons
266264
- Smooth scrolling
@@ -273,7 +271,7 @@ There is so much more we can do. Just to list a few
273271
- Search
274272
- Copy/paste support
275273
276-
Let's play with a few`}
274+
Here are a few to play with.`}
277275
</Marked>
278276
<label style={{ display: "block" }}>
279277
<input type="checkbox" checked={rowMarkers} onChange={e => setRowMarkers(e.target.checked)} /> Row
@@ -301,6 +299,7 @@ Let's play with a few`}
301299
</DocWrapper>
302300
);
303301
};
302+
(GettingStarted as any).storyName = "01. Getting Started";
304303
(GettingStarted as any).parameters = {
305304
options: {
306305
showPanel: false,

0 commit comments

Comments
 (0)