Table of Contents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compound Components | |
// 💯 Support non-toggle children | |
// http://localhost:3000/isolated/final/02.extra-1.js | |
import * as React from 'react' | |
import {Switch} from '../switch' | |
function Toggle({children}) { | |
const [on, setOn] = React.useState(false) | |
const toggle = () => setOn(!on) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* font size & line height in px */ | |
$font-size-body-px: 14; | |
$line-height-px: 21; | |
/* calculate font-size (in %) and line-height (in em) */ | |
$font-size-body: pc($font-size-body-px, 16); | |
$line-height: em($line-height-px, $font-size-body-px); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function asyncReducer(state, action) { | |
switch (action.type) { | |
case 'pending': { | |
return {status: 'pending', data: null, error: null} | |
} | |
case 'resolved': { | |
return {status: 'resolved', data: action.data, error: null} | |
} | |
case 'rejected': { | |
return {status: 'rejected', data: null, error: action.error} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react' | |
/** | |
* | |
* @param {String} key The key to set in localStorage for this value | |
* @param {Object} defaultValue The value to use if it is not already in localStorage | |
* @param {{serialize: Function, deserialize: Function}} options The serialize and deserialize functions to use (defaults to JSON.stringify and JSON.parse respectively) | |
*/ | |
function useLocalStorageState( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Flexible Compound Components with context | |
// 💯 custom hook validation | |
import * as React from 'react' | |
import {Switch} from '../switch' | |
const ToggleContext = React.createContext() | |
ToggleContext.displayName = 'ToggleContext' | |
function Toggle({children}) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prop Collections and Getters | |
// 💯 prop getters | |
import * as React from 'react' | |
import {Switch} from '../switch' | |
const callAll = (...fns) => (...args) => fns.forEach(fn => fn?.(...args)) | |
function useToggle() { | |
const [on, setOn] = React.useState(false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Control Props | |
// 💯 don't warn in production | |
import * as React from 'react' | |
import warning from 'warning' | |
import {Switch} from '../switch' | |
const callAll = (...fns) => (...args) => fns.forEach(fn => fn?.(...args)) | |
const actionTypes = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Control Props | |
// 💯 add read only warning | |
import * as React from 'react' | |
import warning from 'warning' | |
import {Switch} from '../switch' | |
const callAll = (...fns) => (...args) => fns.forEach(fn => fn?.(...args)) | |
const actionTypes = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Control Props | |
// 💯 add a controlled state warning | |
import * as React from 'react' | |
import warning from 'warning' | |
import {Switch} from '../switch' | |
const callAll = (...fns) => (...args) => fns.forEach(fn => fn?.(...args)) | |
const actionTypes = { |
NewerOlder