tldraw/apps/docs/components/Autocomplete.css
Mime Čuvalo 157d24db73
docs: rework search UI (#2723)
Reworks search to not be a page and instead to be inline dropdown.

<img width="763" alt="Screenshot 2024-02-05 at 13 22 58"
src="https://github.com/tldraw/tldraw/assets/469604/4e5a8076-62cd-44bb-b8e7-7f5ecdc4af24">


- rework search completely
- rm Search Results css
- uses Ariakit and add appropriate hooks / styling
- I couldn't use Radix unfortunately since they're still working on
adding a Combox: https://github.com/radix-ui/primitives/issues/1342
- I'm open to other suggestions but Ariakit plays nicely with Radix and
keeps things open to migrate to Radix in the future
- fixes bug with not scrolling to right place when having a direct link
- adds categories in the search results - examples / reference / learn
- and adds category icons. Let me know if there's a better policy for
adding new SVG icons cc @steveruizok

### Change Type

- [x] `minor` — New feature

### Test Plan

1. Test searches using normal method for each type (examples, docs,
refs)
2. Test searches using AI for each type (ditto)

### Release Notes

- Docs: rework the search to be an inline dropdown.
2024-02-05 14:32:50 +00:00

193 lines
3.7 KiB
CSS

.autocomplete__wrapper {
position: relative;
display: flex;
height: 40px;
flex-direction: row;
border-radius: 24px;
padding: 0 16px;
background-color: var(--color-tint-1);
}
.autocomplete__input {
position: relative;
padding-left: 20px;
height: 100%;
width: 100%;
border-radius: 4px;
border: none;
background-color: var(--color-background);
font-family: var(--font-body);
font-size: 14px;
background-color: none;
background: none;
}
.autocomplete__input:disabled {
/* background-color: var(--color-tint-1); */
color: var(--color-tint-5);
}
.autocomplete__input::placeholder {
color: var(--color-tint-5);
}
.autocomplete__input:focus {
outline: none;
}
.autocomplete__icon {
position: absolute;
top: 50%;
transform: translateY(-50%);
color: var(--color-tint-5);
left: 12px;
z-index: 2;
pointer-events: none;
transition: color 0.12s;
}
.autocomplete__cancel {
display: none;
}
.autocomplete__wrapper:focus-within .autocomplete__cancel {
display: flex;
}
.autocomplete__cancel {
justify-content: center;
align-items: center;
position: absolute;
top: 50%;
right: 12px;
transform: translateY(-50%);
z-index: 2;
border: 0;
cursor: pointer;
height: 24px;
min-width: 24px;
line-height: 26px;
color: var(--color-tint-6);
background-color: var(--color-tint-2);
border-radius: 2px;
}
.autocomplete__item__icon {
width: 24px;
height: 24px;
flex: 0 0 24px;
}
.autocomplete__group {
font-size: 14px;
font-weight: normal;
color: var(--color-text-secondary);
text-transform: uppercase;
white-space: nowrap;
}
.autocomplete__wrapper:focus-within .autocomplete__icon {
color: var(--color-text);
}
.autocomplete__item {
position: relative;
display: flex;
height: 2.5rem;
cursor: default;
scroll-margin-top: 0.25rem;
scroll-margin-bottom: 0.25rem;
align-items: center;
border-radius: 0.25rem;
padding-left: 1.75rem;
padding-right: 1.75rem;
color: hsl(204 10% 10%);
outline: 2px solid transparent;
outline-offset: 2px;
}
.autocomplete__item [data-user-value] {
font-weight: bold;
}
@media (min-width: 640px) {
.autocomplete__item {
height: 2.25rem;
font-size: 15px;
}
}
.autocomplete__popover {
position: relative;
z-index: 50;
display: flex;
max-height: min(var(--popover-available-height, 300px), 300px);
flex-direction: column;
overflow: auto;
overscroll-behavior: contain;
border-radius: 0.5rem;
border-width: 1px;
border-style: solid;
border-color: hsl(204 20% 88%);
background-color: hsl(204 20% 100%);
padding: 0.5rem;
color: hsl(204 10% 10%);
outline: 2px solid transparent;
outline-offset: 2px;
box-shadow:
0 10px 15px -3px rgb(0 0 0 / 0.1),
0 4px 6px -4px rgb(0 0 0 / 0.1);
}
:is([data-theme="dark"] .autocomplete__popover) {
border-color: hsl(204 3% 26%);
background-color: hsl(204 3% 18%);
color: hsl(204 20% 100%);
box-shadow:
0 10px 15px -3px rgb(0 0 0 / 0.25),
0 4px 6px -4px rgb(0 0 0 / 0.1);
}
.autocomplete__item {
display: flex;
cursor: pointer;
scroll-margin: 0.5rem;
align-items: center;
gap: 0.5rem;
border-radius: 0.25rem;
padding: 0.5rem;
outline: none !important;
white-space: nowrap;
overflow: hidden;
}
.autocomplete__item:hover {
background-color: hsl(204 100% 80% / 0.4);
}
.autocomplete__item[data-active-item] {
background-color: hsl(204 100% 40%);
color: hsl(204 20% 100%);
}
.autocomplete__item:active,
.autocomplete__item[data-active] {
padding-top: 9px;
padding-bottom: 7px;
}
:is([data-theme="dark"] .autocomplete__item) {
color: hsl(204 20% 100%);
}
:is([data-theme="dark"] .autocomplete__item__icon path) {
fill: hsl(204 20% 100%);
}
:is([data-theme="dark"] .autocomplete__item:hover) {
background-color: hsl(204 100% 40% / 0.25);
}
:is([data-theme="dark"] .autocomplete__item)[data-active-item] {
background-color: hsl(204 100% 40%);
}