blob: e9201ee121a6fcc1572c015680139ee985660e66 [file] [log] [blame]
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +02001import {css, html, LitElement} from 'lit';
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +02002import {customElement} from 'lit/decorators.js';
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +02003import {map} from 'lit/directives/map.js';
4import {unsafeHTML} from 'lit/directives/unsafe-html.js';
5
Adrià Vilanova Martínez5bdc4732022-05-31 20:12:21 +02006import {msg} from '../../../common/i18n';
Adrià Vilanova Martínez5bdc4732022-05-31 20:12:21 +02007import {DIALOG_STYLES} from '../../shared/dialog-styles';
8import {SHARED_STYLES} from '../../shared/shared-styles';
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +02009import {credits, i18nCredits} from '../../tsCredits';
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020010
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +020011@customElement('credits-dialog')
12export default class CreditsDialog extends LitElement {
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020013 static get styles() {
14 return [
15 SHARED_STYLES,
16 DIALOG_STYLES,
17 css`
18 dialog {
19 max-height: 430px;
20 width: 400px;
21 }
22
23 dialog[open] {
24 display: flex;
25 flex-direction: column;
26 }
27
28 .content_area h4 {
29 margin-bottom: 0;
30 }
31
32 .entry {
33 position: relative;
34 }
35
36 .entry a.homepage {
37 position: absolute;
38 inset-inline-end: 16px;
39 font-size: 14px;
40 }
41
42 p,
43 span {
44 font-size: 14px;
45 }
46
47 p.author {
48 margin-top: 7px;
49 }
50
51 #translators .name {
52 font-weight: bold;
53 }
54
55 .createdby {
56 font-style: italic;
57 }
58 `,
59 ];
60 }
61
62 constructor() {
63 super();
64 this.addEventListener('show-credits-dialog', this.showDialog);
65 }
66
67 render() {
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +020068 const translators = map(i18nCredits, (contributor) => {
69 const languagesArray =
70 contributor?.languages?.map?.((lang) => lang?.name ?? 'undefined');
71 const languages =
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020072 languagesArray.length > 0 ? ': ' + languagesArray.join(', ') : '';
73 return html`
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +020074 <li><span class="name">${contributor?.name}</span>${languages}</li>
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020075 `;
76 });
77
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +020078 const homepageMsg = msg('options_credits_homepage');
79 const creditsByMsg = msg('options_credits_by');
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020080
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +020081 const otherCredits = map(credits, (c) => {
82 const url = c.url ?
83 html` <a href=${c?.url} target="_blank" class="homepage">
84 ${homepageMsg}
85 </a>` :
86 undefined;
87 const license = c.license ? ' - ' + c.license : '';
88 const author = c.author ?
89 html` <p class="author">${creditsByMsg} ${c.author}${license}</p> ` :
90 undefined;
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020091
92 return html`
93 <div class="entry">
94 ${url}
95 <h4>${c?.name}</h4>
96 ${author}
97 </div>
98 `;
99 });
100
101 return html`
102 <dialog>
103 <div class="scrollable">
104 <h3>${msg('options_credits')}</h3>
105 <div class="entry createdby">
106 <div>${unsafeHTML(msg('options_credits_createdby'))}</div>
107 </div>
108 <div class="entry">
109 <a href="https://gtranslate.avm99963.com/" class="homepage" target="_blank">
110 ${msg('options_credits_homepage')}
111 </a>
112 <h4>${msg('options_credits_translations')}</h4>
113 <div>${msg('options_credits_translations_paragraph')}</div>
114 <ul id="translators">
115 ${translators}
116 </ul>
117 </div>
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +0200118 <div class="content_area">${otherCredits}</div>
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +0200119 </div>
120 <div class="action_buttons">
121 <button id="credits_ok" @click="${this.closeDialog}">
122 ${msg('options_ok')}
123 </button>
124 </div>
125 </dialog>
126 `;
127 }
128
129 showDialog() {
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +0200130 const dialog = this.renderRoot.querySelector('dialog');
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +0200131 dialog.showModal();
132 dialog.querySelector('.scrollable').scrollTo(0, 0);
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +0200133 (dialog.querySelector('#credits_ok') as HTMLElement).focus();
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +0200134 }
135
136 closeDialog() {
137 this.renderRoot.querySelector('dialog').close();
138 }
139}