Skip to content

Commit

Permalink
site update
Browse files Browse the repository at this point in the history
  • Loading branch information
lavrton committed Aug 11, 2020
1 parent 5291745 commit f260375
Show file tree
Hide file tree
Showing 17 changed files with 277 additions and 124 deletions.
118 changes: 68 additions & 50 deletions react-demos/basic_demo/src/index.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,75 @@
import React, { Component } from 'react';
import Konva from 'konva';
import React from 'react';
import { render } from 'react-dom';
import { Stage, Layer, Star, Text } from 'react-konva';

class App extends Component {
handleDragStart = e => {
e.target.setAttrs({
shadowOffset: {
x: 15,
y: 15
},
scaleX: 1.1,
scaleY: 1.1
});
};
handleDragEnd = e => {
e.target.to({
duration: 0.5,
easing: Konva.Easings.ElasticEaseOut,
scaleX: 1,
scaleY: 1,
shadowOffsetX: 5,
shadowOffsetY: 5
});
function generateShapes() {
return [...Array(10)].map((_, i) => ({
id: i.toString(),
x: Math.random() * window.innerWidth,
y: Math.random() * window.innerHeight,
rotation: Math.random() * 180,
isDragging: false,
}));
}

const INITIAL_STATE = generateShapes();

const App = () => {
const [stars, setStars] = React.useState(INITIAL_STATE);

const handleDragStart = (e) => {
const id = e.target.id();
setStars(
stars.map((star) => {
return {
...star,
isDragging: star.id === id,
};
})
);
};
render() {
return (
<Stage width={window.innerWidth} height={window.innerHeight}>
<Layer>
<Text text="Try to drag a star" />
{[...Array(10)].map((_, i) => (
<Star
key={i}
x={Math.random() * window.innerWidth}
y={Math.random() * window.innerHeight}
numPoints={5}
innerRadius={20}
outerRadius={40}
fill="#89b717"
opacity={0.8}
draggable
rotation={Math.random() * 180}
shadowColor="black"
shadowBlur={10}
shadowOpacity={0.6}
onDragStart={this.handleDragStart}
onDragEnd={this.handleDragEnd}
/>
))}
</Layer>
</Stage>
const handleDragStart = (e) => {
setStars(
stars.map((star) => {
return {
...star,
isDragging: false,
};
})
);
}
}
};

return (
<Stage width={window.innerWidth} height={window.innerHeight}>
<Layer>
<Text text="Try to drag a star" />
{stars.map((star) => (
<Star
key={star.id}
id={star.id}
x={star.x}
y={star.y}
numPoints={5}
innerRadius={20}
outerRadius={40}
fill="#89b717"
opacity={0.8}
draggable
rotation={star.rotation}
shadowColor="black"
shadowBlur={10}
shadowOpacity={0.6}
shadowOffsetX={start.isDragging ? 10 : 5}
shadowOffsetY={start.isDragging ? 10 : 5}
scaleX={start.isDragging ? 1.2 : 1}
scaleY={start.isDragging ? 1.2 : 1}
onDragStart={handleDragStart}
onDragEnd={handleDragEnd}
/>
))}
</Layer>
</Stage>
);
};

render(<App />, document.getElementById('root'));
22 changes: 14 additions & 8 deletions scripts/helpers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var links = {
index: 'https://github.com/konvajs/konva'
index: 'https://github.com/konvajs/konva',
};

hexo.extend.helper.register('github_link', function(data) {
hexo.extend.helper.register('github_link', function (data) {
var match = data.file.match(/(\w+)\/lib\/(.+)/),
name = match[1],
path = 'lib/' + match[2];
Expand All @@ -29,22 +29,28 @@ hexo.extend.helper.register('github_link', function(data) {
);
});

hexo.extend.helper.register('item_flags', function(data) {
hexo.extend.helper.register('item_flags', function (data) {
var result = '';

['static', 'chainable', 'async', 'final'].forEach(function(i) {
['static', 'chainable', 'async', 'final'].forEach(function (i) {
if (data[i])
result += '<span class="api-item-flag ' + i + '">' + i + '</span>';
});

return result;
});

hexo.extend.helper.register('page_nav', function() {
var sidebar = this.theme.doc_sidebar,
path = this.path.replace(/^docs\//, ''),
hexo.extend.helper.register('page_nav', function () {
var sidebar = Object.assign(
{},
this.theme.doc_sidebar,
this.theme.react_sidebar,
this.theme.vue_sidebar,
this.theme.demo_sidebar
);
(path = this.path.replace(/^docs\//, '')),
// path = this.path,
list = {};
(list = {});

for (var i in sidebar) {
for (var j in sidebar[i]) {
Expand Down
50 changes: 50 additions & 0 deletions source/docs/react/Intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
title: react-konva - declarative canvas components for React
layout: react_page
---

```bash
npm install react-konva konva
```



<div class="features">
<div class="feature"><img src="/assets/features/undraw_abstract_x68e.svg" />
<h3 class="desc">All common shapes for graphical applications</h3>
</div>
<div class="feature"><img src="/assets/features/undraw_file_sync_ot38.svg" />
<h3 class="desc">Support for desktop and mobile devices</h3>
</div>
<div class="feature"><img src="/assets/features/undraw_fitting_pieces_cli3.svg" />
<h3 class="desc">Node nesting, grouping and event bubbling</h3>
</div>
<div class="feature"><img src="/assets/features/undraw_image_viewer_wxce.svg" />
<h3 class="desc">Hight quality exports into data URLs, image data, or image objects</h3>
</div>
</div>

## How it looks?

```js
import { Stage, Layer, Rect } from 'react-konva';

export const App = () => {
return (
// Stage - is a div wrapper
// Layer - is an actual 2d canvas element, so you can clear several layers inside the stage
// Rect and Circle are not DOM elements. It is 2d shapes on canvas
<Stage width={window.innerWidth} height={window.innerHeight}>
<Layer>
<Rect width={50} height={50} fill="red" />
<Circle x={200} y={200} stroke="black" radius={50} />
</Layer>
<Stage>
);
}
```

## Demo

<iframe src="https://codesandbox.io/embed/github/konvajs/site/tree/master/react-demos/basic_demo?hidenavigation=1&view=split&fontsize=10" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>

<div id="intro-btn-wrap" style="margin-bottom: 50px"><a id="intro-btn" href="/docs/react/index.html">Get Started</a></div>
57 changes: 57 additions & 0 deletions source/docs/react/_index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
layout: react_page
title: react-konva - declarative canvas components for React
description: react-konva is react library for canvas for drawings shapes, animations, node nesting, layering, filtering, event handling, drag and drop and much more.
comments: false
---
.intro-wrap

.outer

h2.intro-features Features

.features
.feature
img(src="/assets/features/undraw_abstract_x68e.svg")
h3.desc Object Oriented API with support of many shapes
.feature
img(src="/assets/features/undraw_file_sync_ot38.svg")
h3.desc Support for desktop and mobile devices

.feature
img(src="/assets/features/undraw_animating_1rgh.svg")
h3.desc Animations and tweens

.feature
img(src="/assets/features/undraw_fitting_pieces_cli3.svg")
h3.desc Node nesting, grouping and event bubbling

.feature
img(src="/assets/features/undraw_image_viewer_wxce.svg")
h3.desc Hight quality exports into data URLs, image data, or image objects

.feature
img(src="/assets/features/undraw_options_2fvi.svg")
h3.desc Nice read-to-use filters

.feature
img(src="/assets/features/undraw_voice_interface_eckp.svg")
h3.desc Native integration with web frameworks such as React and Vue

.feature
img(src="/assets/features/undraw_drag_5i9w.svg")
h3.desc Built-in Drag&drop support

h2.intro-features Demo

iframe(src='https://codesandbox.io/embed/github/konvajs/site/tree/master/react-demos/basic_demo?hidenavigation=1&view=split&fontsize=10',style='width:100%; height:600px; box-shadow: 0 0 10px grey; border-radius: 4px; overflow:hidden;',sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin")



#intro-btn-wrap
a.add-app(href="https://github.com/konvajs/konva/issues/256") Do you want to add your app here?



.outer
#intro-btn-wrap
a#intro-btn(href="/docs/index.html") Get Started
14 changes: 7 additions & 7 deletions source/docs/react/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ title: Getting started with react and canvas via Konva
layout: react_page
---

![ReactKonva Logo](https://cloud.githubusercontent.com/assets/1443320/12193428/3bda2fcc-b623-11e5-8319-b1ccfc95eaec.png)
<div style="text-align: center">
<img src="https://cloud.githubusercontent.com/assets/1443320/12193428/3bda2fcc-b623-11e5-8319-b1ccfc95eaec.png"/>
</div>

React Konva is a JavaScript library for drawing complex canvas graphics using [React](http://facebook.github.io/react/). It provides declarative and reactive bindings to the [Konva Framework](https://konvajs.org/).
`react-konva` is a JavaScript library for drawing complex canvas graphics using [React](http://facebook.github.io/react/). It provides declarative and reactive bindings to the [Konva Framework](https://konvajs.org/).


[Github Repo](https://github.com/lavrton/react-konva)
Expand All @@ -14,9 +16,9 @@ An attempt to make [React](http://facebook.github.io/react/) work with the HTML5

**Currently, `react-konva` is not supported in React Native environment.**

Currently you can use all `Konva` nodes and shapes as React components and all `Konva` events are supported on them in same way as normal browser events are supported.
Currently you can use all `Konva` nodes and shapes as React components and all `Konva` events are supported on them in same way.

**Note: you can find a lot of demos and examples of using Konva there: [https://konvajs.org/](https://konvajs.org/). Really, just go there and take a look what Konva can do for you. You will be able to do the same with react-konva too. You don't need to learn `react-konva`, just learn Konva.**
**Note: you can find a lot of demos and examples of using Konva there: [https://konvajs.org/](https://konvajs.org/). Really, just go there and take a look what Konva can do for you. You will be able to do the same with react-konva too. `Konva` for `react-konva` is like DOM for `React`.**

## Installation

Expand Down Expand Up @@ -45,7 +47,5 @@ shapes.

### react-konva vs vanilla canvas

Vanilla canvas is faster because when you use `react-konva` you have two layers of abstractions. Konva framework is on top of canvas and React is on top of Konva.
Depending on the use case this approach can be slow.
The purpose of `react-konva` is to reduce the complexity of the application and use well-known declarative way for drawing on canvas.
Vanilla canvas can is faster because when you use `react-konva` you have two layers of abstractions: (1) `Konva` framework is on top of canvas and (2) `React` is on top of `Konva`. For many applications is performance is still very good. The purpose of `react-konva` is to reduce the complexity of the application and use well-known declarative way for drawing on canvas.

8 changes: 4 additions & 4 deletions themes/hexo3/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ menu:
Tutorials: /docs/index.html
Demos: /docs/sandbox/index.html
API docs: /api/Konva.html
React: /docs/react/index.html
React: /docs/react/Intro.html
Vue: /docs/vue/index.html
Support Konva: /docs/donate.html
Need help?: /docs/support.html
Expand Down Expand Up @@ -355,11 +355,11 @@ demo_sidebar:
# Touch Gestures: sandbox/Gestures.html

react_sidebar:
Getting Started with React:
Intro: react/index.html
Docs and demos:
Intro: react/Intro.html
Overview: react/index.html
Basic shapes: react/Shapes.html
Custom shape: react/Custom_Shape.html
React demos:
Events: react/Events.html
Images: react/Images.html
Filters: react/Filters.html
Expand Down
11 changes: 8 additions & 3 deletions themes/hexo3/layout/_partial/comment.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<% if (page.comments && config.disqus_shortname){ %>
<section id="comments">
<section id="comments" style="margin-top: 50px;">
<div id="disqus_thread">
<noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<noscript
>Please enable JavaScript to view the
<a href="//disqus.com/?ref_noscript"
>comments powered by Disqus.</a
></noscript
>
</div>
</section>
<% } %>
<% } %>
1 change: 0 additions & 1 deletion themes/hexo3/layout/_partial/subscribe.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Adapted from: http://blog.heyimcat.com/universal-signup-form/ */
.mc_embed_signup form {
text-align: center;
padding: 10px 0 10px 0;
}
.mc-field-group {
Expand Down
Loading

0 comments on commit f260375

Please sign in to comment.