NotAvailableForGuest.jsx 760 B

123456789101112131415161718192021222324252627282930
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { UncontrolledTooltip } from 'reactstrap';
  4. const NotAvailableForGuest = ({ children }) => {
  5. const id = children.props.id || `grw-not-available-for-guest-${Math.random().toString(32).substring(2)}`;
  6. // clone and add className
  7. const clonedChild = React.cloneElement(children, {
  8. id,
  9. className: `${children.props.className} grw-not-available-for-guest`,
  10. onClick: () => { /* do nothing */ },
  11. });
  12. return (
  13. <>
  14. { clonedChild }
  15. <UncontrolledTooltip placement="top" target={id}>Not available for guest</UncontrolledTooltip>
  16. </>
  17. );
  18. };
  19. NotAvailableForGuest.propTypes = {
  20. children: PropTypes.node.isRequired,
  21. };
  22. export default NotAvailableForGuest;