Skip to content

Commit 62ca5a3

Browse files
committed
Better naming and other minor enhancements
1 parent b7b1072 commit 62ca5a3

File tree

5 files changed

+607
-333
lines changed

5 files changed

+607
-333
lines changed

README.md

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ An accessible, "batteries included", popover component for React.
5151
[Check out the example on CodeSandbox](https://codesandbox.io/s/accessiblepopover-example-6l3u0)
5252

5353
```jsx harmony
54-
import {Popover, PopoverBox, PopoverMe} from '@accessible/popover'
54+
import {Popover, Dialog, Trigger} from '@accessible/popover'
5555

5656
const Component = () => (
5757
<Popover repositionOnScroll repositionOnResize>
58-
<PopoverBox placement="bottomLeft">
58+
<Dialog placement="bottomLeft">
5959
<div className="my-popover">Hello world</div>
60-
</PopoverBox>
60+
</Dialog>
6161

62-
<PopoverMe on="hover">
62+
<Trigger on="hover">
6363
<a href="/profile/me">
6464
<img src="avatar.jpg" />
6565
</a>
66-
</PopoverMe>
66+
</Trigger>
6767
</Popover>
6868
)
6969
```
@@ -72,11 +72,11 @@ const Component = () => (
7272

7373
### Components
7474

75-
| Component | Description |
76-
| ----------------------------- | ------------------------------------------------------------------------------------------------------------ |
77-
| [`<Popover>`](#popover) | This component creates the context for your popover box and trigger and contains some configuration options. |
78-
| [`<PopoverBox>`](#popoverbox) | This component wraps any React element and turns it into a popover box. |
79-
| [`<PopoverMe>`](#popoverme) | This component wraps any React element and turns it into a popover trigger. |
75+
| Component | Description |
76+
| ------------------------- | ------------------------------------------------------------------------------------------------------------ |
77+
| [`<Popover>`](#popover) | This component creates the context for your popover box and trigger and contains some configuration options. |
78+
| [`<Dialog>`](#popoverbox) | This component wraps any React element and turns it into a popover box. |
79+
| [`<Trigger>`](#popoverme) | This component wraps any React element and turns it into a popover trigger. |
8080

8181
### Hooks
8282

@@ -112,7 +112,7 @@ configuration options.
112112
| `"flipY"` | This will attempt to flip its position on only the `y` axis to attempt to remain within the bounds of the window. |
113113
| `function` | You can decide what to do with the popover on your own by providing a callback with the signature <code>(placement: string, triggerRect: ClientRect, popoverRect: ClientRect) => Placement &#124; PlacementResult</code> where [`Placement`](#placement) is a string returning an alternative placement and `PlacementResult` is an object shaped `{placement: Placement, style: CSSProperties}` |
114114

115-
### `<PopoverBox>`
115+
### `<Dialog>`
116116

117117
This component wraps any React element and turns it into a popover box.
118118

@@ -160,9 +160,9 @@ These are the default placements allowed by the popover relative to its triggeri
160160
#### Example
161161

162162
```jsx harmony
163-
<PopoverBox placement="innerTopLeft">
163+
<Dialog placement="innerTopLeft">
164164
<div className="menu">Menu</div>
165-
</PopoverBox>
165+
</Dialog>
166166

167167
// <div
168168
// class="menu"
@@ -176,23 +176,27 @@ These are the default placements allowed by the popover relative to its triggeri
176176
// </div>
177177
```
178178

179-
### `<PopoverMe>`
179+
### `<Trigger>`
180180

181181
This component wraps any React element and turns it into a popover trigger.
182182

183183
#### Props
184184

185-
| Prop | Type | Default | Required? | Description |
186-
| -------- | --------------------------------------------------- | ----------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
187-
| on | <code>"hover" &#124; "click" &#124; "focus" </code> | `undefined` | Yes | `"hover"` causes the popover to open on `mouseenter` and close on `mouseleave`. `"click"` causes the popover to toggle its visibility each `click` event. `"focus"` causes the popover to open when the child element is focused while nothing happens on blur. |
188-
| children | `React.ReactElement` | `undefined` | Yes | The child is cloned by this component and has aria attributes injected into its props as well as the events defined above. |
185+
| Prop | Type | Default | Required? | Description |
186+
| --------------- | --------------------------------------------------- | ----------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
187+
| on | <code>"hover" &#124; "click" &#124; "focus" </code> | `undefined` | Yes | `"hover"` causes the popover to open on `mouseenter` and close on `mouseleave`. `"click"` causes the popover to toggle its visibility each `click` event. `"focus"` causes the popover to open when the child element is focused while nothing happens on blur. |
188+
| closedClassName | `string` | `undefined` | No | This class name will be applied to the child element when the popover is `closed`. |
189+
| openClassName | `string` | `undefined` | No | This class name will be applied to the child element when the popover is `open`. |
190+
| closedStyle | `React.CSSProperties` | `undefined` | No | These styles will be applied to the child element when the popover is `closed`. |
191+
| openStyle | `React.CSSProperties` | `undefined` | No | These styles name will be applied to the child element when the popover is `open`. |
192+
| children | `React.ReactElement` | `undefined` | Yes | The child is cloned by this component and has aria attributes injected into its props as well as the events defined above. |
189193

190194
#### Example
191195

192196
```jsx harmony
193-
<PopoverMe on="click">
197+
<Trigger on="click">
194198
<button className="my-button">Popover me!</button>
195-
</PopoverMe>
199+
</Trigger>
196200

197201
// <button
198202
// class="my-button"
@@ -240,7 +244,7 @@ interface PopoverContextValue {
240244
// the rendered placement of the popover
241245
placement: Placement
242246
// sets the ref for the popover box
243-
ref: React.MutableRefObject<HTMLElement | null>
247+
dialogRef: React.MutableRefObject<HTMLElement | null>
244248
// sets the ref for the triggering element
245249
triggerRef: React.MutableRefObject<HTMLElement | null>
246250
// this describes the events that cause the popover
@@ -261,30 +265,30 @@ This hook provides access to the popover's rendered placement
261265
const Component = () => {
262266
const placement = usePlacement()
263267
return (
264-
<PopoverBox placement="top">
268+
<Dialog placement="top">
265269
<div className="my-popover">
266270
<span className={`arrow--${placement}`} />
267271
</div>
268-
</PopoverBox>
272+
</Dialog>
269273
)
270274
}
271275
```
272276

273277
### `useControls()`
274278

275-
This hook provides access to the popover's `open`, `close`, and `toggle` functions
279+
This hook provides access to the popover's `open`, `close`, `toggle`, and `reposition` functions
276280

277281
#### Example
278282

279283
```jsx harmony
280284
const Component = () => {
281285
const {open, close, toggle} = useControls()
282286
return (
283-
<PopoverBox>
287+
<Dialog>
284288
<div className="my-popover">
285289
<button onClick={close}>Close me</button>
286290
</div>
287-
</PopoverBox>
291+
</Dialog>
288292
)
289293
}
290294
```
@@ -299,9 +303,9 @@ This hook provides access to the popover's `isOpen` value
299303
const Component = () => {
300304
const isOpen = useIsOpen()
301305
return (
302-
<PopoverBox>
306+
<Dialog>
303307
<div className="my-popover">Am I open? {isOpen ? 'Yes' : 'No'}</div>
304-
</PopoverBox>
308+
</Dialog>
305309
)
306310
}
307311
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@accessible/popover",
3-
"version": "1.0.1",
3+
"version": "2.0.0",
44
"homepage": "https://github.com/accessible-ui/popover#readme",
55
"repository": "github:accessible-ui/popover",
66
"bugs": "https://github.com/accessible-ui/popover/issues",

0 commit comments

Comments
 (0)