Skip to content

Commit bc3a60f

Browse files
committed
feat(scroll-top): add support for icon customisation
1 parent f3ea9a8 commit bc3a60f

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

apps/docs/src/app/app.component.html

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113

114114
<div class="mt-2">
115115
<router-outlet />
116+
<flowbite-scroll-top />
116117
</div>
117118

118119
<ng-template #footerContent>

apps/docs/src/app/app.component.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from 'flowbite-angular/navbar';
1515
import { FlowbiteRouterLinkDirective } from 'flowbite-angular/router-link';
1616
import { FlowbiteRouterLinkActiveDirective } from 'flowbite-angular/router-link-active';
17+
import { ScrollTopComponent } from 'flowbite-angular/scroll-top';
1718

1819
import { Location } from '@angular/common';
1920
import { Component, computed, inject } from '@angular/core';
@@ -44,6 +45,7 @@ import {
4445
FlowbiteRouterLinkDirective,
4546
FlowbiteRouterLinkActiveDirective,
4647
BadgeComponent,
48+
ScrollTopComponent,
4749
],
4850
selector: 'flowbite-root',
4951
templateUrl: './app.component.html',

libs/flowbite-angular/scroll-top/scroll-top.component.ts

+24-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { BaseComponent } from 'flowbite-angular';
1111
import { IconComponent, IconRegistry } from 'flowbite-angular/icon';
1212
import { CHEVRON_UP_SVG_ICON } from 'flowbite-angular/utils';
1313

14-
import type { OnInit } from '@angular/core';
14+
import { NgTemplateOutlet } from '@angular/common';
15+
import type { OnInit, TemplateRef } from '@angular/core';
1516
import {
1617
ChangeDetectionStrategy,
1718
Component,
@@ -31,6 +32,10 @@ export const FLOWBITE_SCROLL_TOP_POSITION_DEFAULT_VALUE = new InjectionToken<
3132
keyof ScrollTopPositions
3233
>('FLOWBITE_SCROLL_TOP_POSITION_DEFAULT_VALUE');
3334

35+
export const FLOWBITE_SCROLL_TOP_ICON_DEFAULT_VALUE = new InjectionToken<
36+
TemplateRef<unknown> | undefined
37+
>('FLOWBITE_SCROLL_TOP_ICON_DEFAULT_VALUE');
38+
3439
export const FLOWBITE_SCROLL_TOP_CUSTOM_STYLE_DEFAULT_VALUE = new InjectionToken<
3540
DeepPartial<ScrollTopTheme>
3641
>('FLOWBITE_SCROLL_TOP_CUSTOM_STYLE_DEFAULT_VALUE');
@@ -44,6 +49,10 @@ export const scrollTopDefaultValueProvider = makeEnvironmentProviders([
4449
provide: FLOWBITE_SCROLL_TOP_POSITION_DEFAULT_VALUE,
4550
useValue: 'bottom-right',
4651
},
52+
{
53+
provide: FLOWBITE_SCROLL_TOP_ICON_DEFAULT_VALUE,
54+
useValue: undefined,
55+
},
4756
{
4857
provide: FLOWBITE_SCROLL_TOP_CUSTOM_STYLE_DEFAULT_VALUE,
4958
useValue: {},
@@ -56,10 +65,16 @@ export const scrollTopDefaultValueProvider = makeEnvironmentProviders([
5665
@Component({
5766
selector: 'flowbite-scroll-top',
5867
standalone: true,
59-
imports: [IconComponent],
60-
template: `<flowbite-icon
61-
svgIcon="flowbite-angular:chevron-up"
62-
class="w-5 h-5" />`,
68+
imports: [IconComponent, NgTemplateOutlet],
69+
template: `
70+
@if (icon()) {
71+
<ng-container [ngTemplateOutlet]="icon()!" />
72+
} @else {
73+
<flowbite-icon
74+
svgIcon="flowbite-angular:chevron-up"
75+
class="w-5 h-5" />
76+
}
77+
`,
6378
host: {
6479
'(click)': 'onClick()',
6580
},
@@ -93,6 +108,10 @@ export class ScrollTopComponent extends BaseComponent<ScrollTopClass> implements
93108
* @default bottom-right
94109
*/
95110
public position = model(inject(FLOWBITE_SCROLL_TOP_POSITION_DEFAULT_VALUE));
111+
/**
112+
* Set the scroll top icon
113+
*/
114+
public icon = model(inject(FLOWBITE_SCROLL_TOP_ICON_DEFAULT_VALUE));
96115
/**
97116
* Set the custom style for this scroll top
98117
*/

0 commit comments

Comments
 (0)