set images in grid of react dropzone uploaders - reactjs

I am confused in setting custom preview as like
image set in grid
I want to do this in react-dropzone-uploader custom preview, where I can upload multiple files.
Current scenario: my normal uploaded images
Code snippet:
const Preview = ({ meta }: IPreviewProps) => {
const { name, percent, status, previewUrl } = meta ;
return (
<Grid item xs={6}>
<div className="preview-box">
<img src={previewUrl} /> <span className="name">{name}</span> - <span className="status">{status}</span>{status !== "done" && <span className="percent"> ({Math.round(percent)}%)</span>}
</div>
</Grid>
)
}
<Dropzone
getUploadParams={getUploadParams}
onSubmit={handleSubmit}
PreviewComponent={Preview}
inputContent="Drop Files"
/>
I am using MUI V4
We don't have any index for images, how can I set images in grid view of 2-2 images using material UI?

You need to wrap the Grid items inside the Grid container.
Please have a look at the guide. https://mui.com/components/grid/
// Parent PreviewContainer.js
...
<Grid container spacing={2}>
{
images.map((image, i) => (
<PreviewItem key={i} meta={meta} />
))
}
</Grid>
...
// Child PreviewItem.js
...
<Grid item xs={4}>
// You can update the item size as you expect, but it seems like it should be 4 regarding the image attached
// Your preview component
</Grid>
...

Related

Implementing Persona Idv on NextJS

We are attempting to use an embedded Persona flow on our NextJS app.
Code as follows:
export default function PersonaTest(props) {
const PersonaInquiry = dynamic(() => import('persona').then((mod) => mod.Inquiry), { ssr: false });
const RenderFrame = () => (
<PersonaInquiry
templateId="itmpl_Ygs16MKTkA6obnF8C3Rb17dm"
environment="sandbox
frameHeight="900"
frameWidth="500"
parent="root"
onLoad={() => {
console.log('Loaded inline');
}}
onComplete={({ inquiryId, status, fields }) => {
// Inquiry completed. Optionally tell your server about it.
console.log(`Sending finished inquiry ${inquiryId} to backend`);
}}
/>
);
return (
<>
<Grid container spacing={2} style={{ paddingTop: 400 }}>
<Grid item xs={12} sm={6}>
<div id="root" />
<RenderFrame />
</Grid>
</Grid>
</>
);
}
The Persona component renders and imbedded iframe to allow an idv flow.
The Persona widget is rendered but in a very small frame.
It seems the params frameHeight, frameWidth and parent are being ignored.
Why dynamic rendering is needed to allow the component to render the iframe (if not, it will throw 'self' type errors).
Persona support is unable to diagnose/help.
What am I doing wrong?
Thanks!
I have tried numerous options to set the frame height and width.
I had a similar issue and found this when I was troubleshooting - frameHeight and frameWidth only set the max height and width. Persona's docs recommend targeting the general iframe tag from a parent container and that ended up working for me. I wrapped my PersonaInquiry tag in a styled component and targeted child iframe tags from there. Hope that helps!

Image slider for Light gallery React

I'm using light gallery for the image viewer. The problem here is when i have multiple images all those are stacked in rows with 2 images in a row and i have 10 rows for 20 images. So i'm trying to integrate a custom carousel in the light gallery with which i'll have one row of images and a slider.
Both work individually well but couldn't integrate. Also wanted to know if the light gallery has an slider inbuilt.
//Light gallery code:
<LightGallery speed={100} download={true} plugins={[lgThumbnail]} mode="lg-fade" >
{
abc.xyz.attachments.map((item: any) => {
let fileName = item.split('/').pop();
return (
<a
data-lg-size="1400-933"
className="gallery-item"
data-src={item}
data-sub-html={"<h4>" + fileName + "</h4>"}
>
<img style={{ margin: '10px' }}
className="img-responsive"
src={item} width={240} height={160}
/>
</a>
)
})
}
</LightGallery>
//Carousel Code:
<Carousel items={abc.xyz.attachments} />
Any help?

ReactJS MUI Component not rendering inside map function

I am using ReactJS along with Material UI Components. I am trying to render a custom element using the below code. The options array is never empty and the console logs are showing as expected - "Adding element to grid ..". However, the element is not rendered on the browser(I checked the browser Inspector to confirm).
What am I missing?
import React from "react";
import Container from "#mui/material/Container";
import Grid from "#mui/material/Grid";
const Element = (props) => {
const {options} = props;
return(
// If I simply pass a JSX component at this location, it renders fine.
// But not inside the map function
{options.map((opt) => {
opt.elements.length > 0 && (
<Grid container spacing={4}>
{opt.elements.map((el) => (
<Grid item xs={12} sm={6}>
{console.log("Adding element to grid ..", el.element_name)}
<h1>{el.element_name}</h1>
</Grid>
))}
</Grid>
);
})}
)
}
You should use parentheses instead of curly brackets inside the first map in the return()
{options.map((opt) => (
opt.elements.length > 0 && (
<Grid container spacing={4}>
{opt.elements.map((el) => (
<Grid item xs={12} sm={6}>
{console.log("Adding element to grid ..", el.element_name)}
<h1>{el.element_name}</h1>
</Grid>
))}
</Grid>
);
))}

How to render images in React JS

I am new to coding so please bear with me -
I am trying to create a dynamic gallery display, in which all the images will be taken from the database and should render in the overall layout as below.
Expected Result
I am unable to make it render in this manner instead it shows second image on repeat for 3rd image position.
Current Result
Attaching the code below which I currently have, any feedback/suggestion would be of great help to me. Thanks in advance.
Data:-
const GALLERY = [
{
qty:1, img_path:`${AMAZON_URL}/Gallery/1.jpg`,
},
{
qty:2, img_path:`${AMAZON_URL}/Gallery/2.jpg`,
},
{
qty:2, img_path:`${AMAZON_URL}/Gallery/3.jpg`,
},
{
qty:1, img_path:`${AMAZON_URL}/Gallery/4.jpg`,
},
{
qty:2, img_path:`${AMAZON_URL}/Gallery/5.jpg`,
},
{
qty:2, img_path:`${AMAZON_URL}/Gallery/6.jpg`,
},
]
{GALLERY.map((item, index) => (
<>
{item.qty === 1?
<Grid item xs="6" my="2" key={index}>
<img className="W100" src={item.img_path} />
</Grid>
:
<Grid item xs="6" my="2" key={index}>
<img className="W100" src={item.img_path} />
<img className="W100" src={item.img_path} />
</Grid>
}
</>
))}
Depending on image sizes you would have more success ditching the col and having the images modified inside the Grid with CSS. If the images are appropriately sized something like this could work.
<Grid>
{GALLERY.map((item, index) => (
<img className="W100" src={item.img_path} />
))}
</Grid>
img {
width:50%;
float:left;
}

How to send unique props to similar Parents?

I currently made a custom component that acts similar to a carousel called Scrollbar. When I select a specific item it dynamically loads the information and displays a content div that has information on the item such as id, name, thumbnail-Image, etc..
The problem I am trying to solve is that I want to display multiple Scrollbars and only have one content div active at a time. The issue is that each Scrollbar has their own content div. I need a way to communicate which one is active.
I'm thinking possibly I need another component lets call it Home that displays multiple Scrollbars and onClick, it sets the current one Active and the rest inActive. All the Scrollbars should still be displaying however, one dynamic content div will appear below the active Scrollbar.
This sounds like I need to send one Scrollbar's prop isActive = true and the others isActive = false. I am unsure how to achieve this.
Here are short versions of my components:
Scrollbar.js
const Scrollbar = ({category, isActive }) => {
return (
<div className="scrollbar">
<h2>{category}</h2>
<div className="item-wrapper" style={{maxWidth: `${scrollbarWidth}px`}}>
.
.
.
.
//Handles Navigating the Scrollbar Left and Right
<SlideButton type="prev" onClick={handlePrev}/>
<SlideButton type="next" onClick={handleNext}/>
</div>
//Dynamic Content gets shown here when user clicks on an item & Scrollbar (tbd)
{isActive && currentCard && <Content activeCard={currentCard} clickFunc={handleCardChange} /> }
</div>
);
}
export default Scrollbar;
Home.js
const Home = () => {
return (
<div className="home">
<Scrollbar key="0" category="Scroll 1" activeBar={null} />,
<Scrollbar key="1" category="Scroll 2" activeBar={null} />
</div>
);
}
export default Home;
The Home component should hold the id of who is the activeBar with useState. It should pass setActiveBar to each Scrollbar.
const Home = () => {
const [activeBar, setActiveBar] = useState(0)
return (
<div className="home">
<Scrollbar
key="0"
id="0"
category="Scroll 1"
activeBar={activeBar}
setActiveBar={setActiveBar}
/>,
<Scrollbar
key="1"
id="1"
category="Scroll 2"
activeBar={activeBar}
setActiveBar={setActiveBar}
/>
</div>
);
}
The Scrollbar component should check if it's id is identical to activeBar, and set isActive accordingly. It should also set itself to be the activeBar when clicked.
const Scrollbar = ({category, id, activeBar, onClick }) => {
const isActive = activeBar === id;
return (
<div
onClick={() => setActiveBar(id)}
className="scrollbar"
>

Resources