Skip to content

Instantly share code, notes, and snippets.

View realtomaszkula's full-sized avatar

Tomasz Kula realtomaszkula

View GitHub Profile
const scroll$ = fromEvent(window, 'scroll').pipe(
throttleTime(10),
map(() => window.pageYOffset),
pairwise(),
map(([y1, y2]): Direction => (y2 < y1 ? Direction.Up : Direction.Down)),
distinctUntilChanged(),
share()
);
const scrollUp$ = scroll$.pipe(
const scroll$ = fromEvent(window, 'scroll').pipe(
throttleTime(10),
map(() => window.pageYOffset),
pairwise(),
map(([y1, y2]): Direction => (y2 < y1 ? Direction.Up : Direction.Down)),
distinctUntilChanged(),
);
enum Direction {
Up = 'Up',
Down = 'Down'
}
const scroll$ = fromEvent(window, 'scroll').pipe(
throttleTime(10),
map(() => window.pageYOffset),
pairwise(),
map(([y1, y2]): Direction => (y2 < y1 ? Direction.Up : Direction.Down)),
const scroll$ = fromEvent(window, 'scroll').pipe(
throttleTime(10),
map(() => window.pageYOffset),
);
@Component({
selector: 'app-sticky-header',
template: `<ng-content></ng-content>`,
styles: [
`
:host {
position: fixed;
top: 0;
width: 100%;
}
enum VisibilityState {
Visible = 'visible',
Hidden = 'hidden'
}
enum Direction {
Up = 'Up',
Down = 'Down'
}
export interface Theme {
primary: string;
accent: string;
}
@Component({
selector: 'app-root',
template: `
<app-card></app-card>
@Component({
selector: 'app-root',
template: `
<app-card></app-card>
<button (click)="theme = indigoPinkTheme">Indigo Pink</button>
<button (click)="theme = pinkBlueGrayTheme">Pink BlueGray</button>
<button (click)="theme = deepPurpleAmberTheme">Deep Purple Amber</button>
<button (click)="theme = randomTheme()">?</button>
`,
@Component({
selector: 'app-root',
template: `<app-card></app-card>`,
})
export class AppComponent {
// ...
randomTheme(): Theme {
const primary = this.randomHex();
const accent = this.randomHex();
@Component({
selector: 'app-root',
template: `<app-card></app-card>`,
})
export class AppComponent {
// ...
@HostBinding('style')
get style() {
return this.sanitizer.bypassSecurityTrustStyle(