update dees-chips
This commit is contained in:
@ -1,41 +1,112 @@
|
||||
import { html } from '@design.estate/dees-element';
|
||||
import { html, cssManager } from '@design.estate/dees-element';
|
||||
|
||||
export const demoFunc = () => html`
|
||||
<style>
|
||||
.demoContainer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
background: #222;
|
||||
gap: 32px;
|
||||
padding: 48px;
|
||||
background: ${cssManager.bdTheme('#f8f9fa', '#0a0a0a')};
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.section {
|
||||
background: ${cssManager.bdTheme('#ffffff', '#18181b')};
|
||||
border: 1px solid ${cssManager.bdTheme('#e5e7eb', '#27272a')};
|
||||
border-radius: 8px;
|
||||
padding: 24px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 16px;
|
||||
color: ${cssManager.bdTheme('#09090b', '#fafafa')};
|
||||
}
|
||||
|
||||
.section-description {
|
||||
font-size: 14px;
|
||||
color: ${cssManager.bdTheme('#71717a', '#a1a1aa')};
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
</style>
|
||||
<div class="demoContainer">
|
||||
<dees-chips
|
||||
selectionMode="none"
|
||||
.selectableChips=${[
|
||||
{ key: 'account1', value: 'Payment Account 1' },
|
||||
{ key: 'account2', value: 'PaymentAccount2' },
|
||||
{ key: 'account3', value: 'Payment Account 3' },
|
||||
]}
|
||||
></dees-chips>
|
||||
<dees-chips
|
||||
selectionMode="single"
|
||||
chipsAreRemovable
|
||||
.selectableChips=${[
|
||||
{ key: 'account1', value: 'Payment Account 1' },
|
||||
{ key: 'account2', value: 'PaymentAccount2' },
|
||||
{ key: 'account3', value: 'Payment Account 3' },
|
||||
]}
|
||||
></dees-chips>
|
||||
<dees-chips
|
||||
selectionMode="multiple"
|
||||
.selectableChips=${[
|
||||
{ key: 'account1', value: 'Payment Account 1' },
|
||||
{ key: 'account2', value: 'PaymentAccount2' },
|
||||
{ key: 'account3', value: 'Payment Account 3' },
|
||||
]}
|
||||
></dees-chips>
|
||||
<div class="section">
|
||||
<div class="section-title">Non-Selectable Chips</div>
|
||||
<div class="section-description">Basic chips without selection capability. Use for display-only tags.</div>
|
||||
<dees-chips
|
||||
selectionMode="none"
|
||||
.selectableChips=${[
|
||||
{ key: 'status', value: 'Active' },
|
||||
{ key: 'tier', value: 'Premium' },
|
||||
{ key: 'region', value: 'EU-West' },
|
||||
{ key: 'type', value: 'Enterprise' },
|
||||
]}
|
||||
></dees-chips>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<div class="section-title">Single Selection Chips</div>
|
||||
<div class="section-description">Click to select one chip at a time. Useful for filters and options.</div>
|
||||
<dees-chips
|
||||
selectionMode="single"
|
||||
.selectableChips=${[
|
||||
{ key: 'all', value: 'All Projects' },
|
||||
{ key: 'active', value: 'Active' },
|
||||
{ key: 'archived', value: 'Archived' },
|
||||
{ key: 'drafts', value: 'Drafts' },
|
||||
]}
|
||||
></dees-chips>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<div class="section-title">Multiple Selection Chips</div>
|
||||
<div class="section-description">Select multiple chips simultaneously. Great for tag selection.</div>
|
||||
<dees-chips
|
||||
selectionMode="multiple"
|
||||
.selectableChips=${[
|
||||
{ key: 'js', value: 'JavaScript' },
|
||||
{ key: 'ts', value: 'TypeScript' },
|
||||
{ key: 'react', value: 'React' },
|
||||
{ key: 'vue', value: 'Vue' },
|
||||
{ key: 'angular', value: 'Angular' },
|
||||
{ key: 'node', value: 'Node.js' },
|
||||
]}
|
||||
></dees-chips>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<div class="section-title">Removable Chips with Keys</div>
|
||||
<div class="section-description">Chips with remove buttons and key-value pairs. Perfect for dynamic lists.</div>
|
||||
<dees-chips
|
||||
selectionMode="single"
|
||||
chipsAreRemovable
|
||||
.selectableChips=${[
|
||||
{ key: 'env', value: 'Production' },
|
||||
{ key: 'version', value: '2.4.1' },
|
||||
{ key: 'branch', value: 'main' },
|
||||
{ key: 'author', value: 'John Doe' },
|
||||
]}
|
||||
></dees-chips>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<div class="section-title">Mixed Content Example</div>
|
||||
<div class="section-description">Combining different chip types for complex UIs.</div>
|
||||
<dees-chips
|
||||
selectionMode="multiple"
|
||||
chipsAreRemovable
|
||||
.selectableChips=${[
|
||||
{ key: 'priority', value: 'High' },
|
||||
{ key: 'status', value: 'In Progress' },
|
||||
{ key: 'bug', value: 'Bug' },
|
||||
{ key: 'feature', value: 'Feature' },
|
||||
{ key: 'sprint', value: 'Sprint 23' },
|
||||
{ key: 'assignee', value: 'Alice' },
|
||||
]}
|
||||
></dees-chips>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
@ -60,52 +60,93 @@ export class DeesChips extends DeesElement {
|
||||
|
||||
.mainbox {
|
||||
user-select: none;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.chip {
|
||||
border-top: ${cssManager.bdTheme('1px solid #CCC', '1px solid #444')};
|
||||
background: #333333;
|
||||
background: ${cssManager.bdTheme('#f4f4f5', '#27272a')};
|
||||
border: 1px solid ${cssManager.bdTheme('#e5e7eb', '#3f3f46')};
|
||||
display: inline-flex;
|
||||
height: 20px;
|
||||
line-height: 20px;
|
||||
padding: 0px 8px;
|
||||
font-size: 12px;
|
||||
color: #fff;
|
||||
border-radius: 40px;
|
||||
margin-right: 4px;
|
||||
margin-bottom: 4px;
|
||||
align-items: center;
|
||||
height: 32px;
|
||||
padding: 0px 12px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: ${cssManager.bdTheme('#09090b', '#fafafa')};
|
||||
border-radius: 6px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3);
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.chip:hover {
|
||||
background: #666666;
|
||||
background: ${cssManager.bdTheme('#e5e7eb', '#3f3f46')};
|
||||
border-color: ${cssManager.bdTheme('#d1d5db', '#52525b')};
|
||||
}
|
||||
|
||||
.chip:active {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
.chip.selected {
|
||||
background: #00a3ff;
|
||||
background: ${cssManager.bdTheme('#3b82f6', '#3b82f6')};
|
||||
border-color: ${cssManager.bdTheme('#3b82f6', '#3b82f6')};
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.chip.selected:hover {
|
||||
background: ${cssManager.bdTheme('#2563eb', '#2563eb')};
|
||||
border-color: ${cssManager.bdTheme('#2563eb', '#2563eb')};
|
||||
}
|
||||
|
||||
.chipKey {
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
height: 100%;
|
||||
display: inline-block;
|
||||
background: ${cssManager.bdTheme('rgba(0, 0, 0, 0.06)', 'rgba(255, 255, 255, 0.1)')};
|
||||
height: 20px;
|
||||
line-height: 20px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
margin-left: -8px;
|
||||
padding-left: 8px;
|
||||
padding-right: 8px;
|
||||
padding: 0px 8px;
|
||||
margin-right: 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: ${cssManager.bdTheme('#71717a', '#a1a1aa')};
|
||||
}
|
||||
|
||||
.chip.selected .chipKey {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
dees-icon {
|
||||
padding: 0px 6px 0px 4px;
|
||||
margin-left: 4px;
|
||||
margin-right: -8px;
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
margin-left: 8px;
|
||||
margin-right: -6px;
|
||||
border-radius: 3px;
|
||||
transition: all 0.15s ease;
|
||||
color: ${cssManager.bdTheme('#71717a', '#a1a1aa')};
|
||||
}
|
||||
|
||||
.chip.selected dees-icon {
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
dees-icon:hover {
|
||||
background: #e4002b;
|
||||
background: ${cssManager.bdTheme('rgba(0, 0, 0, 0.1)', 'rgba(255, 255, 255, 0.1)')};
|
||||
color: ${cssManager.bdTheme('#ef4444', '#ef4444')};
|
||||
}
|
||||
|
||||
.chip.selected dees-icon:hover {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
color: #ffffff;
|
||||
}
|
||||
`,
|
||||
];
|
||||
@ -139,19 +180,25 @@ export class DeesChips extends DeesElement {
|
||||
}
|
||||
|
||||
public async firstUpdated() {
|
||||
if (!this.textContent) {
|
||||
this.textContent = 'Button';
|
||||
this.performUpdate();
|
||||
}
|
||||
// Component initialized
|
||||
}
|
||||
|
||||
private isSelected(chip: Tag): boolean {
|
||||
if (this.selectionMode === 'single') {
|
||||
return this.selectedChip?.key === chip.key;
|
||||
return this.selectedChip ? this.isSameChip(this.selectedChip, chip) : false;
|
||||
} else {
|
||||
return this.selectedChips.some((selected) => selected.key === chip.key);
|
||||
return this.selectedChips.some((selected) => this.isSameChip(selected, chip));
|
||||
}
|
||||
}
|
||||
|
||||
private isSameChip(chip1: Tag, chip2: Tag): boolean {
|
||||
// If both have keys, compare by key
|
||||
if (chip1.key && chip2.key) {
|
||||
return chip1.key === chip2.key;
|
||||
}
|
||||
// Otherwise compare by value (and key if present)
|
||||
return chip1.value === chip2.value && chip1.key === chip2.key;
|
||||
}
|
||||
|
||||
public async selectChip(chip: Tag) {
|
||||
if (this.selectionMode === 'none') {
|
||||
@ -168,7 +215,7 @@ export class DeesChips extends DeesElement {
|
||||
}
|
||||
} else if (this.selectionMode === 'multiple') {
|
||||
if (this.isSelected(chip)) {
|
||||
this.selectedChips = this.selectedChips.filter((selected) => selected.key !== chip.key);
|
||||
this.selectedChips = this.selectedChips.filter((selected) => !this.isSameChip(selected, chip));
|
||||
} else {
|
||||
this.selectedChips = [...this.selectedChips, chip];
|
||||
}
|
||||
@ -179,13 +226,13 @@ export class DeesChips extends DeesElement {
|
||||
|
||||
public removeChip(chipToRemove: Tag): void {
|
||||
// Remove the chip from selectableChips
|
||||
this.selectableChips = this.selectableChips.filter((chip) => chip.key !== chipToRemove.key);
|
||||
this.selectableChips = this.selectableChips.filter((chip) => !this.isSameChip(chip, chipToRemove));
|
||||
|
||||
// Remove the chip from selectedChips if present
|
||||
this.selectedChips = this.selectedChips.filter((chip) => chip.key !== chipToRemove.key);
|
||||
this.selectedChips = this.selectedChips.filter((chip) => !this.isSameChip(chip, chipToRemove));
|
||||
|
||||
// If the removed chip was the selectedChip, set selectedChip to null
|
||||
if (this.selectedChip && this.selectedChip.key === chipToRemove.key) {
|
||||
if (this.selectedChip && this.isSameChip(this.selectedChip, chipToRemove)) {
|
||||
this.selectedChip = null;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user