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.
@@ -1,3 +1,4 @@
1
1
  export * from './utils';
2
2
  export * from './trie';
3
3
  export * from './property-utils';
4
+ export * from './test-id';
@@ -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
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sera-components",
3
3
  "private": false,
4
- "version": "1.6.2",
4
+ "version": "1.6.3",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"