Customize section elements with Section and useSectionStore
mainThe Section component and useSectionStore hook allow you to provide custom configuration for the visual elements used within the JSON viewer (such as the ellipsis, key names, and row containers).
By wrapping your component tree in a Section provider, you can override the default styles and HTML tags for internal UI elements. You can then access these configurations using the useSectionStore hook.
Available Section Elements
When providing an initial state to the Section component, you can customize the following keys:
Copied: The element shown when a value is copied.CountInfo: The element displaying object size/info.CountInfoExtra: Additional info element.Ellipsis: The element used for truncated objects (e.g.,...).Row: The container for a single JSON line/row.KeyName: The element used to render object keys.
import { Section, useSectionStore } from './path-to-section';
const customInitial = {
Ellipsis: {
as: 'span',
style: { color: 'red' },
children: ' (more)'
},
// ... other elements
};
function App() {
return (
<Section initial={customInitial} dispatch={dispatch}>
<MyJsonViewer />
</Section>
);
}
// Inside a child component:
function MyJsonViewer() {
const section = useSectionStore();
// section.Ellipsis contains your custom config
}