@workday/canvas-kit-react 6.2.2 → 6.3.0-next.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.
- package/checkbox/lib/Checkbox.tsx +1 -1
- package/common/README.md +78 -0
- package/common/lib/utils/useUniqueId.ts +44 -3
- package/dist/commonjs/checkbox/lib/Checkbox.d.ts +1 -1
- package/dist/commonjs/common/lib/utils/useUniqueId.d.ts +28 -0
- package/dist/commonjs/common/lib/utils/useUniqueId.d.ts.map +1 -1
- package/dist/commonjs/common/lib/utils/useUniqueId.js +40 -5
- package/dist/commonjs/form-field/lib/FormField.d.ts.map +1 -1
- package/dist/commonjs/form-field/lib/FormField.js +1 -2
- package/dist/commonjs/popup/lib/hooks/focus-trap-js.d.ts.map +1 -1
- package/dist/commonjs/popup/lib/hooks/focus-trap-js.js +1 -0
- package/dist/commonjs/radio/lib/Radio.d.ts +1 -1
- package/dist/commonjs/switch/lib/Switch.d.ts +1 -1
- package/dist/commonjs/tooltip/lib/useTooltip.js +2 -5
- package/dist/es6/checkbox/lib/Checkbox.d.ts +1 -1
- package/dist/es6/common/lib/utils/useUniqueId.d.ts +28 -0
- package/dist/es6/common/lib/utils/useUniqueId.d.ts.map +1 -1
- package/dist/es6/common/lib/utils/useUniqueId.js +40 -2
- package/dist/es6/form-field/lib/FormField.d.ts.map +1 -1
- package/dist/es6/form-field/lib/FormField.js +2 -3
- package/dist/es6/popup/lib/hooks/focus-trap-js.d.ts.map +1 -1
- package/dist/es6/popup/lib/hooks/focus-trap-js.js +1 -0
- package/dist/es6/radio/lib/Radio.d.ts +1 -1
- package/dist/es6/switch/lib/Switch.d.ts +1 -1
- package/dist/es6/tooltip/lib/useTooltip.js +2 -2
- package/form-field/lib/FormField.tsx +8 -3
- package/package.json +6 -7
- package/popup/lib/hooks/focus-trap-js.ts +1 -0
- package/radio/lib/Radio.tsx +1 -1
- package/switch/lib/Switch.tsx +1 -1
- package/tooltip/lib/useTooltip.tsx +2 -2
- package/ts3.5/dist/commonjs/checkbox/lib/Checkbox.d.ts +1 -1
- package/ts3.5/dist/commonjs/common/lib/utils/useUniqueId.d.ts +28 -0
- package/ts3.5/dist/commonjs/radio/lib/Radio.d.ts +1 -1
- package/ts3.5/dist/commonjs/switch/lib/Switch.d.ts +1 -1
- package/ts3.5/dist/es6/checkbox/lib/Checkbox.d.ts +1 -1
- package/ts3.5/dist/es6/common/lib/utils/useUniqueId.d.ts +28 -0
- package/ts3.5/dist/es6/radio/lib/Radio.d.ts +1 -1
- package/ts3.5/dist/es6/switch/lib/Switch.d.ts +1 -1
|
@@ -33,7 +33,7 @@ export interface CheckboxProps extends Themeable {
|
|
|
33
33
|
disabled?: boolean;
|
|
34
34
|
/**
|
|
35
35
|
* The HTML `id` of the underlying checkbox input element. This is required if `label` is defined as a non-empty string.
|
|
36
|
-
* @default A uniquely generated id
|
|
36
|
+
* @default A uniquely generated id
|
|
37
37
|
*/
|
|
38
38
|
id?: string;
|
|
39
39
|
/**
|
package/common/README.md
CHANGED
|
@@ -17,6 +17,9 @@ Includes:
|
|
|
17
17
|
- [Component Functions](#component-functions)
|
|
18
18
|
- [createComponent](#createcomponent)
|
|
19
19
|
- [ExtractProps](#extractprops)
|
|
20
|
+
- [Common Hooks](#common-hooks)
|
|
21
|
+
- [useUniqueId](#useuniqueid)
|
|
22
|
+
- [Utility Functions](#utility-functions)
|
|
20
23
|
|
|
21
24
|
## CanvasProvider
|
|
22
25
|
|
|
@@ -369,3 +372,78 @@ const MyNewComponent = createComponent('aside')(
|
|
|
369
372
|
|
|
370
373
|
If the component is a `Component` and not an `ElementComponent`, only the prop interface will ever
|
|
371
374
|
be returned since there is not HTML attribute interface associated with `Component`.
|
|
375
|
+
|
|
376
|
+
## Common Hooks
|
|
377
|
+
|
|
378
|
+
### useUniqueId
|
|
379
|
+
|
|
380
|
+
A hook to generate a unique identifier for an element. Most commonly used for accessibility. The
|
|
381
|
+
hook will generate a unique id the first render and always return the same id every render. This
|
|
382
|
+
uses [generateUniqueId](#generateuniqueid) internally.
|
|
383
|
+
|
|
384
|
+
```tsx
|
|
385
|
+
const MyComponent = () => {
|
|
386
|
+
const id = useUniqueId();
|
|
387
|
+
|
|
388
|
+
return <div id={id}>Hello!</div>;
|
|
389
|
+
};
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
If you wish to support user-defined ids, `useUniqueId` allows an optional id to override. This
|
|
393
|
+
provides a safe and easy way of handling id overrides without conditional hooks.
|
|
394
|
+
|
|
395
|
+
```tsx
|
|
396
|
+
const MyComponent = ({id}) => {
|
|
397
|
+
const localId = useUniqueId(id);
|
|
398
|
+
|
|
399
|
+
return <div id={localId}>Hello!</div>;
|
|
400
|
+
};
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
## Utility Functions
|
|
404
|
+
|
|
405
|
+
### generateUniqueId
|
|
406
|
+
|
|
407
|
+
Generates a unique and HTML5 compliant identifier every time it is called. Internally it uses a 4
|
|
408
|
+
character random seed starting with a letter. This seed is unique to each instance of this package
|
|
409
|
+
meaning different versions of Canvas Kit on the page will have a different seed. Each call will use
|
|
410
|
+
a Base 36 string (10 numbers + 26 letters) based on an incremented number. The incremented number
|
|
411
|
+
always starts at 0 and can be reset for testing purposes using
|
|
412
|
+
[resetUniqueIdCount](#resetuniqueidcount). [setUniqueSeed](#setuniqueseed) can also be used for
|
|
413
|
+
testing or server side rendering to get the same results during hydration.
|
|
414
|
+
|
|
415
|
+
```ts
|
|
416
|
+
const id1 = generateUniqueId(); // vi1e0
|
|
417
|
+
const id2 = generateUniqueId(); // vi1e1
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
### setUniqueSeed
|
|
421
|
+
|
|
422
|
+
Update the seed used by the id generator. This is useful for snapshot tests to help stabilize ids
|
|
423
|
+
generated each run. This could also be used for server-side hydration - if you choose the same seed
|
|
424
|
+
for server and set that on the client before components are rendered, the ids generated will be the
|
|
425
|
+
same.
|
|
426
|
+
|
|
427
|
+
For snapshot testing, this will help stabilize snapshot tests. Use in conjunction with
|
|
428
|
+
[resetUniqueIdCount](#resetuniqueidcount).
|
|
429
|
+
|
|
430
|
+
```ts
|
|
431
|
+
// set in a script tag from the server
|
|
432
|
+
setUniqueSeed(window.__ID_SEED); // set in a script tag from the server
|
|
433
|
+
|
|
434
|
+
// jest setup
|
|
435
|
+
before(() => {
|
|
436
|
+
setUniqueSeed('a');
|
|
437
|
+
});
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### resetUniqueIdCount
|
|
441
|
+
|
|
442
|
+
This should only be called for tests in `beforeEach` for snapshot tests. Use in conjunction with
|
|
443
|
+
[setUniqueSeed](#setuniqueseed).
|
|
444
|
+
|
|
445
|
+
```ts
|
|
446
|
+
beforeEach(() => {
|
|
447
|
+
resetUniqueIdCount();
|
|
448
|
+
});
|
|
449
|
+
```
|
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
import uuid from 'uuid/v4';
|
|
2
|
-
|
|
3
1
|
import {useConstant} from './useConstant';
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
// Create a unique seed per import to prevent collisions from other versions of `useUniqueId`
|
|
4
|
+
let seed = Math.random()
|
|
5
|
+
.toString(36)
|
|
6
|
+
.slice(2)
|
|
7
|
+
.replace(/[0-9]*/, '')
|
|
8
|
+
.substr(0, 4);
|
|
9
|
+
|
|
10
|
+
let c = 0;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Generates a unique and HTML5 compliant identifier every time it is called. Internally it uses a 4
|
|
14
|
+
* character random seed starting with a letter. This seed is unique to each instance of this
|
|
15
|
+
* package meaning different versions of Canvas Kit on the page will have a different seed. Each
|
|
16
|
+
* call will use a Base 36 string (10 numbers + 26 letters) based on an incremented number. The
|
|
17
|
+
* incremented number always starts at 0 and can be reset for testing purposes using
|
|
18
|
+
* [resetUniqueIdCount](#resetuniqueidcount). [setUniqueSeed](#setuniqueseed) can also be used for
|
|
19
|
+
* testing or server side rendering to get the same results during hydration.
|
|
20
|
+
*/
|
|
21
|
+
export const generateUniqueId = () => seed + (c++).toString(36);
|
|
6
22
|
|
|
7
23
|
/**
|
|
8
24
|
* Generate a unique ID if one is not provided. The generated ID will be stable across renders
|
|
@@ -20,3 +36,28 @@ export const useUniqueId = (id?: string) => {
|
|
|
20
36
|
* TODO: Remove in major release
|
|
21
37
|
*/
|
|
22
38
|
export const uniqueId = useUniqueId;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Update the seed used by the id generator. This is useful for snapshot tests to help stabilize ids
|
|
42
|
+
* generated each run. This could also be used for server-side hydration - if you choose the same
|
|
43
|
+
* seed for server and set that on the client before components are rendered, the ids generated will
|
|
44
|
+
* be the same.
|
|
45
|
+
* @example
|
|
46
|
+
* // set in a script tag from the server
|
|
47
|
+
* setSeed(window.__ID_SEED); // set in a script tag from the server
|
|
48
|
+
*
|
|
49
|
+
* // jest setup
|
|
50
|
+
* before(() => {
|
|
51
|
+
* setSeed('a')
|
|
52
|
+
* })
|
|
53
|
+
*/
|
|
54
|
+
export const setUniqueSeed = (s: string) => {
|
|
55
|
+
seed = s;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* This should only be called for tests in an `beforeEach`
|
|
60
|
+
*/
|
|
61
|
+
export const resetUniqueIdCount = () => {
|
|
62
|
+
c = 0;
|
|
63
|
+
};
|
|
@@ -13,7 +13,7 @@ export interface CheckboxProps extends Themeable {
|
|
|
13
13
|
disabled?: boolean;
|
|
14
14
|
/**
|
|
15
15
|
* The HTML `id` of the underlying checkbox input element. This is required if `label` is defined as a non-empty string.
|
|
16
|
-
* @default A uniquely generated id
|
|
16
|
+
* @default A uniquely generated id
|
|
17
17
|
*/
|
|
18
18
|
id?: string;
|
|
19
19
|
/**
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a unique and HTML5 compliant identifier every time it is called. Internally it uses a 4
|
|
3
|
+
* character random seed starting with a letter. This seed is unique to each instance of this
|
|
4
|
+
* package meaning different versions of Canvas Kit on the page will have a different seed. Each
|
|
5
|
+
* call will use a Base 36 string (10 numbers + 26 letters) based on an incremented number. The
|
|
6
|
+
* incremented number always starts at 0 and can be reset for testing purposes using
|
|
7
|
+
* [resetUniqueIdCount](#resetuniqueidcount). [setUniqueSeed](#setuniqueseed) can also be used for
|
|
8
|
+
* testing or server side rendering to get the same results during hydration.
|
|
9
|
+
*/
|
|
1
10
|
export declare const generateUniqueId: () => string;
|
|
2
11
|
/**
|
|
3
12
|
* Generate a unique ID if one is not provided. The generated ID will be stable across renders
|
|
@@ -10,4 +19,23 @@ export declare const useUniqueId: (id?: string | undefined) => string;
|
|
|
10
19
|
* TODO: Remove in major release
|
|
11
20
|
*/
|
|
12
21
|
export declare const uniqueId: (id?: string | undefined) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Update the seed used by the id generator. This is useful for snapshot tests to help stabilize ids
|
|
24
|
+
* generated each run. This could also be used for server-side hydration - if you choose the same
|
|
25
|
+
* seed for server and set that on the client before components are rendered, the ids generated will
|
|
26
|
+
* be the same.
|
|
27
|
+
* @example
|
|
28
|
+
* // set in a script tag from the server
|
|
29
|
+
* setSeed(window.__ID_SEED); // set in a script tag from the server
|
|
30
|
+
*
|
|
31
|
+
* // jest setup
|
|
32
|
+
* before(() => {
|
|
33
|
+
* setSeed('a')
|
|
34
|
+
* })
|
|
35
|
+
*/
|
|
36
|
+
export declare const setUniqueSeed: (s: string) => void;
|
|
37
|
+
/**
|
|
38
|
+
* This should only be called for tests in an `beforeEach`
|
|
39
|
+
*/
|
|
40
|
+
export declare const resetUniqueIdCount: () => void;
|
|
13
41
|
//# sourceMappingURL=useUniqueId.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUniqueId.d.ts","sourceRoot":"","sources":["../../../../../common/lib/utils/useUniqueId.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUniqueId.d.ts","sourceRoot":"","sources":["../../../../../common/lib/utils/useUniqueId.ts"],"names":[],"mappings":"AAWA;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,cAAkC,CAAC;AAEhE;;;GAGG;AACH,eAAO,MAAM,WAAW,qCAIvB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,QAAQ,qCAAc,CAAC;AAEpC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,qBAEzB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,YAE9B,CAAC"}
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var v4_1 = __importDefault(require("uuid/v4"));
|
|
7
3
|
var useConstant_1 = require("./useConstant");
|
|
8
|
-
|
|
4
|
+
// Create a unique seed per import to prevent collisions from other versions of `useUniqueId`
|
|
5
|
+
var seed = Math.random()
|
|
6
|
+
.toString(36)
|
|
7
|
+
.slice(2)
|
|
8
|
+
.replace(/[0-9]*/, '')
|
|
9
|
+
.substr(0, 4);
|
|
10
|
+
var c = 0;
|
|
11
|
+
/**
|
|
12
|
+
* Generates a unique and HTML5 compliant identifier every time it is called. Internally it uses a 4
|
|
13
|
+
* character random seed starting with a letter. This seed is unique to each instance of this
|
|
14
|
+
* package meaning different versions of Canvas Kit on the page will have a different seed. Each
|
|
15
|
+
* call will use a Base 36 string (10 numbers + 26 letters) based on an incremented number. The
|
|
16
|
+
* incremented number always starts at 0 and can be reset for testing purposes using
|
|
17
|
+
* [resetUniqueIdCount](#resetuniqueidcount). [setUniqueSeed](#setuniqueseed) can also be used for
|
|
18
|
+
* testing or server side rendering to get the same results during hydration.
|
|
19
|
+
*/
|
|
20
|
+
exports.generateUniqueId = function () { return seed + (c++).toString(36); };
|
|
9
21
|
/**
|
|
10
22
|
* Generate a unique ID if one is not provided. The generated ID will be stable across renders
|
|
11
23
|
* @param id Optional ID provided that will be used instead of a unique ID
|
|
@@ -21,3 +33,26 @@ exports.useUniqueId = function (id) {
|
|
|
21
33
|
* TODO: Remove in major release
|
|
22
34
|
*/
|
|
23
35
|
exports.uniqueId = exports.useUniqueId;
|
|
36
|
+
/**
|
|
37
|
+
* Update the seed used by the id generator. This is useful for snapshot tests to help stabilize ids
|
|
38
|
+
* generated each run. This could also be used for server-side hydration - if you choose the same
|
|
39
|
+
* seed for server and set that on the client before components are rendered, the ids generated will
|
|
40
|
+
* be the same.
|
|
41
|
+
* @example
|
|
42
|
+
* // set in a script tag from the server
|
|
43
|
+
* setSeed(window.__ID_SEED); // set in a script tag from the server
|
|
44
|
+
*
|
|
45
|
+
* // jest setup
|
|
46
|
+
* before(() => {
|
|
47
|
+
* setSeed('a')
|
|
48
|
+
* })
|
|
49
|
+
*/
|
|
50
|
+
exports.setUniqueSeed = function (s) {
|
|
51
|
+
seed = s;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* This should only be called for tests in an `beforeEach`
|
|
55
|
+
*/
|
|
56
|
+
exports.resetUniqueIdCount = function () {
|
|
57
|
+
c = 0;
|
|
58
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormField.d.ts","sourceRoot":"","sources":["../../../../form-field/lib/FormField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,
|
|
1
|
+
{"version":3,"file":"FormField.d.ts","sourceRoot":"","sources":["../../../../form-field/lib/FormField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EACL,cAAc,EACd,SAAS,EAET,SAAS,EAEV,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAC,sBAAsB,EAAiC,MAAM,SAAS,CAAC;AAE/E,MAAM,WAAW,cACf,SAAQ,SAAS,EACf,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,EACpC,cAAc;IAChB;;;OAGG;IACH,aAAa,CAAC,EAAE,sBAAsB,CAAC;IACvC;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAoED,cAAM,SAAU,SAAQ,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC;IACrD,MAAM,CAAC,aAAa,gCAA0B;IAC9C,MAAM,CAAC,SAAS,mBAAa;IAE7B,OAAO,CAAC,OAAO,CAAoD;IAEnE,OAAO,CAAC,cAAc,CA8BpB;IAEF,MAAM;CA2DP;AAKD,eAAe,SAAS,CAAC"}
|
|
@@ -51,7 +51,6 @@ var common_1 = require("@workday/canvas-kit-react/common");
|
|
|
51
51
|
var Hint_1 = __importDefault(require("./Hint"));
|
|
52
52
|
var Label_1 = __importDefault(require("./Label"));
|
|
53
53
|
var types_1 = require("./types");
|
|
54
|
-
var v4_1 = __importDefault(require("uuid/v4"));
|
|
55
54
|
// Use a fieldset element for accessible radio groups
|
|
56
55
|
var FormFieldFieldsetContainer = common_1.styled('fieldset')(function (_a) {
|
|
57
56
|
var grow = _a.grow, labelPosition = _a.labelPosition;
|
|
@@ -111,7 +110,7 @@ var FormField = /** @class */ (function (_super) {
|
|
|
111
110
|
__extends(FormField, _super);
|
|
112
111
|
function FormField() {
|
|
113
112
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
114
|
-
_this.inputId = _this.props.inputId ||
|
|
113
|
+
_this.inputId = _this.props.inputId || common_1.generateUniqueId();
|
|
115
114
|
_this.renderChildren = function (child) {
|
|
116
115
|
if (React.isValidElement(child)) {
|
|
117
116
|
var props = __assign({}, child.props);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focus-trap-js.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/focus-trap-js.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"focus-trap-js.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/focus-trap-js.ts"],"names":[],"mappings":"AAkFA,iBAAS,cAAc,CACrB,KAAK,EAAE,aAAa,EACpB,UAAU,EAAE,WAAW,GAAG,QAAQ,EAClC,YAAY,GAAE,WAAW,EAAE,GAAG,IAAW,uBAgC1C;kBAnCQ,cAAc;;;AA0DvB,OAAO,EAAC,cAAc,EAAC,CAAC"}
|
|
@@ -13,7 +13,7 @@ export interface RadioProps extends Themeable {
|
|
|
13
13
|
disabled?: boolean;
|
|
14
14
|
/**
|
|
15
15
|
* The HTML `id` of the underlying radio input element. This is required if `label` is defined as a non-empty string.
|
|
16
|
-
* @default A uniquely generated id
|
|
16
|
+
* @default A uniquely generated id
|
|
17
17
|
*/
|
|
18
18
|
id?: string;
|
|
19
19
|
/**
|
|
@@ -6,13 +6,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
6
6
|
result["default"] = mod;
|
|
7
7
|
return result;
|
|
8
8
|
};
|
|
9
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
-
};
|
|
12
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
10
|
var React = __importStar(require("react"));
|
|
14
|
-
var v4_1 = __importDefault(require("uuid/v4"));
|
|
15
11
|
var popup_1 = require("@workday/canvas-kit-react/popup");
|
|
12
|
+
var common_1 = require("@workday/canvas-kit-react/common");
|
|
16
13
|
var useIntentTimer = function (fn, waitMs) {
|
|
17
14
|
if (waitMs === void 0) { waitMs = 0; }
|
|
18
15
|
var timer = React.useRef();
|
|
@@ -57,7 +54,7 @@ function useTooltip(_a) {
|
|
|
57
54
|
var mouseDownRef = React.useRef(false); // use to prevent newly focused from making tooltip flash
|
|
58
55
|
var popupModel = popup_1.usePopupModel();
|
|
59
56
|
var _g = React.useState(null), anchorElement = _g[0], setAnchorElement = _g[1];
|
|
60
|
-
var id =
|
|
57
|
+
var id = common_1.useUniqueId();
|
|
61
58
|
var intentTimerHide = useIntentTimer(popupModel.events.hide, hideDelay);
|
|
62
59
|
var intentTimerShow = useIntentTimer(popupModel.events.show, showDelay);
|
|
63
60
|
var onHide = function () {
|
|
@@ -13,7 +13,7 @@ export interface CheckboxProps extends Themeable {
|
|
|
13
13
|
disabled?: boolean;
|
|
14
14
|
/**
|
|
15
15
|
* The HTML `id` of the underlying checkbox input element. This is required if `label` is defined as a non-empty string.
|
|
16
|
-
* @default A uniquely generated id
|
|
16
|
+
* @default A uniquely generated id
|
|
17
17
|
*/
|
|
18
18
|
id?: string;
|
|
19
19
|
/**
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a unique and HTML5 compliant identifier every time it is called. Internally it uses a 4
|
|
3
|
+
* character random seed starting with a letter. This seed is unique to each instance of this
|
|
4
|
+
* package meaning different versions of Canvas Kit on the page will have a different seed. Each
|
|
5
|
+
* call will use a Base 36 string (10 numbers + 26 letters) based on an incremented number. The
|
|
6
|
+
* incremented number always starts at 0 and can be reset for testing purposes using
|
|
7
|
+
* [resetUniqueIdCount](#resetuniqueidcount). [setUniqueSeed](#setuniqueseed) can also be used for
|
|
8
|
+
* testing or server side rendering to get the same results during hydration.
|
|
9
|
+
*/
|
|
1
10
|
export declare const generateUniqueId: () => string;
|
|
2
11
|
/**
|
|
3
12
|
* Generate a unique ID if one is not provided. The generated ID will be stable across renders
|
|
@@ -10,4 +19,23 @@ export declare const useUniqueId: (id?: string | undefined) => string;
|
|
|
10
19
|
* TODO: Remove in major release
|
|
11
20
|
*/
|
|
12
21
|
export declare const uniqueId: (id?: string | undefined) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Update the seed used by the id generator. This is useful for snapshot tests to help stabilize ids
|
|
24
|
+
* generated each run. This could also be used for server-side hydration - if you choose the same
|
|
25
|
+
* seed for server and set that on the client before components are rendered, the ids generated will
|
|
26
|
+
* be the same.
|
|
27
|
+
* @example
|
|
28
|
+
* // set in a script tag from the server
|
|
29
|
+
* setSeed(window.__ID_SEED); // set in a script tag from the server
|
|
30
|
+
*
|
|
31
|
+
* // jest setup
|
|
32
|
+
* before(() => {
|
|
33
|
+
* setSeed('a')
|
|
34
|
+
* })
|
|
35
|
+
*/
|
|
36
|
+
export declare const setUniqueSeed: (s: string) => void;
|
|
37
|
+
/**
|
|
38
|
+
* This should only be called for tests in an `beforeEach`
|
|
39
|
+
*/
|
|
40
|
+
export declare const resetUniqueIdCount: () => void;
|
|
13
41
|
//# sourceMappingURL=useUniqueId.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUniqueId.d.ts","sourceRoot":"","sources":["../../../../../common/lib/utils/useUniqueId.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUniqueId.d.ts","sourceRoot":"","sources":["../../../../../common/lib/utils/useUniqueId.ts"],"names":[],"mappings":"AAWA;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,cAAkC,CAAC;AAEhE;;;GAGG;AACH,eAAO,MAAM,WAAW,qCAIvB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,QAAQ,qCAAc,CAAC;AAEpC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,qBAEzB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,YAE9B,CAAC"}
|
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
import uuid from 'uuid/v4';
|
|
2
1
|
import { useConstant } from './useConstant';
|
|
3
|
-
|
|
2
|
+
// Create a unique seed per import to prevent collisions from other versions of `useUniqueId`
|
|
3
|
+
var seed = Math.random()
|
|
4
|
+
.toString(36)
|
|
5
|
+
.slice(2)
|
|
6
|
+
.replace(/[0-9]*/, '')
|
|
7
|
+
.substr(0, 4);
|
|
8
|
+
var c = 0;
|
|
9
|
+
/**
|
|
10
|
+
* Generates a unique and HTML5 compliant identifier every time it is called. Internally it uses a 4
|
|
11
|
+
* character random seed starting with a letter. This seed is unique to each instance of this
|
|
12
|
+
* package meaning different versions of Canvas Kit on the page will have a different seed. Each
|
|
13
|
+
* call will use a Base 36 string (10 numbers + 26 letters) based on an incremented number. The
|
|
14
|
+
* incremented number always starts at 0 and can be reset for testing purposes using
|
|
15
|
+
* [resetUniqueIdCount](#resetuniqueidcount). [setUniqueSeed](#setuniqueseed) can also be used for
|
|
16
|
+
* testing or server side rendering to get the same results during hydration.
|
|
17
|
+
*/
|
|
18
|
+
export var generateUniqueId = function () { return seed + (c++).toString(36); };
|
|
4
19
|
/**
|
|
5
20
|
* Generate a unique ID if one is not provided. The generated ID will be stable across renders
|
|
6
21
|
* @param id Optional ID provided that will be used instead of a unique ID
|
|
@@ -16,3 +31,26 @@ export var useUniqueId = function (id) {
|
|
|
16
31
|
* TODO: Remove in major release
|
|
17
32
|
*/
|
|
18
33
|
export var uniqueId = useUniqueId;
|
|
34
|
+
/**
|
|
35
|
+
* Update the seed used by the id generator. This is useful for snapshot tests to help stabilize ids
|
|
36
|
+
* generated each run. This could also be used for server-side hydration - if you choose the same
|
|
37
|
+
* seed for server and set that on the client before components are rendered, the ids generated will
|
|
38
|
+
* be the same.
|
|
39
|
+
* @example
|
|
40
|
+
* // set in a script tag from the server
|
|
41
|
+
* setSeed(window.__ID_SEED); // set in a script tag from the server
|
|
42
|
+
*
|
|
43
|
+
* // jest setup
|
|
44
|
+
* before(() => {
|
|
45
|
+
* setSeed('a')
|
|
46
|
+
* })
|
|
47
|
+
*/
|
|
48
|
+
export var setUniqueSeed = function (s) {
|
|
49
|
+
seed = s;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* This should only be called for tests in an `beforeEach`
|
|
53
|
+
*/
|
|
54
|
+
export var resetUniqueIdCount = function () {
|
|
55
|
+
c = 0;
|
|
56
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormField.d.ts","sourceRoot":"","sources":["../../../../form-field/lib/FormField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,
|
|
1
|
+
{"version":3,"file":"FormField.d.ts","sourceRoot":"","sources":["../../../../form-field/lib/FormField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EACL,cAAc,EACd,SAAS,EAET,SAAS,EAEV,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAC,sBAAsB,EAAiC,MAAM,SAAS,CAAC;AAE/E,MAAM,WAAW,cACf,SAAQ,SAAS,EACf,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,EACpC,cAAc;IAChB;;;OAGG;IACH,aAAa,CAAC,EAAE,sBAAsB,CAAC;IACvC;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAoED,cAAM,SAAU,SAAQ,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC;IACrD,MAAM,CAAC,aAAa,gCAA0B;IAC9C,MAAM,CAAC,SAAS,mBAAa;IAE7B,OAAO,CAAC,OAAO,CAAoD;IAEnE,OAAO,CAAC,cAAc,CA8BpB;IAEF,MAAM;CA2DP;AAKD,eAAe,SAAS,CAAC"}
|
|
@@ -35,11 +35,10 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
35
35
|
};
|
|
36
36
|
import * as React from 'react';
|
|
37
37
|
import { space } from '@workday/canvas-kit-react/tokens';
|
|
38
|
-
import { ErrorType, styled } from '@workday/canvas-kit-react/common';
|
|
38
|
+
import { ErrorType, styled, generateUniqueId, } from '@workday/canvas-kit-react/common';
|
|
39
39
|
import Hint from './Hint';
|
|
40
40
|
import Label from './Label';
|
|
41
41
|
import { FormFieldLabelPosition } from './types';
|
|
42
|
-
import uuid from 'uuid/v4';
|
|
43
42
|
// Use a fieldset element for accessible radio groups
|
|
44
43
|
var FormFieldFieldsetContainer = styled('fieldset')(function (_a) {
|
|
45
44
|
var grow = _a.grow, labelPosition = _a.labelPosition;
|
|
@@ -99,7 +98,7 @@ var FormField = /** @class */ (function (_super) {
|
|
|
99
98
|
__extends(FormField, _super);
|
|
100
99
|
function FormField() {
|
|
101
100
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
102
|
-
_this.inputId = _this.props.inputId ||
|
|
101
|
+
_this.inputId = _this.props.inputId || generateUniqueId();
|
|
103
102
|
_this.renderChildren = function (child) {
|
|
104
103
|
if (React.isValidElement(child)) {
|
|
105
104
|
var props = __assign({}, child.props);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focus-trap-js.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/focus-trap-js.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"focus-trap-js.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/focus-trap-js.ts"],"names":[],"mappings":"AAkFA,iBAAS,cAAc,CACrB,KAAK,EAAE,aAAa,EACpB,UAAU,EAAE,WAAW,GAAG,QAAQ,EAClC,YAAY,GAAE,WAAW,EAAE,GAAG,IAAW,uBAgC1C;kBAnCQ,cAAc;;;AA0DvB,OAAO,EAAC,cAAc,EAAC,CAAC"}
|
|
@@ -13,7 +13,7 @@ export interface RadioProps extends Themeable {
|
|
|
13
13
|
disabled?: boolean;
|
|
14
14
|
/**
|
|
15
15
|
* The HTML `id` of the underlying radio input element. This is required if `label` is defined as a non-empty string.
|
|
16
|
-
* @default A uniquely generated id
|
|
16
|
+
* @default A uniquely generated id
|
|
17
17
|
*/
|
|
18
18
|
id?: string;
|
|
19
19
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import uuid from 'uuid/v4';
|
|
3
2
|
import { useCloseOnEscape, useAlwaysCloseOnOutsideClick, usePopupModel, useCloseOnFullscreenExit, } from '@workday/canvas-kit-react/popup';
|
|
3
|
+
import { useUniqueId } from '@workday/canvas-kit-react/common';
|
|
4
4
|
var useIntentTimer = function (fn, waitMs) {
|
|
5
5
|
if (waitMs === void 0) { waitMs = 0; }
|
|
6
6
|
var timer = React.useRef();
|
|
@@ -45,7 +45,7 @@ export function useTooltip(_a) {
|
|
|
45
45
|
var mouseDownRef = React.useRef(false); // use to prevent newly focused from making tooltip flash
|
|
46
46
|
var popupModel = usePopupModel();
|
|
47
47
|
var _g = React.useState(null), anchorElement = _g[0], setAnchorElement = _g[1];
|
|
48
|
-
var id =
|
|
48
|
+
var id = useUniqueId();
|
|
49
49
|
var intentTimerHide = useIntentTimer(popupModel.events.hide, hideDelay);
|
|
50
50
|
var intentTimerShow = useIntentTimer(popupModel.events.show, showDelay);
|
|
51
51
|
var onHide = function () {
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import {space} from '@workday/canvas-kit-react/tokens';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
GrowthBehavior,
|
|
5
|
+
ErrorType,
|
|
6
|
+
styled,
|
|
7
|
+
Themeable,
|
|
8
|
+
generateUniqueId,
|
|
9
|
+
} from '@workday/canvas-kit-react/common';
|
|
4
10
|
import Hint from './Hint';
|
|
5
11
|
import Label from './Label';
|
|
6
12
|
import {FormFieldLabelPosition, FormFieldLabelPositionBehavior} from './types';
|
|
7
|
-
import uuid from 'uuid/v4';
|
|
8
13
|
|
|
9
14
|
export interface FormFieldProps
|
|
10
15
|
extends Themeable,
|
|
@@ -135,7 +140,7 @@ class FormField extends React.Component<FormFieldProps> {
|
|
|
135
140
|
static LabelPosition = FormFieldLabelPosition;
|
|
136
141
|
static ErrorType = ErrorType;
|
|
137
142
|
|
|
138
|
-
private inputId: string = this.props.inputId ||
|
|
143
|
+
private inputId: string = this.props.inputId || generateUniqueId();
|
|
139
144
|
|
|
140
145
|
private renderChildren = (child: React.ReactNode): React.ReactNode => {
|
|
141
146
|
if (React.isValidElement(child)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workday/canvas-kit-react",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.0-next.0+6e10a940",
|
|
4
4
|
"description": "The parent module that contains all Workday Canvas Kit React components",
|
|
5
5
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"@emotion/styled": "^10.0.27",
|
|
58
58
|
"@popperjs/core": "^2.5.4",
|
|
59
59
|
"@workday/canvas-colors-web": "^2.0.0",
|
|
60
|
-
"@workday/canvas-kit-labs-react": "^6.
|
|
61
|
-
"@workday/canvas-kit-popup-stack": "^6.
|
|
62
|
-
"@workday/canvas-kit-preview-react": "^6.
|
|
60
|
+
"@workday/canvas-kit-labs-react": "^6.3.0-next.0+6e10a940",
|
|
61
|
+
"@workday/canvas-kit-popup-stack": "^6.3.0-next.0+6e10a940",
|
|
62
|
+
"@workday/canvas-kit-preview-react": "^6.3.0-next.0+6e10a940",
|
|
63
63
|
"@workday/canvas-system-icons-web": "1.0.41",
|
|
64
64
|
"@workday/design-assets-types": "^0.2.4",
|
|
65
65
|
"chroma-js": "^2.1.0",
|
|
@@ -71,12 +71,11 @@
|
|
|
71
71
|
"resize-observer-polyfill": "^1.5.1",
|
|
72
72
|
"rtl-css-js": "^1.14.1",
|
|
73
73
|
"screenfull": "^5.2.0",
|
|
74
|
-
"use-resize-observer": "~7.0.1"
|
|
75
|
-
"uuid": "^3.3.3"
|
|
74
|
+
"use-resize-observer": "~7.0.1"
|
|
76
75
|
},
|
|
77
76
|
"devDependencies": {
|
|
78
77
|
"@workday/canvas-accent-icons-web": "^1.0.0",
|
|
79
78
|
"@workday/canvas-applet-icons-web": "^0.17.50"
|
|
80
79
|
},
|
|
81
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "6e10a940283828fb6e34b23598a917a478bbabd6"
|
|
82
81
|
}
|
package/radio/lib/Radio.tsx
CHANGED
|
@@ -28,7 +28,7 @@ export interface RadioProps extends Themeable {
|
|
|
28
28
|
disabled?: boolean;
|
|
29
29
|
/**
|
|
30
30
|
* The HTML `id` of the underlying radio input element. This is required if `label` is defined as a non-empty string.
|
|
31
|
-
* @default A uniquely generated id
|
|
31
|
+
* @default A uniquely generated id
|
|
32
32
|
*/
|
|
33
33
|
id?: string;
|
|
34
34
|
/**
|
package/switch/lib/Switch.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import uuid from 'uuid/v4';
|
|
3
2
|
import {
|
|
4
3
|
useCloseOnEscape,
|
|
5
4
|
useAlwaysCloseOnOutsideClick,
|
|
6
5
|
usePopupModel,
|
|
7
6
|
useCloseOnFullscreenExit,
|
|
8
7
|
} from '@workday/canvas-kit-react/popup';
|
|
8
|
+
import {useUniqueId} from '@workday/canvas-kit-react/common';
|
|
9
9
|
|
|
10
10
|
const useIntentTimer = (fn: Function, waitMs: number = 0): {start(): void; clear(): void} => {
|
|
11
11
|
const timer = React.useRef() as React.MutableRefObject<number | undefined>;
|
|
@@ -91,7 +91,7 @@ export function useTooltip<T extends Element = Element>({
|
|
|
91
91
|
const mouseDownRef = React.useRef(false); // use to prevent newly focused from making tooltip flash
|
|
92
92
|
const popupModel = usePopupModel();
|
|
93
93
|
const [anchorElement, setAnchorElement] = React.useState<T | null>(null);
|
|
94
|
-
const
|
|
94
|
+
const id = useUniqueId();
|
|
95
95
|
const intentTimerHide = useIntentTimer(popupModel.events.hide, hideDelay);
|
|
96
96
|
const intentTimerShow = useIntentTimer(popupModel.events.show, showDelay);
|
|
97
97
|
|
|
@@ -13,7 +13,7 @@ export interface CheckboxProps extends Themeable {
|
|
|
13
13
|
disabled?: boolean;
|
|
14
14
|
/**
|
|
15
15
|
* The HTML `id` of the underlying checkbox input element. This is required if `label` is defined as a non-empty string.
|
|
16
|
-
* @default A uniquely generated id
|
|
16
|
+
* @default A uniquely generated id
|
|
17
17
|
*/
|
|
18
18
|
id?: string;
|
|
19
19
|
/**
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a unique and HTML5 compliant identifier every time it is called. Internally it uses a 4
|
|
3
|
+
* character random seed starting with a letter. This seed is unique to each instance of this
|
|
4
|
+
* package meaning different versions of Canvas Kit on the page will have a different seed. Each
|
|
5
|
+
* call will use a Base 36 string (10 numbers + 26 letters) based on an incremented number. The
|
|
6
|
+
* incremented number always starts at 0 and can be reset for testing purposes using
|
|
7
|
+
* [resetUniqueIdCount](#resetuniqueidcount). [setUniqueSeed](#setuniqueseed) can also be used for
|
|
8
|
+
* testing or server side rendering to get the same results during hydration.
|
|
9
|
+
*/
|
|
1
10
|
export declare const generateUniqueId: () => string;
|
|
2
11
|
/**
|
|
3
12
|
* Generate a unique ID if one is not provided. The generated ID will be stable across renders
|
|
@@ -10,4 +19,23 @@ export declare const useUniqueId: (id?: string | undefined) => string;
|
|
|
10
19
|
* TODO: Remove in major release
|
|
11
20
|
*/
|
|
12
21
|
export declare const uniqueId: (id?: string | undefined) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Update the seed used by the id generator. This is useful for snapshot tests to help stabilize ids
|
|
24
|
+
* generated each run. This could also be used for server-side hydration - if you choose the same
|
|
25
|
+
* seed for server and set that on the client before components are rendered, the ids generated will
|
|
26
|
+
* be the same.
|
|
27
|
+
* @example
|
|
28
|
+
* // set in a script tag from the server
|
|
29
|
+
* setSeed(window.__ID_SEED); // set in a script tag from the server
|
|
30
|
+
*
|
|
31
|
+
* // jest setup
|
|
32
|
+
* before(() => {
|
|
33
|
+
* setSeed('a')
|
|
34
|
+
* })
|
|
35
|
+
*/
|
|
36
|
+
export declare const setUniqueSeed: (s: string) => void;
|
|
37
|
+
/**
|
|
38
|
+
* This should only be called for tests in an `beforeEach`
|
|
39
|
+
*/
|
|
40
|
+
export declare const resetUniqueIdCount: () => void;
|
|
13
41
|
//# sourceMappingURL=useUniqueId.d.ts.map
|
|
@@ -13,7 +13,7 @@ export interface RadioProps extends Themeable {
|
|
|
13
13
|
disabled?: boolean;
|
|
14
14
|
/**
|
|
15
15
|
* The HTML `id` of the underlying radio input element. This is required if `label` is defined as a non-empty string.
|
|
16
|
-
* @default A uniquely generated id
|
|
16
|
+
* @default A uniquely generated id
|
|
17
17
|
*/
|
|
18
18
|
id?: string;
|
|
19
19
|
/**
|
|
@@ -13,7 +13,7 @@ export interface CheckboxProps extends Themeable {
|
|
|
13
13
|
disabled?: boolean;
|
|
14
14
|
/**
|
|
15
15
|
* The HTML `id` of the underlying checkbox input element. This is required if `label` is defined as a non-empty string.
|
|
16
|
-
* @default A uniquely generated id
|
|
16
|
+
* @default A uniquely generated id
|
|
17
17
|
*/
|
|
18
18
|
id?: string;
|
|
19
19
|
/**
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a unique and HTML5 compliant identifier every time it is called. Internally it uses a 4
|
|
3
|
+
* character random seed starting with a letter. This seed is unique to each instance of this
|
|
4
|
+
* package meaning different versions of Canvas Kit on the page will have a different seed. Each
|
|
5
|
+
* call will use a Base 36 string (10 numbers + 26 letters) based on an incremented number. The
|
|
6
|
+
* incremented number always starts at 0 and can be reset for testing purposes using
|
|
7
|
+
* [resetUniqueIdCount](#resetuniqueidcount). [setUniqueSeed](#setuniqueseed) can also be used for
|
|
8
|
+
* testing or server side rendering to get the same results during hydration.
|
|
9
|
+
*/
|
|
1
10
|
export declare const generateUniqueId: () => string;
|
|
2
11
|
/**
|
|
3
12
|
* Generate a unique ID if one is not provided. The generated ID will be stable across renders
|
|
@@ -10,4 +19,23 @@ export declare const useUniqueId: (id?: string | undefined) => string;
|
|
|
10
19
|
* TODO: Remove in major release
|
|
11
20
|
*/
|
|
12
21
|
export declare const uniqueId: (id?: string | undefined) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Update the seed used by the id generator. This is useful for snapshot tests to help stabilize ids
|
|
24
|
+
* generated each run. This could also be used for server-side hydration - if you choose the same
|
|
25
|
+
* seed for server and set that on the client before components are rendered, the ids generated will
|
|
26
|
+
* be the same.
|
|
27
|
+
* @example
|
|
28
|
+
* // set in a script tag from the server
|
|
29
|
+
* setSeed(window.__ID_SEED); // set in a script tag from the server
|
|
30
|
+
*
|
|
31
|
+
* // jest setup
|
|
32
|
+
* before(() => {
|
|
33
|
+
* setSeed('a')
|
|
34
|
+
* })
|
|
35
|
+
*/
|
|
36
|
+
export declare const setUniqueSeed: (s: string) => void;
|
|
37
|
+
/**
|
|
38
|
+
* This should only be called for tests in an `beforeEach`
|
|
39
|
+
*/
|
|
40
|
+
export declare const resetUniqueIdCount: () => void;
|
|
13
41
|
//# sourceMappingURL=useUniqueId.d.ts.map
|
|
@@ -13,7 +13,7 @@ export interface RadioProps extends Themeable {
|
|
|
13
13
|
disabled?: boolean;
|
|
14
14
|
/**
|
|
15
15
|
* The HTML `id` of the underlying radio input element. This is required if `label` is defined as a non-empty string.
|
|
16
|
-
* @default A uniquely generated id
|
|
16
|
+
* @default A uniquely generated id
|
|
17
17
|
*/
|
|
18
18
|
id?: string;
|
|
19
19
|
/**
|