Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui-kit/chat-footer): component #586

Merged
merged 7 commits into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 20 additions & 81 deletions ui/demo-pwa/src/page-chat.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import {customElement, AlwatrSmartElement, css, html, map} from '@alwatr/element';
import {l10n} from '@alwatr/i18n';
import {customElement, AlwatrSmartElement, css, html} from '@alwatr/element';

import '@alwatr/ui-kit/chat/chat-avatar.js';
import '@alwatr/ui-kit/chat/chat-bubble.js';
import '@alwatr/ui-kit/chat/chat-message.js';
import '@alwatr/ui-kit/chat/chat-text-input.js';
import '@alwatr/ui-kit/chat/chat-footer.js';
import '@alwatr/ui-kit/chat/chat-list.js';
import '@alwatr/ui-kit/icon-button/standard-icon-button.js';

import type {ChatStorage} from '@alwatr/ui-kit/chat/chat-list.js';

Expand Down Expand Up @@ -94,100 +89,44 @@ const chatStorage: ChatStorage = {
},
};

const messageListShort = Object.values(chatStorage.data).splice(0, 5);

/**
* Alwatr Demo Home Page
*/
@customElement('alwatr-page-chat')
export class AlwatrPageHome extends AlwatrSmartElement {
static override styles = css`
:host {
display: block;
box-sizing: border-box;
height: 100%;
overflow-y: auto;
padding: var(--md-sys-spacing-side-padding);
}

p {
padding: var(--md-sys-spacing-track-2) var(--md-sys-spacing-track-1) var(--md-sys-spacing-track-1);
color: var(--md-sys-color-on-surface-variant);
background-color: var(--md-sys-color-surface-variant);
}
p.surface {
color: var(--md-sys-color-on-surface);
background-color: var(--md-sys-color-surface);
.alwatr-chat {
height: 100%;
}

.section-name {
display: block;
margin-bottom: var(--md-sys-spacing-track-1);
/* inside alwatr chat */
.alwatr-chat {
display: flex;
flex-direction: column;

color: var(--md-sys-color-on-secondary-container);
background-color: var(--md-sys-color-secondary-container);
}

alwatr-chat-message {
margin: var(--md-sys-spacing-track-1) 0;
alwatr-chat-list {
flex-grow: 1;
overflow-y: auto;
background-color: transparent;
color: inherit;
}
`;

override render(): unknown {
super.render();
return html`
text on surface

<p @click=${this._changeLocale}>text on surface-variant</p>

<p>
<span class="section-name">alwatr-standard-icon-button</span>
<alwatr-standard-icon-button .icon=${'menu-outline'}></alwatr-standard-icon-button>
<alwatr-standard-icon-button .icon=${'mic-outline'}></alwatr-standard-icon-button>
<alwatr-standard-icon-button .icon=${'happy-outline'}></alwatr-standard-icon-button>
<alwatr-standard-icon-button .icon=${'send'}></alwatr-standard-icon-button>
</p>

<p class="surface">
<span class="section-name">alwatr-chat-text-input</span>
<alwatr-chat-text-input></alwatr-chat-text-input>
</p>

<p>
<span class="section-name">alwatr-chat-avatar</span>
${map(messageListShort, (message) => html`<alwatr-chat-avatar .user=${message.from}></alwatr-chat-avatar>`)}
</p>

<p>
<span class="section-name">alwatr-chat-bubble</span>
${map(
messageListShort,
(message) => html`
<alwatr-chat-bubble .text=${message.text} ?end-side=${message.from !== currentUser}></alwatr-chat-bubble>
`,
)}
</p>

<p>
<span class="section-name">alwatr-chat-message</span>
${map(
messageListShort,
(message) => html`
<alwatr-chat-message .message=${message} ?end-side=${message.from !== currentUser}></alwatr-chat-message>
`,
)}
</p>

<alwatr-chat-list .storage=${chatStorage} .currentUser=${currentUser}></alwatr-chat-list>
<main class="alwatr-chat">
<alwatr-chat-list .storage=${chatStorage} .currentUser=${currentUser}></alwatr-chat-list>
<alwatr-chat-footer></alwatr-chat-footer>
</main>
`;
}

protected _changeLocale(): void {
l10n.setLocal(
l10n.locale?.code !== l10n.config.defaultLocale.code
? l10n.config.defaultLocale
: {
code: 'fa-IR',
direction: 'rtl',
language: 'fa',
},
);
}
}
43 changes: 43 additions & 0 deletions ui/ui-kit/src/chat/chat-footer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {AlwatrDummyElement, css, customElement, html} from '@alwatr/element';

import './chat-text-input.js';
import '../icon-button/standard-icon-button.js';

declare global {
interface HTMLElementTagNameMap {
'alwatr-chat-footer': AlwatrChatFooter;
}
}

/**
* Alwatr chat footer element.
*/
@customElement('alwatr-chat-footer')
export class AlwatrChatFooter extends AlwatrDummyElement {
static override styles = css`
:host {
display: flex;

color: var(--md-sys-color-on-surface);
background-color: var(--md-sys-color-surface);

gap: var(--md-sys-spacing-track-1);
padding: var(--md-sys-spacing-track-2);

border-top-left-radius: var(--md-sys-shape-corner-large-top-top-left);
border-top-right-radius: var(--md-sys-shape-corner-large-top-top-right);
}

alwatr-standard-icon-button {
width: var(--md-sys-spacing-track-6);
height: var(--md-sys-spacing-track-6);
}
`;

override render(): unknown {
return html`
<alwatr-standard-icon-button .icon=${'happy-outline'}></alwatr-standard-icon-button>
<alwatr-chat-text-input></alwatr-chat-text-input>
`;
}
}
3 changes: 2 additions & 1 deletion ui/ui-kit/src/chat/chat-text-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export class AlwatrChatTextInput extends LocalizeMixin(AlwatrDummyElement) {
user-select: none;
align-items: flex-end;
vertical-align: middle;
border-radius: calc(var(--_height)/2);
border-radius: calc(var(--_height) / 2);
color: var(--md-sys-color-on-surface-variant);
background-color: var(--md-sys-color-surface-variant);
flex-grow: 1;
}

alwatr-standard-icon-button {
Expand Down