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