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

Add onSelect feature from react-json-view #68

Open
Bushstar opened this issue Feb 17, 2025 · 3 comments
Open

Add onSelect feature from react-json-view #68

Bushstar opened this issue Feb 17, 2025 · 3 comments

Comments

@Bushstar
Copy link

react-json-view has the onSelect prop, it takes a function, clicking a value triggers that function.

@jaywcjlove
Copy link
Member

@Bushstar You can achieve a similar onSelect effect using the Row component:

<Row onClick={() => { }} />

@Bushstar
Copy link
Author

That would be great. Does this usage look correct?

const Row = JsonView.Row;

return (
    <JsonView
        value={data}
    >
        <Row onSelect={(params) => {
            console.log(params);
        }} />
    </JsonView>
);

@jaywcjlove
Copy link
Member

@Bushstar You can try running the example; it looks fine.

Supports certain partial customizations such as: `<Copied />`, `<CountInfo />`, `<CountInfoExtra />`, `<Ellipsis />`, `<KeyName />`, `<Row />`
```tsx mdx:preview
import React, { Fragment } from 'react';
import JsonView, { ValueQuote } from '@uiw/react-json-view';
const Copied = JsonView.Copied;
export default function Demo() {
return (
<JsonView
value={{
url: new URL('https://example.com?t=12'),
urlStr: "https://example.com",
github: "https://example.com",
}}
style={{
'--w-rjv-background-color': '#ffffff',
}}
>
<Copied
render={({ 'data-copied': copied, style, onClick, ...props }, { value }) => {
const styl = { whiteSpace: 'nowrap' }
if (copied) {
return <span style={{ ...style, ...styl }}>复制成功</span>
}
return <span style={{ ...style, ...styl }} onClick={onClick}>复制</span>
}}
/>
<JsonView.Url
render={(props, { type, value }) => {
if (type === 'type' && value instanceof URL) {
return <span />
}
if (type === 'value' && value instanceof URL) {
return (
<Fragment>
<a href={value.href} target="_blank" {...props}>
<ValueQuote />
{value.href}
<ValueQuote />
</a>
Open URL
</Fragment>
);
}
}}
/>
</JsonView>
)
}
```

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

2 participants