@ledgerhq/native-ui 0.39.0-nightly.2 → 0.39.0-nightly.3
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/lib/pre-ldls/components/Search/Search.d.ts +9 -0
- package/lib/pre-ldls/components/Search/Search.d.ts.map +1 -0
- package/lib/pre-ldls/components/Search/Search.js +26 -0
- package/lib/pre-ldls/components/Search/Search.stories.d.ts +8 -0
- package/lib/pre-ldls/components/Search/Search.stories.d.ts.map +1 -0
- package/lib/pre-ldls/components/Search/Search.stories.js +29 -0
- package/lib/pre-ldls/hooks/index.d.ts +2 -0
- package/lib/pre-ldls/hooks/index.d.ts.map +1 -0
- package/lib/pre-ldls/hooks/index.js +1 -0
- package/lib/pre-ldls/hooks/useDebouncedCallback.d.ts +2 -0
- package/lib/pre-ldls/hooks/useDebouncedCallback.d.ts.map +1 -0
- package/lib/pre-ldls/hooks/useDebouncedCallback.js +15 -0
- package/lib/pre-ldls/hooks/useDebouncedCallback.stories.d.ts +14 -0
- package/lib/pre-ldls/hooks/useDebouncedCallback.stories.d.ts.map +1 -0
- package/lib/pre-ldls/hooks/useDebouncedCallback.stories.js +41 -0
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { TextInputProps } from "react-native";
|
|
3
|
+
type Props = Readonly<TextInputProps & {
|
|
4
|
+
onDebouncedChange?: (current: string, prev: string) => void;
|
|
5
|
+
debounceTime?: number;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function Search({ onDebouncedChange, debounceTime, onChange, ...props }: Props): React.JSX.Element;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=Search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Search.d.ts","sourceRoot":"","sources":["../../../../src/pre-ldls/components/Search/Search.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0B,MAAM,OAAO,CAAC;AAI/C,OAAO,EAAkD,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9F,KAAK,KAAK,GAAG,QAAQ,CACnB,cAAc,GAAG;IACf,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CACF,CAAC;AAEF,wBAAgB,MAAM,CAAC,EAAE,iBAAiB,EAAE,YAAkB,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,KAAK,qBAyB1F"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { useMemo, useRef } from "react";
|
|
2
|
+
import { Icons } from "../../../assets";
|
|
3
|
+
import { useDebouncedCallback } from "../../hooks";
|
|
4
|
+
import { Input } from "..";
|
|
5
|
+
export function Search({ onDebouncedChange, debounceTime = 500, onChange, ...props }) {
|
|
6
|
+
const initialValue = props.value ?? props.defaultValue ?? "";
|
|
7
|
+
const prevValue = useRef(String(initialValue));
|
|
8
|
+
const handleDebouncedChange = useDebouncedCallback(useMemo(() => {
|
|
9
|
+
if (!onDebouncedChange)
|
|
10
|
+
return;
|
|
11
|
+
return (e) => {
|
|
12
|
+
const current = e.nativeEvent.text;
|
|
13
|
+
onDebouncedChange(current, prevValue.current);
|
|
14
|
+
prevValue.current = current;
|
|
15
|
+
};
|
|
16
|
+
}, [onDebouncedChange]), debounceTime);
|
|
17
|
+
const handleChange = useMemo(() => {
|
|
18
|
+
if (!handleDebouncedChange && !onChange)
|
|
19
|
+
return;
|
|
20
|
+
return (e) => {
|
|
21
|
+
onChange?.(e);
|
|
22
|
+
handleDebouncedChange?.(e);
|
|
23
|
+
};
|
|
24
|
+
}, [handleDebouncedChange, onChange]);
|
|
25
|
+
return React.createElement(Input, { ...props, icon: Icons.Search, onChange: handleChange });
|
|
26
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Meta, type StoryObj } from "@storybook/react";
|
|
2
|
+
import { Search } from "./Search";
|
|
3
|
+
declare const meta: Meta<typeof Search>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Search>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const WithInteraction: Story;
|
|
8
|
+
//# sourceMappingURL=Search.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Search.stories.d.ts","sourceRoot":"","sources":["../../../../src/pre-ldls/components/Search/Search.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAOlC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,MAAM,CAU7B,CAAC;AACF,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,MAAM,CAAC,CAAC;AAErC,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC;AAGjC,eAAO,MAAM,eAAe,EAAE,KAU7B,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Search } from "./Search";
|
|
2
|
+
import { expect, jest } from "@storybook/jest";
|
|
3
|
+
import { within, userEvent } from "@storybook/testing-library";
|
|
4
|
+
const onDebouncedChange = jest.fn();
|
|
5
|
+
const onChange = jest.fn();
|
|
6
|
+
const meta = {
|
|
7
|
+
component: Search,
|
|
8
|
+
title: "PreLdls/Components/Search",
|
|
9
|
+
tags: ["autodocs"],
|
|
10
|
+
args: {
|
|
11
|
+
debounceTime: 500,
|
|
12
|
+
placeholder: "Search",
|
|
13
|
+
onDebouncedChange,
|
|
14
|
+
onChange,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export default meta;
|
|
18
|
+
export const Default = {};
|
|
19
|
+
// Interaction Testing
|
|
20
|
+
export const WithInteraction = {
|
|
21
|
+
args: {},
|
|
22
|
+
controls: { expanded: true },
|
|
23
|
+
play: async ({ canvasElement }) => {
|
|
24
|
+
const canvas = within(canvasElement);
|
|
25
|
+
const input = canvas.getByRole("textbox");
|
|
26
|
+
await userEvent.type(input, "Write something");
|
|
27
|
+
await expect(input).toHaveValue("Write something");
|
|
28
|
+
},
|
|
29
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pre-ldls/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useDebouncedCallback";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDebouncedCallback.d.ts","sourceRoot":"","sources":["../../../src/pre-ldls/hooks/useDebouncedCallback.ts"],"names":[],"mappings":"AAEA,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,OAAO,EAAE,EACtD,QAAQ,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC,GAAG,SAAS,EAC5C,KAAK,CAAC,EAAE,MAAM,cAEuD,CAAC,KAAK,IAAI,cAehF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
export function useDebouncedCallback(callback, delay) {
|
|
3
|
+
const [debouncedCallback, setDebouncedCallback] = useState();
|
|
4
|
+
const timeout = useRef();
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (!callback)
|
|
7
|
+
return setDebouncedCallback(undefined);
|
|
8
|
+
setDebouncedCallback(() => (...args) => {
|
|
9
|
+
clearTimeout(timeout.current);
|
|
10
|
+
timeout.current = setTimeout(() => callback(...args), delay);
|
|
11
|
+
});
|
|
12
|
+
return () => clearTimeout(timeout.current);
|
|
13
|
+
}, [callback, delay]);
|
|
14
|
+
return debouncedCallback;
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
3
|
+
import { jest } from "@storybook/jest";
|
|
4
|
+
declare const meta: Meta<typeof Template>;
|
|
5
|
+
export default meta;
|
|
6
|
+
type TemplateProps = {
|
|
7
|
+
delay: number;
|
|
8
|
+
callback1: typeof jest.fn;
|
|
9
|
+
callback2: typeof jest.fn;
|
|
10
|
+
};
|
|
11
|
+
declare function Template({ callback1, callback2, delay }: TemplateProps): React.JSX.Element;
|
|
12
|
+
export declare const Default: StoryObj<typeof Template>;
|
|
13
|
+
export declare const WithInteraction: StoryObj<typeof Template>;
|
|
14
|
+
//# sourceMappingURL=useDebouncedCallback.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDebouncedCallback.stories.d.ts","sourceRoot":"","sources":["../../../src/pre-ldls/hooks/useDebouncedCallback.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAU,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAM/C,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,QAAQ,CAS/B,CAAC;AACF,eAAe,IAAI,CAAC;AAEpB,KAAK,aAAa,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC;IAC1B,SAAS,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC;CAC3B,CAAC;AACF,iBAAS,QAAQ,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,aAAa,qBAoB/D;AAED,eAAO,MAAM,OAAO,EAAE,QAAQ,CAAC,OAAO,QAAQ,CAAM,CAAC;AAErD,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,OAAO,QAAQ,CAUrD,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { useDebouncedCallback } from ".";
|
|
3
|
+
import { expect, jest } from "@storybook/jest";
|
|
4
|
+
import { within, userEvent } from "@storybook/testing-library";
|
|
5
|
+
const callback1 = jest.fn();
|
|
6
|
+
const callback2 = jest.fn();
|
|
7
|
+
const meta = {
|
|
8
|
+
component: Template,
|
|
9
|
+
title: "PreLdls/Hooks/useDebouncedCallback",
|
|
10
|
+
tags: ["!autodocs"],
|
|
11
|
+
args: {
|
|
12
|
+
delay: 1000,
|
|
13
|
+
callback1,
|
|
14
|
+
callback2,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export default meta;
|
|
18
|
+
function Template({ callback1, callback2, delay }) {
|
|
19
|
+
const [callback, setCallback] = useState(() => callback1);
|
|
20
|
+
const debouncedCallback = useDebouncedCallback(callback, delay);
|
|
21
|
+
const [value, setValue] = useState("");
|
|
22
|
+
return (React.createElement("div", null,
|
|
23
|
+
React.createElement("input", { type: "text", value: value, onChange: (event) => {
|
|
24
|
+
const value = event.target.value;
|
|
25
|
+
setValue(value);
|
|
26
|
+
debouncedCallback?.(value);
|
|
27
|
+
} }),
|
|
28
|
+
React.createElement("button", { onClick: () => setCallback(() => callback1) }, "Use Callback 1"),
|
|
29
|
+
React.createElement("button", { onClick: () => setCallback(() => callback2) }, "Use Callback 2")));
|
|
30
|
+
}
|
|
31
|
+
export const Default = {};
|
|
32
|
+
export const WithInteraction = {
|
|
33
|
+
args: {},
|
|
34
|
+
controls: { expanded: true },
|
|
35
|
+
play: async ({ canvasElement }) => {
|
|
36
|
+
const canvas = within(canvasElement);
|
|
37
|
+
const input = canvas.getByRole("textbox");
|
|
38
|
+
await userEvent.type(input, "Write something");
|
|
39
|
+
await expect(input).toHaveValue("Write something");
|
|
40
|
+
},
|
|
41
|
+
};
|