Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toggle icon when sidebar is open to use LeftPanelClose #1422

Closed
1 task done
burggraf opened this issue Nov 1, 2024 · 3 comments
Closed
1 task done

toggle icon when sidebar is open to use LeftPanelClose #1422

burggraf opened this issue Nov 1, 2024 · 3 comments
Labels
type: feature Introduction of new functionality to the application

Comments

@burggraf
Copy link

burggraf commented Nov 1, 2024

Prerequisites

  • This feature already exists in shadcn/ui - if not, it won't be considered here so don't continue with your issue.

Describe the feature

I've changed the code of sidebar-trigger.svelte so that:

  • when the sidebar is open, the icon is LeftPanelClose
  • when the sidebar is closed, the icon is LeftPanel

Here's the new code (since I don't have access to create a PR):

<script lang="ts">
	import { Button } from "$lib/components/ui/button/index.js";
	import { cn } from "$lib/utils.js";
	import PanelLeft from "lucide-svelte/icons/panel-left";
	import PanelLeftClose from "lucide-svelte/icons/panel-left-close";
	import type { ComponentProps } from "svelte";
	import { useSidebar } from "./context.svelte.js";

	let {
		ref = $bindable(null),
		class: className,
		onclick,
		...restProps
	}: ComponentProps<typeof Button> & {
		onclick?: (e: MouseEvent) => void;
	} = $props();

	const sidebar = useSidebar();
	let isOpen = $derived(sidebar.open);
</script>

<Button
	type="button"
	onclick={(e) => {
		onclick?.(e);
		sidebar.toggle();
	}}
	data-sidebar="trigger"
	variant="ghost"
	size="icon"
	class={cn("h-7 w-7", className)}
	aria-expanded={isOpen}
	{...restProps}
>
	{#if isOpen}
		<PanelLeftClose />
	{:else}
		<PanelLeft />
	{/if}
	<span class="sr-only">Toggle Sidebar</span>
</Button>
@burggraf burggraf added the type: feature Introduction of new functionality to the application label Nov 1, 2024
@huntabyte
Copy link
Owner

huntabyte commented Nov 1, 2024

This feature already exists in shadcn/ui - if not, it won't be considered here so don't continue with your issue.

Where does this exist currently in shadcn/ui? I try to avoid adding things that aren't in the original as we're trying to maintain consistency in this port. If it gets approved/merged there, I'm more than happy to have the same here 😁

@burggraf
Copy link
Author

burggraf commented Nov 1, 2024

Ah, I didn't look to see if it's in shadcn/ui -- it just made perfect sense from a UX POV. I guess I misunderstood that checkbox :(

@huntabyte
Copy link
Owner

No worries at all @burggraf! Perhaps open the PR over there first and if it lands we can add it here as well! Until then going to close this issue 😁

@huntabyte huntabyte closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

2 participants