Skip to content

Commit 6909794

Browse files
committed
chore(docs,tabs): update API docs, fix CSS spacing
1 parent 2ecc712 commit 6909794

File tree

5 files changed

+74
-15
lines changed

5 files changed

+74
-15
lines changed

apps/website/src/routes/docs.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
@apply lg:ml-80 w-full lg:max-w-4xl xl:max-w-6xl py-8 px-8 lg:px-16;
44
}
55

6-
/*
6+
/*
77
Styles that are direct descendents of .docs
8-
this should not affect the styles inside of the tabpanel
8+
this should not affect the styles inside of the tabpanel
99
A.K.A the components
1010
*/
1111
& > {
@@ -31,11 +31,11 @@
3131
}
3232

3333
h3 {
34-
@apply text-xl font-bold mb-6;
34+
@apply text-xl font-bold mt-4 mb-6;
3535
}
3636

3737
h4 {
38-
@apply text-lg mb-6;
38+
@apply text-lg mt-4 mb-6;
3939
}
4040

4141
h5 {

apps/website/src/routes/docs/_components/api-table/api-table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type APITableProps = {
1212
export const APITable = component$(({ propDescriptors }: APITableProps) => {
1313
return (
1414
<div class="overflow-auto">
15-
<table class="w-full min-w-[540px] border-b border-gray-700 text-left sm:min-w-full">
15+
<table class="w-full min-w-[540px] border-b border-gray-700 text-left sm:min-w-full mb-6">
1616
<tbody class="divide-y divide-gray-700">
1717
<tr class="w-1/4 dark:text-white ">
1818
<td class="w-1/6 whitespace-nowrap py-2 pl-4 text-sm font-medium sm:pl-0">

apps/website/src/routes/docs/headless/(components)/tabs/index.mdx

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import { APITable } from '../../../_components/api-table/api-table';
6060

6161
return (
6262
<>
63-
<Tabs>
63+
<Tabs seletedIndex={1}>
6464
<TabList>
6565
<Tab>Tab 1</Tab>
6666
<Tab>Tab 2</Tab>
@@ -91,7 +91,7 @@ import { APITable } from '../../../_components/api-table/api-table';
9191
<>
9292
<Tabs>
9393
<TabPanel title="Tab 1">Content 1</TabPanel>
94-
<TabPanel title="Tab 2">Content 2</TabPanel>
94+
<TabPanel title="Tab 2" selected>Content 2</TabPanel>
9595
<TabPanel title="Tab 3">Content 3</TabPanel>
9696
</Tabs>
9797
</>
@@ -406,6 +406,11 @@ return <div>
406406
type: 'number',
407407
description: 'A way to set the selected index programmatically',
408408
},
409+
{
410+
name: 'selectedTabId',
411+
type: 'number',
412+
description: 'A way to set the selected tabId programmatically. The tabId is set by the `key` prop of the Tab or TabPanel',
413+
},
409414
{
410415
name: 'vertical',
411416
type: 'boolean',
@@ -417,7 +422,38 @@ return <div>
417422
type: 'function',
418423
info: '(index: number) => void',
419424
description:
420-
'An event hook that getting notified whenever the selected index changes',
425+
'An event hook that gets notified whenever the selected index changes',
426+
},
427+
{
428+
name: 'onSelectedTabIdChange$',
429+
type: 'function',
430+
info: '(index: string) => void',
431+
description:
432+
'An event hook that gets notified whenever the selected tabId changes',
433+
},
434+
{
435+
name: 'bind:selectedIndex',
436+
type: 'signal',
437+
info: 'Signal<number | undefined>',
438+
description:
439+
'A signal that binds the selected index. This is a more efficient version of `selectedIndex` + `onSelectedIndexChange$`',
440+
},
441+
{
442+
name: 'bind:selectedTabId',
443+
type: 'signal',
444+
info: 'Signal<string | undefined>',
445+
description:
446+
'A signal that binds the selected tabId. This is a more efficient version of `selectedTabId` + `onSelectedTabIdChange$`',
447+
},
448+
{
449+
name: 'tabClass',
450+
type: 'string',
451+
description: 'The class name to apply to tabs',
452+
},
453+
{
454+
name: 'panelClass',
455+
type: 'string',
456+
description: 'The class name to apply to panels',
421457
},
422458
]}
423459
/>
@@ -432,10 +468,9 @@ return <div>
432468
description: 'The class name to apply when the tab is selected',
433469
},
434470
{
435-
name: 'onClick',
436-
info: '(event: QwikMouseEvent) => void',
437-
type: 'function',
438-
description: 'A custom click handler to wire to tab click event',
471+
name: 'selected',
472+
type: 'boolean',
473+
description: 'Select this tab by default',
439474
},
440475
{
441476
name: 'disabled',
@@ -444,4 +479,20 @@ return <div>
444479
},
445480
]}
446481
/>
447-
```
482+
483+
### TabPanel
484+
485+
<APITable
486+
propDescriptors={[
487+
{
488+
name: 'label',
489+
type: 'element',
490+
description: 'Shorthand for `<Tab>{label}</Tab>`',
491+
},
492+
{
493+
name: 'selected',
494+
type: 'boolean',
495+
description: 'Select this tab by default',
496+
},
497+
]}
498+
/>

packages/kit-headless/src/components/tabs/tabs.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ describe('Tabs', () => {
160160
))}
161161
</TabList>
162162
{tabsState.map((tab) => (
163-
<TabPanel key={tab}>{tab} Panel</TabPanel>
163+
// Making sure the key is taken from the tab
164+
<TabPanel key={'panel' + tab}>{tab} Panel</TabPanel>
164165
))}
165166
</Tabs>
166167
<button onClick$={() => tabsState.splice(tabIndexToDelete, 1)}>

packages/kit-headless/src/components/tabs/tabs.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ import { TabList } from './tabs-list';
3434
* NOTE: scrolling support? or multiple lines? (probably not for headless but for tailwind / material )
3535
* Add ability to close tabs with an ❌ icon (and keyboard support)
3636
37+
* TO DISCUSS
38+
- name of the components, e.g. Tabs, Tabs.Trigger, Tabs.Panel
39+
- selectedClassname => selectedClass
40+
- do we keep all current props (tabId callbacks?)
41+
- shorthand for tab: "label" or "tab"?
42+
- the TODOs
43+
- why id and data-tab-id? we don't need any of them
3744
*
3845
*/
3946

@@ -149,7 +156,7 @@ export const Tabs: FunctionComponent<TabsProps> = (props) => {
149156
case TabPanel: {
150157
const { label, selected } = child.props;
151158
// The consumer must provide a key if they change the order
152-
const tabId = child.key || `${panelIndex}`;
159+
const tabId = tabComponents[panelIndex]?.key || child.key || `${panelIndex}`;
153160

154161
if (label) {
155162
tabComponents.push(<Tab>{label}</Tab>);

0 commit comments

Comments
 (0)