Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
44fe1f8
feat: add useDebounce
Feb 18, 2024
687b9c1
feat: add use-debounce-callback
Mar 21, 2024
865b3e8
feat: add useDebounse
Apr 10, 2024
51cf537
feat: resolve conflicts
Apr 10, 2024
256b0de
resolve conflicts
Apr 10, 2024
b04673f
fix: fix name
Apr 17, 2024
ecdb5be
fix: delete wrong changes
Apr 17, 2024
4565f11
fix: fix test
Apr 17, 2024
6f85519
fix: fix tests
Apr 17, 2024
0fe4443
chore: fix package.json
sadcitizen Sep 29, 2024
ef01236
refactor(usedebounce): рефакторинг хуков
Nov 29, 2024
458ed3e
Merge branch 'master' into feature/useDebounce
Nov 29, 2024
66f4185
feat(useDebounce): добавил tsconfig.build.json
Dec 1, 2024
a577238
feat(useDebounce): добавил tsconfig.build.json
Dec 1, 2024
610f581
test(hooks/usedebounce): тесты и ридми
Dec 2, 2024
c19db26
feat(hooks/usedebounce): рефактор и истории
Dec 2, 2024
02e2257
feat(hooks/useDebouncedValue): разобрался со storybook и mdx
Dec 3, 2024
4934f14
feat(hooks/useDebouncedCallback): истории
SmorodinVik Dec 4, 2024
26c5f8d
feat(usedebounce): убрал story из документации
SmorodinVik Dec 4, 2024
39661b7
Merge branch 'master' into feature/useDebounce
SmorodinVik Dec 4, 2024
e358b55
feat(usedebounce): обновил истории
SmorodinVik Dec 4, 2024
157d3e4
feat(useDebounce): поправил стили
Dec 5, 2024
40feece
feat(useDebounce): поправил стили
Dec 5, 2024
6fce773
fix(useDebounce): фиксы после ревью
Dec 5, 2024
ef4b293
feat(useDebounce): css модули и обновления шаблонов
Dec 5, 2024
377bf15
feat(codeOfConduct): обновление имени файла стилей историй
Dec 5, 2024
6ddc8c2
Merge branch 'master' into feature/useDebounce
AMZhukov Jan 7, 2025
b7a1a1b
feat(useDebounce): add tests for useDebouncedCallback hook
AMZhukov Jan 8, 2025
f0665de
feat(useDebounce): refactor useDebouncedCallback to use useTimeout
AMZhukov Jan 8, 2025
afc67f2
feat(useDebounce): refactor` index.ts` to export directly
AMZhukov Jan 8, 2025
1554c4f
fix(useDebounce): fix dependencies for `useDebounce`
AMZhukov Jan 22, 2025
22daa71
refactor(useDebounce): fix markdown code `useDebounced`
AMZhukov Jan 22, 2025
328d771
feat(useDebounce): improve type for `useDebouncedValue`
AMZhukov Jan 22, 2025
757042a
fix(useDebounce): fix test for `useDebouncedCallback`
AMZhukov Jan 22, 2025
51f20d4
feat(useArray): добавил css modules в истории
Jan 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .templates/create/hook/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ to: hooks/<%= h.changeCase.paramCase(name) %>/package.json
"url": "git+https://github.com/Byndyusoft/ui.git"
},
"scripts": {
"build": "tsc",
"build": "tsc --project tsconfig.build.json",
"clean": "rimraf dist",
"lint": "eslint src --config ../../eslint.config.js",
"test": "jest --config ../../jest.config.js --roots components/<%= h.changeCase.paramCase(name) %>/src"
Expand Down
7 changes: 7 additions & 0 deletions .templates/create/hook/tsconfig.build.json.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
to: hooks/<%= h.changeCase.paramCase(name) %>/tsconfig.build.json
---
{
"extends": "./tsconfig.json",
"exclude": ["src/*.tests.ts", "src/*.stories.tsx"]
}
9 changes: 1 addition & 8 deletions .templates/create/hook/tsconfig.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,5 @@ to: hooks/<%= h.changeCase.paramCase(name) %>/tsconfig.json
"module": "commonjs",
"target": "es6"
},
"include": [
"src"
],
"exclude": [
"node_modules",
"src/**/*.tests.tsx",
"src/**/*.stories.tsx"
]
"include": ["src", "src/*.stories.tsx"]
}
6 changes: 3 additions & 3 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ component-name // Название компонента в kebab case
| ├── ComponentName.types.ts
| ├── ComponentName.tests.tsx
| ├── ComponentName.stories.tsx
| ├── ComponentName.stories.css // стили историй
| ├── ComponentName.stories.module.css // стили историй
| ├── ComponentName.docs.mdx // документация компонента
| └── index.ts
├── README.md
Expand All @@ -78,7 +78,7 @@ use-hook-name // Название хука в kebab case
| ├── useHookName.utilities.ts // логика и методы хука
| ├── useHookName.tests.ts
| ├── useHookName.stories.tsx
| ├── useHookName.stories.css
| ├── useHookName.stories.module.css // стили историй
| └── useHookName.docs.mdx // документация хука
├── README.md
├── package.json
Expand Down Expand Up @@ -176,7 +176,7 @@ src
"module": "commonjs",
"target": "es6"
},
"include": ["src"]
"include": ["src", "src/*.stories.tsx"]
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
flex-grow: 1;
}

button {
.button {
flex-basis: 100px;
flex-shrink: 0;
}
88 changes: 64 additions & 24 deletions hooks/use-array/src/useArray.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { StoryObj } from '@storybook/react';
import useArray from './useArray';
import './useArray.stories.css';
import styles from './useArray.stories.module.css';

const Template = (): JSX.Element => {
const [addValue, setAddValue] = useState(0);
Expand All @@ -18,81 +18,121 @@ const Template = (): JSX.Element => {
<h1>List</h1>
<strong>{list.length > 0 ? list.join(', ') : 'Empty'}</strong>
<hr />
<div className="container">
<div className="row">
<div className={styles.container}>
<div className={styles.row}>
<input
className="input"
className={styles.input}
value={addValue}
type="numeric"
onChange={e => setAddValue(Number(e.target.value))}
/>
<button type="button" onClick={() => append(addValue)}>
<button
className={styles.button}
type="button"
onClick={() => append(addValue)}
>
Append
</button>
</div>
<div className="row">
<div className={styles.row}>
<input
className="input"
className={styles.input}
value={prependValue}
type="numeric"
onChange={e => setPrependValue(Number(e.target.value))}
/>
<button onClick={() => prepend(prependValue)}>Prepend</button>
<button
className={styles.button}
onClick={() => prepend(prependValue)}
>
Prepend
</button>
</div>
<div className="row">
<div className={styles.row}>
<span>from</span>
<input
className="input"
className={styles.input}
value={fromValue}
type="numeric"
onChange={e => setFromValue(Number(e.target.value))}
/>
<span>to</span>
<input
className="input"
className={styles.input}
value={lessValue}
type="numeric"
onChange={e => setLessValue(Number(e.target.value))}
/>
<button onClick={() => filter(a => a >= fromValue && a <= lessValue)}>Filter</button>
<button
className={styles.button}
onClick={() => filter(a => a >= fromValue && a <= lessValue)}
>
Filter
</button>
</div>
<div className="row">
<div className={styles.row}>
<span>index</span>
<input
className="input"
className={styles.input}
value={indexUpdateValue}
type="numeric"
onChange={e => setIndexUpdateValue(Number(e.target.value))}
/>
<span>item</span>
<input
className="input"
className={styles.input}
value={updateValue}
type="numeric"
onChange={e => setUpdateValue(Number(e.target.value))}
/>
<button onClick={() => update(indexUpdateValue, updateValue)}>Update</button>
<button
className={styles.button}
onClick={() => update(indexUpdateValue, updateValue)}
>
Update
</button>
</div>
<div className="row">
<div className={styles.row}>
<input
className="input"
className={styles.input}
value={indexRemoveValue}
type="numeric"
onChange={e => setIndexRemoveValue(Number(e.target.value))}
/>
<button onClick={() => remove(indexRemoveValue)}>Remove</button>
<button
className={styles.button}
onClick={() => remove(indexRemoveValue)}
>
Remove
</button>
</div>
<div className="row">
<button type="button" onClick={() => reset()}>
<div className={styles.row}>
<button
className={styles.button}
type="button"
onClick={() => reset()}
>
Reset
</button>
<button type="button" onClick={() => clear()}>
<button
className={styles.button}
type="button"
onClick={() => clear()}
>
Clear
</button>
<button type="button" onClick={() => sort((a, b) => a - b)}>
<button
className={styles.button}
type="button"
onClick={() => sort((a, b) => a - b)}
>
Sort ASC
</button>
<button type="button" onClick={() => sort((a, b) => b - a)}>
<button
className={styles.button}
type="button"
onClick={() => sort((a, b) => b - a)}
>
Sort DES
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion hooks/use-array/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"module": "commonjs",
"target": "es6"
},
"include": ["src"]
"include": ["src", "../../types.d.ts"]
}
1 change: 1 addition & 0 deletions hooks/use-debounced-callback/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src
34 changes: 34 additions & 0 deletions hooks/use-debounced-callback/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# `@byndyusoft-ui/use-debounced-callback`
---

> A React hook that uses for delaying the execution of functions updates until a specified time period has passed without any further changes

### Installation

```
npm i @byndyusoft-ui/use-debounced-callback
# or
yarn add @byndyusoft-ui/use-debounced-callback
```

### Usage

```ts
type THookReturn<T> = [T, (arg: T) => void];

const useDebouncedValue = <T>(value: T, delay = 300): THookReturn<T> => {
const [debouncedValue, setValue] = useState(value);

const setDebouncedValue = useDebouncedCallback(setValue, delay);

return [debouncedValue, setDebouncedValue];
};
```

### License

Apache-2.0

### Authors

Anastasia Vasenina, Viktor Smorodin
39 changes: 39 additions & 0 deletions hooks/use-debounced-callback/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@byndyusoft-ui/use-debounced-callback",
"version": "0.0.0",
"description": "Byndyusoft UI React Hook",
"keywords": [
"byndyusoft",
"byndyusoft-ui",
"react",
"hook",
"debounce"
],
"author": "Anastasia Vasenina <vasenina@byndyusoft.com>",
"homepage": "https://github.com/Byndyusoft/ui/tree/master/hooks/use-debounced-callback#readme",
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/Byndyusoft/ui.git"
},
"scripts": {
"build": "tsc --project tsconfig.build.json",
"clean": "rimraf dist",
"lint": "eslint src --config ../../eslint.config.js",
"test": "jest --config ../../jest.config.js --roots hooks/use-debounced-callback/src"
},
"bugs": {
"url": "https://github.com/Byndyusoft/ui/issues"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@byndyusoft-ui/use-timeout": "*"
},
"peerDependencies": {
"@byndyusoft-ui/types": "*"
}
}
1 change: 1 addition & 0 deletions hooks/use-debounced-callback/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './useDebouncedCallback';
19 changes: 19 additions & 0 deletions hooks/use-debounced-callback/src/useDebouncedCallback.docs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Markdown, Source, Canvas, Meta } from '@storybook/blocks';
import * as useDebouncedCallbackStories from './useDebouncedCallback.stories';
import Readme from '../README.md';

<Meta title="hooks/useDebouncedCallback" of={useDebouncedCallbackStories} />

<Markdown>{Readme}</Markdown>

## Guide

To use the hook in your project you must:

1. Import the hook where you need it:

<Source language="javascript" code="import useDebouncedCallback from '@byndyusoft-ui/use-debounced-callback';" />

2. Give callback and delay args.

<Canvas sourceState="shown" of={useDebouncedCallbackStories.DebouncedColorChangeStory} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.container {
display: flex;
gap: 2rem;
}

.block {
display: flex;
flex-direction: column;
gap: 1rem;

width: 15rem;
}

.rectangle {
width: 100%;
height: 5rem;
}

.button {
height: 5rem;
}
47 changes: 47 additions & 0 deletions hooks/use-debounced-callback/src/useDebouncedCallback.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { useState } from 'react';
import type { StoryObj } from '@storybook/react';
import useDebouncedCallback from './useDebouncedCallback';
import styles from './useDebouncedCallback.stories.module.css';

const COLORS = ['red', 'green', 'yellow'];

const DebouncedColorChange = () => {
const [firstColorIndex, setFirstColorIndex] = useState(0);
const [secondColorIndex, setSecondColorIndex] = useState(0);
const setDebouncedSecondColorIndex = useDebouncedCallback(setSecondColorIndex, 1000);

return (
<div className={styles.container}>
<div className={styles.block}>
<button
className={styles.button}
type="button"
onClick={() => setFirstColorIndex((firstColorIndex + 1) % 3)}
>
Click for color change
</button>
<div className={styles.rectangle} style={{ backgroundColor: COLORS[firstColorIndex] }} />
</div>

<div className={styles.block}>
<button
className={styles.button}
type="button"
onClick={() => setDebouncedSecondColorIndex((secondColorIndex + 1) % 3)}
>
Click for debounced color change (delay: 1000 ms)
</button>
<div className={styles.rectangle} style={{ backgroundColor: COLORS[secondColorIndex] }} />
</div>
</div>
);
};

export const DebouncedColorChangeStory: StoryObj<typeof DebouncedColorChange> = {
name: 'Debounced color change',
render: DebouncedColorChange
};

export default {
title: 'hooks/useDebouncedCallback'
};
Loading