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 { |
| 7 | constructor(props) { |
| 8 | super(props); |
| 9 | } |
| 10 | |
| 11 | render() { |
| 12 | return ( |
| 13 | <div className={Styles.list}> |
| 14 | { |
| 15 | react.Children.toArray(this.props.children).map((item, index) => { |
| 16 | return <div key={index} className={Styles.listItem}> |
| 17 | <div className={Styles.square} style={{borderColor: `#${this.props.colour}`}} /> |
| 18 | <div>{item}</div> |
| 19 | </div> |
| 20 | }) |
| 21 | } |
| 22 | </div> |
| 23 | ) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | class ListItem extends Component { |
| 28 | render() { |
| 29 | return this.props.children |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | class Code extends Component { |
| 34 | constructor(props) { |
| 35 | super(props); |
| 36 | this.state = { |
| 37 | isPopoverOpen: false, |
| 38 | }; |
| 39 | } |
| 40 | |
| 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 | }, 1000) |
| 48 | } |
| 49 | |
| 50 | render() { |
| 51 | if ( this.props.clickable === false) { |
| 52 | return <pre |
| 53 | className={Styles.code} |
pineafan | 4627016 | 2022-02-13 12:06:17 +0000 | [diff] [blame] | 54 | style={{color: `#${this.props.colour}`, boxShadow: `0px -3px 10px 2px #424242`}} |
pineafan | 15b813d | 2022-02-13 10:06:09 +0000 | [diff] [blame] | 55 | >{this.props.children}</pre> |
| 56 | } else { |
| 57 | return <Popover |
| 58 | isOpen={this.state.isPopoverOpen} |
| 59 | positions={['top', 'bottom', 'left', 'right']} // preferred positions by priority |
| 60 | content={<Code colour={this.props.colour} clickable={false}>Copied!</Code>} |
| 61 | > |
| 62 | <pre |
| 63 | className={Styles.code} |
| 64 | style={{color: `#${this.props.colour}`}} |
| 65 | onClick={() => this.clicked()} |
| 66 | >{this.props.children}</pre> |
| 67 | </Popover> |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | export { List, ListItem, Code }; |