Skip to content

Commit

Permalink
Merge pull request #281 from Tap30/refactor/button/add-parts
Browse files Browse the repository at this point in the history
feat(button): add css parts
  • Loading branch information
amir78729 authored Nov 25, 2024
2 parents 1f119d7 + 5e16668 commit bc27206
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/web-components/src/button/base/base-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ export abstract class BaseButton extends BaseClass implements FormSubmitter {
return html`
<button
id="root"
part="root"
class=${rootClasses}
part="button"
@click=${this._handleClick}
?disabled=${this.disabled}
type=${ifDefined(this.type)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export class IconButton extends BaseButton {
}

protected override renderContent(): TemplateResult {
return html`<div class="icon"><slot></slot></div>`;
return html`<div
class="icon"
part="icon"
>
<slot></slot>
</div>`;
}
}
15 changes: 11 additions & 4 deletions packages/web-components/src/button/standard/button.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { runAfterRepaint } from "../../utils";
import { html, type TemplateResult } from "lit";
import { state } from "lit/decorators.js";
import { getRenderRootSlot } from "../../utils";
import { getRenderRootSlot, runAfterRepaint } from "../../utils";
import { BaseButton } from "../base";
import { Slots } from "./constants";

Expand Down Expand Up @@ -37,18 +36,26 @@ export class Button extends BaseButton {

protected override renderContent(): TemplateResult {
return html`
<div class="body">
<div
class="body"
part="body"
>
<div
class="icon"
part=${Slots.LEADING_ICON}
?hidden=${!this._hasLeadingIcon}
>
<slot name=${Slots.LEADING_ICON}></slot>
</div>
<div class="content">
<div
class="content"
part="content"
>
<slot></slot>
</div>
<div
class="icon"
part=${Slots.TRAILING_ICON}
?hidden=${!this._hasTrailingIcon}
>
<slot name=${Slots.TRAILING_ICON}></slot>
Expand Down

0 comments on commit bc27206

Please sign in to comment.