2023-01-31 21:43:03 +00:00
|
|
|
import React, { ReactNode } from 'react'
|
|
|
|
import { useCssHandles } from 'vtex.css-handles'
|
2023-01-20 13:07:13 +00:00
|
|
|
|
2023-01-31 21:43:03 +00:00
|
|
|
const CSS_HANDLES = ['html'] as const
|
|
|
|
|
|
|
|
import './style.css'
|
2023-01-20 13:07:13 +00:00
|
|
|
|
|
|
|
type HtmlProps = {
|
2023-01-31 21:43:03 +00:00
|
|
|
children?: ReactNode
|
2023-01-26 14:21:37 +00:00
|
|
|
/**
|
|
|
|
* Qual tag Html que deseja que seja usar
|
|
|
|
*
|
|
|
|
* @default div
|
|
|
|
*/
|
2023-01-31 21:43:03 +00:00
|
|
|
tag?: keyof React.ReactHTML
|
2023-01-26 14:21:37 +00:00
|
|
|
/**
|
|
|
|
* Classes CSS extras que deseja adicionar.
|
|
|
|
* Feito para uso de [classes do tachyons](https://tachyons.io/)
|
|
|
|
*/
|
2023-01-31 21:43:03 +00:00
|
|
|
tachyonsClasses?: string
|
2023-01-26 14:21:37 +00:00
|
|
|
/**
|
|
|
|
* Se caso quiser usar esse componente
|
|
|
|
* para adicinar um texto simples
|
|
|
|
*/
|
2023-01-31 21:43:03 +00:00
|
|
|
text?: string
|
2023-01-26 14:21:37 +00:00
|
|
|
/**
|
|
|
|
* Tag ID para
|
|
|
|
*/
|
2023-01-31 21:43:03 +00:00
|
|
|
testId?: string
|
|
|
|
}
|
2023-01-20 13:07:13 +00:00
|
|
|
|
2023-01-26 14:21:37 +00:00
|
|
|
export const Html = ({
|
|
|
|
children = null,
|
2023-01-31 21:43:03 +00:00
|
|
|
tag = 'div',
|
|
|
|
text = '',
|
|
|
|
tachyonsClasses: classes = '',
|
2023-01-26 14:21:37 +00:00
|
|
|
testId,
|
|
|
|
}: HtmlProps) => {
|
2023-01-31 21:43:03 +00:00
|
|
|
const { handles } = useCssHandles(CSS_HANDLES)
|
2023-01-20 13:07:13 +00:00
|
|
|
|
2023-01-26 14:21:37 +00:00
|
|
|
const props = {
|
|
|
|
className: `${handles.html} ${classes}`,
|
2023-01-31 21:43:03 +00:00
|
|
|
'data-testid': testId,
|
|
|
|
}
|
2023-01-26 14:21:37 +00:00
|
|
|
const Children = (
|
|
|
|
<>
|
|
|
|
{children}
|
|
|
|
{text}
|
|
|
|
</>
|
2023-01-31 21:43:03 +00:00
|
|
|
)
|
|
|
|
const Element = React.createElement(tag, props, Children)
|
2023-01-20 13:07:13 +00:00
|
|
|
|
2023-01-31 21:43:03 +00:00
|
|
|
return <>{Element}</>
|
|
|
|
}
|