Skip to content
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

chore(docs): added tabs to select token layer to display #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
51 changes: 47 additions & 4 deletions packages/module/patternfly-docs/content/tokensTable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import React from 'react';
import { Flex, FlexItem, Grid, GridItem, Title, capitalize } from '@patternfly/react-core';
import {
Flex,
FlexItem,
Grid,
GridItem,
Tabs,
Tab,
TabContent,
TabTitleText,
Title,
capitalize
} from '@patternfly/react-core';
import {
Table,
Thead,
Expand Down Expand Up @@ -104,6 +115,15 @@ export const TokensTable = ({ tokenJson, formatThemeText = capitalize }) => {
const otherExpandedTokens = prevExpanded.filter((n) => n !== tokenName);
return isExpanding ? [...otherExpandedTokens, tokenName] : otherExpandedTokens;
});
const [activeTabKey, setActiveTabKey] = React.useState(0);
// Toggle currently active tab
const handleTabClick = (_event, tabIndex) => setActiveTabKey(tabIndex);
const tokenLayers = Object.keys(allTokens);
// create refs for each layer for tabs
let tabRefs = {};
tokenLayers.forEach((layer) => {
tabRefs[`${layer}Ref`] = React.createRef();
});

return (
<React.Fragment>
Expand All @@ -113,11 +133,29 @@ export const TokensTable = ({ tokenJson, formatThemeText = capitalize }) => {
selectedCategories={selectedCategories}
setSelectedCategories={setSelectedCategories}
/>
<Tabs
unmountOnExit
activeKey={activeTabKey}
onSelect={handleTabClick}
aria-label="Tabs to select tokens layer"
role="region"
>
{tokenLayers.map((layer, idx) => (
<Tab
key={idx}
eventKey={idx}
title={<TabTitleText>{formatThemeText(layer)} tokens</TabTitleText>}
aria-label={`${layer} tokens content`}
tabContentId={`${layer}TokensTabContent`}
tabContentRef={tabRefs[`${layer}Ref`]}
/>
))}
</Tabs>
<OuterScrollContainer className="tokens-table-outer-wrapper">
<InnerScrollContainer>
{
// Create new Table for each tokens layer [base, chart, palette, semantic]
Object.entries(allTokens).map(([layerName, layerDataObj], _rowIndex) => {
Object.entries(allTokens).map(([layerName, layerDataObj], idx) => {
// save if semantic layer - used for custom styling due to description field
const isSemanticLayer = layerName === 'semantic';

Expand All @@ -137,7 +175,12 @@ export const TokensTable = ({ tokenJson, formatThemeText = capitalize }) => {
);

return (
<>
<TabContent
eventKey={idx}
id={`${layerName}TokensTabContent`}
ref={tabRefs[`${layerName}Ref`]}
aria-label={`${layerName} tokens tab content`}
>
<Title headingLevel="h2" id={`${layerName}-table`} className="pf-v6-u-mt-xl">
{formatThemeText(layerName)} tokens
</Title>
Expand Down Expand Up @@ -235,7 +278,7 @@ export const TokensTable = ({ tokenJson, formatThemeText = capitalize }) => {
);
})}
</Table>
</>
</TabContent>
);
})
}
Expand Down
Loading