Skip to content

Commit 3b73225

Browse files
committed
feat(chip): add closeable chip and final size
1 parent 38c945e commit 3b73225

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

src/chip-input/ux-chip-theme.css

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,45 @@ styles.chip {
44

55
font-size: 14px;
66

7-
padding: 8px 12px;
8-
7+
height: 32px;
98
border-radius: 100px;
109

1110
background-color: ${background || $design.accent};
1211
color: ${foreground || $design.accentForeground};
13-
1412
}
13+
14+
styles.chip:focus {
15+
outline: none;
16+
box-shadow: ${$design.elevation4dp};
17+
}
18+
19+
styles.chip > span {
20+
margin: 0 12px;
21+
}
22+
23+
styles.chip > span.close {
24+
display:none;
25+
}
26+
27+
styles.chip[deletable] > span {
28+
margin-right: 0;
29+
}
30+
31+
styles.chip[deletable] > span.close {
32+
display: inline-flex;
33+
justify-content: center;
34+
align-items: center;
35+
margin: 0 4px;
36+
color: ${background || $design.accent};
37+
background-color: #a6a6a6;
38+
height: 24px;
39+
width: 24px;
40+
border-radius: 24px;
41+
cursor: pointer;
42+
}
43+
44+
styles.chip[deletable] > span.close::before {
45+
content: '+';
46+
font-size: 24px;
47+
transform: rotate(45deg);
48+
}

src/chip-input/ux-chip.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<template role="textbox" styles.chip>
22
<require from="./ux-chip-theme"></require>
33

4-
<slot></slot>
4+
<span>
5+
<slot></slot>
6+
</span>
57

8+
<span class="close" click.delegate="closeChip()">
9+
</span>
610
</template>

src/chip-input/ux-chip.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { customElement, bindable, ViewResources, View, processAttributes } from 'aurelia-templating';
2+
import { DOM } from 'aurelia-pal';
23
import { bindingMode } from 'aurelia-binding';
34
import { inject } from 'aurelia-dependency-injection';
45
import { StyleEngine } from '../styles/style-engine';
@@ -12,13 +13,14 @@ import { processDesignAttributes } from '../designs/design-attributes';
1213
export class UxChip implements Themable {
1314
@bindable public theme = null;
1415
@bindable public type: any;
16+
1517
@bindable({ defaultBindingMode: bindingMode.twoWay })
1618
public value: any = undefined;
1719

1820
public view: View;
1921

2022
constructor(
21-
/*private element: HTMLInputElement,*/
23+
private element: HTMLInputElement,
2224
public resources: ViewResources,
2325
private styleEngine: StyleEngine) { }
2426

@@ -35,4 +37,10 @@ export class UxChip implements Themable {
3537
public themeChanged(newValue: any) {
3638
this.styleEngine.applyTheme(this, newValue);
3739
}
40+
41+
public closeChip() {
42+
const closeEvent = DOM.createCustomEvent('close', { bubbles: false });
43+
44+
this.element.dispatchEvent(closeEvent);
45+
}
3846
}

0 commit comments

Comments
 (0)