Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudcolas committed Jan 23, 2019
1 parent 09e62d2 commit 8c33c3b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
19 changes: 10 additions & 9 deletions lib/api/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import { DefaultDraftInlineStyle } from "draft-js";

// See https://github.com/facebook/draft-js/blob/master/src/model/immutable/DefaultDraftBlockRenderMap.js
Expand Down Expand Up @@ -124,15 +125,15 @@ export const KEY_CODES = {
J: 74,
I: 73,
X: 88,
0: 48,
1: 49,
2: 50,
3: 51,
4: 52,
5: 53,
6: 54,
7: 55,
8: 56,
"0": 48,
"1": 49,
"2": 50,
"3": 51,
"4": 52,
"5": 53,
"6": 54,
"7": 55,
"8": 56,
".": 190,
",": 188,
};
Expand Down
37 changes: 14 additions & 23 deletions lib/components/Icon.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import PropTypes from "prop-types";
// @flow
import React from "react";
import type { Node } from "react";

type Props = {|
// The icon definition is very flexible.
// String icon = SVG path or symbol reference.
// List of SVG paths.
// Arbitrary React element.
icon: string | string[] | Node,
title: ?string,
className: ?string,
|};

/**
* Icon as SVG element. Can optionally render a React element instead.
*/
const Icon = ({ icon, title, className }) => {
const isPathOrRef = typeof icon === "string";
const Icon = ({ icon, title, className }: Props) => {
let children;

if (isPathOrRef) {
if (typeof icon === "string") {
if (icon.includes("#")) {
children = <use xlinkHref={icon} />;
} else {
Expand Down Expand Up @@ -36,23 +46,4 @@ const Icon = ({ icon, title, className }) => {
);
};

Icon.propTypes = {
// The icon definition is very flexible.
icon: PropTypes.oneOfType([
// String icon = SVG path or symbol reference.
PropTypes.string,
// List of SVG paths.
PropTypes.arrayOf(PropTypes.string),
// Arbitrary React element.
PropTypes.node,
]).isRequired,
title: PropTypes.string,
className: PropTypes.string,
};

Icon.defaultProps = {
title: null,
className: null,
};

export default Icon;
14 changes: 11 additions & 3 deletions lib/components/ToolbarButton.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import PropTypes from "prop-types";
// @flow
import React, { PureComponent } from "react";

import Icon from "./Icon";

type Props = {||};

type State = {|
showTooltipOnHover: boolean,
|};

/**
* Displays a basic button, with optional active variant,
* enriched with a tooltip. The tooltip stops showing on click.
*/
class ToolbarButton extends PureComponent {
class ToolbarButton extends PureComponent<Props, State> {
constructor(props) {
super(props);

Expand All @@ -19,7 +25,8 @@ class ToolbarButton extends PureComponent {
this.onMouseLeave = this.onMouseLeave.bind(this);
}

onMouseDown(e) {
/* :: onMouseDown: (e: Event) => void; */
onMouseDown(e: Event) {
const { name, onClick } = this.props;

e.preventDefault();
Expand All @@ -31,6 +38,7 @@ class ToolbarButton extends PureComponent {
onClick(name);
}

/* :: onMouseLeave: () => void; */
onMouseLeave() {
this.setState({
showTooltipOnHover: true,
Expand Down

0 comments on commit 8c33c3b

Please sign in to comment.