invoke-prompt-editor-demo/src/components/Nugget.tsx

28 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-02-21 17:19:29 +01:00
import { Button, ButtonGroup, Chip, Divider } from '@material-ui/core';
import React, { Component, useState } from 'react';
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowUp';
import {Composable} from "./IComposable"
2024-02-21 17:19:29 +01:00
import "./Nugget.css";
export default function Nugget({ text, initialScore }: { text: string, initialScore?: number }) {
const [score, setScore] = useState(initialScore || 0);
return (
<div className='nugget'>
<span className='text'>{text}</span>
<Divider orientation="vertical" variant="middle" flexItem />
<span className='score'>{score > 0 ? "+" + score : score}</span>
<span className='buttons'>
<ButtonGroup size="small" orientation='vertical'>
2024-02-23 16:57:42 +01:00
<Button onClick={() => setScore(score + 1)} className='incScore'>
2024-02-21 17:19:29 +01:00
<KeyboardArrowUpIcon />
</Button>
2024-02-23 16:57:42 +01:00
<Button onClick={() => setScore(score - 1)} className='decScore'>
2024-02-21 17:19:29 +01:00
<KeyboardArrowDownIcon />
</Button>
</ButtonGroup>
</span>
</div>
) as Composable;
2024-02-21 17:19:29 +01:00
}