This is my solution to the GitHub user search app challenge on Frontend Mentor.
Users should be able to:
- View the optimal layout for the app depending on their device's screen size
- See hover states for all interactive elements on the page
- Search for GitHub users by their username
- See relevant user information based on their search
- Switch between light and dark themes
- Bonus: Have the correct color scheme chosen for them based on their computer preferences. Hint: Research
prefers-color-scheme
in CSS.
- Solution URL: https://github.com/kateneilsen/github-user-search-svelte
- Live Site URL: https://github-user-search-svelte.vercel.app/
- Svelte - JS Framework
- JavaScript
- Mobile-first workflow
This is my first project using the svelte framework. Key Takeaways:
- svelte has two-way data binding!
- create custom events using the
createEventDispatcher
utility. This allows you to bubble up an event to the parent component. - component scoped styles (did not utilize this but plan to in the future)
Search.svelte
import { createEventDispatcher } from "svelte";
const dispatch = createEventDispatcher();
<button
class="search-button"
on:click={() => dispatch("filter", searchFilter)}
on:keydown={() => dispatch("filter", searchFilter)}
>
Search
</button>;
App.svelte:
const getUser = async () => {
if (searchFilter === "") {
const data = await fetch(`${base_url}/octocat`);
const result = await data.json();
user = result;
} else {
const data = await fetch(`${base_url}/${searchFilter}`);
if (data.status === 404) {
searchError = true;
searchFilter = "";
} else {
searchError = false;
const result = await data.json();
user = result;
}
}
};
<Search
{isDarkMode}
bind:searchFilter
on:filter={() => getUser()}
{searchError}
/>
- local storage
- Svelte stores
- accessibility in svelte
- Custom Svelte Store - This helped me with understanding custom stores in svelte and working with the css 'prefers-color-scheme'.
- MDN: Svelte - This is my first project using svelte. I used this article to help me learn the basics and apply them to this project.
- GitHub - @kateneilsen
- Frontend Mentor - @kateneilsen