@oaknational/oak-components 3.28.0 → 3.29.1
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/npm/cjs/index.js +1026 -768
- package/dist/npm/cjs/types.d.ts +1032 -1011
- package/dist/npm/es/components/buttons/OakIconButton/OakIconButton.js +36 -0
- package/dist/npm/es/components/buttons/OakIconButton/variant.config.js +104 -0
- package/dist/npm/es/components/messaging-and-feedback/OakErrorBoundary/OakErrorBoundary.js +1 -0
- package/dist/npm/es/components/presentational/OakVideo/OakVideo.js +1 -0
- package/dist/npm/es/image-map.js +2 -0
- package/dist/npm/es/index.js +6 -5
- package/dist/npm/es/types.d.ts +1032 -1011
- package/dist/npm/es/utils/focusStyles.js +31 -0
- package/dist/npm/es/utils/propsLookup.js +47 -0
- package/dist/npm/es/utils/trie.js +74 -0
- package/package.json +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { __makeTemplateObject } from 'tslib';
|
|
2
|
+
import { css } from 'styled-components';
|
|
3
|
+
import '../styles/theme/color.js';
|
|
4
|
+
import '../styles/theme/typography.js';
|
|
5
|
+
import { parseBorderRadius } from '../styles/helpers/parseBorderRadius.js';
|
|
6
|
+
import { parseColor } from '../styles/helpers/parseColor.js';
|
|
7
|
+
import { parseDropShadow } from '../styles/helpers/parseDropShadow.js';
|
|
8
|
+
import { responsiveStyle } from '../styles/utils/responsiveStyle.js';
|
|
9
|
+
|
|
10
|
+
function isJSDOM() {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
return (_b = (_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes("jsdom/");
|
|
13
|
+
}
|
|
14
|
+
var focusVisibleChildren = "\n a".concat(isJSDOM() ? "" : ":focus-visible", ",\n button").concat(isJSDOM() ? "" : ":focus-visible", "\n");
|
|
15
|
+
/**
|
|
16
|
+
* Wrap focusable components `<a/>`/`<button/>` and this will add focus styles then the inner element is focused
|
|
17
|
+
*/
|
|
18
|
+
var focusStyles = css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), function (props) {
|
|
19
|
+
var focusStyles = css(templateObject_1 || (templateObject_1 = __makeTemplateObject([""], [""])));
|
|
20
|
+
if (!props.disabled) {
|
|
21
|
+
focusStyles = css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n &:hover {\n ", ";\n box-shadow: ", ";\n }\n\n &:active {\n box-shadow: ", ";\n }\n "], ["\n &:hover {\n ", ";\n box-shadow: ", ";\n }\n\n &:active {\n box-shadow: ", ";\n }\n "])), responsiveStyle("background-color", function (props) { return props.$hoverBackground; }, function (value) { return parseColor(value); }), parseDropShadow("drop-shadow-lemon"), ["drop-shadow-lemon", "drop-shadow-grey"]
|
|
22
|
+
.map(function (i) { return parseDropShadow(i); })
|
|
23
|
+
.join(", "));
|
|
24
|
+
}
|
|
25
|
+
return css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n &:focus {\n ", "\n box-shadow: ", ";\n\n & ", " {\n outline: none;\n }\n }\n ", "\n "], ["\n &:focus {\n ", "\n box-shadow: ", ";\n\n & ", " {\n outline: none;\n }\n }\n ", "\n "])), responsiveStyle("border-radius", function (props) { return props.$borderRadius; }, parseBorderRadius), ["drop-shadow-centered-lemon", "drop-shadow-centered-grey"]
|
|
26
|
+
.map(function (i) { return parseDropShadow(i); })
|
|
27
|
+
.join(", "), focusVisibleChildren, focusStyles);
|
|
28
|
+
});
|
|
29
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
|
|
30
|
+
|
|
31
|
+
export { focusStyles };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { __read } from 'tslib';
|
|
2
|
+
import { isEqual } from 'lodash';
|
|
3
|
+
import { Trie } from './trie.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Lookup a value for the set of props, ideal for complex matrices of values
|
|
7
|
+
* @param entries
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
function propsLookup(entries) {
|
|
11
|
+
var trie = new Trie();
|
|
12
|
+
if (entries.length < 1) {
|
|
13
|
+
throw new Error("Must provide entries for lookup");
|
|
14
|
+
}
|
|
15
|
+
var expectedKeys = Object.keys(entries[0][0]).toSorted(function (a, b) {
|
|
16
|
+
return a.localeCompare(b);
|
|
17
|
+
});
|
|
18
|
+
entries.forEach(function (_a) {
|
|
19
|
+
var _b = __read(_a, 2), obj = _b[0], value = _b[1];
|
|
20
|
+
var sortedEntries = Object.entries(obj).toSorted(function (_a, _b) {
|
|
21
|
+
var _c = __read(_a, 1), aKey = _c[0];
|
|
22
|
+
var _d = __read(_b, 1), bKey = _d[0];
|
|
23
|
+
return aKey.localeCompare(bKey);
|
|
24
|
+
});
|
|
25
|
+
var sortedKey = sortedEntries.map(function (_a) {
|
|
26
|
+
var _b = __read(_a, 1), k = _b[0];
|
|
27
|
+
return k;
|
|
28
|
+
});
|
|
29
|
+
var sortedValue = sortedEntries.map(function (_a) {
|
|
30
|
+
var _b = __read(_a, 2), v = _b[1];
|
|
31
|
+
return v;
|
|
32
|
+
});
|
|
33
|
+
if (trie.has(sortedValue)) {
|
|
34
|
+
throw new Error("Keys must be unique");
|
|
35
|
+
}
|
|
36
|
+
if (!isEqual(sortedKey, expectedKeys)) {
|
|
37
|
+
throw new Error("For performance reasons objects must all have the same shape");
|
|
38
|
+
}
|
|
39
|
+
trie.set(sortedValue, value);
|
|
40
|
+
});
|
|
41
|
+
return function (obj) {
|
|
42
|
+
var lookupKey = expectedKeys.map(function (k) { return obj[k]; });
|
|
43
|
+
return trie.get(lookupKey);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { propsLookup };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { __values } from 'tslib';
|
|
2
|
+
|
|
3
|
+
var TrieNode = /** @class */ (function () {
|
|
4
|
+
function TrieNode() {
|
|
5
|
+
this.children = new Map();
|
|
6
|
+
this.hasValue = false;
|
|
7
|
+
}
|
|
8
|
+
return TrieNode;
|
|
9
|
+
}());
|
|
10
|
+
var Trie = /** @class */ (function () {
|
|
11
|
+
function Trie() {
|
|
12
|
+
this.root = new TrieNode();
|
|
13
|
+
}
|
|
14
|
+
Trie.prototype.set = function (path, value) {
|
|
15
|
+
var e_1, _a;
|
|
16
|
+
var node = this.root;
|
|
17
|
+
try {
|
|
18
|
+
for (var path_1 = __values(path), path_1_1 = path_1.next(); !path_1_1.done; path_1_1 = path_1.next()) {
|
|
19
|
+
var key = path_1_1.value;
|
|
20
|
+
var next = node.children.get(key);
|
|
21
|
+
if (!next) {
|
|
22
|
+
next = new TrieNode();
|
|
23
|
+
node.children.set(key, next);
|
|
24
|
+
}
|
|
25
|
+
node = next;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
29
|
+
finally {
|
|
30
|
+
try {
|
|
31
|
+
if (path_1_1 && !path_1_1.done && (_a = path_1.return)) _a.call(path_1);
|
|
32
|
+
}
|
|
33
|
+
finally { if (e_1) throw e_1.error; }
|
|
34
|
+
}
|
|
35
|
+
node.hasValue = true;
|
|
36
|
+
node.value = value;
|
|
37
|
+
return this;
|
|
38
|
+
};
|
|
39
|
+
Trie.prototype.get = function (path) {
|
|
40
|
+
var node = this.find(path);
|
|
41
|
+
return (node === null || node === void 0 ? void 0 : node.hasValue) ? node.value : undefined;
|
|
42
|
+
};
|
|
43
|
+
Trie.prototype.has = function (path) {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
return (_b = (_a = this.find(path)) === null || _a === void 0 ? void 0 : _a.hasValue) !== null && _b !== void 0 ? _b : false;
|
|
46
|
+
};
|
|
47
|
+
Trie.prototype.hasPrefix = function (path) {
|
|
48
|
+
return this.find(path) !== undefined;
|
|
49
|
+
};
|
|
50
|
+
Trie.prototype.find = function (path) {
|
|
51
|
+
var e_2, _a;
|
|
52
|
+
var node = this.root;
|
|
53
|
+
try {
|
|
54
|
+
for (var path_2 = __values(path), path_2_1 = path_2.next(); !path_2_1.done; path_2_1 = path_2.next()) {
|
|
55
|
+
var key = path_2_1.value;
|
|
56
|
+
var next = node.children.get(key);
|
|
57
|
+
if (!next)
|
|
58
|
+
return undefined;
|
|
59
|
+
node = next;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
63
|
+
finally {
|
|
64
|
+
try {
|
|
65
|
+
if (path_2_1 && !path_2_1.done && (_a = path_2.return)) _a.call(path_2);
|
|
66
|
+
}
|
|
67
|
+
finally { if (e_2) throw e_2.error; }
|
|
68
|
+
}
|
|
69
|
+
return node;
|
|
70
|
+
};
|
|
71
|
+
return Trie;
|
|
72
|
+
}());
|
|
73
|
+
|
|
74
|
+
export { Trie };
|