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
const schema = require("schm"); | |
const Joi = require("joi"); | |
const joiValidate = constraints => prevSchema => prevSchema.merge({ | |
validate(values) { | |
const parsed = prevSchema.parse(values); | |
return Joi.validate(parsed, constraints); | |
} | |
}); |
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
const Avatar = ({ profile, ...props }) => ( | |
<img | |
className="avatar" | |
src={profile.photoSrc} | |
alt={profile.photoAlt} | |
{...props} | |
/> | |
); |
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
const Avatar = ({ profile, ...props }) => ( | |
<img | |
className="avatar" | |
src={profile && profile.photoUrl} | |
alt={profile && profile.photoAlt} | |
{...props} | |
/> | |
); | |
Avatar.propTypes = { |
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
const Card = ({ profile, imageUrl, imageAlt, title, description }) => ( | |
<div className="card"> | |
<div className="top-bar"> | |
<img className="avatar" src={profile.photoUrl} alt={profile.photoAlt} /> | |
<div className="username">{profile.username}</div> | |
</div> | |
<img className="image" src={imageUrl} alt={imageAlt} /> | |
<div className="content"> | |
<h2 className="title">{title}</h2> | |
<p className="description">{description}</p> |
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
const Avatar = props => <img className="avatar" {...props} />; | |
Avatar.propTypes = { | |
src: PropTypes.string.isRequired, | |
alt: PropTypes.string.isRequired | |
}; |
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
const Avatar = ({ className, ...props }) => ( | |
<img className={`avatar ${className}`} {...props} /> | |
); | |
Avatar.propTypes = { | |
src: PropTypes.string.isRequired, | |
alt: PropTypes.string.isRequired, | |
className: PropTypes.string | |
}; |
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
const Avatar = ({ className, style, ...props }) => ( | |
<img | |
className={`avatar ${className}`} | |
style={{ borderRadius: "50%", ...style }} | |
{...props} | |
/> | |
); | |
Avatar.propTypes = { | |
src: PropTypes.string.isRequired, |
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
const callAll = (...fns) => (...args) => fns.forEach(fn => fn && fn(...args)); | |
const internalOnLoad = () => console.log("loaded"); | |
const Avatar = ({ className, style, onLoad, ...props }) => ( | |
<img | |
className={`avatar ${className}`} | |
style={{ borderRadius: "50%", ...style }} | |
onLoad={callAll(internalOnLoad, onLoad)} | |
{...props} |
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
const Button = ({ as: T, ...props }) => <T {...props} />; | |
Button.propTypes = { | |
as: PropTypes.oneOfType([PropTypes.string, PropTypes.func]) | |
}; | |
Button.defaultProps = { | |
as: "button" | |
}; |