This repository has been archived on 2025-05-09. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Astral-nook/resources/scripts/components/elements/Can.tsx

24 lines
650 B
TypeScript

import React, { memo } from 'react';
import { usePermissions } from '@/plugins/usePermissions';
import isEqual from 'react-fast-compare';
interface Props {
action: string | string[];
matchAny?: boolean;
renderOnError?: React.ReactNode | null;
children: React.ReactNode;
}
const Can = ({ action, matchAny = false, renderOnError, children }: Props) => {
const can = usePermissions(action);
return (
<>
{(matchAny && can.filter((p) => p).length > 0) || (!matchAny && can.every((p) => p))
? children
: renderOnError}
</>
);
};
export default memo(Can, isEqual);