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

feat: add react optimization hooks and use lib classNames in more components #449

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions website/components/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ import video from "../../src/plugins/video/plugin";

const initialEditorState = editorStateFromRaw(INITIAL_CONTENT);

const keyBindings = [
{
name: "save",
isKeyBound: e => e.keyCode === 83 && e.ctrlKey,
action: () => console.log("save")
}
];

function Editor(props) {
const { editorState, onChange } = props;
const keyBindings = [
{
name: "save",
isKeyBound: e => e.keyCode === 83 && e.ctrlKey,
action: () => console.log("save")
}
];

function onAction(args) {
console.log("onAction fired with args:", args);
Expand Down
35 changes: 20 additions & 15 deletions website/components/menubar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useState, useRef } from "react";
import React, { useState, useRef, useCallback, useMemo } from "react";
import { Sticky } from "react-sticky";
import Scroll from "react-scroll";
import { Link } from "react-router-dom";
import classNames from "classnames";

import { common } from "@material-ui/core/colors";
import Grid from "@material-ui/core/Grid";
Expand All @@ -10,7 +11,6 @@ import Divider from "@material-ui/core/Divider";
import Menu from "@material-ui/core/Menu";
import Toolbar from "@material-ui/core/Toolbar";
import Button from "@material-ui/core/Button";
import { useCallback } from "react";

import { Burger } from "./icons/burger";

Expand All @@ -23,28 +23,31 @@ const MenuBar = props => {
const documentationMenu = useRef(null);
const [closeMenu, setCloseMenu] = useState(true);

const handleTouchTap = event => {
const handleTouchTap = useCallback(event => {
// This prevents ghost click.
event.preventDefault();

scroller.scrollTo("appbar", { duration: 300, smooth: true });
setTimeout(() => setShowMenuDropdown(true), 300);
};
}, []);

const handleChangeOpenMenu = useCallback(() => {
setCloseMenu(prev => !prev);
}, []);

const handleRequestClose = () => {
const handleRequestClose = useCallback(() => {
setShowMenuDropdown(false);
!closeMenu && handleChangeOpenMenu();
};
}, [closeMenu, handleChangeOpenMenu]);

const dropDownData = {
documentationMenu,
handleRequestClose,
showMenuDropdown
};
const dropDownData = useMemo(
() => ({
documentationMenu,
handleRequestClose,
showMenuDropdown
}),
[documentationMenu, handleRequestClose, showMenuDropdown]
);

return (
<Element name="appbar" className="appBar">
Expand Down Expand Up @@ -96,12 +99,14 @@ const MenuBar = props => {
</Grid>
</Grid>
<div
className={`dropdown-menu ${closeMenu &&
"dropdown-menu__hidden"}`}
className={classNames("dropdown-menu", {
"dropdown-menu__hidden": closeMenu
})}
>
<div
className={`dropdown-menu__header ${!showLeft &&
"dropdown-menu__header__dark"} `}
className={classNames("dropdown-menu__header", {
"dropdown-menu__header__dark": !showLeft
})}
>
Menu{" "}
<button onClick={handleChangeOpenMenu}>
Expand Down
5 changes: 3 additions & 2 deletions website/components/toggleButton.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from "react";
import classNames from "classnames";

import { makeStyles } from "@material-ui/core/styles";
import Button from "@material-ui/core/Button";

import { yellow } from "@material-ui/core/colors";

const useStyles = makeStyles(theme => ({
Expand All @@ -18,7 +19,7 @@ const ToggleButton = ({ children, color, onClick }) => {
return (
<Button
onClick={onClick}
className={color === "yellow" ? classes.yellow : null}
className={classNames({ [classes.yellow]: color === "yellow" })}
>
{children}
</Button>
Expand Down