@mantine/hooks 5.7.2 → 5.8.0

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.
@@ -5,20 +5,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var React = require('react');
6
6
 
7
7
  function useToggle(options = [false, true]) {
8
- const [state, setState] = React.useState(options[0]);
9
- const toggle = (value) => {
10
- if (typeof value !== "undefined") {
11
- setState(value);
12
- } else {
13
- setState((current) => {
14
- if (current === options[0]) {
15
- return options[1];
16
- }
17
- return options[0];
18
- });
19
- }
20
- };
21
- return [state, toggle];
8
+ const [[option], toggle] = React.useReducer((state, action) => {
9
+ const value = action instanceof Function ? action(state[0]) : action;
10
+ const index = Math.abs(state.indexOf(value));
11
+ return state.slice(index).concat(state.slice(0, index));
12
+ }, options);
13
+ return [option, toggle];
22
14
  }
23
15
 
24
16
  exports.useToggle = useToggle;
@@ -1 +1 @@
1
- {"version":3,"file":"use-toggle.js","sources":["../../src/use-toggle/use-toggle.ts"],"sourcesContent":["import { useState } from 'react';\n\nexport function useToggle<T = boolean>(options: readonly [T, T] = [false, true] as any) {\n const [state, setState] = useState(options[0]);\n\n const toggle = (value?: React.SetStateAction<T>) => {\n if (typeof value !== 'undefined') {\n setState(value);\n } else {\n setState((current) => {\n if (current === options[0]) {\n return options[1];\n }\n\n return options[0];\n });\n }\n };\n\n return [state, toggle] as const;\n}\n"],"names":["useState"],"mappings":";;;;;;AACO,SAAS,SAAS,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE;AACnD,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AACjD,EAAE,MAAM,MAAM,GAAG,CAAC,KAAK,KAAK;AAC5B,IAAI,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;AACtC,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;AACtB,KAAK,MAAM;AACX,MAAM,QAAQ,CAAC,CAAC,OAAO,KAAK;AAC5B,QAAQ,IAAI,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE;AACpC,UAAU,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AAC5B,SAAS;AACT,QAAQ,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AAC1B,OAAO,CAAC,CAAC;AACT,KAAK;AACL,GAAG,CAAC;AACJ,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACzB;;;;"}
1
+ {"version":3,"file":"use-toggle.js","sources":["../../src/use-toggle/use-toggle.ts"],"sourcesContent":["import { useReducer } from 'react';\n\nexport function useToggle<T = boolean>(options: readonly T[] = [false, true] as any) {\n const [[option], toggle] = useReducer((state: T[], action: React.SetStateAction<T>) => {\n const value = action instanceof Function ? action(state[0]) : action;\n const index = Math.abs(state.indexOf(value));\n\n return state.slice(index).concat(state.slice(0, index));\n }, options as T[]);\n\n return [option, toggle as (value?: React.SetStateAction<T>) => void] as const;\n}\n"],"names":["useReducer"],"mappings":";;;;;;AACO,SAAS,SAAS,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE;AACnD,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,GAAGA,gBAAU,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK;AAC3D,IAAI,MAAM,KAAK,GAAG,MAAM,YAAY,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;AACzE,IAAI,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AACjD,IAAI,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;AAC5D,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC1B;;;;"}
@@ -1,20 +1,12 @@
1
- import { useState } from 'react';
1
+ import { useReducer } from 'react';
2
2
 
3
3
  function useToggle(options = [false, true]) {
4
- const [state, setState] = useState(options[0]);
5
- const toggle = (value) => {
6
- if (typeof value !== "undefined") {
7
- setState(value);
8
- } else {
9
- setState((current) => {
10
- if (current === options[0]) {
11
- return options[1];
12
- }
13
- return options[0];
14
- });
15
- }
16
- };
17
- return [state, toggle];
4
+ const [[option], toggle] = useReducer((state, action) => {
5
+ const value = action instanceof Function ? action(state[0]) : action;
6
+ const index = Math.abs(state.indexOf(value));
7
+ return state.slice(index).concat(state.slice(0, index));
8
+ }, options);
9
+ return [option, toggle];
18
10
  }
19
11
 
20
12
  export { useToggle };
@@ -1 +1 @@
1
- {"version":3,"file":"use-toggle.js","sources":["../../src/use-toggle/use-toggle.ts"],"sourcesContent":["import { useState } from 'react';\n\nexport function useToggle<T = boolean>(options: readonly [T, T] = [false, true] as any) {\n const [state, setState] = useState(options[0]);\n\n const toggle = (value?: React.SetStateAction<T>) => {\n if (typeof value !== 'undefined') {\n setState(value);\n } else {\n setState((current) => {\n if (current === options[0]) {\n return options[1];\n }\n\n return options[0];\n });\n }\n };\n\n return [state, toggle] as const;\n}\n"],"names":[],"mappings":";;AACO,SAAS,SAAS,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE;AACnD,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AACjD,EAAE,MAAM,MAAM,GAAG,CAAC,KAAK,KAAK;AAC5B,IAAI,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;AACtC,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;AACtB,KAAK,MAAM;AACX,MAAM,QAAQ,CAAC,CAAC,OAAO,KAAK;AAC5B,QAAQ,IAAI,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE;AACpC,UAAU,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AAC5B,SAAS;AACT,QAAQ,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AAC1B,OAAO,CAAC,CAAC;AACT,KAAK;AACL,GAAG,CAAC;AACJ,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACzB;;;;"}
1
+ {"version":3,"file":"use-toggle.js","sources":["../../src/use-toggle/use-toggle.ts"],"sourcesContent":["import { useReducer } from 'react';\n\nexport function useToggle<T = boolean>(options: readonly T[] = [false, true] as any) {\n const [[option], toggle] = useReducer((state: T[], action: React.SetStateAction<T>) => {\n const value = action instanceof Function ? action(state[0]) : action;\n const index = Math.abs(state.indexOf(value));\n\n return state.slice(index).concat(state.slice(0, index));\n }, options as T[]);\n\n return [option, toggle as (value?: React.SetStateAction<T>) => void] as const;\n}\n"],"names":[],"mappings":";;AACO,SAAS,SAAS,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE;AACnD,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK;AAC3D,IAAI,MAAM,KAAK,GAAG,MAAM,YAAY,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;AACzE,IAAI,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AACjD,IAAI,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;AAC5D,GAAG,EAAE,OAAO,CAAC,CAAC;AACd,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC1B;;;;"}
@@ -1,2 +1,2 @@
1
- export declare function useToggle<T = boolean>(options?: readonly [T, T]): readonly [T, (value?: React.SetStateAction<T>) => void];
1
+ export declare function useToggle<T = boolean>(options?: readonly T[]): readonly [T, (value?: React.SetStateAction<T>) => void];
2
2
  //# sourceMappingURL=use-toggle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-toggle.d.ts","sourceRoot":"","sources":["../../src/use-toggle/use-toggle.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,GAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAwB,yBAG5D,MAAM,cAAc,CAAC,CAAC,CAAC,WAehD"}
1
+ {"version":3,"file":"use-toggle.d.ts","sourceRoot":"","sources":["../../src/use-toggle/use-toggle.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,GAAE,SAAS,CAAC,EAAyB,yBAQ9C,MAAM,cAAc,CAAC,CAAC,CAAC,KAAK,IAAI,EACpE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantine/hooks",
3
- "version": "5.7.2",
3
+ "version": "5.8.0",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "types": "lib/index.d.ts",