sera-components 1.6.2 → 1.6.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/dist/index.js +1230 -1190
- package/dist/index.umd.cjs +7 -7
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/test-id.d.ts +62 -0
- package/package.json +1 -1
package/dist/utils/index.d.ts
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context to control test ID generation.
|
|
3
|
+
* Set to true to enable data-testid attributes on components.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* // In your app entry point
|
|
8
|
+
* import { TestIdProvider } from "sera-components";
|
|
9
|
+
*
|
|
10
|
+
* function App() {
|
|
11
|
+
* // Enable test IDs only in development/test mode
|
|
12
|
+
* const enableTestIds = import.meta.env.DEV || import.meta.env.MODE === "test";
|
|
13
|
+
*
|
|
14
|
+
* return (
|
|
15
|
+
* <TestIdProvider value={enableTestIds}>
|
|
16
|
+
* <YourApp />
|
|
17
|
+
* </TestIdProvider>
|
|
18
|
+
* );
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const TestIdContext: import('react').Context<boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* Provider component for enabling/disabling test IDs globally.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* <TestIdProvider value={true}>
|
|
29
|
+
* <App />
|
|
30
|
+
* </TestIdProvider>
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare const TestIdProvider: import('react').Provider<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* Hook that returns test ID props when test IDs are enabled via TestIdContext.
|
|
36
|
+
* Returns an object with data-testid attribute when enabled, or an empty object when disabled.
|
|
37
|
+
*
|
|
38
|
+
* @param name - The test ID name to use
|
|
39
|
+
* @returns An object containing the data-testid attribute or an empty object
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* function MyInput({ name }: { name: string }) {
|
|
44
|
+
* const testId = useTestId(`input:${name}`);
|
|
45
|
+
* return <input {...testId} />;
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function useTestId(name: string): {
|
|
50
|
+
"data-testid"?: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Non-hook utility for getting test ID props.
|
|
54
|
+
* Use this when you can't use hooks (e.g., in render functions or callbacks).
|
|
55
|
+
*
|
|
56
|
+
* @param name - The test ID name to use
|
|
57
|
+
* @param enabled - Whether test IDs are enabled
|
|
58
|
+
* @returns An object containing the data-testid attribute or an empty object
|
|
59
|
+
*/
|
|
60
|
+
export declare function getTestIdProps(name: string, enabled: boolean): {
|
|
61
|
+
"data-testid"?: string;
|
|
62
|
+
};
|