@telia-ace/knowledge-widget-components-tag-list 0.0.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/index.d.ts +3 -0
- package/index.js +1 -0
- package/index.mjs +48 -0
- package/package.json +25 -0
- package/tag-list-bd4c0029.js +83 -0
- package/tag-list-component.d.ts +17 -0
- package/tag-list-d143c7b3.mjs +193 -0
- package/tag-list.d.ts +7 -0
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const d=require("@telia-ace/knowledge-data-client"),g=require("@telia-ace/knowledge-widget-core"),p=require("@telia-ace/knowledge-widget-ui"),b=s=>p.createReactComponent(s,"tag-list",Promise.resolve().then(()=>require("./tag-list-bd4c0029.js")),t=>{const{events:o}=s.get("$widget"),[c,u]=g.createEventSubscriber(o);t.actions.create("fetch",({items:e=[]})=>t.actions.dispatch("fetched",{items:e,loading:!0})),t.actions.create("fetched",e=>t.writeProperties({...e,loading:!1}));const a=(e={})=>{t.writeProperties({loading:!0,error:void 0}),t.actions.dispatch("fetch",e)};return s.getAsync("router").then(e=>{const{params:i}=e.getRouteData();a(i)}),c("router:changed",(e,{current:i})=>{a(i.routeData.params)}),()=>{u()}}).then(()=>g.extendComponent(s,"tag-list",t=>{t.actions.watch("tag-list.fetch",(o,c)=>d.DataClient.getInstance(s).then(u=>{const{static:a=!1,rootTagLabel:e=""}=t.properties(),{phrase:i,guideCategory:h,tag:l}=o;return u.fetch(a?d.DataType.Tags:d.DataType.TagsOnGuides,{searchPhrase:i,categories:h,tagId:l}).then((n=[])=>{if(a){const r=n.findIndex(f=>f.id==="0");r>-1&&n.unshift(n.splice(r,1)[0])}return c({items:n.map(r=>(r.id==="0"&&(r.title=e),r))})}).catch(n=>c({items:[]}))}))}));module.exports=b;
|
package/index.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { DataClient as p, DataType as d } from "@telia-ace/knowledge-data-client";
|
|
2
|
+
import { createEventSubscriber as l, extendComponent as m } from "@telia-ace/knowledge-widget-core";
|
|
3
|
+
import { createReactComponent as b } from "@telia-ace/knowledge-widget-ui";
|
|
4
|
+
const w = (a) => b(
|
|
5
|
+
a,
|
|
6
|
+
"tag-list",
|
|
7
|
+
import("./tag-list-d143c7b3.mjs"),
|
|
8
|
+
(e) => {
|
|
9
|
+
const { events: o } = a.get("$widget"), [n, u] = l(o);
|
|
10
|
+
e.actions.create("fetch", ({ items: t = [] }) => e.actions.dispatch("fetched", {
|
|
11
|
+
items: t,
|
|
12
|
+
loading: !0
|
|
13
|
+
})), e.actions.create("fetched", (t) => e.writeProperties({ ...t, loading: !1 }));
|
|
14
|
+
const s = (t = {}) => {
|
|
15
|
+
e.writeProperties({ loading: !0, error: void 0 }), e.actions.dispatch("fetch", t);
|
|
16
|
+
};
|
|
17
|
+
return a.getAsync("router").then((t) => {
|
|
18
|
+
const { params: i } = t.getRouteData();
|
|
19
|
+
s(i);
|
|
20
|
+
}), n("router:changed", (t, { current: i }) => {
|
|
21
|
+
s(i.routeData.params);
|
|
22
|
+
}), () => {
|
|
23
|
+
u();
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
).then(() => m(a, "tag-list", (e) => {
|
|
27
|
+
e.actions.watch("tag-list.fetch", (o, n) => p.getInstance(a).then(
|
|
28
|
+
(u) => {
|
|
29
|
+
const { static: s = !1, rootTagLabel: t = "" } = e.properties(), { phrase: i, guideCategory: h, tag: f } = o;
|
|
30
|
+
return u.fetch(s ? d.Tags : d.TagsOnGuides, {
|
|
31
|
+
searchPhrase: i,
|
|
32
|
+
categories: h,
|
|
33
|
+
tagId: f
|
|
34
|
+
}).then((c = []) => {
|
|
35
|
+
if (s) {
|
|
36
|
+
const r = c.findIndex((g) => g.id === "0");
|
|
37
|
+
r > -1 && c.unshift(c.splice(r, 1)[0]);
|
|
38
|
+
}
|
|
39
|
+
return n({
|
|
40
|
+
items: c.map((r) => (r.id === "0" && (r.title = t), r))
|
|
41
|
+
});
|
|
42
|
+
}).catch((c) => n({ items: [] }));
|
|
43
|
+
}
|
|
44
|
+
));
|
|
45
|
+
}));
|
|
46
|
+
export {
|
|
47
|
+
w as default
|
|
48
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@telia-ace/knowledge-widget-components-tag-list",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "./index.js",
|
|
5
|
+
"types": "./index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./index.mjs",
|
|
9
|
+
"require": "./index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@telia-ace/knowledge-widget-core": "*",
|
|
14
|
+
"@telia-ace/knowledge-data-client": "*",
|
|
15
|
+
"@telia-ace/knowledge-widget-ui": "*",
|
|
16
|
+
"@telia-ace/widget-utilities": "*",
|
|
17
|
+
"@telia-ace/knowledge-widget-component-utilities": "*",
|
|
18
|
+
"@webprovisions/platform": "^1.1.4"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@emotion/react": "11.11.1",
|
|
22
|
+
"@emotion/styled": "11.11.0",
|
|
23
|
+
"react": "18.2.0"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),u=require("@emotion/react"),l=require("@emotion/styled"),C=require("@telia-ace/knowledge-widget-component-utilities"),s=require("@telia-ace/knowledge-widget-ui"),y=require("@telia-ace/widget-utilities"),I=(e,t,o)=>e&&o?r.jsx(x,{symbol:o,size:18}):t?r.jsx(x,{symbol:t,size:18}):null,q=({className:e,...t})=>{const{route:o="search",items:h=[],header:$,loading:a=!1,style:c="badge",showMatchCount:w=!1,showIcons:S=!1,static:i=!1,fallbackOnInitialRoute:z=!1,itemAriaLabel:p}=s.useProperties(),j=s.useContainer(),{params:m}=s.useRouteData();if(!h.length&&(!a||i))return s.createEmptyComponent(j,{...t,className:y.appendClassNames(e,"humany-tag-list")});const v=c==="badge"?A:B;return r.jsx(R,{...t,"data-loading":!i&&a,className:y.appendClassNames(e,"humany-tag-list"),header:!i&&a?"":$,items:h,type:c,renderItem:n=>{const{id:b,title:f,defaultIcon:L,activeIcon:T,matches:d}=n,g=(m.tag?m.tag.split(","):[]).includes(n.id)||!m.tag&&n.id==="0",k=p&&p.replace("{{title}}",f).replace("{{matches}}",`${d}`);return r.jsx(M,{notAllowed:(i&&!d&&c==="pill").toString(),"data-tag":b,children:r.jsxs(v,{...C.initialRouteFallback(n,o,z,"tag"),role:"button","aria-pressed":g,"aria-label":k,disabled:i&&!d,selected:g,text:f,children:[S&&I(g,L,T),w&&r.jsx(U,{children:`(${d})`})]})},b)},children:!i&&r.jsx(s.Loader,{loading:a})})},R=l(s.ItemList)`
|
|
2
|
+
${s.contentBox}
|
|
3
|
+
${s.itemList}
|
|
4
|
+
${s.loadingOpacity}
|
|
5
|
+
justify-content: flex-start;
|
|
6
|
+
padding: ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.large}};
|
|
7
|
+
ul {
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-wrap: wrap;
|
|
10
|
+
${e=>e.type==="pill"&&u.css`
|
|
11
|
+
justify-content: center;
|
|
12
|
+
`}
|
|
13
|
+
|
|
14
|
+
li {
|
|
15
|
+
margin: 0 ${e=>{var t,o;return`${(t=e.theme.sizes)==null?void 0:t.small} ${(o=e.theme.sizes)==null?void 0:o.small}`}} 0;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
`,A=l(s.TextLink)`
|
|
19
|
+
padding: 8px 15px;
|
|
20
|
+
background-color: ${e=>{var t,o;return e.selected?(t=e.theme.colors)==null?void 0:t.text:(o=e.theme.colors)==null?void 0:o.primary}};
|
|
21
|
+
border-radius: ${e=>e.theme.borderRadius};
|
|
22
|
+
font-weight: 300;
|
|
23
|
+
font-size: ${e=>{var t;return(t=e.theme.fonts)==null?void 0:t.normal}};
|
|
24
|
+
display: flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
color: #ffffff;
|
|
27
|
+
|
|
28
|
+
&:focus-visible {
|
|
29
|
+
${s.borderTabStyle}
|
|
30
|
+
padding: 6px 15px;
|
|
31
|
+
background-color: transparent;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@media (hover: hover) {
|
|
35
|
+
&:hover {
|
|
36
|
+
background-color: ${e=>{var t,o;return e.selected?(t=e.theme.colors)==null?void 0:t.primary:(o=e.theme.colors)==null?void 0:o.text}};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
`,B=l(s.TextLink)`
|
|
40
|
+
border: 1px solid
|
|
41
|
+
${e=>{var t;return e.selected?(t=e.theme.colors)==null?void 0:t.text:"transparent"}};
|
|
42
|
+
line-height: 2em;
|
|
43
|
+
border-radius: 1em;
|
|
44
|
+
padding: 0 0.5em;
|
|
45
|
+
display: flex;
|
|
46
|
+
align-items: center;
|
|
47
|
+
font-weight: ${e=>e.selected?"normal":300};
|
|
48
|
+
color: ${e=>{var t;return(t=e.theme.colors)==null?void 0:t.text}};
|
|
49
|
+
|
|
50
|
+
&:disabled {
|
|
51
|
+
color: ${e=>{var t;return(t=e.theme.colors)==null?void 0:t.textLight}};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&:focus-visible {
|
|
55
|
+
${s.borderTabStyle}
|
|
56
|
+
border-radius: 1em;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@media (hover: hover) {
|
|
60
|
+
&:hover {
|
|
61
|
+
border: 1px solid ${e=>{var t;return(t=e.theme.colors)==null?void 0:t.text}};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
${e=>e.disabled&&u.css`
|
|
66
|
+
opacity: 0.5;
|
|
67
|
+
`}
|
|
68
|
+
`,U=l(s.Text)`
|
|
69
|
+
order: 2;
|
|
70
|
+
margin-left: ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.small}};
|
|
71
|
+
`,x=l(s.SymbolBadge)`
|
|
72
|
+
margin-right: ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.small}};
|
|
73
|
+
${e=>{if(e.symbol.type==="Uri")return`
|
|
74
|
+
width: ${e.size}px;
|
|
75
|
+
height: ${e.size}px;
|
|
76
|
+
`;if(e.symbol.type==="FontAwesome")return`
|
|
77
|
+
font-size: ${e.size}px;
|
|
78
|
+
`}}
|
|
79
|
+
`,M=l.li`
|
|
80
|
+
${e=>e.notAllowed==="true"&&u.css`
|
|
81
|
+
cursor: not-allowed;
|
|
82
|
+
`}
|
|
83
|
+
`;exports.default=q;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Tag } from '../../../knowledge/core/src/index.ts';
|
|
2
|
+
import { Container } from '@webprovisions/platform';
|
|
3
|
+
|
|
4
|
+
export type TagListComponentProps = {
|
|
5
|
+
header: string;
|
|
6
|
+
route?: string;
|
|
7
|
+
items: Tag[];
|
|
8
|
+
style?: 'badge' | 'pill';
|
|
9
|
+
showMatchCount?: boolean;
|
|
10
|
+
showIcons?: boolean;
|
|
11
|
+
static?: boolean;
|
|
12
|
+
rootTagLabel?: string;
|
|
13
|
+
fallbackOnInitialRoute?: boolean;
|
|
14
|
+
itemAriaLabel?: string;
|
|
15
|
+
};
|
|
16
|
+
declare const TagListComponent: (container: Container) => Promise<void>;
|
|
17
|
+
export default TagListComponent;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { jsx as r, jsxs as j } from "react/jsx-runtime";
|
|
2
|
+
import { css as h } from "@emotion/react";
|
|
3
|
+
import a from "@emotion/styled";
|
|
4
|
+
import { initialRouteFallback as A } from "@telia-ace/knowledge-widget-component-utilities";
|
|
5
|
+
import { useProperties as B, useContainer as R, useRouteData as F, createEmptyComponent as M, Loader as N, ItemList as O, contentBox as P, itemList as D, loadingOpacity as E, TextLink as $, borderTabStyle as x, Text as U, SymbolBadge as q } from "@telia-ace/knowledge-widget-ui";
|
|
6
|
+
import { appendClassNames as y } from "@telia-ace/widget-utilities";
|
|
7
|
+
const G = (e, t, o) => e && o ? /* @__PURE__ */ r(b, { symbol: o, size: 18 }) : t ? /* @__PURE__ */ r(b, { symbol: t, size: 18 }) : null, oe = ({ className: e, ...t }) => {
|
|
8
|
+
const {
|
|
9
|
+
route: o = "search",
|
|
10
|
+
items: g = [],
|
|
11
|
+
header: z,
|
|
12
|
+
loading: l = !1,
|
|
13
|
+
style: d = "badge",
|
|
14
|
+
showMatchCount: w = !1,
|
|
15
|
+
showIcons: v = !1,
|
|
16
|
+
static: s = !1,
|
|
17
|
+
fallbackOnInitialRoute: L = !1,
|
|
18
|
+
itemAriaLabel: f
|
|
19
|
+
} = B(), S = R(), { params: c } = F();
|
|
20
|
+
if (!g.length && (!l || s))
|
|
21
|
+
return M(S, {
|
|
22
|
+
...t,
|
|
23
|
+
className: y(e, "humany-tag-list")
|
|
24
|
+
});
|
|
25
|
+
const I = d === "badge" ? J : K;
|
|
26
|
+
return /* @__PURE__ */ r(
|
|
27
|
+
H,
|
|
28
|
+
{
|
|
29
|
+
...t,
|
|
30
|
+
"data-loading": !s && l,
|
|
31
|
+
className: y(e, "humany-tag-list"),
|
|
32
|
+
header: !s && l ? "" : z,
|
|
33
|
+
items: g,
|
|
34
|
+
type: d,
|
|
35
|
+
renderItem: (i) => {
|
|
36
|
+
const { id: p, title: u, defaultIcon: T, activeIcon: k, matches: n } = i, m = (c.tag ? c.tag.split(",") : []).includes(i.id) || !c.tag && i.id === "0", C = f && f.replace("{{title}}", u).replace("{{matches}}", `${n}`);
|
|
37
|
+
return /* @__PURE__ */ r(
|
|
38
|
+
V,
|
|
39
|
+
{
|
|
40
|
+
notAllowed: (s && !n && d === "pill").toString(),
|
|
41
|
+
"data-tag": p,
|
|
42
|
+
children: /* @__PURE__ */ j(
|
|
43
|
+
I,
|
|
44
|
+
{
|
|
45
|
+
...A(
|
|
46
|
+
i,
|
|
47
|
+
o,
|
|
48
|
+
L,
|
|
49
|
+
"tag"
|
|
50
|
+
),
|
|
51
|
+
role: "button",
|
|
52
|
+
"aria-pressed": m,
|
|
53
|
+
"aria-label": C,
|
|
54
|
+
disabled: s && !n,
|
|
55
|
+
selected: m,
|
|
56
|
+
text: u,
|
|
57
|
+
children: [
|
|
58
|
+
v && G(m, T, k),
|
|
59
|
+
w && /* @__PURE__ */ r(Q, { children: `(${n})` })
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
},
|
|
64
|
+
p
|
|
65
|
+
);
|
|
66
|
+
},
|
|
67
|
+
children: !s && /* @__PURE__ */ r(N, { loading: l })
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
}, H = a(O)`
|
|
71
|
+
${P}
|
|
72
|
+
${D}
|
|
73
|
+
${E}
|
|
74
|
+
justify-content: flex-start;
|
|
75
|
+
padding: ${(e) => {
|
|
76
|
+
var t;
|
|
77
|
+
return (t = e.theme.sizes) == null ? void 0 : t.large;
|
|
78
|
+
}};
|
|
79
|
+
ul {
|
|
80
|
+
display: flex;
|
|
81
|
+
flex-wrap: wrap;
|
|
82
|
+
${(e) => e.type === "pill" && h`
|
|
83
|
+
justify-content: center;
|
|
84
|
+
`}
|
|
85
|
+
|
|
86
|
+
li {
|
|
87
|
+
margin: 0 ${(e) => {
|
|
88
|
+
var t, o;
|
|
89
|
+
return `${(t = e.theme.sizes) == null ? void 0 : t.small} ${(o = e.theme.sizes) == null ? void 0 : o.small}`;
|
|
90
|
+
}} 0;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
`, J = a($)`
|
|
94
|
+
padding: 8px 15px;
|
|
95
|
+
background-color: ${(e) => {
|
|
96
|
+
var t, o;
|
|
97
|
+
return e.selected ? (t = e.theme.colors) == null ? void 0 : t.text : (o = e.theme.colors) == null ? void 0 : o.primary;
|
|
98
|
+
}};
|
|
99
|
+
border-radius: ${(e) => e.theme.borderRadius};
|
|
100
|
+
font-weight: 300;
|
|
101
|
+
font-size: ${(e) => {
|
|
102
|
+
var t;
|
|
103
|
+
return (t = e.theme.fonts) == null ? void 0 : t.normal;
|
|
104
|
+
}};
|
|
105
|
+
display: flex;
|
|
106
|
+
align-items: center;
|
|
107
|
+
color: #ffffff;
|
|
108
|
+
|
|
109
|
+
&:focus-visible {
|
|
110
|
+
${x}
|
|
111
|
+
padding: 6px 15px;
|
|
112
|
+
background-color: transparent;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@media (hover: hover) {
|
|
116
|
+
&:hover {
|
|
117
|
+
background-color: ${(e) => {
|
|
118
|
+
var t, o;
|
|
119
|
+
return e.selected ? (t = e.theme.colors) == null ? void 0 : t.primary : (o = e.theme.colors) == null ? void 0 : o.text;
|
|
120
|
+
}};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
`, K = a($)`
|
|
124
|
+
border: 1px solid
|
|
125
|
+
${(e) => {
|
|
126
|
+
var t;
|
|
127
|
+
return e.selected ? (t = e.theme.colors) == null ? void 0 : t.text : "transparent";
|
|
128
|
+
}};
|
|
129
|
+
line-height: 2em;
|
|
130
|
+
border-radius: 1em;
|
|
131
|
+
padding: 0 0.5em;
|
|
132
|
+
display: flex;
|
|
133
|
+
align-items: center;
|
|
134
|
+
font-weight: ${(e) => e.selected ? "normal" : 300};
|
|
135
|
+
color: ${(e) => {
|
|
136
|
+
var t;
|
|
137
|
+
return (t = e.theme.colors) == null ? void 0 : t.text;
|
|
138
|
+
}};
|
|
139
|
+
|
|
140
|
+
&:disabled {
|
|
141
|
+
color: ${(e) => {
|
|
142
|
+
var t;
|
|
143
|
+
return (t = e.theme.colors) == null ? void 0 : t.textLight;
|
|
144
|
+
}};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
&:focus-visible {
|
|
148
|
+
${x}
|
|
149
|
+
border-radius: 1em;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@media (hover: hover) {
|
|
153
|
+
&:hover {
|
|
154
|
+
border: 1px solid ${(e) => {
|
|
155
|
+
var t;
|
|
156
|
+
return (t = e.theme.colors) == null ? void 0 : t.text;
|
|
157
|
+
}};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
${(e) => e.disabled && h`
|
|
162
|
+
opacity: 0.5;
|
|
163
|
+
`}
|
|
164
|
+
`, Q = a(U)`
|
|
165
|
+
order: 2;
|
|
166
|
+
margin-left: ${(e) => {
|
|
167
|
+
var t;
|
|
168
|
+
return (t = e.theme.sizes) == null ? void 0 : t.small;
|
|
169
|
+
}};
|
|
170
|
+
`, b = a(q)`
|
|
171
|
+
margin-right: ${(e) => {
|
|
172
|
+
var t;
|
|
173
|
+
return (t = e.theme.sizes) == null ? void 0 : t.small;
|
|
174
|
+
}};
|
|
175
|
+
${(e) => {
|
|
176
|
+
if (e.symbol.type === "Uri")
|
|
177
|
+
return `
|
|
178
|
+
width: ${e.size}px;
|
|
179
|
+
height: ${e.size}px;
|
|
180
|
+
`;
|
|
181
|
+
if (e.symbol.type === "FontAwesome")
|
|
182
|
+
return `
|
|
183
|
+
font-size: ${e.size}px;
|
|
184
|
+
`;
|
|
185
|
+
}}
|
|
186
|
+
`, V = a.li`
|
|
187
|
+
${(e) => e.notAllowed === "true" && h`
|
|
188
|
+
cursor: not-allowed;
|
|
189
|
+
`}
|
|
190
|
+
`;
|
|
191
|
+
export {
|
|
192
|
+
oe as default
|
|
193
|
+
};
|