-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: Tabs overflow handling * change to `svelte:window` * format * Update tabs-list.svelte * Update tabs-list.svelte * change to default on * use masks instead --------- Co-authored-by: Davis SHYAKA <87414827+davis-shyaka@users.noreply.github.com>
- Loading branch information
1 parent
b62d435
commit dce074a
Showing
7 changed files
with
107 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,66 @@ | ||
<script lang="ts"> | ||
import { cn } from '$lib/utils.js'; | ||
import { Tabs as TabsPrimitive } from 'bits-ui'; | ||
import { onMount } from 'svelte'; | ||
type $$Props = TabsPrimitive.ListProps & { | ||
variant?: 'default' | 'secondary'; | ||
/** When `true`, masks either edge of the scrollable content to indicate there is more content to the user @default true */ | ||
mask_overflow?: boolean; | ||
}; | ||
let class_name: $$Props['class'] = undefined; | ||
export let variant: $$Props['variant'] = 'default'; | ||
export { class_name as class }; | ||
export let mask_overflow: $$Props['mask_overflow'] = true; | ||
let el: HTMLDivElement; | ||
let pre_mask = false; | ||
let post_mask = false; | ||
// When the tabs are scrolled it will determine whether or not to show the mask at the end | ||
function handle_mask() { | ||
if (el.offsetWidth + el.scrollLeft < el.scrollWidth - 10) { | ||
post_mask = true; | ||
} else { | ||
post_mask = false; | ||
} | ||
if (el.scrollLeft == 0) { | ||
pre_mask = false; | ||
} else { | ||
pre_mask = true; | ||
} | ||
} | ||
onMount(() => { | ||
handle_mask(); // initially determine mask state | ||
el.addEventListener('scroll', handle_mask); | ||
return () => { | ||
el.removeEventListener('scroll', handle_mask); | ||
}; | ||
}); | ||
</script> | ||
|
||
<!-- TODO: Add a no-scrollbar class. --> | ||
<svelte:window on:resize={handle_mask} /> | ||
|
||
<!-- Make sure you have the `no-scrollbar` class in your tailwind.config file --> | ||
<TabsPrimitive.List | ||
data-variant={variant} | ||
bind:el | ||
class={cn( | ||
'group inline-flex w-full flex-wrap items-baseline gap-3 overflow-hidden overflow-x-auto p-1 text-gray-900 data-[variant=default]:[box-shadow:_0_-1px_0_var(--accents-2)_inset;]', | ||
'group flex w-full items-baseline gap-3 overflow-hidden overflow-x-auto p-1 text-gray-900 no-scrollbar data-[variant=default]:[box-shadow:_0_-1px_0_var(--accents-2)_inset;]', | ||
{ | ||
'mask-linear mask-dir-to-r mask-from-0 mask-to-100 mask-point-to-[15%]': | ||
mask_overflow && pre_mask, | ||
'mask-linear mask-dir-to-l mask-from-0 mask-to-100 mask-point-to-[15%]': | ||
mask_overflow && post_mask | ||
}, | ||
class_name | ||
)} | ||
{...$$restProps} | ||
> | ||
<slot /> | ||
<slot></slot> | ||
</TabsPrimitive.List> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<script lang="ts"> | ||
import * as Tabs from '$lib/components/ui/tabs'; | ||
const tabs = [ | ||
{ title: 'Apple', value: 'apple' }, | ||
{ title: 'Banana', value: 'banana' }, | ||
{ title: 'Orange', value: 'orange' }, | ||
{ title: 'Strawberry', value: 'strawberry' }, | ||
{ title: 'Mango', value: 'mango' }, | ||
{ title: 'Pineapple', value: 'pineapple' }, | ||
{ title: 'Grape', value: 'grape' }, | ||
{ title: 'Watermelon', value: 'watermelon' }, | ||
{ title: 'Peach', value: 'peach' }, | ||
{ title: 'Kiwi', value: 'kiwi' }, | ||
{ title: 'Cherry', value: 'cherry' }, | ||
{ title: 'Blueberry', value: 'blueberry' }, | ||
{ title: 'Pear', value: 'pear' }, | ||
{ title: 'Plum', value: 'plum' }, | ||
{ title: 'Raspberry', value: 'raspberry' } | ||
]; | ||
</script> | ||
|
||
<Tabs.Root value="apple"> | ||
<Tabs.List> | ||
{#each tabs as { title, value }} | ||
<Tabs.Trigger {value}>{title}</Tabs.Trigger> | ||
{/each} | ||
</Tabs.List> | ||
</Tabs.Root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters