Skip to content

Commit 9d04180

Browse files
committed
feat: backtop support custom position
1 parent d7765e1 commit 9d04180

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

.changeset/tzfeng-handsome.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@alauda/ui": patch
3+
---
4+
5+
feat: backtop support custom position

src/back-top/back-top.component.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<div
22
class="aui-back-top"
3-
[class.show]="isDisplayed$ | async"
3+
[style.display]="display$ | async"
4+
[style.position]="'fixed'"
5+
[style]="position"
46
>
57
<button
68
aui-button="text"

src/back-top/back-top.component.scss

-8
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,14 @@
44
$block: 'aui-back-top';
55

66
.#{$block} {
7-
position: fixed;
8-
right: 12px;
9-
bottom: 12px;
107
@include flex-center;
118

129
height: use-var(inline-height-m);
1310
width: use-var(inline-height-m);
1411
border-radius: use-var(border-radius-m);
1512
overflow: hidden;
16-
visibility: hidden;
1713
cursor: pointer;
1814
@include popper-shadow;
1915

2016
background-color: use-rgb(n-10);
21-
22-
&.show {
23-
visibility: visible;
24-
}
2517
}

src/back-top/back-top.component.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
map,
1717
switchMap,
1818
throttleTime,
19+
startWith,
1920
} from 'rxjs';
2021

2122
type TargetType = Element | Window | string;
@@ -39,6 +40,14 @@ export class BackTopComponent {
3940
return this._visibilityHeight;
4041
}
4142

43+
@Input()
44+
position: {
45+
left?: string;
46+
right?: string;
47+
top?: string;
48+
bottom?: string;
49+
} = { right: '12px', bottom: '12px' };
50+
4251
@Input()
4352
set target(val: TargetType) {
4453
this._target = val;
@@ -63,7 +72,7 @@ export class BackTopComponent {
6372

6473
constructor(@Optional() private readonly cdkScrollable: CdkScrollable) {}
6574

66-
isDisplayed$ = combineLatest([
75+
display$ = combineLatest([
6776
this.target$$.asObservable().pipe(
6877
map(target => this.getTarget(target)),
6978
switchMap(target =>
@@ -77,6 +86,8 @@ export class BackTopComponent {
7786
this.visibilityHeight$$,
7887
]).pipe(
7988
map(([scrollTop, visibilityHeight]) => scrollTop >= visibilityHeight),
89+
map(visible => (visible ? 'flex' : 'none')),
90+
startWith('none'),
8091
distinctUntilChanged(),
8192
);
8293

stories/back-top/back-top.mdx

+5-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ import * as useSelector from './use-selector.stories';
4141

4242
## Backtop Inputs
4343

44-
| 名称 | 类型 | 默认值 | 描述 |
45-
| ---------------- | --------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------- |
46-
| visibilityHeight | number | 400 | 目标容器滚动到多高的距离,展示 backtop 按钮 |
47-
| target | Element \| Window \| string | - | 指定目标容器,可以指定 ElementRef,selector 来选择目标组件,不指定时优先选择外部的 cdkScrollable 组件,若没有则选择 window |
44+
| 名称 | 类型 | 默认值 | 描述 |
45+
| ---------------- | ------------------------------------------------------------------- | ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
46+
| visibilityHeight | number | 400 | 目标容器滚动到多高的距离,展示 backtop 按钮 |
47+
| position | \{ left?: string; right?: string; top?: string; bottom?: string; \} | \{ right: '12px', bottom: '12px' \} | 设置按钮在浏览器窗口中的位置 |
48+
| target | Element \| Window \| string | - | 指定目标容器,可以指定 ElementRef,selector 来选择目标组件,不指定时优先选择外部的 cdkScrollable 组件,若没有则选择 window |
4849

4950
## Backtop Outputs
5051

0 commit comments

Comments
 (0)