Skip to content

Instantly share code, notes, and snippets.

View paularmstrong's full-sized avatar
🐈‍⬛
Codes with cats

Paul Armstrong paularmstrong

🐈‍⬛
Codes with cats
View GitHub Profile
@paularmstrong
paularmstrong / transition-provider.tsx
Last active March 26, 2024 04:07
SolidJS with Solid Router View Transition provider.
import { useBeforeLeave, useIsRouting } from '@solidjs/router';
import type { ParentProps } from 'solid-js';
/**
* Usage:
*
* Wrap your application, from within the <Router> with the TransitionProvider:
*
* ```ts
* return (
@paularmstrong
paularmstrong / avatar-fallback.tsx
Created March 12, 2024 22:03
Scalable Avatar fallback component that masks the circle with the user's initials to show the underlying background beneath.
import { createUniqueId, splitProps } from 'solid-js';
import type { JSX } from 'solid-js';
type Props = {
firstName: string;
lastName: string;
} & JSX.SvgSVGAttributes<SVGSVGElement>;
export function AvatarFallback(allProps: Props) {
const id = createUniqueId();
import yargsParser from 'yargs-parser';
import Logger from './logger';
type $ObjMap<O extends {}, T> = {
[K in keyof O]: T;
};
type CommandOption = {
alias?: Array<string> | string;
description: string;
export default function(target) {
const originalMethods = {
UNSAFE_componentWillMount: target.prototype.UNSAFE_componentWillMount || noop,
componentDidMount: target.prototype.componentDidMount || noop,
UNSAFE_componentWillUpdate: target.prototype.UNSAFE_componentWillUpdate || noop,
componentDidUpdate: target.prototype.componentDidUpdate || noop,
componentWillUnmount: target.prototype.componentWillUnmount || noop
};
/**
* Copyright (c) 2019 Paul Armstrong
*/
import * as Theme from '../theme';
import React from 'react';
import { StyleProp, StyleSheet, TouchableOpacity, TouchableOpacityProps, View, ViewStyle } from 'react-native';
interface Props {
children: React.ReactElement;
disabled?: boolean;
/**
* Copyright (c) 2019 Paul Armstrong
*/
import React from 'react';
import { render } from 'react-testing-library';
import Tooltip from '../Tooltip';
import { Dimensions, MeasureOnSuccessCallback, View } from 'react-native';
describe('Tooltip', () => {
let viewRef;
export default function(target) {
const originalMethods = {
UNSAFE_componentWillMount: target.prototype.UNSAFE_componentWillMount || noop,
componentDidMount: target.prototype.componentDidMount || noop,
UNSAFE_componentWillUpdate: target.prototype.UNSAFE_componentWillUpdate || noop,
componentDidUpdate: target.prototype.componentDidUpdate || noop,
componentWillUnmount: target.prototype.componentWillUnmount || noop
};
target.prototype.UNSAFE_componentWillMount = function(...args) {
@paularmstrong
paularmstrong / react-native-web_v0.x.x.js
Last active March 4, 2020 04:18
Ensure you add `module.name_mapper='^react-native$' -> 'react-native-web'` to your `.flowconfig` options
// @flow
// flow-typed signature: aa279642a4cb992a390fedc5acdc896d
// flow-typed version: react-native_v0.5.0/flow_v0.65.0
type RNW$Dimension = {| fontScale: number, height: number, scale: number, width: number |};
type RNW$DimensionsObject = {| window: RNW$Dimension, screen: RNW$Dimension |};
type RNW$StyleObject = { [key: string]: * };
type RNW$Style = mixed;
type RNW$Styles = RNW$StyleObject | RNW$Style | Array<RNW$Styles>;
@paularmstrong
paularmstrong / what-forces-layout.md
Created August 8, 2017 19:18 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
const HeartIcon = (props) => React.createElement('svg', {
...props,
dangerouslySetInnerHTML: { __html: '<g><path d="M38.723 12c-7.187 0-11.16 7.306-11.723 8.131C26.437 19.306 22.504 12 15.277 12 8.791 12 3.533 18.163 3.533 24.647 3.533 39.964 21.891 55.907 27 56c5.109-.093 23.467-16.036 23.467-31.353C50.467 18.163 45.209 12 38.723 12z"></path></g>' },
viewBox: '0 0 54 72'
});