@srcroot/ui 0.0.46 → 0.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -336,7 +336,7 @@ export function cn(...inputs: ClassValue[]) {
336
336
  }
337
337
  async installDependencies() {
338
338
  const cfg = this.config;
339
- const spinner = ora("Installing dependencies...").start();
339
+ const spinner = ora("Checking dependencies...").start();
340
340
  const deps = [
341
341
  "clsx",
342
342
  "tailwind-merge",
@@ -347,15 +347,25 @@ export function cn(...inputs: ClassValue[]) {
347
347
  deps.push("tailwindcss-animate");
348
348
  }
349
349
  try {
350
- await execa(cfg.packageManager, [cfg.installCmd, ...deps], {
350
+ const packageJsonPath = path3.join(cfg.cwd, "package.json");
351
+ const pkg = await fs3.readJson(packageJsonPath);
352
+ const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
353
+ const missingDeps = deps.filter((dep) => !allDeps[dep]);
354
+ if (missingDeps.length === 0) {
355
+ spinner.succeed("Dependencies already installed");
356
+ return;
357
+ }
358
+ spinner.text = "Installing dependencies...";
359
+ await execa(cfg.packageManager, [cfg.installCmd, ...missingDeps], {
351
360
  cwd: cfg.cwd,
352
361
  stdio: "pipe"
353
362
  });
354
- spinner.succeed(`Installed ${deps.length} dependencies`);
363
+ spinner.succeed(`Installed ${missingDeps.length} dependencies`);
355
364
  } catch (error) {
356
365
  spinner.fail("Failed to install dependencies");
366
+ const missingDeps = deps;
357
367
  logger.warn(`
358
- Manually run: ${cfg.packageManager} ${cfg.installCmd} ${deps.join(" ")}`);
368
+ Manually run: ${cfg.packageManager} ${cfg.installCmd} ${missingDeps.join(" ")}`);
359
369
  }
360
370
  }
361
371
  printSuccess() {
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "@srcroot/ui",
3
- "version": "0.0.46",
3
+ "version": "0.0.49",
4
4
  "description": "A UI library with polymorphic, accessible React components",
5
+ "author": "Shifaul Islam",
6
+ "license": "MIT",
5
7
  "type": "module",
6
8
  "bin": {
7
9
  "srcroot-ui": "./dist/index.js"
@@ -277,7 +277,7 @@ const DropdownMenuItem = React.forwardRef<
277
277
  tabIndex={disabled ? -1 : 0}
278
278
  aria-disabled={disabled}
279
279
  className={cn(
280
- "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 hover:bg-accent hover:text-accent-foreground",
280
+ "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 hover:bg-accent hover:text-accent-foreground cursor-pointer",
281
281
  inset && "pl-8",
282
282
  disabled && "pointer-events-none opacity-50",
283
283
  className
@@ -181,7 +181,7 @@ const SheetContent = React.forwardRef<HTMLDivElement, SheetContentProps>(
181
181
  >
182
182
  {children}
183
183
  <button
184
- className="absolute right-4 top-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"
184
+ className="absolute right-4 top-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 cursor-pointer"
185
185
  onClick={() => context.onOpenChange(false)}
186
186
  >
187
187
  <svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
@@ -63,7 +63,7 @@ const SidebarProvider = React.forwardRef<
63
63
 
64
64
  React.useEffect(() => {
65
65
  const checkMobile = () => {
66
- setIsMobile(window.innerWidth < 1024) // lg breakpoint
66
+ setIsMobile(window.innerWidth < 768) // md breakpoint
67
67
  }
68
68
  checkMobile()
69
69
  window.addEventListener("resize", checkMobile)
@@ -169,7 +169,7 @@ const Sidebar = React.forwardRef<
169
169
  <div
170
170
  ref={ref}
171
171
  className={cn(
172
- "group peer hidden md:block text-sidebar-foreground",
172
+ "group peer md:block text-sidebar-foreground",
173
173
  className
174
174
  )}
175
175
  data-state={state}
@@ -192,7 +192,7 @@ const Sidebar = React.forwardRef<
192
192
  {/* Actual Fixed Sidebar */}
193
193
  <div
194
194
  className={cn(
195
- "duration-200 fixed inset-y-0 z-10 hidden h-svh w-[var(--sidebar-width)] transition-[left,right,width] ease-linear md:flex",
195
+ "duration-200 fixed inset-y-0 z-10 h-svh w-[var(--sidebar-width)] transition-[left,right,width] ease-linear md:flex",
196
196
  side === "left"
197
197
  ? "left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]"
198
198
  : "right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",
@@ -448,14 +448,10 @@ const SidebarMenuButton = React.forwardRef<
448
448
  },
449
449
  ref
450
450
  ) => {
451
- const Comp = "button"
452
- // manual asChild handling
453
- // const Comp = asChild ? Slot : "button"
454
- // But we want to avoid Slot if possible per user request?
455
- // Actually, if I can use the same cloneElement approach:
451
+ const { isMobile, state, setOpen } = useSidebar()
456
452
 
457
453
  const buttonClass = cn(
458
- "peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
454
+ "cursor-pointer peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
459
455
  "data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground",
460
456
  "data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground",
461
457
  "group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:group-data-[collapsible=icon]:hidden",
@@ -464,6 +460,13 @@ const SidebarMenuButton = React.forwardRef<
464
460
 
465
461
  // If tooltip is needed, we should implement it. For now, ignoring complexity of tooltip.
466
462
 
463
+ const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
464
+ props.onClick?.(e)
465
+ if (!isMobile && state === "collapsed") {
466
+ setOpen(true)
467
+ }
468
+ }
469
+
467
470
  if (asChild) {
468
471
  const child = React.Children.only(props.children) as React.ReactElement<any>
469
472
 
@@ -474,6 +477,10 @@ const SidebarMenuButton = React.forwardRef<
474
477
  "data-sidebar": "menu-button",
475
478
  "data-size": size,
476
479
  ...props,
480
+ onClick: (e: React.MouseEvent<HTMLButtonElement>) => {
481
+ handleClick(e)
482
+ child.props.onClick?.(e)
483
+ },
477
484
  children: child.props.children
478
485
  })
479
486
  }
@@ -485,6 +492,7 @@ const SidebarMenuButton = React.forwardRef<
485
492
  data-size={size}
486
493
  data-active={isActive}
487
494
  className={buttonClass}
495
+ onClick={handleClick}
488
496
  {...props}
489
497
  />
490
498
  )
@@ -23,9 +23,9 @@ import { cn } from "@/lib/utils"
23
23
 
24
24
  const Table = React.forwardRef<
25
25
  HTMLTableElement,
26
- React.HTMLAttributes<HTMLTableElement>
27
- >(({ className, ...props }, ref) => (
28
- <div className="relative w-full overflow-auto">
26
+ React.HTMLAttributes<HTMLTableElement> & { containerClassName?: string }
27
+ >(({ className, containerClassName, ...props }, ref) => (
28
+ <div className={cn("relative w-full overflow-auto", containerClassName)}>
29
29
  <table
30
30
  ref={ref}
31
31
  className={cn("w-full caption-bottom text-sm", className)}