Compare commits

...

2 Commits
master ... dev

124 changed files with 7143 additions and 9159 deletions

View File

@ -78,12 +78,25 @@ impl App {
.await; .await;
}; };
#[cfg(all(unix, debug_assertions))]
let quit = async {
signal::unix::signal(signal::unix::SignalKind::quit())
.expect("Failed to install SIGQUIT handler")
.recv()
.await;
println!("Received SIGQUIT");
};
#[cfg(not(unix))] #[cfg(not(unix))]
let terminate = std::future::pending::<()>(); let terminate = std::future::pending::<()>();
#[cfg(all(not(unix), debug_assertions))]
let quit = std::future::pending::<()>();
tokio::select! { tokio::select! {
() = ctrl_c => {}, () = ctrl_c => {},
() = terminate => {}, () = terminate => {},
() = quit => {},
} }
} }
} }

View File

@ -0,0 +1,20 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "src/app.css",
"baseColor": "neutral",
"cssVariables": true
},
"aliases": {
"components": "@/components",
"utils": "@/styles/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
},
"iconLibrary": "lucide"
}

View File

@ -4,6 +4,20 @@
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script>
(function() {
try {
const theme = localStorage.getItem('prefers-color-scheme');
document.documentElement.classList.remove('dark', 'light');
if (theme === 'dark' || theme === 'light') {
document.documentElement.classList.add(theme);
} else {
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
document.documentElement.classList.add(systemTheme);
}
} catch(e) {}
})();
</script>
</head> </head>
<body> <body>

View File

@ -10,49 +10,79 @@
}, },
"dependencies": { "dependencies": {
"@abraham/reflection": "^0.12.0", "@abraham/reflection": "^0.12.0",
"@ark-ui/solid": "^4.10.2",
"@codemirror/language": "6.0.0", "@codemirror/language": "6.0.0",
"@corvu/drawer": "^0.2.3", "@corvu/drawer": "^0.2.3",
"@corvu/otp-field": "^0.1.4", "@corvu/otp-field": "^0.1.4",
"@corvu/resizable": "^0.2.4", "@corvu/resizable": "^0.2.4",
"@graphiql/toolkit": "^0.11.1", "@graphiql/toolkit": "^0.11.1",
"@kobalte/core": "^0.13.9", "@hookform/resolvers": "^5.0.1",
"@kobalte/tailwindcss": "^0.9.0",
"@outposts/injection-js": "^2.5.1", "@outposts/injection-js": "^2.5.1",
"@solid-primitives/graphql": "^2.2.0", "@radix-ui/react-accordion": "^1.2.7",
"@solid-primitives/refs": "^1.1.0", "@radix-ui/react-alert-dialog": "^1.1.10",
"@tailwindcss/postcss": "^4.0.9", "@radix-ui/react-aspect-ratio": "^1.1.4",
"@radix-ui/react-avatar": "^1.1.6",
"@radix-ui/react-checkbox": "^1.2.2",
"@radix-ui/react-collapsible": "^1.1.7",
"@radix-ui/react-context-menu": "^2.2.11",
"@radix-ui/react-dialog": "^1.1.10",
"@radix-ui/react-dropdown-menu": "^2.1.11",
"@radix-ui/react-hover-card": "^1.1.10",
"@radix-ui/react-label": "^2.1.4",
"@radix-ui/react-menubar": "^1.1.11",
"@radix-ui/react-navigation-menu": "^1.2.9",
"@radix-ui/react-popover": "^1.1.10",
"@radix-ui/react-progress": "^1.1.4",
"@radix-ui/react-radio-group": "^1.3.3",
"@radix-ui/react-scroll-area": "^1.2.5",
"@radix-ui/react-select": "^2.2.2",
"@radix-ui/react-separator": "^1.1.4",
"@radix-ui/react-slider": "^1.3.2",
"@radix-ui/react-slot": "^1.2.0",
"@radix-ui/react-switch": "^1.2.2",
"@radix-ui/react-tabs": "^1.1.8",
"@radix-ui/react-toggle": "^1.1.6",
"@radix-ui/react-toggle-group": "^1.1.7",
"@radix-ui/react-tooltip": "^1.2.3",
"@rsbuild/plugin-react": "^1.2.0",
"@tanstack/react-router": "^1.112.13", "@tanstack/react-router": "^1.112.13",
"@tanstack/router-devtools": "^1.112.13", "@tanstack/router-devtools": "^1.112.13",
"@tanstack/solid-router": "^1.112.12",
"arktype": "^2.1.6", "arktype": "^2.1.6",
"chart.js": "^4.4.8", "chart.js": "^4.4.8",
"class-variance-authority": "^0.7.1", "class-variance-authority": "^0.7.1",
"clsx": "^2.1.1", "clsx": "^2.1.1",
"cmdk-solid": "^1.1.2", "cmdk": "^1.1.1",
"embla-carousel-solid": "^8.5.2", "date-fns": "^4.1.0",
"embla-carousel-react": "^8.6.0",
"graphiql": "^3.8.3", "graphiql": "^3.8.3",
"lucide-solid": "^0.477.0", "input-otp": "^1.4.2",
"jotai": "^2.12.3",
"jotai-signal": "^0.9.0",
"lucide-react": "^0.503.0",
"next-themes": "^0.4.6",
"oidc-client-rx": "0.1.0-alpha.9", "oidc-client-rx": "0.1.0-alpha.9",
"react": "^18.3.1", "react": "^19.1.0",
"react-dom": "^18.3.1", "react-day-picker": "8.10.1",
"react-dom": "^19.1.0",
"react-hook-form": "^7.56.0",
"react-resizable-panels": "^2.1.7",
"recharts": "^2.15.3",
"rxjs": "^7.8.2", "rxjs": "^7.8.2",
"solid-js": "^1.9.5", "sonner": "^2.0.3",
"solid-sonner": "^0.2.8", "tailwind-merge": "^3.2.0",
"tailwind-merge": "^3.0.2", "tailwindcss": "^4.0.6",
"tailwindcss": "^3.4.17", "tw-animate-css": "^1.2.7",
"tailwindcss-animate": "^1.0.7" "type-fest": "^4.40.0",
"vaul": "^1.1.2",
"zod": "^3.24.3"
}, },
"devDependencies": { "devDependencies": {
"@rsbuild/core": "^1.2.15", "@rsbuild/core": "^1.2.15",
"@rsbuild/plugin-babel": "^1.0.4",
"@rsbuild/plugin-solid": "^1.0.5",
"@tailwindcss/postcss": "^4.0.9", "@tailwindcss/postcss": "^4.0.9",
"@tanstack/react-router": "^1.112.0", "@tanstack/react-router": "^1.112.0",
"@tanstack/router-devtools": "^1.112.6", "@tanstack/router-devtools": "^1.112.6",
"@tanstack/router-plugin": "^1.112.13", "@tanstack/router-plugin": "^1.112.13",
"@types/react": "^18.3.18", "@types/react": "^19.1.2",
"@types/react-dom": "^18.3.5", "@types/react-dom": "^19.1.2",
"chalk": "^5.4.1", "chalk": "^5.4.1",
"commander": "^13.1.0", "commander": "^13.1.0",
"postcss": "^8.5.3" "postcss": "^8.5.3"

View File

@ -1,5 +1,5 @@
export default { export default {
plugins: { plugins: {
'tailwindcss': {}, '@tailwindcss/postcss': {},
}, },
}; };

View File

@ -1,6 +1,5 @@
import { defineConfig } from '@rsbuild/core'; import { defineConfig } from '@rsbuild/core';
import { pluginBabel } from '@rsbuild/plugin-babel'; import { pluginReact } from '@rsbuild/plugin-react';
import { pluginSolid } from '@rsbuild/plugin-solid';
import { TanStackRouterRspack } from '@tanstack/router-plugin/rspack'; import { TanStackRouterRspack } from '@tanstack/router-plugin/rspack';
export default defineConfig({ export default defineConfig({
@ -8,16 +7,11 @@ export default defineConfig({
title: 'Konobangu', title: 'Konobangu',
favicon: './public/assets/favicon.ico', favicon: './public/assets/favicon.ico',
}, },
plugins: [ plugins: [pluginReact()],
pluginBabel({
include: /\.(?:jsx|tsx)$/,
}),
pluginSolid(),
],
tools: { tools: {
rspack: { rspack: {
plugins: [ plugins: [
TanStackRouterRspack({ target: 'solid', autoCodeSplitting: true }), TanStackRouterRspack({ target: 'react', autoCodeSplitting: true }),
], ],
}, },
}, },

View File

@ -1,149 +1,146 @@
@tailwind base; @import "tailwindcss";
@tailwind components; @import "tw-animate-css";
@tailwind utilities;
@layer base { @custom-variant dark (&:is(.dark *));
:root {
--background: 0 0% 100%;
--foreground: 240 10% 3.9%;
--muted: 240 4.8% 95.9%; :root {
--muted-foreground: 240 3.8% 46.1%; --radius: 0.625rem;
--background: oklch(1 0 0);
--foreground: oklch(0.145 0 0);
--card: oklch(1 0 0);
--card-foreground: oklch(0.145 0 0);
--popover: oklch(1 0 0);
--popover-foreground: oklch(0.145 0 0);
--primary: oklch(0.205 0 0);
--primary-foreground: oklch(0.985 0 0);
--secondary: oklch(0.97 0 0);
--secondary-foreground: oklch(0.205 0 0);
--muted: oklch(0.97 0 0);
--muted-foreground: oklch(0.556 0 0);
--accent: oklch(0.97 0 0);
--accent-foreground: oklch(0.205 0 0);
--destructive: oklch(0.577 0.245 27.325);
--border: oklch(0.922 0 0);
--input: oklch(0.922 0 0);
--ring: oklch(0.708 0 0);
--chart-1: oklch(0.646 0.222 41.116);
--chart-2: oklch(0.6 0.118 184.704);
--chart-3: oklch(0.398 0.07 227.392);
--chart-4: oklch(0.828 0.189 84.429);
--chart-5: oklch(0.769 0.188 70.08);
--sidebar: oklch(0.985 0 0);
--sidebar-foreground: oklch(0.145 0 0);
--sidebar-primary: oklch(0.205 0 0);
--sidebar-primary-foreground: oklch(0.985 0 0);
--sidebar-accent: oklch(0.97 0 0);
--sidebar-accent-foreground: oklch(0.205 0 0);
--sidebar-border: oklch(0.922 0 0);
--sidebar-ring: oklch(0.708 0 0);
}
--popover: 0 0% 100%; .dark {
--popover-foreground: 240 10% 3.9%; --background: oklch(0.145 0 0);
--foreground: oklch(0.985 0 0);
--card: oklch(0.205 0 0);
--card-foreground: oklch(0.985 0 0);
--popover: oklch(0.205 0 0);
--popover-foreground: oklch(0.985 0 0);
--primary: oklch(0.922 0 0);
--primary-foreground: oklch(0.205 0 0);
--secondary: oklch(0.269 0 0);
--secondary-foreground: oklch(0.985 0 0);
--muted: oklch(0.269 0 0);
--muted-foreground: oklch(0.708 0 0);
--accent: oklch(0.269 0 0);
--accent-foreground: oklch(0.985 0 0);
--destructive: oklch(0.704 0.191 22.216);
--border: oklch(1 0 0 / 10%);
--input: oklch(1 0 0 / 15%);
--ring: oklch(0.556 0 0);
--chart-1: oklch(0.488 0.243 264.376);
--chart-2: oklch(0.696 0.17 162.48);
--chart-3: oklch(0.769 0.188 70.08);
--chart-4: oklch(0.627 0.265 303.9);
--chart-5: oklch(0.645 0.246 16.439);
--sidebar: oklch(0.205 0 0);
--sidebar-foreground: oklch(0.985 0 0);
--sidebar-primary: oklch(0.488 0.243 264.376);
--sidebar-primary-foreground: oklch(0.985 0 0);
--sidebar-accent: oklch(0.269 0 0);
--sidebar-accent-foreground: oklch(0.985 0 0);
--sidebar-border: oklch(1 0 0 / 10%);
--sidebar-ring: oklch(0.556 0 0);
}
--border: 240 5.9% 90%; @theme inline {
--input: 240 5.9% 90%; --color-background: var(--background);
--color-foreground: var(--foreground);
--color-card: var(--card);
--color-card-foreground: var(--card-foreground);
--color-popover: var(--popover);
--color-popover-foreground: var(--popover-foreground);
--color-primary: var(--primary);
--color-primary-foreground: var(--primary-foreground);
--color-secondary: var(--secondary);
--color-secondary-foreground: var(--secondary-foreground);
--color-muted: var(--muted);
--color-muted-foreground: var(--muted-foreground);
--color-accent: var(--accent);
--color-accent-foreground: var(--accent-foreground);
--color-destructive: var(--destructive);
--color-destructive-foreground: var(--destructive-foreground);
--color-border: var(--border);
--color-input: var(--input);
--color-ring: var(--ring);
--color-chart-1: var(--chart-1);
--color-chart-2: var(--chart-2);
--color-chart-3: var(--chart-3);
--color-chart-4: var(--chart-4);
--color-chart-5: var(--chart-5);
--radius-sm: calc(var(--radius) - 4px);
--radius-md: calc(var(--radius) - 2px);
--radius-lg: var(--radius);
--radius-xl: calc(var(--radius) + 4px);
--color-sidebar: var(--sidebar);
--color-sidebar-foreground: var(--sidebar-foreground);
--color-sidebar-primary: var(--sidebar-primary);
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
--color-sidebar-accent: var(--sidebar-accent);
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
--color-sidebar-border: var(--sidebar-border);
--color-sidebar-ring: var(--sidebar-ring);
--animate-accordion-down: accordion-down 0.2s ease-out;
--animate-accordion-up: accordion-up 0.2s ease-out;
--card: 0 0% 100%; @keyframes accordion-down {
--card-foreground: 240 10% 3.9%; from {
height: 0;
--primary: 240 5.9% 10%; }
--primary-foreground: 0 0% 98%; to {
height: var(--radix-accordion-content-height);
--secondary: 240 4.8% 95.9%; }
--secondary-foreground: 240 5.9% 10%;
--accent: 240 4.8% 95.9%;
--accent-foreground: 240 5.9% 10%;
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 0 0% 98%;
--info: 204 94% 94%;
--info-foreground: 199 89% 48%;
--success: 149 80% 90%;
--success-foreground: 160 84% 39%;
--warning: 48 96% 89%;
--warning-foreground: 25 95% 53%;
--error: 0 93% 94%;
--error-foreground: 0 84% 60%;
--ring: 240 5.9% 10%;
--radius: 0.5rem;
--sidebar-background: 0 0% 98%;
--sidebar-foreground: 240 5.3% 26.1%;
--sidebar-primary: 240 5.9% 10%;
--sidebar-primary-foreground: 0 0% 98%;
--sidebar-accent: 240 4.8% 95.9%;
--sidebar-accent-foreground: 240 5.9% 10%;
--sidebar-border: 220 13% 91%;
--sidebar-ring: 217.2 91.2% 59.8%;
} }
.dark, @keyframes accordion-up {
[data-kb-theme="dark"] { from {
--background: 240 10% 3.9%; height: var(--radix-accordion-content-height);
--foreground: 0 0% 98%; }
to {
--muted: 240 3.7% 15.9%; height: 0;
--muted-foreground: 240 5% 64.9%; }
--accent: 240 3.7% 15.9%;
--accent-foreground: 0 0% 98%;
--popover: 240 10% 3.9%;
--popover-foreground: 0 0% 98%;
--border: 240 3.7% 15.9%;
--input: 240 3.7% 15.9%;
--card: 240 10% 3.9%;
--card-foreground: 0 0% 98%;
--primary: 0 0% 98%;
--primary-foreground: 240 5.9% 10%;
--secondary: 240 3.7% 15.9%;
--secondary-foreground: 0 0% 98%;
--destructive: 0 62.8% 30.6%;
--destructive-foreground: 0 0% 98%;
--info: 204 94% 94%;
--info-foreground: 199 89% 48%;
--success: 149 80% 90%;
--success-foreground: 160 84% 39%;
--warning: 48 96% 89%;
--warning-foreground: 25 95% 53%;
--error: 0 93% 94%;
--error-foreground: 0 84% 60%;
--ring: 240 4.9% 83.9%;
--radius: 0.5rem;
--sidebar-background: 240 5.9% 10%;
--sidebar-foreground: 240 4.8% 95.9%;
--sidebar-primary: 224.3 76.3% 48%;
--sidebar-primary-foreground: 0 0% 100%;
--sidebar-accent: 240 3.7% 15.9%;
--sidebar-accent-foreground: 240 4.8% 95.9%;
--sidebar-border: 240 3.7% 15.9%;
--sidebar-ring: 217.2 91.2% 59.8%;
} }
/* custom start */
::-webkit-scrollbar {
width: 16px;
}
::-webkit-scrollbar-thumb {
border-radius: 9999px;
border: 4px solid transparent;
background-clip: content-box;
@apply bg-accent;
}
::-webkit-scrollbar-corner {
display: none;
}
/* custom end */
} }
@layer base { @layer base {
* { * {
@apply border-border; @apply border-border outline-ring/50;
} }
body { body {
@apply bg-background text-foreground; @apply bg-background text-foreground;
font-feature-settings:
"rlig" 1,
"calt" 1;
} }
}
@media (max-width: 640px) { button:not(:disabled),
.container { [role="button"]:not(:disabled) {
@apply px-4; cursor: pointer;
} }
} }

View File

@ -1,7 +1,14 @@
import { LogLevel, type OpenIdConfiguration } from 'oidc-client-rx'; import { LogLevel, type OpenIdConfiguration } from 'oidc-client-rx';
import type { ValueOf } from 'type-fest';
export const isBasicAuth = process.env.AUTH_TYPE === 'basic'; export const AuthMethodEnum = {
export const isOidcAuth = process.env.AUTH_TYPE === 'oidc'; BASIC: 'basic',
OIDC: 'oidc',
} as const;
export type AuthMethodType = ValueOf<typeof AuthMethodEnum>;
export const AppAuthMethod = process.env.AUTH_TYPE as AuthMethodType;
export function buildOidcConfig(): OpenIdConfiguration { export function buildOidcConfig(): OpenIdConfiguration {
const origin = window.location.origin; const origin = window.location.origin;

View File

@ -1,4 +1,85 @@
import { createSignal } from 'solid-js'; import { UnreachableError } from '@/errors/common';
import { isBasicAuth } from './config'; import type { Injector, Provider } from '@outposts/injection-js';
import type { AnyRouter } from '@tanstack/react-router';
import { atomSignal } from 'jotai-signal';
import type { Atom } from 'jotai/vanilla';
import {
CHECK_AUTH_RESULT_EVENT,
type CheckAuthResultEventType,
OidcSecurityService,
provideAuth as provideOidcAuth,
withCheckAuthResultEvent,
withDefaultFeatures,
} from 'oidc-client-rx';
import { withTanstackRouter } from 'oidc-client-rx/adapters/@tanstack/react-router';
import { NEVER, type Observable, map, of } from 'rxjs';
import { AppAuthMethod, AuthMethodEnum, buildOidcConfig } from './config';
export const [isAuthenticated, setIsAuthenticated] = createSignal(isBasicAuth); export function provideAuth(router: AnyRouter): Provider[] {
if (AppAuthMethod === AuthMethodEnum.OIDC) {
return provideOidcAuth(
{
config: buildOidcConfig(),
},
withDefaultFeatures({
router: { enabled: false },
securityStorage: { type: 'local-storage' },
}),
withTanstackRouter(router),
withCheckAuthResultEvent()
);
}
return [];
}
export function setupAuthContext(injector: Injector) {
if (AppAuthMethod === AuthMethodEnum.OIDC) {
const oidcSecurityService = injector.get(OidcSecurityService);
oidcSecurityService.checkAuth().subscribe();
}
}
export interface OidcAuthContext {
type: typeof AuthMethodEnum.OIDC;
oidcSecurityService: OidcSecurityService;
isAuthenticated$: Observable<boolean>;
userData$: Observable<any>;
checkAuthResultEvent$: Observable<CheckAuthResultEventType>;
}
export interface BasicAuthContext {
type: typeof AuthMethodEnum.BASIC;
isAuthenticated$: Observable<true>;
userData$: Observable<{}>;
checkAuthResultEvent$: Observable<CheckAuthResultEventType>;
}
export type AuthContext = OidcAuthContext | BasicAuthContext;
const BASIC_AUTH_IS_AUTHENTICATED$ = of(true) as Observable<true>;
const BASIC_AUTH_USER_DATA$ = of({});
export function authContextFromInjector(injector: Injector): AuthContext {
if (AppAuthMethod === AuthMethodEnum.OIDC) {
const oidcSecurityService = injector.get(OidcSecurityService)!;
return {
type: AuthMethodEnum.OIDC,
oidcSecurityService: injector.get(OidcSecurityService),
isAuthenticated$: oidcSecurityService.isAuthenticated$.pipe(
map((s) => s.isAuthenticated)
),
userData$: oidcSecurityService.userData$.pipe(map((s) => s.userData)),
checkAuthResultEvent$: injector.get(CHECK_AUTH_RESULT_EVENT),
};
}
if (AppAuthMethod === AuthMethodEnum.BASIC) {
return {
type: AuthMethodEnum.BASIC,
isAuthenticated$: BASIC_AUTH_IS_AUTHENTICATED$,
userData$: BASIC_AUTH_USER_DATA$,
checkAuthResultEvent$: NEVER,
};
}
throw new UnreachableError('Invalid auth method');
}

View File

@ -1,12 +1,14 @@
import type { RouterContext } from '@/traits/router';
import { runInInjectionContext } from '@outposts/injection-js'; import { runInInjectionContext } from '@outposts/injection-js';
import { autoLoginPartialRoutesGuard } from 'oidc-client-rx'; import { autoLoginPartialRoutesGuard } from 'oidc-client-rx';
import { firstValueFrom } from 'rxjs'; import { firstValueFrom } from 'rxjs';
import type { RouterContext } from '~/traits/router'; import { authContextFromInjector } from './context';
export const beforeLoadGuard = async ({ export const beforeLoadGuard = async ({
context, context,
}: { context: RouterContext }) => { }: { context: RouterContext }) => {
if (!context.isAuthenticated()) { const { isAuthenticated$ } = authContextFromInjector(context.injector);
if (!(await firstValueFrom(isAuthenticated$))) {
const guard$ = runInInjectionContext(context.injector, () => const guard$ = runInInjectionContext(context.injector, () =>
autoLoginPartialRoutesGuard() autoLoginPartialRoutesGuard()
); );

View File

@ -1,55 +1,34 @@
import { CHECK_AUTH_RESULT_EVENT } from 'oidc-client-rx'; import { atomWithObservable } from 'jotai/utils';
import { import { useInjector } from 'oidc-client-rx/adapters/react';
InjectorContextVoidInjector, import { useMemo } from 'react';
useOidcClient, import type { Observable } from 'rxjs';
} from 'oidc-client-rx/adapters/solid-js'; import { authContextFromInjector } from './context';
import { NEVER, map, of } from 'rxjs';
import { from } from 'solid-js';
import { isBasicAuth, isOidcAuth } from './config';
const BASIC_AUTH_IS_AUTHENTICATED$ = of({
isAuthenticated: true,
allConfigsAuthenticated: [],
});
const BASIC_AUTH_USER_DATA$ = of({
userData: {},
allUserData: [],
});
const useOidcClientExt = isOidcAuth
? useOidcClient
: () => ({
oidcSecurityService: undefined,
injector: InjectorContextVoidInjector,
});
export function useAuth() { export function useAuth() {
const { oidcSecurityService, injector } = useOidcClientExt(); const injector = useInjector();
const isAuthenticated$ = ( const authContext = useMemo(
oidcSecurityService?.isAuthenticated$ ?? BASIC_AUTH_IS_AUTHENTICATED$ () => authContextFromInjector(injector),
).pipe(map((s) => s.isAuthenticated)); [injector]
);
const userData$ = ( const isAuthenticated = useMemo(
oidcSecurityService?.userData$ ?? BASIC_AUTH_USER_DATA$ () =>
).pipe(map((s) => s.userData)); atomWithObservable(
() => authContext.isAuthenticated$ as Observable<boolean>
),
[authContext.isAuthenticated$]
);
const isAuthenticated = from(isAuthenticated$); const userData = useMemo(
() => atomWithObservable(() => authContext.userData$ as Observable<any>),
const userData = from(userData$); [authContext]
);
const checkAuthResultEvent$ = isBasicAuth
? NEVER
: injector.get(CHECK_AUTH_RESULT_EVENT);
return { return {
oidcSecurityService,
isAuthenticated$,
isAuthenticated,
userData$,
userData, userData,
injector, injector,
checkAuthResultEvent$, isAuthenticated,
authContext,
}; };
} }

View File

@ -1,9 +1,10 @@
import {Image} from '@kobalte/core/image';
import { import {
SidebarMenu, SidebarMenu,
SidebarMenuButton, SidebarMenuButton,
SidebarMenuItem, SidebarMenuItem,
} from '~/components/ui/sidebar'; } from '@/components/ui/sidebar';
import { Image } from '@/components/ui/image';
export function AppIcon() { export function AppIcon() {
return ( return (
@ -11,21 +12,20 @@ export function AppIcon() {
<SidebarMenuItem> <SidebarMenuItem>
<SidebarMenuButton <SidebarMenuButton
size="lg" size="lg"
class="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground" className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
> >
<div <div className="flex size-8 items-center justify-center rounded-lg bg-sidebar-primary text-sidebar-primary-foreground">
class="flex aspect-square size-8 items-center justify-center rounded-lg bg-sidebar-primary text-sidebar-primary-foreground"> <div className="relative size-8">
<Image fallbackDelay={1000}> <Image
<Image.Img
src="/assets/favicon.png" src="/assets/favicon.png"
class="size-8 object-cover" alt="App Logo"
className="object-cover"
/> />
<Image.Fallback>KO</Image.Fallback> </div>
</Image>
</div> </div>
<div class="grid flex-1 gap-1 py-1 text-left text-sm leading-tight"> <div className="grid flex-1 gap-1 py-1 text-left text-xs leading-tight">
<span class="truncate font-semibold">Konobangu</span> <span className="truncate font-semibold">Konobangu</span>
<span class="mt-1 truncate">@dumtruck</span> <span className="mt-1 truncate">@dumtruck</span>
</div> </div>
</SidebarMenuButton> </SidebarMenuButton>
</SidebarMenuItem> </SidebarMenuItem>

View File

@ -1,54 +1,53 @@
import { useMatches } from '@tanstack/solid-router'; import { AppSidebar } from '@/components/layout/app-sidebar';
import {
type ComponentProps,
type FlowProps,
For,
Show,
createMemo,
splitProps,
} from 'solid-js';
import { Dynamic } from 'solid-js/web';
import { AppSidebar } from '~/components/layout/app-sidebar';
import { import {
Breadcrumb, Breadcrumb,
BreadcrumbItem, BreadcrumbItem,
BreadcrumbLink, BreadcrumbLink,
BreadcrumbList, BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator, BreadcrumbSeparator,
} from '~/components/ui/breadcrumb'; } from '@/components/ui/breadcrumb';
import { Separator } from '~/components/ui/separator'; import { Separator } from '@/components/ui/separator';
import { import {
SidebarInset, SidebarInset,
SidebarProvider, SidebarProvider,
SidebarTrigger, SidebarTrigger,
} from '~/components/ui/sidebar'; } from '@/components/ui/sidebar';
import type { RouteStateDataOption } from '~/traits/router'; import { cn } from '@/styles/utils';
import type { RouteBreadcrumbItem } from '~/traits/router'; import type { RouteStateDataOption } from '@/traits/router';
import { cn } from '~/utils/styles'; import type { RouteBreadcrumbItem } from '@/traits/router';
import { useMatches } from '@tanstack/react-router';
import {
type DetailedHTMLProps,
Fragment,
type HTMLAttributes,
useMemo,
} from 'react';
import { ProLink } from '../ui/pro-link'; import { ProLink } from '../ui/pro-link';
export type AppAsideBreadcrumbItem = RouteBreadcrumbItem; export type AppAsideBreadcrumbItem = RouteBreadcrumbItem;
export interface AppAsideProps extends FlowProps<ComponentProps<'div'>> {
export interface AppAsideProps
extends DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
breadcrumb?: AppAsideBreadcrumbItem[]; breadcrumb?: AppAsideBreadcrumbItem[];
extractBreadcrumbFromRoutes?: boolean; extractBreadcrumbFromRoutes?: boolean;
} }
export function AppAside(props: AppAsideProps) { export function AppAside({
const [local, other] = splitProps(props, [ children,
'children', className,
'class', breadcrumb: propBreadcrumb,
'breadcrumb', extractBreadcrumbFromRoutes,
'extractBreadcrumbFromRoutes', ...other
]); }: AppAsideProps) {
const matches = useMatches(); const matches = useMatches();
const breadcrumb = createMemo(() => { const breadcrumb = useMemo(() => {
if (local.breadcrumb) { if (propBreadcrumb) {
return local.breadcrumb; return propBreadcrumb;
} }
if (local.extractBreadcrumbFromRoutes) { if (extractBreadcrumbFromRoutes) {
return matches() return matches
.map((m, i, arr) => { .map((m, i, arr) => {
const staticData = m.staticData as RouteStateDataOption; const staticData = m.staticData as RouteStateDataOption;
if (staticData.breadcrumb) { if (staticData.breadcrumb) {
@ -67,61 +66,69 @@ export function AppAside(props: AppAsideProps) {
.filter((b): b is AppAsideBreadcrumbItem => !!b); .filter((b): b is AppAsideBreadcrumbItem => !!b);
} }
return []; return [];
}); }, [matches, propBreadcrumb, extractBreadcrumbFromRoutes]);
const breadcrumbLength = breadcrumb().length; const breadcrumbLength = breadcrumb.length;
return ( return (
<SidebarProvider> <SidebarProvider>
<AppSidebar /> <AppSidebar />
<SidebarInset> <SidebarInset>
<header class="flex h-16 shrink-0 items-center gap-2 transition-[width,height] ease-linear group-has-[[data-collapsible=icon]]/sidebar-wrapper:h-12"> <header className="flex h-16 shrink-0 items-center gap-2 transition-[width,height] ease-linear group-has-[[data-collapsible=icon]]/sidebar-wrapper:h-12">
<div class="flex items-center gap-2 px-4"> <div className="flex items-center gap-2 px-4">
<SidebarTrigger class="-ml-1" /> <SidebarTrigger className="-ml-1" />
<Show when={breadcrumbLength}> {breadcrumbLength > 0 && (
<Separator orientation="vertical" class="mr-2 h-4" /> <>
<Breadcrumb> <Separator orientation="vertical" className="mr-2 h-4" />
<BreadcrumbList> <Breadcrumb>
<For each={breadcrumb()}> <BreadcrumbList>
{(item, index) => { {breadcrumb.map((item, index) => {
const iconEl = ( const iconEl = item.icon ? (
<Show when={!!item.icon}> <item.icon className="size-4" />
<Dynamic component={item.icon} class=" size-4" /> ) : null;
</Show>
);
const isCurrent = index() + 1 === breadcrumbLength; const isCurrent = index + 1 === breadcrumbLength;
const LinkChild = (
item.link ? ProLink : Fragment
) as typeof ProLink;
return ( return (
<> <Fragment key={index}>
<Show when={index() > 0}> {index > 0 && (
<BreadcrumbSeparator class="hidden md:block" /> <BreadcrumbSeparator className="hidden md:block" />
</Show> )}
<BreadcrumbItem class="hidden md:block"> <BreadcrumbItem className="hidden md:block">
<BreadcrumbLink {isCurrent ? (
class="text-[var(--foreground)] hover:text-inherit" <BreadcrumbPage>
as={item.link ? ProLink : undefined} {iconEl}
current={isCurrent} {item.label}
{...item?.link} </BreadcrumbPage>
> ) : (
{iconEl} <BreadcrumbLink
{item.label} className="text-[var(--foreground)] hover:text-inherit"
</BreadcrumbLink> asChild={!!item.link}
>
<LinkChild {...item?.link}>
{iconEl}
{item.label}
</LinkChild>
</BreadcrumbLink>
)}
</BreadcrumbItem> </BreadcrumbItem>
</> </Fragment>
); );
}} })}
</For> </BreadcrumbList>
</BreadcrumbList> </Breadcrumb>
</Breadcrumb> </>
</Show> )}
</div> </div>
</header> </header>
<div <div
{...other} {...other}
class={cn('flex min-h-0 flex-1 flex-col p-4 pt-0', local.class)} className={cn('flex min-h-0 flex-1 flex-col p-4 pt-0', className)}
> >
{local.children} {children}
</div> </div>
</SidebarInset> </SidebarInset>
</SidebarProvider> </SidebarProvider>

View File

@ -2,7 +2,7 @@ import {
type AnyRoute, type AnyRoute,
type ParsedLocation, type ParsedLocation,
redirect, redirect,
} from '@tanstack/solid-router'; } from '@tanstack/react-router';
import { ProLink } from '../ui/pro-link'; import { ProLink } from '../ui/pro-link';
export function guardRouteIndexAsNotFound( export function guardRouteIndexAsNotFound(
@ -21,19 +21,19 @@ export function guardRouteIndexAsNotFound(
export function AppNotFoundComponent() { export function AppNotFoundComponent() {
return ( return (
<div class="flex h-svh items-center px-4 py-12 sm:px-6 md:px-8 lg:px-12 xl:px-16"> <div className="flex h-svh items-center px-4 py-12 sm:px-6 md:px-8 lg:px-12 xl:px-16">
<div class="w-full space-y-6 text-center"> <div className="w-full space-y-6 text-center">
<div class="space-y-3"> <div className="space-y-3">
<h1 class="font-bold text-4xl tracking-tighter sm:text-5xl"> <h1 className="font-bold text-4xl tracking-tighter sm:text-5xl">
404 Page Not Found 404 Page Not Found
</h1> </h1>
<p class="text-gray-500"> <p className="text-gray-500">
Sorry, we couldn&#x27;t find the page you&#x27;re looking for. Sorry, we couldn&#x27;t find the page you&#x27;re looking for.
</p> </p>
</div> </div>
<ProLink <ProLink
to="/" to="/"
class="inline-flex h-10 items-center rounded-md border border-gray-200 border-gray-200 bg-white px-8 font-medium text-sm shadow-sm transition-colors hover:bg-gray-100 hover:text-gray-900 dark:border-gray-800 dark:border-gray-800 dark:bg-gray-950 dark:focus-visible:ring-gray-300 dark:hover:bg-gray-800 dark:hover:text-gray-50" className="inline-flex h-10 items-center rounded-md border border-gray-20 bg-white px-8 font-medium text-xs shadow-xs transition-colors hover:bg-gray-100 hover:text-gray-900 dark:border-gray-800 dark:bg-gray-950 dark:focus-visible:ring-gray-300 dark:hover:bg-gray-800 dark:hover:text-gray-50"
> >
Return to website Return to website
</ProLink> </ProLink>

View File

@ -1,12 +1,12 @@
import type { ComponentProps } from 'solid-js';
import { import {
Sidebar, Sidebar,
SidebarContent, SidebarContent,
SidebarFooter, SidebarFooter,
SidebarHeader, SidebarHeader,
SidebarRail, SidebarRail,
} from '~/components/ui/sidebar'; } from '@/components/ui/sidebar';
import { AppNavMainData } from '~/config/app-layout'; import { AppNavMainData } from '@/config/app-layout';
import type { ComponentPropsWithoutRef } from 'react';
import { AppIcon } from './app-icon'; import { AppIcon } from './app-icon';
import { NavMain } from './nav-main'; import { NavMain } from './nav-main';
import { NavUser } from './nav-user'; import { NavUser } from './nav-user';
@ -19,7 +19,10 @@ const data = {
}, },
}; };
type AppSidebarRootProps = Omit<ComponentProps<typeof Sidebar>, 'collapsible'>; type AppSidebarRootProps = Omit<
ComponentPropsWithoutRef<typeof Sidebar>,
'collapsible'
>;
export const AppSidebar = (props: AppSidebarRootProps) => { export const AppSidebar = (props: AppSidebarRootProps) => {
return ( return (

View File

@ -1,12 +1,12 @@
export function AppSkeleton() { export function AppSkeleton() {
return ( return (
<div class="flex min-h-svh flex-1 flex-col gap-4 md:min-h-0"> <div className="flex min-h-svh flex-1 flex-col gap-4 md:min-h-0">
<div class="grid auto-rows-min gap-4 md:grid-cols-3"> <div className="grid auto-rows-min gap-4 md:grid-cols-3">
<div class="aspect-video rounded-xl bg-muted/50" /> <div className="aspect-video rounded-xl bg-muted/50" />
<div class="aspect-video rounded-xl bg-muted/50" /> <div className="aspect-video rounded-xl bg-muted/50" />
<div class="aspect-video rounded-xl bg-muted/50" /> <div className="aspect-video rounded-xl bg-muted/50" />
</div> </div>
<div class="min-h-svh flex-1 rounded-xl bg-muted/50 md:min-h-0" /> <div className="min-h-svh flex-1 rounded-xl bg-muted/50 md:min-h-0" />
</div> </div>
); );
} }

View File

@ -1,12 +1,12 @@
import { ChevronRight, type LucideIcon } from 'lucide-solid'; 'use client';
import { For, Show, createSignal } from 'solid-js';
import { ChevronRight, type LucideIcon } from 'lucide-react';
import { useMatch, useMatches } from '@tanstack/solid-router';
import { import {
Collapsible, Collapsible,
CollapsibleContent, CollapsibleContent,
CollapsibleTrigger, CollapsibleTrigger,
} from '~/components/ui/collapsible'; } from '@/components/ui/collapsible';
import { import {
SidebarGroup, SidebarGroup,
SidebarGroupLabel, SidebarGroupLabel,
@ -16,7 +16,8 @@ import {
SidebarMenuSub, SidebarMenuSub,
SidebarMenuSubButton, SidebarMenuSubButton,
SidebarMenuSubItem, SidebarMenuSubItem,
} from '~/components/ui/sidebar'; } from '@/components/ui/sidebar';
import { useMatches } from '@tanstack/react-router';
import { ProLink, type ProLinkProps } from '../ui/pro-link'; import { ProLink, type ProLinkProps } from '../ui/pro-link';
export interface NavMainItem { export interface NavMainItem {
@ -43,7 +44,7 @@ export function NavMain({
if (!linkTo) { if (!linkTo) {
return false; return false;
} }
return matches().some((match) => match.pathname.startsWith(linkTo)); return matches.some((match) => match.pathname.startsWith(linkTo));
}; };
const renderSidebarMenuItemButton = (item: NavMainItem) => { const renderSidebarMenuItemButton = (item: NavMainItem) => {
@ -51,71 +52,68 @@ export function NavMain({
<> <>
{item.icon && <item.icon />} {item.icon && <item.icon />}
<span>{item.title}</span> <span>{item.title}</span>
<ChevronRight class="ml-auto transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90" /> <ChevronRight className="ml-auto transition-transform duration-200 group-data-[state=open]:rotate-90" />
</> </>
); );
}; };
return ( return groups.map((group, groupIndex) => {
<For each={groups}> return (
{(group) => ( <SidebarGroup key={groupIndex}>
<SidebarGroup> <SidebarGroupLabel>{group.group}</SidebarGroupLabel>
<SidebarGroupLabel>{group.group}</SidebarGroupLabel> <SidebarMenu>
<SidebarMenu> {group.items.map((item, itemIndex) => {
<For each={group.items}> if (!item.children?.length) {
{(item) => { return (
return ( <SidebarMenuItem key={itemIndex}>
<Show <SidebarMenuButton asChild tooltip={item.title}>
when={!!item.children?.length} <ProLink {...item.link}>
fallback={ {renderSidebarMenuItemButton(item)}
<SidebarMenuItem> </ProLink>
<SidebarMenuButton </SidebarMenuButton>
as={ProLink} </SidebarMenuItem>
{...item.link} );
tooltip={item.title} }
> return (
{renderSidebarMenuItemButton(item)} <Collapsible
</SidebarMenuButton> key={itemIndex}
</SidebarMenuItem> asChild
} className="group/collapsible"
> defaultOpen={isMenuMatch(item.link)}
<Collapsible >
as={SidebarMenuItem} <SidebarMenuItem>
class="group/collapsible" <CollapsibleTrigger asChild>
defaultOpen={isMenuMatch(item.link)} <SidebarMenuButton tooltip={item.title}>
> {renderSidebarMenuItemButton(item)}
<CollapsibleTrigger </SidebarMenuButton>
as={SidebarMenuButton} </CollapsibleTrigger>
tooltip={item.title} <CollapsibleContent>
> <SidebarMenuSub>
{renderSidebarMenuItemButton(item)} {(item.children || []).map((subItem, subItemIndex) => {
</CollapsibleTrigger> return (
<CollapsibleContent> <SidebarMenuSubItem key={subItemIndex}>
<SidebarMenuSub> <SidebarMenuSubButton
<For each={item.children || []}> asChild
{(subItem) => ( isActive={isMenuMatch(subItem.link)}
<SidebarMenuSubItem> >
<SidebarMenuSubButton <ProLink
as={ProLink} {...subItem.link}
{...subItem.link} activeProps={{ className: '' }}
isActive={isMenuMatch(subItem.link)} >
activeProps={{ class: '' }} <span>{subItem.title}</span>
> </ProLink>
<span>{subItem.title}</span> </SidebarMenuSubButton>
</SidebarMenuSubButton> </SidebarMenuSubItem>
</SidebarMenuSubItem> );
)} })}
</For> </SidebarMenuSub>
</SidebarMenuSub> </CollapsibleContent>
</CollapsibleContent> </SidebarMenuItem>
</Collapsible> </Collapsible>
</Show> );
); })}
}} </SidebarMenu>
</For> </SidebarGroup>
</SidebarMenu> );
</SidebarGroup> });
)}
</For>
);
} }

View File

@ -1,12 +1,14 @@
import { Link } from '@tanstack/solid-router'; 'use client';
import { Link } from '@tanstack/react-router';
import { import {
Folder, Folder,
Forward, Forward,
type LucideIcon, type LucideIcon,
MoreHorizontal, MoreHorizontal,
Trash2, Trash2,
} from 'lucide-solid'; } from 'lucide-react';
import { type ComponentProps, For } from 'solid-js';
import { import {
DropdownMenu, DropdownMenu,
@ -14,7 +16,7 @@ import {
DropdownMenuItem, DropdownMenuItem,
DropdownMenuSeparator, DropdownMenuSeparator,
DropdownMenuTrigger, DropdownMenuTrigger,
} from '~/components/ui/dropdown-menu'; } from '@/components/ui/dropdown-menu';
import { import {
SidebarGroup, SidebarGroup,
SidebarGroupLabel, SidebarGroupLabel,
@ -22,7 +24,9 @@ import {
SidebarMenuAction, SidebarMenuAction,
SidebarMenuButton, SidebarMenuButton,
SidebarMenuItem, SidebarMenuItem,
} from '~/components/ui/sidebar'; useSidebar,
} from '@/components/ui/sidebar';
import type { ComponentProps } from 'react';
export function NavProjects({ export function NavProjects({
projects, projects,
@ -33,44 +37,52 @@ export function NavProjects({
link: ComponentProps<typeof Link>; link: ComponentProps<typeof Link>;
}[]; }[];
}) { }) {
const { isMobile } = useSidebar();
return ( return (
<SidebarGroup class="group-data-[collapsible=icon]:hidden"> <SidebarGroup className="group-data-[collapsible=icon]:hidden">
<SidebarGroupLabel>Projects</SidebarGroupLabel> <SidebarGroupLabel>Projects</SidebarGroupLabel>
<SidebarMenu> <SidebarMenu>
<For each={projects}> {projects.map((item) => (
{(item) => ( <SidebarMenuItem key={item.name}>
<SidebarMenuItem> <SidebarMenuButton asChild>
<SidebarMenuButton as={Link} {...item?.link}> <Link {...item.link}>
<item.icon /> <item.icon />
<span>{item.name}</span> <span>{item.name}</span>
</SidebarMenuButton> </Link>
<DropdownMenu> </SidebarMenuButton>
<DropdownMenuTrigger as={SidebarMenuAction} showOnHover> <DropdownMenu>
<DropdownMenuTrigger asChild>
<SidebarMenuAction showOnHover>
<MoreHorizontal /> <MoreHorizontal />
<span class="sr-only">More</span> <span className="sr-only">More</span>
</DropdownMenuTrigger> </SidebarMenuAction>
<DropdownMenuContent class="w-48 rounded-lg"> </DropdownMenuTrigger>
<DropdownMenuItem> <DropdownMenuContent
<Folder class="text-muted-foreground" /> className="w-48 rounded-lg"
<span>View Project</span> side={isMobile ? 'bottom' : 'right'}
</DropdownMenuItem> align={isMobile ? 'end' : 'start'}
<DropdownMenuItem> >
<Forward class="text-muted-foreground" /> <DropdownMenuItem>
<span>Share Project</span> <Folder className="text-muted-foreground" />
</DropdownMenuItem> <span>View Project</span>
<DropdownMenuSeparator /> </DropdownMenuItem>
<DropdownMenuItem> <DropdownMenuItem>
<Trash2 class="text-muted-foreground" /> <Forward className="text-muted-foreground" />
<span>Delete Project</span> <span>Share Project</span>
</DropdownMenuItem> </DropdownMenuItem>
</DropdownMenuContent> <DropdownMenuSeparator />
</DropdownMenu> <DropdownMenuItem>
</SidebarMenuItem> <Trash2 className="text-muted-foreground" />
)} <span>Delete Project</span>
</For> </DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</SidebarMenuItem>
))}
<SidebarMenuItem> <SidebarMenuItem>
<SidebarMenuButton class="text-sidebar-foreground/70"> <SidebarMenuButton className="text-sidebar-foreground/70">
<MoreHorizontal class="text-sidebar-foreground/70" /> <MoreHorizontal className="text-sidebar-foreground/70" />
<span>More</span> <span>More</span>
</SidebarMenuButton> </SidebarMenuButton>
</SidebarMenuItem> </SidebarMenuItem>

View File

@ -1,3 +1,5 @@
'use client';
import { import {
BadgeCheck, BadgeCheck,
Bell, Bell,
@ -5,9 +7,9 @@ import {
CreditCard, CreditCard,
LogOut, LogOut,
Sparkles, Sparkles,
} from 'lucide-solid'; } from 'lucide-react';
import { Avatar, AvatarFallback, AvatarImage } from '~/components/ui/avatar'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { import {
DropdownMenu, DropdownMenu,
DropdownMenuContent, DropdownMenuContent,
@ -16,12 +18,13 @@ import {
DropdownMenuLabel, DropdownMenuLabel,
DropdownMenuSeparator, DropdownMenuSeparator,
DropdownMenuTrigger, DropdownMenuTrigger,
} from '~/components/ui/dropdown-menu'; } from '@/components/ui/dropdown-menu';
import { import {
SidebarMenu, SidebarMenu,
SidebarMenuButton, SidebarMenuButton,
SidebarMenuItem, SidebarMenuItem,
} from '~/components/ui/sidebar'; useSidebar,
} from '@/components/ui/sidebar';
export function NavUser({ export function NavUser({
user, user,
@ -32,35 +35,43 @@ export function NavUser({
avatar: string; avatar: string;
}; };
}) { }) {
const { isMobile } = useSidebar();
return ( return (
<SidebarMenu> <SidebarMenu>
<SidebarMenuItem> <SidebarMenuItem>
<DropdownMenu> <DropdownMenu>
<DropdownMenuTrigger <DropdownMenuTrigger asChild>
as={SidebarMenuButton} <SidebarMenuButton
size="lg" size="lg"
class="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground" className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
> >
<Avatar class="h-8 w-8 rounded-lg"> <Avatar className="h-8 w-8 rounded-lg">
<AvatarImage src={user.avatar} alt={user.name} /> <AvatarImage src={user.avatar} alt={user.name} />
<AvatarFallback class="rounded-lg">CN</AvatarFallback> <AvatarFallback className="rounded-lg">CN</AvatarFallback>
</Avatar> </Avatar>
<div class="grid flex-1 text-left text-sm leading-tight"> <div className="grid flex-1 text-left text-xs leading-tight">
<span class="truncate font-semibold">{user.name}</span> <span className="truncate font-semibold">{user.name}</span>
<span class="truncate text-xs">{user.email}</span> <span className="truncate text-xs">{user.email}</span>
</div> </div>
<ChevronsUpDown class="ml-auto size-4" /> <ChevronsUpDown className="ml-auto size-4" />
</SidebarMenuButton>
</DropdownMenuTrigger> </DropdownMenuTrigger>
<DropdownMenuContent class="w-[--radix-dropdown-menu-trigger-width] min-w-56 rounded-lg"> <DropdownMenuContent
<DropdownMenuLabel class="p-0 font-normal"> className="w-[--radix-dropdown-menu-trigger-width] min-w-56 rounded-lg"
<div class="flex items-center gap-2 px-1 py-1.5 text-left text-sm"> side={isMobile ? 'bottom' : 'right'}
<Avatar class="h-8 w-8 rounded-lg"> align="end"
sideOffset={4}
>
<DropdownMenuLabel className="p-0 font-normal">
<div className="flex items-center gap-2 px-1 py-1.5 text-left text-xs">
<Avatar className="h-8 w-8 rounded-lg">
<AvatarImage src={user.avatar} alt={user.name} /> <AvatarImage src={user.avatar} alt={user.name} />
<AvatarFallback class="rounded-lg">CN</AvatarFallback> <AvatarFallback className="rounded-lg">CN</AvatarFallback>
</Avatar> </Avatar>
<div class="grid flex-1 text-left text-sm leading-tight"> <div className="grid flex-1 text-left text-xs leading-tight">
<span class="truncate font-semibold">{user.name}</span> <span className="truncate font-semibold">{user.name}</span>
<span class="truncate text-xs">{user.email}</span> <span className="truncate text-xs">{user.email}</span>
</div> </div>
</div> </div>
</DropdownMenuLabel> </DropdownMenuLabel>

View File

@ -1,91 +1,64 @@
import type { JSX, ValidComponent } from 'solid-js'; import * as React from "react"
import { splitProps } from 'solid-js'; import * as AccordionPrimitive from "@radix-ui/react-accordion"
import { ChevronDownIcon } from "lucide-react"
import * as AccordionPrimitive from '@kobalte/core/accordion'; import { cn } from "@/styles/utils"
import type { PolymorphicProps } from '@kobalte/core/polymorphic';
import { cn } from '~/utils/styles'; function Accordion({
...props
}: React.ComponentProps<typeof AccordionPrimitive.Root>) {
return <AccordionPrimitive.Root data-slot="accordion" {...props} />
}
const Accordion = AccordionPrimitive.Root; function AccordionItem({
className,
type AccordionItemProps<T extends ValidComponent = 'div'> = ...props
AccordionPrimitive.AccordionItemProps<T> & { }: React.ComponentProps<typeof AccordionPrimitive.Item>) {
class?: string | undefined;
};
const AccordionItem = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, AccordionItemProps<T>>
) => {
const [local, others] = splitProps(props as AccordionItemProps, ['class']);
return ( return (
<AccordionPrimitive.Item class={cn('border-b', local.class)} {...others} /> <AccordionPrimitive.Item
); data-slot="accordion-item"
}; className={cn("border-b last:border-b-0", className)}
{...props}
/>
)
}
type AccordionTriggerProps<T extends ValidComponent = 'button'> = function AccordionTrigger({
AccordionPrimitive.AccordionTriggerProps<T> & { className,
class?: string | undefined; children,
children?: JSX.Element; ...props
}; }: React.ComponentProps<typeof AccordionPrimitive.Trigger>) {
const AccordionTrigger = <T extends ValidComponent = 'button'>(
props: PolymorphicProps<T, AccordionTriggerProps<T>>
) => {
const [local, others] = splitProps(props as AccordionTriggerProps, [
'class',
'children',
]);
return ( return (
<AccordionPrimitive.Header class="flex"> <AccordionPrimitive.Header className="flex">
<AccordionPrimitive.Trigger <AccordionPrimitive.Trigger
class={cn( data-slot="accordion-trigger"
'flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-expanded]>svg]:rotate-180', className={cn(
local.class "focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180",
className
)} )}
{...others} {...props}
> >
{local.children} {children}
<svg <ChevronDownIcon className="text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200" />
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4 shrink-0 transition-transform duration-200"
>
<path d="M6 9l6 6l6 -6" />
</svg>
</AccordionPrimitive.Trigger> </AccordionPrimitive.Trigger>
</AccordionPrimitive.Header> </AccordionPrimitive.Header>
); )
}; }
type AccordionContentProps<T extends ValidComponent = 'div'> = function AccordionContent({
AccordionPrimitive.AccordionContentProps<T> & { className,
class?: string | undefined; children,
children?: JSX.Element; ...props
}; }: React.ComponentProps<typeof AccordionPrimitive.Content>) {
const AccordionContent = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, AccordionContentProps<T>>
) => {
const [local, others] = splitProps(props as AccordionContentProps, [
'class',
'children',
]);
return ( return (
<AccordionPrimitive.Content <AccordionPrimitive.Content
class={cn( data-slot="accordion-content"
'animate-accordion-up overflow-hidden text-sm transition-all data-[expanded]:animate-accordion-down', className="data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm"
local.class {...props}
)}
{...others}
> >
<div class="pt-0 pb-4">{local.children}</div> <div className={cn("pt-0 pb-4", className)}>{children}</div>
</AccordionPrimitive.Content> </AccordionPrimitive.Content>
); )
}; }
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }; export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }

View File

@ -1,117 +1,146 @@
import type { JSX, ValidComponent } from 'solid-js'; "use client"
import { splitProps } from 'solid-js';
import * as AlertDialogPrimitive from '@kobalte/core/alert-dialog'; import * as React from "react"
import type { PolymorphicProps } from '@kobalte/core/polymorphic'; import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"
import { cn } from '~/utils/styles'; import { cn } from "@/styles/utils"
import { buttonVariants } from "@/components/ui/button"
const AlertDialog = AlertDialogPrimitive.Root; function AlertDialog({
const AlertDialogTrigger = AlertDialogPrimitive.Trigger; ...props
const AlertDialogPortal = AlertDialogPrimitive.Portal; }: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {
return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />
}
type AlertDialogOverlayProps<T extends ValidComponent = 'div'> = function AlertDialogTrigger({
AlertDialogPrimitive.AlertDialogOverlayProps<T> & { ...props
class?: string | undefined; }: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) {
}; return (
<AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />
)
}
const AlertDialogOverlay = <T extends ValidComponent = 'div'>( function AlertDialogPortal({
props: PolymorphicProps<T, AlertDialogOverlayProps<T>> ...props
) => { }: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {
const [local, others] = splitProps(props as AlertDialogOverlayProps, [ return (
'class', <AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />
]); )
}
function AlertDialogOverlay({
className,
...props
}: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) {
return ( return (
<AlertDialogPrimitive.Overlay <AlertDialogPrimitive.Overlay
class={cn( data-slot="alert-dialog-overlay"
'data-[closed]:fade-out-0 data-[expanded]:fade-in-0 fixed inset-0 z-50 bg-background/80 backdrop-blur-sm data-[closed]:animate-out data-[expanded]:animate-in', className={cn(
local.class "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
className
)} )}
{...others} {...props}
/> />
); )
}; }
type AlertDialogContentProps<T extends ValidComponent = 'div'> = function AlertDialogContent({
AlertDialogPrimitive.AlertDialogContentProps<T> & { className,
class?: string | undefined; ...props
children?: JSX.Element; }: React.ComponentProps<typeof AlertDialogPrimitive.Content>) {
};
const AlertDialogContent = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, AlertDialogContentProps<T>>
) => {
const [local, others] = splitProps(props as AlertDialogContentProps, [
'class',
'children',
]);
return ( return (
<AlertDialogPortal> <AlertDialogPortal>
<AlertDialogOverlay /> <AlertDialogOverlay />
<AlertDialogPrimitive.Content <AlertDialogPrimitive.Content
class={cn( data-slot="alert-dialog-content"
'-translate-x-1/2 -translate-y-1/2 data-[closed]:fade-out-0 data-[expanded]:fade-in-0 data-[closed]:zoom-out-95 data-[expanded]:zoom-in-95 data-[closed]:slide-out-to-left-1/2 data-[closed]:slide-out-to-top-[48%] data-[expanded]:slide-in-from-left-1/2 data-[expanded]:slide-in-from-top-[48%] fixed top-1/2 left-1/2 z-50 grid w-full max-w-lg gap-4 border bg-background p-6 shadow-lg duration-200 data-[closed]:animate-out data-[expanded]:animate-in sm:rounded-lg md:w-full', className={cn(
local.class "bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",
className
)} )}
{...others} {...props}
> />
{local.children}
<AlertDialogPrimitive.CloseButton class="absolute top-4 right-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[expanded]:bg-accent data-[expanded]:text-muted-foreground">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M18 6l-12 12" />
<path d="M6 6l12 12" />
</svg>
<span class="sr-only">Close</span>
</AlertDialogPrimitive.CloseButton>
</AlertDialogPrimitive.Content>
</AlertDialogPortal> </AlertDialogPortal>
); )
}; }
type AlertDialogTitleProps<T extends ValidComponent = 'h2'> = function AlertDialogHeader({
AlertDialogPrimitive.AlertDialogTitleProps<T> & { className,
class?: string | undefined; ...props
}; }: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-dialog-header"
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
{...props}
/>
)
}
const AlertDialogTitle = <T extends ValidComponent = 'h2'>( function AlertDialogFooter({
props: PolymorphicProps<T, AlertDialogTitleProps<T>> className,
) => { ...props
const [local, others] = splitProps(props as AlertDialogTitleProps, ['class']); }: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-dialog-footer"
className={cn(
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
className
)}
{...props}
/>
)
}
function AlertDialogTitle({
className,
...props
}: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {
return ( return (
<AlertDialogPrimitive.Title <AlertDialogPrimitive.Title
class={cn('font-semibold text-lg', local.class)} data-slot="alert-dialog-title"
{...others} className={cn("text-lg font-semibold", className)}
{...props}
/> />
); )
}; }
type AlertDialogDescriptionProps<T extends ValidComponent = 'p'> = function AlertDialogDescription({
AlertDialogPrimitive.AlertDialogDescriptionProps<T> & { className,
class?: string | undefined; ...props
}; }: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {
const AlertDialogDescription = <T extends ValidComponent = 'p'>(
props: PolymorphicProps<T, AlertDialogDescriptionProps<T>>
) => {
const [local, others] = splitProps(props as AlertDialogDescriptionProps, [
'class',
]);
return ( return (
<AlertDialogPrimitive.Description <AlertDialogPrimitive.Description
class={cn('text-muted-foreground text-sm', local.class)} data-slot="alert-dialog-description"
{...others} className={cn("text-muted-foreground text-sm", className)}
{...props}
/> />
); )
}; }
function AlertDialogAction({
className,
...props
}: React.ComponentProps<typeof AlertDialogPrimitive.Action>) {
return (
<AlertDialogPrimitive.Action
className={cn(buttonVariants(), className)}
{...props}
/>
)
}
function AlertDialogCancel({
className,
...props
}: React.ComponentProps<typeof AlertDialogPrimitive.Cancel>) {
return (
<AlertDialogPrimitive.Cancel
className={cn(buttonVariants({ variant: "outline" }), className)}
{...props}
/>
)
}
export { export {
AlertDialog, AlertDialog,
@ -119,6 +148,10 @@ export {
AlertDialogOverlay, AlertDialogOverlay,
AlertDialogTrigger, AlertDialogTrigger,
AlertDialogContent, AlertDialogContent,
AlertDialogHeader,
AlertDialogFooter,
AlertDialogTitle, AlertDialogTitle,
AlertDialogDescription, AlertDialogDescription,
}; AlertDialogAction,
AlertDialogCancel,
}

View File

@ -1,63 +1,66 @@
import type { Component, ComponentProps, ValidComponent } from 'solid-js'; import * as React from "react"
import { splitProps } from 'solid-js'; import { cva, type VariantProps } from "class-variance-authority"
import * as AlertPrimitive from '@kobalte/core/alert'; import { cn } from "@/styles/utils"
import type { PolymorphicProps } from '@kobalte/core/polymorphic';
import type { VariantProps } from 'class-variance-authority';
import { cva } from 'class-variance-authority';
import { cn } from '~/utils/styles';
const alertVariants = cva( const alertVariants = cva(
'relative w-full rounded-lg border p-4 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:top-4 [&>svg]:left-4 [&>svg]:text-foreground [&>svg~*]:pl-7', "relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
{ {
variants: { variants: {
variant: { variant: {
default: 'bg-background text-foreground', default: "bg-card text-card-foreground",
destructive: destructive:
'border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive', "text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90",
}, },
}, },
defaultVariants: { defaultVariants: {
variant: 'default', variant: "default",
}, },
} }
); )
type AlertRootProps<T extends ValidComponent = 'div'> = function Alert({
AlertPrimitive.AlertRootProps<T> & className,
VariantProps<typeof alertVariants> & { class?: string | undefined }; variant,
...props
const Alert = <T extends ValidComponent = 'div'>( }: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
props: PolymorphicProps<T, AlertRootProps<T>>
) => {
const [local, others] = splitProps(props as AlertRootProps, [
'class',
'variant',
]);
return ( return (
<AlertPrimitive.Root <div
class={cn(alertVariants({ variant: props.variant }), local.class)} data-slot="alert"
{...others} role="alert"
className={cn(alertVariants({ variant }), className)}
{...props}
/> />
); )
}; }
const AlertTitle: Component<ComponentProps<'h5'>> = (props) => { function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
const [local, others] = splitProps(props, ['class']);
return ( return (
<h5 <div
class={cn('mb-1 font-medium leading-none tracking-tight', local.class)} data-slot="alert-title"
{...others} className={cn(
"col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",
className
)}
{...props}
/> />
); )
}; }
const AlertDescription: Component<ComponentProps<'div'>> = (props) => { function AlertDescription({
const [local, others] = splitProps(props, ['class']); className,
...props
}: React.ComponentProps<"div">) {
return ( return (
<div class={cn('text-sm [&_p]:leading-relaxed', local.class)} {...others} /> <div
); data-slot="alert-description"
}; className={cn(
"text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",
className
)}
{...props}
/>
)
}
export { Alert, AlertTitle, AlertDescription }; export { Alert, AlertTitle, AlertDescription }

View File

@ -1,31 +1,9 @@
import type { Component, ComponentProps } from "solid-js" import * as AspectRatioPrimitive from "@radix-ui/react-aspect-ratio"
import { mergeProps, splitProps } from "solid-js"
type AspectRatioProps = ComponentProps<"div"> & { ratio?: number } function AspectRatio({
...props
const AspectRatio: Component<AspectRatioProps> = (rawProps) => { }: React.ComponentProps<typeof AspectRatioPrimitive.Root>) {
const props = mergeProps({ ratio: 1 / 1 }, rawProps) return <AspectRatioPrimitive.Root data-slot="aspect-ratio" {...props} />
const [local, others] = splitProps(props, ["ratio"])
return (
<div
style={{
position: "relative",
width: "100%",
"padding-bottom": `${100 / local.ratio}%`
}}
>
<div
style={{
position: "absolute",
top: 0,
right: 0,
bottom: 0,
left: 0
}}
{...others}
/>
</div>
)
} }
export { AspectRatio } export { AspectRatio }

View File

@ -1,64 +1,53 @@
import type { ValidComponent } from 'solid-js'; "use client"
import { splitProps } from 'solid-js';
import * as ImagePrimitive from '@kobalte/core/image'; import * as React from "react"
import type { PolymorphicProps } from '@kobalte/core/polymorphic'; import * as AvatarPrimitive from "@radix-ui/react-avatar"
import { cn } from '~/utils/styles'; import { cn } from "@/styles/utils"
type AvatarRootProps<T extends ValidComponent = 'span'> = function Avatar({
ImagePrimitive.ImageRootProps<T> & { className,
class?: string | undefined; ...props
}; }: React.ComponentProps<typeof AvatarPrimitive.Root>) {
const Avatar = <T extends ValidComponent = 'span'>(
props: PolymorphicProps<T, AvatarRootProps<T>>
) => {
const [local, others] = splitProps(props as AvatarRootProps, ['class']);
return ( return (
<ImagePrimitive.Root <AvatarPrimitive.Root
class={cn( data-slot="avatar"
'relative flex size-10 shrink-0 overflow-hidden rounded-full', className={cn(
local.class "relative flex size-8 shrink-0 overflow-hidden rounded-full",
className
)} )}
{...others} {...props}
/> />
); )
}; }
type AvatarImageProps<T extends ValidComponent = 'img'> = function AvatarImage({
ImagePrimitive.ImageImgProps<T> & { className,
class?: string | undefined; ...props
}; }: React.ComponentProps<typeof AvatarPrimitive.Image>) {
const AvatarImage = <T extends ValidComponent = 'img'>(
props: PolymorphicProps<T, AvatarImageProps<T>>
) => {
const [local, others] = splitProps(props as AvatarImageProps, ['class']);
return ( return (
<ImagePrimitive.Img <AvatarPrimitive.Image
class={cn('aspect-square size-full', local.class)} data-slot="avatar-image"
{...others} className={cn("aspect-square size-full", className)}
{...props}
/> />
); )
}; }
type AvatarFallbackProps<T extends ValidComponent = 'span'> = function AvatarFallback({
ImagePrimitive.ImageFallbackProps<T> & { class?: string | undefined }; className,
...props
const AvatarFallback = <T extends ValidComponent = 'span'>( }: React.ComponentProps<typeof AvatarPrimitive.Fallback>) {
props: PolymorphicProps<T, AvatarFallbackProps<T>>
) => {
const [local, others] = splitProps(props as AvatarFallbackProps, ['class']);
return ( return (
<ImagePrimitive.Fallback <AvatarPrimitive.Fallback
class={cn( data-slot="avatar-fallback"
'flex size-full items-center justify-center bg-muted', className={cn(
local.class "bg-muted flex size-full items-center justify-center rounded-full",
className
)} )}
{...others} {...props}
/> />
); )
}; }
export { Avatar, AvatarImage, AvatarFallback }; export { Avatar, AvatarImage, AvatarFallback }

View File

@ -1,156 +0,0 @@
import type { Component, JSXElement } from 'solid-js';
import { createEffect, on, splitProps } from 'solid-js';
import type { VariantProps } from 'class-variance-authority';
import { cva } from 'class-variance-authority';
import type { BadgeProps } from '~/components/ui/badge';
import { Badge } from '~/components/ui/badge';
import { cn } from '~/utils/styles';
type DeltaType =
| 'increase'
| 'moderateIncrease'
| 'unchanged'
| 'moderateDecrease'
| 'decrease';
const badgeDeltaVariants = cva('', {
variants: {
variant: {
success: 'bg-success text-success-foreground hover:bg-success',
warning: 'bg-warning text-warning-foreground hover:bg-warning',
error: 'bg-error text-error-foreground hover:bg-error',
},
},
});
type DeltaVariant = NonNullable<
VariantProps<typeof badgeDeltaVariants>['variant']
>;
const iconMap: {
[key in DeltaType]: (props: { class?: string }) => JSXElement;
} = {
increase: (props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class={props.class}
>
<path d="M12 5l0 14" />
<path d="M18 11l-6 -6" />
<path d="M6 11l6 -6" />
</svg>
),
moderateIncrease: (props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class={props.class}
>
<path d="M17 7l-10 10" />
<path d="M8 7l9 0l0 9" />
</svg>
),
unchanged: (props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class={props.class}
>
<path d="M5 12l14 0" />
<path d="M13 18l6 -6" />
<path d="M13 6l6 6" />
</svg>
),
moderateDecrease: (props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class={props.class}
>
<path d="M7 7l10 10" />
<path d="M17 8l0 9l-9 0" />
</svg>
),
decrease: (props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class={props.class}
>
<path d="M12 5l0 14" />
<path d="M18 13l-6 6" />
<path d="M6 13l6 6" />
</svg>
),
};
const variantMap: { [key in DeltaType]: DeltaVariant } = {
increase: 'success',
moderateIncrease: 'success',
unchanged: 'warning',
moderateDecrease: 'error',
decrease: 'error',
};
type BadgeDeltaProps = Omit<BadgeProps, 'variant'> & {
deltaType: DeltaType;
};
const BadgeDelta: Component<BadgeDeltaProps> = (props) => {
const [local, others] = splitProps(props, ['class', 'children', 'deltaType']);
// eslint-disable-next-line solid/reactivity
let Icon = iconMap[local.deltaType];
createEffect(
on(
() => local.deltaType,
() => {
Icon = iconMap[local.deltaType];
}
)
);
return (
<Badge
class={cn(
badgeDeltaVariants({ variant: variantMap[local.deltaType] }),
local.class
)}
{...others}
>
<span class="flex gap-1">
<Icon class="size-4" />
{local.children}
</span>
</Badge>
);
};
export { BadgeDelta };

View File

@ -1,48 +1,46 @@
import type { Component, ComponentProps } from 'solid-js'; import * as React from "react"
import { splitProps } from 'solid-js'; import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"
import type { VariantProps } from 'class-variance-authority'; import { cn } from "@/styles/utils"
import { cva } from 'class-variance-authority';
import { cn } from '~/utils/styles';
const badgeVariants = cva( const badgeVariants = cva(
'inline-flex items-center rounded-md border px-2.5 py-0.5 font-semibold text-xs transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2', "inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
{ {
variants: { variants: {
variant: { variant: {
default: 'border-transparent bg-primary text-primary-foreground', default:
secondary: 'border-transparent bg-secondary text-secondary-foreground', "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
outline: 'text-foreground', secondary:
success: 'border-success-foreground bg-success text-success-foreground', "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
warning: 'border-warning-foreground bg-warning text-warning-foreground', destructive:
error: 'border-error-foreground bg-error text-error-foreground', "border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
outline:
"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
}, },
}, },
defaultVariants: { defaultVariants: {
variant: 'default', variant: "default",
}, },
} }
); )
type BadgeProps = ComponentProps<'div'> & function Badge({
VariantProps<typeof badgeVariants> & { className,
round?: boolean; variant,
}; asChild = false,
...props
}: React.ComponentProps<"span"> &
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
const Comp = asChild ? Slot : "span"
const Badge: Component<BadgeProps> = (props) => {
const [local, others] = splitProps(props, ['class', 'variant', 'round']);
return ( return (
<div <Comp
class={cn( data-slot="badge"
badgeVariants({ variant: local.variant }), className={cn(badgeVariants({ variant }), className)}
local.round && 'rounded-full', {...props}
local.class
)}
{...others}
/> />
); )
}; }
export type { BadgeProps }; export { Badge, badgeVariants }
export { Badge, badgeVariants };

View File

@ -1,111 +0,0 @@
import type { ComponentProps, JSX } from 'solid-js';
import { For, Show, mergeProps, splitProps } from 'solid-js';
import { Dynamic } from 'solid-js/web';
import { cn } from '~/utils/styles';
type Bar<T> = T & {
value: number;
name: JSX.Element;
icon?: (props: ComponentProps<'svg'>) => JSX.Element;
href?: string;
target?: string;
};
type SortOrder = 'ascending' | 'descending' | 'none';
type ValueFormatter = (value: number) => string;
const defaultValueFormatter: ValueFormatter = (value: number) =>
value.toString();
type BarListProps<T> = ComponentProps<'div'> & {
data: Bar<T>[];
valueFormatter?: ValueFormatter;
sortOrder?: SortOrder;
};
const BarList = <T,>(rawProps: BarListProps<T>) => {
const props = mergeProps(
{
valueFormatter: defaultValueFormatter,
sortOrder: 'descending' as SortOrder,
},
rawProps
);
const [local, others] = splitProps(props, [
'class',
'data',
'valueFormatter',
'sortOrder',
]);
const sortedData = () => {
if (local.sortOrder === 'none') {
return local.data;
}
return local.data.sort((a, b) =>
local.sortOrder === 'ascending' ? a.value - b.value : b.value - a.value
);
};
const widths = () => {
const maxValue = Math.max(...sortedData().map((item) => item.value), 0);
return sortedData().map((item) =>
item.value === 0 ? 0 : Math.max((item.value / maxValue) * 100, 2)
);
};
return (
<div
class={cn('flex flex-col space-y-1.5', local.class)}
aria-sort={local.sortOrder}
{...others}
>
<For each={sortedData()}>
{(bar, idx) => {
return (
<div class="row flex w-full justify-between space-x-6">
<div class="grow">
<div
class={cn(
'flex h-8 items-center rounded-md bg-secondary px-2'
)}
style={{
width: `${widths()[idx()]}%`,
}}
>
<Show when={bar.icon}>
{(icon) => (
<Dynamic
component={icon()}
class="mr-2 size-5 flex-none"
/>
)}
</Show>
<Show when={bar.href} fallback={<p>{bar.name}</p>}>
{(href) => (
<a
href={href()}
target={bar.target ?? '_blank'}
rel="noreferrer"
class="hover:underline"
>
{bar.name}
</a>
)}
</Show>
</div>
</div>
<div class="flex items-center">
{local.valueFormatter(bar.value)}
</div>
</div>
);
}}
</For>
</div>
);
};
export { BarList };

View File

@ -1,125 +1,109 @@
import type { Component, ComponentProps, JSX, ValidComponent } from 'solid-js'; import * as React from "react"
import { Show, splitProps } from 'solid-js'; import { Slot } from "@radix-ui/react-slot"
import { ChevronRight, MoreHorizontal } from "lucide-react"
import type { PolymorphicProps } from '@kobalte/core'; import { cn } from "@/styles/utils"
import * as BreadcrumbPrimitive from '@kobalte/core/breadcrumbs';
import { cn } from '~/utils/styles'; function Breadcrumb({ ...props }: React.ComponentProps<"nav">) {
return <nav aria-label="breadcrumb" data-slot="breadcrumb" {...props} />
}
const Breadcrumb = BreadcrumbPrimitive.Root; function BreadcrumbList({ className, ...props }: React.ComponentProps<"ol">) {
const BreadcrumbList: Component<ComponentProps<'ol'>> = (props) => {
const [local, others] = splitProps(props, ['class']);
return ( return (
<ol <ol
class={cn( data-slot="breadcrumb-list"
'flex flex-wrap items-center gap-1.5 break-words text-muted-foreground text-sm sm:gap-2.5', className={cn(
local.class "text-muted-foreground flex flex-wrap items-center gap-1.5 text-sm break-words sm:gap-2.5",
className
)} )}
{...others} {...props}
/> />
); )
}; }
const BreadcrumbItem: Component<ComponentProps<'li'>> = (props) => { function BreadcrumbItem({ className, ...props }: React.ComponentProps<"li">) {
const [local, others] = splitProps(props, ['class']);
return ( return (
<li <li
class={cn('inline-flex items-center gap-1.5', local.class)} data-slot="breadcrumb-item"
{...others} className={cn("inline-flex items-center gap-1.5", className)}
{...props}
/> />
); )
}; }
type BreadcrumbLinkProps<T extends ValidComponent = 'a'> = function BreadcrumbLink({
BreadcrumbPrimitive.BreadcrumbsLinkProps<T> & { class?: string | undefined }; asChild,
className,
...props
}: React.ComponentProps<"a"> & {
asChild?: boolean
}) {
const Comp = asChild ? Slot : "a"
const BreadcrumbLink = <T extends ValidComponent = 'a'>(
props: PolymorphicProps<T, BreadcrumbLinkProps<T>>
) => {
const [local, others] = splitProps(props as BreadcrumbLinkProps, ['class']);
return ( return (
<BreadcrumbPrimitive.Link <Comp
class={cn( data-slot="breadcrumb-link"
'transition-colors hover:text-foreground data-[current]:font-normal data-[current]:text-foreground', className={cn("hover:text-foreground transition-colors", className)}
local.class {...props}
)}
{...others}
/> />
); )
}; }
type BreadcrumbSeparatorProps<T extends ValidComponent = 'span'> = function BreadcrumbPage({ className, ...props }: React.ComponentProps<"span">) {
BreadcrumbPrimitive.BreadcrumbsSeparatorProps<T> & {
class?: string | undefined;
children?: JSX.Element;
};
const BreadcrumbSeparator = <T extends ValidComponent = 'span'>(
props: PolymorphicProps<T, BreadcrumbSeparatorProps<T>>
) => {
const [local, others] = splitProps(props as BreadcrumbSeparatorProps, [
'class',
'children',
]);
return (
<BreadcrumbPrimitive.Separator
class={cn('[&>svg]:size-3.5', local.class)}
{...others}
>
<Show
when={local.children}
fallback={
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M9 6l6 6l-6 6" />
</svg>
}
>
{local.children}
</Show>
</BreadcrumbPrimitive.Separator>
);
};
const BreadcrumbEllipsis: Component<ComponentProps<'span'>> = (props) => {
const [local, others] = splitProps(props, ['class']);
return ( return (
<span <span
class={cn('flex size-9 items-center justify-center', local.class)} data-slot="breadcrumb-page"
{...others} role="link"
aria-disabled="true"
aria-current="page"
className={cn("text-foreground font-normal", className)}
{...props}
/>
)
}
function BreadcrumbSeparator({
children,
className,
...props
}: React.ComponentProps<"li">) {
return (
<li
data-slot="breadcrumb-separator"
role="presentation"
aria-hidden="true"
className={cn("[&>svg]:size-3.5", className)}
{...props}
> >
<svg {children ?? <ChevronRight />}
xmlns="http://www.w3.org/2000/svg" </li>
viewBox="0 0 24 24" )
fill="none" }
stroke="currentColor"
stroke-width="2" function BreadcrumbEllipsis({
stroke-linecap="round" className,
stroke-linejoin="round" ...props
class="size-4" }: React.ComponentProps<"span">) {
> return (
<path d="M5 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" /> <span
<path d="M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" /> data-slot="breadcrumb-ellipsis"
<path d="M19 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" /> role="presentation"
</svg> aria-hidden="true"
<span class="sr-only">More</span> className={cn("flex size-9 items-center justify-center", className)}
{...props}
>
<MoreHorizontal className="size-4" />
<span className="sr-only">More</span>
</span> </span>
); )
}; }
export { export {
Breadcrumb, Breadcrumb,
BreadcrumbList, BreadcrumbList,
BreadcrumbItem, BreadcrumbItem,
BreadcrumbLink, BreadcrumbLink,
BreadcrumbPage,
BreadcrumbSeparator, BreadcrumbSeparator,
BreadcrumbEllipsis, BreadcrumbEllipsis,
}; }

View File

@ -1,67 +1,59 @@
import type { JSX, ValidComponent } from 'solid-js'; import * as React from "react"
import { splitProps } from 'solid-js'; import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"
import * as ButtonPrimitive from '@kobalte/core/button'; import { cn } from "@/styles/utils"
import type { PolymorphicProps } from '@kobalte/core/polymorphic';
import type { VariantProps } from 'class-variance-authority';
import { cva } from 'class-variance-authority';
import { cn } from '~/utils/styles';
const buttonVariants = cva( const buttonVariants = cva(
'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md font-medium text-sm ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0', "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
{ {
variants: { variants: {
variant: { variant: {
default: 'bg-primary text-primary-foreground hover:bg-primary/90', default:
"bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",
destructive: destructive:
'bg-destructive text-destructive-foreground hover:bg-destructive/90', "bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
outline: outline:
'border border-input hover:bg-accent hover:text-accent-foreground', "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
secondary: secondary:
'bg-secondary text-secondary-foreground hover:bg-secondary/80', "bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
ghost: 'hover:bg-accent hover:text-accent-foreground', ghost:
link: 'text-primary underline-offset-4 hover:underline', "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
link: "text-primary underline-offset-4 hover:underline",
}, },
size: { size: {
default: 'h-10 px-4 py-2', default: "h-9 px-4 py-2 has-[>svg]:px-3",
sm: 'h-9 px-3 text-xs', sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
lg: 'h-11 px-8', lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
icon: 'size-10', icon: "size-9",
}, },
}, },
defaultVariants: { defaultVariants: {
variant: 'default', variant: "default",
size: 'default', size: "default",
}, },
} }
); )
type ButtonProps<T extends ValidComponent = 'button'> = function Button({
ButtonPrimitive.ButtonRootProps<T> & className,
VariantProps<typeof buttonVariants> & { variant,
class?: string | undefined; size,
children?: JSX.Element; asChild = false,
}; ...props
}: React.ComponentProps<"button"> &
VariantProps<typeof buttonVariants> & {
asChild?: boolean
}) {
const Comp = asChild ? Slot : "button"
const Button = <T extends ValidComponent = 'button'>(
props: PolymorphicProps<T, ButtonProps<T>>
) => {
const [local, others] = splitProps(props as ButtonProps, [
'variant',
'size',
'class',
]);
return ( return (
<ButtonPrimitive.Root <Comp
class={cn( data-slot="button"
buttonVariants({ variant: local.variant, size: local.size }), className={cn(buttonVariants({ variant, size, className }))}
local.class {...props}
)}
{...others}
/> />
); )
}; }
export type { ButtonProps }; export { Button, buttonVariants }
export { Button, buttonVariants };

View File

@ -0,0 +1,73 @@
import * as React from "react"
import { ChevronLeft, ChevronRight } from "lucide-react"
import { DayPicker } from "react-day-picker"
import { cn } from "@/styles/utils"
import { buttonVariants } from "@/components/ui/button"
function Calendar({
className,
classNames,
showOutsideDays = true,
...props
}: React.ComponentProps<typeof DayPicker>) {
return (
<DayPicker
showOutsideDays={showOutsideDays}
className={cn("p-3", className)}
classNames={{
months: "flex flex-col sm:flex-row gap-2",
month: "flex flex-col gap-4",
caption: "flex justify-center pt-1 relative items-center w-full",
caption_label: "text-sm font-medium",
nav: "flex items-center gap-1",
nav_button: cn(
buttonVariants({ variant: "outline" }),
"size-7 bg-transparent p-0 opacity-50 hover:opacity-100"
),
nav_button_previous: "absolute left-1",
nav_button_next: "absolute right-1",
table: "w-full border-collapse space-x-1",
head_row: "flex",
head_cell:
"text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]",
row: "flex w-full mt-2",
cell: cn(
"relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-range-end)]:rounded-r-md",
props.mode === "range"
? "[&:has(>.day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md"
: "[&:has([aria-selected])]:rounded-md"
),
day: cn(
buttonVariants({ variant: "ghost" }),
"size-8 p-0 font-normal aria-selected:opacity-100"
),
day_range_start:
"day-range-start aria-selected:bg-primary aria-selected:text-primary-foreground",
day_range_end:
"day-range-end aria-selected:bg-primary aria-selected:text-primary-foreground",
day_selected:
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground",
day_today: "bg-accent text-accent-foreground",
day_outside:
"day-outside text-muted-foreground aria-selected:text-muted-foreground",
day_disabled: "text-muted-foreground opacity-50",
day_range_middle:
"aria-selected:bg-accent aria-selected:text-accent-foreground",
day_hidden: "invisible",
...classNames,
}}
components={{
IconLeft: ({ className, ...props }) => (
<ChevronLeft className={cn("size-4", className)} {...props} />
),
IconRight: ({ className, ...props }) => (
<ChevronRight className={cn("size-4", className)} {...props} />
),
}}
{...props}
/>
)
}
export { Calendar }

View File

@ -1,46 +0,0 @@
import type { Component, ComponentProps } from 'solid-js';
import { splitProps } from 'solid-js';
import type { VariantProps } from 'class-variance-authority';
import { cva } from 'class-variance-authority';
import { cn } from '~/utils/styles';
const calloutVariants = cva('rounded-md border-l-4 p-2 pl-4', {
variants: {
variant: {
default: 'border-info-foreground bg-info text-info-foreground',
success: 'border-success-foreground bg-success text-success-foreground',
warning: 'border-warning-foreground bg-warning text-warning-foreground',
error: 'border-error-foreground bg-error text-error-foreground',
},
},
defaultVariants: {
variant: 'default',
},
});
type CalloutProps = ComponentProps<'div'> &
VariantProps<typeof calloutVariants>;
const Callout: Component<CalloutProps> = (props) => {
const [local, others] = splitProps(props, ['class', 'variant']);
return (
<div
class={cn(calloutVariants({ variant: local.variant }), local.class)}
{...others}
/>
);
};
const CalloutTitle: Component<ComponentProps<'h3'>> = (props) => {
const [local, others] = splitProps(props, ['class']);
return <h3 class={cn('font-semibold', local.class)} {...others} />;
};
const CalloutContent: Component<ComponentProps<'div'>> = (props) => {
const [local, others] = splitProps(props, ['class']);
return <div class={cn('mt-2', local.class)} {...others} />;
};
export { Callout, CalloutTitle, CalloutContent };

View File

@ -1,65 +1,92 @@
import type { Component, ComponentProps } from 'solid-js'; import type * as React from 'react';
import { splitProps } from 'solid-js';
import { cn } from '~/utils/styles'; import { cn } from '@/styles/utils';
const Card: Component<ComponentProps<'div'>> = (props) => { function Card({ className, ...props }: React.ComponentProps<'div'>) {
const [local, others] = splitProps(props, ['class']);
return ( return (
<div <div
class={cn( data-slot="card"
'rounded-lg border bg-card text-card-foreground shadow-sm', className={cn(
local.class 'flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm',
className
)} )}
{...others} {...props}
/> />
); );
}; }
const CardHeader: Component<ComponentProps<'div'>> = (props) => { function CardHeader({ className, ...props }: React.ComponentProps<'div'>) {
const [local, others] = splitProps(props, ['class']);
return ( return (
<div class={cn('flex flex-col space-y-1.5 p-6', local.class)} {...others} /> <div
); data-slot="card-header"
}; className={cn(
'@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6',
const CardTitle: Component<ComponentProps<'h3'>> = (props) => { className
const [local, others] = splitProps(props, ['class']);
return (
<h3
class={cn(
'font-semibold text-lg leading-none tracking-tight',
local.class
)} )}
{...others} {...props}
/> />
); );
}; }
const CardDescription: Component<ComponentProps<'p'>> = (props) => { function CardTitle({ className, ...props }: React.ComponentProps<'div'>) {
const [local, others] = splitProps(props, ['class']);
return ( return (
<p class={cn('text-muted-foreground text-sm', local.class)} {...others} /> <div
data-slot="card-title"
className={cn('font-semibold leading-none', className)}
{...props}
/>
); );
}; }
const CardContent: Component<ComponentProps<'div'>> = (props) => { function CardDescription({ className, ...props }: React.ComponentProps<'div'>) {
const [local, others] = splitProps(props, ['class']);
return <div class={cn('p-6 pt-0', local.class)} {...others} />;
};
const CardFooter: Component<ComponentProps<'div'>> = (props) => {
const [local, others] = splitProps(props, ['class']);
return ( return (
<div class={cn('flex items-center p-6 pt-0', local.class)} {...others} /> <div
data-slot="card-description"
className={cn('text-muted-foreground text-sm', className)}
{...props}
/>
); );
}; }
function CardAction({ className, ...props }: React.ComponentProps<'div'>) {
return (
<div
data-slot="card-action"
className={cn(
'col-start-2 row-span-2 row-start-1 self-start justify-self-end',
className
)}
{...props}
/>
);
}
function CardContent({ className, ...props }: React.ComponentProps<'div'>) {
return (
<div
data-slot="card-content"
className={cn('px-6', className)}
{...props}
/>
);
}
function CardFooter({ className, ...props }: React.ComponentProps<'div'>) {
return (
<div
data-slot="card-footer"
className={cn('flex items-center px-6 [.border-t]:pt-6', className)}
{...props}
/>
);
}
export { export {
Card, Card,
CardHeader, CardHeader,
CardFooter, CardFooter,
CardTitle, CardTitle,
CardAction,
CardDescription, CardDescription,
CardContent, CardContent,
}; };

View File

@ -1,285 +1,241 @@
import type { Accessor, Component, ComponentProps, VoidProps } from 'solid-js'; "use client"
import {
createContext,
createEffect,
createMemo,
createSignal,
mergeProps,
splitProps,
useContext,
} from 'solid-js';
import type { CreateEmblaCarouselType } from 'embla-carousel-solid'; import * as React from "react"
import createEmblaCarousel from 'embla-carousel-solid'; import useEmblaCarousel, {
type UseEmblaCarouselType,
} from "embla-carousel-react"
import { ArrowLeft, ArrowRight } from "lucide-react"
import type { ButtonProps } from '~/components/ui/button'; import { cn } from "@/styles/utils"
import { Button } from '~/components/ui/button'; import { Button } from "@/components/ui/button"
import { cn } from '~/utils/styles';
export type CarouselApi = CreateEmblaCarouselType[1]; type CarouselApi = UseEmblaCarouselType[1]
type UseCarouselParameters = Parameters<typeof useEmblaCarousel>
type UseCarouselParameters = Parameters<typeof createEmblaCarousel>; type CarouselOptions = UseCarouselParameters[0]
type CarouselOptions = NonNullable<UseCarouselParameters[0]>; type CarouselPlugin = UseCarouselParameters[1]
type CarouselPlugin = NonNullable<UseCarouselParameters[1]>;
type CarouselProps = { type CarouselProps = {
opts?: ReturnType<CarouselOptions>; opts?: CarouselOptions
plugins?: ReturnType<CarouselPlugin>; plugins?: CarouselPlugin
orientation?: 'horizontal' | 'vertical'; orientation?: "horizontal" | "vertical"
setApi?: (api: CarouselApi) => void; setApi?: (api: CarouselApi) => void
}; }
type CarouselContextProps = { type CarouselContextProps = {
carouselRef: ReturnType<typeof createEmblaCarousel>[0]; carouselRef: ReturnType<typeof useEmblaCarousel>[0]
api: ReturnType<typeof createEmblaCarousel>[1]; api: ReturnType<typeof useEmblaCarousel>[1]
scrollPrev: () => void; scrollPrev: () => void
scrollNext: () => void; scrollNext: () => void
canScrollPrev: Accessor<boolean>; canScrollPrev: boolean
canScrollNext: Accessor<boolean>; canScrollNext: boolean
} & CarouselProps; } & CarouselProps
const CarouselContext = createContext<Accessor<CarouselContextProps> | null>( const CarouselContext = React.createContext<CarouselContextProps | null>(null)
null
);
const useCarousel = () => { function useCarousel() {
const context = useContext(CarouselContext); const context = React.useContext(CarouselContext)
if (!context) { if (!context) {
throw new Error('useCarousel must be used within a <Carousel />'); throw new Error("useCarousel must be used within a <Carousel />")
} }
return context(); return context
}; }
const Carousel: Component<CarouselProps & ComponentProps<'div'>> = ( function Carousel({
rawProps orientation = "horizontal",
) => { opts,
const props = mergeProps<(CarouselProps & ComponentProps<'div'>)[]>( setApi,
{ orientation: 'horizontal' }, plugins,
rawProps className,
); children,
...props
}: React.ComponentProps<"div"> & CarouselProps) {
const [carouselRef, api] = useEmblaCarousel(
{
...opts,
axis: orientation === "horizontal" ? "x" : "y",
},
plugins
)
const [canScrollPrev, setCanScrollPrev] = React.useState(false)
const [canScrollNext, setCanScrollNext] = React.useState(false)
const [local, others] = splitProps(props, [ const onSelect = React.useCallback((api: CarouselApi) => {
'orientation', if (!api) return
'opts', setCanScrollPrev(api.canScrollPrev())
'setApi', setCanScrollNext(api.canScrollNext())
'plugins', }, [])
'class',
'children',
]);
const [carouselRef, api] = createEmblaCarousel( const scrollPrev = React.useCallback(() => {
() => ({ api?.scrollPrev()
...local.opts, }, [api])
axis: local.orientation === 'horizontal' ? 'x' : 'y',
}),
() => (local.plugins === undefined ? [] : local.plugins)
);
const [canScrollPrev, setCanScrollPrev] = createSignal(false);
const [canScrollNext, setCanScrollNext] = createSignal(false);
const onSelect = (api: NonNullable<ReturnType<CarouselApi>>) => { const scrollNext = React.useCallback(() => {
setCanScrollPrev(api.canScrollPrev()); api?.scrollNext()
setCanScrollNext(api.canScrollNext()); }, [api])
};
const scrollPrev = () => { const handleKeyDown = React.useCallback(
api()?.scrollPrev(); (event: React.KeyboardEvent<HTMLDivElement>) => {
}; if (event.key === "ArrowLeft") {
event.preventDefault()
scrollPrev()
} else if (event.key === "ArrowRight") {
event.preventDefault()
scrollNext()
}
},
[scrollPrev, scrollNext]
)
const scrollNext = () => { React.useEffect(() => {
api()?.scrollNext(); if (!api || !setApi) return
}; setApi(api)
}, [api, setApi])
const handleKeyDown = (event: KeyboardEvent) => { React.useEffect(() => {
if (event.key === 'ArrowLeft') { if (!api) return
event.preventDefault(); onSelect(api)
scrollPrev(); api.on("reInit", onSelect)
} else if (event.key === 'ArrowRight') { api.on("select", onSelect)
event.preventDefault();
scrollNext();
}
};
createEffect(() => {
if (!api() || !local.setApi) {
return;
}
local.setApi(api);
});
createEffect(() => {
if (!api()) {
return;
}
onSelect(api()!);
api()!.on('reInit', onSelect);
api()!.on('select', onSelect);
return () => { return () => {
api()?.off('select', onSelect); api?.off("select", onSelect)
}; }
}); }, [api, onSelect])
const value = createMemo( return (
() => <CarouselContext.Provider
({ value={{
carouselRef, carouselRef,
api, api: api,
opts: local.opts, opts,
orientation: orientation:
local.orientation || orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
(local.opts?.axis === 'y' ? 'vertical' : 'horizontal'),
scrollPrev, scrollPrev,
scrollNext, scrollNext,
canScrollPrev, canScrollPrev,
canScrollNext, canScrollNext,
}) satisfies CarouselContextProps }}
); >
return (
<CarouselContext.Provider value={value}>
<div <div
onKeyDown={handleKeyDown} onKeyDownCapture={handleKeyDown}
class={cn('relative', local.class)} className={cn("relative", className)}
role="region" role="region"
aria-roledescription="carousel" aria-roledescription="carousel"
{...others} data-slot="carousel"
{...props}
> >
{local.children} {children}
</div> </div>
</CarouselContext.Provider> </CarouselContext.Provider>
); )
}; }
const CarouselContent: Component<ComponentProps<'div'>> = (props) => { function CarouselContent({ className, ...props }: React.ComponentProps<"div">) {
const [local, others] = splitProps(props, ['class']); const { carouselRef, orientation } = useCarousel()
const { carouselRef, orientation } = useCarousel();
return ( return (
<div ref={carouselRef} class="overflow-hidden"> <div
ref={carouselRef}
className="overflow-hidden"
data-slot="carousel-content"
>
<div <div
class={cn( className={cn(
'flex', "flex",
orientation === 'horizontal' ? '-ml-4' : '-mt-4 flex-col', orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
local.class className
)} )}
{...others} {...props}
/> />
</div> </div>
); )
}; }
const CarouselItem: Component<ComponentProps<'div'>> = (props) => { function CarouselItem({ className, ...props }: React.ComponentProps<"div">) {
const [local, others] = splitProps(props, ['class']); const { orientation } = useCarousel()
const { orientation } = useCarousel();
return ( return (
<div <div
role="group" role="group"
aria-roledescription="slide" aria-roledescription="slide"
class={cn( data-slot="carousel-item"
'min-w-0 shrink-0 grow-0 basis-full', className={cn(
orientation === 'horizontal' ? 'pl-4' : 'pt-4', "min-w-0 shrink-0 grow-0 basis-full",
local.class orientation === "horizontal" ? "pl-4" : "pt-4",
className
)} )}
{...others} {...props}
/> />
); )
}; }
type CarouselButtonProps = VoidProps<ButtonProps>; function CarouselPrevious({
className,
const CarouselPrevious: Component<CarouselButtonProps> = (rawProps) => { variant = "outline",
const props = mergeProps<CarouselButtonProps[]>( size = "icon",
{ variant: 'outline', size: 'icon' }, ...props
rawProps }: React.ComponentProps<typeof Button>) {
); const { orientation, scrollPrev, canScrollPrev } = useCarousel()
const [local, others] = splitProps(props, ['class', 'variant', 'size']);
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
return ( return (
<Button <Button
variant={local.variant} data-slot="carousel-previous"
size={local.size} variant={variant}
class={cn( size={size}
'absolute size-8 touch-manipulation rounded-full', className={cn(
orientation === 'horizontal' "absolute size-8 rounded-full",
? '-left-12 -translate-y-1/2 top-1/2' orientation === "horizontal"
: '-top-12 -translate-x-1/2 left-1/2 rotate-90', ? "top-1/2 -left-12 -translate-y-1/2"
local.class : "-top-12 left-1/2 -translate-x-1/2 rotate-90",
className
)} )}
disabled={!canScrollPrev()} disabled={!canScrollPrev}
onClick={scrollPrev} onClick={scrollPrev}
{...others} {...props}
> >
<svg <ArrowLeft />
xmlns="http://www.w3.org/2000/svg" <span className="sr-only">Previous slide</span>
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M5 12l14 0" />
<path d="M5 12l6 6" />
<path d="M5 12l6 -6" />
</svg>
<span class="sr-only">Previous slide</span>
</Button> </Button>
); )
}; }
const CarouselNext: Component<CarouselButtonProps> = (rawProps) => { function CarouselNext({
const props = mergeProps<CarouselButtonProps[]>( className,
{ variant: 'outline', size: 'icon' }, variant = "outline",
rawProps size = "icon",
); ...props
const [local, others] = splitProps(props, ['class', 'variant', 'size']); }: React.ComponentProps<typeof Button>) {
const { orientation, scrollNext, canScrollNext } = useCarousel(); const { orientation, scrollNext, canScrollNext } = useCarousel()
return ( return (
<Button <Button
variant={local.variant} data-slot="carousel-next"
size={local.size} variant={variant}
class={cn( size={size}
'absolute size-8 touch-manipulation rounded-full', className={cn(
orientation === 'horizontal' "absolute size-8 rounded-full",
? '-right-12 -translate-y-1/2 top-1/2' orientation === "horizontal"
: '-bottom-12 -translate-x-1/2 left-1/2 rotate-90', ? "top-1/2 -right-12 -translate-y-1/2"
local.class : "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
className
)} )}
disabled={!canScrollNext()} disabled={!canScrollNext}
onClick={scrollNext} onClick={scrollNext}
{...others} {...props}
> >
<svg <ArrowRight />
xmlns="http://www.w3.org/2000/svg" <span className="sr-only">Next slide</span>
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M5 12l14 0" />
<path d="M13 18l6 -6" />
<path d="M13 6l6 6" />
</svg>
<span class="sr-only">Next slide</span>
</Button> </Button>
); )
}; }
export { export {
type CarouselApi,
Carousel, Carousel,
CarouselContent, CarouselContent,
CarouselItem, CarouselItem,
CarouselPrevious, CarouselPrevious,
CarouselNext, CarouselNext,
}; }

View File

@ -0,0 +1,351 @@
import * as React from "react"
import * as RechartsPrimitive from "recharts"
import { cn } from "@/styles/utils"
// Format: { THEME_NAME: CSS_SELECTOR }
const THEMES = { light: "", dark: ".dark" } as const
export type ChartConfig = {
[k in string]: {
label?: React.ReactNode
icon?: React.ComponentType
} & (
| { color?: string; theme?: never }
| { color?: never; theme: Record<keyof typeof THEMES, string> }
)
}
type ChartContextProps = {
config: ChartConfig
}
const ChartContext = React.createContext<ChartContextProps | null>(null)
function useChart() {
const context = React.useContext(ChartContext)
if (!context) {
throw new Error("useChart must be used within a <ChartContainer />")
}
return context
}
function ChartContainer({
id,
className,
children,
config,
...props
}: React.ComponentProps<"div"> & {
config: ChartConfig
children: React.ComponentProps<
typeof RechartsPrimitive.ResponsiveContainer
>["children"]
}) {
const uniqueId = React.useId()
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`
return (
<ChartContext.Provider value={{ config }}>
<div
data-slot="chart"
data-chart={chartId}
className={cn(
"[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
className
)}
{...props}
>
<ChartStyle id={chartId} config={config} />
<RechartsPrimitive.ResponsiveContainer>
{children}
</RechartsPrimitive.ResponsiveContainer>
</div>
</ChartContext.Provider>
)
}
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
const colorConfig = Object.entries(config).filter(
([, config]) => config.theme || config.color
)
if (!colorConfig.length) {
return null
}
return (
<style
dangerouslySetInnerHTML={{
__html: Object.entries(THEMES)
.map(
([theme, prefix]) => `
${prefix} [data-chart=${id}] {
${colorConfig
.map(([key, itemConfig]) => {
const color =
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ||
itemConfig.color
return color ? ` --color-${key}: ${color};` : null
})
.join("\n")}
}
`
)
.join("\n"),
}}
/>
)
}
const ChartTooltip = RechartsPrimitive.Tooltip
function ChartTooltipContent({
active,
payload,
className,
indicator = "dot",
hideLabel = false,
hideIndicator = false,
label,
labelFormatter,
labelClassName,
formatter,
color,
nameKey,
labelKey,
}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
React.ComponentProps<"div"> & {
hideLabel?: boolean
hideIndicator?: boolean
indicator?: "line" | "dot" | "dashed"
nameKey?: string
labelKey?: string
}) {
const { config } = useChart()
const tooltipLabel = React.useMemo(() => {
if (hideLabel || !payload?.length) {
return null
}
const [item] = payload
const key = `${labelKey || item?.dataKey || item?.name || "value"}`
const itemConfig = getPayloadConfigFromPayload(config, item, key)
const value =
!labelKey && typeof label === "string"
? config[label as keyof typeof config]?.label || label
: itemConfig?.label
if (labelFormatter) {
return (
<div className={cn("font-medium", labelClassName)}>
{labelFormatter(value, payload)}
</div>
)
}
if (!value) {
return null
}
return <div className={cn("font-medium", labelClassName)}>{value}</div>
}, [
label,
labelFormatter,
payload,
hideLabel,
labelClassName,
config,
labelKey,
])
if (!active || !payload?.length) {
return null
}
const nestLabel = payload.length === 1 && indicator !== "dot"
return (
<div
className={cn(
"border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl",
className
)}
>
{!nestLabel ? tooltipLabel : null}
<div className="grid gap-1.5">
{payload.map((item, index) => {
const key = `${nameKey || item.name || item.dataKey || "value"}`
const itemConfig = getPayloadConfigFromPayload(config, item, key)
const indicatorColor = color || item.payload.fill || item.color
return (
<div
key={item.dataKey}
className={cn(
"[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5",
indicator === "dot" && "items-center"
)}
>
{formatter && item?.value !== undefined && item.name ? (
formatter(item.value, item.name, item, index, item.payload)
) : (
<>
{itemConfig?.icon ? (
<itemConfig.icon />
) : (
!hideIndicator && (
<div
className={cn(
"shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
{
"h-2.5 w-2.5": indicator === "dot",
"w-1": indicator === "line",
"w-0 border-[1.5px] border-dashed bg-transparent":
indicator === "dashed",
"my-0.5": nestLabel && indicator === "dashed",
}
)}
style={
{
"--color-bg": indicatorColor,
"--color-border": indicatorColor,
} as React.CSSProperties
}
/>
)
)}
<div
className={cn(
"flex flex-1 justify-between leading-none",
nestLabel ? "items-end" : "items-center"
)}
>
<div className="grid gap-1.5">
{nestLabel ? tooltipLabel : null}
<span className="text-muted-foreground">
{itemConfig?.label || item.name}
</span>
</div>
{item.value && (
<span className="text-foreground font-mono font-medium tabular-nums">
{item.value.toLocaleString()}
</span>
)}
</div>
</>
)}
</div>
)
})}
</div>
</div>
)
}
const ChartLegend = RechartsPrimitive.Legend
function ChartLegendContent({
className,
hideIcon = false,
payload,
verticalAlign = "bottom",
nameKey,
}: React.ComponentProps<"div"> &
Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
hideIcon?: boolean
nameKey?: string
}) {
const { config } = useChart()
if (!payload?.length) {
return null
}
return (
<div
className={cn(
"flex items-center justify-center gap-4",
verticalAlign === "top" ? "pb-3" : "pt-3",
className
)}
>
{payload.map((item) => {
const key = `${nameKey || item.dataKey || "value"}`
const itemConfig = getPayloadConfigFromPayload(config, item, key)
return (
<div
key={item.value}
className={cn(
"[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3"
)}
>
{itemConfig?.icon && !hideIcon ? (
<itemConfig.icon />
) : (
<div
className="h-2 w-2 shrink-0 rounded-[2px]"
style={{
backgroundColor: item.color,
}}
/>
)}
{itemConfig?.label}
</div>
)
})}
</div>
)
}
// Helper to extract item config from a payload.
function getPayloadConfigFromPayload(
config: ChartConfig,
payload: unknown,
key: string
) {
if (typeof payload !== "object" || payload === null) {
return undefined
}
const payloadPayload =
"payload" in payload &&
typeof payload.payload === "object" &&
payload.payload !== null
? payload.payload
: undefined
let configLabelKey: string = key
if (
key in payload &&
typeof payload[key as keyof typeof payload] === "string"
) {
configLabelKey = payload[key as keyof typeof payload] as string
} else if (
payloadPayload &&
key in payloadPayload &&
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
) {
configLabelKey = payloadPayload[
key as keyof typeof payloadPayload
] as string
}
return configLabelKey in config
? config[configLabelKey]
: config[key as keyof typeof config]
}
export {
ChartContainer,
ChartTooltip,
ChartTooltipContent,
ChartLegend,
ChartLegendContent,
ChartStyle,
}

View File

@ -1,292 +0,0 @@
import type { Component } from "solid-js"
import { createEffect, createSignal, mergeProps, on, onCleanup, onMount } from "solid-js"
import { unwrap } from "solid-js/store"
import type { Ref } from "@solid-primitives/refs"
import { mergeRefs } from "@solid-primitives/refs"
import type {
ChartComponent,
ChartData,
ChartItem,
ChartOptions,
Plugin as ChartPlugin,
ChartType,
ChartTypeRegistry,
TooltipModel
} from "chart.js"
import {
ArcElement,
BarController,
BarElement,
BubbleController,
CategoryScale,
Chart,
Colors,
DoughnutController,
Filler,
Legend,
LinearScale,
LineController,
LineElement,
PieController,
PointElement,
PolarAreaController,
RadarController,
RadialLinearScale,
ScatterController,
Tooltip
} from "chart.js"
type TypedChartProps = {
data: ChartData
options?: ChartOptions
plugins?: ChartPlugin[]
ref?: Ref<HTMLCanvasElement | null>
width?: number | undefined
height?: number | undefined
}
type ChartProps = TypedChartProps & {
type: ChartType
}
type ChartContext = {
chart: Chart
tooltip: TooltipModel<keyof ChartTypeRegistry>
}
const BaseChart: Component<ChartProps> = (rawProps) => {
const [canvasRef, setCanvasRef] = createSignal<HTMLCanvasElement | null>()
const [chart, setChart] = createSignal<Chart>()
const props = mergeProps(
{
width: 512,
height: 512,
options: { responsive: true } as ChartOptions,
plugins: [] as ChartPlugin[]
},
rawProps
)
const init = () => {
const ctx = canvasRef()?.getContext("2d") as ChartItem
const config = unwrap(props)
const chart = new Chart(ctx, {
type: config.type,
data: config.data,
options: config.options,
plugins: config.plugins
})
setChart(chart)
}
onMount(() => init())
createEffect(
on(
() => props.data,
() => {
chart()!.data = props.data
chart()!.update()
},
{ defer: true }
)
)
createEffect(
on(
() => props.options,
() => {
chart()!.options = props.options
chart()!.update()
},
{ defer: true }
)
)
createEffect(
on(
[() => props.width, () => props.height],
() => {
chart()!.resize(props.width, props.height)
},
{ defer: true }
)
)
createEffect(
on(
() => props.type,
() => {
const dimensions = [chart()!.width, chart()!.height]
chart()!.destroy()
init()
chart()!.resize(...dimensions)
},
{ defer: true }
)
)
onCleanup(() => {
chart()?.destroy()
mergeRefs(props.ref, null)
})
Chart.register(Colors, Filler, Legend, Tooltip)
return (
<canvas
ref={mergeRefs(props.ref, (el) => setCanvasRef(el))}
height={props.height}
width={props.width}
/>
)
}
function showTooltip(context: ChartContext) {
let el = document.getElementById("chartjs-tooltip")
if (!el) {
el = document.createElement("div")
el.id = "chartjs-tooltip"
document.body.appendChild(el)
}
const model = context.tooltip
if (model.opacity === 0 || !model.body) {
el.style.opacity = "0"
return
}
el.className = `p-2 bg-card text-card-foreground rounded-lg border shadow-sm text-sm ${
model.yAlign ?? `no-transform`
}`
let content = ""
model.title.forEach((title) => {
content += `<h3 class="font-semibold leading-none tracking-tight">${title}</h3>`
})
content += `<div class="mt-1 text-muted-foreground">`
const body = model.body.flatMap((body) => body.lines)
body.forEach((line, i) => {
const colors = model.labelColors[i]
content += `
<div class="flex items-center">
<span class="inline-block h-2 w-2 mr-1 rounded-full border" style="background: ${colors.backgroundColor}; border-color: ${colors.borderColor}"></span>
${line}
</div>`
})
content += `</div>`
el.innerHTML = content
const pos = context.chart.canvas.getBoundingClientRect()
el.style.opacity = "1"
el.style.position = "absolute"
el.style.left = `${pos.left + window.scrollX + model.caretX}px`
el.style.top = `${pos.top + window.scrollY + model.caretY}px`
el.style.pointerEvents = "none"
}
function createTypedChart(
type: ChartType,
components: ChartComponent[]
): Component<TypedChartProps> {
const chartsWithScales: ChartType[] = ["bar", "line", "scatter"]
const chartsWithLegends: ChartType[] = ["bar", "line"]
const options: ChartOptions = {
responsive: true,
maintainAspectRatio: false,
scales: chartsWithScales.includes(type)
? {
x: {
border: { display: false },
grid: { display: false }
},
y: {
border: {
dash: [3],
dashOffset: 3,
display: false
},
grid: {
color: "hsla(240, 3.8%, 46.1%, 0.4)"
}
}
}
: {},
plugins: {
legend: chartsWithLegends.includes(type)
? {
display: true,
align: "end",
labels: {
usePointStyle: true,
boxWidth: 6,
boxHeight: 6,
color: "hsl(240, 3.8%, 46.1%)",
font: { size: 14 }
}
}
: { display: false },
tooltip: {
enabled: false,
external: (context) => showTooltip(context)
}
}
}
Chart.register(...components)
return (props) => <BaseChart type={type} options={options} {...props} />
}
const BarChart = /* #__PURE__ */ createTypedChart("bar", [
BarController,
BarElement,
CategoryScale,
LinearScale
])
const BubbleChart = /* #__PURE__ */ createTypedChart("bubble", [
BubbleController,
PointElement,
LinearScale
])
const DonutChart = /* #__PURE__ */ createTypedChart("doughnut", [DoughnutController, ArcElement])
const LineChart = /* #__PURE__ */ createTypedChart("line", [
LineController,
LineElement,
PointElement,
CategoryScale,
LinearScale
])
const PieChart = /* #__PURE__ */ createTypedChart("pie", [PieController, ArcElement])
const PolarAreaChart = /* #__PURE__ */ createTypedChart("polarArea", [
PolarAreaController,
ArcElement,
RadialLinearScale
])
const RadarChart = /* #__PURE__ */ createTypedChart("radar", [
RadarController,
LineElement,
PointElement,
RadialLinearScale
])
const ScatterChart = /* #__PURE__ */ createTypedChart("scatter", [
ScatterController,
PointElement,
LinearScale
])
export {
BaseChart as Chart,
BarChart,
BubbleChart,
DonutChart,
LineChart,
PieChart,
PolarAreaChart,
RadarChart,
ScatterChart
}

View File

@ -1,60 +1,32 @@
import type { ValidComponent } from 'solid-js'; "use client"
import { Match, Switch, splitProps } from 'solid-js';
import * as CheckboxPrimitive from '@kobalte/core/checkbox'; import * as React from "react"
import type { PolymorphicProps } from '@kobalte/core/polymorphic'; import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
import { CheckIcon } from "lucide-react"
import { cn } from '~/utils/styles'; import { cn } from "@/styles/utils"
type CheckboxRootProps<T extends ValidComponent = 'div'> = function Checkbox({
CheckboxPrimitive.CheckboxRootProps<T> & { class?: string | undefined }; className,
...props
const Checkbox = <T extends ValidComponent = 'div'>( }: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
props: PolymorphicProps<T, CheckboxRootProps<T>>
) => {
const [local, others] = splitProps(props as CheckboxRootProps, ['class']);
return ( return (
<CheckboxPrimitive.Root <CheckboxPrimitive.Root
class={cn('items-top group relative flex space-x-2', local.class)} data-slot="checkbox"
{...others} className={cn(
"peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
className
)}
{...props}
> >
<CheckboxPrimitive.Input class="peer" /> <CheckboxPrimitive.Indicator
<CheckboxPrimitive.Control class="size-4 shrink-0 rounded-sm border border-primary ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-ring peer-focus-visible:ring-offset-2 data-[checked]:border-none data-[indeterminate]:border-none data-[checked]:bg-primary data-[indeterminate]:bg-primary data-[checked]:text-primary-foreground data-[indeterminate]:text-primary-foreground"> data-slot="checkbox-indicator"
<CheckboxPrimitive.Indicator> className="flex items-center justify-center text-current transition-none"
<Switch> >
<Match when={!others.indeterminate}> <CheckIcon className="size-3.5" />
<svg </CheckboxPrimitive.Indicator>
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M5 12l5 5l10 -10" />
</svg>
</Match>
<Match when={others.indeterminate}>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M5 12l14 0" />
</svg>
</Match>
</Switch>
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Control>
</CheckboxPrimitive.Root> </CheckboxPrimitive.Root>
); )
}; }
export { Checkbox }; export { Checkbox }

View File

@ -1,9 +1,31 @@
import * as CollapsiblePrimitive from "@kobalte/core/collapsible" import * as CollapsiblePrimitive from "@radix-ui/react-collapsible"
const Collapsible = CollapsiblePrimitive.Root function Collapsible({
...props
}: React.ComponentProps<typeof CollapsiblePrimitive.Root>) {
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />
}
const CollapsibleTrigger = CollapsiblePrimitive.Trigger function CollapsibleTrigger({
...props
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleTrigger>) {
return (
<CollapsiblePrimitive.CollapsibleTrigger
data-slot="collapsible-trigger"
{...props}
/>
)
}
const CollapsibleContent = CollapsiblePrimitive.Content function CollapsibleContent({
...props
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleContent>) {
return (
<CollapsiblePrimitive.CollapsibleContent
data-slot="collapsible-content"
{...props}
/>
)
}
export { Collapsible, CollapsibleTrigger, CollapsibleContent } export { Collapsible, CollapsibleTrigger, CollapsibleContent }

View File

@ -1,203 +0,0 @@
import type { JSX, ValidComponent } from 'solid-js';
import { Show, splitProps } from 'solid-js';
import * as ComboboxPrimitive from '@kobalte/core/combobox';
import type { PolymorphicProps } from '@kobalte/core/polymorphic';
import { cn } from '~/utils/styles';
const Combobox = ComboboxPrimitive.Root;
const ComboboxItemLabel = ComboboxPrimitive.ItemLabel;
const ComboboxHiddenSelect = ComboboxPrimitive.HiddenSelect;
type ComboboxItemProps<T extends ValidComponent = 'li'> =
ComboboxPrimitive.ComboboxItemProps<T> & {
class?: string | undefined;
};
const ComboboxItem = <T extends ValidComponent = 'li'>(
props: PolymorphicProps<T, ComboboxItemProps<T>>
) => {
const [local, others] = splitProps(props as ComboboxItemProps, ['class']);
return (
<ComboboxPrimitive.Item
class={cn(
'relative flex cursor-default select-none items-center justify-between rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled]:pointer-events-none data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[disabled]:opacity-50',
local.class
)}
{...others}
/>
);
};
type ComboboxItemIndicatorProps<T extends ValidComponent = 'div'> =
ComboboxPrimitive.ComboboxItemIndicatorProps<T> & {
children?: JSX.Element;
};
const ComboboxItemIndicator = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, ComboboxItemIndicatorProps<T>>
) => {
const [local, others] = splitProps(props as ComboboxItemIndicatorProps, [
'children',
]);
return (
<ComboboxPrimitive.ItemIndicator {...others}>
<Show
when={local.children}
fallback={
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M5 12l5 5l10 -10" />
</svg>
}
>
{(children) => children()}
</Show>
</ComboboxPrimitive.ItemIndicator>
);
};
type ComboboxSectionProps<T extends ValidComponent = 'li'> =
ComboboxPrimitive.ComboboxSectionProps<T> & { class?: string | undefined };
const ComboboxSection = <T extends ValidComponent = 'li'>(
props: PolymorphicProps<T, ComboboxSectionProps<T>>
) => {
const [local, others] = splitProps(props as ComboboxSectionProps, ['class']);
return (
<ComboboxPrimitive.Section
class={cn(
'overflow-hidden p-1 px-2 py-1.5 font-medium text-muted-foreground text-xs ',
local.class
)}
{...others}
/>
);
};
type ComboboxControlProps<
U,
T extends ValidComponent = 'div',
> = ComboboxPrimitive.ComboboxControlProps<U, T> & {
class?: string | undefined;
};
const ComboboxControl = <T, U extends ValidComponent = 'div'>(
props: PolymorphicProps<U, ComboboxControlProps<T>>
) => {
const [local, others] = splitProps(props as ComboboxControlProps<T>, [
'class',
]);
return (
<ComboboxPrimitive.Control
class={cn('flex h-10 items-center rounded-md border px-3', local.class)}
{...others}
/>
);
};
type ComboboxInputProps<T extends ValidComponent = 'input'> =
ComboboxPrimitive.ComboboxInputProps<T> & { class?: string | undefined };
const ComboboxInput = <T extends ValidComponent = 'input'>(
props: PolymorphicProps<T, ComboboxInputProps<T>>
) => {
const [local, others] = splitProps(props as ComboboxInputProps, ['class']);
return (
<ComboboxPrimitive.Input
class={cn(
'flex size-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50',
local.class
)}
{...others}
/>
);
};
type ComboboxTriggerProps<T extends ValidComponent = 'button'> =
ComboboxPrimitive.ComboboxTriggerProps<T> & {
class?: string | undefined;
children?: JSX.Element;
};
const ComboboxTrigger = <T extends ValidComponent = 'button'>(
props: PolymorphicProps<T, ComboboxTriggerProps<T>>
) => {
const [local, others] = splitProps(props as ComboboxTriggerProps, [
'class',
'children',
]);
return (
<ComboboxPrimitive.Trigger
class={cn('size-4 opacity-50', local.class)}
{...others}
>
<ComboboxPrimitive.Icon>
<Show
when={local.children}
fallback={
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M8 9l4 -4l4 4" />
<path d="M16 15l-4 4l-4 -4" />
</svg>
}
>
{(children) => children()}
</Show>
</ComboboxPrimitive.Icon>
</ComboboxPrimitive.Trigger>
);
};
type ComboboxContentProps<T extends ValidComponent = 'div'> =
ComboboxPrimitive.ComboboxContentProps<T> & { class?: string | undefined };
const ComboboxContent = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, ComboboxContentProps<T>>
) => {
const [local, others] = splitProps(props as ComboboxContentProps, ['class']);
return (
<ComboboxPrimitive.Portal>
<ComboboxPrimitive.Content
class={cn(
'fade-in-80 relative z-50 min-w-32 animate-in overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md',
local.class
)}
{...others}
>
<ComboboxPrimitive.Listbox class="m-0 p-1" />
</ComboboxPrimitive.Content>
</ComboboxPrimitive.Portal>
);
};
export {
Combobox,
ComboboxItem,
ComboboxItemLabel,
ComboboxItemIndicator,
ComboboxSection,
ComboboxControl,
ComboboxTrigger,
ComboboxInput,
ComboboxHiddenSelect,
ComboboxContent,
};

View File

@ -1,163 +1,168 @@
import type { "use client"
Component,
ComponentProps,
ParentProps,
VoidProps,
} from 'solid-js';
import { splitProps } from 'solid-js';
import type { DialogRootProps } from '@kobalte/core/dialog'; import * as React from "react"
import * as CommandPrimitive from 'cmdk-solid'; import { Command as CommandPrimitive } from "cmdk"
import { SearchIcon } from "lucide-react"
import { Dialog, DialogContent } from '~/components/ui/dialog'; import { cn } from "@/styles/utils"
import { cn } from '~/utils/styles'; import {
Dialog,
const Command: Component<ParentProps<CommandPrimitive.CommandRootProps>> = ( DialogContent,
props DialogDescription,
) => { DialogHeader,
const [local, others] = splitProps(props, ['class']); DialogTitle,
} from "@/components/ui/dialog"
function Command({
className,
...props
}: React.ComponentProps<typeof CommandPrimitive>) {
return ( return (
<CommandPrimitive.CommandRoot <CommandPrimitive
class={cn( data-slot="command"
'flex size-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground blur-none', className={cn(
local.class "bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",
className
)} )}
{...others} {...props}
/> />
); )
}; }
const CommandDialog: Component<ParentProps<DialogRootProps>> = (props) => {
const [local, others] = splitProps(props, ['children']);
function CommandDialog({
title = "Command Palette",
description = "Search for a command to run...",
children,
...props
}: React.ComponentProps<typeof Dialog> & {
title?: string
description?: string
}) {
return ( return (
<Dialog {...others}> <Dialog {...props}>
<DialogContent class="overflow-hidden p-0"> <DialogHeader className="sr-only">
<Command class="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:size-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:size-5"> <DialogTitle>{title}</DialogTitle>
{local.children} <DialogDescription>{description}</DialogDescription>
</DialogHeader>
<DialogContent className="overflow-hidden p-0">
<Command className="[&_[cmdk-group-heading]]:text-muted-foreground **:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">
{children}
</Command> </Command>
</DialogContent> </DialogContent>
</Dialog> </Dialog>
); )
}; }
const CommandInput: Component<VoidProps<CommandPrimitive.CommandInputProps>> = (
props
) => {
const [local, others] = splitProps(props, ['class']);
function CommandInput({
className,
...props
}: React.ComponentProps<typeof CommandPrimitive.Input>) {
return ( return (
<div class="flex items-center border-b px-3" cmdk-input-wrapper=""> <div
<svg data-slot="command-input-wrapper"
xmlns="http://www.w3.org/2000/svg" className="flex h-9 items-center gap-2 border-b px-3"
viewBox="0 0 24 24" >
fill="none" <SearchIcon className="size-4 shrink-0 opacity-50" />
stroke="currentColor" <CommandPrimitive.Input
stroke-width="2" data-slot="command-input"
stroke-linecap="round" className={cn(
stroke-linejoin="round" "placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
class="mr-2 size-4 shrink-0 opacity-50" className
>
<path d="M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0" />
<path d="M21 21l-6 -6" />
</svg>
<CommandPrimitive.CommandInput
class={cn(
'flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50',
local.class
)} )}
{...others} {...props}
/> />
</div> </div>
); )
}; }
const CommandList: Component<ParentProps<CommandPrimitive.CommandListProps>> = (
props
) => {
const [local, others] = splitProps(props, ['class']);
function CommandList({
className,
...props
}: React.ComponentProps<typeof CommandPrimitive.List>) {
return ( return (
<CommandPrimitive.CommandList <CommandPrimitive.List
class={cn('max-h-[300px] overflow-y-auto overflow-x-hidden', local.class)} data-slot="command-list"
{...others} className={cn(
/> "max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",
); className
};
const CommandEmpty: Component<
ParentProps<CommandPrimitive.CommandEmptyProps>
> = (props) => {
const [local, others] = splitProps(props, ['class']);
return (
<CommandPrimitive.CommandEmpty
class={cn('py-6 text-center text-sm', local.class)}
{...others}
/>
);
};
const CommandGroup: Component<
ParentProps<CommandPrimitive.CommandGroupProps>
> = (props) => {
const [local, others] = splitProps(props, ['class']);
return (
<CommandPrimitive.CommandGroup
class={cn(
'overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:text-xs',
local.class
)} )}
{...others} {...props}
/> />
); )
}; }
const CommandSeparator: Component<
VoidProps<CommandPrimitive.CommandSeparatorProps>
> = (props) => {
const [local, others] = splitProps(props, ['class']);
function CommandEmpty({
...props
}: React.ComponentProps<typeof CommandPrimitive.Empty>) {
return ( return (
<CommandPrimitive.CommandSeparator <CommandPrimitive.Empty
class={cn('h-px bg-border', local.class)} data-slot="command-empty"
{...others} className="py-6 text-center text-sm"
{...props}
/> />
); )
}; }
const CommandItem: Component<ParentProps<CommandPrimitive.CommandItemProps>> = (
props
) => {
const [local, others] = splitProps(props, ['class']);
function CommandGroup({
className,
...props
}: React.ComponentProps<typeof CommandPrimitive.Group>) {
return ( return (
<CommandPrimitive.CommandItem <CommandPrimitive.Group
cmdk-item="" data-slot="command-group"
class={cn( className={cn(
'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50', "text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium",
local.class className
)} )}
{...others} {...props}
/> />
); )
}; }
const CommandShortcut: Component<ComponentProps<'span'>> = (props) => { function CommandSeparator({
const [local, others] = splitProps(props, ['class']); className,
...props
}: React.ComponentProps<typeof CommandPrimitive.Separator>) {
return (
<CommandPrimitive.Separator
data-slot="command-separator"
className={cn("bg-border -mx-1 h-px", className)}
{...props}
/>
)
}
function CommandItem({
className,
...props
}: React.ComponentProps<typeof CommandPrimitive.Item>) {
return (
<CommandPrimitive.Item
data-slot="command-item"
className={cn(
"data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
/>
)
}
function CommandShortcut({
className,
...props
}: React.ComponentProps<"span">) {
return ( return (
<span <span
class={cn( data-slot="command-shortcut"
'ml-auto text-muted-foreground text-xs tracking-widest', className={cn(
local.class "text-muted-foreground ml-auto text-xs tracking-widest",
className
)} )}
{...others} {...props}
/> />
); )
}; }
export { export {
Command, Command,
@ -169,4 +174,4 @@ export {
CommandItem, CommandItem,
CommandShortcut, CommandShortcut,
CommandSeparator, CommandSeparator,
}; }

View File

@ -1,273 +1,252 @@
import type { Component, ComponentProps, JSX, ValidComponent } from 'solid-js'; "use client"
import { splitProps } from 'solid-js';
import * as ContextMenuPrimitive from '@kobalte/core/context-menu'; import * as React from "react"
import type { PolymorphicProps } from '@kobalte/core/polymorphic'; import * as ContextMenuPrimitive from "@radix-ui/react-context-menu"
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
import { cn } from '~/utils/styles'; import { cn } from "@/styles/utils"
const ContextMenuTrigger = ContextMenuPrimitive.Trigger; function ContextMenu({
const ContextMenuPortal = ContextMenuPrimitive.Portal; ...props
const ContextMenuSub = ContextMenuPrimitive.Sub; }: React.ComponentProps<typeof ContextMenuPrimitive.Root>) {
const ContextMenuGroup = ContextMenuPrimitive.Group; return <ContextMenuPrimitive.Root data-slot="context-menu" {...props} />
const ContextMenuRadioGroup = ContextMenuPrimitive.RadioGroup; }
const ContextMenu: Component<ContextMenuPrimitive.ContextMenuRootProps> = ( function ContextMenuTrigger({
props ...props
) => { }: React.ComponentProps<typeof ContextMenuPrimitive.Trigger>) {
return <ContextMenuPrimitive.Root gutter={4} {...props} />; return (
}; <ContextMenuPrimitive.Trigger data-slot="context-menu-trigger" {...props} />
)
}
type ContextMenuContentProps<T extends ValidComponent = 'div'> = function ContextMenuGroup({
ContextMenuPrimitive.ContextMenuContentProps<T> & { ...props
class?: string | undefined; }: React.ComponentProps<typeof ContextMenuPrimitive.Group>) {
}; return (
<ContextMenuPrimitive.Group data-slot="context-menu-group" {...props} />
)
}
const ContextMenuContent = <T extends ValidComponent = 'div'>( function ContextMenuPortal({
props: PolymorphicProps<T, ContextMenuContentProps<T>> ...props
) => { }: React.ComponentProps<typeof ContextMenuPrimitive.Portal>) {
const [local, others] = splitProps(props as ContextMenuContentProps, [ return (
'class', <ContextMenuPrimitive.Portal data-slot="context-menu-portal" {...props} />
]); )
}
function ContextMenuSub({
...props
}: React.ComponentProps<typeof ContextMenuPrimitive.Sub>) {
return <ContextMenuPrimitive.Sub data-slot="context-menu-sub" {...props} />
}
function ContextMenuRadioGroup({
...props
}: React.ComponentProps<typeof ContextMenuPrimitive.RadioGroup>) {
return (
<ContextMenuPrimitive.RadioGroup
data-slot="context-menu-radio-group"
{...props}
/>
)
}
function ContextMenuSubTrigger({
className,
inset,
children,
...props
}: React.ComponentProps<typeof ContextMenuPrimitive.SubTrigger> & {
inset?: boolean
}) {
return (
<ContextMenuPrimitive.SubTrigger
data-slot="context-menu-sub-trigger"
data-inset={inset}
className={cn(
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
>
{children}
<ChevronRightIcon className="ml-auto" />
</ContextMenuPrimitive.SubTrigger>
)
}
function ContextMenuSubContent({
className,
...props
}: React.ComponentProps<typeof ContextMenuPrimitive.SubContent>) {
return (
<ContextMenuPrimitive.SubContent
data-slot="context-menu-sub-content"
className={cn(
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
className
)}
{...props}
/>
)
}
function ContextMenuContent({
className,
...props
}: React.ComponentProps<typeof ContextMenuPrimitive.Content>) {
return ( return (
<ContextMenuPrimitive.Portal> <ContextMenuPrimitive.Portal>
<ContextMenuPrimitive.Content <ContextMenuPrimitive.Content
class={cn( data-slot="context-menu-content"
'z-50 min-w-32 origin-[var(--kb-menu-content-transform-origin)] animate-in overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md', className={cn(
local.class "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-context-menu-content-available-height) min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
className
)} )}
{...others} {...props}
/> />
</ContextMenuPrimitive.Portal> </ContextMenuPrimitive.Portal>
); )
}; }
type ContextMenuItemProps<T extends ValidComponent = 'div'> = function ContextMenuItem({
ContextMenuPrimitive.ContextMenuItemProps<T> & { className,
class?: string | undefined; inset,
}; variant = "default",
...props
const ContextMenuItem = <T extends ValidComponent = 'div'>( }: React.ComponentProps<typeof ContextMenuPrimitive.Item> & {
props: PolymorphicProps<T, ContextMenuItemProps<T>> inset?: boolean
) => { variant?: "default" | "destructive"
const [local, others] = splitProps(props as ContextMenuItemProps, ['class']); }) {
return ( return (
<ContextMenuPrimitive.Item <ContextMenuPrimitive.Item
class={cn( data-slot="context-menu-item"
'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50', data-inset={inset}
local.class data-variant={variant}
className={cn(
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)} )}
{...others} {...props}
/> />
); )
}; }
const ContextMenuShortcut: Component<ComponentProps<'span'>> = (props) => { function ContextMenuCheckboxItem({
const [local, others] = splitProps(props, ['class']); className,
return ( children,
<span checked,
class={cn('ml-auto text-xs tracking-widest opacity-60', local.class)} ...props
{...others} }: React.ComponentProps<typeof ContextMenuPrimitive.CheckboxItem>) {
/>
);
};
type ContextMenuSeparatorProps<T extends ValidComponent = 'hr'> =
ContextMenuPrimitive.ContextMenuSeparatorProps<T> & {
class?: string | undefined;
};
const ContextMenuSeparator = <T extends ValidComponent = 'hr'>(
props: PolymorphicProps<T, ContextMenuSeparatorProps<T>>
) => {
const [local, others] = splitProps(props as ContextMenuSeparatorProps, [
'class',
]);
return (
<ContextMenuPrimitive.Separator
class={cn('-mx-1 my-1 h-px bg-muted', local.class)}
{...others}
/>
);
};
type ContextMenuSubTriggerProps<T extends ValidComponent = 'div'> =
ContextMenuPrimitive.ContextMenuSubTriggerProps<T> & {
class?: string | undefined;
children?: JSX.Element;
};
const ContextMenuSubTrigger = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, ContextMenuSubTriggerProps<T>>
) => {
const [local, others] = splitProps(props as ContextMenuSubTriggerProps, [
'class',
'children',
]);
return (
<ContextMenuPrimitive.SubTrigger
class={cn(
'flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent',
local.class
)}
{...others}
>
{local.children}
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="ml-auto size-4"
>
<path d="M9 6l6 6l-6 6" />
</svg>
</ContextMenuPrimitive.SubTrigger>
);
};
type ContextMenuSubContentProps<T extends ValidComponent = 'div'> =
ContextMenuPrimitive.ContextMenuSubContentProps<T> & {
class?: string | undefined;
};
const ContextMenuSubContent = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, ContextMenuSubContentProps<T>>
) => {
const [local, others] = splitProps(props as ContextMenuSubContentProps, [
'class',
]);
return (
<ContextMenuPrimitive.SubContent
class={cn(
'z-50 min-w-32 origin-[var(--kb-menu-content-transform-origin)] animate-in overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md',
local.class
)}
{...others}
/>
);
};
type ContextMenuCheckboxItemProps<T extends ValidComponent = 'div'> =
ContextMenuPrimitive.ContextMenuCheckboxItemProps<T> & {
class?: string | undefined;
children?: JSX.Element;
};
const ContextMenuCheckboxItem = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, ContextMenuCheckboxItemProps<T>>
) => {
const [local, others] = splitProps(props as ContextMenuCheckboxItemProps, [
'class',
'children',
]);
return ( return (
<ContextMenuPrimitive.CheckboxItem <ContextMenuPrimitive.CheckboxItem
class={cn( data-slot="context-menu-checkbox-item"
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pr-2 pl-8 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50', className={cn(
local.class "focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)} )}
{...others} checked={checked}
{...props}
> >
<span class="absolute left-2 flex size-3.5 items-center justify-center"> <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
<ContextMenuPrimitive.ItemIndicator> <ContextMenuPrimitive.ItemIndicator>
<svg <CheckIcon className="size-4" />
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M5 12l5 5l10 -10" />
</svg>
</ContextMenuPrimitive.ItemIndicator> </ContextMenuPrimitive.ItemIndicator>
</span> </span>
{local.children} {children}
</ContextMenuPrimitive.CheckboxItem> </ContextMenuPrimitive.CheckboxItem>
); )
}; }
type ContextMenuGroupLabelProps<T extends ValidComponent = 'span'> = function ContextMenuRadioItem({
ContextMenuPrimitive.ContextMenuGroupLabelProps<T> & { className,
class?: string | undefined; children,
}; ...props
}: React.ComponentProps<typeof ContextMenuPrimitive.RadioItem>) {
const ContextMenuGroupLabel = <T extends ValidComponent = 'span'>(
props: PolymorphicProps<T, ContextMenuGroupLabelProps<T>>
) => {
const [local, others] = splitProps(props as ContextMenuGroupLabelProps, [
'class',
]);
return (
<ContextMenuPrimitive.GroupLabel
class={cn('px-2 py-1.5 font-semibold text-sm', local.class)}
{...others}
/>
);
};
type ContextMenuRadioItemProps<T extends ValidComponent = 'div'> =
ContextMenuPrimitive.ContextMenuRadioItemProps<T> & {
class?: string | undefined;
children?: JSX.Element;
};
const ContextMenuRadioItem = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, ContextMenuRadioItemProps<T>>
) => {
const [local, others] = splitProps(props as ContextMenuRadioItemProps, [
'class',
'children',
]);
return ( return (
<ContextMenuPrimitive.RadioItem <ContextMenuPrimitive.RadioItem
class={cn( data-slot="context-menu-radio-item"
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pr-2 pl-8 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50', className={cn(
local.class "focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)} )}
{...others} {...props}
> >
<span class="absolute left-2 flex size-3.5 items-center justify-center"> <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
<ContextMenuPrimitive.ItemIndicator> <ContextMenuPrimitive.ItemIndicator>
<svg <CircleIcon className="size-2 fill-current" />
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-2 fill-current"
>
<path d="M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" />
</svg>
</ContextMenuPrimitive.ItemIndicator> </ContextMenuPrimitive.ItemIndicator>
</span> </span>
{local.children} {children}
</ContextMenuPrimitive.RadioItem> </ContextMenuPrimitive.RadioItem>
); )
}; }
function ContextMenuLabel({
className,
inset,
...props
}: React.ComponentProps<typeof ContextMenuPrimitive.Label> & {
inset?: boolean
}) {
return (
<ContextMenuPrimitive.Label
data-slot="context-menu-label"
data-inset={inset}
className={cn(
"text-foreground px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
className
)}
{...props}
/>
)
}
function ContextMenuSeparator({
className,
...props
}: React.ComponentProps<typeof ContextMenuPrimitive.Separator>) {
return (
<ContextMenuPrimitive.Separator
data-slot="context-menu-separator"
className={cn("bg-border -mx-1 my-1 h-px", className)}
{...props}
/>
)
}
function ContextMenuShortcut({
className,
...props
}: React.ComponentProps<"span">) {
return (
<span
data-slot="context-menu-shortcut"
className={cn(
"text-muted-foreground ml-auto text-xs tracking-widest",
className
)}
{...props}
/>
)
}
export { export {
ContextMenu, ContextMenu,
ContextMenuTrigger, ContextMenuTrigger,
ContextMenuPortal,
ContextMenuContent, ContextMenuContent,
ContextMenuItem, ContextMenuItem,
ContextMenuShortcut,
ContextMenuSeparator,
ContextMenuSub,
ContextMenuSubTrigger,
ContextMenuSubContent,
ContextMenuCheckboxItem, ContextMenuCheckboxItem,
ContextMenuGroup,
ContextMenuGroupLabel,
ContextMenuRadioGroup,
ContextMenuRadioItem, ContextMenuRadioItem,
}; ContextMenuLabel,
ContextMenuSeparator,
ContextMenuShortcut,
ContextMenuGroup,
ContextMenuPortal,
ContextMenuSub,
ContextMenuSubContent,
ContextMenuSubTrigger,
ContextMenuRadioGroup,
}

View File

@ -1,301 +0,0 @@
import { Show, children, splitProps } from 'solid-js';
import { DatePicker as DatePickerPrimitive } from '@ark-ui/solid';
import { buttonVariants } from '~/components/ui/button';
import { cn } from '~/utils/styles';
const DatePicker = DatePickerPrimitive.Root;
const DatePickerLabel = DatePickerPrimitive.Label;
const DatePickerContext = DatePickerPrimitive.Context;
const DatePickerTableHead = DatePickerPrimitive.TableHead;
const DatePickerTableBody = DatePickerPrimitive.TableBody;
const DatePickerYearSelect = DatePickerPrimitive.YearSelect;
const DatePickerMonthSelect = DatePickerPrimitive.MonthSelect;
const DatePickerPositioner = DatePickerPrimitive.Positioner;
const DatePickerControl = (props: DatePickerPrimitive.ControlProps) => {
const [local, others] = splitProps(props, ['class']);
return (
<DatePickerPrimitive.Control
class={cn('inline-flex items-center gap-1', local.class)}
{...others}
/>
);
};
const DatePickerInput = (props: DatePickerPrimitive.InputProps) => {
const [local, others] = splitProps(props, ['class']);
return (
<DatePickerPrimitive.Input
class={cn(
'h-9 w-full rounded-md border border-border bg-background px-3 py-1 text-sm shadow-sm transition-shadow placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-[1.5px] focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
local.class
)}
{...others}
/>
);
};
const DatePickerTrigger = (props: DatePickerPrimitive.TriggerProps) => {
const [local, others] = splitProps(props, ['class', 'children']);
// prevents rendering children twice
const resolvedChildren = children(() => local.children);
const hasChildren = () => resolvedChildren.toArray().length !== 0;
return (
<DatePickerPrimitive.Trigger
class={cn(
'flex min-h-9 min-w-9 items-center justify-center rounded-md border border-border bg-background transition-[box-shadow,background-color] hover:bg-accent/50 focus-visible:outline-none focus-visible:ring-[1.5px] focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>svg]:size-4',
local.class
)}
{...others}
>
<Show when={!hasChildren()} fallback={resolvedChildren()}>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M4 7a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12z" />
<path d="M16 3v4" />
<path d="M8 3v4" />
<path d="M4 11h16" />
<path d="M11 15h1" />
<path d="M12 15v3" />
<title>Calendar</title>
</svg>
</Show>
</DatePickerPrimitive.Trigger>
);
};
const DatePickerContent = (props: DatePickerPrimitive.ContentProps) => {
const [local, others] = splitProps(props, ['class', 'children']);
return (
<DatePickerPrimitive.Content
class={cn(
'data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 z-50 rounded-md border bg-popover p-3 text-popover-foreground shadow-md outline-none data-[state=closed]:animate-out data-[state=open]:animate-in',
local.class
)}
{...others}
>
{local.children}
</DatePickerPrimitive.Content>
);
};
const DatePickerView = (props: DatePickerPrimitive.ViewProps) => {
const [local, others] = splitProps(props, ['class']);
return (
<DatePickerPrimitive.View
class={cn('space-y-4', local.class)}
{...others}
/>
);
};
const DatePickerViewControl = (props: DatePickerPrimitive.ViewControlProps) => {
const [local, others] = splitProps(props, ['class']);
return (
<DatePickerPrimitive.ViewControl
class={cn('flex items-center justify-between gap-4', local.class)}
{...others}
/>
);
};
const DatePickerPrevTrigger = (props: DatePickerPrimitive.PrevTriggerProps) => {
const [local, others] = splitProps(props, ['class', 'children']);
// prevents rendering children twice
const resolvedChildren = children(() => local.children);
const hasChildren = () => resolvedChildren.toArray().length !== 0;
return (
<DatePickerPrimitive.PrevTrigger
class={cn(
buttonVariants({
variant: 'outline',
}),
'size-7 bg-transparent p-0 opacity-50 hover:opacity-100',
local.class
)}
{...others}
>
<Show when={!hasChildren()} fallback={resolvedChildren()}>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M15 6l-6 6l6 6" />
<title>Previous</title>
</svg>
</Show>
</DatePickerPrimitive.PrevTrigger>
);
};
const DatePickerNextTrigger = (props: DatePickerPrimitive.NextTriggerProps) => {
const [local, others] = splitProps(props, ['class', 'children']);
// prevents rendering children twice
const resolvedChildren = children(() => local.children);
const hasChildren = () => resolvedChildren.toArray().length !== 0;
return (
<DatePickerPrimitive.NextTrigger
class={cn(
buttonVariants({
variant: 'outline',
}),
'size-7 bg-transparent p-0 opacity-50 hover:opacity-100',
local.class
)}
{...others}
>
<Show when={!hasChildren()} fallback={resolvedChildren()}>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M9 6l6 6l-6 6" />
<title>Next</title>
</svg>
</Show>
</DatePickerPrimitive.NextTrigger>
);
};
const DatePickerViewTrigger = (props: DatePickerPrimitive.ViewTriggerProps) => {
const [local, others] = splitProps(props, ['class']);
return (
<DatePickerPrimitive.ViewTrigger
class={cn(buttonVariants({ variant: 'ghost' }), 'h-7', local.class)}
{...others}
/>
);
};
const DatePickerRangeText = (props: DatePickerPrimitive.RangeTextProps) => {
const [local, others] = splitProps(props, ['class']);
return (
<DatePickerPrimitive.RangeText
class={cn('font-medium text-sm', local.class)}
{...others}
/>
);
};
const DatePickerTable = (props: DatePickerPrimitive.TableProps) => {
const [local, others] = splitProps(props, ['class']);
return (
<DatePickerPrimitive.Table
class={cn('w-full border-collapse space-y-1', local.class)}
{...others}
/>
);
};
const DatePickerTableRow = (props: DatePickerPrimitive.TableRowProps) => {
const [local, others] = splitProps(props, ['class']);
return (
<DatePickerPrimitive.TableRow
class={cn('mt-2 flex w-full', local.class)}
{...others}
/>
);
};
const DatePickerTableHeader = (props: DatePickerPrimitive.TableHeaderProps) => {
const [local, others] = splitProps(props, ['class']);
return (
<DatePickerPrimitive.TableHeader
class={cn(
'w-8 flex-1 font-normal text-[0.8rem] text-muted-foreground',
local.class
)}
{...others}
/>
);
};
const DatePickerTableCell = (props: DatePickerPrimitive.TableCellProps) => {
const [local, others] = splitProps(props, ['class']);
return (
<DatePickerPrimitive.TableCell
class={cn(
'flex-1 p-0 text-center text-sm has-[[data-range-end]]:rounded-r-md has-[[data-range-start]]:rounded-l-md has-[[data-in-range]]:bg-accent has-[[data-outside-range][data-in-range]]:bg-accent/50 has-[[data-in-range]]:last-of-type:rounded-r-md has-[[data-in-range]]:first-of-type:rounded-l-md',
local.class
)}
{...others}
/>
);
};
const DatePickerTableCellTrigger = (
props: DatePickerPrimitive.TableCellTriggerProps
) => {
const [local, others] = splitProps(props, ['class']);
return (
<DatePickerPrimitive.TableCellTrigger
class={cn(
buttonVariants({ variant: 'ghost' }),
'size-8 w-full p-0 font-normal data-[selected]:opacity-100',
'data-[today]:bg-accent data-[today]:text-accent-foreground',
'[&:is([data-today][data-selected])]:bg-primary [&:is([data-today][data-selected])]:text-primary-foreground',
'data-[selected]:bg-primary data-[selected]:text-primary-foreground data-[selected]:hover:bg-primary data-[selected]:hover:text-primary-foreground',
'data-[disabled]:text-muted-foreground data-[disabled]:opacity-50',
'data-[outside-range]:text-muted-foreground data-[outside-range]:opacity-50',
'[&:is([data-outside-range][data-in-range])]:bg-accent/50 [&:is([data-outside-range][data-in-range])]:text-muted-foreground [&:is([data-outside-range][data-in-range])]:opacity-30',
local.class
)}
{...others}
/>
);
};
export {
DatePicker,
DatePickerLabel,
DatePickerControl,
DatePickerInput,
DatePickerTrigger,
DatePickerContent,
DatePickerView,
DatePickerViewControl,
DatePickerPrevTrigger,
DatePickerNextTrigger,
DatePickerViewTrigger,
DatePickerRangeText,
DatePickerContext,
DatePickerTable,
DatePickerTableHead,
DatePickerTableBody,
DatePickerTableRow,
DatePickerTableHeader,
DatePickerTableCell,
DatePickerTableCellTrigger,
DatePickerYearSelect,
DatePickerMonthSelect,
DatePickerPositioner,
};

View File

@ -1,75 +0,0 @@
import {
type Component,
type ComponentProps,
Show,
mergeProps,
splitProps,
} from 'solid-js';
import { cn } from '~/utils/styles';
type DeltaBarProps = ComponentProps<'div'> & {
value: number;
isIncreasePositive?: boolean;
};
const DeltaBar: Component<DeltaBarProps> = (rawProps) => {
const props = mergeProps(
{
isIncreasePositive: true,
},
rawProps
);
const [local, others] = splitProps(props, [
'value',
'isIncreasePositive',
'class',
]);
return (
<div
class={cn(
'relative flex h-2 w-full items-center rounded-full bg-secondary',
local.class
)}
{...others}
>
<div class="flex h-full w-1/2 justify-end">
<Show when={local.value < 0}>
<div
class={cn(
'rounded-l-full',
(local.value > 0 && local.isIncreasePositive) ||
(local.value < 0 && !local.isIncreasePositive)
? 'bg-success-foreground'
: 'bg-error-foreground'
)}
style={{ width: `${Math.abs(local.value)}%` }}
/>
</Show>
</div>
<div
class={cn(
'z-10 h-4 w-1 rounded-full bg-primary ring-2 ring-background'
)}
/>
<div class="flex h-full w-1/2 justify-start">
<Show when={local.value > 0}>
<div
class={cn(
'rounded-r-full',
(local.value > 0 && local.isIncreasePositive) ||
(local.value < 0 && !local.isIncreasePositive)
? 'bg-success-foreground'
: 'bg-error-foreground'
)}
style={{ width: `${Math.abs(local.value)}%` }}
/>
</Show>
</div>
</div>
);
};
export type { DeltaBarProps };
export { DeltaBar };

View File

@ -1,157 +1,133 @@
import type { Component, ComponentProps, JSX, ValidComponent } from 'solid-js'; import * as React from "react"
import { splitProps } from 'solid-js'; import * as DialogPrimitive from "@radix-ui/react-dialog"
import { XIcon } from "lucide-react"
import * as DialogPrimitive from '@kobalte/core/dialog'; import { cn } from "@/styles/utils"
import type { PolymorphicProps } from '@kobalte/core/polymorphic';
import { cn } from '~/utils/styles'; function Dialog({
...props
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
return <DialogPrimitive.Root data-slot="dialog" {...props} />
}
const Dialog = DialogPrimitive.Root; function DialogTrigger({
const DialogTrigger = DialogPrimitive.Trigger; ...props
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
}
const DialogPortal: Component<DialogPrimitive.DialogPortalProps> = (props) => { function DialogPortal({
const [, rest] = splitProps(props, ['children']); ...props
return ( }: React.ComponentProps<typeof DialogPrimitive.Portal>) {
<DialogPrimitive.Portal {...rest}> return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
<div class="fixed inset-0 z-50 flex items-start justify-center sm:items-center"> }
{props.children}
</div>
</DialogPrimitive.Portal>
);
};
type DialogOverlayProps<T extends ValidComponent = 'div'> = function DialogClose({
DialogPrimitive.DialogOverlayProps<T> & { class?: string | undefined }; ...props
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
}
const DialogOverlay = <T extends ValidComponent = 'div'>( function DialogOverlay({
props: PolymorphicProps<T, DialogOverlayProps<T>> className,
) => { ...props
const [, rest] = splitProps(props as DialogOverlayProps, ['class']); }: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
return ( return (
<DialogPrimitive.Overlay <DialogPrimitive.Overlay
class={cn( data-slot="dialog-overlay"
'data-[closed]:fade-out-0 data-[expanded]:fade-in-0 fixed inset-0 z-50 bg-background/80 data-[closed]:animate-out data-[expanded]:animate-in', className={cn(
props.class "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
className
)} )}
{...rest} {...props}
/> />
); )
}; }
type DialogContentProps<T extends ValidComponent = 'div'> = function DialogContent({
DialogPrimitive.DialogContentProps<T> & { className,
class?: string | undefined; children,
children?: JSX.Element; ...props
}; }: React.ComponentProps<typeof DialogPrimitive.Content>) {
const DialogContent = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, DialogContentProps<T>>
) => {
const [, rest] = splitProps(props as DialogContentProps, [
'class',
'children',
]);
return ( return (
<DialogPortal> <DialogPortal data-slot="dialog-portal">
<DialogOverlay /> <DialogOverlay />
<DialogPrimitive.Content <DialogPrimitive.Content
class={cn( data-slot="dialog-content"
'-translate-x-1/2 -translate-y-1/2 data-[closed]:fade-out-0 data-[expanded]:fade-in-0 data-[closed]:zoom-out-95 data-[expanded]:zoom-in-95 data-[closed]:slide-out-to-left-1/2 data-[closed]:slide-out-to-top-[48%] data-[expanded]:slide-in-from-left-1/2 data-[expanded]:slide-in-from-top-[48%] fixed top-1/2 left-1/2 z-50 grid max-h-screen w-full max-w-lg gap-4 overflow-y-auto border bg-background p-6 shadow-lg duration-200 data-[closed]:animate-out data-[expanded]:animate-in sm:rounded-lg', className={cn(
props.class "bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",
className
)} )}
{...rest} {...props}
> >
{props.children} {children}
<DialogPrimitive.CloseButton class="absolute top-4 right-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[expanded]:bg-accent data-[expanded]:text-muted-foreground"> <DialogPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4">
<svg <XIcon />
xmlns="http://www.w3.org/2000/svg" <span className="sr-only">Close</span>
viewBox="0 0 24 24" </DialogPrimitive.Close>
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M18 6l-12 12" />
<path d="M6 6l12 12" />
</svg>
<span class="sr-only">Close</span>
</DialogPrimitive.CloseButton>
</DialogPrimitive.Content> </DialogPrimitive.Content>
</DialogPortal> </DialogPortal>
); )
}; }
const DialogHeader: Component<ComponentProps<'div'>> = (props) => { function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
const [, rest] = splitProps(props, ['class']);
return ( return (
<div <div
class={cn( data-slot="dialog-header"
'flex flex-col space-y-1.5 text-center sm:text-left', className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
props.class {...props}
)}
{...rest}
/> />
); )
}; }
const DialogFooter: Component<ComponentProps<'div'>> = (props) => { function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
const [, rest] = splitProps(props, ['class']);
return ( return (
<div <div
class={cn( data-slot="dialog-footer"
'flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2', className={cn(
props.class "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
className
)} )}
{...rest} {...props}
/> />
); )
}; }
type DialogTitleProps<T extends ValidComponent = 'h2'> = function DialogTitle({
DialogPrimitive.DialogTitleProps<T> & { className,
class?: string | undefined; ...props
}; }: React.ComponentProps<typeof DialogPrimitive.Title>) {
const DialogTitle = <T extends ValidComponent = 'h2'>(
props: PolymorphicProps<T, DialogTitleProps<T>>
) => {
const [, rest] = splitProps(props as DialogTitleProps, ['class']);
return ( return (
<DialogPrimitive.Title <DialogPrimitive.Title
class={cn( data-slot="dialog-title"
'font-semibold text-lg leading-none tracking-tight', className={cn("text-lg leading-none font-semibold", className)}
props.class {...props}
)}
{...rest}
/> />
); )
}; }
type DialogDescriptionProps<T extends ValidComponent = 'p'> = function DialogDescription({
DialogPrimitive.DialogDescriptionProps<T> & { className,
class?: string | undefined; ...props
}; }: React.ComponentProps<typeof DialogPrimitive.Description>) {
const DialogDescription = <T extends ValidComponent = 'p'>(
props: PolymorphicProps<T, DialogDescriptionProps<T>>
) => {
const [, rest] = splitProps(props as DialogDescriptionProps, ['class']);
return ( return (
<DialogPrimitive.Description <DialogPrimitive.Description
class={cn('text-muted-foreground text-sm', props.class)} data-slot="dialog-description"
{...rest} className={cn("text-muted-foreground text-sm", className)}
{...props}
/> />
); )
}; }
export { export {
Dialog, Dialog,
DialogTrigger, DialogClose,
DialogContent, DialogContent,
DialogHeader,
DialogFooter,
DialogTitle,
DialogDescription, DialogDescription,
}; DialogFooter,
DialogHeader,
DialogOverlay,
DialogPortal,
DialogTitle,
DialogTrigger,
}

View File

@ -1,129 +1,120 @@
import type { Component, ComponentProps, JSX, ValidComponent } from 'solid-js'; import * as React from "react"
import { splitProps } from 'solid-js'; import { Drawer as DrawerPrimitive } from "vaul"
import type { import { cn } from "@/styles/utils"
ContentProps,
DescriptionProps,
DynamicProps,
LabelProps,
OverlayProps,
} from '@corvu/drawer';
import DrawerPrimitive from '@corvu/drawer';
import { cn } from '~/utils/styles'; function Drawer({
...props
}: React.ComponentProps<typeof DrawerPrimitive.Root>) {
return <DrawerPrimitive.Root data-slot="drawer" {...props} />
}
const Drawer = DrawerPrimitive; function DrawerTrigger({
...props
}: React.ComponentProps<typeof DrawerPrimitive.Trigger>) {
return <DrawerPrimitive.Trigger data-slot="drawer-trigger" {...props} />
}
const DrawerTrigger = DrawerPrimitive.Trigger; function DrawerPortal({
...props
}: React.ComponentProps<typeof DrawerPrimitive.Portal>) {
return <DrawerPrimitive.Portal data-slot="drawer-portal" {...props} />
}
const DrawerPortal = DrawerPrimitive.Portal; function DrawerClose({
...props
}: React.ComponentProps<typeof DrawerPrimitive.Close>) {
return <DrawerPrimitive.Close data-slot="drawer-close" {...props} />
}
const DrawerClose = DrawerPrimitive.Close; function DrawerOverlay({
className,
type DrawerOverlayProps<T extends ValidComponent = 'div'> = OverlayProps<T> & { ...props
class?: string; }: React.ComponentProps<typeof DrawerPrimitive.Overlay>) {
};
const DrawerOverlay = <T extends ValidComponent = 'div'>(
props: DynamicProps<T, DrawerOverlayProps<T>>
) => {
const [, rest] = splitProps(props as DrawerOverlayProps, ['class']);
const drawerContext = DrawerPrimitive.useContext();
return ( return (
<DrawerPrimitive.Overlay <DrawerPrimitive.Overlay
class={cn( data-slot="drawer-overlay"
'fixed inset-0 z-50 data-[transitioning]:transition-colors data-[transitioning]:duration-300', className={cn(
props.class "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
className
)} )}
style={{ {...props}
'background-color': `rgb(0 0 0 / ${0.8 * drawerContext.openPercentage()})`,
}}
{...rest}
/> />
); )
}; }
type DrawerContentProps<T extends ValidComponent = 'div'> = ContentProps<T> & { function DrawerContent({
class?: string; className,
children?: JSX.Element; children,
}; ...props
}: React.ComponentProps<typeof DrawerPrimitive.Content>) {
const DrawerContent = <T extends ValidComponent = 'div'>(
props: DynamicProps<T, DrawerContentProps<T>>
) => {
const [, rest] = splitProps(props as DrawerContentProps, [
'class',
'children',
]);
return ( return (
<DrawerPortal> <DrawerPortal data-slot="drawer-portal">
<DrawerOverlay /> <DrawerOverlay />
<DrawerPrimitive.Content <DrawerPrimitive.Content
class={cn( data-slot="drawer-content"
'fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background after:absolute after:inset-x-0 after:top-full after:h-1/2 after:bg-inherit data-[transitioning]:transition-transform data-[transitioning]:duration-300 md:select-none', className={cn(
props.class "group/drawer-content bg-background fixed z-50 flex h-auto flex-col",
"data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[80vh] data-[vaul-drawer-direction=top]:rounded-b-lg data-[vaul-drawer-direction=top]:border-b",
"data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[80vh] data-[vaul-drawer-direction=bottom]:rounded-t-lg data-[vaul-drawer-direction=bottom]:border-t",
"data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:right-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=right]:border-l data-[vaul-drawer-direction=right]:sm:max-w-sm",
"data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:left-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=left]:border-r data-[vaul-drawer-direction=left]:sm:max-w-sm",
className
)} )}
{...rest} {...props}
> >
<div class="mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted" /> <div className="bg-muted mx-auto mt-4 hidden h-2 w-[100px] shrink-0 rounded-full group-data-[vaul-drawer-direction=bottom]/drawer-content:block" />
{props.children} {children}
</DrawerPrimitive.Content> </DrawerPrimitive.Content>
</DrawerPortal> </DrawerPortal>
); )
}; }
const DrawerHeader: Component<ComponentProps<'div'>> = (props) => { function DrawerHeader({ className, ...props }: React.ComponentProps<"div">) {
const [, rest] = splitProps(props, ['class']);
return ( return (
<div <div
class={cn('grid gap-1.5 p-4 text-center sm:text-left', props.class)} data-slot="drawer-header"
{...rest} className={cn("flex flex-col gap-1.5 p-4", className)}
{...props}
/> />
); )
}; }
const DrawerFooter: Component<ComponentProps<'div'>> = (props) => { function DrawerFooter({ className, ...props }: React.ComponentProps<"div">) {
const [, rest] = splitProps(props, ['class']);
return ( return (
<div class={cn('t-auto flex flex-col gap-2 p-4', props.class)} {...rest} /> <div
); data-slot="drawer-footer"
}; className={cn("mt-auto flex flex-col gap-2 p-4", className)}
{...props}
type DrawerTitleProps<T extends ValidComponent = 'div'> = LabelProps<T> & {
class?: string;
};
const DrawerTitle = <T extends ValidComponent = 'div'>(
props: DynamicProps<T, DrawerTitleProps<T>>
) => {
const [, rest] = splitProps(props as DrawerTitleProps, ['class']);
return (
<DrawerPrimitive.Label
class={cn(
'font-semibold text-lg leading-none tracking-tight',
props.class
)}
{...rest}
/> />
); )
}; }
type DrawerDescriptionProps<T extends ValidComponent = 'div'> = function DrawerTitle({
DescriptionProps<T> & { className,
class?: string; ...props
}; }: React.ComponentProps<typeof DrawerPrimitive.Title>) {
return (
<DrawerPrimitive.Title
data-slot="drawer-title"
className={cn("text-foreground font-semibold", className)}
{...props}
/>
)
}
const DrawerDescription = <T extends ValidComponent = 'div'>( function DrawerDescription({
props: DynamicProps<T, DrawerDescriptionProps<T>> className,
) => { ...props
const [, rest] = splitProps(props as DrawerDescriptionProps, ['class']); }: React.ComponentProps<typeof DrawerPrimitive.Description>) {
return ( return (
<DrawerPrimitive.Description <DrawerPrimitive.Description
class={cn('text-muted-foreground text-sm', props.class)} data-slot="drawer-description"
{...rest} className={cn("text-muted-foreground text-sm", className)}
{...props}
/> />
); )
}; }
export { export {
Drawer, Drawer,
@ -136,4 +127,4 @@ export {
DrawerFooter, DrawerFooter,
DrawerTitle, DrawerTitle,
DrawerDescription, DrawerDescription,
}; }

View File

@ -1,282 +1,257 @@
import type { Component, ComponentProps, JSX, ValidComponent } from 'solid-js'; "use client"
import { splitProps } from 'solid-js';
import * as DropdownMenuPrimitive from '@kobalte/core/dropdown-menu'; import * as React from "react"
import type { PolymorphicProps } from '@kobalte/core/polymorphic'; import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
import { cn } from '~/utils/styles'; import { cn } from "@/styles/utils"
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger; function DropdownMenu({
const DropdownMenuPortal = DropdownMenuPrimitive.Portal; ...props
const DropdownMenuSub = DropdownMenuPrimitive.Sub; }: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
const DropdownMenuGroup = DropdownMenuPrimitive.Group; return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />
const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup; }
const DropdownMenu: Component<DropdownMenuPrimitive.DropdownMenuRootProps> = ( function DropdownMenuPortal({
props ...props
) => { }: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
return <DropdownMenuPrimitive.Root gutter={4} {...props} />; return (
}; <DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
)
}
type DropdownMenuContentProps<T extends ValidComponent = 'div'> = function DropdownMenuTrigger({
DropdownMenuPrimitive.DropdownMenuContentProps<T> & { ...props
class?: string | undefined; }: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
}; return (
<DropdownMenuPrimitive.Trigger
data-slot="dropdown-menu-trigger"
{...props}
/>
)
}
const DropdownMenuContent = <T extends ValidComponent = 'div'>( function DropdownMenuContent({
props: PolymorphicProps<T, DropdownMenuContentProps<T>> className,
) => { sideOffset = 4,
const [, rest] = splitProps(props as DropdownMenuContentProps, ['class']); ...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
return ( return (
<DropdownMenuPrimitive.Portal> <DropdownMenuPrimitive.Portal>
<DropdownMenuPrimitive.Content <DropdownMenuPrimitive.Content
class={cn( data-slot="dropdown-menu-content"
'z-50 min-w-32 origin-[var(--kb-menu-content-transform-origin)] animate-content-hide overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[expanded]:animate-content-show', sideOffset={sideOffset}
props.class className={cn(
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
className
)} )}
{...rest} {...props}
/> />
</DropdownMenuPrimitive.Portal> </DropdownMenuPrimitive.Portal>
); )
}; }
type DropdownMenuItemProps<T extends ValidComponent = 'div'> = function DropdownMenuGroup({
DropdownMenuPrimitive.DropdownMenuItemProps<T> & { ...props
class?: string | undefined; }: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
}; return (
<DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
)
}
const DropdownMenuItem = <T extends ValidComponent = 'div'>( function DropdownMenuItem({
props: PolymorphicProps<T, DropdownMenuItemProps<T>> className,
) => { inset,
const [, rest] = splitProps(props as DropdownMenuItemProps, ['class']); variant = "default",
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
inset?: boolean
variant?: "default" | "destructive"
}) {
return ( return (
<DropdownMenuPrimitive.Item <DropdownMenuPrimitive.Item
class={cn( data-slot="dropdown-menu-item"
'relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50', data-inset={inset}
props.class data-variant={variant}
className={cn(
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)} )}
{...rest} {...props}
/> />
); )
}; }
const DropdownMenuShortcut: Component<ComponentProps<'span'>> = (props) => { function DropdownMenuCheckboxItem({
const [, rest] = splitProps(props, ['class']); className,
return ( children,
<span checked,
class={cn('ml-auto text-xs tracking-widest opacity-60', props.class)} ...props
{...rest} }: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {
/>
);
};
const DropdownMenuLabel: Component<
ComponentProps<'div'> & { inset?: boolean }
> = (props) => {
const [, rest] = splitProps(props, ['class', 'inset']);
return (
<div
class={cn(
'px-2 py-1.5 font-semibold text-sm',
props.inset && 'pl-8',
props.class
)}
{...rest}
/>
);
};
type DropdownMenuSeparatorProps<T extends ValidComponent = 'hr'> =
DropdownMenuPrimitive.DropdownMenuSeparatorProps<T> & {
class?: string | undefined;
};
const DropdownMenuSeparator = <T extends ValidComponent = 'hr'>(
props: PolymorphicProps<T, DropdownMenuSeparatorProps<T>>
) => {
const [, rest] = splitProps(props as DropdownMenuSeparatorProps, ['class']);
return (
<DropdownMenuPrimitive.Separator
class={cn('-mx-1 my-1 h-px bg-muted', props.class)}
{...rest}
/>
);
};
type DropdownMenuSubTriggerProps<T extends ValidComponent = 'div'> =
DropdownMenuPrimitive.DropdownMenuSubTriggerProps<T> & {
class?: string | undefined;
children?: JSX.Element;
};
const DropdownMenuSubTrigger = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, DropdownMenuSubTriggerProps<T>>
) => {
const [, rest] = splitProps(props as DropdownMenuSubTriggerProps, [
'class',
'children',
]);
return (
<DropdownMenuPrimitive.SubTrigger
class={cn(
'flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent',
props.class
)}
{...rest}
>
{props.children}
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="ml-auto size-4"
>
<path d="M9 6l6 6l-6 6" />
</svg>
</DropdownMenuPrimitive.SubTrigger>
);
};
type DropdownMenuSubContentProps<T extends ValidComponent = 'div'> =
DropdownMenuPrimitive.DropdownMenuSubContentProps<T> & {
class?: string | undefined;
};
const DropdownMenuSubContent = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, DropdownMenuSubContentProps<T>>
) => {
const [, rest] = splitProps(props as DropdownMenuSubContentProps, ['class']);
return (
<DropdownMenuPrimitive.SubContent
class={cn(
'z-50 min-w-32 origin-[var(--kb-menu-content-transform-origin)] animate-in overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md',
props.class
)}
{...rest}
/>
);
};
type DropdownMenuCheckboxItemProps<T extends ValidComponent = 'div'> =
DropdownMenuPrimitive.DropdownMenuCheckboxItemProps<T> & {
class?: string | undefined;
children?: JSX.Element;
};
const DropdownMenuCheckboxItem = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, DropdownMenuCheckboxItemProps<T>>
) => {
const [, rest] = splitProps(props as DropdownMenuCheckboxItemProps, [
'class',
'children',
]);
return ( return (
<DropdownMenuPrimitive.CheckboxItem <DropdownMenuPrimitive.CheckboxItem
class={cn( data-slot="dropdown-menu-checkbox-item"
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pr-2 pl-8 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50', className={cn(
props.class "focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)} )}
{...rest} checked={checked}
{...props}
> >
<span class="absolute left-2 flex size-3.5 items-center justify-center"> <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
<DropdownMenuPrimitive.ItemIndicator> <DropdownMenuPrimitive.ItemIndicator>
<svg <CheckIcon className="size-4" />
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M5 12l5 5l10 -10" />
</svg>
</DropdownMenuPrimitive.ItemIndicator> </DropdownMenuPrimitive.ItemIndicator>
</span> </span>
{props.children} {children}
</DropdownMenuPrimitive.CheckboxItem> </DropdownMenuPrimitive.CheckboxItem>
); )
}; }
type DropdownMenuGroupLabelProps<T extends ValidComponent = 'span'> = function DropdownMenuRadioGroup({
DropdownMenuPrimitive.DropdownMenuGroupLabelProps<T> & { ...props
class?: string | undefined; }: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
};
const DropdownMenuGroupLabel = <T extends ValidComponent = 'span'>(
props: PolymorphicProps<T, DropdownMenuGroupLabelProps<T>>
) => {
const [, rest] = splitProps(props as DropdownMenuGroupLabelProps, ['class']);
return ( return (
<DropdownMenuPrimitive.GroupLabel <DropdownMenuPrimitive.RadioGroup
class={cn('px-2 py-1.5 font-semibold text-sm', props.class)} data-slot="dropdown-menu-radio-group"
{...rest} {...props}
/> />
); )
}; }
type DropdownMenuRadioItemProps<T extends ValidComponent = 'div'> = function DropdownMenuRadioItem({
DropdownMenuPrimitive.DropdownMenuRadioItemProps<T> & { className,
class?: string | undefined; children,
children?: JSX.Element; ...props
}; }: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {
const DropdownMenuRadioItem = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, DropdownMenuRadioItemProps<T>>
) => {
const [, rest] = splitProps(props as DropdownMenuRadioItemProps, [
'class',
'children',
]);
return ( return (
<DropdownMenuPrimitive.RadioItem <DropdownMenuPrimitive.RadioItem
class={cn( data-slot="dropdown-menu-radio-item"
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pr-2 pl-8 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50', className={cn(
props.class "focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)} )}
{...rest} {...props}
> >
<span class="absolute left-2 flex size-3.5 items-center justify-center"> <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
<DropdownMenuPrimitive.ItemIndicator> <DropdownMenuPrimitive.ItemIndicator>
<svg <CircleIcon className="size-2 fill-current" />
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-2 fill-current"
>
<path d="M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" />
</svg>
</DropdownMenuPrimitive.ItemIndicator> </DropdownMenuPrimitive.ItemIndicator>
</span> </span>
{props.children} {children}
</DropdownMenuPrimitive.RadioItem> </DropdownMenuPrimitive.RadioItem>
); )
}; }
function DropdownMenuLabel({
className,
inset,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
inset?: boolean
}) {
return (
<DropdownMenuPrimitive.Label
data-slot="dropdown-menu-label"
data-inset={inset}
className={cn(
"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
className
)}
{...props}
/>
)
}
function DropdownMenuSeparator({
className,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
return (
<DropdownMenuPrimitive.Separator
data-slot="dropdown-menu-separator"
className={cn("bg-border -mx-1 my-1 h-px", className)}
{...props}
/>
)
}
function DropdownMenuShortcut({
className,
...props
}: React.ComponentProps<"span">) {
return (
<span
data-slot="dropdown-menu-shortcut"
className={cn(
"text-muted-foreground ml-auto text-xs tracking-widest",
className
)}
{...props}
/>
)
}
function DropdownMenuSub({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />
}
function DropdownMenuSubTrigger({
className,
inset,
children,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
inset?: boolean
}) {
return (
<DropdownMenuPrimitive.SubTrigger
data-slot="dropdown-menu-sub-trigger"
data-inset={inset}
className={cn(
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8",
className
)}
{...props}
>
{children}
<ChevronRightIcon className="ml-auto size-4" />
</DropdownMenuPrimitive.SubTrigger>
)
}
function DropdownMenuSubContent({
className,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
return (
<DropdownMenuPrimitive.SubContent
data-slot="dropdown-menu-sub-content"
className={cn(
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
className
)}
{...props}
/>
)
}
export { export {
DropdownMenu, DropdownMenu,
DropdownMenuTrigger,
DropdownMenuPortal, DropdownMenuPortal,
DropdownMenuTrigger,
DropdownMenuContent, DropdownMenuContent,
DropdownMenuItem, DropdownMenuGroup,
DropdownMenuShortcut,
DropdownMenuLabel, DropdownMenuLabel,
DropdownMenuItem,
DropdownMenuCheckboxItem,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator, DropdownMenuSeparator,
DropdownMenuShortcut,
DropdownMenuSub, DropdownMenuSub,
DropdownMenuSubTrigger, DropdownMenuSubTrigger,
DropdownMenuSubContent, DropdownMenuSubContent,
DropdownMenuCheckboxItem, }
DropdownMenuGroup,
DropdownMenuGroupLabel,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
};

View File

@ -1,76 +0,0 @@
import type { Component, ComponentProps } from 'solid-js';
import { mergeProps, splitProps } from 'solid-js';
import { cn } from '~/utils/styles';
type JustifyContent =
| 'start'
| 'end'
| 'center'
| 'between'
| 'around'
| 'evenly';
type AlignItems = 'start' | 'end' | 'center' | 'baseline' | 'stretch';
type FlexDirection = 'row' | 'col' | 'row-reverse' | 'col-reverse';
type FlexProps = ComponentProps<'div'> & {
flexDirection?: FlexDirection;
justifyContent?: JustifyContent;
alignItems?: AlignItems;
};
const Flex: Component<FlexProps> = (rawProps) => {
const props = mergeProps(
{
flexDirection: 'row',
justifyContent: 'between',
alignItems: 'center',
} satisfies FlexProps,
rawProps
);
const [local, others] = splitProps(props, [
'flexDirection',
'justifyContent',
'alignItems',
'class',
]);
return (
<div
class={cn(
'flex w-full',
flexDirectionClassNames[local.flexDirection],
justifyContentClassNames[local.justifyContent],
alignItemsClassNames[local.alignItems],
local.class
)}
{...others}
/>
);
};
export { Flex };
const justifyContentClassNames: { [key in JustifyContent]: string } = {
start: 'justify-start',
end: 'justify-end',
center: 'justify-center',
between: 'justify-between',
around: 'justify-around',
evenly: 'justify-evenly',
};
const alignItemsClassNames: { [key in AlignItems]: string } = {
start: 'items-start',
end: 'items-end',
center: 'items-center',
baseline: 'items-baseline',
stretch: 'items-stretch',
};
const flexDirectionClassNames: { [key in FlexDirection]: string } = {
row: 'flex-row',
col: 'flex-col',
'row-reverse': 'flex-row-reverse',
'col-reverse': 'flex-col-reverse',
};

View File

@ -0,0 +1,165 @@
import * as React from "react"
import * as LabelPrimitive from "@radix-ui/react-label"
import { Slot } from "@radix-ui/react-slot"
import {
Controller,
FormProvider,
useFormContext,
useFormState,
type ControllerProps,
type FieldPath,
type FieldValues,
} from "react-hook-form"
import { cn } from "@/styles/utils"
import { Label } from "@/components/ui/label"
const Form = FormProvider
type FormFieldContextValue<
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
> = {
name: TName
}
const FormFieldContext = React.createContext<FormFieldContextValue>(
{} as FormFieldContextValue
)
const FormField = <
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
>({
...props
}: ControllerProps<TFieldValues, TName>) => {
return (
<FormFieldContext.Provider value={{ name: props.name }}>
<Controller {...props} />
</FormFieldContext.Provider>
)
}
const useFormField = () => {
const fieldContext = React.useContext(FormFieldContext)
const itemContext = React.useContext(FormItemContext)
const { getFieldState } = useFormContext()
const formState = useFormState({ name: fieldContext.name })
const fieldState = getFieldState(fieldContext.name, formState)
if (!fieldContext) {
throw new Error("useFormField should be used within <FormField>")
}
const { id } = itemContext
return {
id,
name: fieldContext.name,
formItemId: `${id}-form-item`,
formDescriptionId: `${id}-form-item-description`,
formMessageId: `${id}-form-item-message`,
...fieldState,
}
}
type FormItemContextValue = {
id: string
}
const FormItemContext = React.createContext<FormItemContextValue>(
{} as FormItemContextValue
)
function FormItem({ className, ...props }: React.ComponentProps<"div">) {
const id = React.useId()
return (
<FormItemContext.Provider value={{ id }}>
<div
data-slot="form-item"
className={cn("grid gap-2", className)}
{...props}
/>
</FormItemContext.Provider>
)
}
function FormLabel({
className,
...props
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
const { error, formItemId } = useFormField()
return (
<Label
data-slot="form-label"
data-error={!!error}
className={cn("data-[error=true]:text-destructive", className)}
htmlFor={formItemId}
{...props}
/>
)
}
function FormControl({ ...props }: React.ComponentProps<typeof Slot>) {
const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
return (
<Slot
data-slot="form-control"
id={formItemId}
aria-describedby={
!error
? `${formDescriptionId}`
: `${formDescriptionId} ${formMessageId}`
}
aria-invalid={!!error}
{...props}
/>
)
}
function FormDescription({ className, ...props }: React.ComponentProps<"p">) {
const { formDescriptionId } = useFormField()
return (
<p
data-slot="form-description"
id={formDescriptionId}
className={cn("text-muted-foreground text-sm", className)}
{...props}
/>
)
}
function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
const { error, formMessageId } = useFormField()
const body = error ? String(error?.message ?? "") : props.children
if (!body) {
return null
}
return (
<p
data-slot="form-message"
id={formMessageId}
className={cn("text-destructive text-sm", className)}
{...props}
>
{body}
</p>
)
}
export {
useFormField,
Form,
FormItem,
FormLabel,
FormControl,
FormDescription,
FormMessage,
FormField,
}

View File

@ -1,200 +0,0 @@
import type { Component, ComponentProps } from 'solid-js';
import { mergeProps, splitProps } from 'solid-js';
import { cn } from '~/utils/styles';
type Cols = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
type Span = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13;
type GridProps = ComponentProps<'div'> & {
cols?: Cols;
colsSm?: Cols;
colsMd?: Cols;
colsLg?: Cols;
};
const Grid: Component<GridProps> = (rawProps) => {
const props = mergeProps({ cols: 1 } satisfies GridProps, rawProps);
const [local, others] = splitProps(props, [
'cols',
'colsSm',
'colsMd',
'colsLg',
'class',
]);
return (
<div
class={cn(
'grid',
gridCols[local.cols],
local.colsSm && gridColsSm[local.colsSm],
local.colsMd && gridColsMd[local.colsMd],
local.colsLg && gridColsLg[local.colsLg],
local.class
)}
{...others}
/>
);
};
type ColProps = ComponentProps<'div'> & {
span?: Span;
spanSm?: Span;
spanMd?: Span;
spanLg?: Span;
};
const Col: Component<ColProps> = (rawProps) => {
const props = mergeProps({ span: 1 as Span }, rawProps);
const [local, others] = splitProps(props, [
'span',
'spanSm',
'spanMd',
'spanLg',
'class',
]);
return (
<div
class={cn(
colSpan[local.span],
local.spanSm && colSpanSm[local.spanSm],
local.spanMd && colSpanMd[local.spanMd],
local.spanLg && colSpanLg[local.spanLg],
local.class
)}
{...others}
/>
);
};
export { Grid, Col };
const gridCols: { [key in Cols]: string } = {
0: 'grid-cols-none',
1: 'grid-cols-1',
2: 'grid-cols-2',
3: 'grid-cols-3',
4: 'grid-cols-4',
5: 'grid-cols-5',
6: 'grid-cols-6',
7: 'grid-cols-7',
8: 'grid-cols-8',
9: 'grid-cols-9',
10: 'grid-cols-10',
11: 'grid-cols-11',
12: 'grid-cols-12',
};
const gridColsSm: { [key in Cols]: string } = {
0: 'sm:grid-cols-none',
1: 'sm:grid-cols-1',
2: 'sm:grid-cols-2',
3: 'sm:grid-cols-3',
4: 'sm:grid-cols-4',
5: 'sm:grid-cols-5',
6: 'sm:grid-cols-6',
7: 'sm:grid-cols-7',
8: 'sm:grid-cols-8',
9: 'sm:grid-cols-9',
10: 'sm:grid-cols-10',
11: 'sm:grid-cols-11',
12: 'sm:grid-cols-12',
};
const gridColsMd: { [key in Cols]: string } = {
0: 'md:grid-cols-none',
1: 'md:grid-cols-1',
2: 'md:grid-cols-2',
3: 'md:grid-cols-3',
4: 'md:grid-cols-4',
5: 'md:grid-cols-5',
6: 'md:grid-cols-6',
7: 'md:grid-cols-7',
8: 'md:grid-cols-8',
9: 'md:grid-cols-9',
10: 'md:grid-cols-10',
11: 'md:grid-cols-11',
12: 'md:grid-cols-12',
};
const gridColsLg: { [key in Cols]: string } = {
0: 'lg:grid-cols-none',
1: 'lg:grid-cols-1',
2: 'lg:grid-cols-2',
3: 'lg:grid-cols-3',
4: 'lg:grid-cols-4',
5: 'lg:grid-cols-5',
6: 'lg:grid-cols-6',
7: 'lg:grid-cols-7',
8: 'lg:grid-cols-8',
9: 'lg:grid-cols-9',
10: 'lg:grid-cols-10',
11: 'lg:grid-cols-11',
12: 'lg:grid-cols-12',
};
const colSpan: { [key in Span]: string } = {
1: 'col-span-1',
2: 'col-span-2',
3: 'col-span-3',
4: 'col-span-4',
5: 'col-span-5',
6: 'col-span-6',
7: 'col-span-7',
8: 'col-span-8',
9: 'col-span-9',
10: 'col-span-10',
11: 'col-span-11',
12: 'col-span-12',
13: 'col-span-13',
};
const colSpanSm: { [key in Span]: string } = {
1: 'sm:col-span-1',
2: 'sm:col-span-2',
3: 'sm:col-span-3',
4: 'sm:col-span-4',
5: 'sm:col-span-5',
6: 'sm:col-span-6',
7: 'sm:col-span-7',
8: 'sm:col-span-8',
9: 'sm:col-span-9',
10: 'sm:col-span-10',
11: 'sm:col-span-11',
12: 'sm:col-span-12',
13: 'sm:col-span-13',
};
const colSpanMd: { [key in Span]: string } = {
1: 'md:col-span-1',
2: 'md:col-span-2',
3: 'md:col-span-3',
4: 'md:col-span-4',
5: 'md:col-span-5',
6: 'md:col-span-6',
7: 'md:col-span-7',
8: 'md:col-span-8',
9: 'md:col-span-9',
10: 'md:col-span-10',
11: 'md:col-span-11',
12: 'md:col-span-12',
13: 'md:col-span-13',
};
const colSpanLg: { [key in Span]: string } = {
1: 'lg:col-span-1',
2: 'lg:col-span-2',
3: 'lg:col-span-3',
4: 'lg:col-span-4',
5: 'lg:col-span-5',
6: 'lg:col-span-6',
7: 'lg:col-span-7',
8: 'lg:col-span-8',
9: 'lg:col-span-9',
10: 'lg:col-span-10',
11: 'lg:col-span-11',
12: 'lg:col-span-12',
13: 'lg:col-span-13',
};

View File

@ -1,37 +1,42 @@
import type { Component, ValidComponent } from 'solid-js'; import * as React from "react"
import { splitProps } from 'solid-js'; import * as HoverCardPrimitive from "@radix-ui/react-hover-card"
import * as HoverCardPrimitive from '@kobalte/core/hover-card'; import { cn } from "@/styles/utils"
import type { PolymorphicProps } from '@kobalte/core/polymorphic';
import { cn } from '~/utils/styles'; function HoverCard({
...props
}: React.ComponentProps<typeof HoverCardPrimitive.Root>) {
return <HoverCardPrimitive.Root data-slot="hover-card" {...props} />
}
const HoverCardTrigger = HoverCardPrimitive.Trigger; function HoverCardTrigger({
...props
const HoverCard: Component<HoverCardPrimitive.HoverCardRootProps> = (props) => { }: React.ComponentProps<typeof HoverCardPrimitive.Trigger>) {
return <HoverCardPrimitive.Root gutter={4} {...props} />;
};
type HoverCardContentProps<T extends ValidComponent = 'div'> =
HoverCardPrimitive.HoverCardContentProps<T> & {
class?: string | undefined;
};
const HoverCardContent = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, HoverCardContentProps<T>>
) => {
const [local, others] = splitProps(props as HoverCardContentProps, ['class']);
return ( return (
<HoverCardPrimitive.Portal> <HoverCardPrimitive.Trigger data-slot="hover-card-trigger" {...props} />
)
}
function HoverCardContent({
className,
align = "center",
sideOffset = 4,
...props
}: React.ComponentProps<typeof HoverCardPrimitive.Content>) {
return (
<HoverCardPrimitive.Portal data-slot="hover-card-portal">
<HoverCardPrimitive.Content <HoverCardPrimitive.Content
class={cn( data-slot="hover-card-content"
'data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=closed]:animate-out data-[state=open]:animate-in', align={align}
local.class sideOffset={sideOffset}
className={cn(
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-64 origin-(--radix-hover-card-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
className
)} )}
{...others} {...props}
/> />
</HoverCardPrimitive.Portal> </HoverCardPrimitive.Portal>
); )
}; }
export { HoverCard, HoverCardTrigger, HoverCardContent }; export { HoverCard, HoverCardTrigger, HoverCardContent }

View File

@ -0,0 +1,9 @@
import type { ComponentProps } from 'react';
export type ImageProps = Omit<ComponentProps<'img'>, 'alt'> &
Required<Pick<ComponentProps<'img'>, 'alt'>>;
export const Image = (props: ImageProps) => {
// biome-ignore lint/nursery/noImgElement: <explanation>
return <img {...props} alt={props.alt} />;
};

View File

@ -0,0 +1,77 @@
"use client"
import * as React from "react"
import { OTPInput, OTPInputContext } from "input-otp"
import { MinusIcon } from "lucide-react"
import { cn } from "@/styles/utils"
function InputOTP({
className,
containerClassName,
...props
}: React.ComponentProps<typeof OTPInput> & {
containerClassName?: string
}) {
return (
<OTPInput
data-slot="input-otp"
containerClassName={cn(
"flex items-center gap-2 has-disabled:opacity-50",
containerClassName
)}
className={cn("disabled:cursor-not-allowed", className)}
{...props}
/>
)
}
function InputOTPGroup({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="input-otp-group"
className={cn("flex items-center", className)}
{...props}
/>
)
}
function InputOTPSlot({
index,
className,
...props
}: React.ComponentProps<"div"> & {
index: number
}) {
const inputOTPContext = React.useContext(OTPInputContext)
const { char, hasFakeCaret, isActive } = inputOTPContext?.slots[index] ?? {}
return (
<div
data-slot="input-otp-slot"
data-active={isActive}
className={cn(
"data-[active=true]:border-ring data-[active=true]:ring-ring/50 data-[active=true]:aria-invalid:ring-destructive/20 dark:data-[active=true]:aria-invalid:ring-destructive/40 aria-invalid:border-destructive data-[active=true]:aria-invalid:border-destructive dark:bg-input/30 border-input relative flex h-9 w-9 items-center justify-center border-y border-r text-sm shadow-xs transition-all outline-none first:rounded-l-md first:border-l last:rounded-r-md data-[active=true]:z-10 data-[active=true]:ring-[3px]",
className
)}
{...props}
>
{char}
{hasFakeCaret && (
<div className="pointer-events-none absolute inset-0 flex items-center justify-center">
<div className="animate-caret-blink bg-foreground h-4 w-px duration-1000" />
</div>
)}
</div>
)
}
function InputOTPSeparator({ ...props }: React.ComponentProps<"div">) {
return (
<div data-slot="input-otp-separator" role="separator" {...props}>
<MinusIcon />
</div>
)
}
export { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator }

View File

@ -0,0 +1,21 @@
import * as React from "react"
import { cn } from "@/styles/utils"
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
return (
<input
type={type}
data-slot="input"
className={cn(
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
className
)}
{...props}
/>
)
}
export { Input }

View File

@ -1,19 +1,24 @@
import type { Component, ComponentProps } from 'solid-js'; "use client"
import { splitProps } from 'solid-js';
import { cn } from '~/utils/styles'; import * as React from "react"
import * as LabelPrimitive from "@radix-ui/react-label"
const Label: Component<ComponentProps<'label'>> = (props) => { import { cn } from "@/styles/utils"
const [local, others] = splitProps(props, ['class']);
function Label({
className,
...props
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
return ( return (
<label <LabelPrimitive.Root
class={cn( data-slot="label"
'font-medium text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70', className={cn(
local.class "flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
className
)} )}
{...others} {...props}
/> />
); )
}; }
export { Label }; export { Label }

View File

@ -1,346 +1,274 @@
import type { Component, ComponentProps, JSX, ValidComponent } from 'solid-js'; import * as React from "react"
import { splitProps } from 'solid-js'; import * as MenubarPrimitive from "@radix-ui/react-menubar"
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
import * as MenubarPrimitive from '@kobalte/core/menubar'; import { cn } from "@/styles/utils"
import type { PolymorphicProps } from '@kobalte/core/polymorphic';
import { cn } from '~/utils/styles'; function Menubar({
className,
const MenubarGroup = MenubarPrimitive.Group; ...props
const MenubarPortal = MenubarPrimitive.Portal; }: React.ComponentProps<typeof MenubarPrimitive.Root>) {
const MenubarSub = MenubarPrimitive.Sub;
const MenubarRadioGroup = MenubarPrimitive.RadioGroup;
type MenubarRootProps<T extends ValidComponent = 'div'> =
MenubarPrimitive.MenubarRootProps<T> & {
class?: string | undefined;
};
const Menubar = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, MenubarRootProps<T>>
) => {
const [local, others] = splitProps(props as MenubarRootProps, ['class']);
return ( return (
<MenubarPrimitive.Root <MenubarPrimitive.Root
class={cn( data-slot="menubar"
'flex h-10 items-center space-x-1 rounded-md border bg-background p-1', className={cn(
local.class "bg-background flex h-9 items-center gap-1 rounded-md border p-1 shadow-xs",
className
)} )}
{...others} {...props}
/> />
); )
}; }
const MenubarMenu: Component<MenubarPrimitive.MenubarMenuProps> = (props) => { function MenubarMenu({
return <MenubarPrimitive.Menu gutter={8} {...props} />; ...props
}; }: React.ComponentProps<typeof MenubarPrimitive.Menu>) {
return <MenubarPrimitive.Menu data-slot="menubar-menu" {...props} />
}
type MenubarTriggerProps<T extends ValidComponent = 'button'> = function MenubarGroup({
MenubarPrimitive.MenubarTriggerProps<T> & { class?: string | undefined }; ...props
}: React.ComponentProps<typeof MenubarPrimitive.Group>) {
return <MenubarPrimitive.Group data-slot="menubar-group" {...props} />
}
const MenubarTrigger = <T extends ValidComponent = 'button'>( function MenubarPortal({
props: PolymorphicProps<T, MenubarTriggerProps<T>> ...props
) => { }: React.ComponentProps<typeof MenubarPrimitive.Portal>) {
const [local, others] = splitProps(props as MenubarTriggerProps, ['class']); return <MenubarPrimitive.Portal data-slot="menubar-portal" {...props} />
}
function MenubarRadioGroup({
...props
}: React.ComponentProps<typeof MenubarPrimitive.RadioGroup>) {
return (
<MenubarPrimitive.RadioGroup data-slot="menubar-radio-group" {...props} />
)
}
function MenubarTrigger({
className,
...props
}: React.ComponentProps<typeof MenubarPrimitive.Trigger>) {
return ( return (
<MenubarPrimitive.Trigger <MenubarPrimitive.Trigger
class={cn( data-slot="menubar-trigger"
'flex cursor-default select-none items-center rounded-sm px-3 py-1.5 font-medium text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground', className={cn(
local.class "focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex items-center rounded-sm px-2 py-1 text-sm font-medium outline-hidden select-none",
className
)} )}
{...others} {...props}
/> />
); )
}; }
type MenubarContentProps<T extends ValidComponent = 'div'> = function MenubarContent({
MenubarPrimitive.MenubarContentProps<T> & { class?: string | undefined }; className,
align = "start",
const MenubarContent = <T extends ValidComponent = 'div'>( alignOffset = -4,
props: PolymorphicProps<T, MenubarContentProps<T>> sideOffset = 8,
) => { ...props
const [local, others] = splitProps(props as MenubarContentProps, ['class']); }: React.ComponentProps<typeof MenubarPrimitive.Content>) {
return ( return (
<MenubarPrimitive.Portal> <MenubarPortal>
<MenubarPrimitive.Content <MenubarPrimitive.Content
class={cn( data-slot="menubar-content"
'z-50 min-w-48 origin-[var(--kb-menu-content-transform-origin)] animate-content-hide overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[expanded]:animate-content-show', align={align}
local.class alignOffset={alignOffset}
sideOffset={sideOffset}
className={cn(
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[12rem] origin-(--radix-menubar-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-md",
className
)} )}
{...others} {...props}
/> />
</MenubarPrimitive.Portal> </MenubarPortal>
); )
}; }
type MenubarSubTriggerProps<T extends ValidComponent = 'div'> = function MenubarItem({
MenubarPrimitive.MenubarSubTriggerProps<T> & { className,
class?: string | undefined; inset,
children?: JSX.Element; variant = "default",
inset?: boolean; ...props
}; }: React.ComponentProps<typeof MenubarPrimitive.Item> & {
inset?: boolean
const MenubarSubTrigger = <T extends ValidComponent = 'div'>( variant?: "default" | "destructive"
props: PolymorphicProps<T, MenubarSubTriggerProps<T>> }) {
) => {
const [local, others] = splitProps(props as MenubarSubTriggerProps, [
'class',
'children',
'inset',
]);
return (
<MenubarPrimitive.SubTrigger
class={cn(
'flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground',
local.inset && 'pl-8',
local.class
)}
{...others}
>
{local.children}
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="ml-auto size-4"
>
<path d="M9 6l6 6l-6 6" />
</svg>
</MenubarPrimitive.SubTrigger>
);
};
type MenubarSubContentProps<T extends ValidComponent = 'div'> =
MenubarPrimitive.MenubarSubContentProps<T> & {
class?: string | undefined;
};
const MenubarSubContent = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, MenubarSubContentProps<T>>
) => {
const [local, others] = splitProps(props as MenubarSubContentProps, [
'class',
]);
return (
<MenubarPrimitive.Portal>
<MenubarPrimitive.SubContent
class={cn(
'z-50 min-w-32 origin-[var(--kb-menu-content-transform-origin)] animate-in overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md',
local.class
)}
{...others}
/>
</MenubarPrimitive.Portal>
);
};
type MenubarItemProps<T extends ValidComponent = 'div'> =
MenubarPrimitive.MenubarItemProps<T> & {
class?: string | undefined;
inset?: boolean;
};
const MenubarItem = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, MenubarItemProps<T>>
) => {
const [local, others] = splitProps(props as MenubarItemProps, [
'class',
'inset',
]);
return ( return (
<MenubarPrimitive.Item <MenubarPrimitive.Item
class={cn( data-slot="menubar-item"
'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50', data-inset={inset}
local.inset && 'pl-8', data-variant={variant}
local.class className={cn(
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)} )}
{...others} {...props}
/> />
); )
}; }
type MenubarCheckboxItemProps<T extends ValidComponent = 'div'> = function MenubarCheckboxItem({
MenubarPrimitive.MenubarCheckboxItemProps<T> & { className,
class?: string | undefined; children,
children?: JSX.Element; checked,
}; ...props
}: React.ComponentProps<typeof MenubarPrimitive.CheckboxItem>) {
const MenubarCheckboxItem = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, MenubarCheckboxItemProps<T>>
) => {
const [local, others] = splitProps(props as MenubarCheckboxItemProps, [
'class',
'children',
]);
return ( return (
<MenubarPrimitive.CheckboxItem <MenubarPrimitive.CheckboxItem
class={cn( data-slot="menubar-checkbox-item"
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pr-2 pl-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50', className={cn(
local.class "focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-xs py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)} )}
{...others} checked={checked}
{...props}
> >
<span class="absolute left-2 flex size-3.5 items-center justify-center"> <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
<MenubarPrimitive.ItemIndicator> <MenubarPrimitive.ItemIndicator>
<svg <CheckIcon className="size-4" />
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M5 12l5 5l10 -10" />
</svg>
</MenubarPrimitive.ItemIndicator> </MenubarPrimitive.ItemIndicator>
</span> </span>
{local.children} {children}
</MenubarPrimitive.CheckboxItem> </MenubarPrimitive.CheckboxItem>
); )
}; }
type MenubarRadioItemProps<T extends ValidComponent = 'div'> = function MenubarRadioItem({
MenubarPrimitive.MenubarRadioItemProps<T> & { className,
class?: string | undefined; children,
children?: JSX.Element; ...props
}; }: React.ComponentProps<typeof MenubarPrimitive.RadioItem>) {
const MenubarRadioItem = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, MenubarRadioItemProps<T>>
) => {
const [local, others] = splitProps(props as MenubarRadioItemProps, [
'class',
'children',
]);
return ( return (
<MenubarPrimitive.RadioItem <MenubarPrimitive.RadioItem
class={cn( data-slot="menubar-radio-item"
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pr-2 pl-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50', className={cn(
local.class "focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-xs py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)} )}
{...others} {...props}
> >
<span class="absolute left-2 flex size-3.5 items-center justify-center"> <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
<MenubarPrimitive.ItemIndicator> <MenubarPrimitive.ItemIndicator>
<svg <CircleIcon className="size-2 fill-current" />
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-2 fill-current"
>
<path d="M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" />
</svg>
</MenubarPrimitive.ItemIndicator> </MenubarPrimitive.ItemIndicator>
</span> </span>
{local.children} {children}
</MenubarPrimitive.RadioItem> </MenubarPrimitive.RadioItem>
); )
}; }
type MenubarItemLabelProps<T extends ValidComponent = 'div'> = function MenubarLabel({
MenubarPrimitive.MenubarItemLabelProps<T> & { className,
class?: string | undefined; inset,
inset?: boolean; ...props
}; }: React.ComponentProps<typeof MenubarPrimitive.Label> & {
inset?: boolean
const MenubarItemLabel = <T extends ValidComponent = 'div'>( }) {
props: PolymorphicProps<T, MenubarItemLabelProps<T>>
) => {
const [local, others] = splitProps(props as MenubarItemLabelProps, [
'class',
'inset',
]);
return ( return (
<MenubarPrimitive.ItemLabel <MenubarPrimitive.Label
class={cn( data-slot="menubar-label"
'px-2 py-1.5 font-semibold text-sm', data-inset={inset}
local.inset && 'pl-8', className={cn(
local.class "px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
className
)} )}
{...others} {...props}
/> />
); )
}; }
type MenubarGroupLabelProps<T extends ValidComponent = 'span'> = function MenubarSeparator({
MenubarPrimitive.MenubarGroupLabelProps<T> & { className,
class?: string | undefined; ...props
inset?: boolean; }: React.ComponentProps<typeof MenubarPrimitive.Separator>) {
};
const MenubarGroupLabel = <T extends ValidComponent = 'span'>(
props: PolymorphicProps<T, MenubarGroupLabelProps<T>>
) => {
const [local, others] = splitProps(props as MenubarGroupLabelProps, [
'class',
'inset',
]);
return (
<MenubarPrimitive.GroupLabel
class={cn(
'px-2 py-1.5 font-semibold text-sm',
local.inset && 'pl-8',
local.class
)}
{...others}
/>
);
};
type MenubarSeparatorProps<T extends ValidComponent = 'hr'> =
MenubarPrimitive.MenubarSeparatorProps<T> & { class?: string | undefined };
const MenubarSeparator = <T extends ValidComponent = 'hr'>(
props: PolymorphicProps<T, MenubarSeparatorProps<T>>
) => {
const [local, others] = splitProps(props as MenubarSeparatorProps, ['class']);
return ( return (
<MenubarPrimitive.Separator <MenubarPrimitive.Separator
class={cn('-mx-1 my-1 h-px bg-muted', local.class)} data-slot="menubar-separator"
{...others} className={cn("bg-border -mx-1 my-1 h-px", className)}
{...props}
/> />
); )
}; }
const MenubarShortcut: Component<ComponentProps<'span'>> = (props) => { function MenubarShortcut({
const [local, others] = splitProps(props, ['class']); className,
...props
}: React.ComponentProps<"span">) {
return ( return (
<span <span
class={cn( data-slot="menubar-shortcut"
'ml-auto text-muted-foreground text-xs tracking-widest', className={cn(
local.class "text-muted-foreground ml-auto text-xs tracking-widest",
className
)} )}
{...others} {...props}
/> />
); )
}; }
function MenubarSub({
...props
}: React.ComponentProps<typeof MenubarPrimitive.Sub>) {
return <MenubarPrimitive.Sub data-slot="menubar-sub" {...props} />
}
function MenubarSubTrigger({
className,
inset,
children,
...props
}: React.ComponentProps<typeof MenubarPrimitive.SubTrigger> & {
inset?: boolean
}) {
return (
<MenubarPrimitive.SubTrigger
data-slot="menubar-sub-trigger"
data-inset={inset}
className={cn(
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-none select-none data-[inset]:pl-8",
className
)}
{...props}
>
{children}
<ChevronRightIcon className="ml-auto h-4 w-4" />
</MenubarPrimitive.SubTrigger>
)
}
function MenubarSubContent({
className,
...props
}: React.ComponentProps<typeof MenubarPrimitive.SubContent>) {
return (
<MenubarPrimitive.SubContent
data-slot="menubar-sub-content"
className={cn(
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-menubar-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
className
)}
{...props}
/>
)
}
export { export {
Menubar, Menubar,
MenubarPortal,
MenubarMenu, MenubarMenu,
MenubarTrigger, MenubarTrigger,
MenubarContent, MenubarContent,
MenubarItem, MenubarGroup,
MenubarSeparator, MenubarSeparator,
MenubarItemLabel, MenubarLabel,
MenubarGroupLabel, MenubarItem,
MenubarShortcut,
MenubarCheckboxItem, MenubarCheckboxItem,
MenubarRadioGroup, MenubarRadioGroup,
MenubarRadioItem, MenubarRadioItem,
MenubarPortal,
MenubarSubContent,
MenubarSubTrigger,
MenubarGroup,
MenubarSub, MenubarSub,
MenubarShortcut, MenubarSubTrigger,
}; MenubarSubContent,
}

View File

@ -1,209 +1,168 @@
import type { JSX, ValidComponent } from 'solid-js'; import * as React from "react"
import { splitProps } from 'solid-js'; import * as NavigationMenuPrimitive from "@radix-ui/react-navigation-menu"
import { cva } from "class-variance-authority"
import { ChevronDownIcon } from "lucide-react"
import type { PolymorphicProps } from '@kobalte/core'; import { cn } from "@/styles/utils"
import * as NavigationMenuPrimitive from '@kobalte/core/navigation-menu';
import { cn } from '~/utils/styles'; function NavigationMenu({
className,
const NavigationMenuItem = NavigationMenuPrimitive.Menu; children,
viewport = true,
type NavigationMenuProps<T extends ValidComponent = 'ul'> = ...props
NavigationMenuPrimitive.NavigationMenuRootProps<T> & { }: React.ComponentProps<typeof NavigationMenuPrimitive.Root> & {
class?: string | undefined; viewport?: boolean
children?: JSX.Element; }) {
};
const NavigationMenu = <T extends ValidComponent = 'ul'>(
props: PolymorphicProps<T, NavigationMenuProps<T>>
) => {
const [local, others] = splitProps(props as NavigationMenuProps, [
'class',
'children',
]);
return ( return (
<NavigationMenuPrimitive.Root <NavigationMenuPrimitive.Root
gutter={6} data-slot="navigation-menu"
class={cn( data-viewport={viewport}
'group/menu flex w-max flex-1 list-none items-center justify-center data-[orientation=vertical]:flex-col [&>li]:w-full', className={cn(
local.class "group/navigation-menu relative flex max-w-max flex-1 items-center justify-center",
className
)} )}
{...others} {...props}
> >
{local.children} {children}
<NavigationMenuViewport /> {viewport && <NavigationMenuViewport />}
</NavigationMenuPrimitive.Root> </NavigationMenuPrimitive.Root>
); )
}; }
type NavigationMenuTriggerProps<T extends ValidComponent = 'button'> = function NavigationMenuList({
NavigationMenuPrimitive.NavigationMenuTriggerProps<T> & { className,
class?: string | undefined; ...props
}; }: React.ComponentProps<typeof NavigationMenuPrimitive.List>) {
const NavigationMenuTrigger = <T extends ValidComponent = 'button'>(
props: PolymorphicProps<T, NavigationMenuTriggerProps<T>>
) => {
const [local, others] = splitProps(props as NavigationMenuTriggerProps, [
'class',
]);
return ( return (
<NavigationMenuPrimitive.Trigger <NavigationMenuPrimitive.List
class={cn( data-slot="navigation-menu-list"
'group/trigger inline-flex h-10 w-full items-center justify-center whitespace-nowrap rounded-md bg-background px-4 py-2 font-medium text-sm transition-colors hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground focus:outline-none disabled:pointer-events-none disabled:opacity-50 data-[active]:bg-accent/50 data-[expanded]:bg-accent/50', className={cn(
local.class "group flex flex-1 list-none items-center justify-center gap-1",
className
)} )}
{...others} {...props}
/> />
); )
}; }
const NavigationMenuIcon = () => {
return (
<NavigationMenuPrimitive.Icon aria-hidden="true">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="group-data-[orientation=vertical]/menu:-rotate-90 relative top-px ml-1 size-3 transition duration-200 group-data-[orientation=vertical]/menu:group-data-[expanded]/trigger:rotate-90 group-data-[expanded]/trigger:rotate-180"
>
<path d="M6 9l6 6l6 -6" />
</svg>
</NavigationMenuPrimitive.Icon>
);
};
type NavigationMenuViewportProps<T extends ValidComponent = 'li'> = function NavigationMenuItem({
NavigationMenuPrimitive.NavigationMenuViewportProps<T> & { className,
class?: string | undefined; ...props
}; }: React.ComponentProps<typeof NavigationMenuPrimitive.Item>) {
const NavigationMenuViewport = <T extends ValidComponent = 'li'>(
props: PolymorphicProps<T, NavigationMenuViewportProps<T>>
) => {
const [local, others] = splitProps(props as NavigationMenuViewportProps, [
'class',
]);
return (
<NavigationMenuPrimitive.Viewport
class={cn(
// base settings
'pointer-events-none z-[1000] flex h-[var(--kb-navigation-menu-viewport-height)] w-[var(--kb-navigation-menu-viewport-width)] origin-[var(--kb-menu-content-transform-origin)] items-center justify-center overflow-x-clip overflow-y-visible rounded-md border bg-popover opacity-0 shadow-lg data-[expanded]:pointer-events-auto data-[orientation=vertical]:overflow-y-clip data-[orientation=vertical]:overflow-x-visible data-[expanded]:rounded-md',
// animate
'animate-content-hide transition-[width,height] duration-200 ease-in data-[expanded]:animate-content-show data-[expanded]:opacity-100 data-[expanded]:ease-out',
local.class
)}
{...others}
/>
);
};
type NavigationMenuContentProps<T extends ValidComponent = 'ul'> =
NavigationMenuPrimitive.NavigationMenuContentProps<T> & {
class?: string | undefined;
};
const NavigationMenuContent = <T extends ValidComponent = 'ul'>(
props: PolymorphicProps<T, NavigationMenuContentProps<T>>
) => {
const [local, others] = splitProps(props as NavigationMenuContentProps, [
'class',
]);
return (
<NavigationMenuPrimitive.Portal>
<NavigationMenuPrimitive.Content
class={cn(
// base settings
'pointer-events-none absolute top-0 left-0 box-border p-4 focus:outline-none data-[expanded]:pointer-events-auto',
// base animation settings
'data-[motion^=from-]:fade-in data-[motion^=to-]:fade-out data-[motion^=from-]:animate-in data-[motion^=to-]:animate-out',
// left to right
'data-[orientation=horizontal]:data-[motion=from-start]:slide-in-from-left-52 data-[orientation=horizontal]:data-[motion=to-end]:slide-out-to-right-52',
// right to left
'data-[orientation=horizontal]:data-[motion=from-end]:slide-in-from-right-52 data-[orientation=horizontal]:data-[motion=to-start]:slide-out-to-left-52',
// top to bottom
'data-[orientation=vertical]:data-[motion=from-start]:slide-in-from-top-52 data-[orientation=vertical]:data-[motion=to-end]:slide-out-to-bottom-52',
//bottom to top
'data-[orientation=vertical]:data-[motion=from-end]:slide-in-from-bottom-52 data-[orientation=vertical]:data-[motion=to-start]:slide-out-to-bottom-52',
local.class
)}
{...others}
/>
</NavigationMenuPrimitive.Portal>
);
};
type NavigationMenuLinkProps<T extends ValidComponent = 'a'> =
NavigationMenuPrimitive.NavigationMenuItemProps<T> & {
class?: string | undefined;
};
const NavigationMenuLink = <T extends ValidComponent = 'a'>(
props: PolymorphicProps<T, NavigationMenuLinkProps<T>>
) => {
const [local, others] = splitProps(props as NavigationMenuLinkProps, [
'class',
]);
return ( return (
<NavigationMenuPrimitive.Item <NavigationMenuPrimitive.Item
class={cn( data-slot="navigation-menu-item"
'block select-none space-y-1 rounded-md p-3 leading-none no-underline outline-none transition-colors hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground', className={cn("relative", className)}
local.class {...props}
/>
)
}
const navigationMenuTriggerStyle = cva(
"group inline-flex h-9 w-max items-center justify-center rounded-md bg-background px-4 py-2 text-sm font-medium hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=open]:hover:bg-accent data-[state=open]:text-accent-foreground data-[state=open]:focus:bg-accent data-[state=open]:bg-accent/50 focus-visible:ring-ring/50 outline-none transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1"
)
function NavigationMenuTrigger({
className,
children,
...props
}: React.ComponentProps<typeof NavigationMenuPrimitive.Trigger>) {
return (
<NavigationMenuPrimitive.Trigger
data-slot="navigation-menu-trigger"
className={cn(navigationMenuTriggerStyle(), "group", className)}
{...props}
>
{children}{" "}
<ChevronDownIcon
className="relative top-[1px] ml-1 size-3 transition duration-300 group-data-[state=open]:rotate-180"
aria-hidden="true"
/>
</NavigationMenuPrimitive.Trigger>
)
}
function NavigationMenuContent({
className,
...props
}: React.ComponentProps<typeof NavigationMenuPrimitive.Content>) {
return (
<NavigationMenuPrimitive.Content
data-slot="navigation-menu-content"
className={cn(
"data-[motion^=from-]:animate-in data-[motion^=to-]:animate-out data-[motion^=from-]:fade-in data-[motion^=to-]:fade-out data-[motion=from-end]:slide-in-from-right-52 data-[motion=from-start]:slide-in-from-left-52 data-[motion=to-end]:slide-out-to-right-52 data-[motion=to-start]:slide-out-to-left-52 top-0 left-0 w-full p-2 pr-2.5 md:absolute md:w-auto",
"group-data-[viewport=false]/navigation-menu:bg-popover group-data-[viewport=false]/navigation-menu:text-popover-foreground group-data-[viewport=false]/navigation-menu:data-[state=open]:animate-in group-data-[viewport=false]/navigation-menu:data-[state=closed]:animate-out group-data-[viewport=false]/navigation-menu:data-[state=closed]:zoom-out-95 group-data-[viewport=false]/navigation-menu:data-[state=open]:zoom-in-95 group-data-[viewport=false]/navigation-menu:data-[state=open]:fade-in-0 group-data-[viewport=false]/navigation-menu:data-[state=closed]:fade-out-0 group-data-[viewport=false]/navigation-menu:top-full group-data-[viewport=false]/navigation-menu:mt-1.5 group-data-[viewport=false]/navigation-menu:overflow-hidden group-data-[viewport=false]/navigation-menu:rounded-md group-data-[viewport=false]/navigation-menu:border group-data-[viewport=false]/navigation-menu:shadow group-data-[viewport=false]/navigation-menu:duration-200 **:data-[slot=navigation-menu-link]:focus:ring-0 **:data-[slot=navigation-menu-link]:focus:outline-none",
className
)} )}
{...others} {...props}
/> />
); )
}; }
type NavigationMenuLabelProps<T extends ValidComponent = 'div'> = function NavigationMenuViewport({
NavigationMenuPrimitive.NavigationMenuItemLabelProps<T> & { className,
class?: string | undefined; ...props
}; }: React.ComponentProps<typeof NavigationMenuPrimitive.Viewport>) {
const NavigationMenuLabel = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, NavigationMenuLabelProps<T>>
) => {
const [local, others] = splitProps(props as NavigationMenuLabelProps, [
'class',
]);
return ( return (
<NavigationMenuPrimitive.ItemLabel <div
class={cn('font-medium text-sm leading-none', local.class)} className={cn(
{...others} "absolute top-full left-0 isolate z-50 flex justify-center"
/> )}
); >
}; <NavigationMenuPrimitive.Viewport
data-slot="navigation-menu-viewport"
className={cn(
"origin-top-center bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-90 relative mt-1.5 h-[var(--radix-navigation-menu-viewport-height)] w-full overflow-hidden rounded-md border shadow md:w-[var(--radix-navigation-menu-viewport-width)]",
className
)}
{...props}
/>
</div>
)
}
type NavigationMenuDescriptionProps<T extends ValidComponent = 'div'> = function NavigationMenuLink({
NavigationMenuPrimitive.NavigationMenuItemDescriptionProps<T> & { className,
class?: string | undefined; ...props
}; }: React.ComponentProps<typeof NavigationMenuPrimitive.Link>) {
const NavigationMenuDescription = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, NavigationMenuDescriptionProps<T>>
) => {
const [local, others] = splitProps(props as NavigationMenuDescriptionProps, [
'class',
]);
return ( return (
<NavigationMenuPrimitive.ItemDescription <NavigationMenuPrimitive.Link
class={cn('text-muted-foreground text-sm leading-snug', local.class)} data-slot="navigation-menu-link"
{...others} className={cn(
"data-[active=true]:focus:bg-accent data-[active=true]:hover:bg-accent data-[active=true]:bg-accent/50 data-[active=true]:text-accent-foreground hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground focus-visible:ring-ring/50 [&_svg:not([class*='text-'])]:text-muted-foreground flex flex-col gap-1 rounded-sm p-2 text-sm transition-all outline-none focus-visible:ring-[3px] focus-visible:outline-1 [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
/> />
); )
}; }
function NavigationMenuIndicator({
className,
...props
}: React.ComponentProps<typeof NavigationMenuPrimitive.Indicator>) {
return (
<NavigationMenuPrimitive.Indicator
data-slot="navigation-menu-indicator"
className={cn(
"data-[state=visible]:animate-in data-[state=hidden]:animate-out data-[state=hidden]:fade-out data-[state=visible]:fade-in top-full z-[1] flex h-1.5 items-end justify-center overflow-hidden",
className
)}
{...props}
>
<div className="bg-border relative top-[60%] h-2 w-2 rotate-45 rounded-tl-sm shadow-md" />
</NavigationMenuPrimitive.Indicator>
)
}
export { export {
NavigationMenu, NavigationMenu,
NavigationMenuList,
NavigationMenuItem, NavigationMenuItem,
NavigationMenuTrigger,
NavigationMenuIcon,
NavigationMenuViewport,
NavigationMenuContent, NavigationMenuContent,
NavigationMenuTrigger,
NavigationMenuLink, NavigationMenuLink,
NavigationMenuLabel, NavigationMenuIndicator,
NavigationMenuDescription, NavigationMenuViewport,
}; navigationMenuTriggerStyle,
}

View File

@ -1,199 +0,0 @@
import type { Component, ComponentProps, JSX, ValidComponent } from 'solid-js';
import { Show, splitProps } from 'solid-js';
import * as NumberFieldPrimitive from '@kobalte/core/number-field';
import type { PolymorphicProps } from '@kobalte/core/polymorphic';
import { cn } from '~/utils/styles';
const NumberField = NumberFieldPrimitive.Root;
const NumberFieldGroup: Component<ComponentProps<'div'>> = (props) => {
const [local, others] = splitProps(props, ['class']);
return (
<div
class={cn(
'relative rounded-md focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2',
local.class
)}
{...others}
/>
);
};
type NumberFieldLabelProps<T extends ValidComponent = 'label'> =
NumberFieldPrimitive.NumberFieldLabelProps<T> & {
class?: string | undefined;
};
const NumberFieldLabel = <T extends ValidComponent = 'label'>(
props: PolymorphicProps<T, NumberFieldLabelProps<T>>
) => {
const [local, others] = splitProps(props as NumberFieldLabelProps, ['class']);
return (
<NumberFieldPrimitive.Label
class={cn(
'font-medium text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70',
local.class
)}
{...others}
/>
);
};
type NumberFieldInputProps<T extends ValidComponent = 'input'> =
NumberFieldPrimitive.NumberFieldInputProps<T> & {
class?: string | undefined;
};
const NumberFieldInput = <T extends ValidComponent = 'input'>(
props: PolymorphicProps<T, NumberFieldInputProps<T>>
) => {
const [local, others] = splitProps(props as NumberFieldInputProps, ['class']);
return (
<NumberFieldPrimitive.Input
class={cn(
'flex h-10 w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:font-medium file:text-sm placeholder:text-muted-foreground focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50 data-[invalid]:border-error-foreground data-[invalid]:text-error-foreground',
local.class
)}
{...others}
/>
);
};
type NumberFieldIncrementTriggerProps<T extends ValidComponent = 'button'> =
NumberFieldPrimitive.NumberFieldIncrementTriggerProps<T> & {
class?: string | undefined;
children?: JSX.Element;
};
const NumberFieldIncrementTrigger = <T extends ValidComponent = 'button'>(
props: PolymorphicProps<T, NumberFieldIncrementTriggerProps<T>>
) => {
const [local, others] = splitProps(
props as NumberFieldIncrementTriggerProps,
['class', 'children']
);
return (
<NumberFieldPrimitive.IncrementTrigger
class={cn(
'absolute top-1 right-1 inline-flex size-4 items-center justify-center',
local.class
)}
{...others}
>
<Show
when={local.children}
fallback={
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M6 15l6 -6l6 6" />
</svg>
}
>
{(children) => children()}
</Show>
</NumberFieldPrimitive.IncrementTrigger>
);
};
type NumberFieldDecrementTriggerProps<T extends ValidComponent = 'button'> =
NumberFieldPrimitive.NumberFieldDecrementTriggerProps<T> & {
class?: string | undefined;
children?: JSX.Element;
};
const NumberFieldDecrementTrigger = <T extends ValidComponent = 'button'>(
props: PolymorphicProps<T, NumberFieldDecrementTriggerProps<T>>
) => {
const [local, others] = splitProps(
props as NumberFieldDecrementTriggerProps,
['class', 'children']
);
return (
<NumberFieldPrimitive.DecrementTrigger
class={cn(
'absolute right-1 bottom-1 inline-flex size-4 items-center justify-center',
local.class
)}
{...others}
>
<Show
when={local.children}
fallback={
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M6 9l6 6l6 -6" />
</svg>
}
>
{(children) => children()}
</Show>
</NumberFieldPrimitive.DecrementTrigger>
);
};
type NumberFieldDescriptionProps<T extends ValidComponent = 'div'> =
NumberFieldPrimitive.NumberFieldDescriptionProps<T> & {
class?: string | undefined;
};
const NumberFieldDescription = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, NumberFieldDescriptionProps<T>>
) => {
const [local, others] = splitProps(props as NumberFieldDescriptionProps, [
'class',
]);
return (
<NumberFieldPrimitive.Description
class={cn('text-muted-foreground text-sm', local.class)}
{...others}
/>
);
};
type NumberFieldErrorMessageProps<T extends ValidComponent = 'div'> =
NumberFieldPrimitive.NumberFieldErrorMessageProps<T> & {
class?: string | undefined;
};
const NumberFieldErrorMessage = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, NumberFieldErrorMessageProps<T>>
) => {
const [local, others] = splitProps(props as NumberFieldErrorMessageProps, [
'class',
]);
return (
<NumberFieldPrimitive.ErrorMessage
class={cn('text-error-foreground text-sm', local.class)}
{...others}
/>
);
};
export {
NumberField,
NumberFieldGroup,
NumberFieldLabel,
NumberFieldInput,
NumberFieldIncrementTrigger,
NumberFieldDecrementTrigger,
NumberFieldDescription,
NumberFieldErrorMessage,
};

View File

@ -1,98 +0,0 @@
import type { Component, ComponentProps, ValidComponent } from 'solid-js';
import { Show, splitProps } from 'solid-js';
import type { DynamicProps, RootProps } from '@corvu/otp-field';
import OtpField from '@corvu/otp-field';
import { cn } from '~/utils/styles';
export const REGEXP_ONLY_DIGITS = '^\\d*$';
export const REGEXP_ONLY_CHARS = '^[a-zA-Z]*$';
export const REGEXP_ONLY_DIGITS_AND_CHARS = '^[a-zA-Z0-9]*$';
type OTPFieldProps<T extends ValidComponent = 'div'> = RootProps<T> & {
class?: string;
};
const OTPField = <T extends ValidComponent = 'div'>(
props: DynamicProps<T, OTPFieldProps<T>>
) => {
const [local, others] = splitProps(props as OTPFieldProps, ['class']);
return (
<OtpField
class={cn(
'flex items-center gap-2 disabled:cursor-not-allowed has-[:disabled]:opacity-50',
local.class
)}
{...others}
/>
);
};
const OTPFieldInput = OtpField.Input;
const OTPFieldGroup: Component<ComponentProps<'div'>> = (props) => {
const [local, others] = splitProps(props, ['class']);
return <div class={cn('flex items-center', local.class)} {...others} />;
};
const OTPFieldSlot: Component<ComponentProps<'div'> & { index: number }> = (
props
) => {
const [local, others] = splitProps(props, ['class', 'index']);
const context = OtpField.useContext();
const char = () => context.value()[local.index];
const showFakeCaret = () =>
context.value().length === local.index && context.isInserting();
return (
<div
class={cn(
'group relative flex size-10 items-center justify-center border-input border-y border-r text-sm first:rounded-l-md first:border-l last:rounded-r-md',
local.class
)}
{...others}
>
<div
class={cn(
'absolute inset-0 z-10 transition-all group-first:rounded-l-md group-last:rounded-r-md',
context.activeSlots().includes(local.index) &&
'ring-2 ring-ring ring-offset-background'
)}
/>
{char()}
<Show when={showFakeCaret()}>
<div class="pointer-events-none absolute inset-0 flex items-center justify-center">
<div class="h-4 w-px animate-caret-blink bg-foreground duration-1000" />
</div>
</Show>
</div>
);
};
const OTPFieldSeparator: Component<ComponentProps<'div'>> = (props) => {
return (
<div {...props}>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-6"
>
<circle cx="12.1" cy="12.1" r="1" />
</svg>
</div>
);
};
export {
OTPField,
OTPFieldInput,
OTPFieldGroup,
OTPFieldSlot,
OTPFieldSeparator,
};

View File

@ -1,193 +1,127 @@
import type { JSX, ValidComponent } from 'solid-js'; import * as React from "react"
import { Show, splitProps } from 'solid-js'; import {
ChevronLeftIcon,
ChevronRightIcon,
MoreHorizontalIcon,
} from "lucide-react"
import * as PaginationPrimitive from '@kobalte/core/pagination'; import { cn } from "@/styles/utils"
import type { PolymorphicProps } from '@kobalte/core/polymorphic'; import { Button, buttonVariants } from "@/components/ui/button"
import { buttonVariants } from '~/components/ui/button'; function Pagination({ className, ...props }: React.ComponentProps<"nav">) {
import { cn } from '~/utils/styles';
const PaginationItems = PaginationPrimitive.Items;
type PaginationRootProps<T extends ValidComponent = 'nav'> =
PaginationPrimitive.PaginationRootProps<T> & { class?: string | undefined };
const Pagination = <T extends ValidComponent = 'nav'>(
props: PolymorphicProps<T, PaginationRootProps<T>>
) => {
const [local, others] = splitProps(props as PaginationRootProps, ['class']);
return ( return (
<PaginationPrimitive.Root <nav
class={cn( role="navigation"
'[&>*]:flex [&>*]:flex-row [&>*]:items-center [&>*]:gap-1', aria-label="pagination"
local.class data-slot="pagination"
)} className={cn("mx-auto flex w-full justify-center", className)}
{...others} {...props}
/> />
); )
}; }
type PaginationItemProps<T extends ValidComponent = 'button'> = function PaginationContent({
PaginationPrimitive.PaginationItemProps<T> & { class?: string | undefined }; className,
...props
const PaginationItem = <T extends ValidComponent = 'button'>( }: React.ComponentProps<"ul">) {
props: PolymorphicProps<T, PaginationItemProps<T>>
) => {
const [local, others] = splitProps(props as PaginationItemProps, ['class']);
return ( return (
<PaginationPrimitive.Item <ul
class={cn( data-slot="pagination-content"
buttonVariants({ className={cn("flex flex-row items-center gap-1", className)}
variant: 'ghost', {...props}
}),
'size-10 data-[current]:border',
local.class
)}
{...others}
/> />
); )
}; }
type PaginationEllipsisProps<T extends ValidComponent = 'div'> = function PaginationItem({ ...props }: React.ComponentProps<"li">) {
PaginationPrimitive.PaginationEllipsisProps<T> & { return <li data-slot="pagination-item" {...props} />
class?: string | undefined; }
};
const PaginationEllipsis = <T extends ValidComponent = 'div'>( type PaginationLinkProps = {
props: PolymorphicProps<T, PaginationEllipsisProps<T>> isActive?: boolean
) => { } & Pick<React.ComponentProps<typeof Button>, "size"> &
const [local, others] = splitProps(props as PaginationEllipsisProps, [ React.ComponentProps<"a">
'class',
]); function PaginationLink({
className,
isActive,
size = "icon",
...props
}: PaginationLinkProps) {
return ( return (
<PaginationPrimitive.Ellipsis <a
class={cn('flex size-10 items-center justify-center', local.class)} aria-current={isActive ? "page" : undefined}
{...others} data-slot="pagination-link"
> data-active={isActive}
<svg className={cn(
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<circle cx="12" cy="12" r="1" />
<circle cx="19" cy="12" r="1" />
<circle cx="5" cy="12" r="1" />
</svg>
<span class="sr-only">More pages</span>
</PaginationPrimitive.Ellipsis>
);
};
type PaginationPreviousProps<T extends ValidComponent = 'button'> =
PaginationPrimitive.PaginationPreviousProps<T> & {
class?: string | undefined;
children?: JSX.Element;
};
const PaginationPrevious = <T extends ValidComponent = 'button'>(
props: PolymorphicProps<T, PaginationPreviousProps<T>>
) => {
const [local, others] = splitProps(props as PaginationPreviousProps, [
'class',
'children',
]);
return (
<PaginationPrimitive.Previous
class={cn(
buttonVariants({ buttonVariants({
variant: 'ghost', variant: isActive ? "outline" : "ghost",
size,
}), }),
'gap-1 pl-2.5', className
local.class
)} )}
{...others} {...props}
> />
<Show )
when={local.children} }
fallback={
<>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M15 6l-6 6l6 6" />
</svg>
<span>Previous</span>
</>
}
>
{(children) => children()}
</Show>
</PaginationPrimitive.Previous>
);
};
type PaginationNextProps<T extends ValidComponent = 'button'> = function PaginationPrevious({
PaginationPrimitive.PaginationNextProps<T> & { className,
class?: string | undefined; ...props
children?: JSX.Element; }: React.ComponentProps<typeof PaginationLink>) {
};
const PaginationNext = <T extends ValidComponent = 'button'>(
props: PolymorphicProps<T, PaginationNextProps<T>>
) => {
const [local, others] = splitProps(props as PaginationNextProps, [
'class',
'children',
]);
return ( return (
<PaginationPrimitive.Next <PaginationLink
class={cn( aria-label="Go to previous page"
buttonVariants({ size="default"
variant: 'ghost', className={cn("gap-1 px-2.5 sm:pl-2.5", className)}
}), {...props}
'gap-1 pl-2.5',
local.class
)}
{...others}
> >
<Show <ChevronLeftIcon />
when={local.children} <span className="hidden sm:block">Previous</span>
fallback={ </PaginationLink>
<> )
<span>Next</span> }
<svg
xmlns="http://www.w3.org/2000/svg" function PaginationNext({
viewBox="0 0 24 24" className,
fill="none" ...props
stroke="currentColor" }: React.ComponentProps<typeof PaginationLink>) {
stroke-width="2" return (
stroke-linecap="round" <PaginationLink
stroke-linejoin="round" aria-label="Go to next page"
class="size-4" size="default"
> className={cn("gap-1 px-2.5 sm:pr-2.5", className)}
<path d="M9 6l6 6l-6 6" /> {...props}
</svg> >
</> <span className="hidden sm:block">Next</span>
} <ChevronRightIcon />
> </PaginationLink>
{(children) => children()} )
</Show> }
</PaginationPrimitive.Next>
); function PaginationEllipsis({
}; className,
...props
}: React.ComponentProps<"span">) {
return (
<span
aria-hidden
data-slot="pagination-ellipsis"
className={cn("flex size-9 items-center justify-center", className)}
{...props}
>
<MoreHorizontalIcon className="size-4" />
<span className="sr-only">More pages</span>
</span>
)
}
export { export {
Pagination, Pagination,
PaginationItems, PaginationContent,
PaginationLink,
PaginationItem, PaginationItem,
PaginationEllipsis,
PaginationPrevious, PaginationPrevious,
PaginationNext, PaginationNext,
}; PaginationEllipsis,
}

View File

@ -1,35 +1,48 @@
import type { Component, ValidComponent } from 'solid-js'; "use client"
import { splitProps } from 'solid-js';
import type { PolymorphicProps } from '@kobalte/core/polymorphic'; import * as React from "react"
import * as PopoverPrimitive from '@kobalte/core/popover'; import * as PopoverPrimitive from "@radix-ui/react-popover"
import { cn } from '~/utils/styles'; import { cn } from "@/styles/utils"
const PopoverTrigger = PopoverPrimitive.Trigger; function Popover({
...props
}: React.ComponentProps<typeof PopoverPrimitive.Root>) {
return <PopoverPrimitive.Root data-slot="popover" {...props} />
}
const Popover: Component<PopoverPrimitive.PopoverRootProps> = (props) => { function PopoverTrigger({
return <PopoverPrimitive.Root gutter={4} {...props} />; ...props
}; }: React.ComponentProps<typeof PopoverPrimitive.Trigger>) {
return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />
}
type PopoverContentProps<T extends ValidComponent = 'div'> = function PopoverContent({
PopoverPrimitive.PopoverContentProps<T> & { class?: string | undefined }; className,
align = "center",
const PopoverContent = <T extends ValidComponent = 'div'>( sideOffset = 4,
props: PolymorphicProps<T, PopoverContentProps<T>> ...props
) => { }: React.ComponentProps<typeof PopoverPrimitive.Content>) {
const [local, others] = splitProps(props as PopoverContentProps, ['class']);
return ( return (
<PopoverPrimitive.Portal> <PopoverPrimitive.Portal>
<PopoverPrimitive.Content <PopoverPrimitive.Content
class={cn( data-slot="popover-content"
'data-[closed]:fade-out-0 data-[expanded]:fade-in-0 data-[closed]:zoom-out-95 data-[expanded]:zoom-in-95 z-50 w-72 origin-[var(--kb-popover-content-transform-origin)] rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[closed]:animate-out data-[expanded]:animate-in', align={align}
local.class sideOffset={sideOffset}
className={cn(
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
className
)} )}
{...others} {...props}
/> />
</PopoverPrimitive.Portal> </PopoverPrimitive.Portal>
); )
}; }
export { Popover, PopoverTrigger, PopoverContent }; function PopoverAnchor({
...props
}: React.ComponentProps<typeof PopoverPrimitive.Anchor>) {
return <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />
}
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor }

View File

@ -1,30 +1,26 @@
import { type LinkComponent, createLink } from '@tanstack/solid-router'; import { cn } from '@/styles/utils';
import { import { type LinkComponent, createLink } from '@tanstack/react-router';
type Component, import type { AnchorHTMLAttributes, ComponentProps } from 'react';
type ComponentProps,
type JSX,
Show,
splitProps,
} from 'solid-js';
type BasicLinkProps = JSX.IntrinsicElements['a']; export interface BasicLinkProps
extends AnchorHTMLAttributes<HTMLAnchorElement> {}
const BasicLinkComponent: Component<BasicLinkProps> = (props) => ( const BasicLinkComponent = (props: ComponentProps<'a'>) => {
<a {...props}>{props.children}</a> return (
); <a
{...props}
className={cn('block px-3 py-2 text-blue-700', props.className)}
/>
);
};
const CreatedLinkComponent = createLink(BasicLinkComponent); const CreatedLinkComponent = createLink(BasicLinkComponent);
export const ProLink: LinkComponent<typeof BasicLinkComponent> = (props) => { export const ProLink: LinkComponent<typeof BasicLinkComponent> = (props) => {
const [local, other] = splitProps(props, ['href']); if (props.href) {
return ( return <BasicLinkComponent {...(props as any)} />;
<Show }
when={!props.href} return <CreatedLinkComponent preload={'intent'} {...props} />;
fallback={<BasicLinkComponent {...(other as any)} href={local.href} />}
>
<CreatedLinkComponent preload={'intent'} {...(other as typeof props)} />
</Show>
);
}; };
export type ProLinkProps = ComponentProps<typeof ProLink>; export type ProLinkProps = ComponentProps<typeof ProLink>;

View File

@ -1,7 +1,5 @@
import type { Component, ComponentProps } from 'solid-js'; import { cn } from '@/styles/utils';
import { mergeProps, splitProps } from 'solid-js'; import type { FC, HTMLAttributes } from 'react';
import { cn } from '~/utils/styles';
type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl'; type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
@ -13,87 +11,81 @@ const sizes: Record<Size, { radius: number; strokeWidth: number }> = {
xl: { radius: 80, strokeWidth: 10 }, xl: { radius: 80, strokeWidth: 10 },
}; };
type ProgressCircleProps = ComponentProps<'div'> & { interface ProgressCircleProps extends HTMLAttributes<HTMLDivElement> {
value?: number; value?: number;
size?: Size; size?: Size;
radius?: number; radius?: number;
strokeWidth?: number; strokeWidth?: number;
showAnimation?: boolean; showAnimation?: boolean;
}; }
const ProgressCircle: Component<ProgressCircleProps> = (rawProps) => { const ProgressCircle: FC<ProgressCircleProps> = ({
const props = mergeProps( className,
{ size: 'md' as Size, showAnimation: true }, children,
rawProps value = 0,
); size = 'md',
const [local, others] = splitProps(props, [ radius,
'class', strokeWidth,
'children', showAnimation = true,
'value', ...props
'size', }) => {
'radius', const currentValue = getLimitedValue(value);
'strokeWidth', const currentRadius = radius ?? sizes[size].radius;
'showAnimation', const currentStrokeWidth = strokeWidth ?? sizes[size].strokeWidth;
]); const normalizedRadius = currentRadius - currentStrokeWidth / 2;
const circumference = normalizedRadius * 2 * Math.PI;
const value = () => getLimitedValue(local.value); const strokeDashoffset = (currentValue / 100) * circumference;
const radius = () => local.radius ?? sizes[local.size].radius; const offset = circumference - strokeDashoffset;
const strokeWidth = () => local.strokeWidth ?? sizes[local.size].strokeWidth;
const normalizedRadius = () => radius() - strokeWidth() / 2;
const circumference = () => normalizedRadius() * 2 * Math.PI;
const strokeDashoffset = () => (value() / 100) * circumference();
const offset = () => circumference() - strokeDashoffset();
return ( return (
<div <div
class={cn('flex flex-col items-center justify-center', local.class)} className={cn('flex flex-col items-center justify-center', className)}
{...others} {...props}
> >
<svg <svg
width={radius() * 2} width={currentRadius * 2}
height={radius() * 2} height={currentRadius * 2}
viewBox={`0 0 ${radius() * 2} ${radius() * 2}`} viewBox={`0 0 ${currentRadius * 2} ${currentRadius * 2}`}
class="-rotate-90" className="-rotate-90"
> >
<circle <circle
r={normalizedRadius()} r={normalizedRadius}
cx={radius()} cx={currentRadius}
cy={radius()} cy={currentRadius}
stroke-width={strokeWidth()} strokeWidth={currentStrokeWidth}
fill="transparent" fill="transparent"
stroke="" stroke=""
stroke-linecap="round" strokeLinecap="round"
class={cn('stroke-secondary transition-colors ease-linear')} className={cn('stroke-secondary transition-colors ease-linear')}
/> />
{value() >= 0 ? ( {currentValue >= 0 && (
<circle <circle
r={normalizedRadius()} r={normalizedRadius}
cx={radius()} cx={currentRadius}
cy={radius()} cy={currentRadius}
stroke-width={strokeWidth()} strokeWidth={currentStrokeWidth}
stroke-dasharray={circumference() + ' ' + circumference()} strokeDasharray={`${circumference} ${circumference}`}
stroke-dashoffset={offset()} strokeDashoffset={offset}
fill="transparent" fill="transparent"
stroke="" stroke=""
stroke-linecap="round" strokeLinecap="round"
class={cn( className={cn(
'stroke-primary transition-colors ease-linear', 'stroke-primary transition-colors ease-linear',
local.showAnimation showAnimation ? 'transition-all duration-300 ease-in-out' : ''
? 'transition-all duration-300 ease-in-out'
: ''
)} )}
/> />
) : null} )}
</svg> </svg>
<div class={cn('absolute flex')}>{local.children}</div> <div className={cn('absolute flex')}>{children}</div>
</div> </div>
); );
}; };
function getLimitedValue(input: number | undefined) { function getLimitedValue(input: number | undefined): number {
if (input === undefined) { if (input === undefined) {
return 0; return 0;
} else if (input > 100) { }
if (input > 100) {
return 100; return 100;
} }
return input; return input;

View File

@ -1,34 +1,29 @@
import type { Component, JSX, ValidComponent } from "solid-js" import * as React from "react"
import { splitProps } from "solid-js" import * as ProgressPrimitive from "@radix-ui/react-progress"
import type { PolymorphicProps } from "@kobalte/core/polymorphic" import { cn } from "@/styles/utils"
import * as ProgressPrimitive from "@kobalte/core/progress"
import { Label } from "~/components/ui/label" function Progress({
className,
type ProgressRootProps<T extends ValidComponent = "div"> = value,
ProgressPrimitive.ProgressRootProps<T> & { children?: JSX.Element } ...props
}: React.ComponentProps<typeof ProgressPrimitive.Root>) {
const Progress = <T extends ValidComponent = "div">(
props: PolymorphicProps<T, ProgressRootProps<T>>
) => {
const [local, others] = splitProps(props as ProgressRootProps, ["children"])
return ( return (
<ProgressPrimitive.Root {...others}> <ProgressPrimitive.Root
{local.children} data-slot="progress"
<ProgressPrimitive.Track class="relative h-2 w-full overflow-hidden rounded-full bg-secondary"> className={cn(
<ProgressPrimitive.Fill class="h-full w-[var(--kb-progress-fill-width)] flex-1 bg-primary transition-all" /> "bg-primary/20 relative h-2 w-full overflow-hidden rounded-full",
</ProgressPrimitive.Track> className
)}
{...props}
>
<ProgressPrimitive.Indicator
data-slot="progress-indicator"
className="bg-primary h-full w-full flex-1 transition-all"
style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
/>
</ProgressPrimitive.Root> </ProgressPrimitive.Root>
) )
} }
const ProgressLabel: Component<ProgressPrimitive.ProgressLabelProps> = (props) => { export { Progress }
return <ProgressPrimitive.Label as={Label} {...props} />
}
const ProgressValueLabel: Component<ProgressPrimitive.ProgressValueLabelProps> = (props) => {
return <ProgressPrimitive.ValueLabel as={Label} {...props} />
}
export { Progress, ProgressLabel, ProgressValueLabel }

View File

@ -1,84 +1,45 @@
import type { JSX, ValidComponent } from 'solid-js'; "use client"
import { splitProps } from 'solid-js';
import type { PolymorphicProps } from '@kobalte/core/polymorphic'; import * as React from "react"
import * as RadioGroupPrimitive from '@kobalte/core/radio-group'; import * as RadioGroupPrimitive from "@radix-ui/react-radio-group"
import { CircleIcon } from "lucide-react"
import { cn } from '~/utils/styles'; import { cn } from "@/styles/utils"
type RadioGroupRootProps<T extends ValidComponent = 'div'> = function RadioGroup({
RadioGroupPrimitive.RadioGroupRootProps<T> & { class?: string | undefined }; className,
...props
const RadioGroup = <T extends ValidComponent = 'div'>( }: React.ComponentProps<typeof RadioGroupPrimitive.Root>) {
props: PolymorphicProps<T, RadioGroupRootProps<T>>
) => {
const [local, others] = splitProps(props as RadioGroupRootProps, ['class']);
return ( return (
<RadioGroupPrimitive.Root <RadioGroupPrimitive.Root
class={cn('grid gap-2', local.class)} data-slot="radio-group"
{...others} className={cn("grid gap-3", className)}
{...props}
/> />
); )
}; }
type RadioGroupItemProps<T extends ValidComponent = 'div'> = function RadioGroupItem({
RadioGroupPrimitive.RadioGroupItemProps<T> & { className,
class?: string | undefined; ...props
children?: JSX.Element; }: React.ComponentProps<typeof RadioGroupPrimitive.Item>) {
};
const RadioGroupItem = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, RadioGroupItemProps<T>>
) => {
const [local, others] = splitProps(props as RadioGroupItemProps, [
'class',
'children',
]);
return ( return (
<RadioGroupPrimitive.Item <RadioGroupPrimitive.Item
class={cn('flex items-center space-x-2', local.class)} data-slot="radio-group-item"
{...others} className={cn(
> "border-input text-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 aspect-square size-4 shrink-0 rounded-full border shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
<RadioGroupPrimitive.ItemInput /> className
<RadioGroupPrimitive.ItemControl class="aspect-square size-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50">
<RadioGroupPrimitive.ItemIndicator class="flex h-full items-center justify-center ">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-2.5 fill-current text-current"
>
<path d="M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" />
</svg>
</RadioGroupPrimitive.ItemIndicator>
</RadioGroupPrimitive.ItemControl>
{local.children}
</RadioGroupPrimitive.Item>
);
};
type RadioGroupLabelProps<T extends ValidComponent = 'label'> =
RadioGroupPrimitive.RadioGroupLabelProps<T> & {
class?: string | undefined;
};
const RadioGroupItemLabel = <T extends ValidComponent = 'label'>(
props: PolymorphicProps<T, RadioGroupLabelProps<T>>
) => {
const [local, others] = splitProps(props as RadioGroupLabelProps, ['class']);
return (
<RadioGroupPrimitive.ItemLabel
class={cn(
'font-medium text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70',
local.class
)} )}
{...others} {...props}
/> >
); <RadioGroupPrimitive.Indicator
}; data-slot="radio-group-indicator"
className="relative flex items-center justify-center"
>
<CircleIcon className="fill-primary absolute top-1/2 left-1/2 size-2 -translate-x-1/2 -translate-y-1/2" />
</RadioGroupPrimitive.Indicator>
</RadioGroupPrimitive.Item>
)
}
export { RadioGroup, RadioGroupItem, RadioGroupItemLabel }; export { RadioGroup, RadioGroupItem }

View File

@ -1,76 +1,54 @@
import type { ValidComponent } from 'solid-js'; import * as React from "react"
import { Show, splitProps } from 'solid-js'; import { GripVerticalIcon } from "lucide-react"
import * as ResizablePrimitive from "react-resizable-panels"
import type { DynamicProps, HandleProps, RootProps } from '@corvu/resizable'; import { cn } from "@/styles/utils"
import ResizablePrimitive from '@corvu/resizable';
import { cn } from '~/utils/styles'; function ResizablePanelGroup({
className,
type ResizableProps<T extends ValidComponent = 'div'> = RootProps<T> & { ...props
class?: string; }: React.ComponentProps<typeof ResizablePrimitive.PanelGroup>) {
};
const Resizable = <T extends ValidComponent = 'div'>(
props: DynamicProps<T, ResizableProps<T>>
) => {
const [, rest] = splitProps(props as ResizableProps, ['class']);
return ( return (
<ResizablePrimitive <ResizablePrimitive.PanelGroup
class={cn( data-slot="resizable-panel-group"
'flex size-full data-[orientation=vertical]:flex-col', className={cn(
props.class "flex h-full w-full data-[panel-group-direction=vertical]:flex-col",
className
)} )}
{...rest} {...props}
/> />
); )
}; }
const ResizablePanel = ResizablePrimitive.Panel; function ResizablePanel({
...props
}: React.ComponentProps<typeof ResizablePrimitive.Panel>) {
return <ResizablePrimitive.Panel data-slot="resizable-panel" {...props} />
}
type ResizableHandleProps<T extends ValidComponent = 'button'> = function ResizableHandle({
HandleProps<T> & { withHandle,
class?: string; className,
withHandle?: boolean; ...props
}; }: React.ComponentProps<typeof ResizablePrimitive.PanelResizeHandle> & {
withHandle?: boolean
const ResizableHandle = <T extends ValidComponent = 'button'>( }) {
props: DynamicProps<T, ResizableHandleProps<T>>
) => {
const [, rest] = splitProps(props as ResizableHandleProps, [
'class',
'withHandle',
]);
return ( return (
<ResizablePrimitive.Handle <ResizablePrimitive.PanelResizeHandle
class={cn( data-slot="resizable-handle"
'after:-translate-x-1/2 data-[orientation=vertical]:after:-translate-y-1/2 relative flex w-px shrink-0 items-center justify-center bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[orientation=vertical]:h-px data-[orientation=vertical]:w-full data-[orientation=vertical]:after:left-0 data-[orientation=vertical]:after:h-1 data-[orientation=vertical]:after:w-full data-[orientation=vertical]:after:translate-x-0 [&[data-orientation=vertical]>div]:rotate-90', className={cn(
props.class "bg-border focus-visible:ring-ring relative flex w-px items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:outline-hidden data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",
className
)} )}
{...rest} {...props}
> >
<Show when={props.withHandle}> {withHandle && (
<div class="z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border"> <div className="bg-border z-10 flex h-4 w-3 items-center justify-center rounded-xs border">
<svg <GripVerticalIcon className="size-2.5" />
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-2.5"
>
<path d="M9 5m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
<path d="M9 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
<path d="M9 19m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
<path d="M15 5m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
<path d="M15 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
<path d="M15 19m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
</svg>
</div> </div>
</Show> )}
</ResizablePrimitive.Handle> </ResizablePrimitive.PanelResizeHandle>
); )
}; }
export { Resizable, ResizablePanel, ResizableHandle }; export { ResizablePanelGroup, ResizablePanel, ResizableHandle }

View File

@ -0,0 +1,58 @@
"use client"
import * as React from "react"
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"
import { cn } from "@/styles/utils"
function ScrollArea({
className,
children,
...props
}: React.ComponentProps<typeof ScrollAreaPrimitive.Root>) {
return (
<ScrollAreaPrimitive.Root
data-slot="scroll-area"
className={cn("relative", className)}
{...props}
>
<ScrollAreaPrimitive.Viewport
data-slot="scroll-area-viewport"
className="focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1"
>
{children}
</ScrollAreaPrimitive.Viewport>
<ScrollBar />
<ScrollAreaPrimitive.Corner />
</ScrollAreaPrimitive.Root>
)
}
function ScrollBar({
className,
orientation = "vertical",
...props
}: React.ComponentProps<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>) {
return (
<ScrollAreaPrimitive.ScrollAreaScrollbar
data-slot="scroll-area-scrollbar"
orientation={orientation}
className={cn(
"flex touch-none p-px transition-colors select-none",
orientation === "vertical" &&
"h-full w-2.5 border-l border-l-transparent",
orientation === "horizontal" &&
"h-2.5 flex-col border-t border-t-transparent",
className
)}
{...props}
>
<ScrollAreaPrimitive.ScrollAreaThumb
data-slot="scroll-area-thumb"
className="bg-border relative flex-1 rounded-full"
/>
</ScrollAreaPrimitive.ScrollAreaScrollbar>
)
}
export { ScrollArea, ScrollBar }

View File

@ -1,198 +1,183 @@
import type { JSX, ValidComponent } from 'solid-js'; import * as React from "react"
import { splitProps } from 'solid-js'; import * as SelectPrimitive from "@radix-ui/react-select"
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"
import type { PolymorphicProps } from '@kobalte/core/polymorphic'; import { cn } from "@/styles/utils"
import * as SelectPrimitive from '@kobalte/core/select';
import { cva } from 'class-variance-authority';
import { cn } from '~/utils/styles'; function Select({
...props
}: React.ComponentProps<typeof SelectPrimitive.Root>) {
return <SelectPrimitive.Root data-slot="select" {...props} />
}
const Select = SelectPrimitive.Root; function SelectGroup({
const SelectValue = SelectPrimitive.Value; ...props
const SelectHiddenSelect = SelectPrimitive.HiddenSelect; }: React.ComponentProps<typeof SelectPrimitive.Group>) {
return <SelectPrimitive.Group data-slot="select-group" {...props} />
}
type SelectTriggerProps<T extends ValidComponent = 'button'> = function SelectValue({
SelectPrimitive.SelectTriggerProps<T> & { ...props
class?: string | undefined; }: React.ComponentProps<typeof SelectPrimitive.Value>) {
children?: JSX.Element; return <SelectPrimitive.Value data-slot="select-value" {...props} />
}; }
const SelectTrigger = <T extends ValidComponent = 'button'>( function SelectTrigger({
props: PolymorphicProps<T, SelectTriggerProps<T>> className,
) => { size = "default",
const [local, others] = splitProps(props as SelectTriggerProps, [ children,
'class', ...props
'children', }: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
]); size?: "sm" | "default"
}) {
return ( return (
<SelectPrimitive.Trigger <SelectPrimitive.Trigger
class={cn( data-slot="select-trigger"
'flex h-10 w-full items-center justify-between rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50', data-size={size}
local.class className={cn(
"border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)} )}
{...others} {...props}
> >
{local.children} {children}
<SelectPrimitive.Icon <SelectPrimitive.Icon asChild>
as="svg" <ChevronDownIcon className="size-4 opacity-50" />
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4 opacity-50"
>
<path d="M8 9l4 -4l4 4" />
<path d="M16 15l-4 4l-4 -4" />
</SelectPrimitive.Icon> </SelectPrimitive.Icon>
</SelectPrimitive.Trigger> </SelectPrimitive.Trigger>
); )
}; }
type SelectContentProps<T extends ValidComponent = 'div'> = function SelectContent({
SelectPrimitive.SelectContentProps<T> & { class?: string | undefined }; className,
children,
const SelectContent = <T extends ValidComponent = 'div'>( position = "popper",
props: PolymorphicProps<T, SelectContentProps<T>> ...props
) => { }: React.ComponentProps<typeof SelectPrimitive.Content>) {
const [local, others] = splitProps(props as SelectContentProps, ['class']);
return ( return (
<SelectPrimitive.Portal> <SelectPrimitive.Portal>
<SelectPrimitive.Content <SelectPrimitive.Content
class={cn( data-slot="select-content"
'fade-in-80 relative z-50 min-w-32 animate-in overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md', className={cn(
local.class "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",
position === "popper" &&
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
className
)} )}
{...others} position={position}
{...props}
> >
<SelectPrimitive.Listbox class="m-0 p-1" /> <SelectScrollUpButton />
<SelectPrimitive.Viewport
className={cn(
"p-1",
position === "popper" &&
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"
)}
>
{children}
</SelectPrimitive.Viewport>
<SelectScrollDownButton />
</SelectPrimitive.Content> </SelectPrimitive.Content>
</SelectPrimitive.Portal> </SelectPrimitive.Portal>
); )
}; }
type SelectItemProps<T extends ValidComponent = 'li'> = function SelectLabel({
SelectPrimitive.SelectItemProps<T> & { className,
class?: string | undefined; ...props
children?: JSX.Element; }: React.ComponentProps<typeof SelectPrimitive.Label>) {
};
const SelectItem = <T extends ValidComponent = 'li'>(
props: PolymorphicProps<T, SelectItemProps<T>>
) => {
const [local, others] = splitProps(props as SelectItemProps, [
'class',
'children',
]);
return (
<SelectPrimitive.Item
class={cn(
'relative mt-0 flex w-full cursor-default select-none items-center rounded-sm py-1.5 pr-8 pl-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
local.class
)}
{...others}
>
<SelectPrimitive.ItemIndicator class="absolute right-2 flex size-3.5 items-center justify-center">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M5 12l5 5l10 -10" />
</svg>
</SelectPrimitive.ItemIndicator>
<SelectPrimitive.ItemLabel>{local.children}</SelectPrimitive.ItemLabel>
</SelectPrimitive.Item>
);
};
const labelVariants = cva(
'font-medium text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70',
{
variants: {
variant: {
label: 'data-[invalid]:text-destructive',
description: 'font-normal text-muted-foreground',
error: 'text-destructive text-xs',
},
},
defaultVariants: {
variant: 'label',
},
}
);
type SelectLabelProps<T extends ValidComponent = 'label'> =
SelectPrimitive.SelectLabelProps<T> & {
class?: string | undefined;
};
const SelectLabel = <T extends ValidComponent = 'label'>(
props: PolymorphicProps<T, SelectLabelProps<T>>
) => {
const [local, others] = splitProps(props as SelectLabelProps, ['class']);
return ( return (
<SelectPrimitive.Label <SelectPrimitive.Label
class={cn(labelVariants(), local.class)} data-slot="select-label"
{...others} className={cn("text-muted-foreground px-2 py-1.5 text-xs", className)}
{...props}
/> />
); )
}; }
type SelectDescriptionProps<T extends ValidComponent = 'div'> = function SelectItem({
SelectPrimitive.SelectDescriptionProps<T> & { className,
class?: string | undefined; children,
}; ...props
}: React.ComponentProps<typeof SelectPrimitive.Item>) {
const SelectDescription = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, SelectDescriptionProps<T>>
) => {
const [local, others] = splitProps(props as SelectDescriptionProps, [
'class',
]);
return ( return (
<SelectPrimitive.Description <SelectPrimitive.Item
class={cn(labelVariants({ variant: 'description' }), local.class)} data-slot="select-item"
{...others} className={cn(
/> "focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
); className
}; )}
{...props}
>
<span className="absolute right-2 flex size-3.5 items-center justify-center">
<SelectPrimitive.ItemIndicator>
<CheckIcon className="size-4" />
</SelectPrimitive.ItemIndicator>
</span>
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
</SelectPrimitive.Item>
)
}
type SelectErrorMessageProps<T extends ValidComponent = 'div'> = function SelectSeparator({
SelectPrimitive.SelectErrorMessageProps<T> & { className,
class?: string | undefined; ...props
}; }: React.ComponentProps<typeof SelectPrimitive.Separator>) {
const SelectErrorMessage = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, SelectErrorMessageProps<T>>
) => {
const [local, others] = splitProps(props as SelectErrorMessageProps, [
'class',
]);
return ( return (
<SelectPrimitive.ErrorMessage <SelectPrimitive.Separator
class={cn(labelVariants({ variant: 'error' }), local.class)} data-slot="select-separator"
{...others} className={cn("bg-border pointer-events-none -mx-1 my-1 h-px", className)}
{...props}
/> />
); )
}; }
function SelectScrollUpButton({
className,
...props
}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
return (
<SelectPrimitive.ScrollUpButton
data-slot="select-scroll-up-button"
className={cn(
"flex cursor-default items-center justify-center py-1",
className
)}
{...props}
>
<ChevronUpIcon className="size-4" />
</SelectPrimitive.ScrollUpButton>
)
}
function SelectScrollDownButton({
className,
...props
}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
return (
<SelectPrimitive.ScrollDownButton
data-slot="select-scroll-down-button"
className={cn(
"flex cursor-default items-center justify-center py-1",
className
)}
{...props}
>
<ChevronDownIcon className="size-4" />
</SelectPrimitive.ScrollDownButton>
)
}
export { export {
Select, Select,
SelectValue,
SelectHiddenSelect,
SelectTrigger,
SelectContent, SelectContent,
SelectGroup,
SelectItem, SelectItem,
SelectLabel, SelectLabel,
SelectDescription, SelectScrollDownButton,
SelectErrorMessage, SelectScrollUpButton,
}; SelectSeparator,
SelectTrigger,
SelectValue,
}

View File

@ -1,32 +1,28 @@
import type { ValidComponent } from 'solid-js'; "use client"
import { splitProps } from 'solid-js';
import type { PolymorphicProps } from '@kobalte/core/polymorphic'; import * as React from "react"
import * as SeparatorPrimitive from '@kobalte/core/separator'; import * as SeparatorPrimitive from "@radix-ui/react-separator"
import { cn } from '~/utils/styles'; import { cn } from "@/styles/utils"
type SeparatorRootProps<T extends ValidComponent = 'hr'> = function Separator({
SeparatorPrimitive.SeparatorRootProps<T> & { class?: string | undefined }; className,
orientation = "horizontal",
const Separator = <T extends ValidComponent = 'hr'>( decorative = true,
props: PolymorphicProps<T, SeparatorRootProps<T>> ...props
) => { }: React.ComponentProps<typeof SeparatorPrimitive.Root>) {
const [local, others] = splitProps(props as SeparatorRootProps, [
'class',
'orientation',
]);
return ( return (
<SeparatorPrimitive.Root <SeparatorPrimitive.Root
orientation={local.orientation ?? 'horizontal'} data-slot="separator-root"
class={cn( decorative={decorative}
'shrink-0 bg-border', orientation={orientation}
local.orientation === 'vertical' ? 'h-full w-px' : 'h-px w-full', className={cn(
local.class "bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
className
)} )}
{...others} {...props}
/> />
); )
}; }
export { Separator }; export { Separator }

View File

@ -1,188 +1,129 @@
import type { Component, ComponentProps, JSX, ValidComponent } from 'solid-js'; import * as React from "react"
import { splitProps } from 'solid-js'; import * as SheetPrimitive from "@radix-ui/react-dialog"
import { XIcon } from "lucide-react"
import * as SheetPrimitive from '@kobalte/core/dialog'; import { cn } from "@/styles/utils"
import type { PolymorphicProps } from '@kobalte/core/polymorphic';
import { type VariantProps, cva } from 'class-variance-authority';
import { cn } from '~/utils/styles'; function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) {
return <SheetPrimitive.Root data-slot="sheet" {...props} />
}
const Sheet = SheetPrimitive.Root; function SheetTrigger({
const SheetTrigger = SheetPrimitive.Trigger; ...props
const SheetClose = SheetPrimitive.CloseButton; }: React.ComponentProps<typeof SheetPrimitive.Trigger>) {
return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />
}
const portalVariants = cva('fixed inset-0 z-50 flex', { function SheetClose({
variants: { ...props
position: { }: React.ComponentProps<typeof SheetPrimitive.Close>) {
top: 'items-start', return <SheetPrimitive.Close data-slot="sheet-close" {...props} />
bottom: 'items-end', }
left: 'justify-start',
right: 'justify-end',
},
},
defaultVariants: { position: 'right' },
});
type PortalProps = SheetPrimitive.DialogPortalProps & function SheetPortal({
VariantProps<typeof portalVariants>; ...props
}: React.ComponentProps<typeof SheetPrimitive.Portal>) {
return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />
}
const SheetPortal: Component<PortalProps> = (props) => { function SheetOverlay({
const [local, others] = splitProps(props, ['position', 'children']); className,
return ( ...props
<SheetPrimitive.Portal {...others}> }: React.ComponentProps<typeof SheetPrimitive.Overlay>) {
<div class={portalVariants({ position: local.position })}>
{local.children}
</div>
</SheetPrimitive.Portal>
);
};
type DialogOverlayProps<T extends ValidComponent = 'div'> =
SheetPrimitive.DialogOverlayProps<T> & {
class?: string | undefined;
};
const SheetOverlay = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, DialogOverlayProps<T>>
) => {
const [local, others] = splitProps(props as DialogOverlayProps, ['class']);
return ( return (
<SheetPrimitive.Overlay <SheetPrimitive.Overlay
class={cn( data-slot="sheet-overlay"
'data-[closed=]:fade-out-0 data-[expanded=]:fade-in-0 fixed inset-0 z-50 bg-black/80 data-[closed=]:animate-out data-[expanded=]:animate-in', className={cn(
local.class "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
className
)} )}
{...others} {...props}
/> />
); )
}; }
const sheetVariants = cva( function SheetContent({
'fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[closed=]:animate-out data-[expanded=]:animate-in data-[closed=]:duration-300 data-[expanded=]:duration-500', className,
{ children,
variants: { side = "right",
position: { ...props
top: 'data-[closed=]:slide-out-to-top data-[expanded=]:slide-in-from-top inset-x-0 top-0 border-b', }: React.ComponentProps<typeof SheetPrimitive.Content> & {
bottom: side?: "top" | "right" | "bottom" | "left"
'data-[closed=]:slide-out-to-bottom data-[expanded=]:slide-in-from-bottom inset-x-0 bottom-0 border-t', }) {
left: 'data-[closed=]:slide-out-to-left data-[expanded=]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm',
right:
'data-[closed=]:slide-out-to-right data-[expanded=]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm',
},
},
defaultVariants: {
position: 'right',
},
}
);
type DialogContentProps<T extends ValidComponent = 'div'> =
SheetPrimitive.DialogContentProps<T> &
VariantProps<typeof sheetVariants> & {
class?: string | undefined;
children?: JSX.Element;
};
const SheetContent = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, DialogContentProps<T>>
) => {
const [local, others] = splitProps(props as DialogContentProps, [
'position',
'class',
'children',
]);
return ( return (
<SheetPortal position={local.position}> <SheetPortal>
<SheetOverlay /> <SheetOverlay />
<SheetPrimitive.Content <SheetPrimitive.Content
class={cn( data-slot="sheet-content"
sheetVariants({ position: local.position }), className={cn(
local.class, "bg-background data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
'max-h-screen overflow-y-auto' side === "right" &&
"data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm",
side === "left" &&
"data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm",
side === "top" &&
"data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b",
side === "bottom" &&
"data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t",
className
)} )}
{...others} {...props}
> >
{local.children} {children}
<SheetPrimitive.CloseButton class="absolute top-4 right-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary"> <SheetPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none">
<svg <XIcon className="size-4" />
xmlns="http://www.w3.org/2000/svg" <span className="sr-only">Close</span>
viewBox="0 0 24 24" </SheetPrimitive.Close>
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M18 6l-12 12" />
<path d="M6 6l12 12" />
</svg>
<span class="sr-only">Close</span>
</SheetPrimitive.CloseButton>
</SheetPrimitive.Content> </SheetPrimitive.Content>
</SheetPortal> </SheetPortal>
); )
}; }
const SheetHeader: Component<ComponentProps<'div'>> = (props) => { function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {
const [local, others] = splitProps(props, ['class']);
return ( return (
<div <div
class={cn( data-slot="sheet-header"
'flex flex-col space-y-2 text-center sm:text-left', className={cn("flex flex-col gap-1.5 p-4", className)}
local.class {...props}
)}
{...others}
/> />
); )
}; }
const SheetFooter: Component<ComponentProps<'div'>> = (props) => { function SheetFooter({ className, ...props }: React.ComponentProps<"div">) {
const [local, others] = splitProps(props, ['class']);
return ( return (
<div <div
class={cn( data-slot="sheet-footer"
'flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2', className={cn("mt-auto flex flex-col gap-2 p-4", className)}
local.class {...props}
)}
{...others}
/> />
); )
}; }
type DialogTitleProps<T extends ValidComponent = 'h2'> = function SheetTitle({
SheetPrimitive.DialogTitleProps<T> & { className,
class?: string | undefined; ...props
}; }: React.ComponentProps<typeof SheetPrimitive.Title>) {
const SheetTitle = <T extends ValidComponent = 'h2'>(
props: PolymorphicProps<T, DialogTitleProps<T>>
) => {
const [local, others] = splitProps(props as DialogTitleProps, ['class']);
return ( return (
<SheetPrimitive.Title <SheetPrimitive.Title
class={cn('font-semibold text-foreground text-lg', local.class)} data-slot="sheet-title"
{...others} className={cn("text-foreground font-semibold", className)}
{...props}
/> />
); )
}; }
type DialogDescriptionProps<T extends ValidComponent = 'p'> = function SheetDescription({
SheetPrimitive.DialogDescriptionProps<T> & { class?: string | undefined }; className,
...props
const SheetDescription = <T extends ValidComponent = 'p'>( }: React.ComponentProps<typeof SheetPrimitive.Description>) {
props: PolymorphicProps<T, DialogDescriptionProps<T>>
) => {
const [local, others] = splitProps(props as DialogDescriptionProps, [
'class',
]);
return ( return (
<SheetPrimitive.Description <SheetPrimitive.Description
class={cn('text-muted-foreground text-sm', local.class)} data-slot="sheet-description"
{...others} className={cn("text-muted-foreground text-sm", className)}
{...props}
/> />
); )
}; }
export { export {
Sheet, Sheet,
@ -193,4 +134,4 @@ export {
SheetFooter, SheetFooter,
SheetTitle, SheetTitle,
SheetDescription, SheetDescription,
}; }

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +1,13 @@
import type { ValidComponent } from 'solid-js'; import { cn } from "@/styles/utils"
import { splitProps } from 'solid-js';
import type { PolymorphicProps } from '@kobalte/core/polymorphic'; function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
import * as SkeletonPrimitive from '@kobalte/core/skeleton';
import { cn } from '~/utils/styles';
type SkeletonRootProps<T extends ValidComponent = 'div'> =
SkeletonPrimitive.SkeletonRootProps<T> & { class?: string | undefined };
const Skeleton = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, SkeletonRootProps<T>>
) => {
const [local, others] = splitProps(props as SkeletonRootProps, ['class']);
return ( return (
<SkeletonPrimitive.Root <div
class={cn( data-slot="skeleton"
"bg-primary/10 data-[animate='true']:animate-pulse", className={cn("bg-accent animate-pulse rounded-md", className)}
local.class {...props}
)}
{...others}
/> />
); )
}; }
export { Skeleton }; export { Skeleton }

View File

@ -1,112 +1,63 @@
import type { JSX, ValidComponent } from 'solid-js'; "use client"
import { splitProps } from 'solid-js';
import type { PolymorphicProps } from '@kobalte/core/polymorphic'; import * as React from "react"
import * as SliderPrimitive from '@kobalte/core/slider'; import * as SliderPrimitive from "@radix-ui/react-slider"
import { Label } from '~/components/ui/label'; import { cn } from "@/styles/utils"
import { cn } from '~/utils/styles';
type SliderRootProps<T extends ValidComponent = 'div'> = function Slider({
SliderPrimitive.SliderRootProps<T> & { className,
class?: string | undefined; defaultValue,
}; value,
min = 0,
max = 100,
...props
}: React.ComponentProps<typeof SliderPrimitive.Root>) {
const _values = React.useMemo(
() =>
Array.isArray(value)
? value
: Array.isArray(defaultValue)
? defaultValue
: [min, max],
[value, defaultValue, min, max]
)
const Slider = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, SliderRootProps<T>>
) => {
const [local, others] = splitProps(props as SliderRootProps, ['class']);
return ( return (
<SliderPrimitive.Root <SliderPrimitive.Root
class={cn( data-slot="slider"
'relative flex w-full touch-none select-none flex-col items-center', defaultValue={defaultValue}
local.class value={value}
min={min}
max={max}
className={cn(
"relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",
className
)} )}
{...others} {...props}
/>
);
};
type SliderTrackProps<T extends ValidComponent = 'div'> =
SliderPrimitive.SliderTrackProps<T> & {
class?: string | undefined;
};
const SliderTrack = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, SliderTrackProps<T>>
) => {
const [local, others] = splitProps(props as SliderTrackProps, ['class']);
return (
<SliderPrimitive.Track
class={cn(
'relative h-2 w-full grow rounded-full bg-secondary',
local.class
)}
{...others}
/>
);
};
type SliderFillProps<T extends ValidComponent = 'div'> =
SliderPrimitive.SliderFillProps<T> & {
class?: string | undefined;
};
const SliderFill = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, SliderFillProps<T>>
) => {
const [local, others] = splitProps(props as SliderFillProps, ['class']);
return (
<SliderPrimitive.Fill
class={cn('absolute h-full rounded-full bg-primary', local.class)}
{...others}
/>
);
};
type SliderThumbProps<T extends ValidComponent = 'span'> =
SliderPrimitive.SliderThumbProps<T> & {
class?: string | undefined;
children?: JSX.Element;
};
const SliderThumb = <T extends ValidComponent = 'span'>(
props: PolymorphicProps<T, SliderThumbProps<T>>
) => {
const [local, others] = splitProps(props as SliderThumbProps, [
'class',
'children',
]);
return (
<SliderPrimitive.Thumb
class={cn(
'top-[-6px] block size-5 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
local.class
)}
{...others}
> >
<SliderPrimitive.Input /> <SliderPrimitive.Track
</SliderPrimitive.Thumb> data-slot="slider-track"
); className={cn(
}; "bg-muted relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5"
)}
>
<SliderPrimitive.Range
data-slot="slider-range"
className={cn(
"bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full"
)}
/>
</SliderPrimitive.Track>
{Array.from({ length: _values.length }, (_, index) => (
<SliderPrimitive.Thumb
data-slot="slider-thumb"
key={index}
className="border-primary bg-background ring-ring/50 block size-4 shrink-0 rounded-full border shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
/>
))}
</SliderPrimitive.Root>
)
}
const SliderLabel = <T extends ValidComponent = 'label'>( export { Slider }
props: PolymorphicProps<T, SliderPrimitive.SliderLabelProps<T>>
) => {
return <SliderPrimitive.Label as={Label} {...props} />;
};
const SliderValueLabel = <T extends ValidComponent = 'label'>(
props: PolymorphicProps<T, SliderPrimitive.SliderValueLabelProps<T>>
) => {
return <SliderPrimitive.ValueLabel as={Label} {...props} />;
};
export {
Slider,
SliderTrack,
SliderFill,
SliderThumb,
SliderLabel,
SliderValueLabel,
};

View File

@ -1,22 +1,20 @@
import type { Component, ComponentProps } from "solid-js" import { useTheme } from "next-themes"
import { Toaster as Sonner, ToasterProps } from "sonner"
import { Toaster as Sonner } from "solid-sonner" const Toaster = ({ ...props }: ToasterProps) => {
const { theme = "system" } = useTheme()
type ToasterProps = ComponentProps<typeof Sonner>
const Toaster: Component<ToasterProps> = (props) => {
return ( return (
<Sonner <Sonner
class="toaster group" theme={theme as ToasterProps["theme"]}
toastOptions={{ className="toaster group"
classes: { style={
toast: {
"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg", "--normal-bg": "var(--popover)",
description: "group-[.toast]:text-muted-foreground", "--normal-text": "var(--popover-foreground)",
actionButton: "group-[.toast]:bg-primary group-[.toast]:text-primary-foreground", "--normal-border": "var(--border)",
cancelButton: "group-[.toast]:bg-muted group-[.toast]:text-muted-foreground" } as React.CSSProperties
} }
}}
{...props} {...props}
/> />
) )

View File

@ -1,50 +1,47 @@
import { cn } from '@/styles/utils';
import { import {
LoaderCircleIcon, Loader,
LoaderIcon, LoaderCircle,
LoaderPinwheelIcon, LoaderPinwheel,
type LucideProps, type LucideProps,
} from 'lucide-solid'; } from 'lucide-react';
import { mergeProps, splitProps } from 'solid-js';
import { cn } from '~/utils/styles';
type SpinnerVariantProps = Omit<SpinnerProps, 'variant'>; export type SpinnerVariantProps = Omit<SpinnerProps, 'variant'>;
const Default = (props: SpinnerVariantProps) => { const Default = ({ className, ...props }: SpinnerVariantProps) => {
const [local, other] = splitProps(props, ['class']); return <Loader className={cn('animate-spin', className)} {...props} />;
return <LoaderIcon class={cn('animate-spin', local.class)} {...other} />;
}; };
const Circle = (props: SpinnerVariantProps) => { const Circle = ({ className, ...props }: SpinnerVariantProps) => {
const [local, other] = splitProps(props, ['class']); return <LoaderCircle className={cn('animate-spin', className)} {...props} />;
};
const Pinwheel = ({ className, ...props }: SpinnerVariantProps) => {
return ( return (
<LoaderCircleIcon class={cn('animate-spin', local.class)} {...other} /> <LoaderPinwheel className={cn('animate-spin', className)} {...props} />
); );
}; };
const Pinwheel = (props: SpinnerVariantProps) => { const CircleFilled = ({
const [local, other] = splitProps(props, ['class']); className,
size = 24,
...props
}: SpinnerVariantProps) => {
return ( return (
<LoaderPinwheelIcon class={cn('animate-spin', local.class)} {...other} /> <div className="relative" style={{ width: size, height: size }}>
); <div className="absolute inset-0 rotate-180">
}; <LoaderCircle
className={cn(
const CircleFilled = (props: SpinnerVariantProps) => { 'animate-spin',
const [local, _] = splitProps(mergeProps({ size: 24 }, props), [ className,
'class', 'text-foreground opacity-20'
'size', )}
]);
const size = `${local.size}`;
return (
<div class="relative" style={{ width: size, height: size }}>
<div class="absolute inset-0 rotate-180">
<LoaderCircleIcon
class={cn('animate-spin', local.class, 'text-foreground opacity-20')}
size={size} size={size}
{...props} {...props}
/> />
</div> </div>
<LoaderCircleIcon <LoaderCircle
class={cn('relative animate-spin', local.class)} className={cn('relative animate-spin', className)}
size={size} size={size}
{...props} {...props}
/> />
@ -52,15 +49,14 @@ const CircleFilled = (props: SpinnerVariantProps) => {
); );
}; };
const Ellipsis = (props: SpinnerVariantProps) => { const Ellipsis = ({ size = 24, ...props }: SpinnerVariantProps) => {
const [{ size = 24 }, other] = splitProps(props, ['size']);
return ( return (
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
width={size} width={size}
height={size} height={size}
viewBox="0 0 24 24" viewBox="0 0 24 24"
{...other} {...props}
> >
<title>Loading...</title> <title>Loading...</title>
<circle cx="4" cy="12" r="2" fill="currentColor"> <circle cx="4" cy="12" r="2" fill="currentColor">
@ -99,8 +95,7 @@ const Ellipsis = (props: SpinnerVariantProps) => {
); );
}; };
const Ring = (props: SpinnerVariantProps) => { const Ring = ({ size = 24, ...props }: SpinnerVariantProps) => {
const [{ size = 24 }, other] = splitProps(props, ['size']);
return ( return (
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
@ -108,10 +103,10 @@ const Ring = (props: SpinnerVariantProps) => {
height={size} height={size}
viewBox="0 0 44 44" viewBox="0 0 44 44"
stroke="currentColor" stroke="currentColor"
{...other} {...props}
> >
<title>Loading...</title> <title>Loading...</title>
<g fill="none" fill-rule="evenodd" stroke-width="2"> <g fill="none" fillRule="evenodd" strokeWidth="2">
<circle cx="22" cy="22" r="1"> <circle cx="22" cy="22" r="1">
<animate <animate
attributeName="r" attributeName="r"
@ -171,30 +166,30 @@ const Bars = ({ size = 24, ...props }: SpinnerVariantProps) => (
> >
<title>Loading...</title> <title>Loading...</title>
<style>{` <style>{`
.spinner-bar { .spinner-bar {
animation: spinner-bars-animation .8s linear infinite; animation: spinner-bars-animation .8s linear infinite;
animation-delay: -.8s; animation-delay: -.8s;
}
.spinner-bars-2 {
animation-delay: -.65s;
}
.spinner-bars-3 {
animation-delay: -0.5s;
}
@keyframes spinner-bars-animation {
0% {
y: 1px;
height: 22px;
} }
93.75% { .spinner-bars-2 {
y: 5px; animation-delay: -.65s;
height: 14px;
opacity: 0.2;
} }
} .spinner-bars-3 {
`}</style> animation-delay: -0.5s;
}
@keyframes spinner-bars-animation {
0% {
y: 1px;
height: 22px;
}
93.75% {
y: 5px;
height: 14px;
opacity: 0.2;
}
}
`}</style>
<rect <rect
class="spinner-bar" className="spinner-bar"
x="1" x="1"
y="1" y="1"
width="6" width="6"
@ -202,7 +197,7 @@ const Bars = ({ size = 24, ...props }: SpinnerVariantProps) => (
fill="currentColor" fill="currentColor"
/> />
<rect <rect
class="spinner-bar spinner-bars-2" className="spinner-bar spinner-bars-2"
x="9" x="9"
y="1" y="1"
width="6" width="6"
@ -210,7 +205,7 @@ const Bars = ({ size = 24, ...props }: SpinnerVariantProps) => (
fill="currentColor" fill="currentColor"
/> />
<rect <rect
class="spinner-bar spinner-bars-3" className="spinner-bar spinner-bars-3"
x="17" x="17"
y="1" y="1"
width="6" width="6"
@ -233,13 +228,13 @@ const Infinite = ({ size = 24, ...props }: SpinnerVariantProps) => (
<path <path
fill="none" fill="none"
stroke="currentColor" stroke="currentColor"
stroke-width="10" strokeWidth="10"
stroke-dasharray="205.271142578125 51.317785644531256" strokeDasharray="205.271142578125 51.317785644531256"
d="M24.3 30C11.4 30 5 43.3 5 50s6.4 20 19.3 20c19.3 0 32.1-40 51.4-40 C88.6 30 95 43.3 95 50s-6.4 20-19.3 20C56.4 70 43.6 30 24.3 30z" d="M24.3 30C11.4 30 5 43.3 5 50s6.4 20 19.3 20c19.3 0 32.1-40 51.4-40 C88.6 30 95 43.3 95 50s-6.4 20-19.3 20C56.4 70 43.6 30 24.3 30z"
stroke-linecap="round" strokeLinecap="round"
style={{ style={{
transform: 'scale(0.8)', transform: 'scale(0.8)',
'transform-origin': '50px 50px', transformOrigin: '50px 50px',
}} }}
> >
<animate <animate

View File

@ -1,91 +1,31 @@
import type { JSX, ValidComponent } from 'solid-js'; "use client"
import { splitProps } from 'solid-js';
import type { PolymorphicProps } from '@kobalte/core'; import * as React from "react"
import * as SwitchPrimitive from '@kobalte/core/switch'; import * as SwitchPrimitive from "@radix-ui/react-switch"
import { cn } from '~/utils/styles'; import { cn } from "@/styles/utils"
const Switch = SwitchPrimitive.Root; function Switch({
const SwitchDescription = SwitchPrimitive.Description; className,
const SwitchErrorMessage = SwitchPrimitive.ErrorMessage; ...props
}: React.ComponentProps<typeof SwitchPrimitive.Root>) {
type SwitchControlProps = SwitchPrimitive.SwitchControlProps & {
class?: string | undefined;
children?: JSX.Element;
};
const SwitchControl = <T extends ValidComponent = 'input'>(
props: PolymorphicProps<T, SwitchControlProps>
) => {
const [local, others] = splitProps(props as SwitchControlProps, [
'class',
'children',
]);
return ( return (
<> <SwitchPrimitive.Root
<SwitchPrimitive.Input data-slot="switch"
class={cn( className={cn(
'[&:focus-visible+div]:outline-none [&:focus-visible+div]:ring-2 [&:focus-visible+div]:ring-ring [&:focus-visible+div]:ring-offset-2 [&:focus-visible+div]:ring-offset-background', "peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
local.class className
)}
{...props}
>
<SwitchPrimitive.Thumb
data-slot="switch-thumb"
className={cn(
"bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0"
)} )}
/> />
<SwitchPrimitive.Control </SwitchPrimitive.Root>
class={cn( )
'inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent bg-input transition-[color,background-color,box-shadow] data-[disabled]:cursor-not-allowed data-[checked]:bg-primary data-[disabled]:opacity-50', }
local.class
)}
{...others}
>
{local.children}
</SwitchPrimitive.Control>
</>
);
};
type SwitchThumbProps = SwitchPrimitive.SwitchThumbProps & { export { Switch }
class?: string | undefined;
};
const SwitchThumb = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, SwitchThumbProps>
) => {
const [local, others] = splitProps(props as SwitchThumbProps, ['class']);
return (
<SwitchPrimitive.Thumb
class={cn(
'pointer-events-none block size-5 translate-x-0 rounded-full bg-background shadow-lg ring-0 transition-transform data-[checked]:translate-x-5',
local.class
)}
{...others}
/>
);
};
type SwitchLabelProps = SwitchPrimitive.SwitchLabelProps & {
class?: string | undefined;
};
const SwitchLabel = <T extends ValidComponent = 'label'>(
props: PolymorphicProps<T, SwitchLabelProps>
) => {
const [local, others] = splitProps(props as SwitchLabelProps, ['class']);
return (
<SwitchPrimitive.Label
class={cn(
'font-medium text-sm leading-none data-[disabled]:cursor-not-allowed data-[disabled]:opacity-70',
local.class
)}
{...others}
/>
);
};
export {
Switch,
SwitchControl,
SwitchThumb,
SwitchLabel,
SwitchDescription,
SwitchErrorMessage,
};

View File

@ -1,87 +1,106 @@
import type { Component, ComponentProps } from 'solid-js'; import * as React from "react"
import { splitProps } from 'solid-js';
import { cn } from '~/utils/styles'; import { cn } from "@/styles/utils"
const Table: Component<ComponentProps<'table'>> = (props) => { function Table({ className, ...props }: React.ComponentProps<"table">) {
const [local, others] = splitProps(props, ['class']);
return ( return (
<div class="relative w-full overflow-auto"> <div
data-slot="table-container"
className="relative w-full overflow-x-auto"
>
<table <table
class={cn('w-full caption-bottom text-sm', local.class)} data-slot="table"
{...others} className={cn("w-full caption-bottom text-sm", className)}
{...props}
/> />
</div> </div>
); )
}; }
const TableHeader: Component<ComponentProps<'thead'>> = (props) => { function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
const [local, others] = splitProps(props, ['class']);
return <thead class={cn('[&_tr]:border-b', local.class)} {...others} />;
};
const TableBody: Component<ComponentProps<'tbody'>> = (props) => {
const [local, others] = splitProps(props, ['class']);
return ( return (
<tbody class={cn('[&_tr:last-child]:border-0', local.class)} {...others} /> <thead
); data-slot="table-header"
}; className={cn("[&_tr]:border-b", className)}
{...props}
/>
)
}
const TableFooter: Component<ComponentProps<'tfoot'>> = (props) => { function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
const [local, others] = splitProps(props, ['class']); return (
<tbody
data-slot="table-body"
className={cn("[&_tr:last-child]:border-0", className)}
{...props}
/>
)
}
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
return ( return (
<tfoot <tfoot
class={cn('bg-primary font-medium text-primary-foreground', local.class)} data-slot="table-footer"
{...others} className={cn(
"bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",
className
)}
{...props}
/> />
); )
}; }
const TableRow: Component<ComponentProps<'tr'>> = (props) => { function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
const [local, others] = splitProps(props, ['class']);
return ( return (
<tr <tr
class={cn( data-slot="table-row"
'border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted', className={cn(
local.class "hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
className
)} )}
{...others} {...props}
/> />
); )
}; }
const TableHead: Component<ComponentProps<'th'>> = (props) => { function TableHead({ className, ...props }: React.ComponentProps<"th">) {
const [local, others] = splitProps(props, ['class']);
return ( return (
<th <th
class={cn( data-slot="table-head"
'h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0', className={cn(
local.class "text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
className
)} )}
{...others} {...props}
/> />
); )
}; }
const TableCell: Component<ComponentProps<'td'>> = (props) => { function TableCell({ className, ...props }: React.ComponentProps<"td">) {
const [local, others] = splitProps(props, ['class']);
return ( return (
<td <td
class={cn('p-2 align-middle [&:has([role=checkbox])]:pr-0', local.class)} data-slot="table-cell"
{...others} className={cn(
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
className
)}
{...props}
/> />
); )
}; }
const TableCaption: Component<ComponentProps<'caption'>> = (props) => { function TableCaption({
const [local, others] = splitProps(props, ['class']); className,
...props
}: React.ComponentProps<"caption">) {
return ( return (
<caption <caption
class={cn('mt-4 text-muted-foreground text-sm', local.class)} data-slot="table-caption"
{...others} className={cn("text-muted-foreground mt-4 text-sm", className)}
{...props}
/> />
); )
}; }
export { export {
Table, Table,
@ -92,4 +111,4 @@ export {
TableRow, TableRow,
TableCell, TableCell,
TableCaption, TableCaption,
}; }

View File

@ -1,91 +1,66 @@
import type { ValidComponent } from 'solid-js'; "use client"
import { splitProps } from 'solid-js';
import type { PolymorphicProps } from '@kobalte/core/polymorphic'; import * as React from "react"
import * as TabsPrimitive from '@kobalte/core/tabs'; import * as TabsPrimitive from "@radix-ui/react-tabs"
import { cn } from '~/utils/styles'; import { cn } from "@/styles/utils"
const Tabs = TabsPrimitive.Root; function Tabs({
className,
...props
}: React.ComponentProps<typeof TabsPrimitive.Root>) {
return (
<TabsPrimitive.Root
data-slot="tabs"
className={cn("flex flex-col gap-2", className)}
{...props}
/>
)
}
type TabsListProps<T extends ValidComponent = 'div'> = function TabsList({
TabsPrimitive.TabsListProps<T> & { className,
class?: string | undefined; ...props
}; }: React.ComponentProps<typeof TabsPrimitive.List>) {
const TabsList = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, TabsListProps<T>>
) => {
const [local, others] = splitProps(props as TabsListProps, ['class']);
return ( return (
<TabsPrimitive.List <TabsPrimitive.List
class={cn( data-slot="tabs-list"
'inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground', className={cn(
local.class "bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",
className
)} )}
{...others} {...props}
/> />
); )
}; }
type TabsTriggerProps<T extends ValidComponent = 'button'> = function TabsTrigger({
TabsPrimitive.TabsTriggerProps<T> & { className,
class?: string | undefined; ...props
}; }: React.ComponentProps<typeof TabsPrimitive.Trigger>) {
const TabsTrigger = <T extends ValidComponent = 'button'>(
props: PolymorphicProps<T, TabsTriggerProps<T>>
) => {
const [local, others] = splitProps(props as TabsTriggerProps, ['class']);
return ( return (
<TabsPrimitive.Trigger <TabsPrimitive.Trigger
class={cn( data-slot="tabs-trigger"
'inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 font-medium text-sm ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[selected]:bg-background data-[selected]:text-foreground data-[selected]:shadow-sm', className={cn(
local.class "data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)} )}
{...others} {...props}
/> />
); )
}; }
type TabsContentProps<T extends ValidComponent = 'div'> = function TabsContent({
TabsPrimitive.TabsContentProps<T> & { className,
class?: string | undefined; ...props
}; }: React.ComponentProps<typeof TabsPrimitive.Content>) {
const TabsContent = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, TabsContentProps<T>>
) => {
const [local, others] = splitProps(props as TabsContentProps, ['class']);
return ( return (
<TabsPrimitive.Content <TabsPrimitive.Content
class={cn( data-slot="tabs-content"
'mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2', className={cn("flex-1 outline-none", className)}
local.class {...props}
)}
{...others}
/> />
); )
}; }
type TabsIndicatorProps<T extends ValidComponent = 'div'> = export { Tabs, TabsList, TabsTrigger, TabsContent }
TabsPrimitive.TabsIndicatorProps<T> & {
class?: string | undefined;
};
const TabsIndicator = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, TabsIndicatorProps<T>>
) => {
const [local, others] = splitProps(props as TabsIndicatorProps, ['class']);
return (
<TabsPrimitive.Indicator
class={cn(
'data-[orientation=horizontal]:-bottom-px data-[orientation=vertical]:-right-px absolute transition-all duration-250ms data-[orientation=horizontal]:h-[2px] data-[orientation=vertical]:w-[2px]',
local.class
)}
{...others}
/>
);
};
export { Tabs, TabsList, TabsTrigger, TabsContent, TabsIndicator };

View File

@ -1,174 +0,0 @@
import type { ValidComponent } from 'solid-js';
import { mergeProps, splitProps } from 'solid-js';
import type { PolymorphicProps } from '@kobalte/core';
import * as TextFieldPrimitive from '@kobalte/core/text-field';
import { cva } from 'class-variance-authority';
import { cn } from '~/utils/styles';
type TextFieldRootProps<T extends ValidComponent = 'div'> =
TextFieldPrimitive.TextFieldRootProps<T> & {
class?: string | undefined;
};
const TextField = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, TextFieldRootProps<T>>
) => {
const [local, others] = splitProps(props as TextFieldRootProps, ['class']);
return (
<TextFieldPrimitive.Root
class={cn('flex flex-col gap-1', local.class)}
{...others}
/>
);
};
type TextFieldInputProps<T extends ValidComponent = 'input'> =
TextFieldPrimitive.TextFieldInputProps<T> & {
class?: string | undefined;
type?:
| 'button'
| 'checkbox'
| 'color'
| 'date'
| 'datetime-local'
| 'email'
| 'file'
| 'hidden'
| 'image'
| 'month'
| 'number'
| 'password'
| 'radio'
| 'range'
| 'reset'
| 'search'
| 'submit'
| 'tel'
| 'text'
| 'time'
| 'url'
| 'week';
};
const TextFieldInput = <T extends ValidComponent = 'input'>(
rawProps: PolymorphicProps<T, TextFieldInputProps<T>>
) => {
const props = mergeProps<TextFieldInputProps<T>[]>(
{ type: 'text' },
rawProps
);
const [local, others] = splitProps(props as TextFieldInputProps, [
'type',
'class',
]);
return (
<TextFieldPrimitive.Input
type={local.type}
class={cn(
'flex h-10 w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:font-medium file:text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[invalid]:border-error-foreground data-[invalid]:text-error-foreground',
local.class
)}
{...others}
/>
);
};
type TextFieldTextAreaProps<T extends ValidComponent = 'textarea'> =
TextFieldPrimitive.TextFieldTextAreaProps<T> & { class?: string | undefined };
const TextFieldTextArea = <T extends ValidComponent = 'textarea'>(
props: PolymorphicProps<T, TextFieldTextAreaProps<T>>
) => {
const [local, others] = splitProps(props as TextFieldTextAreaProps, [
'class',
]);
return (
<TextFieldPrimitive.TextArea
class={cn(
'flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
local.class
)}
{...others}
/>
);
};
const labelVariants = cva(
'font-medium text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70',
{
variants: {
variant: {
label: 'data-[invalid]:text-destructive',
description: 'font-normal text-muted-foreground',
error: 'text-destructive text-xs',
},
},
defaultVariants: {
variant: 'label',
},
}
);
type TextFieldLabelProps<T extends ValidComponent = 'label'> =
TextFieldPrimitive.TextFieldLabelProps<T> & { class?: string | undefined };
const TextFieldLabel = <T extends ValidComponent = 'label'>(
props: PolymorphicProps<T, TextFieldLabelProps<T>>
) => {
const [local, others] = splitProps(props as TextFieldLabelProps, ['class']);
return (
<TextFieldPrimitive.Label
class={cn(labelVariants(), local.class)}
{...others}
/>
);
};
type TextFieldDescriptionProps<T extends ValidComponent = 'div'> =
TextFieldPrimitive.TextFieldDescriptionProps<T> & {
class?: string | undefined;
};
const TextFieldDescription = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, TextFieldDescriptionProps<T>>
) => {
const [local, others] = splitProps(props as TextFieldDescriptionProps, [
'class',
]);
return (
<TextFieldPrimitive.Description
class={cn(labelVariants({ variant: 'description' }), local.class)}
{...others}
/>
);
};
type TextFieldErrorMessageProps<T extends ValidComponent = 'div'> =
TextFieldPrimitive.TextFieldErrorMessageProps<T> & {
class?: string | undefined;
};
const TextFieldErrorMessage = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, TextFieldErrorMessageProps<T>>
) => {
const [local, others] = splitProps(props as TextFieldErrorMessageProps, [
'class',
]);
return (
<TextFieldPrimitive.ErrorMessage
class={cn(labelVariants({ variant: 'error' }), local.class)}
{...others}
/>
);
};
export {
TextField,
TextFieldInput,
TextFieldTextArea,
TextFieldLabel,
TextFieldDescription,
TextFieldErrorMessage,
};

View File

@ -0,0 +1,18 @@
import * as React from "react"
import { cn } from "@/styles/utils"
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
return (
<textarea
data-slot="textarea"
className={cn(
"border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
className
)}
{...props}
/>
)
}
export { Textarea }

View File

@ -1,160 +0,0 @@
import type { ComponentProps, ParentComponent } from 'solid-js';
import {
type Component,
For,
type JSXElement,
Show,
mergeProps,
splitProps,
} from 'solid-js';
import { cn } from '~/utils/styles';
export type TimelinePropsItem = Omit<
TimelineItemProps,
'isActive' | 'isActiveBullet' | 'bulletSize' | 'lineSize'
> & {
bulletSize?: number;
};
export type TimelineProps = {
items: TimelinePropsItem[];
activeItem: number;
bulletSize?: number;
lineSize?: number;
};
/*
No bullet or line is active when activeItem is -1
First bullet is active only if activeItem is 0 or more
First line is active only if activeItem is 1 or more
*/
const Timeline: Component<TimelineProps> = (rawProps) => {
const props = mergeProps({ bulletSize: 16, lineSize: 2 }, rawProps);
return (
<ul
style={{
'padding-left': `${props.bulletSize / 2}px`,
}}
>
<For each={props.items}>
{(item, index) => (
<TimelineItem
title={item.title}
description={item.description}
bullet={item.bullet}
isLast={index() === props.items.length - 1}
isActive={
props.activeItem === -1 ? false : props.activeItem >= index() + 1
}
isActiveBullet={
props.activeItem === -1 ? false : props.activeItem >= index()
}
bulletSize={props.bulletSize}
lineSize={props.lineSize}
/>
)}
</For>
</ul>
);
};
export type TimelineItemProps = {
title: JSXElement;
description?: JSXElement;
bullet?: JSXElement;
isLast?: boolean;
isActive: boolean;
isActiveBullet: boolean;
class?: string;
bulletSize: number;
lineSize: number;
};
const TimelineItem: Component<TimelineItemProps> = (props) => {
const [local, others] = splitProps(props, [
'class',
'bullet',
'description',
'title',
'isLast',
'isActive',
'isActiveBullet',
'bulletSize',
'lineSize',
]);
return (
<li
class={cn(
'relative border-l pb-8 pl-8',
local.isLast && 'border-l-transparent pb-0',
local.isActive && !local.isLast && 'border-l-primary',
local.class
)}
style={{
'border-left-width': `${local.lineSize}px`,
}}
{...others}
>
<TimelineItemBullet
lineSize={local.lineSize}
bulletSize={local.bulletSize}
isActive={local.isActiveBullet}
>
{local.bullet}
</TimelineItemBullet>
<TimelineItemTitle>{local.title}</TimelineItemTitle>
<Show when={local.description}>
<TimelineItemDescription>{local.description}</TimelineItemDescription>
</Show>
</li>
);
};
export type TimelineItemBulletProps = {
children?: JSXElement;
isActive?: boolean;
bulletSize: number;
lineSize: number;
};
const TimelineItemBullet: Component<TimelineItemBulletProps> = (props) => {
return (
<div
class={cn(
`absolute top-0 flex items-center justify-center rounded-full border bg-background`,
props.isActive && 'border-primary'
)}
style={{
width: `${props.bulletSize}px`,
height: `${props.bulletSize}px`,
left: `${-props.bulletSize / 2 - props.lineSize / 2}px`,
'border-width': `${props.lineSize}px`,
}}
aria-hidden="true"
>
{props.children}
</div>
);
};
const TimelineItemTitle: ParentComponent = (props) => {
return (
<div class="mb-1 font-semibold text-base leading-none">
{props.children}
</div>
);
};
const TimelineItemDescription: Component<ComponentProps<'p'>> = (props) => {
const [local, others] = splitProps(props, ['class', 'children']);
return (
<p class={cn('text-muted-foreground text-sm', local.class)} {...others}>
{local.children}
</p>
);
};
export { Timeline };

View File

@ -1,205 +0,0 @@
import type { JSX, ValidComponent } from 'solid-js';
import { Match, Switch, splitProps } from 'solid-js';
import { Portal } from 'solid-js/web';
import type { PolymorphicProps } from '@kobalte/core/polymorphic';
import * as ToastPrimitive from '@kobalte/core/toast';
import type { VariantProps } from 'class-variance-authority';
import { cva } from 'class-variance-authority';
import { cn } from '~/utils/styles';
const toastVariants = cva(
'group data-[closed]:fade-out-80 data-[closed]:slide-out-to-right-full data-[opened]:slide-in-from-top-full data-[opened]:sm:slide-in-from-bottom-full pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--kb-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--kb-toast-swipe-move-x)] data-[closed]:animate-out data-[opened]:animate-in data-[swipe=end]:animate-out data-[swipe=move]:transition-none',
{
variants: {
variant: {
default: 'border bg-background text-foreground',
destructive:
'destructive group border-destructive bg-destructive text-destructive-foreground',
success:
'success border-success-foreground bg-success text-success-foreground',
warning:
'warning border-warning-foreground bg-warning text-warning-foreground',
error: 'error border-error-foreground bg-error text-error-foreground',
},
},
defaultVariants: {
variant: 'default',
},
}
);
type ToastVariant = NonNullable<VariantProps<typeof toastVariants>['variant']>;
type ToastListProps<T extends ValidComponent = 'ol'> =
ToastPrimitive.ToastListProps<T> & {
class?: string | undefined;
};
const Toaster = <T extends ValidComponent = 'ol'>(
props: PolymorphicProps<T, ToastListProps<T>>
) => {
const [local, others] = splitProps(props as ToastListProps, ['class']);
return (
<Portal>
<ToastPrimitive.Region>
<ToastPrimitive.List
class={cn(
'fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse gap-2 p-4 sm:top-auto sm:right-0 sm:bottom-0 sm:flex-col md:max-w-[420px]',
local.class
)}
{...others}
/>
</ToastPrimitive.Region>
</Portal>
);
};
type ToastRootProps<T extends ValidComponent = 'li'> =
ToastPrimitive.ToastRootProps<T> &
VariantProps<typeof toastVariants> & { class?: string | undefined };
const Toast = <T extends ValidComponent = 'li'>(
props: PolymorphicProps<T, ToastRootProps<T>>
) => {
const [local, others] = splitProps(props as ToastRootProps, [
'class',
'variant',
]);
return (
<ToastPrimitive.Root
class={cn(toastVariants({ variant: local.variant }), local.class)}
{...others}
/>
);
};
type ToastCloseButtonProps<T extends ValidComponent = 'button'> =
ToastPrimitive.ToastCloseButtonProps<T> & { class?: string | undefined };
const ToastClose = <T extends ValidComponent = 'button'>(
props: PolymorphicProps<T, ToastCloseButtonProps<T>>
) => {
const [local, others] = splitProps(props as ToastCloseButtonProps, ['class']);
return (
<ToastPrimitive.CloseButton
class={cn(
'absolute top-2 right-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-destructive-foreground group-[.error]:text-error-foreground group-[.success]:text-success-foreground group-[.warning]:text-warning-foreground',
local.class
)}
{...others}
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-4"
>
<path d="M18 6l-12 12" />
<path d="M6 6l12 12" />
</svg>
</ToastPrimitive.CloseButton>
);
};
type ToastTitleProps<T extends ValidComponent = 'div'> =
ToastPrimitive.ToastTitleProps<T> & {
class?: string | undefined;
};
const ToastTitle = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, ToastTitleProps<T>>
) => {
const [local, others] = splitProps(props as ToastTitleProps, ['class']);
return (
<ToastPrimitive.Title
class={cn('font-semibold text-sm', local.class)}
{...others}
/>
);
};
type ToastDescriptionProps<T extends ValidComponent = 'div'> =
ToastPrimitive.ToastDescriptionProps<T> & { class?: string | undefined };
const ToastDescription = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, ToastDescriptionProps<T>>
) => {
const [local, others] = splitProps(props as ToastDescriptionProps, ['class']);
return (
<ToastPrimitive.Description
class={cn('text-sm opacity-90', local.class)}
{...others}
/>
);
};
function showToast(props: {
title?: JSX.Element;
description?: JSX.Element;
variant?: ToastVariant;
duration?: number;
}) {
ToastPrimitive.toaster.show((data) => (
<Toast
toastId={data.toastId}
variant={props.variant}
duration={props.duration}
>
<div class="grid gap-1">
{props.title && <ToastTitle>{props.title}</ToastTitle>}
{props.description && (
<ToastDescription>{props.description}</ToastDescription>
)}
</div>
<ToastClose />
</Toast>
));
}
function showToastPromise<T, U>(
promise: Promise<T> | (() => Promise<T>),
options: {
loading?: JSX.Element;
success?: (data: T) => JSX.Element;
error?: (error: U) => JSX.Element;
duration?: number;
}
) {
const variant: { [key in ToastPrimitive.ToastPromiseState]: ToastVariant } = {
pending: 'default',
fulfilled: 'success',
rejected: 'error',
};
return ToastPrimitive.toaster.promise<T, U>(promise, (props) => (
<Toast
toastId={props.toastId}
variant={variant[props.state]}
duration={options.duration}
>
<Switch>
<Match when={props.state === 'pending'}>{options.loading}</Match>
<Match when={props.state === 'fulfilled'}>
{options.success?.(props.data!)}
</Match>
<Match when={props.state === 'rejected'}>
{options.error?.(props.error!)}
</Match>
</Switch>
</Toast>
));
}
export {
Toaster,
Toast,
ToastClose,
ToastTitle,
ToastDescription,
showToast,
showToastPromise,
};

View File

@ -1,82 +1,73 @@
import type { JSX, ValidComponent } from 'solid-js'; "use client"
import { createContext, splitProps, useContext } from 'solid-js';
import type { PolymorphicProps } from '@kobalte/core/polymorphic'; import * as React from "react"
import * as ToggleGroupPrimitive from '@kobalte/core/toggle-group'; import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group"
import type { VariantProps } from 'class-variance-authority'; import { type VariantProps } from "class-variance-authority"
import { toggleVariants } from '~/components/ui/toggle'; import { cn } from "@/styles/utils"
import { cn } from '~/utils/styles'; import { toggleVariants } from "@/components/ui/toggle"
const ToggleGroupContext = createContext<VariantProps<typeof toggleVariants>>({ const ToggleGroupContext = React.createContext<
size: 'default', VariantProps<typeof toggleVariants>
variant: 'default', >({
}); size: "default",
variant: "default",
type ToggleGroupRootProps<T extends ValidComponent = 'div'> = })
ToggleGroupPrimitive.ToggleGroupRootProps<T> &
VariantProps<typeof toggleVariants> & {
class?: string | undefined;
children?: JSX.Element;
};
const ToggleGroup = <T extends ValidComponent = 'div'>(
props: PolymorphicProps<T, ToggleGroupRootProps<T>>
) => {
const [local, others] = splitProps(props as ToggleGroupRootProps, [
'class',
'children',
'size',
'variant',
]);
function ToggleGroup({
className,
variant,
size,
children,
...props
}: React.ComponentProps<typeof ToggleGroupPrimitive.Root> &
VariantProps<typeof toggleVariants>) {
return ( return (
<ToggleGroupPrimitive.Root <ToggleGroupPrimitive.Root
class={cn('flex items-center justify-center gap-1', local.class)} data-slot="toggle-group"
{...others} data-variant={variant}
data-size={size}
className={cn(
"group/toggle-group flex w-fit items-center rounded-md data-[variant=outline]:shadow-xs",
className
)}
{...props}
> >
<ToggleGroupContext.Provider <ToggleGroupContext.Provider value={{ variant, size }}>
value={{ {children}
get size() {
return local.size;
},
get variant() {
return local.variant;
},
}}
>
{local.children}
</ToggleGroupContext.Provider> </ToggleGroupContext.Provider>
</ToggleGroupPrimitive.Root> </ToggleGroupPrimitive.Root>
); )
}; }
type ToggleGroupItemProps<T extends ValidComponent = 'button'> = function ToggleGroupItem({
ToggleGroupPrimitive.ToggleGroupItemProps<T> & className,
VariantProps<typeof toggleVariants> & { class?: string | undefined }; children,
variant,
size,
...props
}: React.ComponentProps<typeof ToggleGroupPrimitive.Item> &
VariantProps<typeof toggleVariants>) {
const context = React.useContext(ToggleGroupContext)
const ToggleGroupItem = <T extends ValidComponent = 'button'>(
props: PolymorphicProps<T, ToggleGroupItemProps<T>>
) => {
const [local, others] = splitProps(props as ToggleGroupItemProps, [
'class',
'size',
'variant',
]);
const context = useContext(ToggleGroupContext);
return ( return (
<ToggleGroupPrimitive.Item <ToggleGroupPrimitive.Item
class={cn( data-slot="toggle-group-item"
data-variant={context.variant || variant}
data-size={context.size || size}
className={cn(
toggleVariants({ toggleVariants({
size: context.size || local.size, variant: context.variant || variant,
variant: context.variant || local.variant, size: context.size || size,
}), }),
'hover:bg-muted hover:text-muted-foreground data-[pressed]:bg-accent data-[pressed]:text-accent-foreground', "min-w-0 flex-1 shrink-0 rounded-none shadow-none first:rounded-l-md last:rounded-r-md focus:z-10 focus-visible:z-10 data-[variant=outline]:border-l-0 data-[variant=outline]:first:border-l",
local.class className
)} )}
{...others} {...props}
/> >
); {children}
}; </ToggleGroupPrimitive.Item>
)
}
export { ToggleGroup, ToggleGroupItem }; export { ToggleGroup, ToggleGroupItem }

View File

@ -1,56 +1,45 @@
import type { ValidComponent } from 'solid-js'; import * as React from "react"
import { splitProps } from 'solid-js'; import * as TogglePrimitive from "@radix-ui/react-toggle"
import { cva, type VariantProps } from "class-variance-authority"
import type { PolymorphicProps } from '@kobalte/core/polymorphic'; import { cn } from "@/styles/utils"
import * as ToggleButtonPrimitive from '@kobalte/core/toggle-button';
import { cva } from 'class-variance-authority';
import type { VariantProps } from 'class-variance-authority';
import { cn } from '~/utils/styles';
const toggleVariants = cva( const toggleVariants = cva(
'inline-flex items-center justify-center rounded-md font-medium text-sm ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50', "inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium hover:bg-muted hover:text-muted-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] outline-none transition-[color,box-shadow] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive whitespace-nowrap",
{ {
variants: { variants: {
variant: { variant: {
default: 'bg-transparent', default: "bg-transparent",
outline: 'border border-input bg-transparent shadow-sm', outline:
"border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground",
}, },
size: { size: {
default: 'h-9 px-3', default: "h-9 px-2 min-w-9",
sm: 'h-8 px-2', sm: "h-8 px-1.5 min-w-8",
lg: 'h-10 px-3', lg: "h-10 px-2.5 min-w-10",
}, },
}, },
defaultVariants: { defaultVariants: {
variant: 'default', variant: "default",
size: 'default', size: "default",
}, },
} }
); )
type ToggleButtonRootProps<T extends ValidComponent = 'button'> = function Toggle({
ToggleButtonPrimitive.ToggleButtonRootProps<T> & className,
VariantProps<typeof toggleVariants> & { class?: string | undefined }; variant,
size,
const Toggle = <T extends ValidComponent = 'button'>( ...props
props: PolymorphicProps<T, ToggleButtonRootProps<T>> }: React.ComponentProps<typeof TogglePrimitive.Root> &
) => { VariantProps<typeof toggleVariants>) {
const [local, others] = splitProps(props as ToggleButtonRootProps, [
'class',
'variant',
'size',
]);
return ( return (
<ToggleButtonPrimitive.Root <TogglePrimitive.Root
class={cn( data-slot="toggle"
toggleVariants({ variant: local.variant, size: local.size }), className={cn(toggleVariants({ variant, size, className }))}
local.class {...props}
)}
{...others}
/> />
); )
}; }
export type { ToggleButtonRootProps as ToggleProps }; export { Toggle, toggleVariants }
export { toggleVariants, Toggle };

View File

@ -1,35 +1,59 @@
import type { ValidComponent } from 'solid-js'; import * as React from "react"
import { type Component, splitProps } from 'solid-js'; import * as TooltipPrimitive from "@radix-ui/react-tooltip"
import type { PolymorphicProps } from '@kobalte/core/polymorphic'; import { cn } from "@/styles/utils"
import * as TooltipPrimitive from '@kobalte/core/tooltip';
import { cn } from '~/utils/styles'; function TooltipProvider({
delayDuration = 0,
...props
}: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
return (
<TooltipPrimitive.Provider
data-slot="tooltip-provider"
delayDuration={delayDuration}
{...props}
/>
)
}
const TooltipTrigger = TooltipPrimitive.Trigger; function Tooltip({
...props
}: React.ComponentProps<typeof TooltipPrimitive.Root>) {
return (
<TooltipProvider>
<TooltipPrimitive.Root data-slot="tooltip" {...props} />
</TooltipProvider>
)
}
const Tooltip: Component<TooltipPrimitive.TooltipRootProps> = (props) => { function TooltipTrigger({
return <TooltipPrimitive.Root gutter={4} {...props} />; ...props
}; }: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />
}
type TooltipContentProps<T extends ValidComponent = 'div'> = function TooltipContent({
TooltipPrimitive.TooltipContentProps<T> & { class?: string | undefined }; className,
sideOffset = 0,
const TooltipContent = <T extends ValidComponent = 'div'>( children,
props: PolymorphicProps<T, TooltipContentProps<T>> ...props
) => { }: React.ComponentProps<typeof TooltipPrimitive.Content>) {
const [local, others] = splitProps(props as TooltipContentProps, ['class']);
return ( return (
<TooltipPrimitive.Portal> <TooltipPrimitive.Portal>
<TooltipPrimitive.Content <TooltipPrimitive.Content
class={cn( data-slot="tooltip-content"
'fade-in-0 zoom-in-95 z-50 origin-[var(--kb-popover-content-transform-origin)] animate-in overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-popover-foreground text-sm shadow-md', sideOffset={sideOffset}
local.class className={cn(
"bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
className
)} )}
{...others} {...props}
/> >
{children}
<TooltipPrimitive.Arrow className="bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" />
</TooltipPrimitive.Content>
</TooltipPrimitive.Portal> </TooltipPrimitive.Portal>
); )
}; }
export { Tooltip, TooltipTrigger, TooltipContent }; export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }

View File

@ -4,7 +4,7 @@ import {
Settings2, Settings2,
SquareTerminal, SquareTerminal,
Telescope, Telescope,
} from 'lucide-solid'; } from 'lucide-react';
export const AppNavMainData = [ export const AppNavMainData = [
{ {

View File

@ -0,0 +1,5 @@
export class UnreachableError extends Error {
constructor(detail: string) {
super(`UnreachableError: ${detail}`);
}
}

View File

@ -0,0 +1,19 @@
import * as React from "react"
const MOBILE_BREAKPOINT = 768
export function useIsMobile() {
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
React.useEffect(() => {
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
const onChange = () => {
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
}
mql.addEventListener("change", onChange)
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
return () => mql.removeEventListener("change", onChange)
}, [])
return !!isMobile
}

View File

@ -1,29 +1,19 @@
import '@abraham/reflection'; import '@abraham/reflection';
import {
ColorModeProvider,
ColorModeScript,
createLocalStorageManager,
} from '@kobalte/core';
import { type Injector, ReflectiveInjector } from '@outposts/injection-js'; import { type Injector, ReflectiveInjector } from '@outposts/injection-js';
import { RouterProvider, createRouter } from '@tanstack/solid-router'; import { RouterProvider, createRouter } from '@tanstack/react-router';
import {
OidcSecurityService,
provideAuth,
withCheckAuthResultEvent,
withDefaultFeatures,
} from 'oidc-client-rx';
import { withTanstackRouter } from 'oidc-client-rx/adapters/@tanstack/solid-router';
import { import {
InjectorContextVoidInjector, InjectorContextVoidInjector,
InjectorProvider, InjectorProvider,
} from 'oidc-client-rx/adapters/solid-js'; } from 'oidc-client-rx/adapters/react';
import { Dynamic, render } from 'solid-js/web'; import { Suspense } from 'react';
import { buildOidcConfig, isBasicAuth, isOidcAuth } from './auth/config'; import { createRoot } from 'react-dom/client';
import { isAuthenticated } from './auth/context'; import { provideAuth, setupAuthContext } from './auth/context';
import { useAuth } from './auth/hooks';
import { routeTree } from './routeTree.gen';
import './app.css';
import { AppNotFoundComponent } from './components/layout/app-not-found'; import { AppNotFoundComponent } from './components/layout/app-not-found';
import { providePlatform } from './platform/context';
import { routeTree } from './routeTree.gen';
import { provideStorages } from './storage/context';
import { provideStyles } from './styles/context';
import './app.css';
// Create a new router instance // Create a new router instance
const router = createRouter({ const router = createRouter({
@ -34,79 +24,44 @@ const router = createRouter({
defaultNotFoundComponent: AppNotFoundComponent, defaultNotFoundComponent: AppNotFoundComponent,
notFoundMode: 'root', notFoundMode: 'root',
context: { context: {
isAuthenticated: isAuthenticated,
injector: InjectorContextVoidInjector, injector: InjectorContextVoidInjector,
oidcSecurityService: {} as OidcSecurityService,
}, },
}); });
// Register the router instance for type safety // Register the router instance for type safety
declare module '@tanstack/solid-router' { declare module '@tanstack/react-router' {
interface Register { interface Register {
router: typeof router; router: typeof router;
} }
} }
const injector: Injector = isBasicAuth const injector: Injector = ReflectiveInjector.resolveAndCreate([
? ReflectiveInjector.resolveAndCreate([]) ...providePlatform(),
: ReflectiveInjector.resolveAndCreate( ...provideStorages(),
provideAuth( ...provideAuth(router),
{ ...provideStyles(),
config: buildOidcConfig(), ]);
},
withDefaultFeatures({
router: { enabled: false },
securityStorage: { type: 'local-storage' },
}),
withTanstackRouter(router),
withCheckAuthResultEvent()
)
);
// if needed, check when init setupAuthContext(injector);
let oidcSecurityService: OidcSecurityService | undefined;
if (isOidcAuth) {
oidcSecurityService = injector.get(OidcSecurityService);
oidcSecurityService.checkAuth().subscribe();
}
// Render the app
const rootElement = document.getElementById('root'); const rootElement = document.getElementById('root');
const AppWithBasicAuth = () => {
return <RouterProvider router={router} />;
};
const AppWithOidcAuth = () => {
const { isAuthenticated, oidcSecurityService, injector } = useAuth();
return (
<RouterProvider
router={router}
context={{
isAuthenticated,
oidcSecurityService,
injector,
}}
/>
);
};
const App = () => { const App = () => {
const storageManager = createLocalStorageManager('color-theme');
return ( return (
<> <Suspense>
<ColorModeScript storageType={storageManager.type} /> <InjectorProvider injector={injector}>
<ColorModeProvider storageManager={storageManager}> <RouterProvider
<InjectorProvider injector={injector}> router={router}
<Dynamic context={{
component={isBasicAuth ? AppWithBasicAuth : AppWithOidcAuth} injector,
/> }}
</InjectorProvider> />
</ColorModeProvider> </InjectorProvider>
</> </Suspense>
); );
}; };
if (rootElement && !rootElement.innerHTML) { if (rootElement) {
render(App, rootElement); const root = createRoot(rootElement);
root.render(<App />);
} }

View File

@ -0,0 +1,5 @@
import { DOCUMENT } from './injection';
export const providePlatform = () => {
return [{ provide: DOCUMENT, useValue: document }];
};

View File

@ -0,0 +1,7 @@
export class FeatureNotAvailablePlatformError extends Error {
constructor(feature: string, platform?: string) {
super(
`Platform error: ${feature} is not available on ${platform ?? 'current platform'}`
);
}
}

View File

@ -0,0 +1,3 @@
import { InjectionToken } from '@outposts/injection-js';
export const DOCUMENT = new InjectionToken<Document>('DOCUMENT');

View File

@ -137,7 +137,7 @@ const AppSubscriptionsEditSubscriptionIdRoute =
// Populate the FileRoutesByPath interface // Populate the FileRoutesByPath interface
declare module '@tanstack/solid-router' { declare module '@tanstack/react-router' {
interface FileRoutesByPath { interface FileRoutesByPath {
'/': { '/': {
id: '/' id: '/'

View File

@ -1,5 +1,5 @@
import { createFileRoute } from '@tanstack/solid-router'; import { AppNotFoundComponent } from '@/components/layout/app-not-found';
import { AppNotFoundComponent } from '~/components/layout/app-not-found'; import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/404')({ export const Route = createFileRoute('/404')({
component: AppNotFoundComponent, component: AppNotFoundComponent,

View File

@ -1,6 +1,6 @@
import { Outlet, createRootRouteWithContext } from '@tanstack/solid-router'; import type { RouteStateDataOption, RouterContext } from '@/traits/router';
import { Home } from 'lucide-solid'; import { Outlet, createRootRouteWithContext } from '@tanstack/react-router';
import type { RouteStateDataOption, RouterContext } from '~/traits/router'; import { Home } from 'lucide-react';
export const Route = createRootRouteWithContext<RouterContext>()({ export const Route = createRootRouteWithContext<RouterContext>()({
component: Outlet, component: Outlet,

View File

@ -1,5 +1,5 @@
import { createFileRoute } from '@tanstack/solid-router'; import type { RouteStateDataOption } from '@/traits/router';
import type { RouteStateDataOption } from '~/traits/router'; import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/_app/_explore/explore')({ export const Route = createFileRoute('/_app/_explore/explore')({
component: ExploreRouteComponent, component: ExploreRouteComponent,

View File

@ -1,5 +1,5 @@
import { createFileRoute } from '@tanstack/solid-router'; import type { RouteStateDataOption } from '@/traits/router';
import type { RouteStateDataOption } from '~/traits/router'; import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/_app/_explore/feed')({ export const Route = createFileRoute('/_app/_explore/feed')({
component: FeedRouteComponent, component: FeedRouteComponent,

View File

@ -1,12 +1,10 @@
import { useAuth } from '@/auth/hooks';
import { type Fetcher, createGraphiQLFetcher } from '@graphiql/toolkit'; import { type Fetcher, createGraphiQLFetcher } from '@graphiql/toolkit';
import { createLazyFileRoute } from '@tanstack/solid-router'; import { createLazyFileRoute } from '@tanstack/react-router';
import GraphiQL from 'graphiql'; import GraphiQL from 'graphiql';
import { createElement } from 'react'; import { useCallback } from 'react';
import { createRoot } from 'react-dom/client';
import { onCleanup, onMount } from 'solid-js';
import { isOidcAuth } from '~/auth/config';
import { useAuth } from '~/auth/hooks';
import 'graphiql/graphiql.css'; import 'graphiql/graphiql.css';
import { AuthMethodEnum } from '@/auth/config';
import { firstValueFrom } from 'rxjs'; import { firstValueFrom } from 'rxjs';
export const Route = createLazyFileRoute('/_app/playground/graphql-api')({ export const Route = createLazyFileRoute('/_app/playground/graphql-api')({
@ -14,41 +12,38 @@ export const Route = createLazyFileRoute('/_app/playground/graphql-api')({
}); });
function PlaygroundGraphQLApiRouteComponent() { function PlaygroundGraphQLApiRouteComponent() {
const auth = useAuth(); const { authContext } = useAuth();
let containerRef: HTMLDivElement | undefined;
onMount(() => { const fetcher: Fetcher = useCallback(
if (containerRef) { async (props) => {
const reactRoot = createRoot(containerRef); const accessToken =
if (reactRoot) { authContext.type === AuthMethodEnum.OIDC
const fetcher: Fetcher = async (props) => { ? await firstValueFrom(
const accessToken = isOidcAuth authContext.oidcSecurityService.getAccessToken()
? await firstValueFrom(auth.oidcSecurityService!.getAccessToken()) )
: undefined; : undefined;
return createGraphiQLFetcher({ return createGraphiQLFetcher({
url: '/api/graphql', url: '/api/graphql',
headers: accessToken headers: accessToken
? { ? {
Authorization: `Bearer ${accessToken}`, Authorization: `Bearer ${accessToken}`,
} }
: undefined, : undefined,
})(props); })(props);
}; },
const graphiql = createElement(GraphiQL, { [
fetcher, authContext.type,
}); // @ts-ignore
reactRoot.render(graphiql); authContext?.oidcSecurityService?.getAccessToken,
]
onCleanup(() => reactRoot.unmount()); );
}
}
});
return ( return (
<div <div
data-id="graphiql-playground-container" data-id="graphiql-playground-container"
class="h-full overflow-hidden rounded-lg" className="h-full overflow-hidden rounded-lg"
ref={containerRef} >
/> <GraphiQL fetcher={fetcher} />
</div>
); );
} }

View File

@ -1,6 +1,6 @@
import { createFileRoute } from '@tanstack/solid-router'; import { AppSkeleton } from '@/components/layout/app-skeleton';
import { AppSkeleton } from '~/components/layout/app-skeleton'; import { buildLeafRouteStaticData } from '@/utils/route';
import { buildLeafRouteStaticData } from '~/utils/route'; import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/_app/playground/graphql-api')({ export const Route = createFileRoute('/_app/playground/graphql-api')({
staticData: buildLeafRouteStaticData({ title: 'GraphQL Api' }), staticData: buildLeafRouteStaticData({ title: 'GraphQL Api' }),

View File

@ -1,5 +1,5 @@
import { createFileRoute } from '@tanstack/solid-router'; import { buildVirtualBranchRouteOptions } from '@/utils/route';
import { buildVirtualBranchRouteOptions } from '~/utils/route'; import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/_app/playground')( export const Route = createFileRoute('/_app/playground')(
buildVirtualBranchRouteOptions({ buildVirtualBranchRouteOptions({

View File

@ -1,6 +1,6 @@
import { Outlet, createFileRoute } from '@tanstack/solid-router'; import { beforeLoadGuard } from '@/auth/guard';
import { beforeLoadGuard } from '~/auth/guard'; import { AppAside } from '@/components/layout/app-layout';
import { AppAside } from '~/components/layout/app-layout'; import { Outlet, createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/_app')({ export const Route = createFileRoute('/_app')({
component: AppLayoutRoute, component: AppLayoutRoute,

View File

@ -1,5 +1,5 @@
import { createFileRoute } from '@tanstack/solid-router'; import { buildLeafRouteStaticData } from '@/utils/route';
import { buildLeafRouteStaticData } from '~/utils/route'; import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/_app/settings/downloader')({ export const Route = createFileRoute('/_app/settings/downloader')({
component: SettingsDownloaderRouteComponent, component: SettingsDownloaderRouteComponent,

Some files were not shown because too many files have changed in this diff Show More