Chapter.js
72 lines
| 1 | import { __ } from "@wordpress/i18n"; |
| 2 | import { Flex, FlexItem, FlexBlock, TextControl, Button } from "@wordpress/components"; |
| 3 | import { useState } from "@wordpress/element"; |
| 4 | import { sanitizeTime } from "../../../util"; |
| 5 | |
| 6 | const Chapter = ({ |
| 7 | update, |
| 8 | add, |
| 9 | remove, |
| 10 | className, |
| 11 | time, |
| 12 | title, |
| 13 | }) => { |
| 14 | const [draftTime, setDraftTime] = useState(time); |
| 15 | |
| 16 | return ( |
| 17 | <Flex align="center" className={className}> |
| 18 | <FlexItem> |
| 19 | <TextControl |
| 20 | className={"presto-player__caption--time"} |
| 21 | style={{ width: "60px" }} |
| 22 | placeholder={"0:00"} |
| 23 | value={draftTime} |
| 24 | onChange={(time) => setDraftTime(time)} |
| 25 | onBlur={() => { |
| 26 | let time = sanitizeTime(draftTime); |
| 27 | update({ time }); |
| 28 | setDraftTime(time); |
| 29 | }} |
| 30 | autoComplete="off" |
| 31 | /> |
| 32 | </FlexItem> |
| 33 | |
| 34 | <FlexBlock> |
| 35 | <TextControl |
| 36 | className={"presto-player__caption--title"} |
| 37 | placeholder={__("Title", "presto-player")} |
| 38 | value={title || ""} |
| 39 | onChange={(title) => update({ title })} |
| 40 | autoComplete="off" |
| 41 | /> |
| 42 | </FlexBlock> |
| 43 | |
| 44 | <FlexItem> |
| 45 | {remove && ( |
| 46 | <Button |
| 47 | icon="minus" |
| 48 | className="ph-chapter__remove" |
| 49 | style={{ marginBottom: "8px" }} |
| 50 | label={__("Remove Chapter", "presto-player")} |
| 51 | onClick={remove} |
| 52 | /> |
| 53 | )} |
| 54 | {add && ( |
| 55 | <Button |
| 56 | icon="plus-alt" |
| 57 | className="ph-chapter__add" |
| 58 | label={__("Add Chapter", "presto-player")} |
| 59 | style={{ marginBottom: "8px" }} |
| 60 | onClick={() => { |
| 61 | add(); |
| 62 | setDraftTime(""); |
| 63 | }} |
| 64 | /> |
| 65 | )} |
| 66 | </FlexItem> |
| 67 | </Flex> |
| 68 | ); |
| 69 | }; |
| 70 | |
| 71 | export default Chapter; |
| 72 |