Skip to content

Commit

Permalink
🐛 FIX: useOutsideClick + Popover & Config Fixes (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylemcd committed Oct 3, 2023
1 parent f040b8b commit 2ec8f26
Show file tree
Hide file tree
Showing 33 changed files with 247 additions and 59 deletions.
16 changes: 16 additions & 0 deletions apps/interunit-dot-dev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# interunit-dot-dev

## 0.1.8

### Patch Changes

- Updated dependencies
- @interunit/popover@0.0.23
- @interunit/config@0.0.15
- @interunit/a11y@0.0.19
- @interunit/combobox@0.0.4
- @interunit/collapsible@0.0.17
- @interunit/form@0.0.13
- @interunit/modal@0.0.17
- @interunit/primitives@0.0.21
- @interunit/responsive@0.0.14
- @interunit/tabs@0.0.13

## 0.1.7

### Patch Changes
Expand Down
79 changes: 49 additions & 30 deletions apps/interunit-dot-dev/app/ui/docs/composites/popover/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const PopoverPage = () => {
data={{title: 'Popover', name, description, version, homepage}}
/>
<ComponentDisplay className="mb-12">
<Popover defaultValue={false}>
<Popover defaultValue={false} className="relative">
<Popover.Trigger asChild>
<Button color={'bg-secondary'}>Click me</Button>
</Popover.Trigger>
Expand Down Expand Up @@ -102,46 +102,41 @@ const PopoverPage = () => {
<PropsTable
propsToDisplay={[
{
name: 'triggerType',
type: `'click' | 'hover'`,
name: 'value',
type: `any`,
required: false,
default: 'click',
description:
'The user action that will trigger the popover. Note: on mobile hover will be ignored and click will be used instead. Also, click encompasses React Native onPress.'
default: '',
description: 'The controlled value of the popover'
},
{
name: 'defaultIsOpen',
type: `boolean`,
name: 'onValueChange',
type: `(any) => void`,
required: false,
default: 'false',
description: 'If true, the popover will be open by default'
default: '',
description: 'The controlled value setter of the popover'
},

{
name: 'settings',
type: `PopoverSettings`,
name: 'defaultValue',
type: `any`,
required: false,
default: '',
description: 'General settings for the popover.',
properties: [
{
name: 'shouldCloseOnInteractionOutside',
type: 'boolean',
required: false,
default: 'true',
description:
'If true, the popover will close when the user clicks outside of the popover'
}
]
description: 'The unconrolled value of the popover'
},

{
name: 'onPopoverChange',
type: `(popoverState) => void`,
name: 'asChild',
type: `boolean`,
required: false,
default: '',
default: 'false',
description:
'A callback that will be called when the popover state changes.'
'Use the built in Popover element or set asChild to true to provide your own'
},
{
name: 'shoudCloseOnOutsideClick',
type: `boolean`,
required: false,
default: 'true',
description:
'Whether or not the popover should close when clicking outside of it'
},
{
name: 'children',
Expand All @@ -159,6 +154,23 @@ const PopoverPage = () => {
</P.TX>
<PropsTable
propsToDisplay={[
{
name: 'interaction',
type: 'click | hover | none',
required: false,
default: 'click',
description:
'The interaction that will trigger the popover to open'
},
{
name: 'asChild',
type: `boolean`,
required: false,
default: 'false',
description:
'Use the built in Popover element or set asChild to true to provide your own'
},

{
name: 'children',
type: 'React.ReactNode',
Expand Down Expand Up @@ -283,7 +295,14 @@ const PopoverPage = () => {
}
]
},

{
name: 'asChild',
type: `boolean`,
required: false,
default: 'false',
description:
'Use the built in Popover element or set asChild to true to provide your own'
},
{
name: 'children',
type: 'React.ReactNode',
Expand Down
2 changes: 1 addition & 1 deletion apps/interunit-dot-dev/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "interunit-dot-dev",
"version": "0.1.7",
"version": "0.1.8",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
14 changes: 14 additions & 0 deletions apps/interunit-example-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# interunit-example-app

## 1.0.5

### Patch Changes

- Updated dependencies
- @interunit/popover@0.0.23
- @interunit/config@0.0.15
- @interunit/combobox@0.0.4
- @interunit/form@0.0.13
- @interunit/modal@0.0.17
- @interunit/primitives@0.0.21
- @interunit/responsive@0.0.14
- @interunit/tabs@0.0.13

## 1.0.4

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/interunit-example-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "interunit-example-app",
"version": "1.0.4",
"version": "1.0.5",
"main": "index.js",
"scripts": {
"dev:all": "expo start --dev-client",
Expand Down
17 changes: 17 additions & 0 deletions packages/a11y/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# @interunit/a11y

## 0.0.19

### Patch Changes

- - A11y
- Fix onOutsideClick hook
- Config
- Optional change the env var to avoid issues
- Popover
- Update docs
- re-enable outside click
- Add 'none' option for trigger interactionA
- Fix offset calculation
- Updated dependencies
- @interunit/config@0.0.15
- @interunit/primitives@0.0.21

## 0.0.18

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/a11y/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@interunit/a11y",
"version": "0.0.18",
"version": "0.0.19",
"description": "A11y utilities to use in InterUnit",
"homepage": "https://github.com/interunit/ui#readme",
"bugs": {
Expand Down
7 changes: 4 additions & 3 deletions packages/a11y/src/hooks/useOutsideClick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ const useOutsideClick = ({
fn,
isEnabled = true
}: {
ref: React.RefObject<any>
ref: any
fn: () => void
isEnabled?: boolean
}) => {
// no-op until we figure out how to get this working in native
if (getEnvironmentName() === 'native') return
const handleClick = (event: MouseEvent) => {
if (isEnabled && ref.current && !ref.current.contains(event.target)) {
fn()
if (!isEnabled || !ref || ref?.contains(event.target)) {
return
}
fn()
}

React.useEffect(() => {
Expand Down
9 changes: 9 additions & 0 deletions packages/collapsible/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @interunit/collapsible

## 0.0.17

### Patch Changes

- Updated dependencies
- @interunit/config@0.0.15
- @interunit/a11y@0.0.19
- @interunit/primitives@0.0.21

## 0.0.16

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/collapsible/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@interunit/collapsible",
"version": "0.0.16",
"version": "0.0.17",
"description": "A component that expands and collapses content",
"homepage": "https://github.com/interunit/ui#readme",
"bugs": {
Expand Down
11 changes: 11 additions & 0 deletions packages/combobox/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @interunit/combobox

## 0.0.4

### Patch Changes

- Updated dependencies
- @interunit/popover@0.0.23
- @interunit/config@0.0.15
- @interunit/a11y@0.0.19
- @interunit/primitives@0.0.21
- @interunit/toolbox@0.0.15

## 0.0.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/combobox/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@interunit/combobox",
"version": "0.0.3",
"version": "0.0.4",
"description": "",
"homepage": "https://github.com/interunit/ui#readme",
"bugs": {
Expand Down
14 changes: 14 additions & 0 deletions packages/config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# @interunit/config

## 0.0.15

### Patch Changes

- - A11y
- Fix onOutsideClick hook
- Config
- Optional change the env var to avoid issues
- Popover
- Update docs
- re-enable outside click
- Add 'none' option for trigger interactionA
- Fix offset calculation

## 0.0.14

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@interunit/config",
"version": "0.0.14",
"version": "0.0.15",
"description": "Handles all config for interactions between packages",
"homepage": "https://github.com/interunit/ui#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/helpers/getEnvironmentName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const getEnvironmentName = () => {
// so native tests run in a web env. This will fix that.
// Might need to rethink this using haste or some other solution
// if more problems arise from this same issue.
if (process.env.TEST_ENV_NAME) {
if (process?.env?.TEST_ENV_NAME) {
if (
process.env.TEST_ENV_NAME !== ('native' as string) &&
process.env.TEST_ENV_NAME !== ('web' as string)
Expand Down
8 changes: 8 additions & 0 deletions packages/crossplatform/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @interunit/crossplatform

## 0.0.15

### Patch Changes

- Updated dependencies
- @interunit/config@0.0.15
- @interunit/toolbox@0.0.15

## 0.0.14

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/crossplatform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@interunit/crossplatform",
"version": "0.0.14",
"version": "0.0.15",
"description": "Components and helpers to make cross-platform translations and development smooth",
"homepage": "https://github.com/interunit/ui#readme",
"bugs": {
Expand Down
9 changes: 9 additions & 0 deletions packages/form/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @interunit/form

## 0.0.13

### Patch Changes

- Updated dependencies
- @interunit/config@0.0.15
- @interunit/a11y@0.0.19
- @interunit/primitives@0.0.21

## 0.0.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/form/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@interunit/form",
"version": "0.0.12",
"version": "0.0.13",
"private": true,
"description": "Components for easily creating accessible forms",
"homepage": "https://github.com/interunit/ui/tree/main/packages/form",
Expand Down
9 changes: 9 additions & 0 deletions packages/modal/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @interunit/modal

## 0.0.17

### Patch Changes

- Updated dependencies
- @interunit/config@0.0.15
- @interunit/a11y@0.0.19
- @interunit/primitives@0.0.21

## 0.0.16

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/modal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@interunit/modal",
"version": "0.0.16",
"version": "0.0.17",
"description": "A low-level component to help display content on top of the current page or view",
"homepage": "https://github.com/interunit/ui#readme",
"bugs": {
Expand Down
Loading

0 comments on commit 2ec8f26

Please sign in to comment.