Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Unreleased
- Added an optional `DisplayTitle` prop to `TabContainer` children tabs to allow displaying custom text on tabs

## 1.2.0

- Added usePlugin hook
Expand Down
30 changes: 29 additions & 1 deletion src/Components/TabContainer.luau
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@
end
```

To override the text displayed on a tab, assign a value to the optional
`DisplayTitle` field in the tab entry; see the "Comments" example below:
```lua
local function MyPluginApp(props: {
comments: { string }
})
local selectedTab, setSelectedTab = React.useState("Comments")
local commentsArray = props.comments

return React.createElement(TabContainer, {
SelectedTab = selectedTab,
OnTabSelected = setSelectedTab,
}, {
["Comments"] = {
LayoutOrder = 1,
DisplayTitle = `Comments ({#commentsArray})`,
Content = React.createElement(...),
},
["Settings"] = {
LayoutOrder = 2,
Content = React.createElement(...),
}
})
end
```

As well as disabling the entire component via the `Disabled` [CommonProp](CommonProps), individual
tabs can be disabled and made unselectable by passing `Disabled` with a value of `true` inside
the tab's entry in the `Tabs` prop table.
Expand All @@ -60,13 +86,15 @@ local TAB_HEIGHT = 30
@interface Tab

@field LayoutOrder number
@field DisplayTitle string?
@field Content React.ReactNode
@field Disabled boolean?
]=]

type Tab = {
Content: React.ReactNode,
LayoutOrder: number,
DisplayTitle: string?,
Disabled: boolean?,
}

Expand Down Expand Up @@ -185,7 +213,7 @@ local function TabContainer(props: TabContainerProps)
tabs[name] = React.createElement(TabButton, {
Size = UDim2.fromScale(1 / count, 1),
LayoutOrder = tab.LayoutOrder,
Text = name,
Text = tab.DisplayTitle or name,
Selected = isSelectedTab,
Disabled = tab.Disabled == true or props.Disabled == true,
OnActivated = function()
Expand Down
Loading