pineafan | 15b813d | 2022-02-13 10:06:09 +0000 | [diff] [blame] | 1 | import react, { Component } from "react"; |
| 2 | import Styles from '../styles/Components/texttools.module.css'; |
| 3 | import { Popover } from 'react-tiny-popover'; |
| 4 | |
| 5 | |
| 6 | class List extends Component { |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 7 | constructor(props) { |
| 8 | super(props); |
| 9 | } |
pineafan | 15b813d | 2022-02-13 10:06:09 +0000 | [diff] [blame] | 10 | |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 11 | render() { |
| 12 | return ( |
pineafan | 15b813d | 2022-02-13 10:06:09 +0000 | [diff] [blame] | 13 | <div className={Styles.list}> |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 14 | { |
| 15 | react.Children.toArray(this.props.children).map((item, index) => { |
| 16 | return <div key={index} className={Styles.listItem}> |
pineafan | 15b813d | 2022-02-13 10:06:09 +0000 | [diff] [blame] | 17 | <div className={Styles.square} style={{borderColor: `#${this.props.colour}`}} /> |
| 18 | <div>{item}</div> |
| 19 | </div> |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 20 | }) |
| 21 | } |
| 22 | </div> |
pineafan | 15b813d | 2022-02-13 10:06:09 +0000 | [diff] [blame] | 23 | ) |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 24 | } |
pineafan | 15b813d | 2022-02-13 10:06:09 +0000 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | class ListItem extends Component { |
| 28 | render() { |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 29 | return this.props.children |
| 30 | } |
pineafan | 15b813d | 2022-02-13 10:06:09 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | class Code extends Component { |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 34 | constructor(props) { |
| 35 | super(props); |
| 36 | this.state = { |
| 37 | isPopoverOpen: false, |
| 38 | }; |
| 39 | } |
pineafan | 15b813d | 2022-02-13 10:06:09 +0000 | [diff] [blame] | 40 | |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 41 | clicked() { |
| 42 | let content = this.props.children |
| 43 | navigator.clipboard.writeText(content) |
| 44 | this.setState({isPopoverOpen: true}) |
| 45 | setTimeout(() => { |
| 46 | this.setState({isPopoverOpen: false}) |
| 47 | }, 2000) |
| 48 | } |
pineafan | 15b813d | 2022-02-13 10:06:09 +0000 | [diff] [blame] | 49 | |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 50 | render() { |
pineafan | f5dd187 | 2023-02-28 17:33:16 +0000 | [diff] [blame] | 51 | return <span |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 52 | className={Styles.code} |
| 53 | style={{color: `#${this.props.colour}`}} |
| 54 | onClick={this.props.clickable ? () => this.clicked() : () => this.clicked()} |
pineafan | f5dd187 | 2023-02-28 17:33:16 +0000 | [diff] [blame] | 55 | >{this.state.isPopoverOpen ? "Copied!" : this.props.children}</span> |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 56 | } |
pineafan | 15b813d | 2022-02-13 10:06:09 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | export { List, ListItem, Code }; |