From aee0fbf7ab3c633b21dd7519c0e86657c279eea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Curcio?= Date: Tue, 24 Jul 2018 16:09:56 -0300 Subject: [PATCH] Support for esc char --- .../stream/components/Comment/Comment.tsx | 25 ++----- .../client/stream/components/Permalink.tsx | 0 .../stream/components/Permalink/Permalink.tsx | 36 ++++++++++ .../{ => Permalink}/PermalinkPopover.css | 2 - .../components/Permalink/PermalinkPopover.tsx | 66 +++++++++++++++++-- .../Permalink/PermalinkShareButton.tsx | 30 --------- .../stream/components/Permalink/Popover.tsx | 9 --- .../components/Permalink/ToggleShow.tsx | 0 .../stream/components/PermalinkPopover.tsx | 61 ----------------- src/core/client/tslint.json | 6 +- .../client/ui/components/Popover/Popover.css | 10 +-- .../client/ui/components/Popover/Popover.mdx | 4 +- .../client/ui/components/Popover/Popover.tsx | 23 ++++++- 13 files changed, 132 insertions(+), 140 deletions(-) delete mode 100644 src/core/client/stream/components/Permalink.tsx create mode 100644 src/core/client/stream/components/Permalink/Permalink.tsx rename src/core/client/stream/components/{ => Permalink}/PermalinkPopover.css (55%) delete mode 100644 src/core/client/stream/components/Permalink/PermalinkShareButton.tsx delete mode 100644 src/core/client/stream/components/Permalink/Popover.tsx delete mode 100644 src/core/client/stream/components/Permalink/ToggleShow.tsx delete mode 100644 src/core/client/stream/components/PermalinkPopover.tsx diff --git a/src/core/client/stream/components/Comment/Comment.tsx b/src/core/client/stream/components/Comment/Comment.tsx index 889ffbe1f..64cefb266 100644 --- a/src/core/client/stream/components/Comment/Comment.tsx +++ b/src/core/client/stream/components/Comment/Comment.tsx @@ -1,8 +1,8 @@ -import { Localized } from "fluent-react/compat"; import React from "react"; import { StatelessComponent } from "react"; -import { Button, Popover, Typography } from "talk-ui/components"; -import PermalinkPopover from "../PermalinkPopover"; +import { Typography } from "talk-ui/components"; + +import Permalink from "../Permalink/Permalink"; import Timestamp from "./Timestamp"; import TopBar from "./TopBar"; import Username from "./Username"; @@ -26,24 +26,7 @@ const Comment: StatelessComponent = props => { {props.body}
- ( - - )} - > - {({ toggleVisibility, forwardRef }) => ( - - )} - +
); diff --git a/src/core/client/stream/components/Permalink.tsx b/src/core/client/stream/components/Permalink.tsx deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/core/client/stream/components/Permalink/Permalink.tsx b/src/core/client/stream/components/Permalink/Permalink.tsx new file mode 100644 index 000000000..f50c5d505 --- /dev/null +++ b/src/core/client/stream/components/Permalink/Permalink.tsx @@ -0,0 +1,36 @@ +import { Localized } from "fluent-react/compat"; +import React from "react"; +import { Button, Popover } from "talk-ui/components"; +import PermalinkPopover from "./PermalinkPopover"; + +interface InnerProps { + commentID: string; +} + +class Permalink extends React.Component { + public render() { + const { commentID } = this.props; + return ( + ( + + )} + > + {({ toggleVisibility, forwardRef }) => ( + + )} + + ); + } +} + +export default Permalink; diff --git a/src/core/client/stream/components/PermalinkPopover.css b/src/core/client/stream/components/Permalink/PermalinkPopover.css similarity index 55% rename from src/core/client/stream/components/PermalinkPopover.css rename to src/core/client/stream/components/Permalink/PermalinkPopover.css index 8f956e370..fe47c28d3 100644 --- a/src/core/client/stream/components/PermalinkPopover.css +++ b/src/core/client/stream/components/Permalink/PermalinkPopover.css @@ -3,6 +3,4 @@ } .root { - padding: 6px 10px; - display: flex; } diff --git a/src/core/client/stream/components/Permalink/PermalinkPopover.tsx b/src/core/client/stream/components/Permalink/PermalinkPopover.tsx index 53f535e3b..a5ff7301f 100644 --- a/src/core/client/stream/components/Permalink/PermalinkPopover.tsx +++ b/src/core/client/stream/components/Permalink/PermalinkPopover.tsx @@ -1,9 +1,61 @@ -import { Manager, Popper, Reference } from "react-popper"; +import { Localized } from "fluent-react/compat"; +import React, { CSSProperties } from "react"; +import CopyToClipboard from "react-copy-to-clipboard"; +import { RefHandler } from "react-popper"; +import { Button, Flex, TextField } from "talk-ui/components"; +import * as styles from "./PermalinkPopover.css"; -import Popover from "./Popover"; +interface InnerProps { + commentID: string; + style?: CSSProperties; + forwardRef?: RefHandler; + toggleVisibility?: () => any; +} -const PermalinkPopover = ({ id, show, style }) => ( - - Copy - -); +interface State { + copied: boolean; +} + +class PermalinkPopover extends React.Component { + public state: State = { + copied: false, + }; + + public onCopy = async () => { + await this.toggleCopied(); + setTimeout(() => { + this.toggleCopied(); + }, 800); + }; + + public toggleCopied = () => { + this.setState((state: State) => ({ + copied: !state.copied, + })); + }; + + public render() { + const { commentID } = this.props; + const { copied } = this.state; + return ( + + + + + + + ); + } +} + +export default PermalinkPopover; diff --git a/src/core/client/stream/components/Permalink/PermalinkShareButton.tsx b/src/core/client/stream/components/Permalink/PermalinkShareButton.tsx deleted file mode 100644 index 7db563182..000000000 --- a/src/core/client/stream/components/Permalink/PermalinkShareButton.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import React from "react"; -import ToggleShow from "./ToggleShow"; - -const PermalinkShareButton = () => ( - - {({ toggleShow, show }) => ( - - - {({ ref }) => ( - - )} - - - {({ ref, style, placement, arrowProps }) => ( - - )} - - - )} - -); - -export default PermalinkShareButton; diff --git a/src/core/client/stream/components/Permalink/Popover.tsx b/src/core/client/stream/components/Permalink/Popover.tsx deleted file mode 100644 index f2c275525..000000000 --- a/src/core/client/stream/components/Permalink/Popover.tsx +++ /dev/null @@ -1,9 +0,0 @@ -const Popover = ({ - id, - style, - children, - visible, - onClose, - firstFocusable, - lastFocusable, -}) =>
{children}
; diff --git a/src/core/client/stream/components/Permalink/ToggleShow.tsx b/src/core/client/stream/components/Permalink/ToggleShow.tsx deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/core/client/stream/components/PermalinkPopover.tsx b/src/core/client/stream/components/PermalinkPopover.tsx deleted file mode 100644 index 3093d009d..000000000 --- a/src/core/client/stream/components/PermalinkPopover.tsx +++ /dev/null @@ -1,61 +0,0 @@ -import { Localized } from "fluent-react/compat"; -import React, { CSSProperties } from "react"; -import CopyToClipboard from "react-copy-to-clipboard"; -import { RefHandler } from "react-popper"; -import { Button, TextField } from "talk-ui/components"; -import * as styles from "./PermalinkPopover.css"; - -interface InnerProps { - commentID: string; - style?: CSSProperties; - forwardRef?: RefHandler; - toggleVisibility?: () => any; -} - -interface State { - copied: boolean; -} - -class PermalinkPopover extends React.Component { - public state: State = { - copied: false, - }; - - public onCopy = async () => { - await this.toggleCopied(); - setTimeout(() => { - this.toggleCopied(); - }, 800); - }; - - public toggleCopied = () => { - this.setState((state: State) => ({ - copied: !state.copied, - })); - }; - - public render() { - const { commentID } = this.props; - const { copied } = this.state; - return ( -
- - - - -
- ); - } -} - -export default PermalinkPopover; diff --git a/src/core/client/tslint.json b/src/core/client/tslint.json index 0079a6de1..a2fafdc6b 100644 --- a/src/core/client/tslint.json +++ b/src/core/client/tslint.json @@ -3,11 +3,13 @@ "rules": { "jsx-curly-spacing": false, "jsx-no-multiline-js": false, - "jsx-boolean-value": [true, "never"] + "jsx-boolean-value": [true, "never"], + "jsx-no-lambda": false }, "jsRules": { "jsx-curly-spacing": false, "jsx-no-multiline-js": false, - "jsx-boolean-value": [true, "never"] + "jsx-boolean-value": [true, "never"], + "jsx-no-lambda": false } } diff --git a/src/core/client/ui/components/Popover/Popover.css b/src/core/client/ui/components/Popover/Popover.css index 708964cdb..89037c5f3 100644 --- a/src/core/client/ui/components/Popover/Popover.css +++ b/src/core/client/ui/components/Popover/Popover.css @@ -1,15 +1,15 @@ .root { - padding: 6px 10px; - background: #ffffff !important; + background: #ffffff; border: 1px solid #c9cacb; box-sizing: border-box; box-shadow: 1px 0px 4px rgba(0, 0, 0, 0.25); border-radius: 1px; - color: #222 !important; - display: flex !important; + color: #222; + display: flex; + padding: 6px 10px; &:after, &::before { - border-top-color: transparent !important; + border-top-color: transparent; } } diff --git a/src/core/client/ui/components/Popover/Popover.mdx b/src/core/client/ui/components/Popover/Popover.mdx index 7623a293d..ad1c22e63 100644 --- a/src/core/client/ui/components/Popover/Popover.mdx +++ b/src/core/client/ui/components/Popover/Popover.mdx @@ -6,6 +6,7 @@ menu: UI Kit import { Playground, PropsTable } from 'docz' import Popover from './Popover' import Button from '../Button' +import ButtonIcon from '../Button/ButtonIcon' # Popover @@ -14,7 +15,6 @@ import Button from '../Button' ## Basic usage This is the body} > {({ toggleVisibility, forwardRef }) => ( @@ -28,12 +28,12 @@ import Button from '../Button' #### Example with `placement=top` (
This is the body
diff --git a/src/core/client/ui/components/Popover/Popover.tsx b/src/core/client/ui/components/Popover/Popover.tsx index 3b30c0b91..e318810d1 100644 --- a/src/core/client/ui/components/Popover/Popover.tsx +++ b/src/core/client/ui/components/Popover/Popover.tsx @@ -57,6 +57,27 @@ class Popover extends React.Component { })); }; + public close = () => { + this.setState((state: State) => ({ + visible: false, + })); + }; + + public handleEsc = (e: KeyboardEvent) => { + if (e.key === "Escape") { + e.preventDefault(); + this.close(); + } + }; + + public componentDidMount() { + document.addEventListener("keydown", this.handleEsc, true); + } + + public componentWillUnmount() { + document.removeEventListener("keydown", this.handleEsc, true); + } + public render() { const { id, @@ -95,7 +116,7 @@ class Popover extends React.Component { > {description} - {/* */} + {/* */}