Skip to content

Instantly share code, notes, and snippets.

@dbhagen
Last active October 14, 2020 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbhagen/51b036c98bca4e767cf1a937c3fa6d63 to your computer and use it in GitHub Desktop.
Save dbhagen/51b036c98bca4e767cf1a937c3fa6d63 to your computer and use it in GitHub Desktop.
[ReactJS to ReactTS]
import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import { withTheme } from '../theme'
import { filterProps } from '../utils'
import { getTailwindClassNames, tailwindProps, propTypes } from '../tailwind'
const Base = ({
theme,
is,
children,
className,
focusable,
innerRef,
...rest
}) => {
const Component = is
return (
<Component
{...filterProps(rest, tailwindProps)}
className={classnames(
getTailwindClassNames(
{
...rest,
'outine-focus': 'none',
'shadow-focus': 'outline',
},
{ prefix: theme.prefix },
),
className,
)}
ref={innerRef}
>
{children}
</Component>
)
}
Base.propTypes = {
theme: PropTypes.shape({}).isRequired,
is: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]),
children: PropTypes.node,
className: PropTypes.string,
innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
...propTypes,
}
Base.defaultProps = {
is: 'div',
children: undefined,
className: undefined,
innerRef: undefined,
}
export { Base as component }
export default withTheme(Base)
import React from 'react'
import classnames from 'classnames'
import { withTheme } from '../theme'
import { filterProps } from '../utils'
import { getTailwindClassNames, tailwindProps, propTypes } from '../tailwind'
import { Class } from 'utility-types'
export interface BaseProps {
theme: Object
is: string | (() => void) | Class<React.ComponentType>
children?: React.ReactNode
className?: string
innerRef?: (() => void) | Object
}
export const Base: React.FunctionComponent<BaseProps> = (
theme,
is = 'div',
children = undefined,
className = undefined,
innerRef = undefined,
...rest
) => {
const Component = is
return (
<Component
{...filterProps(rest, tailwindProps)}
className={
classnames(
getTailwindClassNames(
{
...rest,
'outine-focus': 'none',
'shadow-focus': 'outline',
},
{ prefix: theme.prefix },
),
className,
)}
ref={innerRef}
{...rest}
>
{children}
</Component>
)
}
export { Base as component }
export default withTheme(Base)
// export default Base

import {Meta, Story, Preview, Props} from '@storybook/addon-docs/blocks'

import { Base } from './Base.tsx'

Button

This is the Base

import { Base } from 'my-components'

test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment