@telia-ace/knowledge-widget-components-guide-category-dropdown 1.0.4 → 1.0.8
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/{lib-esm → dist}/guide-category-dropdown-component.d.ts +0 -0
- package/{lib-esm → dist}/guide-category-dropdown-item.d.ts +0 -0
- package/{lib-esm → dist}/guide-category-dropdown-match-count.d.ts +0 -0
- package/{lib-esm → dist}/guide-category-dropdown.d.ts +0 -0
- package/dist/guide-category-dropdown.js +323 -0
- package/dist/guide-category-dropdown.js.map +1 -0
- package/{lib-esm → dist}/guide-category-dropdown.styles.d.ts +0 -0
- package/{lib-esm → dist}/index.d.ts +0 -0
- package/dist/index.js +91 -0
- package/dist/index.js.map +1 -0
- package/package.json +12 -13
- package/lib/guide-category-dropdown-component.d.ts +0 -16
- package/lib/guide-category-dropdown-component.js +0 -132
- package/lib/guide-category-dropdown-item.d.ts +0 -8
- package/lib/guide-category-dropdown-item.js +0 -50
- package/lib/guide-category-dropdown-match-count.d.ts +0 -4
- package/lib/guide-category-dropdown-match-count.js +0 -20
- package/lib/guide-category-dropdown.d.ts +0 -6
- package/lib/guide-category-dropdown.js +0 -120
- package/lib/guide-category-dropdown.styles.d.ts +0 -10
- package/lib/guide-category-dropdown.styles.js +0 -64
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -7
- package/lib-esm/guide-category-dropdown-component.js +0 -107
- package/lib-esm/guide-category-dropdown-item.js +0 -45
- package/lib-esm/guide-category-dropdown-match-count.js +0 -15
- package/lib-esm/guide-category-dropdown.js +0 -92
- package/lib-esm/guide-category-dropdown.styles.js +0 -39
- package/lib-esm/index.js +0 -2
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
import { loadingOpacity, contentBox, borderTabStyle, Link as Link$1, linkTabStyle, List as List$1, list, Text, useProperties, useHover, SymbolBadge, useRouteData, useContainer, createEmptyComponent } from "@telia-ace/knowledge-widget-ui";
|
|
33
|
+
import { appendClassNames, createParams, formatUrl } from "@telia-ace/widget-utilities";
|
|
34
|
+
import React, { useState, useEffect } from "react";
|
|
35
|
+
import { initialRouteFallback } from "@telia-ace/knowledge-widget-component-utilities";
|
|
36
|
+
import styled, { css } from "styled-components";
|
|
37
|
+
const Wrapper = styled.div`
|
|
38
|
+
${loadingOpacity}
|
|
39
|
+
${contentBox}
|
|
40
|
+
overflow: hidden;
|
|
41
|
+
min-height: 50px;
|
|
42
|
+
${(p) => {
|
|
43
|
+
var _a;
|
|
44
|
+
return p["data-toggler-in-focus"] && ((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && css`
|
|
45
|
+
&& {
|
|
46
|
+
${borderTabStyle}
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
}};
|
|
50
|
+
`;
|
|
51
|
+
const Toggler = styled.button`
|
|
52
|
+
background: none;
|
|
53
|
+
border: 0;
|
|
54
|
+
outline: 0;
|
|
55
|
+
display: block;
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
padding: 0;
|
|
58
|
+
font-size: ${(p) => {
|
|
59
|
+
var _a;
|
|
60
|
+
return (_a = p.theme.fonts) == null ? void 0 : _a.normal;
|
|
61
|
+
}};
|
|
62
|
+
text-align: end;
|
|
63
|
+
flex: 1 0 auto;
|
|
64
|
+
svg {
|
|
65
|
+
path,
|
|
66
|
+
line {
|
|
67
|
+
stroke: ${(p) => {
|
|
68
|
+
var _a;
|
|
69
|
+
return (_a = p.theme.colors) == null ? void 0 : _a.text;
|
|
70
|
+
}};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
const styling = css`
|
|
75
|
+
font-size: ${(p) => {
|
|
76
|
+
var _a;
|
|
77
|
+
return (_a = p.theme.fonts) == null ? void 0 : _a.normal;
|
|
78
|
+
}};
|
|
79
|
+
text-align: left;
|
|
80
|
+
text-align: left;
|
|
81
|
+
text-decoration: none;
|
|
82
|
+
font-weight: 300;
|
|
83
|
+
display: flex;
|
|
84
|
+
align-items: center;
|
|
85
|
+
padding: ${(p) => {
|
|
86
|
+
var _a;
|
|
87
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.small;
|
|
88
|
+
}};
|
|
89
|
+
padding-left: ${(p) => {
|
|
90
|
+
var _a;
|
|
91
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.large;
|
|
92
|
+
}};
|
|
93
|
+
cursor: pointer;
|
|
94
|
+
overflow: hidden;
|
|
95
|
+
${(p) => {
|
|
96
|
+
var _a, _b, _c;
|
|
97
|
+
return p.selected ? css`
|
|
98
|
+
border-left: 2px solid ${(_a = p.theme.colors) == null ? void 0 : _a.primary};
|
|
99
|
+
color: ${(_b = p.theme.colors) == null ? void 0 : _b.primary};
|
|
100
|
+
` : css`
|
|
101
|
+
color: ${(_c = p.theme.colors) == null ? void 0 : _c.text};
|
|
102
|
+
`;
|
|
103
|
+
}};
|
|
104
|
+
|
|
105
|
+
span {
|
|
106
|
+
overflow: hidden;
|
|
107
|
+
text-overflow: ellipsis;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
i {
|
|
111
|
+
margin-right: ${(p) => {
|
|
112
|
+
var _a;
|
|
113
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
114
|
+
}};
|
|
115
|
+
font-size: ${(p) => {
|
|
116
|
+
var _a;
|
|
117
|
+
return (_a = p.theme.fonts) == null ? void 0 : _a.medium;
|
|
118
|
+
}};
|
|
119
|
+
min-height: 1em;
|
|
120
|
+
min-width: 1em;
|
|
121
|
+
}
|
|
122
|
+
`;
|
|
123
|
+
const Item = styled.div`
|
|
124
|
+
${styling}
|
|
125
|
+
`;
|
|
126
|
+
const Link = styled(Link$1)`
|
|
127
|
+
${styling}
|
|
128
|
+
&:focus {
|
|
129
|
+
outline: none;
|
|
130
|
+
span {
|
|
131
|
+
${(p) => {
|
|
132
|
+
var _a;
|
|
133
|
+
return ((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && linkTabStyle;
|
|
134
|
+
}};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
`;
|
|
138
|
+
const TopItem = styled.div`
|
|
139
|
+
display: flex;
|
|
140
|
+
justify-content: space-between;
|
|
141
|
+
padding-right: ${(p) => {
|
|
142
|
+
var _a;
|
|
143
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.large;
|
|
144
|
+
}};
|
|
145
|
+
min-height: 52px;
|
|
146
|
+
white-space: nowrap;
|
|
147
|
+
|
|
148
|
+
&& {
|
|
149
|
+
font-weight: normal;
|
|
150
|
+
|
|
151
|
+
a {
|
|
152
|
+
font-weight: normal;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
${Item} {
|
|
156
|
+
font-weight: normal;
|
|
157
|
+
}
|
|
158
|
+
`;
|
|
159
|
+
const List = styled(List$1)`
|
|
160
|
+
${list}
|
|
161
|
+
display: flex;
|
|
162
|
+
justify-content: center;
|
|
163
|
+
flex-direction: column;
|
|
164
|
+
margin-right: ${(p) => {
|
|
165
|
+
var _a;
|
|
166
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.medium;
|
|
167
|
+
}};
|
|
168
|
+
margin-left: ${(p) => {
|
|
169
|
+
var _a;
|
|
170
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.large;
|
|
171
|
+
}};
|
|
172
|
+
margin-bottom: 22px;
|
|
173
|
+
border-left: ${(p) => p.theme.border};
|
|
174
|
+
li {
|
|
175
|
+
margin: 0 0 ${(p) => {
|
|
176
|
+
var _a;
|
|
177
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.normal;
|
|
178
|
+
}} -2px;
|
|
179
|
+
}
|
|
180
|
+
li:last-child {
|
|
181
|
+
margin: 0 0 0 -2px;
|
|
182
|
+
}
|
|
183
|
+
flex-basis: 100%;
|
|
184
|
+
border-width: 2px;
|
|
185
|
+
`;
|
|
186
|
+
const MatchCount = styled(Text)`
|
|
187
|
+
margin: 0 0 0 ${(p) => {
|
|
188
|
+
var _a;
|
|
189
|
+
return (_a = p.theme.sizes) == null ? void 0 : _a.small;
|
|
190
|
+
}};
|
|
191
|
+
`;
|
|
192
|
+
var Styled = {
|
|
193
|
+
Wrapper,
|
|
194
|
+
Toggler,
|
|
195
|
+
List,
|
|
196
|
+
Item,
|
|
197
|
+
Link,
|
|
198
|
+
TopItem,
|
|
199
|
+
MatchCount
|
|
200
|
+
};
|
|
201
|
+
const GuideCategoryDropdownMatchCount = ({ matches }) => {
|
|
202
|
+
const { showMatchCount = false } = useProperties();
|
|
203
|
+
if (!showMatchCount || typeof matches === "undefined") {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
return /* @__PURE__ */ React.createElement(Styled.MatchCount, null, "(", matches, ")");
|
|
207
|
+
};
|
|
208
|
+
const GuideCategoryDropdownItem = ({ item, guideCategory }) => {
|
|
209
|
+
const {
|
|
210
|
+
route = "browse",
|
|
211
|
+
categoryAriaLabel = "",
|
|
212
|
+
activeCategoryAriaLabel = "",
|
|
213
|
+
fallbackOnInitialRoute = false
|
|
214
|
+
} = useProperties();
|
|
215
|
+
const [hovering, elem] = useHover();
|
|
216
|
+
const { id, title, symbol, activeSymbol } = item;
|
|
217
|
+
const selected = guideCategory === id;
|
|
218
|
+
return /* @__PURE__ */ React.createElement("li", {
|
|
219
|
+
ref: elem
|
|
220
|
+
}, /* @__PURE__ */ React.createElement(Styled.Link, __spreadProps(__spreadValues({}, initialRouteFallback(item, route, fallbackOnInitialRoute, "category")), {
|
|
221
|
+
"aria-pressed": selected,
|
|
222
|
+
"aria-label": (selected ? activeCategoryAriaLabel : categoryAriaLabel).replace("{{category}}", title),
|
|
223
|
+
className: "humany-guide-category-dropdown-link",
|
|
224
|
+
"aria-current": selected,
|
|
225
|
+
selected
|
|
226
|
+
}), (selected || hovering) && activeSymbol ? /* @__PURE__ */ React.createElement(SymbolBadge, {
|
|
227
|
+
symbol: activeSymbol
|
|
228
|
+
}) : symbol && /* @__PURE__ */ React.createElement(SymbolBadge, {
|
|
229
|
+
symbol
|
|
230
|
+
}), /* @__PURE__ */ React.createElement(Text, null, title), /* @__PURE__ */ React.createElement(GuideCategoryDropdownMatchCount, __spreadValues({}, item))));
|
|
231
|
+
};
|
|
232
|
+
const GuideCategoryDropdown = (_a) => {
|
|
233
|
+
var _b = _a, { className } = _b, other = __objRest(_b, ["className"]);
|
|
234
|
+
const routeData = useRouteData();
|
|
235
|
+
const [togglerFocus, setTogglerFocus] = useState(false);
|
|
236
|
+
const {
|
|
237
|
+
parent,
|
|
238
|
+
route = "browse",
|
|
239
|
+
categories = [],
|
|
240
|
+
loading = false
|
|
241
|
+
} = useProperties();
|
|
242
|
+
const container = useContainer();
|
|
243
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
244
|
+
const { params } = routeData;
|
|
245
|
+
const { guideCategory, tag, phrase, sorting } = params;
|
|
246
|
+
useEffect(() => {
|
|
247
|
+
if (isOpen) {
|
|
248
|
+
setIsOpen(false);
|
|
249
|
+
}
|
|
250
|
+
}, [guideCategory]);
|
|
251
|
+
if (loading || !parent || !categories.length) {
|
|
252
|
+
return createEmptyComponent(container, __spreadProps(__spreadValues({}, other), {
|
|
253
|
+
className: appendClassNames(className, "humany-guide-category-dropdown")
|
|
254
|
+
}));
|
|
255
|
+
}
|
|
256
|
+
const selected = categories.find((category) => category.id === guideCategory) || parent;
|
|
257
|
+
const selectedSymbol = selected.activeSymbol || selected.symbol;
|
|
258
|
+
return /* @__PURE__ */ React.createElement(Styled.Wrapper, __spreadProps(__spreadValues({}, other), {
|
|
259
|
+
"data-loading": false,
|
|
260
|
+
"data-toggler-in-focus": togglerFocus,
|
|
261
|
+
"aria-expanded": isOpen,
|
|
262
|
+
className: appendClassNames(className, "humany-guide-category-dropdown")
|
|
263
|
+
}), isOpen ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Styled.TopItem, {
|
|
264
|
+
className: "humany-guide-category-dropdown-top-item"
|
|
265
|
+
}, /* @__PURE__ */ React.createElement(Styled.Link, {
|
|
266
|
+
className: "humany-guide-category-dropdown-link",
|
|
267
|
+
routeName: route,
|
|
268
|
+
params: createParams({
|
|
269
|
+
tag,
|
|
270
|
+
phrase,
|
|
271
|
+
sorting,
|
|
272
|
+
guideCategory: parent.id,
|
|
273
|
+
uriName: formatUrl(parent.title)
|
|
274
|
+
}),
|
|
275
|
+
selected: false
|
|
276
|
+
}, parent.symbol ? /* @__PURE__ */ React.createElement(SymbolBadge, {
|
|
277
|
+
symbol: parent.symbol
|
|
278
|
+
}) : null, /* @__PURE__ */ React.createElement(Text, null, parent.title), /* @__PURE__ */ React.createElement(GuideCategoryDropdownMatchCount, __spreadValues({}, parent))), /* @__PURE__ */ React.createElement(Styled.Toggler, {
|
|
279
|
+
onBlur: () => setTogglerFocus(false),
|
|
280
|
+
onFocus: () => setTogglerFocus(true),
|
|
281
|
+
className: "humany-guide-category-dropdown-toggler",
|
|
282
|
+
onClick: () => {
|
|
283
|
+
setIsOpen(!isOpen);
|
|
284
|
+
},
|
|
285
|
+
"aria-expanded": "true",
|
|
286
|
+
"aria-label": selected.title
|
|
287
|
+
}, /* @__PURE__ */ React.createElement(SymbolBadge, {
|
|
288
|
+
size: 18,
|
|
289
|
+
symbol: { type: "Svg", content: "caret-up" }
|
|
290
|
+
}))), /* @__PURE__ */ React.createElement(Styled.List, {
|
|
291
|
+
className: "humany-guide-category-dropdown-open",
|
|
292
|
+
items: categories,
|
|
293
|
+
renderItem: (item) => /* @__PURE__ */ React.createElement(GuideCategoryDropdownItem, {
|
|
294
|
+
key: item.id,
|
|
295
|
+
item,
|
|
296
|
+
guideCategory
|
|
297
|
+
})
|
|
298
|
+
})) : /* @__PURE__ */ React.createElement(Styled.TopItem, {
|
|
299
|
+
className: "humany-guide-category-dropdown-top-item"
|
|
300
|
+
}, /* @__PURE__ */ React.createElement(Styled.Item, {
|
|
301
|
+
className: "humany-guide-category-dropdown-item",
|
|
302
|
+
onClick: () => {
|
|
303
|
+
setIsOpen(!isOpen);
|
|
304
|
+
},
|
|
305
|
+
selected: false
|
|
306
|
+
}, selectedSymbol ? /* @__PURE__ */ React.createElement(SymbolBadge, {
|
|
307
|
+
symbol: selectedSymbol
|
|
308
|
+
}) : null, /* @__PURE__ */ React.createElement(Text, null, selected.title), /* @__PURE__ */ React.createElement(GuideCategoryDropdownMatchCount, __spreadValues({}, selected))), /* @__PURE__ */ React.createElement(Styled.Toggler, {
|
|
309
|
+
onBlur: () => setTogglerFocus(false),
|
|
310
|
+
onFocus: () => setTogglerFocus(true),
|
|
311
|
+
className: "humany-guide-category-dropdown-toggler",
|
|
312
|
+
onClick: () => {
|
|
313
|
+
setIsOpen(!isOpen);
|
|
314
|
+
},
|
|
315
|
+
"aria-expanded": "false",
|
|
316
|
+
"aria-label": selected.title
|
|
317
|
+
}, /* @__PURE__ */ React.createElement(SymbolBadge, {
|
|
318
|
+
size: 18,
|
|
319
|
+
symbol: { type: "Svg", content: "caret-down" }
|
|
320
|
+
}))));
|
|
321
|
+
};
|
|
322
|
+
export { GuideCategoryDropdown as default };
|
|
323
|
+
//# sourceMappingURL=guide-category-dropdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guide-category-dropdown.js","sources":["../src/guide-category-dropdown.styles.ts","../src/guide-category-dropdown-match-count.tsx","../src/guide-category-dropdown-item.tsx","../src/guide-category-dropdown.tsx"],"sourcesContent":["import {\r\n borderTabStyle,\r\n contentBox,\r\n Link as BaseLink,\r\n linkTabStyle,\r\n List as BaseList,\r\n list,\r\n loadingOpacity,\r\n Text,\r\n} from '@telia-ace/knowledge-widget-ui';\r\nimport styled, { css } from 'styled-components';\r\n\r\n// FUTURE TODO: Look into the typescript error when removing \": any\".\r\nconst Wrapper: any = styled.div<any>`\r\n ${loadingOpacity}\r\n ${contentBox}\r\n overflow: hidden;\r\n min-height: 50px;\r\n ${(p) =>\r\n p['data-toggler-in-focus'] &&\r\n p.theme.accessibility?.isTabbing &&\r\n css`\r\n && {\r\n ${borderTabStyle}\r\n }\r\n `};\r\n`;\r\n\r\n// FUTURE TODO: Look into the typescript error when removing \": any\".\r\nconst Toggler: any = styled.button`\r\n background: none;\r\n border: 0;\r\n outline: 0;\r\n display: block;\r\n cursor: pointer;\r\n padding: 0;\r\n font-size: ${(p) => p.theme.fonts?.normal};\r\n text-align: end;\r\n flex: 1 0 auto;\r\n svg {\r\n path,\r\n line {\r\n stroke: ${(p) => p.theme.colors?.text};\r\n }\r\n }\r\n`;\r\n\r\n// FUTURE TODO: Look into the typescript error when removing \": any\".\r\nconst styling = css<{ selected: boolean }>`\r\n font-size: ${(p) => p.theme.fonts?.normal};\r\n text-align: left;\r\n text-align: left;\r\n text-decoration: none;\r\n font-weight: 300;\r\n display: flex;\r\n align-items: center;\r\n padding: ${(p) => p.theme.sizes?.small};\r\n padding-left: ${(p) => p.theme.sizes?.large};\r\n cursor: pointer;\r\n overflow: hidden;\r\n ${(p) =>\r\n p.selected\r\n ? css`\r\n border-left: 2px solid ${p.theme.colors?.primary};\r\n color: ${p.theme.colors?.primary};\r\n `\r\n : css`\r\n color: ${p.theme.colors?.text};\r\n `};\r\n\r\n span {\r\n overflow: hidden;\r\n text-overflow: ellipsis;\r\n }\r\n\r\n i {\r\n margin-right: ${(p) => p.theme.sizes?.normal};\r\n font-size: ${(p) => p.theme.fonts?.medium};\r\n min-height: 1em;\r\n min-width: 1em;\r\n }\r\n`;\r\n\r\n// FUTURE TODO: Look into the typescript error when removing \": any\".\r\nconst Item: any = styled.div`\r\n ${styling}\r\n`;\r\n\r\nconst Link: any = styled(BaseLink)<any>`\r\n ${styling}\r\n &:focus {\r\n outline: none;\r\n span {\r\n ${(p) => p.theme.accessibility?.isTabbing && linkTabStyle};\r\n }\r\n }\r\n`;\r\n\r\n// FUTURE TODO: Look into the typescript error when removing \": any\".\r\nconst TopItem: any = styled.div`\r\n display: flex;\r\n justify-content: space-between;\r\n padding-right: ${(p) => p.theme.sizes?.large};\r\n min-height: 52px;\r\n white-space: nowrap;\r\n\r\n && {\r\n font-weight: normal;\r\n\r\n a {\r\n font-weight: normal;\r\n }\r\n }\r\n ${Item} {\r\n font-weight: normal;\r\n }\r\n`;\r\n\r\n// FUTURE TODO: Look into the typescript error when removing \": any\".\r\nconst List: any = styled(BaseList)<any>`\r\n ${list}\r\n display: flex;\r\n justify-content: center;\r\n flex-direction: column;\r\n margin-right: ${(p) => p.theme.sizes?.medium};\r\n margin-left: ${(p) => p.theme.sizes?.large};\r\n margin-bottom: 22px;\r\n border-left: ${(p) => p.theme.border};\r\n li {\r\n margin: 0 0 ${(p) => p.theme.sizes?.normal} -2px;\r\n }\r\n li:last-child {\r\n margin: 0 0 0 -2px;\r\n }\r\n flex-basis: 100%;\r\n border-width: 2px;\r\n`;\r\n\r\n// FUTURE TODO: Look into the typescript error when removing \": any\".\r\nconst MatchCount: any = styled(Text)`\r\n margin: 0 0 0 ${(p) => p.theme.sizes?.small};\r\n`;\r\n\r\nexport default {\r\n Wrapper,\r\n Toggler,\r\n List,\r\n Item,\r\n Link,\r\n TopItem,\r\n MatchCount,\r\n};\r\n","import { Category } from '@telia-ace/knowledge-widget-core';\r\nimport { useProperties } from '@telia-ace/knowledge-widget-ui';\r\nimport React from 'react';\r\nimport { GuideCategoryDropdownComponentProps } from './guide-category-dropdown-component';\r\nimport Styled from './guide-category-dropdown.styles';\r\n\r\nconst GuideCategoryDropdownMatchCount: React.FC<Category> = ({ matches }) => {\r\n const { showMatchCount = false } = useProperties<GuideCategoryDropdownComponentProps>();\r\n\r\n if (!showMatchCount || typeof matches === 'undefined') {\r\n return null;\r\n }\r\n\r\n return <Styled.MatchCount>({matches})</Styled.MatchCount>;\r\n};\r\n\r\nexport default GuideCategoryDropdownMatchCount;\r\n","import { initialRouteFallback } from '@telia-ace/knowledge-widget-component-utilities';\r\nimport { Category } from '@telia-ace/knowledge-widget-core';\r\nimport { SymbolBadge, Text, useHover, useProperties } from '@telia-ace/knowledge-widget-ui';\r\nimport React from 'react';\r\nimport { GuideCategoryDropdownComponentProps } from './guide-category-dropdown-component';\r\nimport GuideCategoryDropdownMatchCount from './guide-category-dropdown-match-count';\r\nimport Styled from './guide-category-dropdown.styles';\r\n\r\ntype Props = {\r\n item: Category;\r\n guideCategory: string;\r\n};\r\n\r\nconst GuideCategoryDropdownItem: React.FC<Props> = ({ item, guideCategory }) => {\r\n const {\r\n route = 'browse',\r\n categoryAriaLabel = '',\r\n activeCategoryAriaLabel = '',\r\n fallbackOnInitialRoute = false,\r\n } = useProperties<GuideCategoryDropdownComponentProps>();\r\n const [hovering, elem] = useHover();\r\n const { id, title, symbol, activeSymbol } = item;\r\n\r\n const selected = guideCategory === id;\r\n return (\r\n <li ref={elem as any}>\r\n <Styled.Link\r\n {...initialRouteFallback(item, route, fallbackOnInitialRoute, 'category')}\r\n aria-pressed={selected}\r\n aria-label={(selected ? activeCategoryAriaLabel : categoryAriaLabel).replace(\r\n '{{category}}',\r\n title\r\n )}\r\n className=\"humany-guide-category-dropdown-link\"\r\n aria-current={selected}\r\n selected={selected}\r\n >\r\n {(selected || hovering) && activeSymbol ? (\r\n <SymbolBadge symbol={activeSymbol} />\r\n ) : (\r\n symbol && <SymbolBadge symbol={symbol} />\r\n )}\r\n <Text>{title}</Text>\r\n <GuideCategoryDropdownMatchCount {...item} />\r\n </Styled.Link>\r\n </li>\r\n );\r\n};\r\n\r\nexport default GuideCategoryDropdownItem;\r\n","import { Category } from '@telia-ace/knowledge-widget-core';\r\nimport {\r\n createEmptyComponent,\r\n SymbolBadge,\r\n Text,\r\n useContainer,\r\n useProperties,\r\n useRouteData,\r\n} from '@telia-ace/knowledge-widget-ui';\r\nimport { appendClassNames, createParams, formatUrl } from '@telia-ace/widget-utilities';\r\nimport React, { useEffect, useState } from 'react';\r\nimport { GuideCategoryDropdownComponentProps } from './guide-category-dropdown-component';\r\nimport GuideCategoryDropdownItem from './guide-category-dropdown-item';\r\nimport GuideCategoryDropdownMatchCount from './guide-category-dropdown-match-count';\r\nimport Styled from './guide-category-dropdown.styles';\r\n\r\ntype Props = {\r\n className: string;\r\n};\r\n\r\nconst GuideCategoryDropdown: React.SFC<Props> = ({ className, ...other }) => {\r\n const routeData = useRouteData();\r\n const [togglerFocus, setTogglerFocus] = useState(false);\r\n const {\r\n parent,\r\n route = 'browse',\r\n categories = [],\r\n loading = false,\r\n } = useProperties<GuideCategoryDropdownComponentProps>();\r\n const container = useContainer();\r\n const [isOpen, setIsOpen] = useState(false);\r\n const { params } = routeData;\r\n const { guideCategory, tag, phrase, sorting } = params;\r\n\r\n useEffect(() => {\r\n if (isOpen) {\r\n setIsOpen(false);\r\n }\r\n }, [guideCategory]);\r\n\r\n if (loading || !parent || !categories.length) {\r\n return createEmptyComponent(container, {\r\n ...other,\r\n className: appendClassNames(className, 'humany-guide-category-dropdown'),\r\n });\r\n }\r\n\r\n const selected = categories.find((category) => category.id === guideCategory) || parent;\r\n const selectedSymbol = selected.activeSymbol || selected.symbol;\r\n\r\n return (\r\n <Styled.Wrapper\r\n {...other}\r\n data-loading={false}\r\n data-toggler-in-focus={togglerFocus}\r\n aria-expanded={isOpen}\r\n className={appendClassNames(className, 'humany-guide-category-dropdown')}\r\n >\r\n {isOpen ? (\r\n <>\r\n <Styled.TopItem className=\"humany-guide-category-dropdown-top-item\">\r\n <Styled.Link\r\n className=\"humany-guide-category-dropdown-link\"\r\n routeName={route}\r\n params={createParams({\r\n tag,\r\n phrase,\r\n sorting,\r\n guideCategory: parent.id,\r\n uriName: formatUrl(parent.title),\r\n })}\r\n selected={false}\r\n >\r\n {parent.symbol ? <SymbolBadge symbol={parent.symbol} /> : null}\r\n <Text>{parent.title}</Text>\r\n <GuideCategoryDropdownMatchCount {...parent} />\r\n </Styled.Link>\r\n <Styled.Toggler\r\n onBlur={() => setTogglerFocus(false)}\r\n onFocus={() => setTogglerFocus(true)}\r\n className=\"humany-guide-category-dropdown-toggler\"\r\n onClick={() => {\r\n setIsOpen(!isOpen);\r\n }}\r\n aria-expanded=\"true\"\r\n aria-label={selected.title}\r\n >\r\n <SymbolBadge size={18} symbol={{ type: 'Svg', content: 'caret-up' }} />\r\n </Styled.Toggler>\r\n </Styled.TopItem>\r\n <Styled.List\r\n className=\"humany-guide-category-dropdown-open\"\r\n items={categories}\r\n renderItem={(item: Category) => (\r\n <GuideCategoryDropdownItem\r\n key={item.id}\r\n item={item}\r\n guideCategory={guideCategory}\r\n />\r\n )}\r\n />\r\n </>\r\n ) : (\r\n <Styled.TopItem className=\"humany-guide-category-dropdown-top-item\">\r\n <Styled.Item\r\n className=\"humany-guide-category-dropdown-item\"\r\n onClick={() => {\r\n setIsOpen(!isOpen);\r\n }}\r\n selected={false}\r\n >\r\n {selectedSymbol ? <SymbolBadge symbol={selectedSymbol} /> : null}\r\n <Text>{selected.title}</Text>\r\n <GuideCategoryDropdownMatchCount {...selected} />\r\n </Styled.Item>\r\n <Styled.Toggler\r\n onBlur={() => setTogglerFocus(false)}\r\n onFocus={() => setTogglerFocus(true)}\r\n className=\"humany-guide-category-dropdown-toggler\"\r\n onClick={() => {\r\n setIsOpen(!isOpen);\r\n }}\r\n aria-expanded=\"false\"\r\n aria-label={selected.title}\r\n >\r\n <SymbolBadge size={18} symbol={{ type: 'Svg', content: 'caret-down' }} />\r\n </Styled.Toggler>\r\n </Styled.TopItem>\r\n )}\r\n </Styled.Wrapper>\r\n );\r\n};\r\n\r\nexport default GuideCategoryDropdown;\r\n"],"names":["BaseLink","BaseList"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,MAAM,UAAe,OAAO;AAAA,MACtB;AAAA,MACA;AAAA;AAAA;AAAA,MAGA,CAAC;;AACC,WAAE,4BACF,SAAE,MAAM,kBAAR,mBAAuB,cACvB;AAAA;AAAA,kBAEU;AAAA;AAAA;AAAA;AAAA;AAMlB,MAAM,UAAe,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAOX,CAAC,MAAM;;AAAA,iBAAE,MAAM,UAAR,mBAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAMjB,CAAC,MAAM;;AAAA,iBAAE,MAAM,WAAR,mBAAgB;AAAA;AAAA;AAAA;AAAA;AAM7C,MAAM,UAAU;AAA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G,QAAQ,MAAM,gBAAgB,KAAK;AAAA,IACnC,SAAS,MAAM,gBAAgB,IAAI;AAAA,IACnC,WAAU;AAAA,IACV,SAAS,MAAM;AACX,gBAAU,CAAC,MAAM;AAAA,IACrB;AAAA,IACA,iBAAc;AAAA,IACd,cAAY,SAAS;AAAA,EAAA,GAEpB,sBAAA,cAAA,aAAA;AAAA,IAAY,MAAM;AAAA,IAAI,QAAQ,EAAE,MAAM,OAAO,SAAS,aAAa;AAAA,EAAA,CAAG,CAC3E,CACJ,CAER;AAER;;"}
|
|
File without changes
|
|
File without changes
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { createEventSubscriber, extendComponent } from "@telia-ace/knowledge-widget-core";
|
|
2
|
+
import { DataType } from "@telia-ace/knowledge-widget-types-grid";
|
|
3
|
+
import { createReactComponent } from "@telia-ace/knowledge-widget-ui";
|
|
4
|
+
const findParentAndSiblings = (categories, root, currentCategoryId) => {
|
|
5
|
+
if (!currentCategoryId || currentCategoryId.length < 1) {
|
|
6
|
+
return root;
|
|
7
|
+
}
|
|
8
|
+
return findRecursive(categories, root, null, currentCategoryId);
|
|
9
|
+
};
|
|
10
|
+
const findRecursive = (categories, root, previous, currentCategoryId) => {
|
|
11
|
+
const filtered = categories.find((c) => c.id === currentCategoryId);
|
|
12
|
+
if (filtered || !currentCategoryId) {
|
|
13
|
+
if (!previous) {
|
|
14
|
+
return root;
|
|
15
|
+
}
|
|
16
|
+
return previous;
|
|
17
|
+
}
|
|
18
|
+
for (let i = 0; i < categories.length; i += 1) {
|
|
19
|
+
const cat = categories[i];
|
|
20
|
+
if (cat.items) {
|
|
21
|
+
const result = findRecursive(cat.items, root, cat, currentCategoryId);
|
|
22
|
+
if (result) {
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const filterEmptyCategories = (category) => category.matches && category.matches > 0;
|
|
29
|
+
var GuideCategoryDropdownComponent = (container) => {
|
|
30
|
+
const { events } = container.get("$widget");
|
|
31
|
+
const [subscribe, unsubscribe] = createEventSubscriber(events);
|
|
32
|
+
return createReactComponent(container, "guide-category-dropdown", import("./guide-category-dropdown.js"), (component) => {
|
|
33
|
+
const fetch = (params) => {
|
|
34
|
+
component.writeProperties({ loading: true });
|
|
35
|
+
component.actions.dispatch("fetch", { params }).then(() => {
|
|
36
|
+
component.writeProperties({ loading: false });
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
component.actions.create("fetch", ({ parent, categories }) => {
|
|
40
|
+
component.writeProperties({
|
|
41
|
+
parent,
|
|
42
|
+
categories,
|
|
43
|
+
loading: false
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
container.getAsync("router").then((router) => {
|
|
47
|
+
const { params } = router.getRouteData();
|
|
48
|
+
fetch(params);
|
|
49
|
+
});
|
|
50
|
+
subscribe("router:changed", (event, { current }) => {
|
|
51
|
+
fetch(current.routeData.params);
|
|
52
|
+
});
|
|
53
|
+
}).then(() => {
|
|
54
|
+
return extendComponent(container, "guide-category-dropdown", (component) => {
|
|
55
|
+
component.actions.watch("guide-category-dropdown.fetch", (input, next) => {
|
|
56
|
+
const {
|
|
57
|
+
matchFilters = {
|
|
58
|
+
search: false,
|
|
59
|
+
tag: false
|
|
60
|
+
},
|
|
61
|
+
rootCategoryHeader
|
|
62
|
+
} = component.properties();
|
|
63
|
+
const {
|
|
64
|
+
params: { phrase, guideCategory, tag }
|
|
65
|
+
} = input;
|
|
66
|
+
return container.getAsync("dataClient").then((dataClient) => {
|
|
67
|
+
return dataClient.fetch(DataType.GuideCategories, {
|
|
68
|
+
searchPhrase: matchFilters.search ? phrase : void 0,
|
|
69
|
+
tagId: matchFilters.tag ? tag : void 0
|
|
70
|
+
}).then(({ categories, matches }) => {
|
|
71
|
+
var _a;
|
|
72
|
+
const parent = findParentAndSiblings(categories, {
|
|
73
|
+
matches,
|
|
74
|
+
id: "0",
|
|
75
|
+
title: rootCategoryHeader,
|
|
76
|
+
items: categories
|
|
77
|
+
}, guideCategory);
|
|
78
|
+
return next({
|
|
79
|
+
parent,
|
|
80
|
+
categories: (_a = parent == null ? void 0 : parent.items) == null ? void 0 : _a.filter(filterEmptyCategories)
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}).then(() => {
|
|
87
|
+
unsubscribe();
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
export { GuideCategoryDropdownComponent as default };
|
|
91
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/guide-category-dropdown-component.ts"],"sourcesContent":["import { MatchFilterProperties } from '@telia-ace/knowledge-widget-component-utilities';\r\nimport { Category, createEventSubscriber, extendComponent } from '@telia-ace/knowledge-widget-core';\r\nimport { CategoriesResult, DataType } from '@telia-ace/knowledge-widget-types-grid';\r\nimport { createReactComponent } from '@telia-ace/knowledge-widget-ui';\r\nimport { Container } from '@webprovisions/platform';\r\n\r\nconst findParentAndSiblings = (\r\n categories: Category[],\r\n root: Category,\r\n currentCategoryId: string\r\n): Category | undefined => {\r\n if (!currentCategoryId || currentCategoryId.length < 1) {\r\n return root;\r\n }\r\n return findRecursive(categories, root, null, currentCategoryId);\r\n};\r\n\r\nconst findRecursive = (\r\n categories: Category[],\r\n root: Category,\r\n previous: Category | null,\r\n currentCategoryId: string\r\n): Category | undefined => {\r\n const filtered = categories.find((c) => c.id === currentCategoryId);\r\n if (filtered || !currentCategoryId) {\r\n if (!previous) {\r\n return root;\r\n }\r\n return previous;\r\n }\r\n\r\n for (let i = 0; i < categories.length; i += 1) {\r\n const cat = categories[i];\r\n if (cat.items) {\r\n const result = findRecursive(cat.items, root, cat, currentCategoryId);\r\n if (result) {\r\n return result;\r\n }\r\n }\r\n }\r\n};\r\n\r\nconst filterEmptyCategories = (category: Category) => category.matches && category.matches > 0;\r\n\r\nexport type GuideCategoryDropdownComponentProps = {\r\n matchFilters?: Partial<MatchFilterProperties>;\r\n rootCategoryHeader: string;\r\n route?: string;\r\n categoryAriaLabel?: string;\r\n activeCategoryAriaLabel?: string;\r\n parent?: Category; // internal\r\n categories?: Category[]; // internal\r\n showMatchCount?: boolean;\r\n fallbackOnInitialRoute?: boolean;\r\n};\r\n\r\nexport default (container: Container) => {\r\n const { events } = container.get('$widget');\r\n const [subscribe, unsubscribe] = createEventSubscriber(events);\r\n\r\n return createReactComponent(\r\n container,\r\n 'guide-category-dropdown',\r\n import('./guide-category-dropdown'),\r\n (component) => {\r\n const fetch = (params: { [key: string]: any }) => {\r\n component.writeProperties({ loading: true });\r\n component.actions.dispatch('fetch', { params }).then(() => {\r\n component.writeProperties({ loading: false });\r\n });\r\n };\r\n\r\n component.actions.create('fetch', ({ parent, categories }) => {\r\n component.writeProperties({\r\n parent,\r\n categories,\r\n loading: false,\r\n });\r\n });\r\n\r\n container.getAsync('router').then((router) => {\r\n const { params } = router.getRouteData();\r\n fetch(params);\r\n });\r\n\r\n subscribe('router:changed', (event: any, { current }: any) => {\r\n fetch(current.routeData.params);\r\n });\r\n }\r\n )\r\n .then(() => {\r\n return extendComponent(container, 'guide-category-dropdown', (component) => {\r\n component.actions.watch('guide-category-dropdown.fetch', (input, next) => {\r\n const {\r\n matchFilters = {\r\n search: false,\r\n tag: false,\r\n },\r\n rootCategoryHeader,\r\n } = component.properties<GuideCategoryDropdownComponentProps>();\r\n const {\r\n params: { phrase, guideCategory, tag },\r\n } = input;\r\n return container.getAsync('dataClient').then((dataClient) => {\r\n return dataClient\r\n .fetch(DataType.GuideCategories, {\r\n searchPhrase: matchFilters.search ? phrase : undefined,\r\n tagId: matchFilters.tag ? tag : undefined,\r\n })\r\n .then(({ categories, matches }: CategoriesResult) => {\r\n const parent = findParentAndSiblings(\r\n categories,\r\n {\r\n matches,\r\n id: '0',\r\n title: rootCategoryHeader,\r\n items: categories,\r\n },\r\n guideCategory\r\n );\r\n\r\n return next({\r\n parent,\r\n categories: parent?.items?.filter(filterEmptyCategories),\r\n });\r\n });\r\n });\r\n });\r\n });\r\n })\r\n .then(() => {\r\n unsubscribe();\r\n });\r\n};\r\n"],"names":[],"mappings":";;;AAMA,MAAM,wBAAwB,CAC1B,YACA,MACA,sBACuB;AACvB,MAAI,CAAC,qBAAqB,kBAAkB,SAAS,GAAG;AAC7C,WAAA;AAAA,EACX;AACA,SAAO,cAAc,YAAY,MAAM,MAAM,iBAAiB;AAClE;AAEA,MAAM,gBAAgB,CAClB,YACA,MACA,UACA,sBACuB;AACvB,QAAM,WAAW,WAAW,KAAK,CAAC,MAAM,EAAE,OAAO,iBAAiB;AAC9D,MAAA,YAAY,CAAC,mBAAmB;AAChC,QAAI,CAAC,UAAU;AACJ,aAAA;AAAA,IACX;AACO,WAAA;AAAA,EACX;AAEA,WAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK,GAAG;AAC3C,UAAM,MAAM,WAAW;AACvB,QAAI,IAAI,OAAO;AACX,YAAM,SAAS,cAAc,IAAI,OAAO,MAAM,KAAK,iBAAiB;AACpE,UAAI,QAAQ;AACD,eAAA;AAAA,MACX;AAAA,IACJ;AAAA,EACJ;AACJ;AAEA,MAAM,wBAAwB,CAAC,aAAuB,SAAS,WAAW,SAAS,UAAU;AAc7F,IAAe,iCAAA,CAAC,cAAyB;AACrC,QAAM,EAAE,WAAW,UAAU,IAAI,SAAS;AAC1C,QAAM,CAAC,WAAW,eAAe,sBAAsB,MAAM;AAE7D,SAAO,qBACH,WACA,2BACA,OAAO,iCACP,CAAC,cAAc;AACL,UAAA,QAAQ,CAAC,WAAmC;AAC9C,gBAAU,gBAAgB,EAAE,SAAS,KAAM,CAAA;AACjC,gBAAA,QAAQ,SAAS,SAAS,EAAE,OAAQ,CAAA,EAAE,KAAK,MAAM;AACvD,kBAAU,gBAAgB,EAAE,SAAS,MAAO,CAAA;AAAA,MAAA,CAC/C;AAAA,IAAA;AAGL,cAAU,Q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@@ -1,34 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/knowledge-widget-components-guide-category-dropdown",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Guide category dropdown component for ACE Knowledge Widgets.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"author": "Telia Company AB",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"telia"
|
|
9
9
|
],
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"module": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
12
|
"files": [
|
|
13
13
|
"LICENSE.txt",
|
|
14
14
|
"README.md",
|
|
15
|
-
"
|
|
16
|
-
"lib-esm/"
|
|
15
|
+
"dist/"
|
|
17
16
|
],
|
|
18
17
|
"publishConfig": {
|
|
19
18
|
"access": "public"
|
|
20
19
|
},
|
|
21
20
|
"scripts": {
|
|
22
|
-
"clean": "
|
|
23
|
-
"
|
|
21
|
+
"clean": "rimraf ./dist",
|
|
22
|
+
"precompile": "tsc -emitDeclarationOnly",
|
|
23
|
+
"compile": "vite build"
|
|
24
24
|
},
|
|
25
25
|
"sideEffects": false,
|
|
26
|
-
"typings": "lib/index.d.ts",
|
|
27
26
|
"dependencies": {
|
|
28
|
-
"@telia-ace/knowledge-widget-component-utilities": "^1.0.
|
|
29
|
-
"@telia-ace/knowledge-widget-core": "^1.0.
|
|
30
|
-
"@telia-ace/knowledge-widget-types-grid": "^1.0.
|
|
31
|
-
"@telia-ace/knowledge-widget-ui": "^1.0.
|
|
27
|
+
"@telia-ace/knowledge-widget-component-utilities": "^1.0.8",
|
|
28
|
+
"@telia-ace/knowledge-widget-core": "^1.0.7",
|
|
29
|
+
"@telia-ace/knowledge-widget-types-grid": "^1.0.14",
|
|
30
|
+
"@telia-ace/knowledge-widget-ui": "^1.0.11",
|
|
32
31
|
"@telia-ace/widget-utilities": "^1.0.1",
|
|
33
32
|
"@webprovisions/platform": "^1.1.2"
|
|
34
33
|
},
|
|
@@ -42,5 +41,5 @@
|
|
|
42
41
|
"@types/react-dom": "^16.8.0",
|
|
43
42
|
"@types/styled-components": "^5.1.7"
|
|
44
43
|
},
|
|
45
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "15dba08c1ba1c3c117353e50a2586be05a966288"
|
|
46
45
|
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { MatchFilterProperties } from '@telia-ace/knowledge-widget-component-utilities';
|
|
2
|
-
import { Category } from '@telia-ace/knowledge-widget-core';
|
|
3
|
-
import { Container } from '@webprovisions/platform';
|
|
4
|
-
export declare type GuideCategoryDropdownComponentProps = {
|
|
5
|
-
matchFilters?: Partial<MatchFilterProperties>;
|
|
6
|
-
rootCategoryHeader: string;
|
|
7
|
-
route?: string;
|
|
8
|
-
categoryAriaLabel?: string;
|
|
9
|
-
activeCategoryAriaLabel?: string;
|
|
10
|
-
parent?: Category;
|
|
11
|
-
categories?: Category[];
|
|
12
|
-
showMatchCount?: boolean;
|
|
13
|
-
fallbackOnInitialRoute?: boolean;
|
|
14
|
-
};
|
|
15
|
-
declare const _default: (container: Container) => Promise<void>;
|
|
16
|
-
export default _default;
|