parts
1 week ago
ActionBar.js
1 week ago
ActionBar.scss
1 week ago
Behavior.js
2 years ago
CTA.js
1 week ago
CTA.scss
1 week ago
Controls.js
5 years ago
Edit.js
1 week ago
Edit.scss
1 week ago
Email.js
1 week ago
Email.scss
1 week ago
Preset.js
4 years ago
Search.js
3 years ago
Style.js
1 week ago
Style.scss
1 week ago
Watermark.js
4 years ago
index.js
1 week ago
index.scss
1 week ago
Search.js
128 lines
| 1 | /** |
| 2 | * WordPress dependencies |
| 3 | */ |
| 4 | import { __ } from "@wordpress/i18n"; |
| 5 | import { |
| 6 | ToggleControl, |
| 7 | BaseControl, |
| 8 | RangeControl, |
| 9 | TextControl, |
| 10 | Button, |
| 11 | } from "@wordpress/components"; |
| 12 | import { chevronDown, chevronUp } from "@wordpress/icons"; |
| 13 | import { useEffect, useState } from "@wordpress/element"; |
| 14 | |
| 15 | export default ({ state, updateState, className }) => { |
| 16 | const { search } = state; |
| 17 | const [showAdvanced, setShowAdvanced] = useState(false); |
| 18 | |
| 19 | const defaults = { |
| 20 | enabled: false, |
| 21 | minMatchCharLength: 1, |
| 22 | threshold: 0.3, |
| 23 | placeholder: "Search", |
| 24 | }; |
| 25 | useEffect(() => { |
| 26 | Object.keys(defaults).forEach((key) => { |
| 27 | if (state?.search?.[key] === undefined) { |
| 28 | updateSearchState({ |
| 29 | [key]: defaults[key], |
| 30 | }); |
| 31 | } |
| 32 | }); |
| 33 | }, [state]); |
| 34 | |
| 35 | const updateSearchState = (updated) => { |
| 36 | updateState({ |
| 37 | ...state, |
| 38 | search: { |
| 39 | ...search, |
| 40 | ...updated, |
| 41 | }, |
| 42 | }); |
| 43 | }; |
| 44 | |
| 45 | return ( |
| 46 | <div className={className}> |
| 47 | <BaseControl> |
| 48 | <h3>{__("Searchable Captions", "presto-player")}</h3> |
| 49 | </BaseControl> |
| 50 | <BaseControl className="presto-player__control--search"> |
| 51 | <ToggleControl |
| 52 | label={__("Enable", "presto-player")} |
| 53 | help={__( |
| 54 | "Show a search bar on your player which enables searching within the subtitles of the video.", |
| 55 | "presto-player" |
| 56 | )} |
| 57 | onChange={(enabled) => { |
| 58 | updateSearchState({ |
| 59 | enabled, |
| 60 | }); |
| 61 | }} |
| 62 | checked={search?.enabled} |
| 63 | /> |
| 64 | </BaseControl> |
| 65 | {search?.enabled && ( |
| 66 | <div> |
| 67 | <BaseControl className="presto-player__control--placeholder-text"> |
| 68 | <TextControl |
| 69 | label={__("Placeholder Text", "presto-player")} |
| 70 | help="" |
| 71 | value={search?.placeholder} |
| 72 | onChange={(placeholder) => updateSearchState({ placeholder })} |
| 73 | /> |
| 74 | </BaseControl> |
| 75 | |
| 76 | <BaseControl> |
| 77 | <Button |
| 78 | onClick={() => setShowAdvanced(!showAdvanced)} |
| 79 | iconPosition="right" |
| 80 | icon={showAdvanced ? chevronUp : chevronDown} |
| 81 | variant="link" |
| 82 | > |
| 83 | {__("Advanced Settings", "presto-player")} |
| 84 | </Button> |
| 85 | </BaseControl> |
| 86 | |
| 87 | {!!showAdvanced && ( |
| 88 | <> |
| 89 | <BaseControl> |
| 90 | <RangeControl |
| 91 | label={__( |
| 92 | "Minimum Matching Character Length", |
| 93 | "presto-player" |
| 94 | )} |
| 95 | help={__( |
| 96 | "Only the matches whose length exceeds this value will be returned. (For instance, if you want to ignore single character matches in the result, set it to 2", |
| 97 | "presto-player" |
| 98 | )} |
| 99 | value={search?.minMatchCharLength || 1} |
| 100 | onChange={(minMatchCharLength) => |
| 101 | updateSearchState({ minMatchCharLength }) |
| 102 | } |
| 103 | min={0} |
| 104 | max={10} |
| 105 | /> |
| 106 | </BaseControl> |
| 107 | <BaseControl> |
| 108 | <RangeControl |
| 109 | label={__("Threshold", "presto-player")} |
| 110 | help={__( |
| 111 | "At what point does the match algorithm give up. A threshold of 0.0 requires a perfect match (of both letters and location), a threshold of 1.0 would match anything.", |
| 112 | "presto-player" |
| 113 | )} |
| 114 | value={search?.threshold || 1} |
| 115 | onChange={(threshold) => updateSearchState({ threshold })} |
| 116 | min={0} |
| 117 | max={1} |
| 118 | step={0.1} |
| 119 | /> |
| 120 | </BaseControl> |
| 121 | </> |
| 122 | )} |
| 123 | </div> |
| 124 | )} |
| 125 | </div> |
| 126 | ); |
| 127 | }; |
| 128 |