jy-headless 0.2.34 → 0.2.36

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.js CHANGED
@@ -3,6 +3,7 @@
3
3
  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
+ var CheckboxList = require('./inputs/checkboxList/CheckboxList.js');
6
7
  var Dropdown = require('./selectors/Dropdown/Dropdown.js');
7
8
  var Tooltip = require('./tooltip/Tooltip/Tooltip.js');
8
9
  require('react');
@@ -12,6 +13,7 @@ function _interopNamespaceDefaultOnly (e) { return Object.freeze({ __proto__: nu
12
13
 
13
14
  var Button__namespace = /*#__PURE__*/_interopNamespaceDefaultOnly(Button);
14
15
  var Input__namespace = /*#__PURE__*/_interopNamespaceDefaultOnly(Input);
16
+ var CheckboxList__namespace = /*#__PURE__*/_interopNamespaceDefaultOnly(CheckboxList);
15
17
  var Dropdown__namespace = /*#__PURE__*/_interopNamespaceDefaultOnly(Dropdown);
16
18
  var Tooltip__namespace = /*#__PURE__*/_interopNamespaceDefaultOnly(Tooltip);
17
19
 
@@ -20,6 +22,7 @@ var Tooltip__namespace = /*#__PURE__*/_interopNamespaceDefaultOnly(Tooltip);
20
22
  exports.Button = Button__namespace;
21
23
  exports.Input = Input__namespace;
22
24
  exports.ImageInput = ImageInput;
25
+ exports.CheckboxList = CheckboxList__namespace;
23
26
  exports.Dropdown = Dropdown__namespace;
24
27
  exports.Tooltip = Tooltip__namespace;
25
28
  exports.DropdownContext = useDropdown.DropdownContext;
@@ -0,0 +1,5 @@
1
+ import { CheckboxItemProps, CheckboxProps } from '../../types';
2
+ declare const CheckboxList: (<T>({ children, values, onChange, max, ...props }: CheckboxProps<T>) => import("react/jsx-runtime").JSX.Element) & {
3
+ Item: <T>({ value, children, id, ...props }: CheckboxItemProps<T>) => import("react/jsx-runtime").JSX.Element | null;
4
+ };
5
+ export default CheckboxList;
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+
6
+ const CheckboxContext = react.createContext(null);
7
+ const CheckBoxRoot = ({ children, values, onChange, max = Infinity, ...props }) => {
8
+ const onToggle = (checked, isCheck) => {
9
+ if (isCheck && values.length < max) {
10
+ onChange([...values, checked]);
11
+ }
12
+ else {
13
+ onChange(values.filter((it) => it != checked));
14
+ }
15
+ };
16
+ return (jsxRuntime.jsx("div", { ...props, children: jsxRuntime.jsx(CheckboxContext.Provider, { value: { values, onToggle }, children: children }) }));
17
+ };
18
+ const CheckBoxItem = ({ value, children, id, ...props }) => {
19
+ const context = react.useContext(CheckboxContext);
20
+ if (!context) {
21
+ logCannotFindContextError('CheckboxList');
22
+ return null;
23
+ }
24
+ const uuid = react.useMemo(() => id || crypto.randomUUID(), []);
25
+ const { values, onToggle } = context;
26
+ return (jsxRuntime.jsxs("div", { ...props, children: [jsxRuntime.jsx("input", { id: uuid, checked: values.includes(value), onChange: (e) => onToggle(value, e.target.checked), type: 'checkbox' }), jsxRuntime.jsxs("label", { htmlFor: uuid, children: [" ", children] })] }));
27
+ };
28
+ const CheckboxList = Object.assign(CheckBoxRoot, {
29
+ Item: CheckBoxItem,
30
+ });
31
+
32
+ module.exports = CheckboxList;
@@ -0,0 +1,5 @@
1
+ import { CheckboxItemProps, CheckboxProps } from '../../types';
2
+ declare const CheckboxList: (<T>({ children, values, onChange, max, ...props }: CheckboxProps<T>) => import("react/jsx-runtime").JSX.Element) & {
3
+ Item: <T>({ value, children, id, ...props }: CheckboxItemProps<T>) => import("react/jsx-runtime").JSX.Element | null;
4
+ };
5
+ export default CheckboxList;
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+
6
+ const CheckboxContext = react.createContext(null);
7
+ const CheckBoxRoot = ({ children, values, onChange, max = Infinity, ...props }) => {
8
+ const onToggle = (checked, isCheck) => {
9
+ if (isCheck && values.length < max) {
10
+ onChange([...values, checked]);
11
+ }
12
+ else {
13
+ onChange(values.filter((it) => it != checked));
14
+ }
15
+ };
16
+ return (jsxRuntime.jsx("div", { ...props, children: jsxRuntime.jsx(CheckboxContext.Provider, { value: { values, onToggle }, children: children }) }));
17
+ };
18
+ const CheckBoxItem = ({ value, children, id, ...props }) => {
19
+ const context = react.useContext(CheckboxContext);
20
+ if (!context) {
21
+ logCannotFindContextError('CheckboxList');
22
+ return null;
23
+ }
24
+ const uuid = react.useMemo(() => id || crypto.randomUUID(), []);
25
+ const { values, onToggle } = context;
26
+ return (jsxRuntime.jsxs("div", { ...props, children: [jsxRuntime.jsx("input", { id: uuid, checked: values.includes(value), onChange: (e) => onToggle(value, e.target.checked), type: 'checkbox' }), jsxRuntime.jsxs("label", { htmlFor: uuid, children: [" ", children] })] }));
27
+ };
28
+ const CheckboxList = Object.assign(CheckBoxRoot, {
29
+ Item: CheckBoxItem,
30
+ });
31
+
32
+ module.exports = CheckboxList;
@@ -1,2 +1,3 @@
1
1
  export * as Input from './Input/Input';
2
2
  export * as ImageInput from './ImageInput/ImageInput';
3
+ export * as CheckboxList from './checkboxList/CheckboxList';
@@ -1,4 +1,5 @@
1
1
  import { ChangeEvent, CSSProperties, InputHTMLAttributes, ReactElement, ReactNode } from 'react';
2
+ import { DivAttribute } from '../common';
2
3
  export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
3
4
  suffixElement?: ReactElement | ReactNode;
4
5
  prefixElement?: ReactElement | ReactNode;
@@ -21,3 +22,15 @@ export interface ImageInputProps extends Omit<InputHTMLAttributes<HTMLInputEleme
21
22
  onChange?: (file: File) => void;
22
23
  value?: File;
23
24
  }
25
+ export interface CheckboxProps<T> extends Omit<DivAttribute<T>, 'onChange'> {
26
+ values: T[];
27
+ onChange: (newValue: T[]) => void;
28
+ max?: number;
29
+ }
30
+ export interface CheckboxItemProps<T> extends DivAttribute<T> {
31
+ value: T;
32
+ }
33
+ export interface CheckboxContextData<T> {
34
+ onToggle: (newValue: T, isCheck: boolean) => void;
35
+ values: T[];
36
+ }
@@ -0,0 +1 @@
1
+ declare const logCannotFindContextError: (componentName: string) => never;
package/index.js CHANGED
@@ -4,6 +4,8 @@ import * as Input from './inputs/Input/Input.js';
4
4
  export { Input };
5
5
  import * as ImageInput from './inputs/ImageInput/ImageInput.js';
6
6
  export { ImageInput };
7
+ import * as CheckboxList from './inputs/checkboxList/CheckboxList.js';
8
+ export { CheckboxList };
7
9
  import * as Dropdown from './selectors/Dropdown/Dropdown.js';
8
10
  export { Dropdown };
9
11
  import * as Tooltip from './tooltip/Tooltip/Tooltip.js';
@@ -0,0 +1,5 @@
1
+ import { CheckboxItemProps, CheckboxProps } from '../../types';
2
+ declare const CheckboxList: (<T>({ children, values, onChange, max, ...props }: CheckboxProps<T>) => import("react/jsx-runtime").JSX.Element) & {
3
+ Item: <T>({ value, children, id, ...props }: CheckboxItemProps<T>) => import("react/jsx-runtime").JSX.Element | null;
4
+ };
5
+ export default CheckboxList;
@@ -0,0 +1,30 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { createContext, useContext, useMemo } from 'react';
3
+
4
+ const CheckboxContext = createContext(null);
5
+ const CheckBoxRoot = ({ children, values, onChange, max = Infinity, ...props }) => {
6
+ const onToggle = (checked, isCheck) => {
7
+ if (isCheck && values.length < max) {
8
+ onChange([...values, checked]);
9
+ }
10
+ else {
11
+ onChange(values.filter((it) => it != checked));
12
+ }
13
+ };
14
+ return (jsx("div", { ...props, children: jsx(CheckboxContext.Provider, { value: { values, onToggle }, children: children }) }));
15
+ };
16
+ const CheckBoxItem = ({ value, children, id, ...props }) => {
17
+ const context = useContext(CheckboxContext);
18
+ if (!context) {
19
+ logCannotFindContextError('CheckboxList');
20
+ return null;
21
+ }
22
+ const uuid = useMemo(() => id || crypto.randomUUID(), []);
23
+ const { values, onToggle } = context;
24
+ return (jsxs("div", { ...props, children: [jsx("input", { id: uuid, checked: values.includes(value), onChange: (e) => onToggle(value, e.target.checked), type: 'checkbox' }), jsxs("label", { htmlFor: uuid, children: [" ", children] })] }));
25
+ };
26
+ const CheckboxList = Object.assign(CheckBoxRoot, {
27
+ Item: CheckBoxItem,
28
+ });
29
+
30
+ export { CheckboxList as default };
@@ -0,0 +1,5 @@
1
+ import { CheckboxItemProps, CheckboxProps } from '../../types';
2
+ declare const CheckboxList: (<T>({ children, values, onChange, max, ...props }: CheckboxProps<T>) => import("react/jsx-runtime").JSX.Element) & {
3
+ Item: <T>({ value, children, id, ...props }: CheckboxItemProps<T>) => import("react/jsx-runtime").JSX.Element | null;
4
+ };
5
+ export default CheckboxList;
@@ -0,0 +1,30 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { createContext, useContext, useMemo } from 'react';
3
+
4
+ const CheckboxContext = createContext(null);
5
+ const CheckBoxRoot = ({ children, values, onChange, max = Infinity, ...props }) => {
6
+ const onToggle = (checked, isCheck) => {
7
+ if (isCheck && values.length < max) {
8
+ onChange([...values, checked]);
9
+ }
10
+ else {
11
+ onChange(values.filter((it) => it != checked));
12
+ }
13
+ };
14
+ return (jsx("div", { ...props, children: jsx(CheckboxContext.Provider, { value: { values, onToggle }, children: children }) }));
15
+ };
16
+ const CheckBoxItem = ({ value, children, id, ...props }) => {
17
+ const context = useContext(CheckboxContext);
18
+ if (!context) {
19
+ logCannotFindContextError('CheckboxList');
20
+ return null;
21
+ }
22
+ const uuid = useMemo(() => id || crypto.randomUUID(), []);
23
+ const { values, onToggle } = context;
24
+ return (jsxs("div", { ...props, children: [jsx("input", { id: uuid, checked: values.includes(value), onChange: (e) => onToggle(value, e.target.checked), type: 'checkbox' }), jsxs("label", { htmlFor: uuid, children: [" ", children] })] }));
25
+ };
26
+ const CheckboxList = Object.assign(CheckBoxRoot, {
27
+ Item: CheckBoxItem,
28
+ });
29
+
30
+ export { CheckboxList as default };
package/inputs/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * as Input from './Input/Input';
2
2
  export * as ImageInput from './ImageInput/ImageInput';
3
+ export * as CheckboxList from './checkboxList/CheckboxList';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jy-headless",
3
- "version": "0.2.34",
3
+ "version": "0.2.36",
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,16 @@
43
43
  "require": "./cjs/types/tooltip/index.js",
44
44
  "types": "./types/tooltip/index.d.ts"
45
45
  },
46
+ "./cjs/inputs/checkboxList": {
47
+ "import": "./cjs/inputs/checkboxList/index.js",
48
+ "require": "./cjs/cjs/inputs/checkboxList/index.js",
49
+ "types": "./cjs/inputs/checkboxList/index.d.ts"
50
+ },
51
+ "./CheckboxList": {
52
+ "import": "./inputs/checkboxList/CheckboxList.js",
53
+ "require": "./cjs/inputs/checkboxList/CheckboxList.js",
54
+ "types": "./inputs/checkboxList/CheckboxList.d.ts"
55
+ },
46
56
  "./ImageInput": {
47
57
  "import": "./inputs/ImageInput/ImageInput.js",
48
58
  "require": "./cjs/inputs/ImageInput/ImageInput.js",
@@ -68,6 +78,11 @@
68
78
  "require": "./cjs/cjs/types/tooltip/index.js",
69
79
  "types": "./cjs/types/tooltip/index.d.ts"
70
80
  },
81
+ "./inputs/checkboxList": {
82
+ "import": "./inputs/checkboxList/index.js",
83
+ "require": "./cjs/inputs/checkboxList/index.js",
84
+ "types": "./inputs/checkboxList/index.d.ts"
85
+ },
71
86
  "./types/tooltip": {
72
87
  "import": "./types/tooltip/index.js",
73
88
  "require": "./cjs/types/tooltip/index.js",
@@ -1,4 +1,5 @@
1
1
  import { ChangeEvent, CSSProperties, InputHTMLAttributes, ReactElement, ReactNode } from 'react';
2
+ import { DivAttribute } from '../common';
2
3
  export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
3
4
  suffixElement?: ReactElement | ReactNode;
4
5
  prefixElement?: ReactElement | ReactNode;
@@ -21,3 +22,15 @@ export interface ImageInputProps extends Omit<InputHTMLAttributes<HTMLInputEleme
21
22
  onChange?: (file: File) => void;
22
23
  value?: File;
23
24
  }
25
+ export interface CheckboxProps<T> extends Omit<DivAttribute<T>, 'onChange'> {
26
+ values: T[];
27
+ onChange: (newValue: T[]) => void;
28
+ max?: number;
29
+ }
30
+ export interface CheckboxItemProps<T> extends DivAttribute<T> {
31
+ value: T;
32
+ }
33
+ export interface CheckboxContextData<T> {
34
+ onToggle: (newValue: T, isCheck: boolean) => void;
35
+ values: T[];
36
+ }
@@ -0,0 +1 @@
1
+ declare const logCannotFindContextError: (componentName: string) => never;
package/version.txt CHANGED
@@ -1 +1 @@
1
- 0.2.34
1
+ 0.2.36