@canonical/react-components 3.9.0 → 3.10.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/Accordion/Accordion.js +15 -11
- package/dist/components/ActionButton/ActionButton.js +13 -10
- package/dist/components/ApplicationLayout/AppAside/AppAside.js +12 -9
- package/dist/components/ApplicationLayout/AppMain/AppMain.js +7 -4
- package/dist/components/ApplicationLayout/AppNavigation/AppNavigation.js +9 -6
- package/dist/components/ApplicationLayout/AppNavigationBar/AppNavigationBar.js +7 -4
- package/dist/components/ApplicationLayout/AppStatus/AppStatus.js +7 -4
- package/dist/components/ApplicationLayout/Application/Application.js +7 -4
- package/dist/components/ApplicationLayout/ApplicationLayout.js +22 -19
- package/dist/components/ArticlePagination/ArticlePagination.js +10 -7
- package/dist/components/Badge/Badge.js +9 -6
- package/dist/components/Button/Button.js +15 -12
- package/dist/components/Card/Card.js +11 -8
- package/dist/components/Card/Card.stories.d.ts +5 -0
- package/dist/components/Card/Card.stories.js +13 -4
- package/dist/components/CheckboxInput/CheckableInput/CheckableInput.js +10 -7
- package/dist/components/CheckboxInput/CheckboxInput.js +7 -4
- package/dist/components/Chip/Chip.js +18 -15
- package/dist/components/Code/Code.js +10 -7
- package/dist/components/CodeSnippet/CodeSnippet.js +7 -4
- package/dist/components/CodeSnippet/CodeSnippetDropdown.js +12 -8
- package/dist/components/Col/Col.js +15 -12
- package/dist/components/ColumnSelector/columnSelectorHelper.js +7 -3
- package/dist/components/ConfirmationButton/ConfirmationButton.js +10 -7
- package/dist/components/ConfirmationModal/ConfirmationModal.js +15 -12
- package/dist/components/ContextualMenu/ContextualMenu.js +27 -24
- package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.js +47 -44
- package/dist/components/CustomSelect/CustomSelect.js +25 -22
- package/dist/components/CustomSelect/CustomSelect.stories.js +8 -5
- package/dist/components/EmptyState/EmptyState.js +9 -6
- package/dist/components/Field/Field.js +22 -19
- package/dist/components/Form/Form.js +9 -6
- package/dist/components/FormikField/FormikField.js +10 -7
- package/dist/components/Icon/Icon.js +8 -5
- package/dist/components/Input/Input.js +28 -21
- package/dist/components/Label/Label.js +9 -6
- package/dist/components/Link/Link.js +11 -8
- package/dist/components/List/List.js +28 -19
- package/dist/components/MainTable/MainTable.js +34 -28
- package/dist/components/Modal/Modal.js +13 -10
- package/dist/components/ModularTable/ModularTable.js +25 -21
- package/dist/components/MultiSelect/MultiSelect.js +17 -14
- package/dist/components/MultiSelect/MultiSelect.stories.js +14 -14
- package/dist/components/Navigation/Navigation.js +31 -23
- package/dist/components/Navigation/NavigationLink/NavigationLink.js +26 -17
- package/dist/components/Navigation/NavigationMenu/NavigationMenu.js +16 -9
- package/dist/components/Notifications/Notification/Notification.js +19 -16
- package/dist/components/Notifications/ToastNotification/ToastNotificationProvider.js +15 -15
- package/dist/components/Pagination/Pagination.js +20 -17
- package/dist/components/Panel/Panel.js +29 -25
- package/dist/components/PasswordToggle/PasswordToggle.js +16 -13
- 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/components/RadioInput/RadioInput.js +6 -3
- package/dist/components/Row/Row.js +7 -4
- package/dist/components/ScrollableTable/ScrollableTable.stories.js +7 -3
- package/dist/components/SearchAndFilter/SearchAndFilter.js +10 -7
- package/dist/components/SearchBox/SearchBox.js +18 -15
- package/dist/components/Select/Select.js +25 -21
- package/dist/components/SideNavigation/SideNavigation.js +19 -13
- package/dist/components/SideNavigation/SideNavigationBase/SideNavigationBase.js +11 -8
- package/dist/components/SideNavigation/SideNavigationItem/SideNavigationItem.js +12 -6
- package/dist/components/SideNavigation/SideNavigationLink/SideNavigationLink.js +7 -4
- package/dist/components/SideNavigation/SideNavigationText/SideNavigationText.js +7 -4
- package/dist/components/Slider/Slider.js +17 -14
- package/dist/components/Spinner/Spinner.js +11 -8
- package/dist/components/StatusLabel/StatusLabel.js +8 -5
- package/dist/components/Stepper/Step/Step.js +15 -12
- package/dist/components/Strip/Strip.js +18 -15
- package/dist/components/Strip/Strip.stories.js +6 -1
- package/dist/components/Switch/Switch.js +9 -6
- package/dist/components/Table/Table.js +9 -6
- package/dist/components/TableCell/TableCell.js +11 -8
- package/dist/components/TableHeader/TableHeader.js +7 -4
- package/dist/components/TablePagination/TablePagination.js +14 -11
- package/dist/components/TablePagination/TablePaginationControls/TablePaginationControls.js +22 -19
- package/dist/components/TableRow/TableRow.js +6 -3
- package/dist/components/Tabs/Tabs.js +10 -7
- package/dist/components/Textarea/Textarea.js +29 -22
- package/dist/esm/components/Card/Card.stories.d.ts +5 -0
- package/dist/esm/components/Card/Card.stories.js +6 -1
- 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/components/Strip/Strip.stories.js +6 -1
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +2 -0
- package/dist/external/useSSR.js +6 -4
- package/dist/index.d.ts +4 -0
- package/dist/index.js +65 -0
- package/package.json +50 -47
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ReactElement } from "react";
|
|
2
|
+
import { type PrefixedInputProps } from "../PrefixedInput";
|
|
3
|
+
import { PropsWithSpread } from "../../types";
|
|
4
|
+
export type PrefixedIpInputProps = PropsWithSpread<{
|
|
5
|
+
/**
|
|
6
|
+
* The CIDR for the subnet (e.g., "192.168.1.0/24" or "2001:db8::/32").
|
|
7
|
+
* Used to calculate the immutable prefix and available IP range.
|
|
8
|
+
*/
|
|
9
|
+
cidr: string;
|
|
10
|
+
/**
|
|
11
|
+
* The full IP address value (if available).
|
|
12
|
+
* For IPv4: e.g., "192.168.1.100"
|
|
13
|
+
* For IPv6: e.g., "2001:db8::1"
|
|
14
|
+
*/
|
|
15
|
+
ip: string;
|
|
16
|
+
/**
|
|
17
|
+
* The name attribute for the input field.
|
|
18
|
+
*/
|
|
19
|
+
name: string;
|
|
20
|
+
/**
|
|
21
|
+
* Callback function that is called when the IP address changes.
|
|
22
|
+
* Receives the full IP address as a string parameter.
|
|
23
|
+
*/
|
|
24
|
+
onIpChange: (ip: string) => void;
|
|
25
|
+
}, Omit<PrefixedInputProps, "immutableText" | "maxLength" | "placeholder" | "name">>;
|
|
26
|
+
declare const PrefixedIpInput: ({ cidr, help, onIpChange, ip, name, ...props }: PrefixedIpInputProps) => ReactElement;
|
|
27
|
+
export default PrefixedIpInput;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var _excluded = ["cidr", "help", "onIpChange", "ip", "name"];
|
|
2
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
5
|
+
import React from "react";
|
|
6
|
+
import PrefixedInput from "../PrefixedInput";
|
|
7
|
+
import { getImmutableAndEditable, isIPv4 } from "./utils";
|
|
8
|
+
var PrefixedIpInput = _ref => {
|
|
9
|
+
var {
|
|
10
|
+
cidr,
|
|
11
|
+
help,
|
|
12
|
+
onIpChange,
|
|
13
|
+
ip,
|
|
14
|
+
name
|
|
15
|
+
} = _ref,
|
|
16
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
17
|
+
var [networkAddress] = cidr.split("/");
|
|
18
|
+
var isIPV4 = isIPv4(networkAddress);
|
|
19
|
+
var [immutable, editable] = getImmutableAndEditable(cidr);
|
|
20
|
+
var inputValue = isIPV4 ? ip.split(".").slice(immutable.split(".").length).join(".") : ip.replace(immutable, "");
|
|
21
|
+
var getIPv4MaxLength = () => {
|
|
22
|
+
var immutableOctetsLength = immutable.split(".").length;
|
|
23
|
+
var lengths = [15, 11, 7, 3]; // Corresponding to 0-3 immutable octets
|
|
24
|
+
return lengths[immutableOctetsLength];
|
|
25
|
+
};
|
|
26
|
+
var maxLength = isIPV4 ? getIPv4MaxLength() : editable.length;
|
|
27
|
+
var placeholder = props.disabled ? "" : editable;
|
|
28
|
+
var setIp = editableValue => {
|
|
29
|
+
var fullIp = editableValue ? isIPV4 ? "".concat(immutable, ".").concat(editableValue) : "".concat(immutable).concat(editableValue) : "";
|
|
30
|
+
onIpChange(fullIp);
|
|
31
|
+
};
|
|
32
|
+
var handlePaste = e => {
|
|
33
|
+
e.preventDefault();
|
|
34
|
+
var pastedText = e.clipboardData.getData("text");
|
|
35
|
+
if (isIPV4) {
|
|
36
|
+
var octets = pastedText.split(".");
|
|
37
|
+
var trimmed = octets.slice(0 - editable.split(".").length);
|
|
38
|
+
var _ip = trimmed.join(".");
|
|
39
|
+
setIp(_ip);
|
|
40
|
+
} else {
|
|
41
|
+
var _ip2 = pastedText.replace(immutable, "");
|
|
42
|
+
setIp(_ip2);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return /*#__PURE__*/React.createElement(PrefixedInput, _extends({
|
|
46
|
+
help: help ? help : /*#__PURE__*/React.createElement(React.Fragment, null, " ", isIPV4 ? /*#__PURE__*/React.createElement(React.Fragment, null, " ", "The available range in this subnet is", " ", /*#__PURE__*/React.createElement("code", null, immutable, ".", editable, " ")) : /*#__PURE__*/React.createElement(React.Fragment, null, " ", "The available IPV6 address range is", " ", /*#__PURE__*/React.createElement("code", null, immutable, editable, " ")), "."),
|
|
47
|
+
immutableText: isIPV4 ? "".concat(immutable, ".") : immutable,
|
|
48
|
+
maxLength: maxLength,
|
|
49
|
+
name: name,
|
|
50
|
+
onPaste: handlePaste,
|
|
51
|
+
value: inputValue,
|
|
52
|
+
onChange: e => {
|
|
53
|
+
setIp(e.target.value);
|
|
54
|
+
},
|
|
55
|
+
placeholder: placeholder
|
|
56
|
+
}, props));
|
|
57
|
+
};
|
|
58
|
+
export default PrefixedIpInput;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import PrefixedIpInput from "./PrefixedIpInput";
|
|
3
|
+
declare const meta: Meta<typeof PrefixedIpInput>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof PrefixedIpInput>;
|
|
6
|
+
export declare const IPv4Default: Story;
|
|
7
|
+
export declare const IPv4WithValue: Story;
|
|
8
|
+
export declare const IPv4WithError: Story;
|
|
9
|
+
export declare const IPv4Disabled: Story;
|
|
10
|
+
export declare const IPv6Default: Story;
|
|
11
|
+
export declare const IPv6WithValue: Story;
|
|
12
|
+
export declare const WithCustomHelp: Story;
|
|
13
|
+
export declare const Required: Story;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
import React, { useState } from "react";
|
|
3
|
+
import PrefixedIpInput from "./PrefixedIpInput";
|
|
4
|
+
var PrefixedIpInputWrapper = args => {
|
|
5
|
+
var [ip, setIp] = useState(args.ip);
|
|
6
|
+
return /*#__PURE__*/React.createElement(PrefixedIpInput, _extends({}, args, {
|
|
7
|
+
ip: ip,
|
|
8
|
+
onIpChange: newIp => {
|
|
9
|
+
var _args$onIpChange;
|
|
10
|
+
setIp(newIp);
|
|
11
|
+
(_args$onIpChange = args.onIpChange) === null || _args$onIpChange === void 0 || _args$onIpChange.call(args, newIp);
|
|
12
|
+
}
|
|
13
|
+
}));
|
|
14
|
+
};
|
|
15
|
+
var meta = {
|
|
16
|
+
component: PrefixedIpInput,
|
|
17
|
+
tags: ["autodocs"],
|
|
18
|
+
argTypes: {
|
|
19
|
+
ip: {
|
|
20
|
+
control: "text"
|
|
21
|
+
},
|
|
22
|
+
cidr: {
|
|
23
|
+
control: "text"
|
|
24
|
+
},
|
|
25
|
+
label: {
|
|
26
|
+
control: "text"
|
|
27
|
+
},
|
|
28
|
+
name: {
|
|
29
|
+
control: "text"
|
|
30
|
+
},
|
|
31
|
+
error: {
|
|
32
|
+
control: "text"
|
|
33
|
+
},
|
|
34
|
+
help: {
|
|
35
|
+
control: "text"
|
|
36
|
+
},
|
|
37
|
+
disabled: {
|
|
38
|
+
control: "boolean"
|
|
39
|
+
},
|
|
40
|
+
required: {
|
|
41
|
+
control: "boolean"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
render: args => /*#__PURE__*/React.createElement(PrefixedIpInputWrapper, args)
|
|
45
|
+
};
|
|
46
|
+
export default meta;
|
|
47
|
+
export var IPv4Default = {
|
|
48
|
+
name: "IPv4 default",
|
|
49
|
+
args: {
|
|
50
|
+
cidr: "192.168.1.0/24",
|
|
51
|
+
ip: "",
|
|
52
|
+
name: "ip-address",
|
|
53
|
+
label: "IP Address",
|
|
54
|
+
onIpChange: ip => console.log("IP changed:", ip)
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
export var IPv4WithValue = {
|
|
58
|
+
name: "IPv4 with value",
|
|
59
|
+
args: {
|
|
60
|
+
cidr: "192.168.1.0/24",
|
|
61
|
+
ip: "192.168.1.100",
|
|
62
|
+
name: "ip-address",
|
|
63
|
+
label: "IP Address",
|
|
64
|
+
onIpChange: ip => console.log("IP changed:", ip)
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
export var IPv4WithError = {
|
|
68
|
+
name: "IPv4 with error",
|
|
69
|
+
args: {
|
|
70
|
+
cidr: "192.168.1.0/24",
|
|
71
|
+
ip: "192.168.1.256",
|
|
72
|
+
name: "ip-address",
|
|
73
|
+
label: "IP Address",
|
|
74
|
+
error: "Invalid IP address",
|
|
75
|
+
onIpChange: ip => console.log("IP changed:", ip)
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
export var IPv4Disabled = {
|
|
79
|
+
name: "IPv4 disabled",
|
|
80
|
+
args: {
|
|
81
|
+
cidr: "192.168.1.0/24",
|
|
82
|
+
ip: "192.168.1.50",
|
|
83
|
+
name: "ip-address",
|
|
84
|
+
label: "IP Address",
|
|
85
|
+
disabled: true,
|
|
86
|
+
onIpChange: ip => console.log("IP changed:", ip)
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
export var IPv6Default = {
|
|
90
|
+
name: "IPv6 default",
|
|
91
|
+
args: {
|
|
92
|
+
cidr: "2001:db8::/32",
|
|
93
|
+
ip: "",
|
|
94
|
+
name: "ipv6-address",
|
|
95
|
+
label: "IPv6 Address",
|
|
96
|
+
onIpChange: ip => console.log("IP changed:", ip)
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
export var IPv6WithValue = {
|
|
100
|
+
name: "IPv6 with value",
|
|
101
|
+
args: {
|
|
102
|
+
cidr: "2001:db8::/32",
|
|
103
|
+
ip: "2001:db8::1",
|
|
104
|
+
name: "ipv6-address",
|
|
105
|
+
label: "IPv6 Address",
|
|
106
|
+
onIpChange: ip => console.log("IP changed:", ip)
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
export var WithCustomHelp = {
|
|
110
|
+
args: {
|
|
111
|
+
cidr: "10.0.0.0/16",
|
|
112
|
+
ip: "",
|
|
113
|
+
name: "ip-address",
|
|
114
|
+
label: "IP Address",
|
|
115
|
+
help: "Enter a custom IP address for this device",
|
|
116
|
+
onIpChange: ip => console.log("IP changed:", ip)
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
export var Required = {
|
|
120
|
+
args: {
|
|
121
|
+
cidr: "192.168.0.0/24",
|
|
122
|
+
ip: "",
|
|
123
|
+
name: "ip-address",
|
|
124
|
+
label: "IP Address",
|
|
125
|
+
required: true,
|
|
126
|
+
onIpChange: ip => console.log("IP changed:", ip)
|
|
127
|
+
}
|
|
128
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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 {};
|
|
@@ -75,7 +75,12 @@ export var ImageStrip = {
|
|
|
75
75
|
src: "https://assets.ubuntu.com/v1/9c74eb2d-logo-canonical-white.svg",
|
|
76
76
|
alt: "Placeholder"
|
|
77
77
|
}))))),
|
|
78
|
-
name: "Image strip"
|
|
78
|
+
name: "Image strip",
|
|
79
|
+
parameters: {
|
|
80
|
+
percy: {
|
|
81
|
+
waitForTimeout: 1000 // Wait for 1 second before taking a snapshot to allow the image to load
|
|
82
|
+
}
|
|
83
|
+
}
|
|
79
84
|
};
|
|
80
85
|
export var BorderedStrip = {
|
|
81
86
|
render: () => /*#__PURE__*/React.createElement(Strip, {
|
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/external/useSSR.js
CHANGED
|
@@ -4,6 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.weAreServer = exports.useSSR = exports.Device = void 0;
|
|
7
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
9
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
11
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
12
|
/**
|
|
8
13
|
* This is a reference implementation of the useSSR hook from use-ssr: https://github.com/iamthesiz/use-ssr/blob/master/useSSR.ts
|
|
9
14
|
* The license for the content in this file is goverened by the original project's license: https://github.com/iamthesiz/use-ssr/blob/master/license.md
|
|
@@ -31,10 +36,7 @@ const assign = function () {
|
|
|
31
36
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
32
37
|
args[_key] = arguments[_key];
|
|
33
38
|
}
|
|
34
|
-
return args.reduce((acc, obj) => ({
|
|
35
|
-
...acc,
|
|
36
|
-
...obj
|
|
37
|
-
}), {});
|
|
39
|
+
return args.reduce((acc, obj) => _objectSpread(_objectSpread({}, acc), obj), {});
|
|
38
40
|
};
|
|
39
41
|
const values = obj => Object.keys(obj).map(key => obj[key]);
|
|
40
42
|
const toArrayObject = () => assign((values(SSRObject), SSRObject));
|
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"));
|