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

How to define RenderValueComponent while using vanilla-jsoneditor #375

Closed
1pone opened this issue Dec 21, 2023 · 13 comments
Closed

How to define RenderValueComponent while using vanilla-jsoneditor #375

1pone opened this issue Dec 21, 2023 · 13 comments
Labels
enhancement New feature or request

Comments

@1pone
Copy link
Contributor

1pone commented Dec 21, 2023

I'm using vanilla-jsoneditor in React, and i need use custom RenderValueComponent for onRenderValue.component to render value as password, like the ReadonlyPassword example shown in the project. But how can i define the RenderValueComponent without svelte?

@1pone
Copy link
Contributor Author

1pone commented Dec 22, 2023

Or can I submit a PR to add ReadonlyPassword export?

@josdejong
Copy link
Owner

I haven't tried out if/how you can use onRenderValue from an other framework like React, we have to do some experimentation there.

I like the idea of exporting ReadonlyPassword: it can be the first a collection of extra value render components. I think though that we should either rename it to something like HiddenValue, or improve on it: it was just a minimal example, and when you double click it to edit, you see all of the password in plain sight, that should remain hidden whilst typing.

@josdejong josdejong added the enhancement New feature or request label Dec 22, 2023
@AlexRMU
Copy link

AlexRMU commented Dec 22, 2023

I think you can do it like this (after #373).
Other frameworks will be able to create everything they need, and reactivity both inside and outside the component will be provided by runes.

@josdejong
Copy link
Owner

Do you mean defining an API like a Svelte action?

@AlexRMU
Copy link

AlexRMU commented Dec 22, 2023

Yes

@josdejong
Copy link
Owner

I think that makes sense indeed.

@josdejong
Copy link
Owner

I tried out using Svelte actions, it works like a charm, see #398

@josdejong
Copy link
Owner

I've finished and merged #398 (not yet published)

@josdejong
Copy link
Owner

#398 is now published in v0.21.5

@13832198312
Copy link

image Can you give me a specific example of how to customize a component

@josdejong
Copy link
Owner

Yes, see /examples/browser/custom_value_renderer.html

@13832198312
Copy link

13832198312 commented Jun 14, 2024

可以这样写自己的样式

onRenderValue={(props: any) => {
          const myRendererAction = {
            action: (node: any) => {
              const content = document.createElement('div')
              content.innerHTML = props.value
              node.classList.add('highlight')
              node.appendChild(content)
              return {
                update: (node: any) => {
                  // update the DOM
                },
                destroy: () => {
                  // cleanup the DOM
                },
              }
            },
            props,
          }
          return [myRendererAction]
        }
      }

@josdejong
Copy link
Owner

Can you please use English?

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

No branches or pull requests

4 participants