-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fuselage-ui-kit): Introduce
TabNavigationBlock
(#29908)
- Loading branch information
1 parent
357a3a5
commit dc1d8ce
Showing
11 changed files
with
297 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@rocket.chat/fuselage-ui-kit": patch | ||
"@rocket.chat/uikit-playground": patch | ||
--- | ||
|
||
feat(fuselage-ui-kit): Introduce `TabsNavigationBlock` |
44 changes: 44 additions & 0 deletions
44
packages/fuselage-ui-kit/src/blocks/TabNavigationBlock.tsx
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,44 @@ | ||
import { Tabs } from '@rocket.chat/fuselage'; | ||
import type { ExperimentalTabNavigationBlock } from '@rocket.chat/ui-kit'; | ||
import type { ReactElement } from 'react'; | ||
import { memo, useState } from 'react'; | ||
|
||
import { TabElement } from '../elements/TabElement'; | ||
import type { BlockProps } from '../utils/BlockProps'; | ||
|
||
type TabNavigationBlockProps = BlockProps<ExperimentalTabNavigationBlock>; | ||
|
||
const TabNavigationBlock = ( | ||
blockProps: TabNavigationBlockProps | ||
): ReactElement => { | ||
const { | ||
block: { tabs }, | ||
context, | ||
surfaceRenderer, | ||
} = blockProps; | ||
|
||
const [selected, select] = useState<number>(); | ||
|
||
return ( | ||
<Tabs marginBlock='x24'> | ||
{tabs.map((innerBlock, idx) => { | ||
if (selected !== undefined) { | ||
innerBlock.selected = idx === selected; | ||
} | ||
|
||
return ( | ||
<TabElement | ||
key={`${innerBlock.blockId}_${idx}`} | ||
index={idx} | ||
context={context} | ||
surfaceRenderer={surfaceRenderer} | ||
block={innerBlock} | ||
select={select} | ||
/> | ||
); | ||
})} | ||
</Tabs> | ||
); | ||
}; | ||
|
||
export default memo(TabNavigationBlock); |
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,33 @@ | ||
import { TabsItem } from '@rocket.chat/fuselage'; | ||
import * as UiKit from '@rocket.chat/ui-kit'; | ||
import type { Dispatch, ReactElement } from 'react'; | ||
|
||
import { useUiKitState } from '../hooks/useUiKitState'; | ||
import type { BlockProps } from '../utils/BlockProps'; | ||
|
||
export const TabElement = ({ | ||
block, | ||
context, | ||
surfaceRenderer, | ||
index, | ||
select, | ||
}: BlockProps<UiKit.ExperimentalTabElement> & { | ||
select: Dispatch<number>; | ||
}): ReactElement => { | ||
const [{ loading }, action] = useUiKitState(block, context); | ||
|
||
const { title, selected, disabled } = block; | ||
|
||
return ( | ||
<TabsItem | ||
selected={selected} | ||
disabled={loading ? true : disabled} | ||
onClick={(e) => { | ||
!disabled && select(index); | ||
!disabled && action(e); | ||
}} | ||
> | ||
{surfaceRenderer.renderTextObject(title, 0, UiKit.BlockContext.NONE)} | ||
</TabsItem> | ||
); | ||
}; |
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
36 changes: 36 additions & 0 deletions
36
packages/uikit-playground/src/Payload/tabNavigation/disabled.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,36 @@ | ||
import { LayoutBlock } from "@rocket.chat/ui-kit"; | ||
|
||
export const disabled: readonly LayoutBlock[] = [{ | ||
type: 'tab_navigation', | ||
tabs: [{ | ||
type: 'tab', | ||
disabled: true, | ||
title: { | ||
type: 'plain_text', | ||
text: 'tab 1', | ||
}, | ||
appId: 'tab_navigation', | ||
blockId: 'tab1', | ||
actionId: 'tab1', | ||
}, | ||
{ | ||
type: 'tab', | ||
title: { | ||
type: 'plain_text', | ||
text: 'tab 2', | ||
}, | ||
appId: 'tab_navigation', | ||
blockId: 'tab2', | ||
actionId: 'tab2', | ||
}, | ||
{ | ||
type: 'tab', | ||
title: { | ||
type: 'plain_text', | ||
text: 'tab 3', | ||
}, | ||
appId: 'tab_navigation', | ||
blockId: 'tab3', | ||
actionId: 'tab3', | ||
}], | ||
}]; |
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,3 @@ | ||
export { plain } from './plain' | ||
export { disabled } from './disabled' | ||
export { selected } from './selected' |
35 changes: 35 additions & 0 deletions
35
packages/uikit-playground/src/Payload/tabNavigation/plain.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,35 @@ | ||
import { LayoutBlock } from "@rocket.chat/ui-kit"; | ||
|
||
export const plain: readonly LayoutBlock[] = [{ | ||
type: 'tab_navigation', | ||
tabs: [{ | ||
type: 'tab', | ||
title: { | ||
type: 'plain_text', | ||
text: 'tab 1', | ||
}, | ||
appId: 'tab_navigation', | ||
blockId: 'tab1', | ||
actionId: 'tab1', | ||
}, | ||
{ | ||
type: 'tab', | ||
title: { | ||
type: 'plain_text', | ||
text: 'tab 2', | ||
}, | ||
appId: 'tab_navigation', | ||
blockId: 'tab2', | ||
actionId: 'tab2', | ||
}, | ||
{ | ||
type: 'tab', | ||
title: { | ||
type: 'plain_text', | ||
text: 'tab 3', | ||
}, | ||
appId: 'tab_navigation', | ||
blockId: 'tab3', | ||
actionId: 'tab3', | ||
}], | ||
}]; |
36 changes: 36 additions & 0 deletions
36
packages/uikit-playground/src/Payload/tabNavigation/selected.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,36 @@ | ||
import { LayoutBlock } from "@rocket.chat/ui-kit"; | ||
|
||
export const selected: readonly LayoutBlock[] = [{ | ||
type: 'tab_navigation', | ||
tabs: [{ | ||
type: 'tab', | ||
title: { | ||
type: 'plain_text', | ||
text: 'tab 1', | ||
}, | ||
appId: 'tab_navigation', | ||
blockId: 'tab1', | ||
actionId: 'tab1', | ||
}, | ||
{ | ||
type: 'tab', | ||
title: { | ||
type: 'plain_text', | ||
text: 'tab 2', | ||
}, | ||
appId: 'tab_navigation', | ||
blockId: 'tab2', | ||
actionId: 'tab2', | ||
}, | ||
{ | ||
type: 'tab', | ||
title: { | ||
type: 'plain_text', | ||
text: 'tab 3', | ||
}, | ||
selected: true, | ||
appId: 'tab_navigation', | ||
blockId: 'tab3', | ||
actionId: 'tab3', | ||
}], | ||
}]; |
Oops, something went wrong.