jy-headless 0.2.29 → 0.2.31

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.
@@ -1 +1 @@
1
- export { default } from './Button/Button';
1
+ export * as Button from './Button/Button';
@@ -1 +1 @@
1
- export { default } from './Button/Button';
1
+ export * as Button from './Button/Button';
package/cjs/index.js CHANGED
@@ -1,11 +1,23 @@
1
1
  'use strict';
2
2
 
3
- require('react/jsx-runtime');
3
+ var Button = require('./buttons/Button/Button.js');
4
+ var Input = require('./inputs/Input/Input.js');
5
+ var ImageInput = require('./inputs/ImageInput/ImageInput.js');
6
+ var Dropdown = require('./selectors/Dropdown/Dropdown.js');
4
7
  require('react');
5
- require('./selectors/Dropdown/Dropdown.js');
6
8
  var useDropdown = require('./hooks/useDropdown.js');
7
9
 
10
+ function _interopNamespaceDefaultOnly (e) { return Object.freeze({ __proto__: null, default: e }); }
8
11
 
12
+ var Button__namespace = /*#__PURE__*/_interopNamespaceDefaultOnly(Button);
13
+ var Input__namespace = /*#__PURE__*/_interopNamespaceDefaultOnly(Input);
14
+ var Dropdown__namespace = /*#__PURE__*/_interopNamespaceDefaultOnly(Dropdown);
9
15
 
16
+
17
+
18
+ exports.Button = Button__namespace;
19
+ exports.Input = Input__namespace;
20
+ exports.ImageInput = ImageInput;
21
+ exports.Dropdown = Dropdown__namespace;
10
22
  exports.DropdownContext = useDropdown.DropdownContext;
11
23
  exports.useDropdownContext = useDropdown.useDropdownContext;
@@ -0,0 +1,7 @@
1
+ import { ImageAttribute, ImageInputContextData, ImageInputProps, LabelAttribute } from '../../types';
2
+ export declare const ImageInputContext: import("react").Context<ImageInputContextData | null>;
3
+ declare const ImageInput: (({ accepts, id, value, draggable, onChange, children, ...props }: ImageInputProps) => import("react/jsx-runtime").JSX.Element) & {
4
+ Preview: ({ src: defaultSrc, ...props }: ImageAttribute) => import("react/jsx-runtime").JSX.Element;
5
+ Uploader: ({ children, ...props }: LabelAttribute) => import("react/jsx-runtime").JSX.Element;
6
+ };
7
+ export default ImageInput;
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var react = require('react');
7
+
8
+ const ImageInputContext = react.createContext(null);
9
+ const getAccepts = (accepts) => {
10
+ return accepts && accepts.length > 0 ? accepts.map((it) => `image/${it}`).join() : 'image/*';
11
+ };
12
+ const ImageInputRoot = ({ accepts, id, value, draggable = false, onChange, children, ...props }) => {
13
+ const [previewUrl, setPreviewUrl] = react.useState('');
14
+ const [dragOver, setDragOver] = react.useState(false);
15
+ const inputId = [id, 'image-input'].join('-');
16
+ react.useEffect(() => {
17
+ if (!value)
18
+ setPreviewUrl('');
19
+ }, [value]);
20
+ const setImagePreview = (file) => {
21
+ const reader = new FileReader();
22
+ reader.onload = (e) => {
23
+ setPreviewUrl(e.target.result);
24
+ };
25
+ reader.readAsDataURL(file);
26
+ };
27
+ const onImageChange = (e) => {
28
+ const file = e.target.files?.[0];
29
+ if (!file)
30
+ return;
31
+ setImagePreview(file);
32
+ onChange?.(file);
33
+ };
34
+ const onDrop = (e) => {
35
+ if (!draggable)
36
+ return;
37
+ e.preventDefault();
38
+ setDragOver(false);
39
+ const file = e.dataTransfer.files?.[0];
40
+ if (file && file.type.startsWith('image/')) {
41
+ setImagePreview(file);
42
+ onChange?.(file);
43
+ }
44
+ };
45
+ const onDragOver = (e) => {
46
+ if (!draggable)
47
+ return;
48
+ e.preventDefault();
49
+ setDragOver(true);
50
+ };
51
+ const onDragLeave = () => setDragOver(false);
52
+ return (jsxRuntime.jsxs("span", { ...props, onDrop: onDrop, onDragOver: onDragOver, onDragEnter: onDragOver, onDragLeave: onDragLeave, children: [jsxRuntime.jsx("input", { "data-testid": inputId, id: inputId, type: 'file', accept: getAccepts(accepts ?? []), onChange: onImageChange, style: { display: 'none' } }), jsxRuntime.jsx(ImageInputContext.Provider, { value: { id: inputId, previewUrl, dragOver }, children: children })] }));
53
+ };
54
+ const ImageInputUploader = ({ children, ...props }) => {
55
+ const context = react.useContext(ImageInputContext);
56
+ if (!context) {
57
+ throw new Error('ImageInput.* 컴포넌트는 ImageInput 내에서만 사용해야 합니다.');
58
+ }
59
+ const { id } = context;
60
+ return (jsxRuntime.jsx("label", { htmlFor: id ?? '', ...props, children: children }));
61
+ };
62
+ const ImageInputPreview = ({ src: defaultSrc, ...props }) => {
63
+ const context = react.useContext(ImageInputContext);
64
+ if (!context) {
65
+ throw new Error('ImageInput.* 컴포넌트는 ImageInput 내에서만 사용해야 합니다.');
66
+ }
67
+ const { previewUrl } = context;
68
+ return jsxRuntime.jsx("img", { ...props, src: previewUrl ?? defaultSrc ?? '' });
69
+ };
70
+ const ImageInput = Object.assign(ImageInputRoot, {
71
+ Preview: ImageInputPreview,
72
+ Uploader: ImageInputUploader,
73
+ });
74
+
75
+ exports.ImageInputContext = ImageInputContext;
76
+ exports.default = ImageInput;
@@ -1 +1,2 @@
1
- export { default } from './Input/Input';
1
+ export * as Input from './Input/Input';
2
+ export * as ImageInput from './ImageInput/ImageInput';
@@ -45,9 +45,11 @@ const DropdownOption = ({ children, value, ...props }) => {
45
45
  const { select } = useDropdown.useDropdownContext();
46
46
  return (jsxRuntime.jsx("div", { role: "option", onClick: () => select(value), ...props, children: children }));
47
47
  };
48
- Object.assign(DropdownRoot, {
48
+ const Dropdown = Object.assign(DropdownRoot, {
49
49
  Button: DropdownButton,
50
50
  Options: DropdownOptions,
51
51
  Option: DropdownOption,
52
52
  Viewer: DropdownViewer,
53
53
  });
54
+
55
+ module.exports = Dropdown;
@@ -1 +1 @@
1
- export { default } from './Dropdown/Dropdown';
1
+ export * as Dropdown from './Dropdown/Dropdown';
@@ -1,7 +1,11 @@
1
- import { HTMLAttributes } from 'react';
1
+ import { HTMLAttributes, ImgHTMLAttributes } from 'react';
2
2
  export interface DivAttribute<T> extends HTMLAttributes<HTMLDivElement> {
3
3
  value?: T;
4
4
  }
5
5
  export interface SpanAttribute<T> extends HTMLAttributes<HTMLSpanElement> {
6
6
  value?: T;
7
7
  }
8
+ export interface LabelAttribute extends HTMLAttributes<HTMLLabelElement> {
9
+ }
10
+ export interface ImageAttribute extends ImgHTMLAttributes<HTMLImageElement> {
11
+ }
@@ -7,3 +7,15 @@ export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
7
7
  useThrottle?: boolean;
8
8
  timeout?: number;
9
9
  }
10
+ export interface ImageInputContextData {
11
+ id?: string;
12
+ previewUrl?: string;
13
+ dragOver?: boolean;
14
+ }
15
+ export type ImageType = 'jpeg' | 'png' | 'gif' | 'svg' | 'bmp' | 'webp' | 'heic' | 'heif' | 'tiff' | 'x-icon' | 'vn';
16
+ export interface ImageInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange'> {
17
+ accepts?: ImageType[];
18
+ draggable?: boolean;
19
+ onChange?: (file: File) => void;
20
+ value?: File;
21
+ }
package/index.js CHANGED
@@ -1,4 +1,10 @@
1
- import 'react/jsx-runtime';
1
+ import * as Button from './buttons/Button/Button.js';
2
+ export { Button };
3
+ import * as Input from './inputs/Input/Input.js';
4
+ export { Input };
5
+ import * as ImageInput from './inputs/ImageInput/ImageInput.js';
6
+ export { ImageInput };
7
+ import * as Dropdown from './selectors/Dropdown/Dropdown.js';
8
+ export { Dropdown };
2
9
  import 'react';
3
- import './selectors/Dropdown/Dropdown.js';
4
10
  export { DropdownContext, useDropdownContext } from './hooks/useDropdown.js';
@@ -0,0 +1,7 @@
1
+ import { ImageAttribute, ImageInputContextData, ImageInputProps, LabelAttribute } from '../../types';
2
+ export declare const ImageInputContext: import("react").Context<ImageInputContextData | null>;
3
+ declare const ImageInput: (({ accepts, id, value, draggable, onChange, children, ...props }: ImageInputProps) => import("react/jsx-runtime").JSX.Element) & {
4
+ Preview: ({ src: defaultSrc, ...props }: ImageAttribute) => import("react/jsx-runtime").JSX.Element;
5
+ Uploader: ({ children, ...props }: LabelAttribute) => import("react/jsx-runtime").JSX.Element;
6
+ };
7
+ export default ImageInput;
@@ -0,0 +1,71 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { createContext, useState, useEffect, useContext } from 'react';
3
+
4
+ const ImageInputContext = createContext(null);
5
+ const getAccepts = (accepts) => {
6
+ return accepts && accepts.length > 0 ? accepts.map((it) => `image/${it}`).join() : 'image/*';
7
+ };
8
+ const ImageInputRoot = ({ accepts, id, value, draggable = false, onChange, children, ...props }) => {
9
+ const [previewUrl, setPreviewUrl] = useState('');
10
+ const [dragOver, setDragOver] = useState(false);
11
+ const inputId = [id, 'image-input'].join('-');
12
+ useEffect(() => {
13
+ if (!value)
14
+ setPreviewUrl('');
15
+ }, [value]);
16
+ const setImagePreview = (file) => {
17
+ const reader = new FileReader();
18
+ reader.onload = (e) => {
19
+ setPreviewUrl(e.target.result);
20
+ };
21
+ reader.readAsDataURL(file);
22
+ };
23
+ const onImageChange = (e) => {
24
+ const file = e.target.files?.[0];
25
+ if (!file)
26
+ return;
27
+ setImagePreview(file);
28
+ onChange?.(file);
29
+ };
30
+ const onDrop = (e) => {
31
+ if (!draggable)
32
+ return;
33
+ e.preventDefault();
34
+ setDragOver(false);
35
+ const file = e.dataTransfer.files?.[0];
36
+ if (file && file.type.startsWith('image/')) {
37
+ setImagePreview(file);
38
+ onChange?.(file);
39
+ }
40
+ };
41
+ const onDragOver = (e) => {
42
+ if (!draggable)
43
+ return;
44
+ e.preventDefault();
45
+ setDragOver(true);
46
+ };
47
+ const onDragLeave = () => setDragOver(false);
48
+ return (jsxs("span", { ...props, onDrop: onDrop, onDragOver: onDragOver, onDragEnter: onDragOver, onDragLeave: onDragLeave, children: [jsx("input", { "data-testid": inputId, id: inputId, type: 'file', accept: getAccepts(accepts ?? []), onChange: onImageChange, style: { display: 'none' } }), jsx(ImageInputContext.Provider, { value: { id: inputId, previewUrl, dragOver }, children: children })] }));
49
+ };
50
+ const ImageInputUploader = ({ children, ...props }) => {
51
+ const context = useContext(ImageInputContext);
52
+ if (!context) {
53
+ throw new Error('ImageInput.* 컴포넌트는 ImageInput 내에서만 사용해야 합니다.');
54
+ }
55
+ const { id } = context;
56
+ return (jsx("label", { htmlFor: id ?? '', ...props, children: children }));
57
+ };
58
+ const ImageInputPreview = ({ src: defaultSrc, ...props }) => {
59
+ const context = useContext(ImageInputContext);
60
+ if (!context) {
61
+ throw new Error('ImageInput.* 컴포넌트는 ImageInput 내에서만 사용해야 합니다.');
62
+ }
63
+ const { previewUrl } = context;
64
+ return jsx("img", { ...props, src: previewUrl ?? defaultSrc ?? '' });
65
+ };
66
+ const ImageInput = Object.assign(ImageInputRoot, {
67
+ Preview: ImageInputPreview,
68
+ Uploader: ImageInputUploader,
69
+ });
70
+
71
+ export { ImageInputContext, ImageInput as default };
package/inputs/index.d.ts CHANGED
@@ -1 +1,2 @@
1
- export { default } from './Input/Input';
1
+ export * as Input from './Input/Input';
2
+ export * as ImageInput from './ImageInput/ImageInput';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jy-headless",
3
- "version": "0.2.29",
3
+ "version": "0.2.31",
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",
@@ -43,6 +43,11 @@
43
43
  "require": "./cjs/index.js",
44
44
  "types": "./index.d.ts"
45
45
  },
46
+ "./ImageInput": {
47
+ "import": "./inputs/ImageInput/ImageInput.js",
48
+ "require": "./cjs/inputs/ImageInput/ImageInput.js",
49
+ "types": "./inputs/ImageInput/ImageInput.d.ts"
50
+ },
46
51
  "./Input": {
47
52
  "import": "./inputs/Input/Input.js",
48
53
  "require": "./cjs/inputs/Input/Input.js",
@@ -43,9 +43,11 @@ const DropdownOption = ({ children, value, ...props }) => {
43
43
  const { select } = useDropdownContext();
44
44
  return (jsx("div", { role: "option", onClick: () => select(value), ...props, children: children }));
45
45
  };
46
- Object.assign(DropdownRoot, {
46
+ const Dropdown = Object.assign(DropdownRoot, {
47
47
  Button: DropdownButton,
48
48
  Options: DropdownOptions,
49
49
  Option: DropdownOption,
50
50
  Viewer: DropdownViewer,
51
51
  });
52
+
53
+ export { Dropdown as default };
@@ -1 +1 @@
1
- export { default } from './Dropdown/Dropdown';
1
+ export * as Dropdown from './Dropdown/Dropdown';
@@ -1,7 +1,11 @@
1
- import { HTMLAttributes } from 'react';
1
+ import { HTMLAttributes, ImgHTMLAttributes } from 'react';
2
2
  export interface DivAttribute<T> extends HTMLAttributes<HTMLDivElement> {
3
3
  value?: T;
4
4
  }
5
5
  export interface SpanAttribute<T> extends HTMLAttributes<HTMLSpanElement> {
6
6
  value?: T;
7
7
  }
8
+ export interface LabelAttribute extends HTMLAttributes<HTMLLabelElement> {
9
+ }
10
+ export interface ImageAttribute extends ImgHTMLAttributes<HTMLImageElement> {
11
+ }
@@ -7,3 +7,15 @@ export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
7
7
  useThrottle?: boolean;
8
8
  timeout?: number;
9
9
  }
10
+ export interface ImageInputContextData {
11
+ id?: string;
12
+ previewUrl?: string;
13
+ dragOver?: boolean;
14
+ }
15
+ export type ImageType = 'jpeg' | 'png' | 'gif' | 'svg' | 'bmp' | 'webp' | 'heic' | 'heif' | 'tiff' | 'x-icon' | 'vn';
16
+ export interface ImageInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange'> {
17
+ accepts?: ImageType[];
18
+ draggable?: boolean;
19
+ onChange?: (file: File) => void;
20
+ value?: File;
21
+ }
package/version.txt CHANGED
@@ -1 +1 @@
1
- 0.2.29
1
+ 0.2.31
@@ -1,4 +0,0 @@
1
- declare const DropdownDefaultTrigger: ({ value }: {
2
- value: boolean;
3
- }) => import("react/jsx-runtime").JSX.Element;
4
- export default DropdownDefaultTrigger;
@@ -1,4 +0,0 @@
1
- declare const DropdownDefaultTrigger: ({ value }: {
2
- value: boolean;
3
- }) => import("react/jsx-runtime").JSX.Element;
4
- export default DropdownDefaultTrigger;