@@ -21,6 +21,7 @@ A Web Component to visualize JSON data in a tree view
2121 - [ Basic Usage] ( #basic-usage )
2222 - [ Load the JSON dynamically] ( #load-the-json-dynamically )
2323 - [ Basic interactions] ( #basic-interactions )
24+ - [ Custom renderer] ( #custom-renderer )
2425- [ Demo] ( #demo )
2526
2627## Installation
@@ -108,15 +109,19 @@ json-viewer {
108109 /* Background, font and indentation */
109110 --background-color : #2a2f3a ;
110111 --color : #f8f8f2 ;
111- --font-family : monaco, Consolas, ' Lucida Console ' , monospace ;
112+ --font-family : Nimbus Mono PS, Courier New , monospace ;
112113 --font-size : 1rem ;
114+ --line-height : 1.2rem ;
113115 --indent-size : 1.5em ;
114116 --indentguide-size : 1px ;
115117 --indentguide-style : solid ;
116118 --indentguide-color : #333 ;
117119 --indentguide-color-active : #666 ;
118120 --indentguide : var (--indentguide-size ) var (--indentguide-style ) var (--indentguide-color );
119121 --indentguide-active : var (--indentguide-size ) var (--indentguide-style ) var (--indentguide-color-active );
122+ --outline-color : #e0e4e5 ;
123+ --outline-width : 1px ;
124+ --outline-style : dotted ;
120125
121126 /* Types colors */
122127 --string-color : #a3eea0 ;
@@ -126,10 +131,10 @@ json-viewer {
126131 --property-color : #6fb3d2 ;
127132
128133 /* Collapsed node preview */
129- --preview-color : rgba ( 222 , 175 , 143 , 0.9 ) ;
134+ --preview-color : #deae8f ;
130135
131136 /* Search highlight color */
132- --highlight-color : #6fb3d2 ;
137+ --highlight-color : #c92a2a ;
133138}
134139```
135140
@@ -172,6 +177,46 @@ const searchIterator = viewer.search('value');
172177searchIterator .next ();
173178```
174179
180+ ### Custom renderer
181+ _ This is an experimental feature and it may change in the future_
182+
183+ The rendering of the values can be customized by defining a static method ` customRenderer ` in the custom element class.
184+ The function receives the value and the path of the node and it should return a HTML node or a Lit's ` TemplateResult ` object.
185+
186+ ``` js
187+ import { JsonViewer } from ' @alenaksu/json-viewer/JsonViewer.js' ;
188+
189+ customElements .define (
190+ ' json-viewer' ,
191+ class extends JsonViewer {
192+ static styles = [
193+ JsonViewer .styles ,
194+ css`
195+ a {
196+ color: white;
197+ text-decoration: underline;
198+ }
199+ `
200+ ];
201+
202+ static customRenderer (value , path ) {
203+ if (typeof value === ' string' ) {
204+ if (URL .canParse (value)) {
205+ return html ` <a href =" ${value}" target =" _blank" >${ value} </a >` ;
206+ } else if (Date .parse (value)) {
207+ return new Date (value).toLocaleString ();
208+ }
209+ } else if (typeof value === ' number' ) {
210+ return value .toFixed (2 );
211+ }
212+
213+ return super .customRenderer (value);
214+ }
215+ }
216+ );
217+
218+ ```
219+
175220## Demo
176221
177222The demo can also be run locally with
0 commit comments