-
Couldn't load subscription status.
- Fork 0
Macgeargear/sucu 68 component tab #8
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1691541
feat(tab): tab content
macgeargear 9121f15
feat(tab): tab list
macgeargear 859366b
feat(tab): tab root
macgeargear 59e2a08
feat(tab): tab trigger
macgeargear 2015db1
feat(tab): tab context
macgeargear 6324e4b
feat(tab): example tab's usage
macgeargear 2a2c466
fix: lint
macgeargear a42874f
feat(tab): mobile
macgeargear 685c527
fix(tab): remove diabled props
macgeargear 8ccf5ad
feat(tabs): remove dispatch event (unused event value)
macgeargear a8b3721
fix(tab): register tab logic
macgeargear 2794cbe
feat(tab): custom class
macgeargear 72b591a
fix(tab): register tab logic
macgeargear 007fa4d
fix: lint
macgeargear 52d394b
Merge branch 'dev' into macgeargear/sucu-68-component-tab
macgeargear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,17 @@ | ||
| <script lang="ts"> | ||
| import { cn } from '$lib/utils'; | ||
| import { getTabsContext } from './tabsContext'; | ||
| export let value: string; | ||
| export let className: string = ''; | ||
| export { className as class }; | ||
| const { activeTab } = getTabsContext(); | ||
| $: isActive = $activeTab === value; | ||
| </script> | ||
|
|
||
| {#if isActive} | ||
| <div class={cn('p-4', className)}> | ||
| <slot /> | ||
| </div> | ||
| {/if} |
This file contains hidden or 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,12 @@ | ||
| <script lang="ts"> | ||
| import { cn } from '$lib/utils'; | ||
| export let className: string = ''; | ||
| export { className as class }; | ||
| </script> | ||
|
|
||
| <div class={cn('border-b border-sucu-gray-light', className)}> | ||
| <nav class="-mb-2 sm:mb-0 flex space-x-8 text-sucu-pink-hover"> | ||
| <slot /> | ||
| </nav> | ||
| </div> |
This file contains hidden or 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,17 @@ | ||
| <script lang="ts"> | ||
| import { setTabsContext } from './tabsContext'; | ||
| export let defaultActiveTab: string = ''; | ||
| export let className: string = ''; | ||
| export { className as class }; | ||
| const tabs = setTabsContext(); | ||
| if (defaultActiveTab) { | ||
| tabs.activeTab.set(defaultActiveTab); | ||
| } | ||
| </script> | ||
|
|
||
| <div class={className}> | ||
| <slot /> | ||
| </div> |
This file contains hidden or 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,46 @@ | ||
| <script lang="ts"> | ||
| import { onMount } from 'svelte'; | ||
| import { getTabsContext } from './tabsContext'; | ||
| import { cn } from '$lib/utils'; | ||
| import { slide } from 'svelte/transition'; | ||
| export let value: string; | ||
| export let className: string = ''; | ||
| export { className as class }; | ||
| const tabsContext = getTabsContext(); | ||
| const { activeTab } = tabsContext; | ||
| onMount(() => { | ||
| tabsContext.registerTab({ value }); | ||
| }); | ||
| $: isActive = $activeTab === value; | ||
| function handleClick() { | ||
| tabsContext.selectTab(value); | ||
| } | ||
| </script> | ||
|
|
||
| <div class={cn('relative inline-block', className)}> | ||
| <button | ||
| class={cn( | ||
| 'text-base mx-auto whitespace-nowrap py-4 px-1 font-medium sm:text-xl text-sucu-gray hover:text-sucu-pink-hover hover:border-gray-300', | ||
| { | ||
| 'border-sucu-pink-hover text-indigo': isActive | ||
| } | ||
| )} | ||
| on:click={handleClick} | ||
| > | ||
| <slot /> | ||
| </button> | ||
|
|
||
| {#if isActive} | ||
| <div | ||
| class={cn( | ||
| 'absolute left-1/2 transform -translate-x-1/2 bottom-[5.5px] sm:-bottom-1 h-1 sm:h-2 w-[120%] bg-sucu-pink-hover rounded-lg' | ||
| )} | ||
| transition:slide={{ duration: 300, axis: 'x' }} | ||
| /> | ||
| {/if} | ||
| </div> |
This file contains hidden or 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 { writable, type Writable } from 'svelte/store'; | ||
| import { setContext, getContext } from 'svelte'; | ||
|
|
||
| interface Tab { | ||
| value: string; | ||
| } | ||
|
|
||
| export interface TabsContext { | ||
| activeTab: Writable<string>; | ||
| tabs: Writable<Tab[]>; | ||
| registerTab: (tab: Tab) => void; | ||
| selectTab: (value: string) => void; | ||
| } | ||
|
|
||
| const createTabs = (): TabsContext => { | ||
| const activeTab = writable<string>(''); | ||
| const tabs = writable<Tab[]>([]); | ||
|
|
||
| const registerTab = (tab: Tab) => { | ||
| tabs.update((currTabs) => [...currTabs, tab]); | ||
| }; | ||
|
|
||
| const selectTab = (value: string) => { | ||
| activeTab.set(value); | ||
| }; | ||
|
|
||
| return { | ||
| activeTab, | ||
| tabs, | ||
| registerTab, | ||
| selectTab | ||
| }; | ||
| }; | ||
|
|
||
| export const setTabsContext = (): TabsContext => { | ||
| const tabs = createTabs(); | ||
| setContext<TabsContext>('tabs', tabs); | ||
| return tabs; | ||
| }; | ||
|
|
||
| export const getTabsContext = (): TabsContext => { | ||
| return getContext<TabsContext>('tabs'); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.