Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 36 additions & 0 deletions packages/docsearch/DocSearch.astro
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ const docsearchTranslations: DocSearchTranslationProps = {
mask-size: 100%;
background-color: currentColor;
}
.DocSearch-Button-Key:first-child {
margin-right: 0.4em;
}
.DocSearch-Button-Key {
display: inline-block;
font-size: 0.75em;
font-weight: 600;
opacity: 0.8;
border: 1px solid var(--sl-color-gray-4);
border-radius: 0.25rem;
padding: 0.125rem 0.375rem;
background-color: var(--sl-color-gray-6);
color: var(--sl-color-gray-1);
line-height: 1;
}
}
</style>

Expand All @@ -136,6 +151,27 @@ const docsearchTranslations: DocSearchTranslationProps = {
Object.assign(options, translations);
} catch {}
docsearch(options);

const keyboardShortcuts = options.keyboardShortcuts ?? {};
const slashEnabled = keyboardShortcuts?.['/'] !== false;
const ctrlCmdKEnabled = keyboardShortcuts?.['Ctrl/Cmd+K'] !== false;

if (slashEnabled && !ctrlCmdKEnabled) {
const styleContainer = document.createElement('style');
styleContainer.innerHTML = `
.DocSearch-Button-Keys::before {
content: '';
width: 1em;
height: 1em;
-webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M17 2H7a5 5 0 0 0-5 5v10a5 5 0 0 0 5 5h10a5 5 0 0 0 5-5V7a5 5 0 0 0-5-5Zm3 15a3 3 0 0 1-3 3H7a3 3 0 0 1-3-3V7a3 3 0 0 1 3-3h10a3 3 0 0 1 3 3v10Z'%3E%3C/path%3E%3Cpath d='M15.293 6.707a1 1 0 1 1 1.414 1.414l-8.485 8.486a1 1 0 0 1-1.414-1.415l8.485-8.485Z'%3E%3C/path%3E%3C/svg%3E");
mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M17 2H7a5 5 0 0 0-5 5v10a5 5 0 0 0 5 5h10a5 5 0 0 0 5-5V7a5 5 0 0 0-5-5Zm3 15a3 3 0 0 1-3 3H7a3 3 0 0 1-3-3V7a3 3 0 0 1 3-3h10a3 3 0 0 1 3 3v10Z'%3E%3C/path%3E%3Cpath d='M15.293 6.707a1 1 0 1 1 1.414 1.414l-8.485 8.486a1 1 0 0 1-1.414-1.415l8.485-8.485Z'%3E%3C/path%3E%3C/svg%3E");
-webkit-mask-size: 100%;
mask-size: 100%;
background-color: currentColor;
}
`;
document.head.appendChild(styleContainer);
}
});
}
}
Expand Down
12 changes: 12 additions & 0 deletions packages/docsearch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ const DocSearchConfigSchema = z
* @see https://www.algolia.com/doc/api-reference/search-api-parameters/
*/
searchParameters: z.custom<SearchOptions>(),
/**
* Configuration for keyboard shortcuts that trigger the DocSearch modal.
* @see https://docsearch.algolia.com/docs/api/#keyboardshortcuts
*/
keyboardShortcuts: z
.object({
/** Enable/disable Ctrl/Cmd+K shortcut. @default true */
'Ctrl/Cmd+K': z.boolean().optional(),
/** Enable/disable / shortcut. @default true */
'/': z.boolean().optional(),
})
.optional(),
})
.strict()
.or(
Expand Down