-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
542 additions
and
31 deletions.
There are no files selected for viewing
File renamed without changes.
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
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,31 @@ | ||
/* eslint-disable local-rules/no-class-without-style */ | ||
import { cn, useStyle } from '../../helpers'; | ||
import { Tabs } from '../primitives'; | ||
import { tabsTriggerVariants } from '../primitives/Tabs/TabsTrigger'; | ||
|
||
export const InboxTab = (props: { label: string; class?: string }) => { | ||
const style = useStyle(); | ||
|
||
// TODO: Replace with actual count from API | ||
const count = Math.floor(Math.random() * 120 + 1); | ||
|
||
return ( | ||
<Tabs.Trigger | ||
value={props.label} | ||
class={style( | ||
'notificationsTabs__tabsTrigger', | ||
cn(tabsTriggerVariants(), `nt-flex nt-gap-2 ${props.class ?? ''}`) | ||
)} | ||
> | ||
<span class={style('notificationsTabsTriggerLabel', 'nt-text-sm nt-font-medium')}>{props.label}</span> | ||
<span | ||
class={style( | ||
'notificationsTabsTriggerCount', | ||
'nt-rounded-full nt-bg-primary nt-px-[6px] nt-text-primary-foreground nt-text-sm' | ||
)} | ||
> | ||
{count >= 100 ? '99+' : count} | ||
</span> | ||
</Tabs.Trigger> | ||
); | ||
}; |
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,111 @@ | ||
/* eslint-disable local-rules/no-class-without-style */ | ||
import { createMemo, createSignal, For, Show } from 'solid-js'; | ||
import { Button, Dropdown, dropdownItemVariants, Tabs } from '../primitives'; | ||
import { NotificationList } from '../Notification'; | ||
import { InboxTab } from './InboxTab'; | ||
import { Check, DotsMenu } from '../../icons'; | ||
import { cn, useStyle } from '../../helpers'; | ||
import { tabsRootVariants } from '../primitives/Tabs/TabsRoot'; | ||
import { useTabsDropdown } from './useTabsDropdown'; | ||
|
||
const tabsDropdownTriggerVariants = () => | ||
`nt-relative after:nt-absolute after:nt-content-[''] after:nt-bottom-0 after:nt-left-0 ` + | ||
`after:nt-w-full after:nt-h-[2px] after:nt-border-b-2 nt-pb-[0.625rem]`; | ||
|
||
type InboxTabsProps = { | ||
tabs: Array<{ label: string; value: Array<string> }>; | ||
}; | ||
|
||
export const InboxTabs = (props: InboxTabsProps) => { | ||
const style = useStyle(); | ||
const [activeTab, setActiveTab] = createSignal<string>((props.tabs[0] && props.tabs[0].label) ?? ''); | ||
const { dropdownTabs, setTabsList, visibleTabs } = useTabsDropdown({ tabs: props.tabs }); | ||
|
||
const options = createMemo(() => | ||
dropdownTabs().map((tab) => ({ | ||
label: tab.label, | ||
rightIcon: tab.label === activeTab() ? <Check class={style('moreTabs__dropdownItemRightIcon')} /> : undefined, | ||
})) | ||
); | ||
|
||
const isTabsDropdownActive = createMemo(() => | ||
dropdownTabs() | ||
.map((tab) => tab.label) | ||
.includes(activeTab()) | ||
); | ||
|
||
return ( | ||
<Tabs.Root | ||
class={style('notificationsTabs__tabsRoot', cn(tabsRootVariants(), 'nt-flex-1 nt-overflow-hidden'))} | ||
value={activeTab()} | ||
onChange={setActiveTab} | ||
> | ||
<Show | ||
when={visibleTabs().length > 0} | ||
fallback={ | ||
<Tabs.List ref={setTabsList} appearanceKey="notificationsTabs__tabsList"> | ||
{props.tabs.map((tab) => ( | ||
<InboxTab label={tab.label} class="nt-invisible" /> | ||
))} | ||
</Tabs.List> | ||
} | ||
> | ||
<Tabs.List appearanceKey="notificationsTabs__tabsList"> | ||
{visibleTabs().map((tab) => ( | ||
<InboxTab label={tab.label} /> | ||
))} | ||
<Show when={dropdownTabs().length > 0}> | ||
<Dropdown.Root fallbackPlacements={['bottom', 'top']} placement={'bottom-start'}> | ||
<Dropdown.Trigger | ||
appearanceKey="moreTabs__dropdownTrigger" | ||
asChild={(triggerProps) => ( | ||
<Button | ||
variant="unstyled" | ||
size="none" | ||
appearanceKey="moreTabs__button" | ||
{...triggerProps} | ||
class={cn( | ||
tabsDropdownTriggerVariants(), | ||
isTabsDropdownActive() | ||
? 'after:nt-border-b-primary' | ||
: 'after:nt-border-b-transparent nt-text-foreground-alpha-600' | ||
)} | ||
> | ||
<DotsMenu appearanceKey="moreTabs__dots" /> | ||
</Button> | ||
)} | ||
/> | ||
<Dropdown.Content appearanceKey="moreTabs__dropdownContent"> | ||
<For each={options()}> | ||
{(option) => ( | ||
<Dropdown.Item | ||
class={style( | ||
'moreTabs__dropdownItem', | ||
cn(dropdownItemVariants(), 'nt-flex nt-justify-between nt-gap-2') | ||
)} | ||
onClick={() => setActiveTab(option.label)} | ||
> | ||
<span class={style('moreTabs__dropdownItemLabel', 'nt-mr-auto')}>{option.label}</span> | ||
{option.rightIcon} | ||
</Dropdown.Item> | ||
)} | ||
</For> | ||
</Dropdown.Content> | ||
</Dropdown.Root> | ||
</Show> | ||
</Tabs.List> | ||
</Show> | ||
{props.tabs.map((tab) => ( | ||
<Tabs.Content | ||
value={tab.label} | ||
class={style( | ||
'notificationsTabs__tabsContent', | ||
cn(activeTab() === tab.label ? 'nt-block' : 'nt-hidden', 'nt-flex-1 nt-overflow-hidden') | ||
)} | ||
> | ||
<NotificationList options={{ tags: tab.value }} /> | ||
</Tabs.Content> | ||
))} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './InboxTabs'; |
43 changes: 43 additions & 0 deletions
43
packages/js/src/ui/components/InboxTabs/useTabsDropdown.ts
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,43 @@ | ||
import { createSignal, onMount } from 'solid-js'; | ||
|
||
type TabsArray = Array<{ label: string; value: Array<string> }>; | ||
|
||
export const useTabsDropdown = ({ tabs }: { tabs: TabsArray }) => { | ||
const [tabsList, setTabsList] = createSignal<HTMLDivElement>(); | ||
const [visibleTabs, setVisibleTabs] = createSignal<TabsArray>([]); | ||
const [dropdownTabs, setDropdownTabs] = createSignal<TabsArray>([]); | ||
|
||
onMount(() => { | ||
const tabsListEl = tabsList(); | ||
if (!tabsListEl) return; | ||
|
||
const tabsElements = [...tabsListEl.querySelectorAll('[role="tab"]')]; | ||
|
||
const observer = new IntersectionObserver( | ||
(entries) => { | ||
let visibleTabIds = entries | ||
.filter((entry) => entry.isIntersecting && entry.intersectionRatio === 1) | ||
.map((entry) => entry.target.id); | ||
|
||
if (tabsElements.length === visibleTabIds.length) { | ||
setVisibleTabs(tabs.filter((tab) => visibleTabIds.includes(tab.label))); | ||
observer.disconnect(); | ||
|
||
return; | ||
} | ||
|
||
visibleTabIds = visibleTabIds.slice(0, -1); | ||
setVisibleTabs(tabs.filter((tab) => visibleTabIds.includes(tab.label))); | ||
setDropdownTabs(tabs.filter((tab) => !visibleTabIds.includes(tab.label))); | ||
observer.disconnect(); | ||
}, | ||
{ root: tabsListEl } | ||
); | ||
|
||
for (const tabElement of tabsElements) { | ||
observer.observe(tabElement); | ||
} | ||
}); | ||
|
||
return { dropdownTabs, setTabsList, visibleTabs }; | ||
}; |
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
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
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
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
Oops, something went wrong.