Skip to content

Instantly share code, notes, and snippets.

@romansndlr
romansndlr / react-component-variants-compound.js.js
Created November 2, 2019 13:52
A simple button component that demonstrates managing different variants using the compound components pattern (using tailwindcss)
import React from 'react'
import classNames from 'classnames'
// We have extracted each variation into a sepreate lazy loaded component
const Primary = React.lazy(() => import('./PrimaryButton'))
const Error = React.lazy(() => import('./ErrorButton'))
const Success = React.lazy(() => import('./SuccessButton'))
const Info = React.lazy(() => import('./InfoButton'))
export default function Button({
@romansndlr
romansndlr / react-component-variants-props.js
Last active November 2, 2019 14:18
A simple button component that demonstrates managing different variants (using tailwindcss)
import React from 'react'
import classNames from 'classnames'
// We keep a map of all variations of each customizable attribute of our button
const backgroundColors = {
default: 'gray-200',
primary: 'blue-500',
error: 'red-500',
success: 'green-500',
info: 'teal-500'