Advertisement
Guest User

addtoListbutton.ce.js

a guest
Jan 22nd, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import React, { useRef } from 'react';
  2. import { element, func, shape, string } from 'prop-types';
  3. import { Heart } from 'react-feather';
  4. import { useAddToListButton } from '@magento/peregrine/lib/talons/Wishlist/AddToListButton/useAddToListButton';
  5. import { useButton } from 'react-aria';
  6.  
  7. import { useStyle } from '@magento/venia-ui/lib/classify';
  8. import Icon from '@magento/venia-ui/lib/components/Icon';
  9. import defaultClasses from './addToListButton.module.css';
  10. import { useCommonToasts } from '@magento/venia-ui/lib/components/Wishlist/AddToListButton/useCommonToasts';
  11.  
  12. const HeartIcon = <Icon size={20} src={Heart} color="#DBB99D" />;
  13.  
  14. const AddToListButton = props => {
  15. const talonProps = useAddToListButton(props);
  16. const buttonRef = useRef();
  17.  
  18. const {
  19. buttonProps,
  20. buttonText,
  21. errorToastProps,
  22. isSelected,
  23. loginToastProps,
  24. successToastProps
  25. } = talonProps;
  26.  
  27. useCommonToasts({ errorToastProps, loginToastProps, successToastProps });
  28. const { buttonProps: ariaButtonProps } = useButton(buttonProps, buttonRef);
  29.  
  30. const classes = useStyle(defaultClasses, props.classes);
  31. const buttonClass = isSelected ? classes.root_selected : classes.root;
  32.  
  33. return (
  34. <button ref={buttonRef} className={buttonClass} {...ariaButtonProps}>
  35. {props.icon} ADD TO WISHLIST
  36. </button>
  37. );
  38. };
  39.  
  40. export default AddToListButton;
  41.  
  42. AddToListButton.defaultProps = {
  43. icon: HeartIcon
  44. };
  45.  
  46. AddToListButton.propTypes = {
  47. afterAdd: func,
  48. beforeAdd: func,
  49. classes: shape({
  50. root: string,
  51. root_selected: string
  52. }),
  53. icon: element
  54. };
  55. ad
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement