Skip to content

Instantly share code, notes, and snippets.

View mosesoak's full-sized avatar

Moses Gunesch mosesoak

View GitHub Profile
@mosesoak
mosesoak / hideOutlineStyle-example.ts
Created March 6, 2021 01:43
hideOutlineStyle state example
// the hook also provides a style object for convenience
const { hideOutlineStyle } = useTabOutline();
// the `style` prop is used here for easy manipulation
<div className="contact-form-checkbox" style={hideOutlineStyle} />
// the object is always defined, so spreading is always safe
<div
style={{
...hideOutlineStyle,
@mosesoak
mosesoak / hideOutline-example.ts
Last active March 6, 2021 01:33
hideOutline state example
// get the state from the hook
const { hideOutline } = useTabOutline();
// in one case this was used in a render like so:
<span
className={classnames({
highlighted,
checkmark: true,
'hide-outline': hideOutline,
})}
@mosesoak
mosesoak / useTabOutline.ts
Last active March 6, 2021 01:49
React hook that automates enabling outlines for a11y when tab is used
import { useEffect, useState } from 'react';
/**
* Workaround for outlines that flash or stick on click.
*
* In general, never globally disable the `outline` attribute for
* accessibility (a11y) reasons, but this can cause visual glitches
* when using a mouse.
*
* This hook provides two ways to automate hiding an element's outline
@mosesoak
mosesoak / gatsby-ssr.js
Last active March 10, 2021 22:15
MSIE Blocker Script (Gatsby)
exports.onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => {
const headComponents = getHeadComponents();
// Show a blocking message on MSIE
// (documentMode is an IE-only property, versions 8-11)
// (dangerouslySetInnerHTML keeps the script string unescaped)
headComponents.push(
<script
key="block-msie"
type="text/javascript"
@mosesoak
mosesoak / msie-blocker-script.html
Last active March 6, 2021 00:01
MSIE Blocker Script (vanilla)
<head>
<script type="text/javascript">
// Show a blocking message on MSIE
// (documentMode is an IE-only property, versions 8-11)
if (typeof window !== 'undefined' && window.document.documentMode) {
window.onload = function () {
document.body.innerHTML =
'Internet Explorer is no longer supported.<br /><br />Please visit this site on Edge or Chrome.';
document.body.style.cssText =
'text-align: center; padding-top: 40vh; font-family: Sans-Serif;';
// Deep-merges arrays without duplicate values
const mergeCustomizer = (objValue: any, srcValue: any) => {
if (Array.isArray(objValue) && Array.isArray(srcValue)) {
return uniqWith(
[...srcValue, ...objValue],
(a, b) => a === b || isEqual(a, b),
);
}
};
<AnimatedNode_
animatedStyle='headerHeight'
>
<Animated.View .../>
</AnimatedNode_>
<Conductor_
animatedStyles={{
headerHeight: this.headerHeightStyle,
}}
>
<YourComponent />
</Conductor_>