Skip to content

Commit 3a9a7e5

Browse files
committed
move logic out of template
1 parent 067d426 commit 3a9a7e5

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

projects/ngx-json-treeview/src/lib/ngx-json-treeview.component.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<section class="ngx-json-treeview">
22
@if (segments().length === 0) {
3-
@let sectionClass =
4-
['object', 'array'].includes(rootType())
5-
? 'punctuation'
6-
: 'segment-type-' + rootType();
7-
<div [class]="sectionClass">
3+
<div [class]="primativeSegmentClass()">
84
<span class="segment-primitive">
95
{{ asString() }}
106
</span>

projects/ngx-json-treeview/src/lib/ngx-json-treeview.component.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ $type-colors: (
110110
}
111111
}
112112
.segment-primitive {
113-
margin: 0px;
114-
padding: 0px;
113+
margin: 0;
114+
padding: 0;
115115
}
116116
// special cases that need highlighting
117117
.segment-type-null > .segment-primitive {

projects/ngx-json-treeview/src/lib/ngx-json-treeview.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ export class NgxJsonTreeviewComponent {
145145
asString = computed<string>(() =>
146146
JSON.stringify(this.json(), null, 2).trim()
147147
);
148+
primativeSegmentClass = computed<string>(() => {
149+
const type = this.rootType();
150+
if (['object', 'array'].includes(type)) {
151+
return 'punctuation';
152+
}
153+
return 'segment-type-' + type;
154+
});
148155

149156
isExpandable(segment: Segment) {
150157
return (

0 commit comments

Comments
 (0)