Skip to content

Commit

Permalink
add in optional setting component to the Panel component
Browse files Browse the repository at this point in the history
Summary: Wanted to create a setting switch to toggle between show/hide for ineditor comments.

Differential Revision: D68719087

fbshipit-source-id: 0e1f2ede4b6ab3752abb437dee22df73108edd91
  • Loading branch information
Jack Huang authored and facebook-github-bot committed Jan 29, 2025
1 parent 34d8453 commit 1508815
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions addons/components/Panels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const styles = stylex.create({
tabpanel: {
padding: '0 6px 10px 6px',
},
spaceBetween: {
justifyContent: 'space-between',
},
});

export type PanelInfo = {render: () => ReactNode; label: ReactNode};
Expand All @@ -47,6 +50,7 @@ export function Panels<T extends string>({
alignmentProps,
active,
onSelect,
tabListOptionalComponent,
}: {
panels: Record<T, PanelInfo>;
xstyle?: stylex.StyleXStyles;
Expand All @@ -55,22 +59,26 @@ export function Panels<T extends string>({
alignmentProps?: ColumnAlignmentProps;
active: T;
onSelect: (item: T) => void;
tabListOptionalComponent?: ReactNode;
}) {
return (
<Column xstyle={xstyle} {...(alignmentProps ?? {alignStart: true})}>
<Row xstyle={[styles.tabList, tabListXstyle]} role="tablist">
{(Object.entries(panels) as Array<[T, PanelInfo]>).map(([name, value]) => {
return (
<button
role="tab"
aria-selected={active === name}
key={name}
onClick={() => onSelect(name)}
{...stylex.props(styles.tab, active === name && styles.activeTab, tabXstyle)}>
{value.label}
</button>
);
})}
<Row xstyle={[styles.tabList, styles.spaceBetween, tabListXstyle]} role="tablist">
<Row>
{(Object.entries(panels) as Array<[T, PanelInfo]>).map(([name, value]) => {
return (
<button
role="tab"
aria-selected={active === name}
key={name}
onClick={() => onSelect(name)}
{...stylex.props(styles.tab, active === name && styles.activeTab, tabXstyle)}>
{value.label}
</button>
);
})}
</Row>
{tabListOptionalComponent}
</Row>
<div role="tabpanel" {...stylex.props(styles.tabpanel)}>
{panels[active]?.render()}
Expand Down

0 comments on commit 1508815

Please sign in to comment.