Skip to content

Commit

Permalink
Merge pull request #29 from EastSun5566/develop
Browse files Browse the repository at this point in the history
chore: update demo
  • Loading branch information
EastSun5566 committed Jul 31, 2020
2 parents c738348 + 32df409 commit 28b400e
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 119 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
🔗 <https://eastsun5566.github.io/cc-gram/>

## 🤔 Why

> [CSSgram](https://github.com/una/CSSgram) is a great CSS filters library, but sometimes you want to access/download the filter image. Then CCgram come into the play. It use CSS to preview filters and draw filter image with canvas filter API when you need it.
## ✨ Install

```sh
Expand All @@ -32,12 +36,15 @@ npm i cc-gram
import CCGram from "cc-gram";

const cg = new CCGram();
```

```js
// or you can turn off init apply
const cg = new CCGram({ init: false });

// you can also specify data attribute
const cg = new CCGram({ dataAttribute: "my-cool-filter" });
// i.e., <img data-my-attr="1977">
const cg = new CCGram({ dataAttribute: "my-attr" });
```

---
Expand All @@ -50,7 +57,7 @@ const cg = new CCGram({ dataAttribute: "my-cool-filter" });
// apply to All targets has `data-filter` attribute
cg.applyFilter();

// or you can just use selector
// or you can just use selector for performance
cg.applyFilter("#my-image");
```

Expand Down Expand Up @@ -130,23 +137,23 @@ cg.removeFilter("my-filter");
### Access Filter image

```js
const target = document.querySelector('img[data-filter="1977"]');
const image = document.querySelector('img[data-filter="1977"]');
```

#### Data URL

> `getDataURL(image[, options = {}])`
```js
const dataUrl = await cg.getDataURL(target);
const dataUrl = await cg.getDataURL(image);
```

#### Blob

> `getBlob(image[, options = {}])`
```js
const blob = await cg.getBlob(target, {
const blob = await cg.getBlob(image, {
type: "image/jpeg",
quality: 0.8,
});
Expand All @@ -160,7 +167,7 @@ const blob = await cg.getBlob(target, {
## 🔧 Develop

```sh
# install dependencies
# install dep
yarn

# fix style
Expand All @@ -169,6 +176,6 @@ yarn lint
# run test
yarn test

# build for production
# build for prod
yarn build
```
45 changes: 3 additions & 42 deletions demo/README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,5 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
# CCgram demo site

## Available Scripts
## Dev

In the project directory, you can run:

### `yarn start`

Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br />
You will also see any lint errors in the console.

### `yarn test`

Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `yarn build`

Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `yarn eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
`yarn dev`
2 changes: 2 additions & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@types/node": "^14.0.27",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"@types/react-transition-group": "^4.4.0",
"babel-eslint": "10.1.0",
"babel-jest": "^26.1.0",
"babel-loader": "8.1.0",
Expand Down Expand Up @@ -57,6 +58,7 @@
"react-app-polyfill": "^1.0.5",
"react-dev-utils": "10.1.0",
"react-dom": "^16.12.0",
"react-transition-group": "^4.4.1",
"resolve": "1.17.0",
"resolve-url-loader": "3.1.1",
"sass-loader": "9.0.2",
Expand Down
28 changes: 5 additions & 23 deletions demo/src/App/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,11 @@
min-height: 100vh;
padding: 0 8px;
@include flex;
}

.input-container {
width: 100%;
max-width: 300px;
min-height: 100px;
border: 1px solid rgba($color-font, 0.5);
border-radius: 8px;

transition: background-color 0.3s;

&:hover {
background-color: rgba($color-font, 0.1);
}

i {
@include abs;
}
flex-direction: column;

input {
opacity: 0;
position: absolute;
@include size;
cursor: pointer;
.title {
color: $color-font;
background-color: $bg-dark;
padding: 8px;
}
}
23 changes: 20 additions & 3 deletions demo/src/App/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { FC, useState, useEffect } from 'react';
import { CSSTransition } from 'react-transition-group';

import './App.scss';

import UploadInput from '../components/UploadInput/UploadInput';
import Preview from '../components/Preview/Preview';
import GithubCorner from '../components/GithubCorner/GithubCorner';
import Note from '../components/Note/Note';

import { cg } from '../cg';

Expand All @@ -18,9 +20,24 @@ const App: FC = () => {
return (
<>
<div id="app">
{imageURL
? <Preview imageURL={imageURL} />
: <UploadInput setImageURL={setImageURL} /> }
<h4 className="title my-3">🖼 CCgram</h4>

<CSSTransition
in={!!imageURL}
timeout={200}
classNames="fade"
>
{imageURL
? (
<Preview
imageURL={imageURL}
setImageURL={setImageURL}
/>
)
: <UploadInput setImageURL={setImageURL} /> }
</CSSTransition>

<Note />
</div>

<GithubCorner />
Expand Down
19 changes: 19 additions & 0 deletions demo/src/assets/styles.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
$color-font: #eee;
$bg-dark: rgba(black, 0.8);

@mixin flex {
display: flex;
Expand All @@ -21,3 +22,21 @@ $color-font: #eee;
@mixin shadow {
box-shadow: 0 8px 16px rgba(black, 0.3);
}

.fade-enter {
opacity: 0;
}

.fade-enter-active {
opacity: 1;
transition: opacity 0.3s;
}

.fade-exit {
opacity: 1;
}

.fade-exit-active {
opacity: 0;
transition: opacity 0.3s;
}
2 changes: 1 addition & 1 deletion demo/src/components/GithubCorner/GithubCorner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './GithubCorner.scss';

const GithubCorner: React.FC = () => (
<a
href="https://github.com/EastSun5566/get-some-cool-emojis/"
href="https://github.com/EastSun5566/cc-gram"
className="github-corner"
aria-label="View source on GitHub"
title="View source on GitHub"
Expand Down
19 changes: 19 additions & 0 deletions demo/src/components/Note/Note.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';

const Note: React.FC = () => (
<small className="d-block text-center my-3">
Made with
<span role="img" aria-label="heart"> ❤️ </span>
By
<a
href="https://github.com/EastSun5566"
className="badge badge-pill badge-dark"
target="_blank"
rel="noreferrer"
>
EastSun5566
</a>
</small>
);

export default Note;
51 changes: 25 additions & 26 deletions demo/src/components/Preview/Preview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,36 @@
text-align: center;

.image-container {
max-width: 400px;
margin: 0 auto 16px auto;

&::after {
content: "\f381";
font-family: "Font Awesome 5 Free";
font-weight: 900;
position: absolute;
top: 0;
left: 0;

@include size;
background-color: rgba(black, 0.3);

@include flex;
cursor: pointer;

opacity: 0;
transition: opacity 0.3s;
pointer-events: none;
}

&:hover::after {
opacity: 1;
}
max-width: 375px;
margin: 0 auto 24px auto;

img {
display: block;
width: 100%;
@include shadow;
}

button {
position: absolute;
border-radius: 0;
@include size(38px);
background-color: $bg-dark;
padding: 0;

transition: transform 0.3s;

&.btn-cross {
top: 0;
right: 0;
transform: translate(50%, -50%);
}

&.btn-download {
left: 0;
bottom: 0;
transform: translate(-50%, 50%);
}
}
}

.filters-container {
Expand All @@ -54,7 +53,7 @@
transform: translateY(-3px);

figcaption {
background-color: rgba(black, 0.8);
background-color: $bg-dark;
}
}

Expand Down
Loading

0 comments on commit 28b400e

Please sign in to comment.