-
Notifications
You must be signed in to change notification settings - Fork 76
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
driskull
wants to merge
73
commits into
dev
Choose a base branch
from
dris0000/autocomplete
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,416
−5
Open
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 f775c65
WIP
driskull f9281c3
WIP
driskull 26ef117
WIP
driskull 895fb3d
WIP
driskull 551a4ef
revert
driskull 1647737
Update .stylelintrc.cjs
driskull 40ff5a4
WIP
driskull 74e8475
Merge branch 'dris0000/autocomplete' of github.com:Esri/calcite-desig…
driskull 50bd853
cleanup
driskull 5003bd5
test app
driskull 08ddfc6
cleanup
driskull 4b63467
test app
driskull d576694
test app
driskull 83b6e04
Merge branch 'dev' into dris0000/autocomplete
driskull eaff04d
Merge branch 'dev' into dris0000/autocomplete
driskull d134939
Merge branch 'dev' into dris0000/autocomplete
driskull ea844e0
feat(autocomplete): add autocomplete component
driskull 023f40a
cleanup
driskull ef0e707
WIP
driskull f5a8775
cleanup
driskull b287e24
WIP
driskull c3ec799
wip
driskull 183d4da
WIP
driskull ae99b87
html demo
driskull b4d4f74
demo
driskull a4f2016
add story
driskull 576ec2b
WIP
driskull 801610f
WIP
driskull 2edd54f
comment
driskull 213530a
WIP
driskull 36d9abc
WIP
driskull 3791285
cleanup
driskull 52a99e6
cleanup css
driskull 9ac5b36
css vars
driskull 66c3ec1
cleanup
driskull a29a378
cleanup
driskull 323bcd9
Merge branch 'dev' into dris0000/autocomplete
driskull 6415af0
tests
driskull 5010488
WIP
driskull 65c6ef7
cleanup
driskull 1348ea4
cleanup
driskull e8df8e1
cleanup
driskull b7dbb1a
WIP
driskull c854608
WIP
driskull cd09b73
update spacing
driskull 4c65bfa
fix group spacing, fix demo html
driskull 0f7fbc1
cleanup demo some more
driskull 43276a5
Merge branch 'dev' into dris0000/autocomplete
driskull 0f6d455
Merge branch 'dev' into dris0000/autocomplete
driskull 8ae99c0
add tests
driskull aa834ba
cleanup
driskull 5092329
Merge branch 'dev' into dris0000/autocomplete
driskull 5991b82
theme tests
driskull 9889c3c
theme work
driskull 120e7e6
cleanup
driskull b0a9fbe
cleanup
driskull eb48083
cleanup
driskull 5bfa535
cleanup
driskull 81b17e0
fix e2e
driskull d40410e
Merge branch 'dev' into dris0000/autocomplete
driskull b24c28d
Merge branch 'dev' into dris0000/autocomplete
driskull dc4b7e2
cleanup
driskull 5b6abed
cleanup
driskull 33118b3
Merge branch 'dev' into dris0000/autocomplete
driskull 1882df7
review fixes
driskull a8a4d9e
tokens fixes
driskull e3997d1
themed demo
driskull 90296fa
fix hover/focus disabled items
driskull 4178284
fix focus/hover styling
driskull 35bbe5a
review fixes
driskull a3921d4
Merge branch 'dev' into dris0000/autocomplete
driskull fbb5ccb
Merge branch 'dev' into dris0000/autocomplete
driskull File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
.../calcite-components/src/components/autocomplete-item-group/autocomplete-item-group.e2e.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
}); | ||
}); | ||
}); |
61 changes: 61 additions & 0 deletions
61
...es/calcite-components/src/components/autocomplete-item-group/autocomplete-item-group.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
75 changes: 75 additions & 0 deletions
75
...ges/calcite-components/src/components/autocomplete-item-group/autocomplete-item-group.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/calcite-components/src/components/autocomplete-item-group/resources.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}; |
75 changes: 75 additions & 0 deletions
75
packages/calcite-components/src/components/autocomplete-item/autocomplete-item.e2e.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
}); | ||
}); | ||
}); |
90 changes: 90 additions & 0 deletions
90
packages/calcite-components/src/components/autocomplete-item/autocomplete-item.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
* @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(); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@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?
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.
Like: