Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add a numeric text field to slider input for fine tune adjustments #275

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions src/components/inputs/accent-range.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React from 'react';
import React, {useState} from 'react';
import styled from 'styled-components';
import {NumberInput} from 'src/components/panes/configure-panes/submenus/macros/keycode-sequence-components';

const Container = styled.span`
display: inline-block;
display: flex;
gap: 10px;
align-items: space-between;
line-height: initial;
width: 200px;
`;
@@ -16,13 +19,21 @@ export const AccentRange: React.FC<
Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange'> & {
onChange: (x: number) => void;
}
> = (props) => (
<Container>
<SliderInput
{...props}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
props.onChange && props.onChange(+e.target.value);
}}
/>
</Container>
);
> = (props) => {
const [value, setValue] = useState<number>(
(props.defaultValue as number) || 0,
);

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const newValue = +e.target.value;
setValue(newValue);
props.onChange && props.onChange(newValue);
};

return (
<Container>
<SliderInput {...props} value={value} onChange={handleChange} />
<NumberInput {...props} value={value} onChange={handleChange} />
</Container>
);
};