blob: 76fa8cfeb96333298e97baa0a0d4a1009adfd5b9 [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 {
pineafanaa9c4fd2022-06-10 19:58:10 +01007 constructor(props) {
8 super(props);
9 }
pineafan15b813d2022-02-13 10:06:09 +000010
pineafanaa9c4fd2022-06-10 19:58:10 +010011 render() {
12 return (
pineafan15b813d2022-02-13 10:06:09 +000013 <div className={Styles.list}>
pineafanaa9c4fd2022-06-10 19:58:10 +010014 {
15 react.Children.toArray(this.props.children).map((item, index) => {
16 return <div key={index} className={Styles.listItem}>
pineafan15b813d2022-02-13 10:06:09 +000017 <div className={Styles.square} style={{borderColor: `#${this.props.colour}`}} />
18 <div>{item}</div>
19 </div>
pineafanaa9c4fd2022-06-10 19:58:10 +010020 })
21 }
22 </div>
pineafan15b813d2022-02-13 10:06:09 +000023 )
pineafanaa9c4fd2022-06-10 19:58:10 +010024 }
pineafan15b813d2022-02-13 10:06:09 +000025}
26
27class ListItem extends Component {
28 render() {
pineafanaa9c4fd2022-06-10 19:58:10 +010029 return this.props.children
30 }
pineafan15b813d2022-02-13 10:06:09 +000031}
32
33class Code extends Component {
pineafanaa9c4fd2022-06-10 19:58:10 +010034 constructor(props) {
35 super(props);
36 this.state = {
37 isPopoverOpen: false,
38 };
39 }
pineafan15b813d2022-02-13 10:06:09 +000040
pineafanaa9c4fd2022-06-10 19:58:10 +010041 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 }
pineafan15b813d2022-02-13 10:06:09 +000049
pineafanaa9c4fd2022-06-10 19:58:10 +010050 render() {
pineafanf5dd1872023-02-28 17:33:16 +000051 return <span
pineafanaa9c4fd2022-06-10 19:58:10 +010052 className={Styles.code}
53 style={{color: `#${this.props.colour}`}}
54 onClick={this.props.clickable ? () => this.clicked() : () => this.clicked()}
pineafanf5dd1872023-02-28 17:33:16 +000055 >{this.state.isPopoverOpen ? "Copied!" : this.props.children}</span>
pineafanaa9c4fd2022-06-10 19:58:10 +010056 }
pineafan15b813d2022-02-13 10:06:09 +000057}
58
59export { List, ListItem, Code };