From a5eeeca1383a0fdf50d0c76730e1ace8f03f3759 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 20 Jun 2021 14:03:22 +0200 Subject: keybind selection and deletion :tada: --- components/keybindselector.tsx | 58 ++++++++++++++++++++++++++++++++---------- pages/editor.tsx | 14 +++++++--- styles/keybindselector.css | 18 ++++++++++++- 3 files changed, 73 insertions(+), 17 deletions(-) diff --git a/components/keybindselector.tsx b/components/keybindselector.tsx index 084d748..1d11b6b 100644 --- a/components/keybindselector.tsx +++ b/components/keybindselector.tsx @@ -1,32 +1,64 @@ import FilledInput from '@material-ui/core/FilledInput'; import FormControl from '@material-ui/core/FormControl'; import InputLabel from '@material-ui/core/InputLabel'; -import { useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { v4 as uuid } from 'uuid'; function Keybind(props: { keyName: string; + onClick?: () => any; }) { - return {props.keyName}; + return {props.keyName}; } -function KeybindSelectorInner(props: { - value: string[]; -}) { - return
- {props.value.map(s => )} -
; -} +var keyBlacklist = [ + 'Shift', + 'Control', + 'Alt', + 'Meta', +]; +var keyMap = { + ' ': 'Space', +}; export default function KeybindSelector(props: { label: string; value: string[]; onChange?: (newValue: string[]) => any; }) { - var [tempID, _setTempID] = useState(uuid()); + var [inputID, _setInputID] = useState(uuid()); + + function KeybindSelectorInner() { + return
+ {props.value.map(s => + { + props.onChange && props.onChange(props.value.filter(v => v != s)); + }} + /> + )} +
; + } + + return { + e.preventDefault(); + var key = e.key; + + if (key in keyMap) key = keyMap[key]; + if (keyBlacklist.includes(key)) return; + + var newArr = Array.from(props.value); + if (!newArr.includes(key)) newArr.push(key); - return - {props.label} - } /> + props.onChange(newArr); + }} + > + {props.label} + } /> ; } diff --git a/pages/editor.tsx b/pages/editor.tsx index 73bcd93..c34d3bd 100644 --- a/pages/editor.tsx +++ b/pages/editor.tsx @@ -631,6 +631,10 @@ function DefaultSettings() { var setPlaying = usePlaying((st: any) => st.setPlaying); var setWorkingTimeline = useWorkingTimeline((st: any) => st.setTimeline); + var [nextSlideKeybinds, setNextSlideKeybinds] = useState(['Space', 'n', 'Enter']); + var [previousSlideKeybinds, setPreviousSlideKeybinds] = useState(['Backspace', 'p']); + var [showMenuKeybinds, setShowMenuKeybinds] = useState(['Escape', 'm']); + return <>

Presentation settings

@@ -693,9 +697,13 @@ function DefaultSettings() {
Keybindings - - - + + +
Cool temporary buttons diff --git a/styles/keybindselector.css b/styles/keybindselector.css index b510dee..cc57501 100644 --- a/styles/keybindselector.css +++ b/styles/keybindselector.css @@ -1,17 +1,33 @@ .keybind-selector-inner { padding: 27px 12px 10px; } +.keybind-selector > * { cursor: pointer !important; } + .keybind-selector-inner .keybind { padding: 2px 4px 1px; margin-right: 3px; border-radius: 4px; user-select: none; + cursor: pointer; + transform: scale(1); + display: inline-block; - transition-property: background-color; + transition-property: background-color, opacity, transform; transition-duration: 100ms; background-color: var(--c800); color: var(--c100); } +.keybind-selector-inner .keybind:hover { + opacity: .7; +} + +.keybind-selector-inner .keybind.new { + opacity: 0; + transform: scale(.85); +} + +.keybind-selector * { font-family: "Inter", sans-serif !important; } + .keybind-selector:focus .keybind-selector-inner .keybind { background-color: var(--gruble); } .keybind-selector:focus label { color: var(--gruble) !important; } .keybind-selector:focus .MuiFilledInput-underline:after { transform: scaleX(1); } -- cgit v1.2.3