-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(combobox, combobox-item): add description
, shortHeading
props and content-end
slot
#9771
Changes from all commits
6614119
ff8f951
98ca0fd
bf2d711
ace0f35
84d9c4a
c60c06d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,10 +28,11 @@ import { getAncestors, getDepth, isSingleLike } from "../combobox/utils"; | |
import { Scale, SelectionMode } from "../interfaces"; | ||
import { getIconScale } from "../../utils/component"; | ||
import { IconName } from "../icon/interfaces"; | ||
import { CSS } from "./resources"; | ||
import { CSS, SLOTS } from "./resources"; | ||
|
||
/** | ||
* @slot - A slot for adding nested `calcite-combobox-item`s. | ||
* @slot content-end - A slot for adding non-actionable elements after the component's content. | ||
*/ | ||
@Component({ | ||
tag: "calcite-combobox-item", | ||
|
@@ -59,6 +60,11 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon | |
/** Specifies the parent and grandparent items, which are set on `calcite-combobox`. */ | ||
@Prop({ mutable: true }) ancestors: ComboboxChildElement[]; | ||
|
||
/** | ||
* A description for the component, which displays below the label. | ||
*/ | ||
@Prop() description: string; | ||
|
||
/** The `id` attribute of the component. When omitted, a globally unique identifier is used. */ | ||
@Prop({ reflect: true }) guid = guid(); | ||
|
||
|
@@ -83,14 +89,18 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon | |
*/ | ||
@Prop({ reflect: true }) filterTextMatchPattern: RegExp; | ||
|
||
/** The component's value. */ | ||
@Prop() value!: any; | ||
|
||
/** | ||
* When `true`, omits the component from the `calcite-combobox` filtered search results. | ||
*/ | ||
@Prop({ reflect: true }) filterDisabled: boolean; | ||
|
||
/** | ||
* Specifies the size of the component inherited from the `calcite-combobox`, defaults to `m`. | ||
* | ||
* @internal | ||
*/ | ||
@Prop() scale: Scale = "m"; | ||
|
||
/** | ||
* Specifies the selection mode of the component, where: | ||
* | ||
|
@@ -110,11 +120,16 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon | |
> = "multiple"; | ||
|
||
/** | ||
* Specifies the size of the component inherited from the `calcite-combobox`, defaults to `m`. | ||
* The component's short heading. | ||
* | ||
* @internal | ||
* When provided, the short heading will be displayed in the component's selection. | ||
* | ||
* It is recommended to use 5 characters or fewer. | ||
*/ | ||
@Prop() scale: Scale = "m"; | ||
@Prop({ reflect: true }) shortHeading: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll submit a separate PR for this since the test doesn't have |
||
|
||
/** The component's value. */ | ||
@Prop() value!: any; | ||
|
||
// -------------------------------------------------------------------------- | ||
// | ||
|
@@ -189,7 +204,6 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon | |
class={{ | ||
[CSS.custom]: !!this.icon, | ||
[CSS.iconActive]: this.icon && this.selected, | ||
[CSS.iconIndent]: true, | ||
}} | ||
flipRtl={this.iconFlipRtl} | ||
icon={this.icon || iconPath} | ||
|
@@ -207,15 +221,13 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon | |
class={{ | ||
[CSS.icon]: true, | ||
[CSS.dot]: true, | ||
[CSS.iconIndent]: true, | ||
}} | ||
/> | ||
) : ( | ||
<calcite-icon | ||
class={{ | ||
[CSS.icon]: true, | ||
[CSS.iconActive]: this.selected, | ||
[CSS.iconIndent]: true, | ||
}} | ||
flipRtl={this.iconFlipRtl} | ||
icon={iconPath} | ||
|
@@ -250,19 +262,31 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon | |
[CSS.active]: this.active, | ||
[CSS.single]: isSingleSelect, | ||
}; | ||
const depth = getDepth(this.el); | ||
const depth = getDepth(this.el) + 1; | ||
|
||
return ( | ||
<Host aria-hidden="true"> | ||
<InteractiveContainer disabled={disabled}> | ||
<div | ||
class={`container scale--${this.scale}`} | ||
class={{ | ||
[CSS.container]: true, | ||
[CSS.scale(this.scale)]: true, | ||
}} | ||
style={{ "--calcite-combobox-item-spacing-indent-multiplier": `${depth}` }} | ||
> | ||
<li class={classes} id={this.guid} onClick={this.itemClickHandler}> | ||
{this.renderSelectIndicator(showDot, iconPath)} | ||
{this.renderIcon(iconPath)} | ||
<span class="title">{this.renderTextContent()}</span> | ||
<div class={CSS.centerContent}> | ||
<div class={CSS.title}>{this.renderTextContent(this.textLabel)}</div> | ||
{this.description ? ( | ||
<div class={CSS.description}>{this.renderTextContent(this.description)}</div> | ||
) : null} | ||
</div> | ||
{this.shortHeading ? ( | ||
<div class={CSS.shortText}>{this.renderTextContent(this.shortHeading)}</div> | ||
) : null} | ||
<slot name={SLOTS.contentEnd} /> | ||
</li> | ||
{this.renderChildren()} | ||
</div> | ||
|
@@ -271,12 +295,14 @@ export class ComboboxItem implements ConditionalSlotComponent, InteractiveCompon | |
); | ||
} | ||
|
||
private renderTextContent(): string | (string | VNode)[] { | ||
if (!this.filterTextMatchPattern) { | ||
return this.textLabel; | ||
private renderTextContent(text: string): string | (string | VNode)[] { | ||
const pattern = this.filterTextMatchPattern; | ||
|
||
if (!pattern || !text) { | ||
return text; | ||
} | ||
|
||
const parts: (string | VNode)[] = this.textLabel.split(this.filterTextMatchPattern); | ||
const parts: (string | VNode)[] = text.split(pattern); | ||
|
||
if (parts.length > 1) { | ||
// we only highlight the first match | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
import { Scale } from "../interfaces"; | ||
|
||
export const CSS = { | ||
icon: "icon", | ||
iconActive: "icon--active", | ||
iconIndent: "icon--indent", | ||
active: "label--active", | ||
centerContent: "center-content", | ||
container: "container", | ||
custom: "icon--custom", | ||
description: "description", | ||
dot: "icon--dot", | ||
single: "label--single", | ||
filterMatch: "filter-match", | ||
icon: "icon", | ||
iconActive: "icon--active", | ||
label: "label", | ||
active: "label--active", | ||
scale: (scale: Scale) => `scale--${scale}` as const, | ||
selected: "label--selected", | ||
title: "title", | ||
shortText: "short-text", | ||
single: "label--single", | ||
textContainer: "text-container", | ||
filterMatch: "filter-match", | ||
title: "title", | ||
}; | ||
|
||
export const SLOTS = { | ||
contentEnd: "content-end", | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will
description
andshort-text
need CSS vars for their color at some point?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description
might. WDTY @ashetland?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we need a custom CSS prop, I'll add it in the component tokens PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would make sense for the short text and I'm guessing we're doing that for description text across components?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe so. I'll double check and add it to #8594.