Skip to content

Instantly share code, notes, and snippets.

@nautilytics
Last active August 9, 2021 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nautilytics/2ab6b81db299f340c29e37c0a099e7d0 to your computer and use it in GitHub Desktop.
Save nautilytics/2ab6b81db299f340c29e37c0a099e7d0 to your computer and use it in GitHub Desktop.
Base Web Accordion with Panel Example
import * as React from 'react';
import {
StatelessAccordion,
} from 'baseui/accordion';
import type {
StatelessAccordionProps,
} from 'baseui/accordion';
export function Accordion(props: StatelessAccordionProps): JSX.Element {
const {
children,
...otherProps
} = props;
return (
<StatelessAccordion
overrides={{
ToggleIcon: {
style: {
display: 'none',
},
},
}}
{...otherProps}
>
{children}
</StatelessAccordion>
);
}
import React from 'react';
import { styled } from 'baseui';
const ColumnLayout = styled('div', {
display: 'flex',
flexDirection: 'column',
});
function CustomPanelContent(props: any): JSX.Element {
return (
<ColumnLayout>
Lots of content
</ColumnLayout>
);
}
export default CustomPanelContent;
import React from 'react';
import { Panel as BasePanel, styled } from 'baseui';
const ColumnLayout = styled('div', {
display: 'flex',
flexDirection: 'column',
});
function CustomPanelContentNotWorking(props: any): JSX.Element {
return (
<BasePanel
key='1'
title="Panel 1"
>
<ColumnLayout>
Lots of content
</ColumnLayout>
</BasePanel>
);
}
export default CustomPanelContentNotWorking;
import React from 'react';
import { Panel as BasePanel } from 'baseui';
import { Accordion as StatelessAccordion } from './Accordion';
import { CustomPanelContent } from './CustomPanelContent';
function CustomAccordion(props): JSX.Element {
const [expanded, setExpanded] = React.useState<React.Key[]>([]);
return (
<StatelessAccordion
expanded={expanded}
accordion={false}
onChange={({ key }) => {
setExpanded([key]);
}}
>
<BasePanel
key='1'
title="Panel 1"
>
<CustomPanelContent />
</BasePanel>
<CustomPanelContentNotWorking />
</StatelessAccordion>
);
}
export default CustomAccordion;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment