Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: minor glitch in markdown ast preview #65

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 30 additions & 25 deletions src/components/tree-entry.tsx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In tightly packed areas when we have more than 3 keys we might actually want to add ellipsis to the text?

before overflow ellipsis after overflow ellipsis
Screenshot 2024-10-04 at 12 15 17 PM Screenshot 2024-10-04 at 12 14 51 PM

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a minimum height and overflow scroll to avoid this issue.

Original file line number Diff line number Diff line change
Expand Up @@ -91,36 +91,41 @@ export const TreeEntry: FC<TreeEntryProperties> = ({ data, path }) => {
const [key, value] = data;
const [open, setOpen] = useState(false);
const Icon = open ? MinusSquareIcon : PlusSquareIcon;

const toggleOpen = () => setOpen(!open);
const isObject = typeof value === "object" && value !== null;
const isExpandable =
isObject &&
(Array.isArray(value)
? value.length > 0
: Object.keys(value).length > 0);
const values = renderValue(value);
const renderParts = values.map((part, partIndex) => (
<span
key={partIndex}
className={`${values.length === 1 ? "flex-1" : ""} ${partIndex ? "text-muted-foreground" : "text-primary"}`}
amareshsm marked this conversation as resolved.
Show resolved Hide resolved
>
{part}
</span>
));

return (
<>
<div className="flex items-center gap-3">
{(typeof value === "object" &&
Object.values(value ?? {}).length) ||
(Array.isArray(value) && value.length) ? (
<button
onClick={toggleOpen}
aria-label="Toggle"
type="button"
>
<Icon size={16} className="text-muted-foreground" />
</button>
) : (
<div className="w-4 h-4" />
)}
{key && <span>{key}</span>}
{renderValue(value).map((part, partIndex) => (
<span
key={partIndex}
className={
partIndex ? "text-muted-foreground" : "text-primary"
}
>
{part}
</span>
))}
<>
amareshsm marked this conversation as resolved.
Show resolved Hide resolved
{isExpandable ? (
<button
onClick={toggleOpen}
aria-label="Toggle"
type="button"
>
<Icon size={16} className="text-muted-foreground" />
</button>
) : (
<div className="w-4 h-4"></div>
)}
{key && <span className="flex-none">{key}</span>}
{renderParts}
</>
</div>
{open ? (
<SanitizeValue
Expand Down