This repository is a Software of Application with React,NodeJS,SASS,etc
Using NodeJS, React preferably.
AOS, React Transitions Group, React Reveal,etc
$ git clone https://github.com/DanielArturoAlejoAlvarez/react-masonry-layout[NAME APP]
$ npm install
$ yarn install
Follow the following steps and you're good to go! Important:
...
const App = () => {
const [cols, setCols] = useState(3);
const [CSSTransitions, setCSSTransitions] = useState("");
useEffect(() => {
setCSSTransitions("ball");
}, [cols]);
return (
<main className={CSSTransitions}>
<Fade isOpen={true}>
<Masonry cols={cols} gutter={2} />
</Fade>
</main>
);
};
...
...
export const Masonry = (props) => {
const gutter = {
gridGap: `${props.gutter}rem`,
};
const [data, setData] = useState([]);
const [columnElements] = useState([]);
const [gallery, setGallery] = useState("");
const [values] = useState({
columns: props.cols,
});
useEffect(() => {
setData(images.gallery);
setGallery(`gallery masonry-layout columns-${values.columns}`);
masonryLayout(
document.getElementById("gallery"),
document.querySelectorAll(".gallery-item"),
values.columns,
columnElements
);
}, [data, values, columnElements]);
return (
<div className={gallery} style={gutter} id="gallery">
{!data ? (
<div>Loading...</div>
) : (
data.map((item, index) => (
<Item
id={item.id}
url_image={item.url_image}
caption={item.caption}
key={index}
/>
))
)}
</div>
);
};
...
...
export const masonryLayout = (container, elements, cols, columnElements) => {
for (let i = 1; i <= cols; i++) {
let column = document.createElement("div");
column.classList.add("masonry-column", `column-${i}`);
container.appendChild(column);
columnElements.push(column);
}
for (let m = 0; m < Math.ceil(elements.length / cols); m++) {
for (let n = 0; n < cols; n++) {
let item = elements[m * cols + n];
columnElements[n].appendChild(item);
item.classList.add("masonry-item");
}
}
};
...
...
.masonry-layout {
--columns: 1;
--gap: 2rem;
$columns: 8;
display: grid;
grid-template-columns: repeat(var(--columns), 1fr);
grid-gap: var(--gap);
.masonry-item {
margin-bottom: var(--gap);
}
@for $i from 1 through $columns {
&.columns-#{$i} {
--columns: #{$i}
}
}
}
...
Bug reports and pull requests are welcome on GitHub at https://github.com/DanielArturoAlejoAlvarez/react-masonry-layout. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.