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

Remove Emotion and add inline css #127

Merged
merged 12 commits into from
May 15, 2020
12 changes: 8 additions & 4 deletions scripts/copy-build-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import path from 'path'
import fse from 'fs-extra'

async function copyFile(file) {
const buildPath = path.resolve(__dirname, '../dist/', path.basename(file))
await fse.copy(file, buildPath)
console.log(`Copied ${file} to ${buildPath}`)
const buildPath = path.resolve(__dirname, '../dist/', path.basename(file.to || file.from))
await fse.copy(file.from, buildPath)
console.log(`Copied ${file.from} to ${buildPath}`)
}

async function createPackageFile() {
Expand Down Expand Up @@ -34,7 +34,11 @@ async function createPackageFile() {
}

async function run() {
await Promise.all(['./README.md'].map(file => copyFile(file)))
await Promise.all(
[{ from: './README.md' }, { from: './src/styles.css', to: 'react-easy-crop.css' }].map(file =>
copyFile(file)
)
)
await createPackageFile()
}

Expand Down
11 changes: 7 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Props = {
restrictPosition: boolean
initialCroppedAreaPixels?: Area
mediaProps: React.ImgHTMLAttributes<HTMLElement> | React.VideoHTMLAttributes<HTMLElement>
disableDefaultStyles?: boolean
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest: disableAutomaticFileInjection

}

type State = {
Expand Down Expand Up @@ -101,10 +102,12 @@ class Cropper extends React.Component<Props, State> {
this.containerRef.addEventListener('gesturechange', this.preventZoomSafari)
}

this.styleRef = document.createElement('style')
this.styleRef.setAttribute('type', 'text/css')
this.styleRef.innerHTML = cssStyles
document.head.appendChild(this.styleRef)
if (!this.props.disableDefaultStyles) {
this.styleRef = document.createElement('style')
this.styleRef.setAttribute('type', 'text/css')
this.styleRef.innerHTML = cssStyles
document.head.appendChild(this.styleRef)
}

// when rendered via SSR, the image can already be loaded and its onLoad callback will never be called
if (this.imageRef && this.imageRef.complete) {
Expand Down