Skip to content

Commit 9d72e32

Browse files
authored
Merge pull request #197 from statelyai/davidkpiano/v5-types
Add types and tweak styles
2 parents e4880b9 + 9580041 commit 9d72e32

File tree

13 files changed

+323
-60
lines changed

13 files changed

+323
-60
lines changed

src/css/custom.css

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222

2323
html,
2424
body {
25+
background-color: var(--st-background);
2526
font-weight: var(--ifm-font-weight-normal);
2627
letter-spacing: -0.011rem;
27-
line-height: 1.45;
28+
line-height: 1.625;
2829
-webkit-font-smoothing: antialiased;
2930
-moz-osx-font-smoothing: grayscale;
3031
}
@@ -116,7 +117,7 @@ body {
116117
--st-violet-50: #fcecff;
117118

118119
/* Gray */
119-
--st-gray-900: #151618;
120+
--st-gray-900: #15151d;
120121
--st-gray-850: #212226;
121122
--st-gray-825: #27282a;
122123
--st-gray-800: #2d2e34;
@@ -159,6 +160,7 @@ body {
159160
--ifm-link-decoration: underline;
160161
--docusaurus-highlighted-code-line-bg: var(--st-code-highlight-background);
161162
--ifm-heading-vertical-rhythm-bottom: 0.75;
163+
--ifm-footer-background-color: var(--st-background);
162164
--ifm-code-background: var(--st-code-highlight-background);
163165
--ifm-code-border-radius: 0.25em;
164166
--ifm-code-font-size: 95%;
@@ -301,7 +303,7 @@ body {
301303
/* tables */
302304
--ifm-table-border-color: var(--st-layout-border);
303305
--ifm-table-background: transparent;
304-
--ifm-table-stripe-background: rgba(255,255,255,0.6);
306+
--ifm-table-stripe-background: rgba(255, 255, 255, 0.6);
305307
--ifm-footer-link-color: var(--st-footer-link);
306308

307309
/* admonitions */
@@ -331,7 +333,7 @@ html[data-theme='light'] body {
331333
--st-text: var(--st-gray-800);
332334
--st-text-highlight: var(--st-gray-900);
333335
--st-heading: var(--st-text-highlight);
334-
--st-text-secondary: var(--st-gray-700);
336+
--st-text-secondary: var(--st-gray-600);
335337
--st-text-link: var(--st-blue-700);
336338
--st-text-link-hover: var(--st-blue-600);
337339
--st-text-link-active: var(--st-blue-500);
@@ -349,7 +351,7 @@ html[data-theme='light'] body {
349351
--st-layout-border-secondary: var(--st-gray-100);
350352
--st-code-border: var(--st-gray-100);
351353
--st-codeblock-background: white;
352-
--st-code-inline-border: 1px solid rgba(191, 227, 248, .5);/* var(--st-blue-100) in rgba */
354+
--st-code-inline-border: 1px solid rgba(191, 227, 248, 0.5); /* var(--st-blue-100) in rgba */
353355
--st-code-inline-text: var(--st-blue-900);
354356
--st-code-highlight-background: var(--st-blue-50);
355357
--st-copy-button-background: var(--st-blue-100);
@@ -413,7 +415,7 @@ html[data-theme='light'] body {
413415
--docsearch-footer-shadow: inset 0 1px 0 0 var(--st-gray-100);
414416

415417
/* tags */
416-
--st-tag-border: 1px solid rgba(191, 227, 248, .5);/* var(--st-blue-100) in rgba */
418+
--st-tag-border: 1px solid rgba(191, 227, 248, 0.5); /* var(--st-blue-100) in rgba */
417419
--st-tag-text: var(--st-blue-900);
418420
--st-tag-background: var(--st-blue-50);
419421

@@ -481,9 +483,9 @@ html[data-theme='dark'] body {
481483
--st-background: var(--st-gray-900);
482484
--st-background-secondary: var(--st-gray-800);
483485
--st-text: var(--st-gray-200);
484-
--st-text-highlight: var(--st-gray-100);
486+
--st-text-highlight: var(--st-gray-50);
485487
--st-heading: var(--st-text-highlight);
486-
--st-text-secondary: var(--st-gray-200);
488+
--st-text-secondary: var(--st-gray-400);
487489
--st-text-link: var(--st-blue-300);
488490
--st-text-link-hover: var(--st-blue-400);
489491
--st-text-link-active: var(--st-blue-400);
@@ -502,7 +504,7 @@ html[data-theme='dark'] body {
502504
--st-layout-border: var(--st-gray-700);
503505
--st-layout-border-secondary: var(--st-gray-700);
504506
--st-code-border: transparent;
505-
--st-code-inline-border: 1px solid rgba(69, 71, 79, .5);/* var(--st-gray-700) in rgba */
507+
--st-code-inline-border: 1px solid rgba(69, 71, 79, 0.5); /* var(--st-gray-700) in rgba */
506508
--st-code-inline-text: var(--st-gray-50);
507509
--st-codeblock-background: var(--st-gray-850);
508510
--st-code-highlight-background: var(--st-gray-800);
@@ -600,7 +602,7 @@ html[data-theme='dark'] body {
600602
--ifm-toc-link-color: var(--st-text);
601603

602604
/* tags */
603-
--st-tag-border: 1px solid rgba(69, 71, 79, .5);/* var(--st-gray-700) in rgba */
605+
--st-tag-border: 1px solid rgba(69, 71, 79, 0.5); /* var(--st-gray-700) in rgba */
604606
--st-tag-text: var(--st-gray-50);
605607
--st-tag-background: var(--st-gray-850);
606608
}
@@ -659,40 +661,44 @@ h1 {
659661
letter-spacing: -0.022rem;
660662
}
661663

662-
.markdown h1, .markdown h1:first-child, .index-page h1 {
663-
--ifm-h1-font-size: 2.5rem;
664+
.markdown h1,
665+
.markdown h1:first-child,
666+
.index-page h1 {
667+
--ifm-h1-font-size: 2rem;
664668
}
665669

666670
h2 {
667671
letter-spacing: -0.021rem;
668672
}
669673

670674
.markdown h2 {
671-
--ifm-h2-font-size: 2rem;
675+
margin-top: 4.5rem;
676+
--ifm-h2-font-size: 1.5rem;
672677
}
673678

674679
h3 {
675680
letter-spacing: -0.019rem;
681+
color: var(--st-heading);
676682
}
677683

678684
.markdown h3 {
679-
--ifm-h3-font-size: 1.5rem;
685+
--ifm-h3-font-size: 1.25rem;
680686
}
681687

682688
.markdown > h3 {
683-
margin-top: calc(var(--ifm-h2-vertical-rhythm-top) * var(--ifm-leading));
689+
margin-top: 3rem;
684690
}
685691

686692
.markdown h4 {
687-
--ifm-h4-font-size: 1.2rem;
693+
--ifm-h4-font-size: 1.15rem;
688694
}
689695

690696
.markdown h5 {
691-
--ifm-h5-font-size: 1.1rem;
697+
--ifm-h5-font-size: 1.05rem;
692698
}
693699

694700
.markdown h6 {
695-
--ifm-h6-font-size: 1.05rem;
701+
--ifm-h6-font-size: 1rem;
696702
}
697703

698704
.text--bold,
@@ -781,7 +787,10 @@ a:hover {
781787
article,
782788
.index-page {
783789
margin: 0 auto;
784-
max-width: 66ch;
790+
max-width: 50rem;
791+
/* adds more side padding when in column mode */
792+
padding-left: 0.5rem;
793+
padding-right: 0.5rem;
785794
}
786795

787796
/* back to top button */
@@ -846,6 +855,12 @@ code {
846855
margin-right: 0;
847856
width: calc(var(--doc-sidebar-width) - 1rem);
848857
}
858+
article,
859+
.index-page {
860+
/* Let content breath some on a not-huge screen */
861+
padding-left: 2rem;
862+
padding-right: 2rem;
863+
}
849864
}
850865

851866
.navbar__logo {
@@ -1077,7 +1092,7 @@ html [class*='toggleButton'] {
10771092

10781093
.theme-doc-sidebar-item-category-level-1 a,
10791094
.theme-doc-sidebar-item-link-level-1 a {
1080-
color: var(--st-text);
1095+
color: var(--st-text-highlight);
10811096
}
10821097

10831098
.theme-doc-sidebar-item-category-level-1 ul li,
@@ -1109,6 +1124,7 @@ html [class*='toggleButton'] {
11091124
}
11101125
.menu__list-item:last-of-type {
11111126
padding-bottom: 0.2rem;
1127+
margin-bottom: 0.5rem;
11121128
}
11131129
.menu__list-item:not(:first-child) {
11141130
margin-top: 0;
@@ -1160,6 +1176,7 @@ html [class*='toggleButton'] {
11601176
.menu__list-item .menu__list-item .menu__link--active {
11611177
border-left: 3px solid var(--st-menu-link-border-active);
11621178
margin-left: -4px;
1179+
color: var(--st-text-highlight);
11631180
}
11641181

11651182
.menu__list-item .menu__list-item .menu__list-item .menu__link--active {
@@ -1364,7 +1381,8 @@ details summary::before {
13641381
--ifm-alert-border-color: var(--st-tip-accent);
13651382
}
13661383

1367-
.alert--danger, .alert--breakingchange {
1384+
.alert--danger,
1385+
.alert--breakingchange {
13681386
--ifm-alert-background-color: var(--st-danger-background);
13691387
--ifm-alert-background-color-highlight: var(--st-danger-accent);
13701388
--ifm-alert-foreground-color: var(--st-danger-text);
@@ -1379,7 +1397,8 @@ details summary::before {
13791397
--ifm-alert-border-color: var(--st-warning-accent);
13801398
}
13811399

1382-
.alert--v4compatible, .alert--breakingchange {
1400+
.alert--v4compatible,
1401+
.alert--breakingchange {
13831402
width: fit-content;
13841403
padding: 4px 10px;
13851404
}
@@ -1570,8 +1589,8 @@ a.link-box strong {
15701589
text-align: center;
15711590
}
15721591

1573-
.docs-intro h2:hover a.hash-link {
1574-
opacity: 0;
1592+
.docs-intro h2:hover a.hash-link {
1593+
opacity: 0;
15751594
}
15761595

15771596
.docs-intro-studio,

versioned_docs/version-5/actions.mdx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,29 @@ const countMachine = createMachine({
524524

525525
## TypeScript
526526

527-
_Coming soon_
527+
You can strongly type the `actions` of your machine in the `types.actions` property of the machine config.
528+
529+
```ts
530+
const machine = createMachine({
531+
types: {} as {
532+
// highlight-start
533+
actions:
534+
| {
535+
type: 'track';
536+
params: {
537+
response: string;
538+
};
539+
}
540+
| { type: 'increment'; params: { value: number } };
541+
// highlight-end
542+
},
543+
// ...
544+
entry: [
545+
{ type: 'track', params: { response: 'good' } },
546+
{ type: 'increment', params: { value: 1 } },
547+
],
548+
});
549+
```
528550

529551
## Cheatsheet
530552

versioned_docs/version-5/actors.mdx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,39 @@ function Component(props: { actor?: AnyActorRef }) {
413413

414414
## TypeScript
415415

416-
_Coming soon_
416+
You can strongly type the `actors` of your machine in the `types.actors` property of the machine config.
417+
418+
```ts
419+
const fetcher = fromPromise(
420+
async ({ input }: { input: { userId: string } }) => {
421+
const user = await fetchUser(input.userId);
422+
423+
return user;
424+
},
425+
);
426+
427+
const machine = createMachine({
428+
types: {} as {
429+
// highlight-start
430+
actors: {
431+
src: 'fetchData'; // src name (inline behaviors ideally inferred)
432+
id: 'fetch1' | 'fetch2'; // possible ids (optional)
433+
logic: typeof fetcher;
434+
};
435+
// highlight-end
436+
},
437+
invoke: {
438+
src: 'fetchData', // strongly typed
439+
id: 'fetch2', // strongly typed
440+
onDone: {
441+
actions: ({ event }) => {
442+
event.output; // strongly typed as { result: string }
443+
},
444+
},
445+
input: { userId: '42' }, // strongly typed
446+
},
447+
});
448+
```
417449

418450
## Cheatsheet
419451

versioned_docs/version-5/context.mdx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,22 @@ feedbackActor.send({
151151

152152
## TypeScript
153153

154+
You can strongly type the `context` of your machine in the `types.context` property of the machine config.
155+
154156
```ts
155157
const machine = createMachine({
156-
schema: {} as {
158+
types: {} as {
159+
// highlight-start
157160
context: {
158161
feedback: string;
159162
rating: number;
160163
};
164+
// highlight-end
165+
},
166+
// Initial context
167+
context: {
168+
feedback: '',
169+
rating: 5,
161170
},
162171
entry: ({ context }) => {
163172
context.feedback; // string

versioned_docs/version-5/delayed-transitions.mdx

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ Delayed transitions have a default time interval of 500ms (0.5 seconds).
7272

7373
1. Select the event you want to replace with a delayed transition.
7474
1. Right-click the event to open the edit menu.
75-
2. From the **Event type** options, choose **After** to turn the event into a delayed transition.
75+
1. From the **Event type** options, choose **After** to turn the event into a delayed transition.
7676

7777
#### Using the transition Details panel
7878

7979
1. Open the transition <Info size={18} /> **Details** panel from the right tool menu.
8080
2. From the **Event type** dropdown menu, choose **After** to turn the event into a delayed transition.
8181

82-
#### Specify delay time
82+
#### Specify delay time
8383

8484
Your delay time interval will be displayed in a human-readable format on hover. For example, 15000ms will be displayed as 15 seconds.
8585

@@ -160,7 +160,36 @@ Delayed transition timers are canceled when the state is exited.
160160

161161
## TypeScript
162162

163-
_Coming soon_
163+
You can strongly type the `delays` of your machine in the `types.delays` property of the machine config.
164+
165+
```ts
166+
const machine = createMachine({
167+
types: {} as {
168+
// highlight-start
169+
delays: 'shortTimeout' | 'longTimeout' | 'eventually';
170+
// highlight-end
171+
// ...
172+
},
173+
// ...
174+
after: {
175+
// Autocompleted
176+
shortTimeout: {
177+
/* ... */
178+
},
179+
},
180+
on: {
181+
someEvent: {
182+
actions: raise(
183+
{ type: 'anotherEvent' },
184+
{
185+
// Autocompleted
186+
delay: 'eventually',
187+
},
188+
),
189+
},
190+
},
191+
});
192+
```
164193

165194
## Cheatsheet
166195

0 commit comments

Comments
 (0)