Skip to content

Instantly share code, notes, and snippets.

Donald Pipowitch donaldpipowitch

Block or report user

Report or block donaldpipowitch

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@donaldpipowitch
donaldpipowitch / axe.js
Created Nov 26, 2018
aXe based a11y checks in your CI for Storybook
View axe.js
const puppeteer = require('puppeteer');
const chalk = require('chalk');
const { green, red, cyan, grey, bold } = chalk;
// we assume storybook can visited at http://localhost:9001
const url = 'http://localhost:9001/iframe.html';
const runAxe = () =>
new Promise((resolve, reject) =>
@donaldpipowitch
donaldpipowitch / README.md
Last active Mar 10, 2019
Use @ts-check for custom ESLint rules
View README.md

This is a very basic example which shows how you can create a simple ESLint rule with @ts-check support. This example features the rule and a test. The rule checks, if you pass an absolute URL to a history.push function or not.

If you want to use this rule in your ESLint configuration without publishing the rule there is a caveat. AFAIK you can't simply include the path to your rule in your .eslintrc.js (correct me if I'm wrong). You need to pass the directory of this rule to the CLI as --rulesdir "./path/to/rules" and if you use VS Code with the ESLint extension you need to set "eslint.options": { "rulePaths": ["./path/to/rules"] }, in your settings.json as well. Only then you can add the rule to your config:

module.exports = {
  // ...yourCurrentConfig,
  rules: {
    // ...yourCurrentConfig.rules,
    'some-rule': 'error'
@donaldpipowitch
donaldpipowitch / useScrollBottom.ts
Created May 29, 2019
React Hook to detect if a scrollable element reached the end.
View useScrollBottom.ts
function useScrollBottom<T extends HTMLElement>(offset?: number) {
const [atBottom, setAtBottom] = useState(false);
const scrollEl = useRef<T>(null);
useEffect(() => {
const { current } = scrollEl;
if (current) {
// by default we take the clientHeight into account, so "bottom" begins as soon as the last
// visible piece appears in the scrollable area
const withOffset = offset === undefined ? current.clientHeight : offset;
@donaldpipowitch
donaldpipowitch / usePrevious.ts
Created Jun 14, 2019
React Hook to use previous value
View usePrevious.ts
import { useEffect, useRef } from 'react';
function usePrevious<T>(value: T) {
const ref = useRef<T>();
useEffect(() => {
ref.current = value;
});
return ref.current;
}
@donaldpipowitch
donaldpipowitch / example.ts
Created Jul 25, 2019
Share useState with useContext
View example.ts
import React, { createContext, useState, useContext, FC } from 'react';
type ContextValue = [boolean, (value: boolean) => void] | undefined;
const FullwidthContext = createContext<ContextValue>(undefined);
const defaultState = false;
export const FullwidthProvider: FC = ({ children }) => {
const state = useState(defaultState);
return (
@donaldpipowitch
donaldpipowitch / interceptor.ts
Created Aug 21, 2019
Try to refresh token once on 401 with RxJS and Angular Http Interceptor
View interceptor.ts
import { Injectable } from '@angular/core';
import {
HttpEvent,
HttpInterceptor,
HttpHandler,
HttpRequest,
HttpErrorResponse,
HttpClient
} from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
@donaldpipowitch
donaldpipowitch / file.ts
Created Aug 21, 2019
Subsequent requests with RxJS (and Angular), but using the first response
View file.ts
this.http.get<Data1>(url1).pipe(
mergeMap((data1) =>
this.http.get<Data2>(url2).pipe(map((_data2) => data1))
)
);
@donaldpipowitch
donaldpipowitch / click-outside.directive.ts
Created Sep 5, 2019
Angular directive to (conditionally) track clicks outside of an element
View click-outside.directive.ts
import {
Directive,
Input,
Output,
EventEmitter,
ElementRef,
OnDestroy
} from '@angular/core';
@Directive({
@donaldpipowitch
donaldpipowitch / example.html
Last active Sep 5, 2019
Angular directive to (conditionally) track focusout outside of an element (children are ignored)
View example.html
div [my-focusout-outside]="shouldTrack" (focusoutOutside)="doSomething()">Hello</div>
@donaldpipowitch
donaldpipowitch / README.md
Created Sep 6, 2019
Small example to showcase differences a CSS-in-JS solution in React can offer vs. styling in Angular
View README.md

React

index.tsx:

import React from 'react';
import styled from 'styled-components';
 
enum Area {
  header = 'header',
You can’t perform that action at this time.