@canonical/react-components 3.9.1 → 3.11.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/dist/components/ConfirmationButton/ConfirmationButton.js +5 -5
- package/dist/components/ConfirmationModal/ConfirmationModal.d.ts +5 -1
- package/dist/components/ConfirmationModal/ConfirmationModal.js +9 -3
- package/dist/components/PrefixedInput/PrefixedInput.d.ts +13 -0
- package/dist/components/PrefixedInput/PrefixedInput.js +64 -0
- package/dist/components/PrefixedInput/PrefixedInput.scss +22 -0
- package/dist/components/PrefixedInput/PrefixedInput.stories.d.ts +11 -0
- package/dist/components/PrefixedInput/PrefixedInput.stories.js +58 -0
- package/dist/components/PrefixedInput/PrefixedInput.test.d.ts +1 -0
- package/dist/components/PrefixedInput/index.d.ts +1 -0
- package/dist/components/PrefixedInput/index.js +13 -0
- package/dist/components/PrefixedIpInput/PrefixedIpInput.d.ts +27 -0
- package/dist/components/PrefixedIpInput/PrefixedIpInput.js +65 -0
- package/dist/components/PrefixedIpInput/PrefixedIpInput.stories.d.ts +13 -0
- package/dist/components/PrefixedIpInput/PrefixedIpInput.stories.js +137 -0
- package/dist/components/PrefixedIpInput/PrefixedIpInput.test.d.ts +1 -0
- package/dist/components/PrefixedIpInput/index.d.ts +2 -0
- package/dist/components/PrefixedIpInput/index.js +56 -0
- package/dist/components/PrefixedIpInput/utils.d.ts +39 -0
- package/dist/components/PrefixedIpInput/utils.js +125 -0
- package/dist/components/PrefixedIpInput/utils.test.d.ts +1 -0
- package/dist/esm/components/ConfirmationButton/ConfirmationButton.js +5 -5
- package/dist/esm/components/ConfirmationModal/ConfirmationModal.d.ts +5 -1
- package/dist/esm/components/ConfirmationModal/ConfirmationModal.js +9 -3
- package/dist/esm/components/PrefixedInput/PrefixedInput.d.ts +13 -0
- package/dist/esm/components/PrefixedInput/PrefixedInput.js +57 -0
- package/dist/esm/components/PrefixedInput/PrefixedInput.scss +22 -0
- package/dist/esm/components/PrefixedInput/PrefixedInput.stories.d.ts +11 -0
- package/dist/esm/components/PrefixedInput/PrefixedInput.stories.js +51 -0
- package/dist/esm/components/PrefixedInput/PrefixedInput.test.d.ts +1 -0
- package/dist/esm/components/PrefixedInput/index.d.ts +1 -0
- package/dist/esm/components/PrefixedInput/index.js +1 -0
- package/dist/esm/components/PrefixedIpInput/PrefixedIpInput.d.ts +27 -0
- package/dist/esm/components/PrefixedIpInput/PrefixedIpInput.js +58 -0
- package/dist/esm/components/PrefixedIpInput/PrefixedIpInput.stories.d.ts +13 -0
- package/dist/esm/components/PrefixedIpInput/PrefixedIpInput.stories.js +128 -0
- package/dist/esm/components/PrefixedIpInput/PrefixedIpInput.test.d.ts +1 -0
- package/dist/esm/components/PrefixedIpInput/index.d.ts +2 -0
- package/dist/esm/components/PrefixedIpInput/index.js +2 -0
- package/dist/esm/components/PrefixedIpInput/utils.d.ts +39 -0
- package/dist/esm/components/PrefixedIpInput/utils.js +112 -0
- package/dist/esm/components/PrefixedIpInput/utils.test.d.ts +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +65 -0
- package/package.json +1 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given IP address is a valid IPv4 address.
|
|
3
|
+
* @param ip The IP address to check
|
|
4
|
+
* @returns True if the IP is a valid IPv4 address, false otherwise
|
|
5
|
+
*/
|
|
6
|
+
export declare const isIPv4: (ip: string) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Takes a subnet CIDR notation (IPv4) and returns the first and last IP of the subnet.
|
|
9
|
+
* The network and host addresses are excluded.
|
|
10
|
+
*
|
|
11
|
+
* @param cidr The CIDR notation of the subnet
|
|
12
|
+
* @returns The first and last valid IP addresses as two strings in a list.
|
|
13
|
+
*/
|
|
14
|
+
export declare const getIpRangeFromCidr: (cidr: string) => string[];
|
|
15
|
+
export declare const getFirstValidIp: (ip: string) => string;
|
|
16
|
+
export declare const convertIpToUint32: (ip: string) => number;
|
|
17
|
+
/**
|
|
18
|
+
* Checks if an IPv4 address is valid for the given subnet.
|
|
19
|
+
*
|
|
20
|
+
* @param ip The IPv4 address to check, as a string
|
|
21
|
+
* @param cidr The subnet's CIDR notation e.g. 192.168.0.0/24
|
|
22
|
+
* @returns True if the IP is in the subnet, false otherwise
|
|
23
|
+
*/
|
|
24
|
+
export declare const isIpInSubnet: (ip: string, cidr: string) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Separates the immutable and editable octets of an IPv4 subnet range.
|
|
27
|
+
*
|
|
28
|
+
* @param startIp The start IP of the subnet
|
|
29
|
+
* @param endIp The end IP of the subnet
|
|
30
|
+
* @returns The immutable and editable octects as two strings in a list
|
|
31
|
+
*/
|
|
32
|
+
export declare const getImmutableAndEditableOctets: (startIp: string, endIp: string) => string[];
|
|
33
|
+
/**
|
|
34
|
+
* Get the immutable and editable parts of an IPv4 or IPv6 subnet.
|
|
35
|
+
*
|
|
36
|
+
* @param cidr The CIDR notation of the subnet
|
|
37
|
+
* @returns The immutable and editable as two strings in a list
|
|
38
|
+
*/
|
|
39
|
+
export declare const getImmutableAndEditable: (cidr: string) => string[];
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given IP address is a valid IPv4 address.
|
|
3
|
+
* @param ip The IP address to check
|
|
4
|
+
* @returns True if the IP is a valid IPv4 address, false otherwise
|
|
5
|
+
*/
|
|
6
|
+
export var isIPv4 = ip => {
|
|
7
|
+
var ipv4Regex = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/;
|
|
8
|
+
return ipv4Regex.test(ip);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Takes a subnet CIDR notation (IPv4) and returns the first and last IP of the subnet.
|
|
13
|
+
* The network and host addresses are excluded.
|
|
14
|
+
*
|
|
15
|
+
* @param cidr The CIDR notation of the subnet
|
|
16
|
+
* @returns The first and last valid IP addresses as two strings in a list.
|
|
17
|
+
*/
|
|
18
|
+
export var getIpRangeFromCidr = cidr => {
|
|
19
|
+
// https://gist.github.com/binarymax/6114792
|
|
20
|
+
|
|
21
|
+
// Get start IP and number of valid addresses
|
|
22
|
+
var [startIp, mask] = cidr.split("/");
|
|
23
|
+
var numberOfAddresses = (1 << 32 - parseInt(mask)) - 1;
|
|
24
|
+
|
|
25
|
+
// IPv4 can be represented by an unsigned 32-bit integer, so we can use a Uint32Array to store the IP
|
|
26
|
+
var buffer = new ArrayBuffer(4); //4 octets
|
|
27
|
+
var int32 = new Uint32Array(buffer);
|
|
28
|
+
|
|
29
|
+
// Convert starting IP to Uint32 and add the number of addresses to get the end IP.
|
|
30
|
+
// Subtract 1 from the number of addresses to exclude the broadcast address.
|
|
31
|
+
int32[0] = convertIpToUint32(startIp) + numberOfAddresses - 1;
|
|
32
|
+
|
|
33
|
+
// Convert the buffer to a Uint8Array to get the octets, then convert it to an array
|
|
34
|
+
var arrayApplyBuffer = Array.from(new Uint8Array(buffer));
|
|
35
|
+
|
|
36
|
+
// Reverse the octets and join them with "." to get the end IP
|
|
37
|
+
var endIp = arrayApplyBuffer.reverse().join(".");
|
|
38
|
+
var firstValidIp = getFirstValidIp(startIp);
|
|
39
|
+
return [firstValidIp, endIp];
|
|
40
|
+
};
|
|
41
|
+
export var getFirstValidIp = ip => {
|
|
42
|
+
var buffer = new ArrayBuffer(4); //4 octets
|
|
43
|
+
var int32 = new Uint32Array(buffer);
|
|
44
|
+
|
|
45
|
+
// add 1 because the first IP is the network address
|
|
46
|
+
int32[0] = convertIpToUint32(ip) + 1;
|
|
47
|
+
var arrayApplyBuffer = Array.from(new Uint8Array(buffer));
|
|
48
|
+
return arrayApplyBuffer.reverse().join(".");
|
|
49
|
+
};
|
|
50
|
+
export var convertIpToUint32 = ip => {
|
|
51
|
+
var octets = ip.split(".").map(a => parseInt(a));
|
|
52
|
+
var buffer = new ArrayBuffer(4);
|
|
53
|
+
var int32 = new Uint32Array(buffer);
|
|
54
|
+
int32[0] = (octets[0] << 24) + (octets[1] << 16) + (octets[2] << 8) + octets[3];
|
|
55
|
+
return int32[0];
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Checks if an IPv4 address is valid for the given subnet.
|
|
60
|
+
*
|
|
61
|
+
* @param ip The IPv4 address to check, as a string
|
|
62
|
+
* @param cidr The subnet's CIDR notation e.g. 192.168.0.0/24
|
|
63
|
+
* @returns True if the IP is in the subnet, false otherwise
|
|
64
|
+
*/
|
|
65
|
+
export var isIpInSubnet = (ip, cidr) => {
|
|
66
|
+
var [startIP, endIP] = getIpRangeFromCidr(cidr);
|
|
67
|
+
var ipUint32 = convertIpToUint32(ip);
|
|
68
|
+
var startIPUint32 = convertIpToUint32(startIP);
|
|
69
|
+
var endIPUint32 = convertIpToUint32(endIP);
|
|
70
|
+
return ipUint32 >= startIPUint32 && ipUint32 <= endIPUint32;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Separates the immutable and editable octets of an IPv4 subnet range.
|
|
75
|
+
*
|
|
76
|
+
* @param startIp The start IP of the subnet
|
|
77
|
+
* @param endIp The end IP of the subnet
|
|
78
|
+
* @returns The immutable and editable octects as two strings in a list
|
|
79
|
+
*/
|
|
80
|
+
export var getImmutableAndEditableOctets = (startIp, endIp) => {
|
|
81
|
+
var startIpOctetList = startIp.split(".");
|
|
82
|
+
var endIpOctetList = endIp.split(".");
|
|
83
|
+
var immutable = [];
|
|
84
|
+
var editable = [];
|
|
85
|
+
startIpOctetList.forEach((octet, index) => {
|
|
86
|
+
if (octet === endIpOctetList[index]) {
|
|
87
|
+
immutable.push(octet);
|
|
88
|
+
} else {
|
|
89
|
+
editable.push("[".concat(octet, "-").concat(endIpOctetList[index], "]"));
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return [immutable.join("."), editable.join(".")];
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Get the immutable and editable parts of an IPv4 or IPv6 subnet.
|
|
97
|
+
*
|
|
98
|
+
* @param cidr The CIDR notation of the subnet
|
|
99
|
+
* @returns The immutable and editable as two strings in a list
|
|
100
|
+
*/
|
|
101
|
+
export var getImmutableAndEditable = cidr => {
|
|
102
|
+
var isIPV4 = isIPv4(cidr.split("/")[0]);
|
|
103
|
+
if (isIPV4) {
|
|
104
|
+
var [startIp, endIp] = getIpRangeFromCidr(cidr);
|
|
105
|
+
return getImmutableAndEditableOctets(startIp, endIp);
|
|
106
|
+
}
|
|
107
|
+
var [networkAddress] = cidr.split("/");
|
|
108
|
+
var immutableIPV6 = networkAddress.substring(0, networkAddress.lastIndexOf(":"));
|
|
109
|
+
var ipv6PlaceholderColons = 7 - (immutableIPV6.match(/:/g) || []).length; // 7 is the maximum number of colons in an IPv6 address
|
|
110
|
+
var editableIPV6 = "".concat("0000:".repeat(ipv6PlaceholderColons), "0000");
|
|
111
|
+
return [immutableIPV6, editableIPV6];
|
|
112
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -43,6 +43,8 @@ export { default as LoginPageLayout } from "./components/LoginPageLayout";
|
|
|
43
43
|
export { default as Pagination } from "./components/Pagination";
|
|
44
44
|
export { default as Panel } from "./components/Panel";
|
|
45
45
|
export { default as PasswordToggle } from "./components/PasswordToggle";
|
|
46
|
+
export { default as PrefixedInput } from "./components/PrefixedInput";
|
|
47
|
+
export { default as PrefixedIpInput, isIPv4, getIpRangeFromCidr, getFirstValidIp, convertIpToUint32, isIpInSubnet, getImmutableAndEditableOctets, getImmutableAndEditable, } from "./components/PrefixedIpInput";
|
|
46
48
|
export { default as RadioInput } from "./components/RadioInput";
|
|
47
49
|
export { default as Row } from "./components/Row";
|
|
48
50
|
export { default as ScrollableContainer } from "./components/ScrollableContainer";
|
|
@@ -118,6 +120,8 @@ export type { NotificationAction, NotificationType, QueuedNotification, Notifica
|
|
|
118
120
|
export type { LoginPageLayoutProps } from "./components/LoginPageLayout";
|
|
119
121
|
export type { PaginationProps } from "./components/Pagination";
|
|
120
122
|
export type { PanelProps } from "./components/Panel";
|
|
123
|
+
export type { PrefixedInputProps } from "./components/PrefixedInput";
|
|
124
|
+
export type { PrefixedIpInputProps } from "./components/PrefixedIpInput";
|
|
121
125
|
export type { RadioInputProps } from "./components/RadioInput";
|
|
122
126
|
export type { RowProps } from "./components/Row";
|
|
123
127
|
export type { ScrollableTableProps } from "./components/ScrollableTable";
|
package/dist/esm/index.js
CHANGED
|
@@ -43,6 +43,8 @@ export { default as LoginPageLayout } from "./components/LoginPageLayout";
|
|
|
43
43
|
export { default as Pagination } from "./components/Pagination";
|
|
44
44
|
export { default as Panel } from "./components/Panel";
|
|
45
45
|
export { default as PasswordToggle } from "./components/PasswordToggle";
|
|
46
|
+
export { default as PrefixedInput } from "./components/PrefixedInput";
|
|
47
|
+
export { default as PrefixedIpInput, isIPv4, getIpRangeFromCidr, getFirstValidIp, convertIpToUint32, isIpInSubnet, getImmutableAndEditableOctets, getImmutableAndEditable } from "./components/PrefixedIpInput";
|
|
46
48
|
export { default as RadioInput } from "./components/RadioInput";
|
|
47
49
|
export { default as Row } from "./components/Row";
|
|
48
50
|
export { default as ScrollableContainer } from "./components/ScrollableContainer";
|
package/dist/index.d.ts
CHANGED
|
@@ -43,6 +43,8 @@ export { default as LoginPageLayout } from "./components/LoginPageLayout";
|
|
|
43
43
|
export { default as Pagination } from "./components/Pagination";
|
|
44
44
|
export { default as Panel } from "./components/Panel";
|
|
45
45
|
export { default as PasswordToggle } from "./components/PasswordToggle";
|
|
46
|
+
export { default as PrefixedInput } from "./components/PrefixedInput";
|
|
47
|
+
export { default as PrefixedIpInput, isIPv4, getIpRangeFromCidr, getFirstValidIp, convertIpToUint32, isIpInSubnet, getImmutableAndEditableOctets, getImmutableAndEditable, } from "./components/PrefixedIpInput";
|
|
46
48
|
export { default as RadioInput } from "./components/RadioInput";
|
|
47
49
|
export { default as Row } from "./components/Row";
|
|
48
50
|
export { default as ScrollableContainer } from "./components/ScrollableContainer";
|
|
@@ -118,6 +120,8 @@ export type { NotificationAction, NotificationType, QueuedNotification, Notifica
|
|
|
118
120
|
export type { LoginPageLayoutProps } from "./components/LoginPageLayout";
|
|
119
121
|
export type { PaginationProps } from "./components/Pagination";
|
|
120
122
|
export type { PanelProps } from "./components/Panel";
|
|
123
|
+
export type { PrefixedInputProps } from "./components/PrefixedInput";
|
|
124
|
+
export type { PrefixedIpInputProps } from "./components/PrefixedIpInput";
|
|
121
125
|
export type { RadioInputProps } from "./components/RadioInput";
|
|
122
126
|
export type { RowProps } from "./components/Row";
|
|
123
127
|
export type { ScrollableTableProps } from "./components/ScrollableTable";
|
package/dist/index.js
CHANGED
|
@@ -64,6 +64,15 @@ var _exportNames = {
|
|
|
64
64
|
Pagination: true,
|
|
65
65
|
Panel: true,
|
|
66
66
|
PasswordToggle: true,
|
|
67
|
+
PrefixedInput: true,
|
|
68
|
+
PrefixedIpInput: true,
|
|
69
|
+
isIPv4: true,
|
|
70
|
+
getIpRangeFromCidr: true,
|
|
71
|
+
getFirstValidIp: true,
|
|
72
|
+
convertIpToUint32: true,
|
|
73
|
+
isIpInSubnet: true,
|
|
74
|
+
getImmutableAndEditableOctets: true,
|
|
75
|
+
getImmutableAndEditable: true,
|
|
67
76
|
RadioInput: true,
|
|
68
77
|
Row: true,
|
|
69
78
|
ScrollableContainer: true,
|
|
@@ -419,6 +428,18 @@ Object.defineProperty(exports, "PasswordToggle", {
|
|
|
419
428
|
return _PasswordToggle.default;
|
|
420
429
|
}
|
|
421
430
|
});
|
|
431
|
+
Object.defineProperty(exports, "PrefixedInput", {
|
|
432
|
+
enumerable: true,
|
|
433
|
+
get: function () {
|
|
434
|
+
return _PrefixedInput.default;
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
Object.defineProperty(exports, "PrefixedIpInput", {
|
|
438
|
+
enumerable: true,
|
|
439
|
+
get: function () {
|
|
440
|
+
return _PrefixedIpInput.default;
|
|
441
|
+
}
|
|
442
|
+
});
|
|
422
443
|
Object.defineProperty(exports, "RadioInput", {
|
|
423
444
|
enumerable: true,
|
|
424
445
|
get: function () {
|
|
@@ -641,6 +662,12 @@ Object.defineProperty(exports, "applyTheme", {
|
|
|
641
662
|
return _ThemeSwitcher.applyTheme;
|
|
642
663
|
}
|
|
643
664
|
});
|
|
665
|
+
Object.defineProperty(exports, "convertIpToUint32", {
|
|
666
|
+
enumerable: true,
|
|
667
|
+
get: function () {
|
|
668
|
+
return _PrefixedIpInput.convertIpToUint32;
|
|
669
|
+
}
|
|
670
|
+
});
|
|
644
671
|
Object.defineProperty(exports, "createEventQueue", {
|
|
645
672
|
enumerable: true,
|
|
646
673
|
get: function () {
|
|
@@ -665,6 +692,30 @@ Object.defineProperty(exports, "getElementAbsoluteHeight", {
|
|
|
665
692
|
return _utils.getElementAbsoluteHeight;
|
|
666
693
|
}
|
|
667
694
|
});
|
|
695
|
+
Object.defineProperty(exports, "getFirstValidIp", {
|
|
696
|
+
enumerable: true,
|
|
697
|
+
get: function () {
|
|
698
|
+
return _PrefixedIpInput.getFirstValidIp;
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
Object.defineProperty(exports, "getImmutableAndEditable", {
|
|
702
|
+
enumerable: true,
|
|
703
|
+
get: function () {
|
|
704
|
+
return _PrefixedIpInput.getImmutableAndEditable;
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
Object.defineProperty(exports, "getImmutableAndEditableOctets", {
|
|
708
|
+
enumerable: true,
|
|
709
|
+
get: function () {
|
|
710
|
+
return _PrefixedIpInput.getImmutableAndEditableOctets;
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
Object.defineProperty(exports, "getIpRangeFromCidr", {
|
|
714
|
+
enumerable: true,
|
|
715
|
+
get: function () {
|
|
716
|
+
return _PrefixedIpInput.getIpRangeFromCidr;
|
|
717
|
+
}
|
|
718
|
+
});
|
|
668
719
|
Object.defineProperty(exports, "getParentsBottomSpacing", {
|
|
669
720
|
enumerable: true,
|
|
670
721
|
get: function () {
|
|
@@ -683,6 +734,18 @@ Object.defineProperty(exports, "isDarkTheme", {
|
|
|
683
734
|
return _ThemeSwitcher.isDarkTheme;
|
|
684
735
|
}
|
|
685
736
|
});
|
|
737
|
+
Object.defineProperty(exports, "isIPv4", {
|
|
738
|
+
enumerable: true,
|
|
739
|
+
get: function () {
|
|
740
|
+
return _PrefixedIpInput.isIPv4;
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
Object.defineProperty(exports, "isIpInSubnet", {
|
|
744
|
+
enumerable: true,
|
|
745
|
+
get: function () {
|
|
746
|
+
return _PrefixedIpInput.isIpInSubnet;
|
|
747
|
+
}
|
|
748
|
+
});
|
|
686
749
|
Object.defineProperty(exports, "isNavigationAnchor", {
|
|
687
750
|
enumerable: true,
|
|
688
751
|
get: function () {
|
|
@@ -859,6 +922,8 @@ var _LoginPageLayout = _interopRequireDefault(require("./components/LoginPageLay
|
|
|
859
922
|
var _Pagination = _interopRequireDefault(require("./components/Pagination"));
|
|
860
923
|
var _Panel = _interopRequireDefault(require("./components/Panel"));
|
|
861
924
|
var _PasswordToggle = _interopRequireDefault(require("./components/PasswordToggle"));
|
|
925
|
+
var _PrefixedInput = _interopRequireDefault(require("./components/PrefixedInput"));
|
|
926
|
+
var _PrefixedIpInput = _interopRequireWildcard(require("./components/PrefixedIpInput"));
|
|
862
927
|
var _RadioInput = _interopRequireDefault(require("./components/RadioInput"));
|
|
863
928
|
var _Row = _interopRequireDefault(require("./components/Row"));
|
|
864
929
|
var _ScrollableContainer = _interopRequireDefault(require("./components/ScrollableContainer"));
|