Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MiniCart Height Fix #1387

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders the correct tree 1`] = `
<aside>
<aside
style={
Object {
"--minicart-height-unit": "7.19px",
}
}
>
<Header
closeDrawer={[MockFunction]}
isEditingItem={false}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import ShallowRenderer from 'react-test-renderer/shallow';

import { useWindowSize } from '@magento/peregrine';

import MiniCart from '../miniCart';

const renderer = new ShallowRenderer();
Expand Down Expand Up @@ -43,6 +45,10 @@ const baseProps = {
updateItemInCart: jest.fn()
};

beforeAll(() => {
useWindowSize.mockReturnValue({ innerHeight: 719 });
});

test('renders the correct tree', () => {
const tree = renderer.render(<MiniCart {...baseProps} />);

Expand Down
4 changes: 3 additions & 1 deletion packages/venia-concept/src/components/MiniCart/miniCart.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.root {
--base-z-index: 4;
--minicart-height: 100vh;
supernova-at marked this conversation as resolved.
Show resolved Hide resolved
--minicart-header-height: 3.5rem;
--minicart-height: calc(
var(--minicart-height-unit, 1vh) * 100
); /* Note: --minicart-height-unit set by JS */
align-content: start;
background-color: white;
bottom: 0;
Expand Down
10 changes: 9 additions & 1 deletion packages/venia-concept/src/components/MiniCart/miniCart.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { arrayOf, bool, func, number, object, shape, string } from 'prop-types';

import { useWindowSize } from '@magento/peregrine';

import Body from './body';
import Footer from './footer';
import Header from './header';
Expand All @@ -26,12 +28,18 @@ const MiniCart = props => {
} = props;
const { editItem, isEditingItem, isLoading, isUpdatingItem } = cart;

// Hooks.
const { innerHeight: viewportHeight } = useWindowSize();

// Members.
const classes = mergeClasses(defaultClasses, props.classes);
const currencyCode = getCurrencyCode(cart);
const cartItems = cart.details.items;
const numItems = cart.details.items_qty;
const rootClass = isOpen ? classes.root_open : classes.root;
const rootStyle = {
'--minicart-height-unit': `${viewportHeight * 0.01}px`
};
const subtotal = cart.totals.subtotal;

const showFooter = !(isCartEmpty || isLoading || isEditingItem);
Expand All @@ -46,7 +54,7 @@ const MiniCart = props => {
) : null;

return (
<aside className={rootClass}>
<aside className={rootClass} style={rootStyle}>
<Header closeDrawer={closeDrawer} isEditingItem={isEditingItem} />
<Body
beginEditItem={beginEditItem}
Expand Down