-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
176 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
ElementRef, | ||
QueryList, | ||
ViewChildren, | ||
} from '@angular/core'; | ||
|
||
import { ContainerForResizableDirective } from '../../src/resizable/resizable.directive'; | ||
|
||
import { ResizableDirective } from '@alauda/ui'; | ||
|
||
@Component({ | ||
template: ` | ||
默认拖动容器为指令的宿主元素 | ||
<div style="display: flex; background: #ccc"> | ||
<div | ||
#resizable | ||
style="width: 100px; height: 100px; background: red;" | ||
auiResizable | ||
(resizeEnd)="resizeEndHandle($event, 0)" | ||
></div> | ||
<div style="width: 100px; height: 100px; background: yellow"></div> | ||
</div> | ||
但也可以通过 auiContainerForResizable 指定容器,例如在灰色 div 上加这个指令 | ||
<div | ||
style="display: flex; background: #ccc;" | ||
auiContainerForResizable | ||
> | ||
<div | ||
#resizable | ||
style="width: 100px; height: 100px; background: red;" | ||
auiResizable | ||
(resizeEnd)="resizeEndHandle($event, 1)" | ||
></div> | ||
<div style="width: 100px; height: 100px; background: yellow"></div> | ||
</div> | ||
你会发现你可以在更大的范围内进行拖动,因为 container | ||
变大了,默认可拖动区域是限定在 container 里的。 | ||
如果你想自定义拖动区域,可以通过设定 minWidth 和 maxWidth | ||
完成,除了支持常规的 number 也就是 XXpx 这种,也支持 | ||
XX%,百分比是相对于容器宽度的,例如下面设定最小60,最大80% | ||
<div | ||
style="display: flex; background: #ccc;" | ||
auiContainerForResizable | ||
> | ||
<div | ||
#resizable | ||
style="width: 100px; height: 100px; background: red;" | ||
auiResizable | ||
(resizeEnd)="resizeEndHandle($event, 2)" | ||
[minWidth]="60" | ||
maxWidth="80%" | ||
></div> | ||
<div style="width: 100px; height: 100px; background: yellow"></div> | ||
</div> | ||
是的,就这么简单,你要考虑的只有——怎么处理 resizeEnd 发出的拖动后的宽度。 | ||
`, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
imports: [ResizableDirective, ContainerForResizableDirective], | ||
styles: [ | ||
` | ||
@import '../../src/resizable/resizable'; | ||
`, | ||
], | ||
standalone: true, | ||
}) | ||
export default class BasicComponent { | ||
@ViewChildren('resizable') | ||
resizable: QueryList<ElementRef>; | ||
|
||
resizeEndHandle(width: number, idx: number) { | ||
this.resizable.get(idx).nativeElement.style.width = `${width}px`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Meta, StoryObj } from '@storybook/angular'; | ||
|
||
import BasicComponent from './basic.component'; | ||
|
||
const meta: Meta<BasicComponent> = { | ||
title: 'Example/Resizable', | ||
component: BasicComponent, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<BasicComponent>; | ||
|
||
export const Basic: Story = { | ||
name: 'Basic', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Canvas, Meta } from '@storybook/blocks'; | ||
|
||
import * as basic from './basic.stories'; | ||
|
||
<Meta title="Example/Resizable" /> | ||
|
||
# Resizable | ||
|
||
Resizable 指令提供了一种通过左右拖动来调整宽度的能力 | ||
|
||
## 使用 | ||
|
||
需要在使用时手动引入 resizable.scss | ||
|
||
``` | ||
@import 'node_modules/@alauda/ui/resizable/resizable'; | ||
``` | ||
|
||
<Canvas | ||
of={basic.Basic} | ||
meta={basic} | ||
/> | ||
|
||
## Inputs | ||
|
||
| 名称 | 类型 | 默认值 | 描述 | | ||
| -------- | ---------------- | ------ | --------------------------------------------- | | ||
| minWidth | string \| number | - | 限定拖动后的最小宽度,为%时以容器的宽度为基数 | | ||
| maxWidth | string \| number | - | 限定拖动后的最大宽度,为%时以容器的宽度为基数 | | ||
|
||
## Outputs | ||
|
||
| 名称 | 回调参数 | 描述 | | ||
| ----------- | ------------- | ---------------------- | | ||
| resizeStart | width: number | 开始调整宽度事件 | | ||
| resizing | width: number | 正在进行宽度调整的事件 | | ||
| resizeEnd | width: number | 调整宽度结束事件 | |