How to use @magento/peregrine - 10 common examples

To help you get started, we’ve selected a few @magento/peregrine examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-concept / src / components / MiniCart / kebab.js View on Github external
const classes = mergeClasses(defaultClasses, props.classes);
    const toggleClass = isOpen ? classes.dropdown_active : classes.dropdown;

    const handleKebabClick = useCallback(() => {
        setIsOpen(!isOpen);
    }, [isOpen]);
    const handleOutsideKebabClick = useCallback(event => {
        // Ensure we're truly outside of the kebab.
        if (!kebabRef.current.contains(event.target)) {
            setIsOpen(false);
        }
    }, []);

    useEventListener(document, 'mousedown', handleOutsideKebabClick);
    useEventListener(document, 'touchend', handleOutsideKebabClick);

    return (
        <div>
            <button>
                
            </button>
            <ul>{children}</ul>
        </div>
    );
};
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-concept / src / components / MiniCart / kebab.js View on Github external
const [isOpen, setIsOpen] = useState(false);

    const classes = mergeClasses(defaultClasses, props.classes);
    const toggleClass = isOpen ? classes.dropdown_active : classes.dropdown;

    const handleKebabClick = useCallback(() =&gt; {
        setIsOpen(!isOpen);
    }, [isOpen]);
    const handleOutsideKebabClick = useCallback(event =&gt; {
        // Ensure we're truly outside of the kebab.
        if (!kebabRef.current.contains(event.target)) {
            setIsOpen(false);
        }
    }, []);

    useEventListener(document, 'mousedown', handleOutsideKebabClick);
    useEventListener(document, 'touchend', handleOutsideKebabClick);

    return (
        <div>
            <button>
                
            </button>
            <ul>{children}</ul>
        </div>
    );
};
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-concept / src / components / App / app.js View on Github external
useEffect(() => {
        for (const { error, id, loc } of errors) {
            const errorToastProps = {
                icon: ErrorIcon,
                message: `${ERROR_MESSAGE}\nDebug: ${id} ${loc}`,
                onDismiss: remove => {
                    getErrorDismisser(error, handleDismiss)();
                    remove();
                },
                timeout: 15000,
                type: 'error'
            };
            // Only add a toast for new errors. Without this condition we would
            // re-add toasts when one error is removed even if there were two
            // added at the same time.
            const errorToastId = getToastId(errorToastProps);
            if (!toasts.get(errorToastId)) {
                addToast(errorToastProps);
            }
        }
    }, [errors, handleDismiss]); // eslint-disable-line
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-ui / lib / components / CategoryList / categoryTile.js View on Github external
const CategoryTile = props => {
    const talonProps = useCategoryTile({
        item: props.item
    });

    const { image, item } = talonProps;

    const imagePath = resourceUrl(image.url, {
        type: image.type,
        width: image.width
    });

    // interpolation doesn't work inside `url()` for legacy reasons
    // so a custom property should wrap its value in `url()`
    const imageUrl = imagePath ? `url(${imagePath})` : 'none';
    const imageWrapperStyle = { '--venia-image': imageUrl };

    const classes = mergeClasses(defaultClasses, props.classes);
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-ui / lib / components / Checkout / __tests__ / paymentsForm.spec.js View on Github external
test('renders a PaymentsForm component', () =&gt; {
    const component = createTestInstance();

    expect(component.toJSON()).toMatchSnapshot();
});
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-concept / src / components / ProductImageCarousel / __tests__ / thumbnailList.spec.js View on Github external
test('renders the ThumbnailList component correctly', () =&gt; {
    const component = createTestInstance(
        
            
        
    );

    expect(component.toJSON()).toMatchSnapshot();
});
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-ui / lib / components / Checkout / __tests__ / overview.spec.js View on Github external
test('Confirm Order button is disabled if submitting', () =&gt; {
    const props = {
        ...defaultProps,
        submitting: true
    };
    const component = createTestInstance();
    expect(component.toJSON()).toMatchSnapshot();
});
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-ui / lib / components / Checkout / __tests__ / editableForm.spec.js View on Github external
test('submit address form calls action with type and values', () =&gt; {
    const props = {
        ...defaultProps,
        editing: 'address'
    };
    const component = createTestInstance();
    const formValues = {
        foo: 'bar'
    };
    act(() =&gt; {
        component.root.findByType(AddressForm).props.onSubmit(formValues);
    });

    expect(mockSubmitShippingAddress).toHaveBeenCalledWith({
        formValues
    });
});
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-concept / src / components / ProductImageCarousel / __tests__ / carousel.spec.js View on Github external
test('renders the Carousel component correctly w/ sorted images', () =&gt; {
    const component = createTestInstance(
        
            
        
    );

    expect(component.toJSON()).toMatchSnapshot();
});
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-ui / lib / components / Checkout / __tests__ / overview.spec.js View on Github external
test('clicking payment form edit sets `editing` state value to "paymentMethod"', () =&gt; {
    const component = createTestInstance();

    act(() =&gt; {
        component.root.findAllByType(Section)[1].props.onClick();
    });

    expect(mockSetEditing).toHaveBeenCalledWith('paymentMethod');
});