Skip to content

Instantly share code, notes, and snippets.

View theer1k's full-sized avatar
🏠
Working from home

Erik Henrique theer1k

🏠
Working from home
View GitHub Profile
@theer1k
theer1k / loading-spin.scss
Last active December 3, 2023 03:53
Loading spinner animation SCSS
.loading-spin {
height: 5rem;
width: 5rem;
border: 0.6rem solid green;
border-radius: 50%;
border-top-color: transparent;
animation: spin 0.6s linear infinite;
}
@keyframes spin {
@theer1k
theer1k / some.component.ts
Created August 11, 2023 11:36
Angular WithControlsFrom type safe form
import {
FormControl,
FormGroup,
NonNullableFormBuilder
} from '@angular/forms';
// 👇 This is a helper to bind any interface with the FormGroup generating a type safe form matching existing keys and FormControl type 🙂
export type WithControlsFrom<T> = {
[P in keyof T]?: FormControl<T[P]>;
};
@theer1k
theer1k / cache.interceptor.spec.ts
Created July 10, 2023 13:23
Angular cache interceptor
import {
HttpEvent,
HttpHandler,
HttpHeaders,
HttpRequest,
} from '@angular/common/http';
import {
HttpClientTestingModule,
HttpTestingController,
} from '@angular/common/http/testing';
@theer1k
theer1k / intersection-observer.directive.ts
Last active June 27, 2023 11:40
IntersectionObserverDirective (Angular)
import {
Directive,
ElementRef,
EventEmitter,
Input,
OnDestroy,
OnInit,
Output,
} from '@angular/core';
import { Observable, Subscription, debounceTime } from 'rxjs';
@theer1k
theer1k / index.css
Created June 13, 2023 22:52
Grid Template CSS - Scrollable Main, sticky Header and Footer
body {
display: grid;
grid-template-areas:
'header'
'main'
'footer';
grid-template-columns: auto;
grid-template-rows: auto 1fr auto;
min-height: 100vh;
}
@theer1k
theer1k / theme-colors-props-shades.mixin.scss
Created June 10, 2023 00:08
Theme Colors Props Shades Mixin Generator
$separator: '\\:' !default;
@mixin theme-colors-props-shades($name, $prop, $colors, $shades) {
@each $color in $colors {
@each $shade in $shades {
.#{$name}-#{$color}-#{$shade} {
#{$prop}: var(--#{$color}-#{$shade});
}
}
@theer1k
theer1k / media-query.css
Created April 4, 2023 14:18 — forked from gokulkrishh/media-query.css
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
/* CSS */
@theer1k
theer1k / removeDuplicatesByProperty.ts
Last active January 23, 2023 11:54
Remove duplicates by property (TypeScript)
/**
* Remove duplicates by property
* @param {string} property - List property identifier.
* @param {T[]} oldList - Old list
* @param {T[]} newList - New list
* @returns {T[]} Returns a new list without duplicates by property passed
*/
export const removeDuplicatesByProperty = <T>(
property: keyof T,
oldList: T[] = [],
@theer1k
theer1k / omit.js
Created September 22, 2022 12:18
Omit object properties
/**
* Create an object composed without ommited object properties
* @param {Object} object
* @param {string} keys
* @returns {Object}
*/
const omit = (obj, ...keys) => Object.fromEntries(
Object.entries(obj)
.filter(([key]) => !keys.includes(key))
);
@theer1k
theer1k / composer.spec.tsx
Last active September 20, 2022 17:12
Componser
import { Context, createContext, useContext } from 'react';
import { render, screen } from '@/test/testUtils';
import { ComponentWithChildren, composer } from '.';
type ContextTuple = [Context<string>, ComponentWithChildren];
const createMockContext = (value: string): ContextTuple => {
const MockContext: Context<string> = createContext('');
const MockContextProvider: ComponentWithChildren = ({ children }) => (
<MockContext.Provider value={value}>{children}</MockContext.Provider>