-
Notifications
You must be signed in to change notification settings - Fork 149
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
30 changed files
with
790 additions
and
140 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
17 changes: 17 additions & 0 deletions
17
packages/fuselage-hooks/docs/fuselage-hooks.getpositionstyle.md
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,17 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@rocket.chat/fuselage-hooks](./fuselage-hooks.md) > [getPositionStyle](./fuselage-hooks.getpositionstyle.md) | ||
|
||
## getPositionStyle variable | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
getPositionStyle: ({ placement, container, targetBoundaries, variantStore, target }: { | ||
placement: Placements; | ||
target: DOMRect; | ||
container: DOMRect; | ||
targetBoundaries: Boundaries; | ||
variantStore: VariantBoundaries; | ||
}) => PositionStyle | null | ||
``` |
15 changes: 15 additions & 0 deletions
15
packages/fuselage-hooks/docs/fuselage-hooks.gettargetboundaries.md
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 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@rocket.chat/fuselage-hooks](./fuselage-hooks.md) > [getTargetBoundaries](./fuselage-hooks.gettargetboundaries.md) | ||
|
||
## getTargetBoundaries variable | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
getTargetBoundaries: ({ referenceBox, target, margin }: { | ||
referenceBox: DOMRect; | ||
target: DOMRect; | ||
margin?: number; | ||
}) => Boundaries | ||
``` |
14 changes: 14 additions & 0 deletions
14
packages/fuselage-hooks/docs/fuselage-hooks.getvariantboundaries.md
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,14 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@rocket.chat/fuselage-hooks](./fuselage-hooks.md) > [getVariantBoundaries](./fuselage-hooks.getvariantboundaries.md) | ||
|
||
## getVariantBoundaries variable | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
getVariantBoundaries: ({ referenceBox, target }: { | ||
referenceBox: DOMRect; | ||
target: DOMRect; | ||
}) => VariantBoundaries | ||
``` |
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,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@rocket.chat/fuselage-hooks](./fuselage-hooks.md) > [Placements](./fuselage-hooks.placements.md) | ||
|
||
## Placements type | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare type Placements = 'top-start' | 'top-middle' | 'top-end' | 'bottom-start' | 'bottom-middle' | 'bottom-end' | 'left-start' | 'left-middle' | 'left-end' | 'right-start' | 'right-middle' | 'right-end' | Positions; | ||
``` |
16 changes: 16 additions & 0 deletions
16
packages/fuselage-hooks/docs/fuselage-hooks.positionfliporder.md
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,16 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@rocket.chat/fuselage-hooks](./fuselage-hooks.md) > [PositionFlipOrder](./fuselage-hooks.positionfliporder.md) | ||
|
||
## PositionFlipOrder type | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare type PositionFlipOrder = { | ||
top: string; | ||
right: string; | ||
bottom: string; | ||
left: string; | ||
}; | ||
``` |
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,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@rocket.chat/fuselage-hooks](./fuselage-hooks.md) > [Positions](./fuselage-hooks.positions.md) | ||
|
||
## Positions type | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare type Positions = 'top' | 'left' | 'bottom' | 'right'; | ||
``` |
16 changes: 16 additions & 0 deletions
16
packages/fuselage-hooks/docs/fuselage-hooks.postionoptions.md
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,16 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@rocket.chat/fuselage-hooks](./fuselage-hooks.md) > [PostionOptions](./fuselage-hooks.postionoptions.md) | ||
|
||
## PostionOptions type | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare type PostionOptions = { | ||
margin?: number; | ||
container?: Element; | ||
placement?: Placements; | ||
watch?: boolean; | ||
}; | ||
``` |
13 changes: 13 additions & 0 deletions
13
packages/fuselage-hooks/docs/fuselage-hooks.useposition.md
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,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@rocket.chat/fuselage-hooks](./fuselage-hooks.md) > [usePosition](./fuselage-hooks.useposition.md) | ||
|
||
## usePosition variable | ||
|
||
Hook to deal with sessionStorage | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
usePosition: (reference: Element, targetEl: Element, options: PostionOptions) => PositionStyle | null | ||
``` |
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,176 @@ | ||
import { getPositionStyle, getTargetBoundaries, getVariantBoundaries } from './usePosition'; | ||
// TODO: add tests targeting the hook itself | ||
|
||
const container = { | ||
bottom: 1000, | ||
height: 1000, | ||
left: 0, | ||
right: 1024, | ||
top: 0, | ||
width: 1024, | ||
x: 0, | ||
y: 0, | ||
} as DOMRect; | ||
|
||
const referenceBox = { | ||
bottom: 300, | ||
height: 100, | ||
left: 0, | ||
right: 100, | ||
top: 200, | ||
width: 100, | ||
x: 0, | ||
y: 200, | ||
} as DOMRect; | ||
|
||
const target = { | ||
bottom: 50, | ||
height: 50, | ||
left: 0, | ||
right: 50, | ||
top: 0, | ||
width: 50, | ||
x: 0, | ||
y: 0, | ||
} as DOMRect; | ||
|
||
describe('usePosition hook', () => { | ||
describe('getTargetBoundaries', () => { | ||
it('...', () => { | ||
const targetBoundaries = getTargetBoundaries({ referenceBox, target }); | ||
expect(targetBoundaries.t).toEqual(150); | ||
expect(targetBoundaries.b).toEqual(300); | ||
expect(targetBoundaries.r).toEqual(100); | ||
expect(targetBoundaries.l).toEqual(-50); | ||
}); | ||
}); | ||
describe('getPositionStyle function', () => { | ||
it('returns a style for placement bottom-start', () => { | ||
const targetBoundaries = getTargetBoundaries({ referenceBox, target }); | ||
const variantStore = getVariantBoundaries({ referenceBox, target }); | ||
const style = getPositionStyle({ placement: 'bottom-start', container, targetBoundaries, variantStore, target }); | ||
expect(style.left).toEqual('0px'); | ||
expect(style.top).toEqual('300px'); | ||
}); | ||
it('returns a style for placement bottom-start if the element height does not fit', () => { | ||
const targetBoundaries = getTargetBoundaries({ referenceBox, target }); | ||
const variantStore = getVariantBoundaries({ referenceBox, target }); | ||
const style = getPositionStyle({ placement: 'bottom-start', | ||
container: { | ||
...container, | ||
bottom: 300, | ||
height: 300, | ||
}, | ||
targetBoundaries, | ||
variantStore, | ||
target }); | ||
expect(style.left).toEqual('0px'); | ||
expect(style.top).toEqual('150px'); | ||
}); | ||
|
||
it('returns a style for placement bottom-middle', () => { | ||
const targetBoundaries = getTargetBoundaries({ referenceBox, target }); | ||
|
||
const variantStore = getVariantBoundaries({ referenceBox, target }); | ||
|
||
const style = getPositionStyle({ placement: 'bottom-middle', container, targetBoundaries, variantStore, target }); | ||
|
||
expect(style.left).toEqual('25px'); | ||
expect(style.top).toEqual('300px'); | ||
}); | ||
it('returns a style for placement bottom-middle if the element height does not fit', () => { | ||
const targetBoundaries = getTargetBoundaries({ referenceBox, target }); | ||
const variantStore = getVariantBoundaries({ referenceBox, target }); | ||
const style = getPositionStyle({ placement: 'bottom-middle', | ||
container: { | ||
...container, | ||
bottom: 300, | ||
height: 300, | ||
}, | ||
targetBoundaries, | ||
variantStore, | ||
target }); | ||
expect(style.left).toEqual('25px'); | ||
expect(style.top).toEqual('150px'); | ||
}); | ||
|
||
it('returns a style for placement bottom-end', () => { | ||
const targetBoundaries = getTargetBoundaries({ referenceBox, target }); | ||
|
||
const variantStore = getVariantBoundaries({ referenceBox, target }); | ||
|
||
const style = getPositionStyle({ placement: 'bottom-end', container, targetBoundaries, variantStore, target }); | ||
|
||
expect(style.left).toEqual('50px'); | ||
expect(style.top).toEqual('300px'); | ||
}); | ||
it('returns a style for placement bottom-end if the element height does not fit', () => { | ||
const targetBoundaries = getTargetBoundaries({ referenceBox, target }); | ||
const variantStore = getVariantBoundaries({ referenceBox, target }); | ||
const style = getPositionStyle({ placement: 'bottom-end', | ||
container: { | ||
...container, | ||
bottom: 300, | ||
height: 300, | ||
}, | ||
targetBoundaries, | ||
variantStore, | ||
target }); | ||
expect(style.left).toEqual('50px'); | ||
expect(style.top).toEqual('150px'); | ||
}); | ||
|
||
|
||
it('returns a style for placement top-start', () => { | ||
const targetBoundaries = getTargetBoundaries({ referenceBox, target }); | ||
const variantStore = getVariantBoundaries({ referenceBox, target }); | ||
const style = getPositionStyle({ placement: 'top-start', container, targetBoundaries, variantStore, target }); | ||
expect(style.left).toEqual('0px'); | ||
expect(style.top).toEqual('150px'); | ||
}); | ||
it('returns a style for placement top-start if the element height does not fit', () => { | ||
const box = { ...referenceBox, top: 10, y: 10, bottom: 110 }; | ||
const targetBoundaries = getTargetBoundaries({ referenceBox: box, target }); | ||
const variantStore = getVariantBoundaries({ referenceBox: box, target }); | ||
const style = getPositionStyle({ placement: 'top-start', container, targetBoundaries, variantStore, target }); | ||
expect(style.left).toEqual('0px'); | ||
expect(style.top).toEqual('110px'); | ||
}); | ||
it('returns a style for placement top-middle', () => { | ||
const targetBoundaries = getTargetBoundaries({ referenceBox, target }); | ||
|
||
const variantStore = getVariantBoundaries({ referenceBox, target }); | ||
|
||
const style = getPositionStyle({ placement: 'top-middle', container, targetBoundaries, variantStore, target }); | ||
|
||
expect(style.left).toEqual('25px'); | ||
expect(style.top).toEqual('150px'); | ||
}); | ||
it('returns a style for placement top-middle if the element height does not fit', () => { | ||
const box = { ...referenceBox, top: 10, y: 10, bottom: 110 }; | ||
const targetBoundaries = getTargetBoundaries({ referenceBox: box, target }); | ||
const variantStore = getVariantBoundaries({ referenceBox: box, target }); | ||
const style = getPositionStyle({ placement: 'top-middle', container, targetBoundaries, variantStore, target }); | ||
expect(style.left).toEqual('25px'); | ||
expect(style.top).toEqual('110px'); | ||
}); | ||
it('returns a style for placement top-end', () => { | ||
const targetBoundaries = getTargetBoundaries({ referenceBox, target }); | ||
|
||
const variantStore = getVariantBoundaries({ referenceBox, target }); | ||
|
||
const style = getPositionStyle({ placement: 'top-end', container, targetBoundaries, variantStore, target }); | ||
|
||
expect(style.left).toEqual('50px'); | ||
expect(style.top).toEqual('150px'); | ||
}); | ||
it('returns a style for placement top-end if the element height does not fit', () => { | ||
const box = { ...referenceBox, top: 10, y: 10, bottom: 110 }; | ||
const targetBoundaries = getTargetBoundaries({ referenceBox: box, target }); | ||
const variantStore = getVariantBoundaries({ referenceBox: box, target }); | ||
const style = getPositionStyle({ placement: 'top-end', container, targetBoundaries, variantStore, target }); | ||
expect(style.left).toEqual('50px'); | ||
expect(style.top).toEqual('110px'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.