1 | var __extends = (this && this.__extends) || (function () {
|
2 | var extendStatics = function (d, b) {
|
3 | extendStatics = Object.setPrototypeOf ||
|
4 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
6 | return extendStatics(d, b);
|
7 | };
|
8 | return function (d, b) {
|
9 | if (typeof b !== "function" && b !== null)
|
10 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
11 | extendStatics(d, b);
|
12 | function __() { this.constructor = d; }
|
13 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
14 | };
|
15 | })();
|
16 | import * as React from 'react';
|
17 | import { counter, getId, getPrefix } from './context';
|
18 |
|
19 | var prefixId = function (id, prefix, name) {
|
20 | var uid = prefix + id;
|
21 | return String(name ? name(uid) : uid);
|
22 | };
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | var UID = (function (_super) {
|
39 | __extends(UID, _super);
|
40 | function UID() {
|
41 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
42 | _this.state = {
|
43 | quartz: _this.props.idSource || counter,
|
44 | prefix: getPrefix(_this.props.idSource),
|
45 | id: getId(_this.props.idSource || counter),
|
46 | };
|
47 | _this.uid = function (item) {
|
48 | return prefixId(_this.state.id + '-' + _this.state.quartz.uid(item), _this.state.prefix, _this.props.name);
|
49 | };
|
50 | return _this;
|
51 | }
|
52 | UID.prototype.render = function () {
|
53 | var _a = this.props, children = _a.children, name = _a.name;
|
54 | var _b = this.state, id = _b.id, prefix = _b.prefix;
|
55 | return children(prefixId(id, prefix, name), this.uid);
|
56 | };
|
57 | return UID;
|
58 | }(React.Component));
|
59 | export { UID };
|