Skip to content

Commit 083a2a8

Browse files
YousefEDniklaskors
andauthored
add first docs (#271)
* add first docs * update docs * Add demo links to demos.md * Apply suggestions from code review Co-authored-by: Niklas Kors <[email protected]> * fix markdown import * change text Co-authored-by: Niklas Kors <[email protected]>
1 parent 115bb6f commit 083a2a8

File tree

16 files changed

+441
-15
lines changed

16 files changed

+441
-15
lines changed

docs/README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,32 @@
1-
_placeholder_
1+
# Welcome to TypeCell Notebooks
2+
3+
Hi there 👋 ! Welcome to the community preview of TypeCell, an experimental _live notebook programming_ environment for the web.
4+
5+
This guide should help you to get started, and learn more about the ins & outs.
6+
7+
## Tutorial
8+
9+
Complete the tutorial to get familiar with TypeCell:
10+
11+
» [Interactive introduction](/docs/interactive-introduction.md)
12+
13+
## Reference manual
14+
15+
We've written about the main functionality of TypeCell in the [manual](/docs/manual):
16+
17+
- [Notebooks and cells](/docs/manual/1.%20Notebooks%20and%20cells.md)
18+
- [TypeScript and exports](/docs/manual/2.%20TypeScript%20and%20exports.md)
19+
- [Reactive variables](/docs/manual/3.%20Reactive%20variables.md)
20+
- [Working with user input](/docs/manual/4.%20Inputs.md)
21+
- [Imports & NPM](/docs/manual/5.%20Imports%20and%20NPM.md)
22+
- [Collaboration](/docs/manual/6.%20Collaboration.md)
23+
24+
## Demos
25+
26+
Another good way to learn is to check out some notebooks from our community:
27+
28+
» [View demo notebooks](/docs/demos.md)
29+
30+
# Feedback ❤️
31+
32+
As always, we'd love to hear your thoughts and see your experiments, so [come and say hi on Discord](https://discord.gg/TcJ9TRC3SV) as well.

docs/demos.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Demos
2+
3+
To showcase some of TypeCell's features, explore these demos from our community:
4+
5+
- [Create an interactive map with Leaflet](/@niklas/maps)
6+
- [Interactive character counter using Vega Lite](/@yousef/character-counter)
7+
- [Visualize weather data with two React chart libraries](/@yousef/charts)
8+
- [Explore TypeCell's reactivity with the help of time](/@niklas/time)
9+
- [Connect React file uploader with an API](/@niklas/api)
10+
- [Working with a CSV dataset](/@niklas/csv)
11+
12+
## Built something exciting?
13+
14+
Let us know [on discord](https://discord.gg/TcJ9TRC3SV) if you'd like to feature your own demo on this page!

docs/examples/sub/README.md

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

docs/examples/sub/test.md

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

docs/manual/1. Notebooks and cells.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Notebooks and Cells
2+
3+
The page you're looking at is called a *notebook*.
4+
It's basically an interactive document that mixes *code* and *text* (documentation).
5+
6+
## Creating and reordering cells
7+
8+
When you hover over a cell, click the `+` sign to insert a new cell above or below.
9+
10+
To reorder a cell, hover next to it (try it out on the left of this text), and simply drag and drop the cell.
11+
12+
To view the source code of a cell, hover over the cell and click the caret <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16" class="notebookCell-sideIcon" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Show / hide code</title><path fill-rule="evenodd" clip-rule="evenodd" d="M10.072 8.024L5.715 3.667l.618-.62L11 7.716v.618L6.333 13l-.618-.619 4.357-4.357z"></path></svg> on the top left.
13+
You'll notice the text you're reading now is written in Markdown.
14+
15+
## Cell types
16+
17+
TypeCell currently supports a number of languages. You can view / change the language of a cell in the bottom-right of the cell's editor.
18+
19+
### Markdown
20+
21+
Useful for writing text / documentation. Markdown cells are collapsed by default (code cells are expanded by default).
22+
23+
### CSS
24+
25+
Use CSS to easily style the output of other cells (those written in Markdown or TypeScript).
26+
27+
28+
```css
29+
.redText {
30+
color: red;
31+
}
32+
33+
```
34+
35+
<div class="redText">This text is red, styled by the CSS cell above.</div>
36+
37+
### TypeScript / JavaScript
38+
39+
40+
```typescript
41+
export let message = "This is a TypeScript cell";
42+
43+
```
44+
45+
TypeScript cells execute automatically as you type.Try editing the`message` above.
46+
47+
You've learned the basics! Continue to learn more about writing code using TypeScript cells.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# TypeScript and exports
2+
3+
TypeScript cells are the main way to write code in TypeCell Notebooks.
4+
5+
You'll get all the benefits of the [Monaco Editor](https://microsoft.github.io/monaco-editor/) while writing code, the same editor that powers VS Code!
6+
7+
Note that TypeScript code still executes, even if there are type errors.
8+
This allows you to quickly write and test code, but still get hints about possible bugs.
9+
10+
<small>Note that this means that any <strong>JavaScript</strong> code works in TypeCell as well (i.e.: you don't <em>need</em> to type everything if you don't want to).</small>
11+
12+
In the example below, you'll notice that we get an error because we assign a `number` to a `string` variable, but the code still executes regardless.
13+
14+
15+
```typescript
16+
export let message = "hello";
17+
message = 4;
18+
19+
```
20+
21+
## Exports
22+
23+
You can export variables from your code, and they'll show up as *output* of the cell. Above, we've exported a single `message` variable.
24+
25+
You can also export multiple variables from a cell, and the _inspector_ will help you to view the output:
26+
27+
28+
```typescript
29+
export let firstVariable = "Hello world";
30+
export let vehicle = {
31+
color: "red",
32+
wheels: 4,
33+
};
34+
35+
```
36+
37+
### DOM Elements
38+
39+
You can create and export DOM Elements to display them directly:
40+
41+
```typescript
42+
export let element = document.createElement("button");
43+
element.innerText = "This is a button. Click me!";
44+
element.onclick = () => window.alert("Hello!");
45+
46+
```
47+
48+
### React / JSX
49+
50+
Think direct DOM manipulation is a little too old school for you? TypeCell supports React & JSX to make your life easier:
51+
52+
```typescript
53+
export let reactElement = (
54+
<button onClick={() => window.alert("Hello from React!")}>
55+
This is a React Button
56+
</button>
57+
);
58+
59+
```
60+
61+
## The `default` export
62+
63+
You use a `default` export to indicate which variable should be displayed in the output.
64+
65+
The following cell exports 2 variables, but only one is displayed in the output:
66+
67+
```typescript
68+
export let myNum = 42;
69+
70+
export default <div>The number is: {myNum}</div>;
71+
72+
```
73+
74+
Now you might ask; what's the use of exporting `myNum` if you don't see it in the output?
75+
76+
This is because exported variables can be reused across cells and notebooks; one of most powerful features of TypeCell!
77+
78+
Continue to learn more about exported variables and Reactivity.

docs/manual/3. Reactive variables.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Reactive variables
2+
3+
This is where things get interesting! Your code can reference variables exported by other cells.
4+
5+
Cells in TypeCell Notebooks (re)evaluate when:
6+
7+
* The code of the cell changes (i.e.: you're editing the code)
8+
* A variable the cell depends upon updates
9+
10+
## The `$` variable
11+
12+
Exports of cells are available under the `$` variable. Have a look at the example below, and change the `name` variable to your own name. Notice how the greeting in the cell below updates automatically.
13+
14+
15+
```typescript
16+
export let name = "Anonymous coder";
17+
18+
```
19+
20+
```typescript
21+
export let greeting = (
22+
<div>
23+
Hello, <strong>{$.name}</strong>!
24+
</div>
25+
);
26+
27+
```
28+
29+
<small>Tip: type `$.` in a TypeScript cell, and the editor (Intellisense) will display a list of all exported variables you can reference.</small>
30+
31+
## Interactive Tutorial
32+
33+
The Reactive model of TypeCell is quite powerful. If you haven't already, follow the [interactive introduction](/docs/interactive-introduction.md) or have a look at the [demos](/docs/demos.md) to get some hands-on experience.
34+

docs/manual/4. Inputs.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Working with user inputs
2+
3+
In your notebook, you'll often want the viewer to be able to control input variables, without changing code.
4+
5+
Of course, you can create input elements using HTML / React. For example, like this:
6+
7+
8+
```typescript
9+
export let textVariable = "Default text";
10+
export default (
11+
<input
12+
type="text"
13+
onChange={(e) => ($.textVariable = e.target.value)}
14+
defaultValue={textVariable}
15+
/>
16+
);
17+
18+
```
19+
20+
```typescript
21+
export default $.textVariable;
22+
23+
```
24+
25+
26+
## Using `typecell.Input`
27+
28+
As the pattern above is quite common, we've created an easy **shorthand** for this that supports different kind of input types:
29+
30+
### Text input
31+
32+
```typescript
33+
// The second parameter (default) is optional
34+
export let text1 = typecell.Input(<input type="text" />, "default text");
35+
36+
```
37+
38+
```typescript
39+
// You can also use a <textarea> element. By setting the default to $views.text1,
40+
// we bind it to the same $.text1 variable
41+
export let textarea1 = typecell.Input(<textarea />, $views.text1);
42+
43+
```
44+
45+
```typescript
46+
export let length = $.text1.length;
47+
48+
```
49+
50+
### Radio buttons and checkboxes
51+
52+
```typescript
53+
// Test two Radio inputs part of the same group
54+
55+
export let color = typecell.Input(<input type="radio" value="red" />);
56+
export let color2 = typecell.Input(<input type="radio" value="green" />, color);
57+
58+
export default (
59+
<div>
60+
<label>{color} Red</label>
61+
<label>{color2} Green</label>
62+
</div>
63+
);
64+
65+
```
66+
67+
```typescript
68+
// Check radio output
69+
export default (
70+
<div style={{ color: $.color, fontWeight: $.bold }}>
71+
Change the color of this text by selecting a radio button
72+
</div>
73+
);
74+
75+
```
76+
77+
```typescript
78+
export let bold = typecell.Input(<input type="checkbox" value="bold" />);
79+
80+
export default (
81+
<div>
82+
<label>{bold} Bold</label>
83+
</div>
84+
);
85+
86+
```
87+
88+
```typescript
89+
export default $.bold;
90+
91+
```
92+
93+
### Selects and Dropdowns
94+
95+
```typescript
96+
// Select with "multiple" attribute
97+
export let selectMultiple = typecell.Input(
98+
<select multiple>
99+
<option value="first">First option</option>
100+
<option value="second">Second option</option>
101+
</select>
102+
);
103+
104+
```
105+
106+
```typescript
107+
// Check select output
108+
export default $.selectMultiple;
109+
```
110+
111+
```typescript
112+
// Select without "multiple" attribute
113+
export let select = typecell.Input(
114+
<select>
115+
<option value="first">First option</option>
116+
<option value="second">Second option</option>
117+
</select>,
118+
"first"
119+
);
120+
121+
```
122+
123+
```typescript
124+
// Check select output
125+
export default $.select;
126+
127+
```
128+
129+
### Numbers & Ranges
130+
131+
You can user _number_ and _range_ input types to allow the user to enter numbers. Make sure to explicitly pass `<number>` to guide the type system that the edited variable is a number.
132+
133+
134+
```typescript
135+
export let num = typecell.Input<number>(<input type="number" />);
136+
137+
```
138+
139+
```typescript
140+
export default $.num;
141+
```
142+
143+
```typescript
144+
export let range = typecell.Input<number>(
145+
<input type="range" min="20" max="100" />
146+
);
147+
148+
```
149+
150+
```typescript
151+
// check value of range
152+
export default $.range;
153+
```

0 commit comments

Comments
 (0)