jy-headless 0.2.31 → 0.2.34

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/cjs/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './buttons';
2
2
  export * from './inputs';
3
3
  export * from './selectors';
4
+ export * from './tooltip';
4
5
  export * from './types';
5
6
  export * from './utils';
6
7
  export * from './hooks';
package/cjs/index.js CHANGED
@@ -4,6 +4,7 @@ var Button = require('./buttons/Button/Button.js');
4
4
  var Input = require('./inputs/Input/Input.js');
5
5
  var ImageInput = require('./inputs/ImageInput/ImageInput.js');
6
6
  var Dropdown = require('./selectors/Dropdown/Dropdown.js');
7
+ var Tooltip = require('./tooltip/Tooltip/Tooltip.js');
7
8
  require('react');
8
9
  var useDropdown = require('./hooks/useDropdown.js');
9
10
 
@@ -12,6 +13,7 @@ function _interopNamespaceDefaultOnly (e) { return Object.freeze({ __proto__: nu
12
13
  var Button__namespace = /*#__PURE__*/_interopNamespaceDefaultOnly(Button);
13
14
  var Input__namespace = /*#__PURE__*/_interopNamespaceDefaultOnly(Input);
14
15
  var Dropdown__namespace = /*#__PURE__*/_interopNamespaceDefaultOnly(Dropdown);
16
+ var Tooltip__namespace = /*#__PURE__*/_interopNamespaceDefaultOnly(Tooltip);
15
17
 
16
18
 
17
19
 
@@ -19,5 +21,6 @@ exports.Button = Button__namespace;
19
21
  exports.Input = Input__namespace;
20
22
  exports.ImageInput = ImageInput;
21
23
  exports.Dropdown = Dropdown__namespace;
24
+ exports.Tooltip = Tooltip__namespace;
22
25
  exports.DropdownContext = useDropdown.DropdownContext;
23
26
  exports.useDropdownContext = useDropdown.useDropdownContext;
@@ -1,3 +1,3 @@
1
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;
2
+ declare const Input: ({ id, value, suffixElement, prefixElement, wrapperStyle, wrapperClass, onChange, timeout, children, showLimit, maxLength, onThrottledChange, ...props }: InputProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default Input;
@@ -3,9 +3,15 @@
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
4
  var useThrottling = require('../../hooks/useThrottling.js');
5
5
 
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] }));
6
+ const Input = ({ id, value, suffixElement, prefixElement, wrapperStyle, wrapperClass = [], onChange, timeout = 300, children, showLimit, maxLength, onThrottledChange, ...props }) => {
7
+ const throttledOnChange = onThrottledChange ? useThrottling(onThrottledChange, timeout) : null;
8
+ const handleChange = (e) => {
9
+ if (maxLength && e.target.value?.length > maxLength)
10
+ return;
11
+ onChange?.(e);
12
+ throttledOnChange?.(e);
13
+ };
14
+ 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, value: value, onChange: handleChange, ...props }), showLimit && maxLength && (jsxRuntime.jsxs("span", { id: [id, 'input-limit'].join('-'), children: [(value ?? '').toString().length, "/", maxLength] })), suffixElement] }));
9
15
  };
10
16
 
11
17
  module.exports = Input;
@@ -0,0 +1,5 @@
1
+ import { TooltipProps } from '../../types/tooltip';
2
+ declare const Tooltip: (({ children, style, position, space, ...props }: TooltipProps) => import("react/jsx-runtime").JSX.Element) & {
3
+ Label: ({ children, style, ...props }: React.HTMLAttributes<HTMLDivElement>) => import("react/jsx-runtime").JSX.Element;
4
+ };
5
+ export default Tooltip;
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+ var index = require('../../types/tooltip/index.js');
6
+
7
+ const TooltipRoot = ({ children, style, position = 'top', space = 8, ...props }) => {
8
+ const [showTooltip, setShowTooltip] = react.useState(false);
9
+ const [tooltipPosition, setTooltipPosition] = react.useState({});
10
+ react.useEffect(() => {
11
+ if (!showTooltip)
12
+ return;
13
+ const positionStyles = {
14
+ zIndex: 1000,
15
+ };
16
+ switch (position) {
17
+ case 'top':
18
+ positionStyles.bottom = `calc(100% + ${space}px)`;
19
+ positionStyles.left = '50%';
20
+ positionStyles.transform = 'translateX(-50%)';
21
+ break;
22
+ case 'bottom':
23
+ positionStyles.top = `calc(100% + ${space}px)`;
24
+ positionStyles.left = '50%';
25
+ positionStyles.transform = 'translateX(-50%)';
26
+ break;
27
+ case 'left':
28
+ positionStyles.right = `calc(100% + ${space}px)`;
29
+ positionStyles.top = '50%';
30
+ positionStyles.transform = 'translateY(-50%)';
31
+ break;
32
+ case 'right':
33
+ positionStyles.left = `calc(100% + ${space}px)`;
34
+ positionStyles.top = '50%';
35
+ positionStyles.transform = 'translateY(-50%)';
36
+ break;
37
+ }
38
+ setTooltipPosition(positionStyles);
39
+ }, [showTooltip, position]);
40
+ const onMouseOver = () => setShowTooltip(true);
41
+ const onMouseLeave = () => setShowTooltip(false);
42
+ return (jsxRuntime.jsx("div", { style: {
43
+ position: 'relative',
44
+ display: 'inline-block', // 자식 크기에 영향 안 받도록
45
+ ...style,
46
+ }, onMouseOver: onMouseOver, onMouseLeave: onMouseLeave, ...props, children: jsxRuntime.jsx(index.TooltipContext.Provider, { value: { show: showTooltip, tooltipPosition }, children: children }) }));
47
+ };
48
+ const TooltipLabel = ({ children, style, ...props }) => {
49
+ const context = react.useContext(index.TooltipContext);
50
+ if (!context) {
51
+ throw new Error('Tooltip.* 컴포넌트는 Tooltip 내에서만 사용해야 합니다.');
52
+ }
53
+ const { show, tooltipPosition } = context;
54
+ const labelStyle = {
55
+ position: 'absolute',
56
+ visibility: show ? 'visible' : 'hidden',
57
+ ...tooltipPosition,
58
+ ...style,
59
+ };
60
+ return (jsxRuntime.jsx("div", { style: labelStyle, ...props, children: children }));
61
+ };
62
+ const Tooltip = Object.assign(TooltipRoot, {
63
+ Label: TooltipLabel,
64
+ });
65
+
66
+ module.exports = Tooltip;
@@ -0,0 +1 @@
1
+ export * as Tooltip from './Tooltip/Tooltip';
@@ -1,11 +1,13 @@
1
- import { CSSProperties, InputHTMLAttributes, ReactElement, ReactNode } from 'react';
1
+ import { ChangeEvent, CSSProperties, InputHTMLAttributes, ReactElement, ReactNode } from 'react';
2
2
  export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
3
3
  suffixElement?: ReactElement | ReactNode;
4
4
  prefixElement?: ReactElement | ReactNode;
5
5
  wrapperStyle?: CSSProperties;
6
6
  wrapperClass?: string[];
7
- useThrottle?: boolean;
8
7
  timeout?: number;
8
+ showLimit?: boolean;
9
+ maxLength?: number;
10
+ onThrottledChange?: (e: ChangeEvent<HTMLInputElement>) => void;
9
11
  }
10
12
  export interface ImageInputContextData {
11
13
  id?: string;
@@ -0,0 +1,14 @@
1
+ import { CSSProperties, HTMLAttributes, ReactNode } from 'react';
2
+ export type TooltipPosition = 'top' | 'bottom' | 'left' | 'right';
3
+ export interface TooltipProps extends HTMLAttributes<HTMLDivElement> {
4
+ children: ReactNode;
5
+ position?: TooltipPosition;
6
+ style?: CSSProperties;
7
+ space?: number;
8
+ }
9
+ interface TooltipContextProps {
10
+ show: boolean;
11
+ tooltipPosition: CSSProperties;
12
+ }
13
+ export declare const TooltipContext: import("react").Context<TooltipContextProps | null>;
14
+ export {};
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+
5
+ const TooltipContext = react.createContext(null);
6
+
7
+ exports.TooltipContext = TooltipContext;
package/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './buttons';
2
2
  export * from './inputs';
3
3
  export * from './selectors';
4
+ export * from './tooltip';
4
5
  export * from './types';
5
6
  export * from './utils';
6
7
  export * from './hooks';
package/index.js CHANGED
@@ -6,5 +6,7 @@ import * as ImageInput from './inputs/ImageInput/ImageInput.js';
6
6
  export { ImageInput };
7
7
  import * as Dropdown from './selectors/Dropdown/Dropdown.js';
8
8
  export { Dropdown };
9
+ import * as Tooltip from './tooltip/Tooltip/Tooltip.js';
10
+ export { Tooltip };
9
11
  import 'react';
10
12
  export { DropdownContext, useDropdownContext } from './hooks/useDropdown.js';
@@ -1,3 +1,3 @@
1
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;
2
+ declare const Input: ({ id, value, suffixElement, prefixElement, wrapperStyle, wrapperClass, onChange, timeout, children, showLimit, maxLength, onThrottledChange, ...props }: InputProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default Input;
@@ -1,9 +1,15 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
2
  import useThrottling from '../../hooks/useThrottling.js';
3
3
 
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] }));
4
+ const Input = ({ id, value, suffixElement, prefixElement, wrapperStyle, wrapperClass = [], onChange, timeout = 300, children, showLimit, maxLength, onThrottledChange, ...props }) => {
5
+ const throttledOnChange = onThrottledChange ? useThrottling(onThrottledChange, timeout) : null;
6
+ const handleChange = (e) => {
7
+ if (maxLength && e.target.value?.length > maxLength)
8
+ return;
9
+ onChange?.(e);
10
+ throttledOnChange?.(e);
11
+ };
12
+ 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, value: value, onChange: handleChange, ...props }), showLimit && maxLength && (jsxs("span", { id: [id, 'input-limit'].join('-'), children: [(value ?? '').toString().length, "/", maxLength] })), suffixElement] }));
7
13
  };
8
14
 
9
15
  export { Input as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jy-headless",
3
- "version": "0.2.31",
3
+ "version": "0.2.34",
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",
@@ -39,9 +39,9 @@
39
39
  "types": "./hooks/useThrottling.d.ts"
40
40
  },
41
41
  "./index": {
42
- "import": "./index.js",
43
- "require": "./cjs/index.js",
44
- "types": "./index.d.ts"
42
+ "import": "./types/tooltip/index.js",
43
+ "require": "./cjs/types/tooltip/index.js",
44
+ "types": "./types/tooltip/index.d.ts"
45
45
  },
46
46
  "./ImageInput": {
47
47
  "import": "./inputs/ImageInput/ImageInput.js",
@@ -57,6 +57,21 @@
57
57
  "import": "./selectors/Dropdown/Dropdown.js",
58
58
  "require": "./cjs/selectors/Dropdown/Dropdown.js",
59
59
  "types": "./selectors/Dropdown/Dropdown.d.ts"
60
+ },
61
+ "./Tooltip": {
62
+ "import": "./tooltip/Tooltip/Tooltip.js",
63
+ "require": "./cjs/tooltip/Tooltip/Tooltip.js",
64
+ "types": "./tooltip/Tooltip/Tooltip.d.ts"
65
+ },
66
+ "./cjs/types/tooltip": {
67
+ "import": "./cjs/types/tooltip/index.js",
68
+ "require": "./cjs/cjs/types/tooltip/index.js",
69
+ "types": "./cjs/types/tooltip/index.d.ts"
70
+ },
71
+ "./types/tooltip": {
72
+ "import": "./types/tooltip/index.js",
73
+ "require": "./cjs/types/tooltip/index.js",
74
+ "types": "./types/tooltip/index.d.ts"
60
75
  }
61
76
  },
62
77
  "keywords": [
@@ -0,0 +1,5 @@
1
+ import { TooltipProps } from '../../types/tooltip';
2
+ declare const Tooltip: (({ children, style, position, space, ...props }: TooltipProps) => import("react/jsx-runtime").JSX.Element) & {
3
+ Label: ({ children, style, ...props }: React.HTMLAttributes<HTMLDivElement>) => import("react/jsx-runtime").JSX.Element;
4
+ };
5
+ export default Tooltip;
@@ -0,0 +1,64 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { useState, useEffect, useContext } from 'react';
3
+ import { TooltipContext } from '../../types/tooltip/index.js';
4
+
5
+ const TooltipRoot = ({ children, style, position = 'top', space = 8, ...props }) => {
6
+ const [showTooltip, setShowTooltip] = useState(false);
7
+ const [tooltipPosition, setTooltipPosition] = useState({});
8
+ useEffect(() => {
9
+ if (!showTooltip)
10
+ return;
11
+ const positionStyles = {
12
+ zIndex: 1000,
13
+ };
14
+ switch (position) {
15
+ case 'top':
16
+ positionStyles.bottom = `calc(100% + ${space}px)`;
17
+ positionStyles.left = '50%';
18
+ positionStyles.transform = 'translateX(-50%)';
19
+ break;
20
+ case 'bottom':
21
+ positionStyles.top = `calc(100% + ${space}px)`;
22
+ positionStyles.left = '50%';
23
+ positionStyles.transform = 'translateX(-50%)';
24
+ break;
25
+ case 'left':
26
+ positionStyles.right = `calc(100% + ${space}px)`;
27
+ positionStyles.top = '50%';
28
+ positionStyles.transform = 'translateY(-50%)';
29
+ break;
30
+ case 'right':
31
+ positionStyles.left = `calc(100% + ${space}px)`;
32
+ positionStyles.top = '50%';
33
+ positionStyles.transform = 'translateY(-50%)';
34
+ break;
35
+ }
36
+ setTooltipPosition(positionStyles);
37
+ }, [showTooltip, position]);
38
+ const onMouseOver = () => setShowTooltip(true);
39
+ const onMouseLeave = () => setShowTooltip(false);
40
+ return (jsx("div", { style: {
41
+ position: 'relative',
42
+ display: 'inline-block', // 자식 크기에 영향 안 받도록
43
+ ...style,
44
+ }, onMouseOver: onMouseOver, onMouseLeave: onMouseLeave, ...props, children: jsx(TooltipContext.Provider, { value: { show: showTooltip, tooltipPosition }, children: children }) }));
45
+ };
46
+ const TooltipLabel = ({ children, style, ...props }) => {
47
+ const context = useContext(TooltipContext);
48
+ if (!context) {
49
+ throw new Error('Tooltip.* 컴포넌트는 Tooltip 내에서만 사용해야 합니다.');
50
+ }
51
+ const { show, tooltipPosition } = context;
52
+ const labelStyle = {
53
+ position: 'absolute',
54
+ visibility: show ? 'visible' : 'hidden',
55
+ ...tooltipPosition,
56
+ ...style,
57
+ };
58
+ return (jsx("div", { style: labelStyle, ...props, children: children }));
59
+ };
60
+ const Tooltip = Object.assign(TooltipRoot, {
61
+ Label: TooltipLabel,
62
+ });
63
+
64
+ export { Tooltip as default };
@@ -0,0 +1 @@
1
+ export * as Tooltip from './Tooltip/Tooltip';
@@ -1,11 +1,13 @@
1
- import { CSSProperties, InputHTMLAttributes, ReactElement, ReactNode } from 'react';
1
+ import { ChangeEvent, CSSProperties, InputHTMLAttributes, ReactElement, ReactNode } from 'react';
2
2
  export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
3
3
  suffixElement?: ReactElement | ReactNode;
4
4
  prefixElement?: ReactElement | ReactNode;
5
5
  wrapperStyle?: CSSProperties;
6
6
  wrapperClass?: string[];
7
- useThrottle?: boolean;
8
7
  timeout?: number;
8
+ showLimit?: boolean;
9
+ maxLength?: number;
10
+ onThrottledChange?: (e: ChangeEvent<HTMLInputElement>) => void;
9
11
  }
10
12
  export interface ImageInputContextData {
11
13
  id?: string;
@@ -0,0 +1,14 @@
1
+ import { CSSProperties, HTMLAttributes, ReactNode } from 'react';
2
+ export type TooltipPosition = 'top' | 'bottom' | 'left' | 'right';
3
+ export interface TooltipProps extends HTMLAttributes<HTMLDivElement> {
4
+ children: ReactNode;
5
+ position?: TooltipPosition;
6
+ style?: CSSProperties;
7
+ space?: number;
8
+ }
9
+ interface TooltipContextProps {
10
+ show: boolean;
11
+ tooltipPosition: CSSProperties;
12
+ }
13
+ export declare const TooltipContext: import("react").Context<TooltipContextProps | null>;
14
+ export {};
@@ -0,0 +1,5 @@
1
+ import { createContext } from 'react';
2
+
3
+ const TooltipContext = createContext(null);
4
+
5
+ export { TooltipContext };
package/version.txt CHANGED
@@ -1 +1 @@
1
- 0.2.31
1
+ 0.2.34