blob: b8f6771df382ec84004aeeaf424adb8ad3404796 [file] [log] [blame]
pineafan15b813d2022-02-13 10:06:09 +00001import react, { Component } from "react";
2import Styles from '../styles/Components/texttools.module.css';
3import { Popover } from 'react-tiny-popover';
4
5
6class 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
27class ListItem extends Component {
28 render() {
29 return this.props.children
30 }
31}
32
33class 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}
pineafan46270162022-02-13 12:06:17 +000054 style={{color: `#${this.props.colour}`, boxShadow: `0px -3px 10px 2px #424242`}}
pineafan15b813d2022-02-13 10:06:09 +000055 >{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
72export { List, ListItem, Code };