-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from EastSun5566/develop
feat: develop
- Loading branch information
Showing
23 changed files
with
2,243 additions
and
1,244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import { CSSTransition } from 'react-transition-group'; | ||
|
||
import './App.scss'; | ||
|
||
import { | ||
UploadInput, | ||
Preview, | ||
GithubCorner, | ||
Note, | ||
} from '../components'; | ||
import { useFilters } from '../hooks'; | ||
|
||
const App: React.FC = () => { | ||
const [imageURL, setImageURL] = useFilters(); | ||
|
||
return ( | ||
<> | ||
<div id="app"> | ||
<h4 className="title my-3">🖼 CCgram</h4> | ||
|
||
<CSSTransition | ||
in={!!imageURL} | ||
timeout={200} | ||
classNames="fade" | ||
> | ||
{imageURL | ||
? ( | ||
<Preview | ||
imageURL={imageURL} | ||
onClear={() => setImageURL('')} | ||
/> | ||
) | ||
: ( | ||
<UploadInput | ||
onUpload={ | ||
({ target }) => target.files && setImageURL(URL.createObjectURL(target.files[0])) | ||
} | ||
/> | ||
)} | ||
</CSSTransition> | ||
|
||
<Note /> | ||
</div> | ||
|
||
<GithubCorner /> | ||
</> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import CCGram from 'cc-gram'; | ||
|
||
export const cg = new CCGram({ init: false }); | ||
|
||
export default cg; |
2 changes: 1 addition & 1 deletion
2
.../components/GithubCorner/GithubCorner.tsx → demo/src/components/GithubCorner/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
demo/src/components/Note/Note.tsx → demo/src/components/Note/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
|
||
import './UploadInput.scss'; | ||
|
||
interface UploadInputProps { | ||
onUpload?: (event: React.ChangeEvent<HTMLInputElement>) => void | ||
} | ||
|
||
export const UploadInput: React.FC<UploadInputProps> = ({ onUpload }) => ( | ||
<div className="input-container"> | ||
<i className="fas fa-cloud-upload-alt" /> | ||
<input | ||
type="file" | ||
accept="image/*" | ||
onChange={onUpload} | ||
/> | ||
</div> | ||
); | ||
|
||
export default UploadInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './GithubCorner'; | ||
export * from './Note'; | ||
export * from './Preview'; | ||
export * from './UploadInput'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './use-filters'; | ||
export * from './use-download-image'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useRef } from 'react'; | ||
import { cg } from '../cg'; | ||
|
||
interface useDownloadImageOptions { | ||
downloadFileName?: string; | ||
} | ||
|
||
export const useDownloadImage = ({ | ||
downloadFileName = 'download', | ||
}: useDownloadImageOptions = {}): { | ||
imageRef: React.RefObject<HTMLImageElement>; | ||
download: () => void; | ||
} => { | ||
const imageRef = useRef<HTMLImageElement>(null); | ||
|
||
const download = async () => { | ||
const { current } = imageRef; | ||
if (!current) throw new Error('No Image'); | ||
|
||
const a = document.createElement('a'); | ||
a.href = await cg.getDataURL(current); | ||
a.download = downloadFileName; | ||
a.click(); | ||
}; | ||
|
||
return { imageRef, download }; | ||
}; | ||
|
||
export default useDownloadImage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { cg } from '../cg'; | ||
|
||
interface useFiltersOptions { | ||
initialValue?: string; | ||
selectors?: string; | ||
} | ||
|
||
export const useFilters = ({ | ||
initialValue = '', | ||
selectors, | ||
}: useFiltersOptions = {}): [ | ||
string, | ||
React.Dispatch<React.SetStateAction<string>> | ||
] => { | ||
const [value, setValue] = useState(initialValue); | ||
|
||
useEffect(() => { | ||
cg.applyFilter(selectors); | ||
}, [value]); | ||
|
||
return [value, setValue]; | ||
}; | ||
|
||
export default useFilters; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.