-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsvg.component.ts
More file actions
35 lines (31 loc) · 1.21 KB
/
svg.component.ts
File metadata and controls
35 lines (31 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { ChangeDetectionStrategy, Component, computed, inject, input } from '@angular/core'
import { Logger } from '@shiftcode/logger'
import { LoggerService } from '@shiftcode/ngx-core'
import { SvgBaseDirective } from './svg-base.directive'
/**
* Standalone SvgComponent to display svg inline.
*
* - Specify the url input to load an SVG icon from a URL.
* The SVG content is directly inlined as a child of the <sc-svg> component,
* so that CSS styles can easily be applied to it.
* The URL is loaded via Angular's {@link HttpClient}, it must be on the same domain as the page or its
* server must be configured to allow cross-domain requests.
* @example
* <sc-svg url="assets/arrow.svg" />
*/
@Component({
selector: 'sc-svg',
template: '<ng-content />',
standalone: true,
styleUrls: ['./svg.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SvgComponent extends SvgBaseDirective {
readonly url = input.required<string>()
readonly attrs = input<Record<string, string>>({})
protected readonly logger: Logger = inject(LoggerService).getInstance('SvgComponent')
protected readonly data = computed(() => ({
url: this.url(),
attrs: this.attrs(),
}))
}