This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(highlight): implement hover highlight (#476)
* refactor(highlight): implement tests for the hightlight component * refactor(highlight): hightlight area implementation * refactor(highlight): implement resize factory * fix(highlight): include hightlight update method * feat(highlight-hover): test implementation of the hightlight hover * feat(highlight): include eventhandler in store * feat(highlight): implementation of the highlight component * feat(highlight): highlight event handler * feat(highlight): finalize highlight component * perf: reduce highlight indicator state to id in preview
- Loading branch information
1 parent
b56e942
commit feb5304
Showing
14 changed files
with
3,678 additions
and
3,443 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,56 @@ | ||
import { HighlightArea } from './highlight-area'; | ||
|
||
describe('Highlight Hover', () => { | ||
const highlightArea = new HighlightArea(); | ||
// tslint:disable:no-any | ||
const node: any = { | ||
getBoundingClientRect: jest.fn(() => ({ | ||
top: 100, | ||
right: 100, | ||
bottom: 100, | ||
left: 100, | ||
width: 100, | ||
height: 100, | ||
x: 100, | ||
y: 100 | ||
})), | ||
parentElement: true | ||
}; | ||
|
||
test('default values should be 0', () => { | ||
expect(highlightArea).toEqual( | ||
expect.objectContaining({ | ||
top: 100, | ||
right: 100, | ||
bottom: 100, | ||
left: 100, | ||
width: 100, | ||
height: 100 | ||
}) | ||
); | ||
}); | ||
|
||
test('values have been updated', () => { | ||
highlightArea.setSize(node); | ||
expect(highlightArea).toEqual( | ||
expect.objectContaining({ | ||
top: 100, | ||
right: 100, | ||
bottom: 100, | ||
left: 100, | ||
width: 100, | ||
height: 100 | ||
}) | ||
); | ||
}); | ||
|
||
test('hover should be visible', () => { | ||
highlightArea.show(); | ||
expect(highlightArea).toEqual(expect.objectContaining({ opacity: 1 })); | ||
}); | ||
|
||
test('hover should be hidden', () => { | ||
highlightArea.hide(); | ||
expect(highlightArea).toEqual(expect.objectContaining({ opacity: 0 })); | ||
}); | ||
}); |
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,48 @@ | ||
import * as MobX from 'mobx'; | ||
|
||
export class HighlightArea { | ||
@MobX.observable public bottom: number = 0; | ||
@MobX.observable public height: number = 0; | ||
|
||
@MobX.observable public isVisible: boolean = false; | ||
@MobX.observable public left: number = 0; | ||
@MobX.observable public node: Element; | ||
@MobX.observable public opacity: number = 0; | ||
@MobX.observable public right: number = 0; | ||
@MobX.observable public top: number = 0; | ||
@MobX.observable public width: number = 0; | ||
|
||
@MobX.action | ||
public hide(): void { | ||
this.opacity = 0; | ||
this.isVisible = false; | ||
} | ||
|
||
@MobX.action | ||
public setSize(element: Element): void | Element { | ||
if (element.parentElement) { | ||
const clientRect: ClientRect = element.getBoundingClientRect(); | ||
this.bottom = clientRect.bottom; | ||
this.height = clientRect.height; | ||
this.left = clientRect.left + window.scrollX; | ||
this.right = clientRect.right; | ||
this.top = clientRect.top + window.scrollY; | ||
this.width = clientRect.width; | ||
this.node = element; | ||
return this.node; | ||
} | ||
} | ||
|
||
@MobX.action | ||
public show(): void { | ||
this.opacity = 1; | ||
this.isVisible = true; | ||
} | ||
|
||
@MobX.action | ||
public update(): void { | ||
if (this.node) { | ||
this.setSize(this.node); | ||
} | ||
} | ||
} |
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,56 @@ | ||
import { HighlightHover } from './highlight-hover'; | ||
|
||
describe('Highlight Hover', () => { | ||
const highlightHover = new HighlightHover(); | ||
// tslint:disable:no-any | ||
const node: any = { | ||
getBoundingClientRect: jest.fn(() => ({ | ||
bottom: 20, | ||
height: 20, | ||
left: 20, | ||
right: 20, | ||
top: 20, | ||
width: 20 | ||
})), | ||
opacity: 0, | ||
parentElement: true | ||
}; | ||
|
||
test('default values should be 0', () => { | ||
expect(highlightHover).toEqual( | ||
expect.objectContaining({ | ||
bottom: 0, | ||
height: 0, | ||
left: 0, | ||
right: 0, | ||
top: 0, | ||
width: 0, | ||
opacity: 0 | ||
}) | ||
); | ||
}); | ||
|
||
test('values have been updated', () => { | ||
highlightHover.setSize(node); | ||
expect(highlightHover).toEqual( | ||
expect.objectContaining({ | ||
bottom: 20, | ||
height: 20, | ||
left: 20, | ||
right: 20, | ||
top: 20, | ||
width: 20 | ||
}) | ||
); | ||
}); | ||
|
||
test('hover should be visible', () => { | ||
highlightHover.show(); | ||
expect(highlightHover).toEqual(expect.objectContaining({ opacity: 1 })); | ||
}); | ||
|
||
test('hover should be hidden', () => { | ||
highlightHover.hide(); | ||
expect(highlightHover).toEqual(expect.objectContaining({ opacity: 0 })); | ||
}); | ||
}); |
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,35 @@ | ||
import * as MobX from 'mobx'; | ||
|
||
export class HighlightHover { | ||
@MobX.observable public bottom: number = 0; | ||
@MobX.observable public height: number = 0; | ||
|
||
@MobX.observable public left: number = 0; | ||
@MobX.observable public opacity: number = 0; | ||
@MobX.observable public right: number = 0; | ||
@MobX.observable public top: number = 0; | ||
@MobX.observable public width: number = 0; | ||
|
||
@MobX.action | ||
public hide(): void { | ||
this.opacity = 0; | ||
} | ||
|
||
@MobX.action | ||
public setSize(node: Element): void { | ||
if (node.parentElement) { | ||
const clientRect: ClientRect = node.getBoundingClientRect(); | ||
this.bottom = clientRect.bottom; | ||
this.height = clientRect.height; | ||
this.left = clientRect.left + window.screenX; | ||
this.right = clientRect.right; | ||
this.top = clientRect.top + window.screenY; | ||
this.width = clientRect.width; | ||
} | ||
} | ||
|
||
@MobX.action | ||
public show(): void { | ||
this.opacity = 1; | ||
} | ||
} |
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
Oops, something went wrong.