Skip to content

Commit

Permalink
Add example for single key press and hold
Browse files Browse the repository at this point in the history
  • Loading branch information
imbhargav5 committed Aug 1, 2019
1 parent 6101003 commit 7a22915
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions packages/storybook/src/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,37 @@ function Basic() {
);
}

function Continuous() {
function PressAndHoldSingle() {
const [left, setLeft] = useState(0);
useKeys(
["KeyD"],
() => {
setLeft(left + 5);
},
{
continuous: true
}
);

return (
<div data-testid="container">
<p>Press and hold d to move the div to the right</p>
<div
style={{
position: "relative",
left,
height: 100,
width: 200,
background: "red"
}}
>
Move me
</div>
</div>
);
}

function PressAndHoldCombination() {
const [left, setLeft] = useState(0);
const [top, setTop] = useState(0);
useKeys(
Expand Down Expand Up @@ -117,4 +147,7 @@ storiesOf("usekeys", module)
}
})
.add("Basic example", () => <Basic />)
.add("Press and hold keys example", () => <Continuous />);
.add("Press and hold single key example", () => <PressAndHoldSingle />)
.add("Press and hold multiple keys example", () => (
<PressAndHoldCombination />
));

0 comments on commit 7a22915

Please sign in to comment.