Skip to content

Commit

Permalink
2.0.0 release A.K.A Typescript rewrite (#88)
Browse files Browse the repository at this point in the history
* Migrate to typescript

* Switch build step to Bili

* Add eslint config

* More cleaning

* Switch doc to TS

* Fix docs typing

* Update dist structure

* Update version

* try fixing codesandbox ci

* Update build package.json file

* extends main tsconfig for docs
  • Loading branch information
ValentinH authored Jan 5, 2020
1 parent 359de79 commit 62af875
Show file tree
Hide file tree
Showing 35 changed files with 8,229 additions and 3,938 deletions.
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ jobs:
key: dependency-cache-{{ checksum "yarn.lock" }}
paths:
- ~/.cache ## cache both yarn and Cypress
- run:
name: Run linting
command: |
yarn lint
- run:
name: Run unit tests
command: |
Expand Down
5 changes: 4 additions & 1 deletion .codesandbox/ci.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"sandboxes": ["v69ly910ql"]
"sandboxes": ["v69ly910ql"],
"publishDirectory": {
"react-easy-crop": "dist"
}
}
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
docs/.cache
dist
.yalc
14 changes: 14 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": [
"plugin:@typescript-eslint/recommended",
"react-app",
"prettier",
"prettier/@typescript-eslint",
"prettier/react"
],
"plugins": ["@typescript-eslint/eslint-plugin"],
"rules": {
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/ban-ts-ignore": 0
}
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 ricardo.ch
Copyright (c) 2020 ricardo.ch

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
60 changes: 29 additions & 31 deletions README.md

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions bili.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Config } from 'bili'

const config: Config = {
input: {
index: 'src/index.tsx',
},
output: {
format: ['cjs', 'umd', 'umd-min', 'esm'],
moduleName: 'ReactEasyCrop',
sourceMap: true,
},
globals: {
react: 'React',
},
extendConfig(config, { format }) {
if (format.startsWith('umd')) {
config.output.fileName = 'umd/react-easy-crop[min].js'
}
if (format === 'esm') {
config.output.fileName = '[name].module.js'
}
return config
},
env: {
NODE_ENV: 'production',
},
}

export default config
1 change: 1 addition & 0 deletions docs/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
author: `@ricardo-ch`,
},
plugins: [
`gatsby-plugin-typescript`,
`gatsby-plugin-react-helmet`,
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
Expand Down
12 changes: 8 additions & 4 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
"deploy": "yarn build --prefix-paths && gh-pages -d public"
},
"dependencies": {
"@material-ui/core": "^3.9.2",
"@material-ui/icons": "^3.0.2",
"@material-ui/lab": "^3.0.0-alpha.30",
"@material-ui/core": "^4.8.2",
"@material-ui/icons": "^4.5.1",
"gatsby": "^2.2.5",
"gatsby-image": "^2.0.34",
"gatsby-plugin-manifest": "^2.0.24",
Expand All @@ -24,18 +23,23 @@
"gatsby-plugin-prefetch-google-fonts": "^1.4.0",
"gatsby-plugin-react-helmet": "^3.0.10",
"gatsby-plugin-sharp": "^2.0.30",
"gatsby-plugin-typescript": "^2.1.23",
"gatsby-source-filesystem": "^2.0.27",
"gatsby-transformer-sharp": "^2.1.17",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-easy-crop": "^1.16.1",
"react-easy-crop": "2.0.0-beta.1",
"react-helmet": "^5.2.0"
},
"repository": {
"type": "git",
"url": "https://github.com/ricardo-ch/react-easy-crop"
},
"devDependencies": {
"@types/node": "^13.1.2",
"@types/react": "^16.9.17",
"@types/react-dom": "^16.9.4",
"@types/react-helmet": "^5.0.14",
"gh-pages": "^2.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState } from 'react'
import FilledInput from '@material-ui/core/FilledInput'
import FormControl from '@material-ui/core/FormControl'
import InputLabel from '@material-ui/core/InputLabel'
import MenuItem from '@material-ui/core/MenuItem'
import FilledInput from '@material-ui/core/FilledInput'
import Select from '@material-ui/core/Select'
import { withStyles } from '@material-ui/core/styles'
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles'
import React, { useState } from 'react'

const sandboxes = [
{ id: 'v69ly910ql', title: 'Basic with hooks' },
Expand All @@ -14,22 +14,25 @@ const sandboxes = [
{ id: '53w20p2o3n', title: 'With round crop area and no grid' },
]

const styles = theme => ({
formControl: {
marginBottom: theme.spacing.unit,
minWidth: 280,
},
})
const useStyles = makeStyles((theme: Theme) =>
createStyles({
formControl: {
marginBottom: theme.spacing(1),
minWidth: 280,
},
})
)

const CodeSandboxes = ({ classes }) => {
const CodeSandboxes: React.FC = props => {
const classes = useStyles(props)
const [sandbox, setSandbox] = useState('v69ly910ql')
return (
<div>
<FormControl variant="filled" className={classes.formControl}>
<InputLabel htmlFor="sandbox-example">Example</InputLabel>
<Select
value={sandbox}
onChange={e => setSandbox(e.target.value)}
onChange={e => setSandbox(String(e.target.value))}
input={<FilledInput name="example" id="sandbox-example" />}
>
{sandboxes.map(s => (
Expand Down Expand Up @@ -57,4 +60,4 @@ const CodeSandboxes = ({ classes }) => {
)
}

export default withStyles(styles)(CodeSandboxes)
export default CodeSandboxes
47 changes: 0 additions & 47 deletions docs/src/components/Demo/ImgDialog/index.js

This file was deleted.

64 changes: 64 additions & 0 deletions docs/src/components/Demo/ImgDialog/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import AppBar from '@material-ui/core/AppBar'
import Dialog from '@material-ui/core/Dialog'
import IconButton from '@material-ui/core/IconButton'
import Slide from '@material-ui/core/Slide'
import { createStyles, makeStyles, Theme, useTheme } from '@material-ui/core/styles'
import Toolbar from '@material-ui/core/Toolbar'
import Typography from '@material-ui/core/Typography'
import useMediaQuery from '@material-ui/core/useMediaQuery'
import CloseIcon from '@material-ui/icons/Close'
import React from 'react'

const useStyles = makeStyles((theme: Theme) =>
createStyles({
appBar: {
position: 'relative',
},
flex: {
flex: 1,
},
img: {
display: 'block',
margin: 'auto',
maxWidth: '100%',
maxHeight: '100%',
},
})
)

type Props = {
img: HTMLImageElement['src'] | null
onClose: () => void
}

function Transition(props) {
return <Slide direction="up" {...props} />
}

const ImgDialog = ({ img, onClose, ...rest }: Props) => {
const classes = useStyles(rest)
const theme = useTheme()
const isAtLeastXs = useMediaQuery(theme.breakpoints.up('xs'))
return (
<Dialog
fullScreen={!isAtLeastXs}
open={!!img}
onClose={onClose}
TransitionComponent={Transition}
>
<AppBar className={classes.appBar}>
<Toolbar>
<IconButton color="inherit" onClick={onClose} aria-label="Close">
<CloseIcon />
</IconButton>
<Typography variant="h6" color="inherit" className={classes.flex}>
Cropped image
</Typography>
</Toolbar>
</AppBar>
<img src={img} alt="Cropped" className={classes.img} />
</Dialog>
)
}

export default ImgDialog
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
function getRadianAngle(degreeValue) {
import { Area } from 'react-easy-crop/dist/types'

function getRadianAngle(degreeValue: number) {
return (degreeValue * Math.PI) / 180
}

export const createImage = url =>
export const createImage = (url: string): Promise<HTMLImageElement> =>
new Promise((resolve, reject) => {
const image = new Image()
image.addEventListener('load', () => resolve(image))
Expand All @@ -13,11 +15,12 @@ export const createImage = url =>

/**
* This function was adapted from the one in the ReadMe of https://github.com/DominicTobias/react-image-crop
* @param {File} image - Image File url
* @param {Object} pixelCrop - pixelCrop Object provided by react-easy-crop
* @param {number} rotation - optional rotation parameter
*/
export default async function getCroppedImg(imageSrc, pixelCrop, rotation = 0) {
export default async function getCroppedImg(
imageSrc: string,
pixelCrop: Area,
rotation = 0
): Promise<string> {
const image = await createImage(imageSrc)
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
Expand Down
Loading

0 comments on commit 62af875

Please sign in to comment.