Skip to content

Instantly share code, notes, and snippets.

View dev-cyprium's full-sized avatar
⚗️
Mixing Elixir Brew

Stefan Kupresak dev-cyprium

⚗️
Mixing Elixir Brew
  • Serbia - Belgrade
View GitHub Profile
@dev-cyprium
dev-cyprium / ComboBox.razor
Created October 27, 2023 23:08
Combo-box
@using LeagueHandlerCore.DTO.Forms
@inject IJSRuntime JSRuntime
<div @ref="containerRef" data-external-click>
<input type="hidden" name="home-id">
<label for="combobox" class="block text-sm font-medium leading-6 text-gray-900">@Label</label>
<div class="relative mt-2">
<h1>Show Dropdown: @ShowDropdown</h1>
<input @onfocus="OnFocus" @bind:event="oninput" @bind="Search" id="combobox" type="text" class="w-full rounded-md border-0 bg-white py-1.5 pl-3 pr-12 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" role="combobox" aria-controls="options" aria-expanded="@ShowDropdown">
// router/index.js
const RouterView = ({ config, notFound }) => {
const router = useRouter();
let Component = config[router.route] || null;
let NotFound = notFound;
return Component ? <Component /> : <NotFound />;
};
/*
router/index.js
*/
/* Rest of the router code */
const Link = ({ href, activeClass, children }) => {
const router = useRouter();
const navTo = (route) => (ev) => {
import { useRouter } from './router';
function Navigation() {
const router = useRouter();
const changeRoute = (route) => () => {
router.push(route);
}
return (
export default function App() {
/* ... */
return <AppRouter>
{/* Rest of the components */}
</AppRouter>
}
@dev-cyprium
dev-cyprium / index.js
Created February 22, 2021 21:25
router/index.js
import React, {
useContext,
createContext,
useEffect,
useState,
cloneElement
} from "react";
const RouterContext = createContext({ route: "", push: () => {} });
@dev-cyprium
dev-cyprium / App.jsx
Created February 22, 2021 20:18
Recap
import { createContext, useContext, useState, useEffect } from "react";
const RouterContext = createContext(/* Context */);
const Home = () => {
/* The route view */
}
const Page = () => {
/* The page view */
const RouterView = ({ config }) => {
const router = useContext(RouterContext);
let Component = config[router.route] || null;
return <Component />;
};
@dev-cyprium
dev-cyprium / App.jsx
Created February 22, 2021 20:08
Creating the router
const AppRouter = ({ children }) => {
const [route, setRoute] = useState("/");
function push(newRoute) {
setRoute(newRoute);
}
useEffect(() => {
window.history.pushState({}, "", route);
}, [route]);
@dev-cyprium
dev-cyprium / App.jsx
Created February 22, 2021 19:35
Router Context
// File App.js
const RouterContext = createContext({
route: "/",
push: () => {}
});