Skip to content

Commit 2a98582

Browse files
committed
Write a changeset
1 parent cd072c8 commit 2a98582

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

.changeset/lovely-feet-float.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@theguild/components': minor
3+
---
4+
5+
Extract Tabs component from Nextra

packages/components/src/components/tabs/index.client.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ export const Tabs = ({
6969
}: TabsProps) => {
7070
const id = useId();
7171

72+
storageKey ??= `tabs-${id}`;
73+
7274
let [selectedIndex, setSelectedIndex] = useState<number>(defaultIndex);
7375
if (_selectedIndex !== undefined) {
7476
selectedIndex = _selectedIndex;
@@ -84,13 +86,7 @@ export const Tabs = ({
8486
id,
8587
);
8688

87-
useActiveTabFromStorage(
88-
storageKey ?? id,
89-
items,
90-
setSelectedIndex,
91-
tabIndexFromSearchParams !== -1,
92-
id,
93-
);
89+
useActiveTabFromStorage(storageKey, items, setSelectedIndex, tabIndexFromSearchParams !== -1, id);
9490

9591
const handleChange = (index: number) => {
9692
onChange?.(index);
@@ -209,8 +205,6 @@ function useActiveTabFromURL(
209205
tabsInSearchParams.includes(getTabKey(items, index, id)),
210206
);
211207

212-
console.log({ tabIndexFromSearchParams, tabsInSearchParams });
213-
214208
useIsomorphicLayoutEffect(() => {
215209
const tabPanel = hash
216210
? tabPanelsRef.current?.querySelector(`[role=tabpanel]:has([id="${hash}"])`)

packages/components/src/components/tabs/tabs.stories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,13 @@ export const TabsSyncedWithStorageEvents: Story = {
454454
<Tabs.Tab key={item}>{item}</Tabs.Tab>
455455
))}
456456
</Tabs>
457+
<hr className="my-8" />
458+
This one doesn't have a `storageKey`, so it's not connected:
459+
<Tabs items={['pnpm', 'npm', 'yarn']}>
460+
{['pnpm', 'npm', 'yarn'].map(item => (
461+
<Tabs.Tab key={item}>{item}</Tabs.Tab>
462+
))}
463+
</Tabs>
457464
</div>
458465
);
459466
},

0 commit comments

Comments
 (0)