Skip to content

Commit

Permalink
refactor: extract message styles into reusable CSS literal (#8242)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Nov 29, 2024
1 parent 0430bb1 commit c63be0f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 38 deletions.
8 changes: 8 additions & 0 deletions packages/message-list/src/vaadin-message-styles.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @license
* Copyright (c) 2021 - 2024 Vaadin Ltd..
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import type { CSSResult } from 'lit';

export const messageStyles: CSSResult;
43 changes: 43 additions & 0 deletions packages/message-list/src/vaadin-message-styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @license
* Copyright (c) 2021 - 2024 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import { css } from 'lit';

export const messageStyles = css`
:host {
display: flex;
flex-direction: row;
outline: none;
}
:host([hidden]) {
display: none !important;
}
[part='content'] {
display: flex;
flex-direction: column;
flex-grow: 1;
}
[part='header'] {
align-items: baseline;
display: flex;
flex-flow: row wrap;
}
[part='name'] {
font-weight: 500;
}
[part='message'] {
white-space: pre-wrap;
}
::slotted([slot='avatar']) {
--vaadin-avatar-outline-width: 0;
flex-shrink: 0;
}
`;
42 changes: 4 additions & 38 deletions packages/message-list/src/vaadin-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import '@vaadin/avatar/src/vaadin-avatar.js';
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
import { MessageMixin } from './vaadin-message-mixin.js';
import { messageStyles } from './vaadin-message-styles.js';

registerStyles('vaadin-message', messageStyles, { moduleId: 'vaadin-message-styles' });

/**
* `<vaadin-message>` is a Web Component for showing a single message with an author, message and time.
Expand Down Expand Up @@ -48,43 +51,6 @@ import { MessageMixin } from './vaadin-message-mixin.js';
class Message extends MessageMixin(ElementMixin(ThemableMixin(PolymerElement))) {
static get template() {
return html`
<style>
:host {
display: flex;
flex-direction: row;
outline: none;
}
:host([hidden]) {
display: none !important;
}
[part='content'] {
display: flex;
flex-direction: column;
flex-grow: 1;
}
[part='header'] {
align-items: baseline;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
[part='name'] {
font-weight: 500;
}
[part='message'] {
white-space: pre-wrap;
}
::slotted([slot='avatar']) {
--vaadin-avatar-outline-width: 0px;
flex-shrink: 0;
}
</style>
<slot name="avatar"></slot>
<div part="content">
<div part="header">
Expand Down

0 comments on commit c63be0f

Please sign in to comment.