Skip to content

Commit 222b91e

Browse files
committed
Add indicators
1 parent be42b5d commit 222b91e

3 files changed

Lines changed: 69 additions & 46 deletions

File tree

src/keyboard/Key.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const Key = ({
5656
const children = Children.map(props.children, (c) => (
5757
<span
5858
data-zoomer={hoverZoom}
59-
className="bg-gray-700 rounded-sm place-content-around"
59+
className="bg-gray-700 rounded-sm place-content-around text-base-content"
6060
>
6161
{c}
6262
</span>

src/keyboard/Keymap.tsx

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
LayoutZoom,
99
PhysicalLayout as PhysicalLayoutComp,
1010
} from "./PhysicalLayout";
11-
import { HidUsageLabel } from "./HidUsageLabel";
11+
import { getBindingChildren } from "./KeymapBindingChildren";
1212

1313
type BehaviorMap = Record<number, GetBehaviorDetailsResponse>;
1414

@@ -22,50 +22,6 @@ export interface KeymapProps {
2222
onKeyPositionClicked: (keyPosition: number) => void;
2323
}
2424

25-
const getBindingChildren = (
26-
header: string,
27-
binding: { param1: number; param2: number },
28-
) => {
29-
if (header === "Layer-Tap") {
30-
return [
31-
<span className="text-sm">
32-
<HidUsageLabel
33-
hid_usage={binding.param2}
34-
/>
35-
</span>,
36-
<span className="text-xs truncate">
37-
<svg className="inline-block mb-0.5 mr-1" xmlns="http://www.w3.org/2000/svg" width="10" height="10" fill="currentColor" viewBox="0 0 16 16">
38-
<path d="M8.235 1.559a.5.5 0 0 0-.47 0l-7.5 4a.5.5 0 0 0 0 .882L3.188 8 .264 9.559a.5.5 0 0 0 0 .882l7.5 4a.5.5 0 0 0 .47 0l7.5-4a.5.5 0 0 0 0-.882L12.813 8l2.922-1.559a.5.5 0 0 0 0-.882zm3.515 7.008L14.438 10 8 13.433 1.562 10 4.25 8.567l3.515 1.874a.5.5 0 0 0 .47 0zM8 9.433 1.562 6 8 2.567 14.438 6z"/>
39-
</svg>
40-
{binding.param1}
41-
</span>
42-
];
43-
}
44-
45-
if (header === "Mod-Tap") {
46-
return [
47-
<span className="text-sm">
48-
<HidUsageLabel
49-
hid_usage={binding.param2}
50-
/>
51-
</span>,
52-
<span className="text-sm">
53-
<HidUsageLabel
54-
hid_usage={binding.param1}
55-
/>
56-
</span>
57-
];
58-
}
59-
60-
return (
61-
<span className="text-base">
62-
<HidUsageLabel
63-
hid_usage={binding.param1}
64-
/>
65-
</span>
66-
);
67-
};
68-
6925
export const Keymap = ({
7026
layout,
7127
keymap,
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { HidUsageLabel } from "./HidUsageLabel";
2+
3+
export interface KeyBinding {
4+
param1: number;
5+
param2: number;
6+
}
7+
8+
const renderIndicator = (numbers: 0|1|2|3 = 1): JSX.Element => (
9+
<div className="absolute ml-0.5 h-full flex flex-col justify-evenly py-1">
10+
{Array.from({ length: Math.max(1, numbers) }, (_, i) => (
11+
<div
12+
key={i}
13+
className="bg-gray-900 opacity-80 rounded-full"
14+
style={{
15+
width: '.2rem',
16+
height: numbers === 0 ? '0.8rem' : '.2rem',
17+
}}
18+
/>
19+
))}
20+
</div>
21+
);
22+
23+
export const getBindingChildren = (
24+
header: string,
25+
binding: KeyBinding,
26+
): JSX.Element | JSX.Element[] => {
27+
if (header === "Layer-Tap") {
28+
return [
29+
<div className="relative text-sm">
30+
{renderIndicator(1)}
31+
<HidUsageLabel hid_usage={binding.param2}/>
32+
</div>,
33+
<div className="text-xs truncate relative">
34+
{renderIndicator(0)}
35+
<svg className="inline-block mb-0.5 mr-1" xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="currentColor" viewBox="0 0 16 16">
36+
<path d="M8.235 1.559a.5.5 0 0 0-.47 0l-7.5 4a.5.5 0 0 0 0 .882L3.188 8 .264 9.559a.5.5 0 0 0 0 .882l7.5 4a.5.5 0 0 0 .47 0l7.5-4a.5.5 0 0 0 0-.882L12.813 8l2.922-1.559a.5.5 0 0 0 0-.882zm3.515 7.008L14.438 10 8 13.433 1.562 10 4.25 8.567l3.515 1.874a.5.5 0 0 0 .47 0zM8 9.433 1.562 6 8 2.567 14.438 6z"/>
37+
</svg>
38+
{binding.param1}
39+
</div>
40+
];
41+
}
42+
43+
if (header === "Mod-Tap") {
44+
return [
45+
<div className="relative">
46+
{renderIndicator(1)}
47+
<span className="text-sm">
48+
<HidUsageLabel hid_usage={binding.param2}/>
49+
</span>
50+
</div>,
51+
<div className="text-xs relative">
52+
{renderIndicator(0)}
53+
<HidUsageLabel hid_usage={binding.param1}/>
54+
</div>
55+
];
56+
}
57+
58+
return (
59+
<div className="relative">
60+
<span className="text-base">
61+
<HidUsageLabel
62+
hid_usage={binding.param1}
63+
/>
64+
</span>
65+
</div>
66+
);
67+
};

0 commit comments

Comments
 (0)