Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 74f3df3

Browse files
authored
feat(Popup): added on prop for triggering the popup on click, hover or focus (#622)
* -added on prop in the Popup for allowing the user to change the trigger event of the popup on click or hover -added usage examples * -updated changelog * -wip: adding focus, click, hover combinations for the on prop * -fixed some issues -copied handlers on the primitive content element * -added escape key handler on the trigger -hover should by default add the focus handler as well * -fixed focus handlers -fixed examples imports * -fixed focus * -added focus usage example * -fixed on prop type -hover on blur should close the popup -rearranged the examples for the on prop * -handle timeout for closing only if mouseLeaveDelay is greater then 0 * -adding comments on the handlers created -refactoring on the blur conditions * -rearranged usage example and added example using the trap focus behavior * -improved typing for the on prop in the Popup * -removed expressions for strings in the examples * -replaced double quotes with single quotes * -added aria-label on the popup examples * -reverted condition for not adding timeout if the mouse delay is 0 * -removed alert in the Popup examples * -refactoring the timeout handling and added clear logic * -small refactorings * docs: simplify popup usage examples * -fix focus + click opening * -fixed changelog after merging master
1 parent b329d6a commit 74f3df3

File tree

10 files changed

+366
-58
lines changed

10 files changed

+366
-58
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1717

1818
## [Unreleased]
1919

20+
### Features
21+
- Add `on` and `mouseLeaveDelay` props to `Popup` component @mnajdova ([#622](https://github.com/stardust-ui/react/pull/622))
22+
2023
<!--------------------------------[ v0.16.0 ]------------------------------- -->
2124
## [v0.16.0](https://github.com/stardust-ui/react/tree/v0.16.0) (2019-01-07)
2225
[Compare changes](https://github.com/stardust-ui/react/compare/v0.15.0...v0.16.0)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as React from 'react'
2+
import { Button, Popup } from '@stardust-ui/react'
3+
4+
const PopupExampleOn = () => (
5+
<div>
6+
<Popup
7+
trigger={<Button icon="expand" content="Click" aria-label="Click button" />}
8+
content="Hello from popup on click!"
9+
on="click"
10+
/>
11+
<Popup
12+
trigger={<Button icon="expand" content="Hover" aria-label="Hover button" />}
13+
content="Hello from popup on hover!"
14+
on="hover"
15+
/>
16+
<Popup
17+
trigger={<Button icon="expand" content="Focus" aria-label="Focus button" />}
18+
content="Hello from popup on focus!"
19+
on="focus"
20+
/>
21+
</div>
22+
)
23+
24+
export default PopupExampleOn
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as React from 'react'
2+
import { Button, Popup } from '@stardust-ui/react'
3+
4+
const PopupExampleOnMultiple = () => (
5+
<div>
6+
<Popup
7+
trigger={<Button icon="expand" content="Click + Focus" aria-label="Click or focus button" />}
8+
content="Hello from popup on click!"
9+
on={['click', 'focus']}
10+
/>
11+
<Popup
12+
trigger={<Button icon="expand" content="Hover + Focus" aria-label="Hover or focus button" />}
13+
content="Hello from popup on hover!"
14+
on={['hover', 'focus']}
15+
/>
16+
</div>
17+
)
18+
19+
export default PopupExampleOnMultiple
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as React from 'react'
2+
import { Button, Popup, popupFocusTrapBehavior } from '@stardust-ui/react'
3+
4+
const contentWithButtons = {
5+
content: (
6+
<>
7+
<Button>First</Button>
8+
<Button primary>Second</Button>
9+
</>
10+
),
11+
}
12+
13+
const PopupExampleOnWithFocusTrap = () => (
14+
<div>
15+
<Popup
16+
trigger={<Button icon="expand" content="Click" aria-label="Click button" />}
17+
content={contentWithButtons}
18+
accessibility={popupFocusTrapBehavior}
19+
on="click"
20+
/>
21+
<Popup
22+
trigger={<Button icon="expand" content="Hover" aria-label="Hover button" />}
23+
content={contentWithButtons}
24+
accessibility={popupFocusTrapBehavior}
25+
on="hover"
26+
/>
27+
<Popup
28+
trigger={<Button icon="expand" content="Focus" aria-label="Focus button" />}
29+
content={contentWithButtons}
30+
accessibility={popupFocusTrapBehavior}
31+
on="focus"
32+
/>
33+
</div>
34+
)
35+
36+
export default PopupExampleOnWithFocusTrap
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as React from 'react'
2+
3+
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample'
4+
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection'
5+
6+
const Usage = () => (
7+
<ExampleSection title="Usage">
8+
<ComponentExample
9+
title="Triggering popup on different actions"
10+
description="A popup can be triggered on click, hover or focus."
11+
examplePath="components/Popup/Usage/PopupExampleOn"
12+
/>
13+
<ComponentExample
14+
title="Using the focus trap behavior"
15+
description="Combining the triggers with popup focus trap behavior, will focus the first focusable element inside the content of the popup."
16+
examplePath="components/Popup/Usage/PopupExampleOnWithFocusTrap"
17+
/>
18+
<ComponentExample
19+
title="Combined triggering actions"
20+
description="The triggering actions can be combined."
21+
examplePath="components/Popup/Usage/PopupExampleOnMultiple"
22+
/>
23+
</ExampleSection>
24+
)
25+
26+
export default Usage

docs/src/examples/components/Popup/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import * as React from 'react'
22
import Types from './Types'
33
import Variations from './Variations'
4+
import Usage from './Usage'
45

56
const PopupExamples = () => (
67
<div>
78
<Types />
89
<Variations />
10+
<Usage />
911
</div>
1012
)
1113

0 commit comments

Comments
 (0)