This file contains hidden or 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 React, { useState } from "react"; | |
| const ProductSearchFilter = ({ | |
| products = [], | |
| colors = [], | |
| sizes = [], | |
| onSearch = () => {} | |
| }) => { | |
| const [product, setProduct] = useState(null); | |
| const [selectedColors, setSelectedColors] = useState([]); |
This file contains hidden or 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 React, { useState, useCallback } from "react"; | |
| const readStyle = { backgroundColor: "grey" }; | |
| const unreadStyle = { backgroundColor: "white" }; | |
| const useReadStatusUpdater = (hasRead, onReset) => { | |
| const [read, setRead] = useState(hasRead || false); | |
| const resetRead = useCallback(() => { | |
| setRead(hasRead); |
This file contains hidden or 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 React, { useState, useCallback } from "react"; | |
| const readStyle = { backgroundColor: "grey" }; | |
| const unreadStyle = { backgroundColor: "white" }; | |
| const EmailsListItem = ({ hasRead, onReadStatusChange }) => { | |
| const [read, setRead] = useState(hasRead || false); | |
| const resetRead = useCallback(() => { | |
| setRead(hasRead); | |
| // Handle side effects during a reset! |
This file contains hidden or 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 React, { useState, useCallback } from "react"; | |
| const readStyle = { backgroundColor: "grey" }; | |
| const unreadStyle = { backgroundColor: "white" }; | |
| const EmailsListItem = ({ hasRead }) => { | |
| const [read, setRead] = useState(hasRead || false); | |
| const resetRead = useCallback(() => setRead(hasRead), [hasRead]); | |
| const style = read ? readStyle : unreadStyle; |
This file contains hidden or 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
| const logClick = () => console.log("button clicked"); | |
| const callAll = (...fns) => (...args) => fns.forEach((fn) => fn(...args)); | |
| export const buttonPropsGetter = ({ customOnClick, ...props }) => ({ | |
| onClick: callAll(logClick, customOnClick), // Extensible | |
| tabIndex: 0, | |
| role: "button", | |
| "aria-disabled": false, | |
| text: "Button", |
This file contains hidden or 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
| const buttonAriaPropCollection = { | |
| tabIndex: 0, | |
| role: "button", | |
| "aria-disabled": false | |
| }; | |
| const Button = ({ text, onClick, tabIndex, role, 'aria-disabled': ariaDisabled }) => { | |
| return ( | |
| <button onClick={onClick} tabIndex={tabIndex} role={role} aria-disabled={ariaDisabled}> | |
| {text} |
This file contains hidden or 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
| const Button = ({ text, onClick, tabIndex, ariaDisabled }) => { | |
| return ( | |
| <button | |
| onClick={onClick} | |
| tabIndex={tabIndex} | |
| role="button" | |
| aria-disabled={ariaDisabled} | |
| > | |
| {text} | |
| </button> |
This file contains hidden or 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 Menu from "./Menu"; | |
| import MenuButton from "./MenuButton"; | |
| import MenuItem from "./MenuItem"; | |
| export default () => ( | |
| <Menu hideButtons> | |
| <MenuButton text="Exit" action={() => console.log("Exiting")} /> | |
| <MenuButton text="Settings" action={() => console.log("settings")} /> | |
| <MenuItem text="News" /> | |
| <MenuItem text="Serials" /> |