@mpen/react-basic-inputs 0.2.2 → 0.2.4

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/README.md CHANGED
@@ -1,26 +1,28 @@
1
- # react-basic-inputs
1
+ # @mpen/react-basic-inputs
2
2
 
3
3
  Thin wrappers around native input elements to make them behave better.
4
4
 
5
+ <a href="https://pkg-size.dev/@mpen/react-basic-inputs"><img src="https://pkg-size.dev/badge/bundle/12662" title="Bundle size for @mpen/react-basic-inputs"></a>
6
+
5
7
  ## Installation
6
8
 
7
9
  ```sh
8
- yarn add @mnpenner/react-basic-inputs
10
+ bun add --dev @mpen/react-basic-inputs
11
+ # or
12
+ yarn add @mpen/react-basic-inputs
9
13
  # or
10
- npm install @mnpenner/react-basic-inputs
14
+ npm install @mpen/react-basic-inputs
11
15
  ```
12
16
 
13
17
  ## Links
14
18
 
15
- - Docs: https://mnpenner.github.io/react-basic-inputs
16
- - Repo: https://github.com/mnpenner/react-basic-inputs
17
- - Code: https://github.com/mnpenner/react-basic-inputs/tree/default/src
18
- - Issues: https://github.com/mnpenner/react-basic-inputs/issues
19
- - Npm: https://www.npmjs.com/package/@mnpenner/react-basic-inputs
20
- - Yarn: https://yarnpkg.com/package/@mnpenner/react-basic-inputs
21
- - Bundlephobia: https://bundlephobia.com/package/@mnpenner/react-basic-inputs
22
- - Unpkg: https://unpkg.com/@mnpenner/react-basic-inputs/dist/bundle.mjs
23
- - jsDelivr: https://cdn.jsdelivr.net/npm/@mnpenner/react-basic-inputs/dist/bundle.mjs
19
+ - Npm: https://www.npmjs.com/package/@mpen/react-basic-inputs
20
+ - https://www.npmjs.com/package/@mpen/react-basic-inputs?activeTab=code
21
+ - Yarn: https://yarnpkg.com/package/@mpen/react-basic-inputs
22
+ - pkg-size: https://pkg-size.dev/@mpen%2Freact-basic-inputs
23
+ - Bundlephobia: https://bundlephobia.com/package/@mpen/react-basic-inputs
24
+ - Unpkg: https://unpkg.com/@mpen/react-basic-inputs/dist/react-basic-inputs.js
25
+ - jsDelivr: https://cdn.jsdelivr.net/npm/@mpen/react-basic-inputs/dist/react-basic-inputs.js
24
26
 
25
27
  ## Components
26
28
 
@@ -9,6 +9,18 @@ import { ReactNode } from 'react';
9
9
  import { RefAttributes } from 'react';
10
10
  import { TextareaHTMLAttributes } from 'react';
11
11
 
12
+ export declare function DebouncedInput({ value: initialValue, onChange, debounce, ...props }: DebouncedInputProps): JSX_2.Element;
13
+
14
+ export declare type DebouncedInputChangeEvent = {
15
+ value: string;
16
+ };
17
+
18
+ export declare type DebouncedInputProps = OverrideProps<'input', {
19
+ value: string;
20
+ onChange: (ev: DebouncedInputChangeEvent) => void;
21
+ debounce?: number;
22
+ }>;
23
+
12
24
  declare type EventCallback<T = never> = (ev: T) => void;
13
25
 
14
26
  declare type HtmlInputElement = HTMLElementTagNameMap['input'];
@@ -107,7 +119,7 @@ export declare type SelectChangeEventHandler<T> = EventCallback<SelectChangeEven
107
119
  export declare type SelectOption<T> = OverrideProps<'option', {
108
120
  value: T;
109
121
  text: ReactNode;
110
- key?: Resolvable<Key, [SelectOption<T>, number]>;
122
+ key?: Resolvable<StrictKey, [SelectOption<T>, number]>;
111
123
  }, 'children' | 'selected'>;
112
124
 
113
125
  export declare type SelectProps<T extends NonNil> = OverrideProps<'select', {
@@ -126,6 +138,8 @@ export declare type SelectProps<T extends NonNil> = OverrideProps<'select', {
126
138
  placeholder?: ReactNode;
127
139
  }, 'children' | 'defaultValue'>;
128
140
 
141
+ declare type StrictKey = string | number;
142
+
129
143
  export declare const TextArea: ForwardRefExoticComponent<Omit<Omit<DetailedHTMLProps<TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "ref">, "initialHeight"> & {
130
144
  /** Initial/minimum height. "0" or "auto" are good choices. Defaults to "auto" */
131
145
  initialHeight?: string | undefined;
@@ -280,7 +280,33 @@ function RadioMenu(menu) {
280
280
  ] }) }, fixedKey);
281
281
  }) });
282
282
  }
283
+ function useBox(value) {
284
+ const ref = useRef(value);
285
+ ref.current = value;
286
+ return ref;
287
+ }
288
+ function DebouncedInput({
289
+ value: initialValue,
290
+ onChange,
291
+ debounce = 500,
292
+ ...props
293
+ }) {
294
+ const [value, setValue] = useState(initialValue);
295
+ const onChangeRef = useBox(onChange);
296
+ const debounceRef = useBox(debounce);
297
+ useEffect(() => {
298
+ setValue(initialValue);
299
+ }, [initialValue]);
300
+ useEffect(() => {
301
+ const timeout = setTimeout(() => {
302
+ onChangeRef.current({ value });
303
+ }, debounceRef.current);
304
+ return () => clearTimeout(timeout);
305
+ }, [debounceRef, onChangeRef, value]);
306
+ return /* @__PURE__ */ jsx("input", { ...props, value, onChange: (e) => setValue(e.target.value) });
307
+ }
283
308
  export {
309
+ DebouncedInput,
284
310
  Input,
285
311
  RadioMenu,
286
312
  Select,
@@ -282,6 +282,32 @@ var __publicField = (obj, key, value) => {
282
282
  ] }) }, fixedKey);
283
283
  }) });
284
284
  }
285
+ function useBox(value) {
286
+ const ref = React.useRef(value);
287
+ ref.current = value;
288
+ return ref;
289
+ }
290
+ function DebouncedInput({
291
+ value: initialValue,
292
+ onChange,
293
+ debounce = 500,
294
+ ...props
295
+ }) {
296
+ const [value, setValue] = React.useState(initialValue);
297
+ const onChangeRef = useBox(onChange);
298
+ const debounceRef = useBox(debounce);
299
+ React.useEffect(() => {
300
+ setValue(initialValue);
301
+ }, [initialValue]);
302
+ React.useEffect(() => {
303
+ const timeout = setTimeout(() => {
304
+ onChangeRef.current({ value });
305
+ }, debounceRef.current);
306
+ return () => clearTimeout(timeout);
307
+ }, [debounceRef, onChangeRef, value]);
308
+ return /* @__PURE__ */ jsxRuntime.jsx("input", { ...props, value, onChange: (e) => setValue(e.target.value) });
309
+ }
310
+ exports2.DebouncedInput = DebouncedInput;
285
311
  exports2.Input = Input;
286
312
  exports2.RadioMenu = RadioMenu;
287
313
  exports2.Select = Select;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mpen/react-basic-inputs",
3
3
  "private": false,
4
- "version": "0.2.2",
4
+ "version": "0.2.4",
5
5
  "type": "module",
6
6
  "files": ["dist"],
7
7
  "main": "./dist/react-basic-inputs.umd.cjs",
@@ -15,11 +15,13 @@
15
15
  },
16
16
  "scripts": {
17
17
  "dev": "bun run --bun vite",
18
- "build": "bun run --bun tsc && bun run --bun vite build",
19
- "lint": "bun run --bun eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
18
+ "build": "bun run --bun vite build",
19
+ "lint": "run-s 'lint:*'",
20
+ "lint:ts": "bun run --bun tsc",
21
+ "lint:es": "bun run --bun eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
20
22
  "preview": "bun run --bun vite preview",
21
23
  "_prepublishOnly": "bun run --bun build",
22
- "publish": "npm publish --access=public"
24
+ "_publish": "npm publish --access=public"
23
25
  },
24
26
  "peerDependencies": {
25
27
  "react": "^18.2.0",
@@ -39,6 +41,7 @@
39
41
  "react": "^18.2.0",
40
42
  "react-dom": "^18.2.0",
41
43
  "react-use": "^17.5.0",
44
+ "sass": "^1.77.2",
42
45
  "typescript": "^5.2.2",
43
46
  "vite": "^5.2.0",
44
47
  "vite-plugin-dts": "^3.9.1"