jy-headless 0.2.26 → 0.2.28
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/buttons/Button/Button.d.ts +1 -1
- package/buttons/Button/Button.js +3 -14
- package/cjs/buttons/Button/Button.d.ts +1 -1
- package/cjs/buttons/Button/Button.js +3 -14
- package/cjs/hooks/index.d.ts +3 -0
- package/cjs/hooks/useDebouncing.d.ts +2 -0
- package/cjs/hooks/useDebouncing.js +16 -0
- package/cjs/hooks/useDropdown.d.ts +10 -0
- package/cjs/hooks/useDropdown.js +32 -0
- package/cjs/hooks/useThrottling.d.ts +2 -0
- package/cjs/hooks/useThrottling.js +16 -0
- package/cjs/index.d.ts +6 -4
- package/cjs/index.js +6 -8
- package/cjs/inputs/Input/Input.d.ts +2 -2
- package/cjs/inputs/Input/Input.js +4 -3
- package/cjs/selectors/Dropdown/Dropdown.d.ts +8 -0
- package/cjs/selectors/Dropdown/Dropdown.js +55 -0
- package/cjs/selectors/Dropdown/DropdownDefaultTrigger.d.ts +4 -0
- package/cjs/selectors/index.d.ts +1 -0
- package/cjs/types/buttons/{types.d.ts → index.d.ts} +2 -1
- package/cjs/types/common/index.d.ts +7 -0
- package/cjs/types/index.d.ts +4 -2
- package/cjs/types/inputs/{types.d.ts → index.d.ts} +3 -1
- package/cjs/types/selectors/index.d.ts +16 -0
- package/cjs/utils/ArrayUtils.d.ts +1 -3
- package/hooks/index.d.ts +3 -0
- package/hooks/useDebouncing.d.ts +2 -0
- package/hooks/useDebouncing.js +14 -0
- package/hooks/useDropdown.d.ts +10 -0
- package/hooks/useDropdown.js +26 -0
- package/hooks/useThrottling.d.ts +2 -0
- package/hooks/useThrottling.js +14 -0
- package/index.d.ts +6 -4
- package/index.js +3 -4
- package/inputs/Input/Input.d.ts +2 -2
- package/inputs/Input/Input.js +4 -3
- package/package.json +23 -28
- package/selectors/Dropdown/Dropdown.d.ts +8 -0
- package/selectors/Dropdown/Dropdown.js +53 -0
- package/selectors/Dropdown/DropdownDefaultTrigger.d.ts +4 -0
- package/selectors/index.d.ts +1 -0
- package/types/buttons/{types.d.ts → index.d.ts} +2 -1
- package/types/common/index.d.ts +7 -0
- package/types/index.d.ts +4 -2
- package/types/inputs/{types.d.ts → index.d.ts} +3 -1
- package/types/selectors/index.d.ts +16 -0
- package/utils/ArrayUtils.d.ts +1 -3
- package/version.txt +1 -1
- package/cjs/types/index.js +0 -2
- package/cjs/utils/ArrayUtils.js +0 -9
- package/cjs/utils/index.js +0 -7
- package/types/index.js +0 -1
- package/utils/ArrayUtils.js +0 -7
- package/utils/index.js +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ButtonProps } from '../../types';
|
|
2
|
-
declare const Button: ({ onClick,
|
|
2
|
+
declare const Button: ({ onClick, loading, readOnly, disabled, useDebounce, timeout, children, ...props }: ButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export default Button;
|
package/buttons/Button/Button.js
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import
|
|
2
|
+
import useDebouncing from '../../hooks/useDebouncing.js';
|
|
3
3
|
|
|
4
|
-
const Button = ({ onClick,
|
|
5
|
-
const
|
|
6
|
-
const handleClick = (() => {
|
|
7
|
-
if (!onClick)
|
|
8
|
-
return;
|
|
9
|
-
if (debounce) {
|
|
10
|
-
return () => {
|
|
11
|
-
clearTimeout(timer.current);
|
|
12
|
-
timer.current = setTimeout(onClick, 300);
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
return onClick;
|
|
16
|
-
})();
|
|
4
|
+
const Button = ({ onClick, loading = false, readOnly = false, disabled = false, useDebounce = false, timeout = 300, children, ...props }) => {
|
|
5
|
+
const handleClick = onClick && useDebounce ? useDebouncing(onClick, timeout || 300) : onClick;
|
|
17
6
|
return (jsx("button", { onClick: handleClick, disabled: disabled || loading || readOnly, ...props, children: children }));
|
|
18
7
|
};
|
|
19
8
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ButtonProps } from '../../types';
|
|
2
|
-
declare const Button: ({ onClick,
|
|
2
|
+
declare const Button: ({ onClick, loading, readOnly, disabled, useDebounce, timeout, children, ...props }: ButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export default Button;
|
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
var
|
|
4
|
+
var useDebouncing = require('../../hooks/useDebouncing.js');
|
|
5
5
|
|
|
6
|
-
const Button = ({ onClick,
|
|
7
|
-
const
|
|
8
|
-
const handleClick = (() => {
|
|
9
|
-
if (!onClick)
|
|
10
|
-
return;
|
|
11
|
-
if (debounce) {
|
|
12
|
-
return () => {
|
|
13
|
-
clearTimeout(timer.current);
|
|
14
|
-
timer.current = setTimeout(onClick, 300);
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
return onClick;
|
|
18
|
-
})();
|
|
6
|
+
const Button = ({ onClick, loading = false, readOnly = false, disabled = false, useDebounce = false, timeout = 300, children, ...props }) => {
|
|
7
|
+
const handleClick = onClick && useDebounce ? useDebouncing(onClick, timeout || 300) : onClick;
|
|
19
8
|
return (jsxRuntime.jsx("button", { onClick: handleClick, disabled: disabled || loading || readOnly, ...props, children: children }));
|
|
20
9
|
};
|
|
21
10
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
const useDebouncing = (callback, delay) => {
|
|
6
|
+
const timer = react.useRef(null);
|
|
7
|
+
return react.useCallback(() => {
|
|
8
|
+
if (timer.current)
|
|
9
|
+
clearTimeout(timer.current);
|
|
10
|
+
timer.current = setTimeout(() => {
|
|
11
|
+
callback();
|
|
12
|
+
}, delay);
|
|
13
|
+
}, [callback, delay]);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
module.exports = useDebouncing;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DropdownContextValue } from '../types';
|
|
2
|
+
export declare const DropdownContext: import("react").Context<DropdownContextValue<any> | null>;
|
|
3
|
+
declare const useDropdown: <T>(defaultValue?: T | null) => {
|
|
4
|
+
isOpen: boolean;
|
|
5
|
+
selected: T | null;
|
|
6
|
+
toggle: () => void;
|
|
7
|
+
select: (value: T) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare const useDropdownContext: <T>() => DropdownContextValue<T>;
|
|
10
|
+
export default useDropdown;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
const DropdownContext = react.createContext(null);
|
|
8
|
+
const useDropdown = (defaultValue = null) => {
|
|
9
|
+
const [isOpen, setIsOpen] = react.useState(false);
|
|
10
|
+
const [selected, setSelected] = react.useState(defaultValue);
|
|
11
|
+
const toggle = () => setIsOpen((prev) => !prev);
|
|
12
|
+
const select = (value) => {
|
|
13
|
+
setSelected(value);
|
|
14
|
+
setIsOpen(false);
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
isOpen,
|
|
18
|
+
selected,
|
|
19
|
+
toggle,
|
|
20
|
+
select,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
const useDropdownContext = () => {
|
|
24
|
+
const context = react.useContext(DropdownContext);
|
|
25
|
+
if (!context)
|
|
26
|
+
throw new Error('Dropdown components must be used within <Dropdown>');
|
|
27
|
+
return context;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.DropdownContext = DropdownContext;
|
|
31
|
+
exports.default = useDropdown;
|
|
32
|
+
exports.useDropdownContext = useDropdownContext;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
const useThrottling = (callback, delay) => {
|
|
6
|
+
const lastCalled = react.useRef(0);
|
|
7
|
+
return react.useCallback((...args) => {
|
|
8
|
+
const now = Date.now();
|
|
9
|
+
if (now - lastCalled.current >= delay) {
|
|
10
|
+
lastCalled.current = now;
|
|
11
|
+
callback(...args);
|
|
12
|
+
}
|
|
13
|
+
}, [callback, delay]);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
module.exports = useThrottling;
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export { default as Button } from './buttons
|
|
2
|
-
export { default as Input } from './inputs
|
|
3
|
-
export
|
|
4
|
-
export *
|
|
1
|
+
export { default as Button } from './buttons';
|
|
2
|
+
export { default as Input } from './inputs';
|
|
3
|
+
export { default as Dropdown } from './selectors';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './utils';
|
|
6
|
+
export * from './hooks';
|
package/cjs/index.js
CHANGED
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
var Button = require('./buttons/Button/Button.js');
|
|
4
4
|
var Input = require('./inputs/Input/Input.js');
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function _interopNamespaceDefaultOnly (e) { return Object.freeze({ __proto__: null, default: e }); }
|
|
9
|
-
|
|
10
|
-
var index__namespace = /*#__PURE__*/_interopNamespaceDefaultOnly(index$1);
|
|
5
|
+
var Dropdown = require('./selectors/Dropdown/Dropdown.js');
|
|
6
|
+
require('react');
|
|
7
|
+
var useDropdown = require('./hooks/useDropdown.js');
|
|
11
8
|
|
|
12
9
|
|
|
13
10
|
|
|
14
11
|
exports.Button = Button;
|
|
15
12
|
exports.Input = Input;
|
|
16
|
-
exports.
|
|
17
|
-
exports.
|
|
13
|
+
exports.Dropdown = Dropdown;
|
|
14
|
+
exports.DropdownContext = useDropdown.DropdownContext;
|
|
15
|
+
exports.useDropdownContext = useDropdown.useDropdownContext;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { InputProps } from '../../types
|
|
2
|
-
declare const Input: ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass, children, ...props }: InputProps) => import("react/jsx-runtime").JSX.Element;
|
|
1
|
+
import { InputProps } from '../../types';
|
|
2
|
+
declare const Input: ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass, onChange, timeout, useThrottle, children, ...props }: InputProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export default Input;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
var
|
|
4
|
+
var useThrottling = require('../../hooks/useThrottling.js');
|
|
5
5
|
|
|
6
|
-
const Input = ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass, children, ...props }) => {
|
|
7
|
-
|
|
6
|
+
const Input = ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass = [], onChange, timeout = 300, useThrottle = false, children, ...props }) => {
|
|
7
|
+
const handleChange = onChange && useThrottle ? useThrottling(onChange, timeout) : onChange;
|
|
8
|
+
return (jsxRuntime.jsxs("span", { "data-testid": 'input-wrapper', id: [id, 'input-wrapper'].join('-'), className: wrapperClass?.join(' '), style: wrapperStyle, children: [prefixElement, jsxRuntime.jsx("input", { role: 'textbox', id: id, onChange: handleChange, ...props }), suffixElement] }));
|
|
8
9
|
};
|
|
9
10
|
|
|
10
11
|
module.exports = Input;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DivAttribute, DropdownProps, SpanAttribute } from '../../types';
|
|
2
|
+
declare const Dropdown: (<T>({ select, selected, isOpen, toggle, children, ...props }: DropdownProps<T>) => import("react/jsx-runtime").JSX.Element) & {
|
|
3
|
+
Button: <T>({ onClick, children, ...props }: SpanAttribute<T>) => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
Options: <T>({ children, ...props }: DivAttribute<T>) => import("react/jsx-runtime").JSX.Element | null;
|
|
5
|
+
Option: <T>({ children, value, ...props }: DivAttribute<T>) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
Viewer: ({ children, ...props }: SpanAttribute<null>) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
};
|
|
8
|
+
export default Dropdown;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var useDropdown = require('../../hooks/useDropdown.js');
|
|
6
|
+
|
|
7
|
+
const DropdownRoot = ({ select, selected, isOpen, toggle, children, ...props }) => {
|
|
8
|
+
const dropdownRef = react.useRef(null);
|
|
9
|
+
const unControlled = useDropdown.default();
|
|
10
|
+
const customValue = {
|
|
11
|
+
isOpen: isOpen ?? unControlled.isOpen,
|
|
12
|
+
toggle: toggle ?? unControlled.toggle,
|
|
13
|
+
select: select ?? unControlled.select,
|
|
14
|
+
selected: selected ?? unControlled.selected,
|
|
15
|
+
};
|
|
16
|
+
react.useEffect(() => {
|
|
17
|
+
if (!dropdownRef.current)
|
|
18
|
+
return;
|
|
19
|
+
const onClickOutside = (e) => {
|
|
20
|
+
if (!dropdownRef.current?.contains(e.target)) {
|
|
21
|
+
if (isOpen && toggle) {
|
|
22
|
+
toggle();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
window.addEventListener('click', onClickOutside);
|
|
27
|
+
return () => window.removeEventListener('click', onClickOutside);
|
|
28
|
+
}, [customValue]);
|
|
29
|
+
return (jsxRuntime.jsx("div", { ...props, ref: dropdownRef, children: jsxRuntime.jsx(useDropdown.DropdownContext.Provider, { value: customValue, children: children }) }));
|
|
30
|
+
};
|
|
31
|
+
const DropdownViewer = ({ children, ...props }) => {
|
|
32
|
+
return (jsxRuntime.jsx("span", { role: 'viewer', ...props, children: children }));
|
|
33
|
+
};
|
|
34
|
+
const DropdownButton = ({ onClick, children, ...props }) => {
|
|
35
|
+
const { toggle } = useDropdown.useDropdownContext();
|
|
36
|
+
return (jsxRuntime.jsx("span", { ...props, onClick: toggle, children: children }));
|
|
37
|
+
};
|
|
38
|
+
const DropdownOptions = ({ children, ...props }) => {
|
|
39
|
+
const { isOpen } = useDropdown.useDropdownContext();
|
|
40
|
+
if (!isOpen)
|
|
41
|
+
return null;
|
|
42
|
+
return jsxRuntime.jsx("div", { ...props, children: children });
|
|
43
|
+
};
|
|
44
|
+
const DropdownOption = ({ children, value, ...props }) => {
|
|
45
|
+
const { select } = useDropdown.useDropdownContext();
|
|
46
|
+
return (jsxRuntime.jsx("div", { role: "option", onClick: () => select(value), ...props, children: children }));
|
|
47
|
+
};
|
|
48
|
+
const Dropdown = Object.assign(DropdownRoot, {
|
|
49
|
+
Button: DropdownButton,
|
|
50
|
+
Options: DropdownOptions,
|
|
51
|
+
Option: DropdownOption,
|
|
52
|
+
Viewer: DropdownViewer,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
module.exports = Dropdown;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './Dropdown/Dropdown';
|
package/cjs/types/index.d.ts
CHANGED
|
@@ -3,5 +3,7 @@ export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
|
3
3
|
suffixElement?: ReactElement | ReactNode;
|
|
4
4
|
prefixElement?: ReactElement | ReactNode;
|
|
5
5
|
wrapperStyle?: CSSProperties;
|
|
6
|
-
wrapperClass?: string
|
|
6
|
+
wrapperClass?: string[];
|
|
7
|
+
useThrottle?: boolean;
|
|
8
|
+
timeout?: number;
|
|
7
9
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
|
+
export interface DropdownContextValue<T> {
|
|
3
|
+
isOpen: boolean;
|
|
4
|
+
toggle: () => void;
|
|
5
|
+
select: (value: T) => void;
|
|
6
|
+
selected: T | null;
|
|
7
|
+
}
|
|
8
|
+
export interface DropdownProps<T> extends HTMLAttributes<HTMLElement> {
|
|
9
|
+
isOpen?: boolean;
|
|
10
|
+
toggle?: () => void;
|
|
11
|
+
select?: (value: T) => void;
|
|
12
|
+
selected?: T | null;
|
|
13
|
+
}
|
|
14
|
+
export interface UseDropdownProps<T> {
|
|
15
|
+
defaultValue?: T;
|
|
16
|
+
}
|
package/hooks/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useRef, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
const useDebouncing = (callback, delay) => {
|
|
4
|
+
const timer = useRef(null);
|
|
5
|
+
return useCallback(() => {
|
|
6
|
+
if (timer.current)
|
|
7
|
+
clearTimeout(timer.current);
|
|
8
|
+
timer.current = setTimeout(() => {
|
|
9
|
+
callback();
|
|
10
|
+
}, delay);
|
|
11
|
+
}, [callback, delay]);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { useDebouncing as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DropdownContextValue } from '../types';
|
|
2
|
+
export declare const DropdownContext: import("react").Context<DropdownContextValue<any> | null>;
|
|
3
|
+
declare const useDropdown: <T>(defaultValue?: T | null) => {
|
|
4
|
+
isOpen: boolean;
|
|
5
|
+
selected: T | null;
|
|
6
|
+
toggle: () => void;
|
|
7
|
+
select: (value: T) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare const useDropdownContext: <T>() => DropdownContextValue<T>;
|
|
10
|
+
export default useDropdown;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createContext, useContext, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
const DropdownContext = createContext(null);
|
|
4
|
+
const useDropdown = (defaultValue = null) => {
|
|
5
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
6
|
+
const [selected, setSelected] = useState(defaultValue);
|
|
7
|
+
const toggle = () => setIsOpen((prev) => !prev);
|
|
8
|
+
const select = (value) => {
|
|
9
|
+
setSelected(value);
|
|
10
|
+
setIsOpen(false);
|
|
11
|
+
};
|
|
12
|
+
return {
|
|
13
|
+
isOpen,
|
|
14
|
+
selected,
|
|
15
|
+
toggle,
|
|
16
|
+
select,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
const useDropdownContext = () => {
|
|
20
|
+
const context = useContext(DropdownContext);
|
|
21
|
+
if (!context)
|
|
22
|
+
throw new Error('Dropdown components must be used within <Dropdown>');
|
|
23
|
+
return context;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { DropdownContext, useDropdown as default, useDropdownContext };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useRef, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
const useThrottling = (callback, delay) => {
|
|
4
|
+
const lastCalled = useRef(0);
|
|
5
|
+
return useCallback((...args) => {
|
|
6
|
+
const now = Date.now();
|
|
7
|
+
if (now - lastCalled.current >= delay) {
|
|
8
|
+
lastCalled.current = now;
|
|
9
|
+
callback(...args);
|
|
10
|
+
}
|
|
11
|
+
}, [callback, delay]);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { useThrottling as default };
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export { default as Button } from './buttons
|
|
2
|
-
export { default as Input } from './inputs
|
|
3
|
-
export
|
|
4
|
-
export *
|
|
1
|
+
export { default as Button } from './buttons';
|
|
2
|
+
export { default as Input } from './inputs';
|
|
3
|
+
export { default as Dropdown } from './selectors';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './utils';
|
|
6
|
+
export * from './hooks';
|
package/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { default as Button } from './buttons/Button/Button.js';
|
|
2
2
|
export { default as Input } from './inputs/Input/Input.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export { index$1 as Utils };
|
|
3
|
+
export { default as Dropdown } from './selectors/Dropdown/Dropdown.js';
|
|
4
|
+
import 'react';
|
|
5
|
+
export { DropdownContext, useDropdownContext } from './hooks/useDropdown.js';
|
package/inputs/Input/Input.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { InputProps } from '../../types
|
|
2
|
-
declare const Input: ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass, children, ...props }: InputProps) => import("react/jsx-runtime").JSX.Element;
|
|
1
|
+
import { InputProps } from '../../types';
|
|
2
|
+
declare const Input: ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass, onChange, timeout, useThrottle, children, ...props }: InputProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export default Input;
|
package/inputs/Input/Input.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import
|
|
2
|
+
import useThrottling from '../../hooks/useThrottling.js';
|
|
3
3
|
|
|
4
|
-
const Input = ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass, children, ...props }) => {
|
|
5
|
-
|
|
4
|
+
const Input = ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass = [], onChange, timeout = 300, useThrottle = false, children, ...props }) => {
|
|
5
|
+
const handleChange = onChange && useThrottle ? useThrottling(onChange, timeout) : onChange;
|
|
6
|
+
return (jsxs("span", { "data-testid": 'input-wrapper', id: [id, 'input-wrapper'].join('-'), className: wrapperClass?.join(' '), style: wrapperStyle, children: [prefixElement, jsx("input", { role: 'textbox', id: id, onChange: handleChange, ...props }), suffixElement] }));
|
|
6
7
|
};
|
|
7
8
|
|
|
8
9
|
export { Input as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jy-headless",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.28",
|
|
4
4
|
"description": "A lightweight and customizable headless UI library for React components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/yCZwIqY/jy-headless",
|
|
@@ -23,40 +23,35 @@
|
|
|
23
23
|
"require": "./cjs/cjs/index.js",
|
|
24
24
|
"types": "./cjs/index.d.ts"
|
|
25
25
|
},
|
|
26
|
+
"./useDebouncing": {
|
|
27
|
+
"import": "./hooks/useDebouncing.js",
|
|
28
|
+
"require": "./cjs/hooks/useDebouncing.js",
|
|
29
|
+
"types": "./hooks/useDebouncing.d.ts"
|
|
30
|
+
},
|
|
31
|
+
"./useDropdown": {
|
|
32
|
+
"import": "./hooks/useDropdown.js",
|
|
33
|
+
"require": "./cjs/hooks/useDropdown.js",
|
|
34
|
+
"types": "./hooks/useDropdown.d.ts"
|
|
35
|
+
},
|
|
36
|
+
"./useThrottling": {
|
|
37
|
+
"import": "./hooks/useThrottling.js",
|
|
38
|
+
"require": "./cjs/hooks/useThrottling.js",
|
|
39
|
+
"types": "./hooks/useThrottling.d.ts"
|
|
40
|
+
},
|
|
26
41
|
"./index": {
|
|
27
|
-
"import": "./
|
|
28
|
-
"require": "./cjs/
|
|
29
|
-
"types": "./
|
|
42
|
+
"import": "./index.js",
|
|
43
|
+
"require": "./cjs/index.js",
|
|
44
|
+
"types": "./index.d.ts"
|
|
30
45
|
},
|
|
31
46
|
"./Input": {
|
|
32
47
|
"import": "./inputs/Input/Input.js",
|
|
33
48
|
"require": "./cjs/inputs/Input/Input.js",
|
|
34
49
|
"types": "./inputs/Input/Input.d.ts"
|
|
35
50
|
},
|
|
36
|
-
"./
|
|
37
|
-
"import": "./
|
|
38
|
-
"require": "./cjs/
|
|
39
|
-
"types": "./
|
|
40
|
-
},
|
|
41
|
-
"./cjs/utils": {
|
|
42
|
-
"import": "./cjs/utils/index.js",
|
|
43
|
-
"require": "./cjs/cjs/utils/index.js",
|
|
44
|
-
"types": "./cjs/utils/index.d.ts"
|
|
45
|
-
},
|
|
46
|
-
"./ArrayUtils": {
|
|
47
|
-
"import": "./utils/ArrayUtils.js",
|
|
48
|
-
"require": "./cjs/utils/ArrayUtils.js",
|
|
49
|
-
"types": "./utils/ArrayUtils.d.ts"
|
|
50
|
-
},
|
|
51
|
-
"./types": {
|
|
52
|
-
"import": "./types/index.js",
|
|
53
|
-
"require": "./cjs/types/index.js",
|
|
54
|
-
"types": "./types/index.d.ts"
|
|
55
|
-
},
|
|
56
|
-
"./utils": {
|
|
57
|
-
"import": "./utils/index.js",
|
|
58
|
-
"require": "./cjs/utils/index.js",
|
|
59
|
-
"types": "./utils/index.d.ts"
|
|
51
|
+
"./Dropdown": {
|
|
52
|
+
"import": "./selectors/Dropdown/Dropdown.js",
|
|
53
|
+
"require": "./cjs/selectors/Dropdown/Dropdown.js",
|
|
54
|
+
"types": "./selectors/Dropdown/Dropdown.d.ts"
|
|
60
55
|
}
|
|
61
56
|
},
|
|
62
57
|
"keywords": [
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DivAttribute, DropdownProps, SpanAttribute } from '../../types';
|
|
2
|
+
declare const Dropdown: (<T>({ select, selected, isOpen, toggle, children, ...props }: DropdownProps<T>) => import("react/jsx-runtime").JSX.Element) & {
|
|
3
|
+
Button: <T>({ onClick, children, ...props }: SpanAttribute<T>) => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
Options: <T>({ children, ...props }: DivAttribute<T>) => import("react/jsx-runtime").JSX.Element | null;
|
|
5
|
+
Option: <T>({ children, value, ...props }: DivAttribute<T>) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
Viewer: ({ children, ...props }: SpanAttribute<null>) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
};
|
|
8
|
+
export default Dropdown;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useRef, useEffect } from 'react';
|
|
3
|
+
import useDropdown, { DropdownContext, useDropdownContext } from '../../hooks/useDropdown.js';
|
|
4
|
+
|
|
5
|
+
const DropdownRoot = ({ select, selected, isOpen, toggle, children, ...props }) => {
|
|
6
|
+
const dropdownRef = useRef(null);
|
|
7
|
+
const unControlled = useDropdown();
|
|
8
|
+
const customValue = {
|
|
9
|
+
isOpen: isOpen ?? unControlled.isOpen,
|
|
10
|
+
toggle: toggle ?? unControlled.toggle,
|
|
11
|
+
select: select ?? unControlled.select,
|
|
12
|
+
selected: selected ?? unControlled.selected,
|
|
13
|
+
};
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!dropdownRef.current)
|
|
16
|
+
return;
|
|
17
|
+
const onClickOutside = (e) => {
|
|
18
|
+
if (!dropdownRef.current?.contains(e.target)) {
|
|
19
|
+
if (isOpen && toggle) {
|
|
20
|
+
toggle();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
window.addEventListener('click', onClickOutside);
|
|
25
|
+
return () => window.removeEventListener('click', onClickOutside);
|
|
26
|
+
}, [customValue]);
|
|
27
|
+
return (jsx("div", { ...props, ref: dropdownRef, children: jsx(DropdownContext.Provider, { value: customValue, children: children }) }));
|
|
28
|
+
};
|
|
29
|
+
const DropdownViewer = ({ children, ...props }) => {
|
|
30
|
+
return (jsx("span", { role: 'viewer', ...props, children: children }));
|
|
31
|
+
};
|
|
32
|
+
const DropdownButton = ({ onClick, children, ...props }) => {
|
|
33
|
+
const { toggle } = useDropdownContext();
|
|
34
|
+
return (jsx("span", { ...props, onClick: toggle, children: children }));
|
|
35
|
+
};
|
|
36
|
+
const DropdownOptions = ({ children, ...props }) => {
|
|
37
|
+
const { isOpen } = useDropdownContext();
|
|
38
|
+
if (!isOpen)
|
|
39
|
+
return null;
|
|
40
|
+
return jsx("div", { ...props, children: children });
|
|
41
|
+
};
|
|
42
|
+
const DropdownOption = ({ children, value, ...props }) => {
|
|
43
|
+
const { select } = useDropdownContext();
|
|
44
|
+
return (jsx("div", { role: "option", onClick: () => select(value), ...props, children: children }));
|
|
45
|
+
};
|
|
46
|
+
const Dropdown = Object.assign(DropdownRoot, {
|
|
47
|
+
Button: DropdownButton,
|
|
48
|
+
Options: DropdownOptions,
|
|
49
|
+
Option: DropdownOption,
|
|
50
|
+
Viewer: DropdownViewer,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export { Dropdown as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './Dropdown/Dropdown';
|
package/types/index.d.ts
CHANGED
|
@@ -3,5 +3,7 @@ export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
|
3
3
|
suffixElement?: ReactElement | ReactNode;
|
|
4
4
|
prefixElement?: ReactElement | ReactNode;
|
|
5
5
|
wrapperStyle?: CSSProperties;
|
|
6
|
-
wrapperClass?: string
|
|
6
|
+
wrapperClass?: string[];
|
|
7
|
+
useThrottle?: boolean;
|
|
8
|
+
timeout?: number;
|
|
7
9
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
|
+
export interface DropdownContextValue<T> {
|
|
3
|
+
isOpen: boolean;
|
|
4
|
+
toggle: () => void;
|
|
5
|
+
select: (value: T) => void;
|
|
6
|
+
selected: T | null;
|
|
7
|
+
}
|
|
8
|
+
export interface DropdownProps<T> extends HTMLAttributes<HTMLElement> {
|
|
9
|
+
isOpen?: boolean;
|
|
10
|
+
toggle?: () => void;
|
|
11
|
+
select?: (value: T) => void;
|
|
12
|
+
selected?: T | null;
|
|
13
|
+
}
|
|
14
|
+
export interface UseDropdownProps<T> {
|
|
15
|
+
defaultValue?: T;
|
|
16
|
+
}
|
package/utils/ArrayUtils.d.ts
CHANGED
package/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.2.
|
|
1
|
+
0.2.28
|
package/cjs/types/index.js
DELETED
package/cjs/utils/ArrayUtils.js
DELETED
package/cjs/utils/index.js
DELETED
package/types/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/utils/ArrayUtils.js
DELETED
package/utils/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './ArrayUtils.js';
|