Skip to content

Commit

Permalink
feat: new Search component (#506)
Browse files Browse the repository at this point in the history
* fix(combobox): stop onInputChange trigger on onChange 

* feat(combobox): add `noResetInputOnBlur` feature to prevent input resets on combobox blur

* fix(combobox): `allowsEmptyCollection` should display dropdown even when `options` is empty

---------

Co-authored-by: jer3m01 <[email protected]>
  • Loading branch information
MengLinMaker and jer3m01 authored Nov 3, 2024
1 parent 5312ce7 commit e57dd03
Show file tree
Hide file tree
Showing 19 changed files with 2,750 additions and 365 deletions.
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
auto-install-peers=true
strict-peer-dependencies=false
link-workspace-packages=true
prefer-workspace-packages=true
15 changes: 8 additions & 7 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,38 @@
"dependencies": {
"@docsearch/css": "3.5.2",
"@docsearch/js": "3.5.2",
"@kobalte/core": "0.13.7",
"@kobalte/core": "workspace:*",
"@solidjs/meta": "0.29.3",
"@solidjs/router": "0.12.4",
"@solidjs/start": "0.6.1",
"@tanstack/solid-virtual": "3.0.0-beta.6",
"clsx": "2.0.0",
"minisearch": "7.1.0",
"solid-js": "1.8.15",
"@solidjs/start": "0.6.1",
"vinxi": "0.3.9",
"undici": "5.23.0"
"undici": "5.23.0",
"vinxi": "0.3.9"
},
"devDependencies": {
"@kobalte/tailwindcss": "0.9.0",
"@mdx-js/mdx": "3.0.0",
"@mdx-js/rollup": "3.0.0",
"@tailwindcss/typography": "0.5.9",
"@vinxi/plugin-mdx": "3.7.1",
"acorn": "8.10.0",
"autoprefixer": "10.4.15",
"github-slugger": "2.0.0",
"postcss": "8.4.28",
"rehype-pretty-code": "0.12.3",
"remark-shiki-twoslash": "3.1.3",
"rehype-raw": "7.0.0",
"rehype-slug": "6.0.0",
"remark-gfm": "4.0.0",
"remark-shiki-twoslash": "3.1.3",
"shiki": "0.14.7",
"solid-mdx": "0.0.7",
"tailwindcss": "3.3.3",
"typescript": "4.9.5",
"unist-util-visit": "5.0.0",
"vite": "5.1.4",
"@vinxi/plugin-mdx": "3.7.1"
"vite": "5.1.4"
},
"engines": {
"node": ">=18"
Expand Down
38 changes: 38 additions & 0 deletions apps/docs/src/components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,41 @@ export function ArrowIcon(props: ComponentProps<"svg">) {
</svg>
);
}

export function MagnifyingGlassIcon(props: ComponentProps<"svg">) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 15 15"
fill="currentColor"
{...props}
>
<title>Magnifying Glass</title>
<path
d="M10 6.5C10 8.433 8.433 10 6.5 10C4.567 10 3 8.433 3 6.5C3 4.567 4.567 3 6.5 3C8.433 3 10 4.567 10 6.5ZM9.30884 10.0159C8.53901 10.6318 7.56251 11 6.5 11C4.01472 11 2 8.98528 2 6.5C2 4.01472 4.01472 2 6.5 2C8.98528 2 11 4.01472 11 6.5C11 7.56251 10.6318 8.53901 10.0159 9.30884L12.8536 12.1464C13.0488 12.3417 13.0488 12.6583 12.8536 12.8536C12.6583 13.0488 12.3417 13.0488 12.1464 12.8536L9.30884 10.0159Z"
fill="currentColor"
fill-rule="evenodd"
clip-rule="evenodd"
/>
</svg>
);
}

export function ReloadIcon(props: ComponentProps<"svg">) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 15 15"
fill="currentColor"
{...props}
>
<title>Reload</title>
<path
d="M1.84998 7.49998C1.84998 4.66458 4.05979 1.84998 7.49998 1.84998C10.2783 1.84998 11.6515 3.9064 12.2367 5H10.5C10.2239 5 10 5.22386 10 5.5C10 5.77614 10.2239 6 10.5 6H13.5C13.7761 6 14 5.77614 14 5.5V2.5C14 2.22386 13.7761 2 13.5 2C13.2239 2 13 2.22386 13 2.5V4.31318C12.2955 3.07126 10.6659 0.849976 7.49998 0.849976C3.43716 0.849976 0.849976 4.18537 0.849976 7.49998C0.849976 10.8146 3.43716 14.15 7.49998 14.15C9.44382 14.15 11.0622 13.3808 12.2145 12.2084C12.8315 11.5806 13.3133 10.839 13.6418 10.0407C13.7469 9.78536 13.6251 9.49315 13.3698 9.38806C13.1144 9.28296 12.8222 9.40478 12.7171 9.66014C12.4363 10.3425 12.0251 10.9745 11.5013 11.5074C10.5295 12.4963 9.16504 13.15 7.49998 13.15C4.05979 13.15 1.84998 10.3354 1.84998 7.49998Z"
fill="currentColor"
fill-rule="evenodd"
clip-rule="evenodd"
/>
</svg>
);
}
285 changes: 285 additions & 0 deletions apps/docs/src/examples/search.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
.search__control {
overflow: hidden;
display: inline-flex;
justify-content: space-between;
width: 250px;
border-radius: 6px;
font-size: 16px;
line-height: 1;
outline: none;
background-color: white;
border: 1px solid hsl(240 6% 90%);
color: hsl(240 4% 16%);
transition:
border-color 250ms,
color 250ms;
}

.search__control_multi {
width: 100%;
min-width: 250px;
max-width: 300px;
}

.search__input {
appearance: none;
display: inline-flex;
width: 100%;
min-height: 40px;
padding-left: 16px;
font-size: 16px;
background: transparent;
border-top-left-radius: 6px;
border-bottom-left-radius: 6px;
outline: none;
}

.search__input::placeholder {
color: hsl(240 4% 46%);
}

.search__indicator {
appearance: none;
display: inline-flex;
justify-content: center;
align-items: center;
width: auto;
outline: none;
padding: 0 10px;
background-color: hsl(240 5% 96%);
border-right: 1px solid hsl(240 6% 90%);
color: hsl(240 4% 16%);
font-size: 16px;
line-height: 0;
transition: 250ms background-color;
}

.search__icon {
height: 20px;
width: 20px;
flex: 0 0 16px;
display: grid;
justify-items: center;
}

.load__icon {
height: 20px;
width: 20px;
display: grid;
justify-items: center;
flex: 0 0 14px;
}

.center__icon {
margin: auto;
}

.spin__icon {
animation: spin 600ms linear;
animation-iteration-count: infinite;
margin: auto;
}

.search__description {
margin-top: 8px;
color: hsl(240 5% 26%);
font-size: 12px;
user-select: none;
}

.search__content {
background-color: white;
border-radius: 6px;
border: 1px solid hsl(240 6% 90%);
box-shadow:
0 4px 6px -1px rgb(0 0 0 / 0.1),
0 2px 4px -2px rgb(0 0 0 / 0.1);
transform-origin: var(--kb-search-content-transform-origin);
animation: contentHide 250ms ease-in forwards;
}

.search__content[data-expanded] {
animation: contentShow 250ms ease-out;
}

.search__listbox {
overflow-y: auto;
max-height: 360px;
padding: 8px;
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
row-gap: 6px;
column-gap: 6px;
line-height: 1;
}

.search__listbox:focus {
outline: none;
}

.search__item {
font-size: 24px;
line-height: 1;
color: hsl(240 4% 16%);
border-radius: 16px;
padding: 8px;
position: relative;
user-select: none;
outline: none;
display: grid;
justify-items: center;
}

.search__item[data-disabled] {
color: hsl(240 5% 65%);
opacity: 0.5;
pointer-events: none;
}

.search__item[data-highlighted] {
outline: none;
box-sizing: border-box;
box-shadow: inset 0 0 0 2px hsl(200 98% 39%);
}

.search__section {
padding: 8px 0 0 8px;
font-size: 14px;
line-height: 32px;
color: hsl(240 4% 46%);
}

.search__no_result {
text-align: center;
padding: 8px;
padding-bottom: 24px;
margin: auto;
color: hsl(240 4% 46%);
}

@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@keyframes contentShow {
from {
opacity: 0;
transform: translateY(-8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}

@keyframes contentHide {
from {
opacity: 1;
transform: translateY(0);
}
to {
opacity: 0;
transform: translateY(-8px);
}
}

[data-kb-theme="dark"] .search__control {
background-color: hsl(240 4% 16%);
border: 1px solid hsl(240 5% 34%);
color: hsl(0 100% 100% / 0.9);
}

[data-kb-theme="dark"] .search__control:hover {
border-color: hsl(240 4% 46%);
}

[data-kb-theme="dark"] .search__input::placeholder {
color: hsl(0 100% 100% / 0.5);
}

[data-kb-theme="dark"] .search__indicator {
background: hsl(240 5% 26%);
border-right: 1px solid hsl(240 5% 34%);
color: hsl(0 100% 100% / 0.9);
}

[data-kb-theme="dark"] .search__content {
border: 1px solid hsl(240 5% 26%);
background-color: hsl(240 4% 16%);
box-shadow: none;
}

[data-kb-theme="dark"] .search__section {
color: hsl(0 100% 100% / 0.7);
}

[data-kb-theme="dark"] .search__item {
color: hsl(0 100% 100% / 0.9);
}

[data-kb-theme="dark"] .search__description {
color: hsl(0 100% 100% / 0.7);
}

.result__content {
margin-top: 16px;
font-size: 16px;
line-height: 1;
}

.search__root_cmdk {
min-height: 240px;
min-width: 250px;
display: flex;
flex-direction: column;
}

.search__control_cmdk {
overflow: hidden;
display: inline-flex;
justify-content: space-between;
border-radius: 12px 12px 0 0;
font-size: 16px;
line-height: 1;
outline: none;
background-color: white;
border: 1px solid hsl(240 6% 90%);
color: hsl(240 4% 16%);
transition:
border-color 250ms,
color 250ms;
}

.search__content_cmdk {
height: 100%;
flex-grow: 1;
background-color: white;
border-radius: 0 0 12px 12px;
border: 1px solid hsl(240 6% 90%);
border-top: none;
display: flex;
flex-direction: column;
}

.search__no_result_cmdk {
text-align: center;
margin: auto;
padding-bottom: 24px;
color: hsl(240 4% 46%);
}

[data-kb-theme="dark"] .search__control_cmdk {
background-color: hsl(240 4% 16%);
border: 1px solid hsl(240 5% 34%);
color: hsl(0 100% 100% / 0.9);
}

[data-kb-theme="dark"] .search__content_cmdk {
background-color: hsl(240 4% 16%);
border: 1px solid hsl(240 5% 34%);
}
Loading

0 comments on commit e57dd03

Please sign in to comment.