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.
Files changed (54) hide show
  1. package/buttons/Button/Button.d.ts +1 -1
  2. package/buttons/Button/Button.js +3 -14
  3. package/cjs/buttons/Button/Button.d.ts +1 -1
  4. package/cjs/buttons/Button/Button.js +3 -14
  5. package/cjs/hooks/index.d.ts +3 -0
  6. package/cjs/hooks/useDebouncing.d.ts +2 -0
  7. package/cjs/hooks/useDebouncing.js +16 -0
  8. package/cjs/hooks/useDropdown.d.ts +10 -0
  9. package/cjs/hooks/useDropdown.js +32 -0
  10. package/cjs/hooks/useThrottling.d.ts +2 -0
  11. package/cjs/hooks/useThrottling.js +16 -0
  12. package/cjs/index.d.ts +6 -4
  13. package/cjs/index.js +6 -8
  14. package/cjs/inputs/Input/Input.d.ts +2 -2
  15. package/cjs/inputs/Input/Input.js +4 -3
  16. package/cjs/selectors/Dropdown/Dropdown.d.ts +8 -0
  17. package/cjs/selectors/Dropdown/Dropdown.js +55 -0
  18. package/cjs/selectors/Dropdown/DropdownDefaultTrigger.d.ts +4 -0
  19. package/cjs/selectors/index.d.ts +1 -0
  20. package/cjs/types/buttons/{types.d.ts → index.d.ts} +2 -1
  21. package/cjs/types/common/index.d.ts +7 -0
  22. package/cjs/types/index.d.ts +4 -2
  23. package/cjs/types/inputs/{types.d.ts → index.d.ts} +3 -1
  24. package/cjs/types/selectors/index.d.ts +16 -0
  25. package/cjs/utils/ArrayUtils.d.ts +1 -3
  26. package/hooks/index.d.ts +3 -0
  27. package/hooks/useDebouncing.d.ts +2 -0
  28. package/hooks/useDebouncing.js +14 -0
  29. package/hooks/useDropdown.d.ts +10 -0
  30. package/hooks/useDropdown.js +26 -0
  31. package/hooks/useThrottling.d.ts +2 -0
  32. package/hooks/useThrottling.js +14 -0
  33. package/index.d.ts +6 -4
  34. package/index.js +3 -4
  35. package/inputs/Input/Input.d.ts +2 -2
  36. package/inputs/Input/Input.js +4 -3
  37. package/package.json +23 -28
  38. package/selectors/Dropdown/Dropdown.d.ts +8 -0
  39. package/selectors/Dropdown/Dropdown.js +53 -0
  40. package/selectors/Dropdown/DropdownDefaultTrigger.d.ts +4 -0
  41. package/selectors/index.d.ts +1 -0
  42. package/types/buttons/{types.d.ts → index.d.ts} +2 -1
  43. package/types/common/index.d.ts +7 -0
  44. package/types/index.d.ts +4 -2
  45. package/types/inputs/{types.d.ts → index.d.ts} +3 -1
  46. package/types/selectors/index.d.ts +16 -0
  47. package/utils/ArrayUtils.d.ts +1 -3
  48. package/version.txt +1 -1
  49. package/cjs/types/index.js +0 -2
  50. package/cjs/utils/ArrayUtils.js +0 -9
  51. package/cjs/utils/index.js +0 -7
  52. package/types/index.js +0 -1
  53. package/utils/ArrayUtils.js +0 -7
  54. package/utils/index.js +0 -1
@@ -1,3 +1,3 @@
1
1
  import type { ButtonProps } from '../../types';
2
- declare const Button: ({ onClick, debounce, loading, readOnly, disabled, children, ...props }: ButtonProps) => import("react/jsx-runtime").JSX.Element;
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,19 +1,8 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
- import { useRef } from 'react';
2
+ import useDebouncing from '../../hooks/useDebouncing.js';
3
3
 
4
- const Button = ({ onClick, debounce = false, loading = false, readOnly = false, disabled = false, children, ...props }) => {
5
- const timer = useRef(0);
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, debounce, loading, readOnly, disabled, children, ...props }: ButtonProps) => import("react/jsx-runtime").JSX.Element;
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 react = require('react');
4
+ var useDebouncing = require('../../hooks/useDebouncing.js');
5
5
 
6
- const Button = ({ onClick, debounce = false, loading = false, readOnly = false, disabled = false, children, ...props }) => {
7
- const timer = react.useRef(0);
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,3 @@
1
+ export * from './useDebouncing';
2
+ export * from './useThrottling';
3
+ export * from './useDropdown';
@@ -0,0 +1,2 @@
1
+ declare const useDebouncing: <T extends (...args: any[]) => void>(callback: T, delay: number) => T;
2
+ export default useDebouncing;
@@ -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,2 @@
1
+ declare const useThrottling: <T extends (...args: any[]) => void>(callback: T, delay: number) => T;
2
+ export default useThrottling;
@@ -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/Button/Button';
2
- export { default as Input } from './inputs/Input/Input';
3
- export * as Types from './types';
4
- export * as Utils from './utils';
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 index = require('./types/index.js');
6
- var index$1 = require('./utils/index.js');
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.Types = index;
17
- exports.Utils = index__namespace;
13
+ exports.Dropdown = Dropdown;
14
+ exports.DropdownContext = useDropdown.DropdownContext;
15
+ exports.useDropdownContext = useDropdown.useDropdownContext;
@@ -1,3 +1,3 @@
1
- import { InputProps } from '../../types/inputs/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 ArrayUtils = require('../../utils/ArrayUtils.js');
4
+ var useThrottling = require('../../hooks/useThrottling.js');
5
5
 
6
- const Input = ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass, children, ...props }) => {
7
- return (jsxRuntime.jsxs("span", { "data-testid": 'input-wrapper', id: [id, 'input-wrapper'].join('-'), className: wrapperClass && ArrayUtils.toFlat(wrapperClass).join(' '), style: wrapperStyle, children: [prefixElement, jsxRuntime.jsx("input", { id: id, ...props }), suffixElement] }));
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,4 @@
1
+ declare const DropdownDefaultTrigger: ({ value }: {
2
+ value: boolean;
3
+ }) => import("react/jsx-runtime").JSX.Element;
4
+ export default DropdownDefaultTrigger;
@@ -0,0 +1 @@
1
+ export { default } from './Dropdown/Dropdown';
@@ -1,6 +1,7 @@
1
1
  import { ButtonHTMLAttributes } from 'react';
2
2
  export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
3
- debounce?: boolean;
4
3
  loading?: boolean;
5
4
  readOnly?: boolean;
5
+ useDebounce?: boolean;
6
+ timeout?: number;
6
7
  }
@@ -0,0 +1,7 @@
1
+ import { HTMLAttributes } from 'react';
2
+ export interface DivAttribute<T> extends HTMLAttributes<HTMLDivElement> {
3
+ value?: T;
4
+ }
5
+ export interface SpanAttribute<T> extends HTMLAttributes<HTMLSpanElement> {
6
+ value?: T;
7
+ }
@@ -1,2 +1,4 @@
1
- export * from './buttons/types';
2
- export * from './inputs/types';
1
+ export * from './buttons';
2
+ export * from './inputs';
3
+ export * from './selectors';
4
+ export * from './common';
@@ -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 | 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
+ }
@@ -1,4 +1,2 @@
1
- declare const ArrayUtils: {
2
- toFlat(...args: (string | string[])[]): string[];
3
- };
1
+ declare const ArrayUtils: {};
4
2
  export default ArrayUtils;
@@ -0,0 +1,3 @@
1
+ export * from './useDebouncing';
2
+ export * from './useThrottling';
3
+ export * from './useDropdown';
@@ -0,0 +1,2 @@
1
+ declare const useDebouncing: <T extends (...args: any[]) => void>(callback: T, delay: number) => T;
2
+ export default useDebouncing;
@@ -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,2 @@
1
+ declare const useThrottling: <T extends (...args: any[]) => void>(callback: T, delay: number) => T;
2
+ export default useThrottling;
@@ -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/Button/Button';
2
- export { default as Input } from './inputs/Input/Input';
3
- export * as Types from './types';
4
- export * as Utils from './utils';
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
- import * as index from './types/index.js';
4
- export { index as Types };
5
- import * as index$1 from './utils/index.js';
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';
@@ -1,3 +1,3 @@
1
- import { InputProps } from '../../types/inputs/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,8 +1,9 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
- import ArrayUtils from '../../utils/ArrayUtils.js';
2
+ import useThrottling from '../../hooks/useThrottling.js';
3
3
 
4
- const Input = ({ id, suffixElement, prefixElement, wrapperStyle, wrapperClass, children, ...props }) => {
5
- return (jsxs("span", { "data-testid": 'input-wrapper', id: [id, 'input-wrapper'].join('-'), className: wrapperClass && ArrayUtils.toFlat(wrapperClass).join(' '), style: wrapperStyle, children: [prefixElement, jsx("input", { id: id, ...props }), suffixElement] }));
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.26",
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": "./utils/index.js",
28
- "require": "./cjs/utils/index.js",
29
- "types": "./utils/index.d.ts"
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
- "./cjs/types": {
37
- "import": "./cjs/types/index.js",
38
- "require": "./cjs/cjs/types/index.js",
39
- "types": "./cjs/types/index.d.ts"
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,4 @@
1
+ declare const DropdownDefaultTrigger: ({ value }: {
2
+ value: boolean;
3
+ }) => import("react/jsx-runtime").JSX.Element;
4
+ export default DropdownDefaultTrigger;
@@ -0,0 +1 @@
1
+ export { default } from './Dropdown/Dropdown';
@@ -1,6 +1,7 @@
1
1
  import { ButtonHTMLAttributes } from 'react';
2
2
  export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
3
- debounce?: boolean;
4
3
  loading?: boolean;
5
4
  readOnly?: boolean;
5
+ useDebounce?: boolean;
6
+ timeout?: number;
6
7
  }
@@ -0,0 +1,7 @@
1
+ import { HTMLAttributes } from 'react';
2
+ export interface DivAttribute<T> extends HTMLAttributes<HTMLDivElement> {
3
+ value?: T;
4
+ }
5
+ export interface SpanAttribute<T> extends HTMLAttributes<HTMLSpanElement> {
6
+ value?: T;
7
+ }
package/types/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
- export * from './buttons/types';
2
- export * from './inputs/types';
1
+ export * from './buttons';
2
+ export * from './inputs';
3
+ export * from './selectors';
4
+ export * from './common';
@@ -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 | 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
+ }
@@ -1,4 +1,2 @@
1
- declare const ArrayUtils: {
2
- toFlat(...args: (string | string[])[]): string[];
3
- };
1
+ declare const ArrayUtils: {};
4
2
  export default ArrayUtils;
package/version.txt CHANGED
@@ -1 +1 @@
1
- 0.2.26
1
+ 0.2.28
@@ -1,2 +0,0 @@
1
- 'use strict';
2
-
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- const ArrayUtils = {
4
- toFlat(...args) {
5
- return args.flat().map(String).filter(Boolean);
6
- },
7
- };
8
-
9
- module.exports = ArrayUtils;
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- var ArrayUtils = require('./ArrayUtils.js');
4
-
5
-
6
-
7
- module.exports = ArrayUtils;
package/types/index.js DELETED
@@ -1 +0,0 @@
1
-
@@ -1,7 +0,0 @@
1
- const ArrayUtils = {
2
- toFlat(...args) {
3
- return args.flat().map(String).filter(Boolean);
4
- },
5
- };
6
-
7
- export { ArrayUtils as default };
package/utils/index.js DELETED
@@ -1 +0,0 @@
1
- export { default } from './ArrayUtils.js';