curls
Version:
💪 Responsive, expressive UI primitives for React written with Style Hooks and Emotion
59 lines (54 loc) • 1.78 kB
JavaScript
function _extends() {
_extends =
Object.assign ||
function(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i]
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key]
}
}
}
return target
}
return _extends.apply(this, arguments)
}
import React from 'react'
import {useTheme, createElement} from '@style-hooks/core'
import {useBox} from '../Box'
import {useText} from '../Text'
import {useLink} from './A'
export const createLink = themeName =>
React.forwardRef((props, ref) => {
var _theme$themeName
const theme = useTheme()
if (process.env.NODE_ENV !== 'production')
if (
!(theme === null || theme === void 0
? void 0
: (_theme$themeName = theme[themeName]) === null ||
_theme$themeName === void 0
? void 0
: _theme$themeName.component)
)
throw new Error(
'You must define a `component` property in your ' +
("'theme." +
themeName +
"' to use the " +
(themeName.charAt(0).toUpperCase() + themeName.slice(1)) +
' component')
)
props = useBox(useText(useLink(props)))
props.ref = ref
return createElement(theme[themeName].component, props)
})
export const Link = createLink('link')
if (process.env.NODE_ENV !== 'production') {
const typePropTypes = require('../Text/propTypes').default,
boxPropTypes = require('../Box/propTypes').default,
flexPropTypes = require('../Flex/propTypes').default
Link.displayName = 'Link'
Link.propTypes = _extends({}, boxPropTypes, typePropTypes, flexPropTypes)
}