mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
* 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
43 lines
1.1 KiB
TypeScript
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>;
|