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

Convert hui-markdown-card to TypeScript/LitElement #1808

Merged
merged 4 commits into from
Oct 21, 2018

Conversation

iantrich
Copy link
Member

No description provided.


public setConfig(config: Config) {
if (!config.content) {
throw new Error("content required");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid Config: Content Required

return html`
${this.renderStyle()}
<ha-card .header="${this.config.title}">
<ha-markdown content="${this.config.content}"></ha-markdown>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure you can use .content here

-webkit-user-select: initial;
-moz-user-select: initial;
}
:host([no-title]) ha-markdown {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You removed this CSS and logic ???

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

padding-top: ${this.config!.title ? '0' : '16px'};

I believe this line covers all the previous CSS and logic that was removed

title?: string;
}

export class HuiMarkdownCard extends HassLocalizeLitMixin(LitElement)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why include HassLocalizeLitMixin?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I just extend LitElement instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HassLocalizeLitMixin provides a localize function for translating text. Since you're not using that, export class HuiMarkdownCard extends LitElement should be enough, yes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I should probably create a new pull to clean up my other conversion as well then: #1801

Thanks

ha-markdown {
display: block;
padding: 0 16px 16px;
padding-top: ${this.config!.title ? '0' : '16px'};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't make stylesheets dynamic, as it means the whole CSS stylesheet has to be re-rendered. I suggest you use a styleMap (example)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that in that case, you could also use a classMap (example), which I think I prefer, as that means we keep all styling inside renderStyle, meaning it can be overridden easily.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return html`
${this.renderStyle()}
<ha-card .header="${this.config.title}">
<ha-markdown class="markdown ${classMap({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets put each attribute/property on its own line example

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only if there is multiple. So ha-card with .header only is okay

@zsarnett
Copy link
Contributor

Seems ready after small change

@balloob balloob merged commit aca1ecf into home-assistant:master Oct 21, 2018
@ghost ghost removed the in progress label Oct 21, 2018
@iantrich iantrich deleted the typescript-markdown-card branch October 27, 2018 20:05
@github-actions github-actions bot locked and limited conversation to collaborators Jul 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants