Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

Commit

Permalink
Show the description property for both nodes and transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardo-forina committed Jan 24, 2022
1 parent 259fb02 commit 196e44d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-seas-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate-viz-app': minor
---

You can now visualize descriptions added directly to state nodes and transitions
6 changes: 4 additions & 2 deletions src/StateNodeViz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export const StateNodeViz: React.FC<{
return null;
}

const description = stateNode.description || stateNode.meta?.description;

return (
<div
data-viz="stateNodeGroup"
Expand Down Expand Up @@ -166,14 +168,14 @@ export const StateNodeViz: React.FC<{
})}
</div>
)}
{stateNode.meta?.description && (
{description && (
<div data-viz="stateNode-meta">
<ReactMarkdown
components={{
a: ({ node, ...props }) => <Link {...props} />,
}}
>
{stateNode.meta.description}
{description}
</ReactMarkdown>
</div>
)}
Expand Down
14 changes: 14 additions & 0 deletions src/TransitionViz.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,17 @@
}
padding: 0rem 0.5rem 0.5rem;
}

[data-viz='transition-description'] {
&:empty {
display: none;
}
border-top: 2px solid var(--chakra-colors-whiteAlpha-300);
padding: 0.5rem;
min-width: max-content;
font-size: var(--chakra-fontSizes-sm);
text-align: left;
> p {
max-width: 10rem;
}
}
5 changes: 5 additions & 0 deletions src/TransitionViz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ export const TransitionViz: React.FC<{
</div>
)}
</div>
{definition.description && (
<div data-viz="transition-description">
<p>{definition.description}</p>
</div>
)}
</button>
);
};

0 comments on commit 196e44d

Please sign in to comment.