-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f49c071
commit c76244c
Showing
5 changed files
with
258 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ module.exports = { | |
"calendar", | ||
"table", | ||
"split-button", | ||
"tag", | ||
], | ||
], | ||
}, | ||
|
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
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
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,93 @@ | ||
:host { | ||
display: inline-block; | ||
max-width: 100%; | ||
} | ||
|
||
.tag { | ||
--bg-color: var(--bl-color-neutral-full); | ||
--color: var(--bl-color-neutral-darker); | ||
--font: var(--bl-font-title-4-medium); | ||
--padding-vertical: var(--bl-size-2xs); | ||
--padding-horizontal: var(--bl-size-m); | ||
--margin-icon: var(--bl-size-2xs); | ||
--icon-size: var(--bl-size-m); | ||
--height: var(--bl-size-2xl); | ||
--border-radius: var(--bl-size-m); | ||
|
||
display: flex; | ||
gap: var(--margin-icon); | ||
justify-content: center; | ||
align-items: center; | ||
box-sizing: border-box; | ||
width: 100%; | ||
border: 1px solid var(--bl-color-neutral-lighter); | ||
border-radius: var(--border-radius); | ||
padding: var(--padding-vertical) var(--padding-horizontal); | ||
background-color: var(--bg-color); | ||
color: var(--color, white); | ||
font: var(--font); | ||
font-kerning: none; | ||
height: var(--height); | ||
} | ||
|
||
:host([variant="selectable"]) .tag { | ||
cursor: pointer; | ||
} | ||
|
||
:host([variant="selectable"]) .tag:hover { | ||
background-color: var(--bl-color-neutral-lightest); | ||
} | ||
|
||
:host([variant="selectable"][selected]) .tag { | ||
border-color: var(--bl-color-neutral-darker); | ||
background-color: var(--bl-color-neutral-darker); | ||
color: var(--bl-color-neutral-full); | ||
} | ||
|
||
:host([disabled]) { | ||
pointer-events: none; | ||
} | ||
|
||
:host([disabled]) .tag { | ||
background-color: var(--bl-color-neutral-lightest); | ||
border-color: var(--bl-color-neutral-lightest); | ||
color: var(--bl-color-neutral-light); | ||
} | ||
|
||
.remove-button { | ||
all: unset; | ||
font-size: var(--bl-size-s); | ||
padding: var(--bl-size-3xs); | ||
border-radius: var(--bl-border-radius-circle); | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
cursor: pointer; | ||
} | ||
|
||
.remove-button:hover { | ||
background-color: var(--bl-color-neutral-lightest); | ||
} | ||
|
||
:host([size="small"]) .tag { | ||
--font: var(--bl-font-title-4-medium); | ||
--height: var(--bl-size-xl); | ||
--icon-size: var(--bl-size-s); | ||
--border-radius: var(--bl-size-xs); | ||
--padding-vertical: var(--bl-size-3xs); | ||
--padding-horizontal: var(--bl-size-2xs); | ||
} | ||
|
||
:host([size="large"]) .tag { | ||
--font: var(--bl-font-title-3-medium); | ||
--padding-vertical: var(--bl-size-2xs); | ||
--padding-horizontal: var(--bl-size-l); | ||
--height: var(--bl-size-3xl); | ||
--icon-size: var(--bl-size-m); | ||
--border-radius: var(--bl-size-l); | ||
} | ||
|
||
/* TODO: çalışmıyor */ | ||
:host ::slotted(bl-icon) { | ||
font-size: var(--icon-size); | ||
} |
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,103 @@ | ||
import { CSSResultGroup, html, LitElement, TemplateResult } from "lit"; | ||
import { customElement, property, query, state } from "lit/decorators.js"; | ||
import { event, EventDispatcher } from "../../utilities/event"; | ||
import "../icon/bl-icon"; | ||
import { BaklavaIcon } from "../icon/icon-list"; | ||
import style from "./bl-tag.css"; | ||
|
||
export type TagSize = "small" | "medium" | "large"; | ||
type TagVariant = "selectable" | "removeable"; | ||
|
||
/** | ||
* @tag bl-tag | ||
* @summary Baklava Tag component | ||
*/ | ||
|
||
@customElement("bl-tag") | ||
export default class BlTag extends LitElement { | ||
static get styles(): CSSResultGroup { | ||
return [style]; | ||
} | ||
|
||
@state() private _actionElement: HTMLElement | null = null; | ||
@query(".remove-button") removeButton!: HTMLButtonElement; | ||
|
||
/** | ||
* Sets the tag size | ||
*/ | ||
@property({ type: String, reflect: true }) | ||
size: TagSize = "medium"; | ||
|
||
@property({ type: String, reflect: true }) | ||
variant: TagVariant = "selectable"; | ||
|
||
@property({ type: Boolean, reflect: true }) | ||
selected = false; | ||
|
||
@property({ type: Boolean, reflect: true }) | ||
disabled = false; | ||
|
||
@property({ type: String, reflect: true }) | ||
value: string | null = null; | ||
|
||
@event("bl-tag-click") _onBlTagClick: EventDispatcher<{ | ||
value: string | null; | ||
selected: boolean; | ||
}>; | ||
|
||
connectedCallback(): void { | ||
super.connectedCallback(); | ||
|
||
this._actionElement?.addEventListener("click", this.handleClick); | ||
} | ||
|
||
disconnectedCallback(): void { | ||
super.disconnectedCallback(); | ||
|
||
this._actionElement?.removeEventListener("click", this.handleClick); | ||
} | ||
|
||
private handleClick() { | ||
console.log(this._actionElement); | ||
|
||
if (this.variant === "selectable") this.selected = !this.selected; | ||
this._onBlTagClick({ selected: this.selected, value: this.value }); | ||
} | ||
|
||
/** | ||
* Sets the name of the icon | ||
*/ | ||
@property({ type: String }) | ||
icon?: BaklavaIcon; | ||
|
||
render(): TemplateResult { | ||
const icon = this.icon | ||
? html` | ||
<slot name="icon"> | ||
<bl-icon name=${this.icon}></bl-icon> | ||
</slot> | ||
` | ||
: ""; | ||
|
||
const removeButton = | ||
this.variant === "removeable" | ||
? html` | ||
<div role="button" type="button" class="remove-button"> | ||
<bl-icon name="close"></bl-icon> | ||
</div> | ||
` | ||
: ""; | ||
|
||
return html`<button type="button" class="tag"> | ||
${icon} | ||
<slot></slot> | ||
${removeButton} | ||
</button>`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"bl-tag": BlTag; | ||
} | ||
} |