-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(badge): update variants and their corresponding styles (#249)
- Loading branch information
Showing
11 changed files
with
965 additions
and
869 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 74 additions & 4 deletions
78
packages/web-components/src/badge-wrapper/badge-wrapper.style.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,86 @@ | ||
import { css } from "lit"; | ||
|
||
export default css` | ||
.wrapper { | ||
.root.left .badge { | ||
transform: translate(-50%, -50%); | ||
} | ||
.root.right .badge { | ||
transform: translate(50%, -50%); | ||
} | ||
.root.rectangle.top .badge { | ||
top: 0; | ||
} | ||
.root.rectangle.middle .badge { | ||
top: 50%; | ||
} | ||
.root.rectangle.left .badge { | ||
left: 0; | ||
} | ||
.root.rectangle.right .badge { | ||
right: 0; | ||
} | ||
.root.circle.top .badge { | ||
top: 14.5%; | ||
} | ||
.root.circle.middle .badge { | ||
top: 50%; | ||
} | ||
.root.circle:not(.middle).left .badge { | ||
left: 14.5%; | ||
} | ||
.root.circle:not(.middle).right .badge { | ||
right: 14.5%; | ||
} | ||
.root.pill.top .badge { | ||
top: 6px; | ||
} | ||
.root.pill.middle .badge { | ||
top: 50%; | ||
} | ||
.root.pill:not(.middle).left .badge { | ||
left: 6px; | ||
} | ||
.root.pill:not(.middle).right .badge { | ||
right: 6px; | ||
} | ||
.root.pill.middle.left .badge { | ||
left: 0; | ||
} | ||
.root.pill.middle.right .badge { | ||
right: 0; | ||
} | ||
.root { | ||
position: relative; | ||
display: inline-flex; | ||
flex-shrink: 0; | ||
vertical-align: middle; | ||
z-index: 2; | ||
} | ||
.badge { | ||
display: inline-flex; | ||
align-items: center; | ||
justify-content: center; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
transform: translate(-50%, -30%); | ||
} | ||
`; |
38 changes: 29 additions & 9 deletions
38
packages/web-components/src/badge-wrapper/badge-wrapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,39 @@ | ||
import { html, LitElement } from "lit"; | ||
import { property } from "lit/decorators.js"; | ||
import { classMap } from "lit/directives/class-map.js"; | ||
import { Slots } from "./constants"; | ||
|
||
export class BadgeWrapper extends LitElement { | ||
@property({ type: String, attribute: "anchor-shape" }) | ||
public anchorShape: "rectangle" | "circle" | "pill" = "rectangle"; | ||
|
||
@property({ type: String, attribute: "badge-side" }) | ||
public badgeSide: "left" | "right" = "right"; | ||
|
||
@property({ type: String, attribute: "badge-alignment" }) | ||
public badgeAlignment: "top" | "middle" = "top"; | ||
|
||
protected override render() { | ||
const rootClasses = classMap({ | ||
root: true, | ||
[this.anchorShape]: true, | ||
[this.badgeAlignment]: true, | ||
[this.badgeSide]: true, | ||
}); | ||
|
||
return html` | ||
<span | ||
class="wrapper" | ||
part="wrapper" | ||
<div | ||
class=${rootClasses} | ||
part="root" | ||
> | ||
<slot></slot> | ||
<slot | ||
class="badge" | ||
name="badge" | ||
part="badge" | ||
></slot> | ||
</span> | ||
<div | ||
class=${Slots.BADGE} | ||
part=${Slots.BADGE} | ||
> | ||
<slot name=${Slots.BADGE}></slot> | ||
</div> | ||
</div> | ||
`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const Slots = { | ||
DEFAULT: "", | ||
BADGE: "badge", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.