-
Notifications
You must be signed in to change notification settings - Fork 113
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
Proper method to disable ColorPicker and TimestampTag rendering #493
Comments
Hi, yes that is indeed the right way, though in your example you should also handle the case when a value is being edited. The It is quite verbose, though the gist of it boils down to the following. The only reason I specify all props individually is that the Svelte compiler gives warnings when passing an unknown prop to a component. function onRenderValue(props: RenderValueProps): RenderValueComponentDescription[] {
const renderers: RenderValueComponentDescription[] = []
if (!props.isEditing && isBoolean(props.value)) {
renderers.push({ component: BooleanToggle, props })
}
if (props.isEditing) {
renderers.push({ component: EditableValue, props })
}
if (!props.isEditing) {
renderers.push({ component: ReadonlyValue, props })
}
return renderers
} |
I'm working on a migration to Svelte 5, and it turns out that Svelte 5 doesn't warning against unused properties anymore, which is great for this very use case. See this commit: e640046 This simplifies the built-in implementation of export function renderValue(props: RenderValueProps): RenderValueComponentDescription[] {
const renderers: RenderValueComponentDescription[] = []
if (!props.isEditing && isBoolean(props.value)) {
renderers.push({ component: BooleanToggle, props })
}
if (!props.isEditing && isColor(props.value)) {
renderers.push({ component: ColorPicker, props })
}
if (props.isEditing) {
renderers.push({ component: EditableValue, props })
}
if (!props.isEditing) {
renderers.push({ component: ReadonlyValue, props })
}
if (!props.isEditing && isTimestamp(props.value)) {
renderers.push({ component: TimestampTag, props })
}
return renderers
} I'm really happy with that 🎉 |
Hi @josdejong, thanks for coming back to me.
Thats correct, in my case I'm using the json editor in read only mode as I just want to display some JSON data in a more user friendly way. I like your suggestion with the easy flags to disable a renderer.
I think it is also better for future updates, as users can benefit from bug fixes/improvements in the original As the detection magic is enabled by default, I guess it would be nice to have some more intuitive way to disable it. Honestly it took me awhile to realize that I really have to replace the entire How ever, maybe I have some rar edge case data which is why I had to disable the Timestamp and Color Picker in the first place. The Svelte 5 implementation you have mentioned looks nice and clean :) Thanks for your time, I appreciate this. |
Thanks for your input! I'll leave the function for now, and we can look into a helper function if there is enough need for it. I've added some more explanation in the docs: 8fded08 |
In the past, there was a
colorPicker: false
andtimestampTag: false
option. I don't find anything like this anymore.As workaround, I copied the default
renderValue
method and removed the ColorPicker and TimestampTag. If i understand the docs correct, that's the supposed way to achieve this?https://github.com/josdejong/svelte-jsoneditor/tree/96e4179871a18c42edbac25d3d62548ed7fe2aa7?tab=readme-ov-file#onrendervalue
Is this really the correct way to disable the colorpicker and Timestamp renderer?
The text was updated successfully, but these errors were encountered: