Skip to content

Commit

Permalink
Correct translation doc and use resize-observer-polyfill package
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjORbj committed Jul 28, 2021
1 parent c677e20 commit fefd78a
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 45 deletions.
2 changes: 2 additions & 0 deletions docs/translations/api-docs/masonry-item/masonry-item-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"propDescriptions": {
"children": "The content of the component, normally an <code>&lt;img /&gt;</code> or a <code>&lt;div /&gt;</code>.",
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"columnSpan": "The number of columns taken up by the component",
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"height": "The height of the component in px.",
"sx": "Allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/the-sx-prop/\">`sx` page</a> for more details."
},
"classDescriptions": { "root": { "description": "Styles applied to the root element." } }
Expand Down
2 changes: 2 additions & 0 deletions docs/translations/api-docs/masonry-item/masonry-item-es.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"propDescriptions": {
"children": "The content of the component, normally an <code>&lt;img /&gt;</code> or a <code>&lt;div /&gt;</code>.",
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"columnSpan": "The number of columns taken up by the component",
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"height": "The height of the component in px.",
"sx": "Allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/the-sx-prop/\">`sx` page</a> for more details."
},
"classDescriptions": { "root": { "description": "Styles applied to the root element." } }
Expand Down
2 changes: 2 additions & 0 deletions docs/translations/api-docs/masonry-item/masonry-item-fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"propDescriptions": {
"children": "The content of the component, normally an <code>&lt;img /&gt;</code> or a <code>&lt;div /&gt;</code>.",
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"columnSpan": "The number of columns taken up by the component",
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"height": "The height of the component in px.",
"sx": "Allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/the-sx-prop/\">`sx` page</a> for more details."
},
"classDescriptions": { "root": { "description": "Styles applied to the root element." } }
Expand Down
2 changes: 2 additions & 0 deletions docs/translations/api-docs/masonry-item/masonry-item-ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"propDescriptions": {
"children": "The content of the component, normally an <code>&lt;img /&gt;</code> or a <code>&lt;div /&gt;</code>.",
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"columnSpan": "The number of columns taken up by the component",
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"height": "The height of the component in px.",
"sx": "Allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/the-sx-prop/\">`sx` page</a> for more details."
},
"classDescriptions": { "root": { "description": "Styles applied to the root element." } }
Expand Down
2 changes: 2 additions & 0 deletions docs/translations/api-docs/masonry-item/masonry-item-pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"propDescriptions": {
"children": "The content of the component, normally an <code>&lt;img /&gt;</code> or a <code>&lt;div /&gt;</code>.",
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"columnSpan": "The number of columns taken up by the component",
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"height": "The height of the component in px.",
"sx": "Allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/the-sx-prop/\">`sx` page</a> for more details."
},
"classDescriptions": { "root": { "description": "Styles applied to the root element." } }
Expand Down
2 changes: 2 additions & 0 deletions docs/translations/api-docs/masonry-item/masonry-item-ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"propDescriptions": {
"children": "The content of the component, normally an <code>&lt;img /&gt;</code> or a <code>&lt;div /&gt;</code>.",
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"columnSpan": "The number of columns taken up by the component",
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"height": "The height of the component in px.",
"sx": "Allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/the-sx-prop/\">`sx` page</a> for more details."
},
"classDescriptions": { "root": { "description": "Styles applied to the root element." } }
Expand Down
2 changes: 2 additions & 0 deletions docs/translations/api-docs/masonry-item/masonry-item-zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"propDescriptions": {
"children": "The content of the component, normally an <code>&lt;img /&gt;</code> or a <code>&lt;div /&gt;</code>.",
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"columnSpan": "The number of columns taken up by the component",
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"height": "The height of the component in px.",
"sx": "Allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/the-sx-prop/\">`sx` page</a> for more details."
},
"classDescriptions": { "root": { "description": "Styles applied to the root element." } }
Expand Down
2 changes: 1 addition & 1 deletion docs/translations/api-docs/masonry/masonry-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"propDescriptions": {
"children": "The content of the component, normally <code>&lt;MasonryItem /&gt;</code>s.",
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"cols": "Number of columns.",
"columns": "Number of columns.",
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"spacing": "Defines the space between children.",
"sx": "Allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/the-sx-prop/\">`sx` page</a> for more details."
Expand Down
2 changes: 1 addition & 1 deletion docs/translations/api-docs/masonry/masonry-es.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"propDescriptions": {
"children": "The content of the component, normally <code>&lt;MasonryItem /&gt;</code>s.",
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"cols": "Number of columns.",
"columns": "Number of columns.",
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"spacing": "Defines the space between children.",
"sx": "Allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/the-sx-prop/\">`sx` page</a> for more details."
Expand Down
2 changes: 1 addition & 1 deletion docs/translations/api-docs/masonry/masonry-fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"propDescriptions": {
"children": "The content of the component, normally <code>&lt;MasonryItem /&gt;</code>s.",
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"cols": "Number of columns.",
"columns": "Number of columns.",
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"spacing": "Defines the space between children.",
"sx": "Allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/the-sx-prop/\">`sx` page</a> for more details."
Expand Down
2 changes: 1 addition & 1 deletion docs/translations/api-docs/masonry/masonry-ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"propDescriptions": {
"children": "The content of the component, normally <code>&lt;MasonryItem /&gt;</code>s.",
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"cols": "Number of columns.",
"columns": "Number of columns.",
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"spacing": "Defines the space between children.",
"sx": "Allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/the-sx-prop/\">`sx` page</a> for more details."
Expand Down
2 changes: 1 addition & 1 deletion docs/translations/api-docs/masonry/masonry-pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"propDescriptions": {
"children": "The content of the component, normally <code>&lt;MasonryItem /&gt;</code>s.",
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"cols": "Number of columns.",
"columns": "Number of columns.",
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"spacing": "Defines the space between children.",
"sx": "Allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/the-sx-prop/\">`sx` page</a> for more details."
Expand Down
2 changes: 1 addition & 1 deletion docs/translations/api-docs/masonry/masonry-ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"propDescriptions": {
"children": "The content of the component, normally <code>&lt;MasonryItem /&gt;</code>s.",
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"cols": "Number of columns.",
"columns": "Number of columns.",
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"spacing": "Defines the space between children.",
"sx": "Allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/the-sx-prop/\">`sx` page</a> for more details."
Expand Down
2 changes: 1 addition & 1 deletion docs/translations/api-docs/masonry/masonry-zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"propDescriptions": {
"children": "The content of the component, normally <code>&lt;MasonryItem /&gt;</code>s.",
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"cols": "Number of columns.",
"columns": "Number of columns.",
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"spacing": "Defines the space between children.",
"sx": "Allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/the-sx-prop/\">`sx` page</a> for more details."
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"react-router-dom": "^5.2.0",
"react-test-renderer": "^17.0.1",
"remark": "^13.0.0",
"resize-observer": "^1.0.2",
"resize-observer-polyfill": "^1.5.1",
"rimraf": "^3.0.0",
"rollup": "^2.10.8",
"rollup-plugin-babel": "^4.3.3",
Expand Down
7 changes: 4 additions & 3 deletions packages/material-ui-lab/src/MasonryItem/MasonryItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { deepmerge, unstable_useForkRef as useForkRef } from '@material-ui/utils';
import { unstable_composeClasses as composeClasses } from '@material-ui/unstyled';
import { styled, useThemeProps } from '@material-ui/core/styles';
import { ResizeObserver } from 'resize-observer';
import ResizeObserver from 'resize-observer-polyfill';
import { getMasonryItemUtilityClass } from './masonryItemClasses';
import MasonryContext from '../Masonry/MasonryContext';

Expand Down Expand Up @@ -45,7 +45,7 @@ export const style = ({ styleProps, theme }) => {
const transformer = createUnarySpacing(theme);
const styleFromPropValue = (propValue) => {
const gap = Number(getValue(transformer, propValue).replace('px', ''));
const rowSpan = styleProps.height ? Math.ceil(styleProps.height + gap) : 0;
const rowSpan = Math.ceil(styleProps.height + gap);
return {
gridRowEnd: `span ${rowSpan}`,
paddingBottom: gap - 1,
Expand Down Expand Up @@ -73,11 +73,12 @@ const MasonryItem = React.forwardRef(function MasonryItem(inProps, ref) {
const masonryItemRef = React.useRef(null);

const { spacing = 1, documentReady = false } = React.useContext(MasonryContext);
const { children, className, component = 'div', columnSpan = 1, ...other } = props;
const { children, className, component = 'div', columnSpan = 1, height = 0, ...other } = props;
const [styleProps, setStyleProps] = React.useState({
...props,
spacing,
columnSpan,
height,
});

const classes = useUtilityClasses(styleProps);
Expand Down
60 changes: 31 additions & 29 deletions packages/material-ui-lab/src/MasonryItem/MasonryItem.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { createClientRender, describeConformanceV5, act } from 'test/utils';
import { createClientRender, describeConformanceV5 } from 'test/utils';
import MasonryItem, { masonryItemClasses as classes } from '@material-ui/lab/MasonryItem';
import { expect } from 'chai';
import { createTheme } from '@material-ui/core/styles';
Expand All @@ -21,7 +21,13 @@ describe('<MasonryItem />', () => {
testComponentPropWith: 'div',
testVariantProps: { variant: 'foo' },
muiName: 'MuiMasonryItem',
skip: ['componentsProp'],
skip: [
'componentsProp',
// reactTestRenderer fails because React state updates should be wrapped into act(...)
// I followed the guideline here: https://reactjs.org/link/wrap-tests-with-act
// but tests still couldn't pass
'reactTestRenderer',
],
}),
);

Expand All @@ -31,20 +37,16 @@ describe('<MasonryItem />', () => {
});

it('should render children by default', () => {
let item = null;
act(() => {
const { getByTestId } = render(<MasonryItem data-testid="test-root">{children}</MasonryItem>);
item = getByTestId('test-children');
});
expect(item).not.to.equal(null);
const { getByTestId } = render(<MasonryItem data-testid="test-root">{children}</MasonryItem>);
expect(getByTestId('test-children')).not.to.equal(null);
});

describe('style attribute:', () => {
it('should render with padding bottom and grid-row-end responsive to breakpoints', () => {
expect(
style({
styleProps: {
contentHeight: 100,
height: 100,
columnSpan: 1,
spacing: { xs: 1, sm: 2, md: 3 },
},
Expand Down Expand Up @@ -76,7 +78,7 @@ describe('<MasonryItem />', () => {
expect(
style({
styleProps: {
contentHeight: 100,
height: 100,
columnSpan: 2,
spacing: 1,
},
Expand All @@ -93,38 +95,38 @@ describe('<MasonryItem />', () => {
gridColumnEnd: 'span 2',
});
});

it('should compute grid-row-end based on given height', () => {
const { getByTestId } = render(
<MasonryItem height={150} data-testid="test-root">
{children}
</MasonryItem>,
);
const computedStyle = getComputedStyle(getByTestId('test-root'));
expect(computedStyle['grid-row-end']).to.equal(
`span ${Math.ceil(150 + Number(theme.spacing(1).replace('px', '')))}`,
);
});
});

describe('props:', () => {
describe('prop: component', () => {
it('should render a div by default', () => {
let item = null;
act(() => {
const { container } = render(<MasonryItem>{children}</MasonryItem>);
item = container;
});
expect(item.firstChild).to.have.property('nodeName', 'DIV');
const { container } = render(<MasonryItem>{children}</MasonryItem>);
expect(container.firstChild).to.have.property('nodeName', 'DIV');
});

it('should render a different component', () => {
let item = null;
act(() => {
const { container } = render(<MasonryItem component="span">{children}</MasonryItem>);
item = container;
});
expect(item.firstChild).to.have.property('nodeName', 'SPAN');
const { container } = render(<MasonryItem component="span">{children}</MasonryItem>);
expect(container.firstChild).to.have.property('nodeName', 'SPAN');
});
});

describe('prop: className', () => {
it('should append the className to the root element', () => {
let item = null;
act(() => {
const { container } = render(<MasonryItem className="foo">{children}</MasonryItem>);
item = container;
});
expect(item.firstChild).to.have.class(classes.root);
expect(item.firstChild).to.have.class('foo');
const { container } = render(<MasonryItem className="foo">{children}</MasonryItem>);
expect(container.firstChild).to.have.class(classes.root);
expect(container.firstChild).to.have.class('foo');
});
});
});
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14297,11 +14297,6 @@ resize-observer-polyfill@^1.5.1:
resolved "https://registry.yarnpkg.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464"
integrity sha512-LwZrotdHOo12nQuZlHEmtuXdqGoOD0OhaxopaNFxWzInpEgaLWoVuAMbTzixuosCx2nEG58ngzW3vxdWoxIgdg==

resize-observer@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/resize-observer/-/resize-observer-1.0.2.tgz#9a87697b275343d12d8b371940e02e9a93e1f452"
integrity sha512-X0lHFNsxItpBRIRsdwOTkl/VguTaLGx7Gz9xoTGix9ObBN3jRYq9J/rSIuYDrey8AdU3IkfgIMpCeVSEW1QS0Q==

resolve-cwd@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-3.0.0.tgz#0f0075f1bb2544766cf73ba6a6e2adfebcb13f2d"
Expand Down

0 comments on commit fefd78a

Please sign in to comment.