AnyRoad / react-json-view-lite

Lightweight Json view component for React
155 stars 14 forks source link

Improve empty objects and empty arrays #28

Closed AndyOGo closed 3 weeks ago

AndyOGo commented 3 weeks ago

First thank you for this component, I really like it.

I noticed that empty objects and empty arrays:


Workaround:

They can be already automatically collapsed with a custom shouldExpandNode callback, but still the three dots indicate that there might be more to show.

import { type Props } from "react-json-view-lite";

const allExpandedExceptEmpty: Props["shouldExpandNode"] = (level, value) => {
  if (value && typeof value === "object") {
    if (Array.isArray(value)) {
      return !!value.length;
    }

    const keys = Object.keys(value);
    return !!keys.length;
  }

  return true;
}
AnyRoad commented 3 weeks ago

Thank you for the bug report and PR! :)

.punctuation-base + .punctuation-base {
  margin-left: -5px;
}

This part might cause some issues with backward compatibility for the projects using custom styles. But it seems like minor issue, I've tried to remove this part and it looks good enough for the default styles. So I think notice in release notes will be enough.

AnyRoad commented 3 weeks ago

Just realised that it also fixes the ] , part which is clearly a bug, so no need to add anything to the release notes :)

AndyOGo commented 3 weeks ago

thx @AnyRoad

Yeah, first I was undecided whether to use the CSS + next sibling combinator or add a new class name like .punctuation-empty.

What would you prefer?

AnyRoad commented 2 weeks ago

thx @AnyRoad

Yeah, first I was undecided whether to use the CSS + next sibling combinator or add a new class name like .punctuation-empty.

What would you prefer?

I think the CSS + next sibling combinator solution is good enough. Thanks!