@toptal/picasso-shared 100.0.0 → 100.1.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.
@@ -1,4 +1,5 @@
1
1
  export * from './use-title-case';
2
2
  export * from './use-isomorphic-layout-effect';
3
3
  export * from './use-has-multiline-counter';
4
+ export * from './use-input-test-id';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA"}
@@ -1,4 +1,5 @@
1
1
  export * from './use-title-case';
2
2
  export * from './use-isomorphic-layout-effect';
3
3
  export * from './use-has-multiline-counter';
4
+ export * from './use-input-test-id';
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Callback ref that stamps `data-testid` onto the `<input>` a Base UI
3
+ * primitive renders internally (e.g. the visually-hidden input of
4
+ * Checkbox/Switch). Base UI exposes that input only through `inputRef` —
5
+ * no prop reaches the input element itself — so the attribute is applied
6
+ * imperatively. The ref re-attaches whenever the testid changes, keeping
7
+ * the attribute in sync (and removing it when the testid is unset).
8
+ */
9
+ export declare const useInputTestId: (testId?: string) => (input: HTMLInputElement | null) => void;
10
+ //# sourceMappingURL=use-input-test-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-input-test-id.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-input-test-id.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,YAAa,MAAM,aAElC,gBAAgB,GAAG,IAAI,SAYhC,CAAA"}
@@ -0,0 +1,21 @@
1
+ import { useCallback } from 'react';
2
+ /**
3
+ * Callback ref that stamps `data-testid` onto the `<input>` a Base UI
4
+ * primitive renders internally (e.g. the visually-hidden input of
5
+ * Checkbox/Switch). Base UI exposes that input only through `inputRef` —
6
+ * no prop reaches the input element itself — so the attribute is applied
7
+ * imperatively. The ref re-attaches whenever the testid changes, keeping
8
+ * the attribute in sync (and removing it when the testid is unset).
9
+ */
10
+ export const useInputTestId = (testId) => useCallback((input) => {
11
+ if (!input) {
12
+ return;
13
+ }
14
+ if (testId === undefined) {
15
+ input.removeAttribute('data-testid');
16
+ }
17
+ else {
18
+ input.setAttribute('data-testid', testId);
19
+ }
20
+ }, [testId]);
21
+ //# sourceMappingURL=use-input-test-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-input-test-id.js","sourceRoot":"","sources":["../../../src/hooks/use-input-test-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAEnC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAe,EAAE,EAAE,CAChD,WAAW,CACT,CAAC,KAA8B,EAAE,EAAE;IACjC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAM;IACR,CAAC;IAED,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,KAAK,CAAC,eAAe,CAAC,aAAa,CAAC,CAAA;IACtC,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,CAAA;IAC3C,CAAC;AACH,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toptal/picasso-shared",
3
- "version": "100.0.0",
3
+ "version": "100.1.0",
4
4
  "description": "Shared types, utils for Picasso internal usage",
5
5
  "author": "Toptal",
6
6
  "homepage": "https://github.com/toptal/picasso/tree/master/packages/picasso-shared#readme",
@@ -1,3 +1,4 @@
1
1
  export * from './use-title-case'
2
2
  export * from './use-isomorphic-layout-effect'
3
3
  export * from './use-has-multiline-counter'
4
+ export * from './use-input-test-id'
@@ -0,0 +1,25 @@
1
+ import { useCallback } from 'react'
2
+
3
+ /**
4
+ * Callback ref that stamps `data-testid` onto the `<input>` a Base UI
5
+ * primitive renders internally (e.g. the visually-hidden input of
6
+ * Checkbox/Switch). Base UI exposes that input only through `inputRef` —
7
+ * no prop reaches the input element itself — so the attribute is applied
8
+ * imperatively. The ref re-attaches whenever the testid changes, keeping
9
+ * the attribute in sync (and removing it when the testid is unset).
10
+ */
11
+ export const useInputTestId = (testId?: string) =>
12
+ useCallback(
13
+ (input: HTMLInputElement | null) => {
14
+ if (!input) {
15
+ return
16
+ }
17
+
18
+ if (testId === undefined) {
19
+ input.removeAttribute('data-testid')
20
+ } else {
21
+ input.setAttribute('data-testid', testId)
22
+ }
23
+ },
24
+ [testId]
25
+ )