@neovici/cosmoz-dropdown 3.3.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cosmoz-dropdown.js +1 -1
- package/dist/use-focus.d.ts +2 -0
- package/dist/use-focus.js +6 -5
- package/dist/use-position.js +1 -1
- package/package.json +10 -10
package/dist/cosmoz-dropdown.js
CHANGED
package/dist/use-focus.d.ts
CHANGED
|
@@ -3,12 +3,14 @@ export interface UseFocusOpts {
|
|
|
3
3
|
onFocus?: (focused: boolean) => void;
|
|
4
4
|
}
|
|
5
5
|
export declare const useFocus: ({ disabled, onFocus }: UseFocusOpts) => {
|
|
6
|
+
focused: boolean | undefined;
|
|
6
7
|
active: boolean | undefined;
|
|
7
8
|
setClosed: (closed: boolean) => void;
|
|
8
9
|
onToggle: (e: Event) => void;
|
|
9
10
|
onFocus: (e: FocusEvent) => void;
|
|
10
11
|
};
|
|
11
12
|
export declare const useHostFocus: (host: HTMLElement & UseFocusOpts) => {
|
|
13
|
+
focused: boolean | undefined;
|
|
12
14
|
active: boolean | undefined;
|
|
13
15
|
setClosed: (closed: boolean) => void;
|
|
14
16
|
onToggle: (e: Event) => void;
|
package/dist/use-focus.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { useEffect, useState, useCallback } from '
|
|
1
|
+
import { useEffect, useState, useCallback } from '@pionjs/pion';
|
|
2
2
|
import { useMeta } from '@neovici/cosmoz-utils/hooks/use-meta';
|
|
3
3
|
const isFocused = (t) => t.matches(':focus-within');
|
|
4
4
|
export const useFocus = ({ disabled, onFocus }) => {
|
|
5
|
-
const [focusState, setState] = useState(), { focused, closed } = focusState || {},
|
|
5
|
+
const [focusState, setState] = useState(), { focused: _focused, closed } = focusState || {}, focused = _focused && !disabled, meta = useMeta({ closed, onFocus }), setClosed = useCallback((closed) => setState((p) => ({ ...p, closed })), []), onToggle = useCallback((e) => {
|
|
6
6
|
const target = e.currentTarget;
|
|
7
7
|
return isFocused(target)
|
|
8
8
|
? setState((p) => ({ focused: true, closed: !p?.closed }))
|
|
9
9
|
: target.focus();
|
|
10
10
|
}, []);
|
|
11
11
|
useEffect(() => {
|
|
12
|
-
if (!
|
|
12
|
+
if (!focused) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
const handler = (e) => {
|
|
@@ -28,9 +28,10 @@ export const useFocus = ({ disabled, onFocus }) => {
|
|
|
28
28
|
};
|
|
29
29
|
document.addEventListener('keydown', handler, true);
|
|
30
30
|
return () => document.removeEventListener('keydown', handler, true);
|
|
31
|
-
}, [
|
|
31
|
+
}, [focused]);
|
|
32
32
|
return {
|
|
33
|
-
|
|
33
|
+
focused,
|
|
34
|
+
active: focused && !closed,
|
|
34
35
|
setClosed,
|
|
35
36
|
onToggle,
|
|
36
37
|
onFocus: useCallback((e) => {
|
package/dist/use-position.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// eslint-disable-next-line
|
|
2
2
|
/// <reference path="../types/position.d.ts" />
|
|
3
|
-
import { useEffect } from '
|
|
3
|
+
import { useEffect } from '@pionjs/pion';
|
|
4
4
|
import getPosition from 'position.js';
|
|
5
5
|
import { onScrolled } from './on-scrolled';
|
|
6
6
|
export const defaultPlacement = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-dropdown",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "A simple dropdown web component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lit-html",
|
|
@@ -69,23 +69,23 @@
|
|
|
69
69
|
"./src/use-position.js": "./dist/use-position.js"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@neovici/cosmoz-utils": "^
|
|
73
|
-
"
|
|
74
|
-
"lit-html": "^2.0.0",
|
|
72
|
+
"@neovici/cosmoz-utils": "^6.0.0",
|
|
73
|
+
"@pionjs/pion": "^2.0.0",
|
|
75
74
|
"position.js": "^0.3.0"
|
|
76
75
|
},
|
|
77
76
|
"devDependencies": {
|
|
78
|
-
"@commitlint/cli": "^
|
|
79
|
-
"@commitlint/config-conventional": "^
|
|
77
|
+
"@commitlint/cli": "^18.0.0",
|
|
78
|
+
"@commitlint/config-conventional": "^18.0.0",
|
|
80
79
|
"@neovici/cfg": "^1.15.2",
|
|
81
|
-
"@open-wc/testing": "^
|
|
80
|
+
"@open-wc/testing": "^4.0.0",
|
|
82
81
|
"@semantic-release/changelog": "^6.0.0",
|
|
83
82
|
"@semantic-release/git": "^10.0.0",
|
|
84
83
|
"@storybook/storybook-deployer": "^2.8.5",
|
|
85
|
-
"@
|
|
84
|
+
"@types/mocha": "^10.0.6",
|
|
85
|
+
"@web/dev-server-storybook": "^2.0.0",
|
|
86
86
|
"husky": "^8.0.0",
|
|
87
|
-
"semantic-release": "^
|
|
88
|
-
"sinon": "^
|
|
87
|
+
"semantic-release": "^22.0.0",
|
|
88
|
+
"sinon": "^17.0.0",
|
|
89
89
|
"typescript": "^5.0.0"
|
|
90
90
|
}
|
|
91
91
|
}
|