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

[Feature Request] Customize the styling of the key value pair #223

Open
sarath-sasikumar opened this issue Sep 19, 2018 · 7 comments
Open

Comments

@sarath-sasikumar
Copy link

Great work on the package !!

I was having a use case, whereby it would be good if we could search the keys in the object and open the corresponding node.

I have managed to do that , using the shouldCollapse attribute but it would have been good if I could somehow highlight the node that I had searched for. Is there any way, we can style a particular node. The use case is not to change the theme but to somehow customize the style of the individual node.

@johnking
Copy link

Hi @sarath-sasikumar,

I have the same requirement, do you have any workaround yet?

thanks

@SourceCipher
Copy link

Same request goes from me. This component is okay but it lacks customisation.

Would be great if we could have the option how to render each item. For example having a method like renderItems which returns the value of each items in the json. Then you could compare each of them with lets say your search word and chose to render the item or not. And even better if we had a raw value and raw name data management for each row so we could render them the way we want (highlighting for search, making it bold etc).

@snailkn
Copy link

snailkn commented Sep 27, 2019

same requirement, is there any solution?

@acchaulk
Copy link

curious about this as well, would appreciate any workarounds people came up with

@nehagup
Copy link

nehagup commented Dec 10, 2021

Yea, my usecase is pretty much same. I want to customise some items style based on some conditions. This component is fine, lacks customization.

@Lingam8454
Copy link

Need same requirement, I have to highlight specific child JSON nodes. Any other solution?

@Ironolife
Copy link

Ironolife commented May 2, 2023

I wrote this workaround for a key I wanted to highlight. Very ugly, but does the job for me :/

// Hightlight value
useEffect(() => {
    const timeout = setTimeout(() => { // Timeout for the node to exist in DOM
        const target = Array.from(document.querySelectorAll('.react-json-view span.object-key'))
            .find((el) => el.textContent === 'keyToFind')
            ?.parentElement
            ?.parentElement
            ?.querySelector('div.variable-value .string-value');

        if (target && target.textContent) {
            (target as HTMLSpanElement).style.backgroundColor = '#16a34a';
            (target as HTMLSpanElement).style.color = '#ffffff';
            (target as HTMLSpanElement).style.padding = '4px';
            (target as HTMLSpanElement).style.fontWeight = '700';
        }
    }, 100);
    
    return () => clearTimeout(timeout);
}, [data]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants