1#[cfg(feature = "stories")]
2pub use stories::*;
3
4#[cfg(feature = "stories")]
5mod stories {
6 use super::*;
7 pub use crate::KeyBinding;
8 use crate::Story;
9 use gpui::{actions, Div, Render};
10 use itertools::Itertools;
11 pub struct KeybindingStory;
12
13 actions!(NoAction);
14
15 pub fn binding(key: &str) -> gpui::KeyBinding {
16 gpui::KeyBinding::new(key, NoAction {}, None)
17 }
18
19 impl Render for KeybindingStory {
20 type Element = Div;
21
22 fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
23 let all_modifier_permutations =
24 ["ctrl", "alt", "cmd", "shift"].into_iter().permutations(2);
25
26 Story::container(cx)
27 .child(Story::title_for::<KeyBinding>(cx))
28 .child(Story::label(cx, "Single Key"))
29 .child(KeyBinding::new(binding("Z")))
30 .child(Story::label(cx, "Single Key with Modifier"))
31 .child(
32 div()
33 .flex()
34 .gap_3()
35 .child(KeyBinding::new(binding("ctrl-c")))
36 .child(KeyBinding::new(binding("alt-c")))
37 .child(KeyBinding::new(binding("cmd-c")))
38 .child(KeyBinding::new(binding("shift-c"))),
39 )
40 .child(Story::label(cx, "Single Key with Modifier (Permuted)"))
41 .child(
42 div().flex().flex_col().children(
43 all_modifier_permutations
44 .chunks(4)
45 .into_iter()
46 .map(|chunk| {
47 div()
48 .flex()
49 .gap_4()
50 .py_3()
51 .children(chunk.map(|permutation| {
52 KeyBinding::new(binding(&*(permutation.join("-") + "-x")))
53 }))
54 }),
55 ),
56 )
57 .child(Story::label(cx, "Single Key with All Modifiers"))
58 .child(KeyBinding::new(binding("ctrl-alt-cmd-shift-z")))
59 .child(Story::label(cx, "Chord"))
60 .child(KeyBinding::new(binding("a z")))
61 .child(Story::label(cx, "Chord with Modifier"))
62 .child(KeyBinding::new(binding("ctrl-a shift-z")))
63 .child(KeyBinding::new(binding("fn-s")))
64 }
65 }
66}