Skip to content
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(autocomplete): add autocomplete component #10562

Open
wants to merge 73 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
e91067a
feat(autocomplete): add autocomplete component. #10044
driskull Oct 8, 2024
f775c65
WIP
driskull Oct 18, 2024
f9281c3
WIP
driskull Oct 18, 2024
26ef117
WIP
driskull Oct 18, 2024
895fb3d
WIP
driskull Oct 18, 2024
551a4ef
revert
driskull Oct 19, 2024
1647737
Update .stylelintrc.cjs
driskull Oct 19, 2024
40ff5a4
WIP
driskull Oct 21, 2024
74e8475
Merge branch 'dris0000/autocomplete' of github.com:Esri/calcite-desig…
driskull Oct 21, 2024
50bd853
cleanup
driskull Oct 21, 2024
5003bd5
test app
driskull Oct 21, 2024
08ddfc6
cleanup
driskull Oct 21, 2024
4b63467
test app
driskull Oct 21, 2024
d576694
test app
driskull Oct 21, 2024
83b6e04
Merge branch 'dev' into dris0000/autocomplete
driskull Oct 31, 2024
eaff04d
Merge branch 'dev' into dris0000/autocomplete
driskull Nov 15, 2024
d134939
Merge branch 'dev' into dris0000/autocomplete
driskull Nov 15, 2024
ea844e0
feat(autocomplete): add autocomplete component
driskull Nov 15, 2024
023f40a
cleanup
driskull Nov 15, 2024
ef0e707
WIP
driskull Nov 18, 2024
f5a8775
cleanup
driskull Nov 18, 2024
b287e24
WIP
driskull Nov 19, 2024
c3ec799
wip
driskull Nov 19, 2024
183d4da
WIP
driskull Nov 19, 2024
ae99b87
html demo
driskull Nov 19, 2024
b4d4f74
demo
driskull Nov 19, 2024
a4f2016
add story
driskull Nov 19, 2024
576ec2b
WIP
driskull Nov 19, 2024
801610f
WIP
driskull Nov 20, 2024
2edd54f
comment
driskull Nov 20, 2024
213530a
WIP
driskull Nov 20, 2024
36d9abc
WIP
driskull Nov 20, 2024
3791285
cleanup
driskull Nov 20, 2024
52a99e6
cleanup css
driskull Nov 21, 2024
9ac5b36
css vars
driskull Nov 21, 2024
66c3ec1
cleanup
driskull Nov 21, 2024
a29a378
cleanup
driskull Nov 21, 2024
323bcd9
Merge branch 'dev' into dris0000/autocomplete
driskull Nov 21, 2024
6415af0
tests
driskull Nov 21, 2024
5010488
WIP
driskull Nov 21, 2024
65c6ef7
cleanup
driskull Nov 21, 2024
1348ea4
cleanup
driskull Nov 21, 2024
e8df8e1
cleanup
driskull Nov 21, 2024
b7dbb1a
WIP
driskull Nov 21, 2024
c854608
WIP
driskull Nov 21, 2024
cd09b73
update spacing
driskull Nov 21, 2024
4c65bfa
fix group spacing, fix demo html
driskull Nov 22, 2024
0f7fbc1
cleanup demo some more
driskull Nov 22, 2024
43276a5
Merge branch 'dev' into dris0000/autocomplete
driskull Nov 25, 2024
0f6d455
Merge branch 'dev' into dris0000/autocomplete
driskull Nov 25, 2024
8ae99c0
add tests
driskull Nov 25, 2024
aa834ba
cleanup
driskull Nov 25, 2024
5092329
Merge branch 'dev' into dris0000/autocomplete
driskull Nov 25, 2024
5991b82
theme tests
driskull Nov 25, 2024
9889c3c
theme work
driskull Nov 26, 2024
120e7e6
cleanup
driskull Nov 26, 2024
b0a9fbe
cleanup
driskull Nov 26, 2024
eb48083
cleanup
driskull Nov 26, 2024
5bfa535
cleanup
driskull Nov 26, 2024
81b17e0
fix e2e
driskull Nov 26, 2024
d40410e
Merge branch 'dev' into dris0000/autocomplete
driskull Nov 26, 2024
b24c28d
Merge branch 'dev' into dris0000/autocomplete
driskull Dec 2, 2024
dc4b7e2
cleanup
driskull Dec 2, 2024
5b6abed
cleanup
driskull Dec 2, 2024
33118b3
Merge branch 'dev' into dris0000/autocomplete
driskull Dec 2, 2024
1882df7
review fixes
driskull Dec 2, 2024
a8a4d9e
tokens fixes
driskull Dec 3, 2024
e3997d1
themed demo
driskull Dec 3, 2024
90296fa
fix hover/focus disabled items
driskull Dec 3, 2024
4178284
fix focus/hover styling
driskull Dec 3, 2024
35bbe5a
review fixes
driskull Dec 3, 2024
a3921d4
Merge branch 'dev' into dris0000/autocomplete
driskull Dec 3, 2024
fbb5ccb
Merge branch 'dev' into dris0000/autocomplete
driskull Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/calcite-components/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ <h1 id="calcite-demo">Calcite demo</h1>
</a>
</div>

<div>
<a href="/src/demos/autocomplete.html">
<calcite-action scale="s" text="Autocomplete" alignment="start" text-enabled appearance="solid">
</calcite-action>
</a>
</div>

<div>
<a href="/src/demos/avatar.html">
<calcite-action scale="s" text="Avatar" alignment="start" text-enabled appearance="solid"> </calcite-action>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { describe } from "vitest";
import { defaults, hidden, renders, themed } from "../../tests/commonTests";
import { CSS } from "./resources";

describe("calcite-autocomplete-item-group", () => {
describe("defaults", () => {
defaults("calcite-autocomplete-item-group", [
{ propertyName: "disableSpacing", defaultValue: false },
{ propertyName: "heading", defaultValue: undefined },
{ propertyName: "label", defaultValue: undefined },
{ propertyName: "scale", defaultValue: "m" },
]);
});

describe("renders", () => {
renders("calcite-autocomplete-item-group", { display: "flex" });
});

describe("honors hidden attribute", () => {
hidden("calcite-autocomplete-item-group");
});

describe("theme", () => {
themed("calcite-autocomplete-item-group", {
"--calcite-autocomplete-background-color": {
shadowSelector: `.${CSS.container}`,
targetProp: "backgroundColor",
},
"--calcite-autocomplete-border-color": {
shadowSelector: `.${CSS.heading}`,
targetProp: "borderBlockEndColor",
},
"--calcite-autocomplete-text-color": {
shadowSelector: `.${CSS.heading}`,
targetProp: "color",
},
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* CSS Custom Properties
*
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-autocomplete-background-color: Specifies the background color of the component.
* @prop --calcite-autocomplete-border-color: Specifies the border color of the component.
* @prop --calcite-autocomplete-text-color: Specifies the text color of the component.
*/

.scale--s {
@apply text-n2h;
--calcite-internal-autocomplete-item-group-spacing-unit-l: theme("spacing.2");
--calcite-internal-autocomplete-item-group-spacing-unit-s: theme("spacing.2");
}

.scale--m {
@apply text-n1h;
--calcite-internal-autocomplete-item-group-spacing-unit-l: theme("spacing.3");
--calcite-internal-autocomplete-item-group-spacing-unit-s: theme("spacing.3");
}

.scale--l {
@apply text-0h;
--calcite-internal-autocomplete-item-group-spacing-unit-l: theme("spacing.4");
--calcite-internal-autocomplete-item-group-spacing-unit-s: theme("spacing.4");
}

:host {
@apply m-0
flex
flex-col;
}

.container {
@apply flex
flex-col;
background-color: var(--calcite-autocomplete-background-color, var(--calcite-color-foreground-1));
padding-block-start: var(--calcite-internal-autocomplete-item-group-spacing-unit-l);
}

.container--no-spacing {
padding-block-start: 0;
}

.heading {
border: 0 solid;
@apply box-border
w-full
min-w-0
max-w-full
word-break
border-b
font-bold;
color: var(--calcite-autocomplete-text-color, var(--calcite-color-text-2));
border-block-end-color: var(--calcite-autocomplete-border-color, var(--calcite-color-border-3));
padding-block: var(--calcite-internal-autocomplete-item-group-spacing-unit-l);
padding-inline: var(--calcite-internal-autocomplete-item-group-spacing-unit-s);
}

@include base-component();
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { LitElement, property, h, JsxNode } from "@arcgis/lumina";
import { Scale } from "../interfaces";
import { CSS } from "./resources";
import { styles } from "./autocomplete-item-group.scss";

declare global {
interface DeclareElements {
"calcite-autocomplete-item-group": AutocompleteItemGroup;
}
}

/** @slot - A slot for adding `calcite-autocomplete-item`s. */
export class AutocompleteItemGroup extends LitElement {
// #region Static Members

static override styles = styles;

// #endregion

// #region Private Properties

// #endregion

// #region Public Properties

/**
* When `true`, signifies that the group should not have extra spacing. Used for styling.
*
* @private
*/
@property() disableSpacing = false;

/** The component's text. */
@property() heading: string;

/** The component's label. */
@property() label: any;

/**
* Specifies the size of the component inherited from the `calcite-autocomplete`, defaults to `m`.
*
* @private
*/
@property() scale: Scale = "m";

// #endregion

// #region Lifecycle

// #endregion

// #region Rendering

override render(): JsxNode {
const { scale } = this;
return (
<div
aria-label={this.label ?? this.heading}
class={{
[CSS.container]: true,
[CSS.containerNoSpacing]: this.disableSpacing,
[`scale--${scale}`]: true,
}}
role="group"
>
<div class={CSS.heading} role="presentation">
{this.heading}
</div>
<slot />
</div>
);
}

// #endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const CSS = {
container: "container",
containerNoSpacing: "container--no-spacing",
heading: "heading",
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { describe } from "vitest";
import { defaults, disabled, hidden, reflects, renders, slots, themed } from "../../tests/commonTests";
import { CSS, SLOTS } from "./resources";

describe("calcite-autocomplete-item", () => {
describe("defaults", () => {
defaults("calcite-autocomplete-item", [
{ propertyName: "active", defaultValue: false },
{ propertyName: "description", defaultValue: undefined },
{ propertyName: "disabled", defaultValue: false },
{ propertyName: "heading", defaultValue: undefined },
{ propertyName: "iconEnd", defaultValue: undefined },
{ propertyName: "iconFlipRtl", defaultValue: undefined },
{ propertyName: "iconStart", defaultValue: undefined },
{ propertyName: "label", defaultValue: undefined },
{ propertyName: "scale", defaultValue: "m" },
{ propertyName: "value", defaultValue: undefined },
]);
});

describe("reflects", () => {
reflects("calcite-autocomplete-item", [
{ propertyName: "disabled", value: true },
{ propertyName: "iconEnd", value: "banana" },
{ propertyName: "iconFlipRtl", value: "end" },
{ propertyName: "iconStart", value: "banana" },
]);
});

describe("renders", () => {
renders("calcite-autocomplete-item", { display: "flex" });
});

describe("honors hidden attribute", () => {
hidden("calcite-autocomplete-item");
});

describe("slots", () => {
slots("calcite-autocomplete-item", SLOTS);
});

describe("disabled", () => {
disabled("calcite-autocomplete-item", { focusTarget: "none" });
});

describe("slots", () => {
slots("calcite-autocomplete-item", SLOTS);
});

describe("theme", () => {
themed("calcite-autocomplete-item", {
"--calcite-autocomplete-background-color": {
shadowSelector: `.${CSS.container}`,
targetProp: "backgroundColor",
},
"--calcite-autocomplete-background-color-hover": {
shadowSelector: `.${CSS.container}`,
state: "hover",
targetProp: "backgroundColor",
},
"--calcite-autocomplete-description-text-color": {
shadowSelector: `.${CSS.description}`,
targetProp: "color",
},
"--calcite-autocomplete-heading-text-color": {
shadowSelector: `.${CSS.heading}`,
targetProp: "color",
},
"--calcite-autocomplete-text-color": {
shadowSelector: `.${CSS.container}`,
targetProp: "color",
},
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* CSS Custom Properties
*
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-autocomplete-background-color: Specifies the background color of the component.
* @prop --calcite-autocomplete-background-color-hover: Specifies the background color of the component when hovered.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alisonailea do we really need this var? I thought if a user could use the host to set the hover state bg color a var wasn't necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like:

calcite-autocomplete-item:hover{
--calcite-autocomplete-background-color: red;
}

* @prop --calcite-autocomplete-description-text-color: Specifies the text color of the component's description.
* @prop --calcite-autocomplete-heading-text-color: Specifies the text color of the component's heading.
* @prop --calcite-autocomplete-text-color: Specifies the text color of the component.
*/

.scale--s {
@apply text-n2h;
--calcite-internal-autocomplete-item-spacing-unit-l: theme("spacing.2");
--calcite-internal-autocomplete-item-spacing-unit-s: theme("spacing.1");
--calcite-internal-autocomplete-item-description-font-size: var(--calcite-font-size-xs);
}

.scale--m {
@apply text-n1h;
--calcite-internal-autocomplete-item-spacing-unit-l: theme("spacing.3");
--calcite-internal-autocomplete-item-spacing-unit-s: theme("spacing[1.5]");
--calcite-internal-autocomplete-item-description-font-size: var(--calcite-font-size-sm);
}

.scale--l {
@apply text-0h;
--calcite-internal-autocomplete-item-spacing-unit-l: theme("spacing.4");
--calcite-internal-autocomplete-item-spacing-unit-s: theme("spacing[2.5]");
--calcite-internal-autocomplete-item-description-font-size: var(--calcite-font-size);
}

:host {
@apply flex;
}

.container {
@apply flex
w-full
min-w-full
cursor-pointer
focus-base
relative
box-border
items-center;
background-color: var(--calcite-autocomplete-background-color, var(--calcite-color-foreground-1));
color: var(--calcite-autocomplete-text-color, var(--calcite-color-text-3));
gap: var(--calcite-internal-autocomplete-item-spacing-unit-l);
padding-inline: var(--calcite-internal-autocomplete-item-spacing-unit-l);
padding-block: var(--calcite-internal-autocomplete-item-spacing-unit-s);
@include word-break();
justify-content: space-around;
}

.description {
color: var(--calcite-autocomplete-description-text-color);
font-size: var(--calcite-internal-autocomplete-item-description-font-size);
}

.heading {
color: var(--calcite-autocomplete-heading-text-color, var(--calcite-color-text-1));
}

.heading,
.description {
line-height: var(--calcite-font-line-height-relative-snug);
}

:host(:hover:not([disabled])) .container {
background-color: var(--calcite-autocomplete-background-color-hover, var(--calcite-color-foreground-2));

.description {
color: var(--calcite-autocomplete-description-text-color, var(--calcite-color-text-2));
}
}

.container--active {
@apply focus-inset;
}

.content-center {
display: flex;
flex-direction: column;
flex-grow: 1;
padding-block: 0;
}

@include base-component();
@include disabled();
Loading
Loading