-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(theme): introduce Autocomplete Classic Theme (#409)
Co-authored-by: François Chalifour <[email protected]>
- Loading branch information
1 parent
74e319f
commit 226fc54
Showing
19 changed files
with
811 additions
and
282 deletions.
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
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
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
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,31 @@ | ||
function initTheme() { | ||
if (isDarkThemeSelected()) { | ||
applyDarkTheme(); | ||
} else { | ||
applyLightTheme(); | ||
} | ||
} | ||
|
||
export function isDarkThemeSelected() { | ||
return localStorage.getItem('darkMode') === 'dark'; | ||
} | ||
|
||
function applyDarkTheme() { | ||
document.body.setAttribute('data-theme', 'dark'); | ||
localStorage.setItem('darkMode', 'dark'); | ||
} | ||
|
||
function applyLightTheme() { | ||
document.body.removeAttribute('data-theme'); | ||
localStorage.removeItem('darkMode'); | ||
} | ||
|
||
export function toggleTheme() { | ||
if (isDarkThemeSelected()) { | ||
applyLightTheme(); | ||
} else { | ||
applyDarkTheme(); | ||
} | ||
} | ||
|
||
initTheme(); |
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
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,98 @@ | ||
import { AutocompletePlugin } from '@algolia/autocomplete-js'; | ||
|
||
import { toggleTheme, isDarkThemeSelected } from './darkMode'; | ||
|
||
type DarkModeItem = { | ||
label: string; | ||
}; | ||
|
||
export const shortcutsPlugin: AutocompletePlugin<DarkModeItem> = { | ||
getSources({ query }) { | ||
if (query !== '/' && query !== 'dark' && query !== 'light') { | ||
return []; | ||
} | ||
|
||
return [ | ||
{ | ||
getItems() { | ||
return [ | ||
{ | ||
label: 'Toggle dark mode', | ||
}, | ||
]; | ||
}, | ||
onSelect({ setIsOpen }) { | ||
toggleTheme(); | ||
setIsOpen(true); | ||
}, | ||
templates: { | ||
header({ createElement, Fragment }) { | ||
return createElement( | ||
Fragment, | ||
{}, | ||
createElement( | ||
'span', | ||
{ className: 'aa-SourceHeaderTitle' }, | ||
'Shortcuts' | ||
), | ||
createElement('div', { className: 'aa-SourceHeaderLine' }) | ||
); | ||
}, | ||
item({ item, createElement, Fragment }) { | ||
const darkIcon = createElement( | ||
'svg', | ||
{ | ||
xmlns: 'http://www.w3.org/2000/svg', | ||
fill: 'none', | ||
viewBox: '0 0 24 24', | ||
stroke: 'currentColor', | ||
}, | ||
createElement('path', { | ||
strokeLinecap: 'round', | ||
strokeLinejoin: 'round', | ||
strokeWidth: 2, | ||
d: | ||
'M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z', | ||
}) | ||
); | ||
const lightIcon = createElement( | ||
'svg', | ||
{ | ||
xmlns: 'http://www.w3.org/2000/svg', | ||
fill: 'none', | ||
viewBox: '0 0 24 24', | ||
stroke: 'currentColor', | ||
}, | ||
createElement('path', { | ||
strokeLinecap: 'round', | ||
strokeLinejoin: 'round', | ||
strokeWidth: 2, | ||
d: | ||
'M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z', | ||
}) | ||
); | ||
|
||
return createElement( | ||
Fragment, | ||
{}, | ||
createElement( | ||
'div', | ||
{ className: 'aa-ItemIcon' }, | ||
isDarkThemeSelected() ? lightIcon : darkIcon | ||
), | ||
createElement( | ||
'div', | ||
{ className: 'aa-ItemContent' }, | ||
createElement( | ||
'div', | ||
{ className: 'aa-ItemContentTitle' }, | ||
item.label | ||
) | ||
) | ||
); | ||
}, | ||
}, | ||
}, | ||
]; | ||
}, | ||
}; |
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
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
.container { | ||
margin: 0 auto; | ||
max-width: 640px; | ||
padding: 1rem; | ||
width: 100%; | ||
} | ||
|
||
.aa-Panel { | ||
max-width: 640px; | ||
width: 100%; | ||
} |
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
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
Oops, something went wrong.