Skip to content

Commit bfb218b

Browse files
committed
Update data select to support icon position
Note support a footer Chips have a fixed line height
1 parent 0e5138d commit bfb218b

File tree

8 files changed

+51
-17
lines changed

8 files changed

+51
-17
lines changed

docs/pages/components/data-select.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ layout: component
1616

1717
## Examples
1818

19-
### Show Prefix
19+
### Icon Position
20+
21+
Icon position can be set to `start` or `end`. The default is `none`.
2022

2123
```html:preview
2224
2325
<div class="form-spacing">
24-
<zn-data-select provider="country" name="country" show-prefix></zn-data-select>
25-
<zn-data-select provider="currency" name="currency" show-prefix></zn-data-select>
26-
<zn-data-select provider="color" name="color" show-prefix></zn-data-select>
26+
<zn-data-select provider="country" name="country" icon-position="start"></zn-data-select>
27+
<zn-data-select provider="country" name="country" icon-position="end"></zn-data-select>
2728
</div>
2829
```
2930

src/components/chip/chip.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default class ZnChip extends ZincElement {
5050
${this.hasSlotController.test('[default]') ? html`
5151
<slot></slot>` : ''}
5252
${this.hasSlotController.test('action') ? html`
53-
<slot name="action"></slot>` : ''}
53+
<slot name="action" class="chip__action"></slot>` : ''}
5454
</div>
5555
`;
5656
}

src/components/chip/chip.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
justify-content: center;
1818
align-items: center;
1919
border: 1px solid transparent;
20+
line-height: 24px;
2021
}
2122

2223
.chip--primary {
@@ -60,3 +61,7 @@
6061
border-color: transparent;
6162
background: transparent;
6263
}
64+
65+
.chip__action {
66+
text-transform: unset;
67+
}

src/components/data-select/data-select.component.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
emptyDataProvider,
77
type LocalDataProvider,
88
} from "./providers/provider";
9-
import {type CSSResultGroup, html, unsafeCSS} from 'lit';
9+
import {type CSSResultGroup, html, unsafeCSS, PropertyValues} from 'lit';
1010
import {FormControlController} from "../../internal/form";
1111
import {ifDefined} from "lit/directives/if-defined.js";
1212
import {LocalizeController} from '../../utilities/localize';
@@ -54,8 +54,7 @@ export default class ZnDataSelect extends ZincElement implements ZincFormControl
5454
/** The provider of the select. */
5555
@property() provider: 'color' | 'currency' | 'country';
5656

57-
/** Whether we should show the prefix of the options, and the select. */
58-
@property({attribute: 'show-prefix', type: Boolean}) showPrefix: boolean;
57+
@property({attribute: 'icon-position'}) iconPosition: 'start' | 'end' | 'none' = 'none';
5958

6059
/** An array of keys to use for filtering the options in the selected provider. */
6160
@property({
@@ -118,19 +117,31 @@ export default class ZnDataSelect extends ZincElement implements ZincFormControl
118117
return this.select.setCustomValidity(message);
119118
}
120119

120+
protected async firstUpdated(_changedProperties: PropertyValues) {
121+
super.firstUpdated(_changedProperties);
122+
await this.updateComplete;
123+
124+
if (this.prefix) this._updatePrefix(); // Update the prefix on first update
125+
}
126+
121127
@watch('value', {waitUntilFirstUpdate: true})
122128
async handleValueChange() {
123129
await this.updateComplete;
124130
this.formControlController.updateValidity();
131+
this._updatePrefix();
132+
}
125133

134+
private _updatePrefix() {
126135
// Set the prefix of the select to the selected values prefix
127136
const selectedOption = this.select.selectedOptions[0];
128-
if (selectedOption && this.showPrefix) {
129-
const prefix = selectedOption.querySelector('[slot="prefix"]');
137+
if (selectedOption && (this.iconPosition !== 'none')) {
138+
const slot = this.iconPosition === 'start'
139+
? selectedOption.querySelector('[slot="prefix"]')
140+
: selectedOption.querySelector('[slot="suffix"]');
130141

131-
if (prefix) {
142+
if (slot) {
132143
this.selectPrefix.innerHTML = '';
133-
this.selectPrefix.appendChild(prefix.cloneNode(true));
144+
this.selectPrefix.appendChild(slot.cloneNode(true));
134145
} else {
135146
this.selectPrefix.innerHTML = '';
136147
}
@@ -185,11 +196,12 @@ export default class ZnDataSelect extends ZincElement implements ZincFormControl
185196
value="${this.value}"
186197
placeholder="Choose a ${localProvider.getName}"
187198
exportparts="combobox,expand-icon,form-control-help-text,form-control-input">
188-
${this.showPrefix ? html`
199+
${this.iconPosition !== 'none' ? html`
189200
<div id="select__prefix" slot="prefix" class="select__prefix"></div>` : ''}
190201
${data.map((item: DataProviderOption) => html`
191202
<zn-option class="select__option" value="${item.key}">
192-
${this.showPrefix ? html`<span slot="prefix">${item.prefix}</span>` : ''}
203+
${this.iconPosition !== 'none' ? html`<span
204+
slot="${this.iconPosition === 'end' ? 'suffix' : 'prefix'}">${item.prefix}</span>` : ''}
193205
${item.value}
194206
</zn-option>`)}
195207
</zn-select>

src/components/data-select/data-select.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@ $colors: (
3333
zn-select::part(listbox) {
3434
max-height: 300px;
3535
}
36+
37+
.select__prefix {
38+
font-size: 20px;
39+
40+
&:empty {
41+
display: contents;
42+
}
43+
}

src/components/inline-edit/inline-edit.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default class ZnInlineEdit extends ZincElement implements ZincFormControl
6060

6161
@property({attribute: 'provider'}) selectProvider: string;
6262

63-
@property({attribute: 'show-prefix', type: Boolean}) showPrefix: boolean;
63+
@property({attribute: 'icon-position', type: Boolean}) iconPosition: 'start' | 'end' | 'none' = 'none';
6464

6565
/** The input's help text. If you need to display HTML, use the `help-text` slot instead. **/
6666
@property({attribute: 'help-text'}) helpText: string = '';
@@ -254,7 +254,7 @@ export default class ZnInlineEdit extends ZincElement implements ZincFormControl
254254
<zn-data-select class="ai__input"
255255
name="${this.name}"
256256
value="${this.value}"
257-
show-prefix="${ifDefined(this.showPrefix)}"
257+
icon-position="${ifDefined(this.iconPosition)}"
258258
help-text="${ifDefined(this.helpText)}"
259259
size="${this.size}"
260260
provider="${this.selectProvider}"

src/components/note/note.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export default class ZnNote extends ZincElement {
5252
<small>${this.date}</small>
5353
</slot>
5454
</div>
55-
<slot name="body" class="note__body">${this.body}</slot>
55+
<slot class="note__body">${this.body}</slot>
56+
<slot name="footer" class="note__footer"></slot>
5657
</div>
5758
`;
5859
}

src/components/note/note.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,11 @@ $colors: (
5454
border-left: 3px solid #{$color};
5555
}
5656
}
57+
58+
&__footer {
59+
display: flex;
60+
flex-direction: row;
61+
flex-wrap: wrap;
62+
gap: var(--zn-spacing-x-small);
63+
}
5764
}

0 commit comments

Comments
 (0)