Tips for customizing image-cropping functionality within a modal with material UI

When it comes to positioning elements on a basic page using CSS, I consider myself decently skilled. However, things get confusing when working inside a modal.

I attempted to use the Dialog component from mui-material to wrap the cropper, but that approach didn't work out as expected. So, I resorted to using the Modal component instead.

My goal is to create something similar to this design which includes only the cropper section, cancel and crop buttons. The buttons should be positioned outside of the cropper with a white background. https://i.stack.imgur.com/QUA59.png

While my modal is functional, its appearance isn't quite up to par yet: https://i.stack.imgur.com/SFgAV.png

This is the code snippet:

// Your code goes here...

Here's the corresponding CSS:


.container {
  height: 100vh;
  width: 70vw;
}

.modal_container {
  position: relative;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 500px;
  height: 70%;
  background-color: whitesmoke;
  box-shadow: 24px;
  padding: 4px;
}

.image_container {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.cropper{
  background-color: red;
}

.slider {
  height: 10%;
}

.slider_container{
  background: white;
  display:flex;
  justify-content: end;
  align-items: center;
}

.disable_cropper {
  display: none;
}

.button_container {
  position: absolute;
}

Answer №1

When working with DialogContent, consider utilizing the Box component to enhance its visual appeal. Additionally, incorporating the Grid component can greatly improve the overall design.

<Box
                alignItems="center"
                justifyContent="center"
                minHeight={400}
                width={"100%"}
                display="flex"
            > 
<ReactCrop
                    crop={crop}
                    onChange={(_, percentCrop) => setCrop(percentCrop)}
                    onComplete={(c) => setCompletedCrop(c)}
                    aspect={3 / 2}
                    minWidth={100}
                    style={{borderRadius: 12}}
                >
                    <img
                        ref={imgRef}
                        alt="Crop me"
                        src={imgSrc}
                        style={{transform: `scale(${scale}) rotate(${rotate}deg)`, borderRadius: 12}}
                        onLoad={onImageLoad}
                    />
                </ReactCrop>

            </Box>

https://i.stack.imgur.com/d0jjf.jpg

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In configuring the print settings, I specified margins to ensure proper formatting. However, I noticed that the margin adjustment only applies to the first page. I need

I have a method that retrieves margin top value from the backend. It works perfectly on the first page of print, but on the second page, the margin top space is missing. initializePrintingSettings() { this.printService.fetchPrintSettings().subscribe(respon ...

The hierarchy of importance in React ViteJs for CSS modules

Working on my React project with ViteJs, I rely on Material UI for the theme and components. To maintain code readability, especially for elements requiring multiple style property lines, I decided to create a separate module.scss file to handle the CSS as ...

Can someone assist me in creating a clickable link that opens a menu in HTML when clicked?

I have been attempting for the past few days to open the megamenu by clicking on a link, but despite my efforts, I have not been successful. After reviewing some code, I discovered a clue in the CSS. It seems that setting the visibility value to visible wi ...

I am looking to set an HTML file as the homepage for my Next.js project

Is there a way in next.js to render a normal .html file (index.html) when someone visits my root directory at "https://example.com/"? I have researched and edited my config file as shown below, /** @type {import('next').NextConfig} */ const next ...

Adsense ad unit is not responsive and fails to display properly at dimensions of 320x50 px

I have a unique banner ad that I want to display as the footer on my responsive website. Using media queries recommended in the advertising documentation, I am adjusting the size based on different screen widths. Check out the CSS code below: <style&g ...

Utilizing Props to Manage State within Child Components

Is it possible to assign the props received from a Parent Component as the state of a Component? export default class SomeComp extends Component { constructor(props) { super(props); this.state = someProps; // <-- I want to set the ...

In React (Next.js), the act of replacing a file is performed instead of adding a file

I kindly request a review of my code prior to making any changes. const test = () => { const [files, setFiles] = useState ([]); //I believe I need to modify the following statement. const handleFile = (e) => { const newFiles = [] for (let i= ...

Guide on adding the .html extension to your URL in Nextjs

In my Nextjs 13.5.2 page directory setup, I am facing a requirement to add ".html" to the URL for SEO purposes on Baidu. For instance: www.test.com/news/123 -> www.test.com/news/123.html I have attempted the following: Renaming the filename to [slug].ht ...

Adapt appearance according to the length of the text

Currently, I have an array that stores multiple strings based on displayed charts. My objective is to find the longest string within this array. So far, this task has been executed without any issues. The code snippet for this process is as follows: var ...

Leap over in a similar fashion to the provided demonstration

In my attempt to create a unique project, I have created this CodePen example. The goal is to have one ball on the circle that remains in a fixed position, while another rotating main ball must avoid touching it at all costs. Points are awarded for success ...

Modify the cursor pointer style in MUI Link using React

Is there a way to customize the cursor pointer style on MUI Link? I've tried using the 'cursor: pointer' style but it doesn't seem to work. Here is my code: <Link style={{ cursor: 'pointer' }} onClick={() => { ...

In the onMenuClose or onBlur event of the react-select component, detect whether the event was triggered by selecting an option or by clicking outside

When using React, the onBlur event or onMenuClose event are activated when a user either selects an option or clicks outside of the control. If the user has not chosen an option, I would like to execute some business logic on the blur event. Simply put, ...

What is the best way to create a line break in a React caption without it being visible to the user?

Is there a way to add a break or invisible character between "we make it simple" and "to create software" in order to match the Figma design for the React web app caption? https://i.stack.imgur.com/Z4rpt.png https://i.stack.imgur.com/06mMO.jpg https://i.s ...

React application not displaying element properly?

I am facing an issue with my react modal that displays a sign-in and sign-up form. The problem arises when I try to access the button on the form using its id, which is modal-sign-in-submit-button. document.getElementById('modal-sign-in-submit-button ...

The iFrame is set to a standard width of 300 pixels, with no specific styling to dictate the size

My current challenge involves utilizing the iframe-resizer package to adjust the size of an iframe dynamically based on its content. However, even before attempting any dynamic resizing, I encounter a fundamental issue with the basic iframe: it stubbornly ...

Revamping the Drawer Contents

Is there a way to dynamically change content upon clicking different items? I have two separate archives, Sidebar.js where items are declared, and Home.js where buttons are placed. However, I am unsure how to pass the information needed to switch between t ...

Discover the best practices for integrating media queries using Radium within Material UI components

Having trouble applying a breakpoint to the Material UI component, Raised button. I have managed to make it work for regular divs, but not for the Material UI component. I attempted wrapping the button inside Radium import RaisedButton from 'materia ...

Having trouble with clicking on an icon link within a list

Seeking assistance with creating a social media icon/link list for the first time on this platform. Any help is appreciated! <div class="social-links"> <ul> <li class="m-link"> <a href="&q ...

Pagination with React Material UI is a user-friendly and visually

Requirement Within the Material UI framework, I need to implement pagination functionality by clicking on the page numbers (e.g., 1, 2) to make an API call with a limit of 10 and an offset incrementing from 10 after the initial call. https://i.stack.imgur. ...

Error in Vercel Deployment: Module 'next/dist/shared/lib/router/utils/resolve-href.js' Not Found

I've recently delved into building a React app using the NextJS framework for the first time. Everything seemed to be running smoothly when testing locally with npm run build or npm run dev, but I encountered errors when attempting to deploy it on Ver ...