Junior Garcia 86f921d098
Feat/server components (#1291)
* feat(root): rsc components added, packages modified, filter dom props function adapted

* fix(root): eslint/prettier issues

* feat(root): exports changed to named, new pkg for system rsc compatible functions
2023-08-05 23:35:28 -03:00

43 lines
1.1 KiB
TypeScript

import type {CodeVariantProps} from "@nextui-org/theme";
import type {HTMLNextUIProps, PropGetter} from "@nextui-org/system-rsc";
import {code} from "@nextui-org/theme";
import {mapPropsVariants} from "@nextui-org/system-rsc";
import {ReactRef} from "@nextui-org/react-utils";
import {useMemo} from "react";
export interface UseCodeProps extends HTMLNextUIProps<"code">, CodeVariantProps {
/**
* Ref to the DOM node.
*/
ref?: ReactRef<HTMLElement | null>;
}
export function useCode(originalProps: UseCodeProps) {
const [props, variantProps] = mapPropsVariants(originalProps, code.variantKeys);
const {as, children, className, ...otherProps} = props;
const Component = as || "code";
const classNames = useMemo(
() =>
code({
...variantProps,
className,
}),
[...Object.values(variantProps), className],
);
const getCodeProps: PropGetter = () => {
return {
className: classNames,
...otherProps,
};
};
return {Component, children, getCodeProps};
}
export type UseCodeReturn = ReturnType<typeof useCode>;