Skip to content

Commit 2479997

Browse files
authored
Merge pull request #369 from Cipulot/test
Addition of explicit slider values option
2 parents b02959b + 100bf6e commit 2479997

File tree

5 files changed

+68
-15
lines changed

5 files changed

+68
-15
lines changed
Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,61 @@
1-
import React from 'react';
1+
import React, {useState, useEffect} from 'react';
22
import styled from 'styled-components';
3+
import {useAppSelector} from 'src/store/hooks';
4+
import {getShowSliderValues} from 'src/store/settingsSlice';
35

4-
const Container = styled.span`
5-
display: inline-block;
6+
const Container = styled.span<{$showValue?: boolean}>`
7+
display: inline-flex;
8+
align-items: center;
69
line-height: initial;
7-
width: 200px;
10+
gap: ${(props) => (props.$showValue ? '10px' : '0')};
11+
width: ${(props) => (props.$showValue ? 'auto' : '200px')};
812
`;
913

1014
const SliderInput = styled.input.attrs({type: 'range'})<any>`
1115
accent-color: var(--color_accent);
12-
width: 100%;
16+
width: ${(props) => (props.$showValue ? '200px' : '100%')};
17+
flex: none;
18+
`;
19+
20+
const ValueDisplay = styled.span`
21+
text-align: right;
22+
font-size: 20px;
23+
color: var(--color_label_highlighted);
24+
white-space: nowrap;
25+
min-width: 40px;
1326
`;
1427

1528
export const AccentRange: React.FC<
1629
Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange'> & {
1730
onChange: (x: number) => void;
1831
}
19-
> = (props) => (
20-
<Container>
21-
<SliderInput
22-
{...props}
23-
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
24-
props.onChange && props.onChange(+e.target.value);
25-
}}
26-
/>
27-
</Container>
28-
);
32+
> = (props) => {
33+
// Get the dynamic value from Redux store
34+
const showValue = useAppSelector(getShowSliderValues);
35+
36+
const [currentValue, setCurrentValue] = useState<number>(
37+
Number(props.defaultValue || props.value || props.min || 0),
38+
);
39+
40+
useEffect(() => {
41+
const newValue = Number(
42+
props.defaultValue || props.value || props.min || 0,
43+
);
44+
setCurrentValue(newValue);
45+
}, [props.defaultValue, props.value, props.min]);
46+
47+
return (
48+
<Container $showValue={showValue}>
49+
{showValue && <ValueDisplay>{currentValue}</ValueDisplay>}
50+
<SliderInput
51+
{...props}
52+
$showValue={showValue}
53+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
54+
const newValue = +e.target.value;
55+
setCurrentValue(newValue);
56+
props.onChange && props.onChange(newValue);
57+
}}
58+
/>
59+
</Container>
60+
);
61+
};

src/components/panes/settings.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import {useAppSelector} from 'src/store/hooks';
1717
import {
1818
getShowDesignTab,
1919
getDisableFastRemap,
20+
getShowSliderValues,
2021
toggleCreatorMode,
2122
toggleFastRemap,
23+
toggleShowSliderValues,
2224
getThemeMode,
2325
toggleThemeMode,
2426
getThemeName,
@@ -57,6 +59,7 @@ export const Settings = () => {
5759
const dispatch = useDispatch();
5860
const showDesignTab = useAppSelector(getShowDesignTab);
5961
const disableFastRemap = useAppSelector(getDisableFastRemap);
62+
const showSliderValues = useAppSelector(getShowSliderValues);
6063
const themeMode = useAppSelector(getThemeMode);
6164
const themeName = useAppSelector(getThemeName);
6265
const renderMode = useAppSelector(getRenderMode);
@@ -120,6 +123,15 @@ export const Settings = () => {
120123
/>
121124
</Detail>
122125
</ControlRow>
126+
<ControlRow>
127+
<Label>Show Slider Values</Label>
128+
<Detail>
129+
<AccentSlider
130+
onChange={() => dispatch(toggleShowSliderValues())}
131+
isChecked={showSliderValues}
132+
/>
133+
</Detail>
134+
</ControlRow>
123135
<ControlRow>
124136
<Label>Light Mode</Label>
125137
<Detail>

src/store/settingsSlice.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ const settingsSlice = createSlice({
4242
toggleFastRemap: (state) => {
4343
toggleBool(state, 'disableFastRemap');
4444
},
45+
toggleShowSliderValues: (state) => {
46+
toggleBool(state, 'showSliderValues');
47+
},
4548
toggleCreatorMode: (state) => {
4649
toggleBool(state, 'showDesignTab');
4750
},
@@ -103,6 +106,7 @@ const settingsSlice = createSlice({
103106

104107
export const {
105108
toggleFastRemap,
109+
toggleShowSliderValues,
106110
toggleCreatorMode,
107111
setTestMatrixEnabled,
108112
setTestKeyboardSoundsSettings,
@@ -123,6 +127,8 @@ export const getAllowGlobalHotKeys = (state: RootState) =>
123127
state.settings.allowGlobalHotKeys;
124128
export const getDisableFastRemap = (state: RootState) =>
125129
state.settings.disableFastRemap;
130+
export const getShowSliderValues = (state: RootState) =>
131+
state.settings.showSliderValues;
126132
export const getShowDesignTab = (state: RootState) =>
127133
state.settings.showDesignTab;
128134
export const getRestartRequired = (state: RootState) =>

src/types/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export type TestKeyboardSoundsSettings = {
8484
export type Settings = {
8585
showDesignTab: boolean;
8686
disableFastRemap: boolean;
87+
showSliderValues: boolean;
8788
renderMode: '3D' | '2D';
8889
themeMode: 'light' | 'dark';
8990
themeName: string;

src/utils/device-store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const defaultStoreData = {
3030
settings: {
3131
showDesignTab: false,
3232
disableFastRemap: false,
33+
showSliderValues: false,
3334
renderMode: '2D' as const,
3435
themeMode: 'dark' as const,
3536
designDefinitionVersion: 'v3' as const,

0 commit comments

Comments
 (0)