Skip to content

Commit fe25ed8

Browse files
authored
feat(scroll-top): add support for icon customisation (#96)
## PR Checklist Please check if your PR fulfills the following requirements: <!--- [ ] Tests for the changes have been added (for bug fixes/features)--> - [ ] Docs have been added/updated (for bug fixes/features) ## PR Type What kind of change does this PR introduce? <!-- Please check the one that applies to this PR using "x". --> - [ ] Bugfix - [x] Feature - [ ] Code style update (formatting, local variables) - [ ] Refactoring (no functional changes, no API changes) - [ ] Build related changes - [ ] CI-related changes - [ ] Documentation content changes - [ ] Other... Please describe: ## Issue Number <!-- Bugs and features must be linked to an issue. --> Issue Number: #85 ## Does this PR introduce a breaking change? <!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. --> - [ ] Yes - [x] No ## Other information <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for dynamic icons in the scroll-to-top feature. - **Bug Fixes** - Ensured that existing functionality and layout remain unaffected by the new component integration. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents f3ea9a8 + 3e2b89c commit fe25ed8

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 28 additions & 5 deletions
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,8 +108,16 @@ 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+
* @default undefined
115+
*/
116+
public icon = model(inject(FLOWBITE_SCROLL_TOP_ICON_DEFAULT_VALUE));
96117
/**
97118
* Set the custom style for this scroll top
119+
*
120+
* @default {}
98121
*/
99122
public customStyle = model(inject(FLOWBITE_SCROLL_TOP_CUSTOM_STYLE_DEFAULT_VALUE));
100123
//#endregion

0 commit comments

Comments
 (0)