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

[EuiPageTemplate] Allow panelled={true} #7044

Merged
merged 5 commits into from
Aug 8, 2023
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
59 changes: 54 additions & 5 deletions src-docs/src/views/page_template/_page_demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ const ExitFullscreenDemoButton = () => {

type toggles = {
pageHeader?: boolean;
panelled?: boolean;
restrictedWidth?: boolean;
sidebar?: boolean;
sidebarSticky?: boolean;
border?: boolean;
// If a sidebar is present, a basic switch can be used
panelledSwitch?: boolean;
// If a sidebar is not present, `undefined` matters - use a group instead
panelledGroup?: boolean;
};

type showing = {
Expand Down Expand Up @@ -75,11 +78,12 @@ export const PageDemo: FunctionComponent<
},
toggle = {
pageHeader: false,
panelled: false,
restrictedWidth: false,
sidebar: false,
sidebarSticky: false,
border: false,
panelledSwitch: false,
panelledGroup: false,
},
template: Template = CustomTemplateExample,
source = CustomTemplateExampleSource,
Expand All @@ -88,7 +92,9 @@ export const PageDemo: FunctionComponent<
const isMobileSize = useIsWithinBreakpoints(['xs', 's']);

const [showHeader, setShowHeader] = useState<boolean>(true);
const [showPanelled, setShowPanelled] = useState<boolean>(true);
const [showPanelled, setShowPanelled] = useState<boolean | undefined>(
toggle.panelledGroup ? undefined : true
);
const [showSidebar, setShowSidebar] = useState<boolean>(
Boolean(show.sidebar)
);
Expand Down Expand Up @@ -288,16 +294,59 @@ export const PageDemo: FunctionComponent<
/>
</EuiFlexItem>
)}
{toggle.panelled && (
{toggle.panelledSwitch && (
<EuiFlexItem grow={false}>
<EuiSwitch
label="Panelled"
checked={showPanelled}
checked={!!showPanelled}
onChange={() => setShowPanelled((showing) => !showing)}
compressed
/>
</EuiFlexItem>
)}
{toggle.panelledGroup && (
<EuiFlexItem grow={false}>
<div>
Panelled:&emsp;
<EuiButtonGroup
options={[
{
id: 'radioTrue',
label: 'true',
},
{
id: 'radioFalse',
label: 'false',
},
{
id: 'radioUndefined',
label: 'undefined',
},
]}
idSelected={
showPanelled === true
? 'radioTrue'
: showPanelled === false
? 'radioFalse'
: 'radioUndefined'
}
onChange={(id) =>
setShowPanelled(
id === 'radioTrue'
? true
: id === 'radioFalse'
? false
: undefined
)
}
name="panelledGroup"
legend="Panelled"
buttonSize="compressed"
color="primary"
/>
</div>
</EuiFlexItem>
)}
</EuiFlexGroup>
);

Expand Down
12 changes: 6 additions & 6 deletions src-docs/src/views/page_template/examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const pageTemplateExamplesSections = [
slug="full-page"
fullscreen
toggle={{
panelled: true,
panelledGroup: true,
restrictedWidth: true,
}}
show={{
Expand All @@ -67,7 +67,7 @@ export const pageTemplateExamplesSections = [
fullscreen
template={Sidebar}
toggle={{
panelled: true,
panelledSwitch: true,
sidebar: true,
sidebarSticky: true,
border: true,
Expand Down Expand Up @@ -116,7 +116,7 @@ export const pageTemplateExamplesSections = [
template={Empty}
toggle={{
pageHeader: true,
panelled: true,
panelledSwitch: true,
sidebar: true,
}}
show={{
Expand Down Expand Up @@ -236,7 +236,7 @@ export const PageTemplateExample = () => (
<PageDemo
slug="full-page"
toggle={{
panelled: true,
panelledGroup: true,
restrictedWidth: true,
}}
show={{
Expand Down Expand Up @@ -300,7 +300,7 @@ export const PageTemplateExample = () => (
<PageDemo
slug="sidebar"
toggle={{
panelled: true,
panelledSwitch: true,
sidebar: true,
border: true,
}}
Expand Down Expand Up @@ -410,7 +410,7 @@ export const PageTemplateExample = () => (
source={EmptySource}
toggle={{
pageHeader: true,
panelled: true,
panelledSwitch: true,
sidebar: true,
}}
show={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ exports[`EuiPageTemplate _EuiPageInnerProps is rendered 1`] = `
</div>
`;

exports[`EuiPageTemplate _EuiPageInnerProps renders as panelled 1`] = `
<div
class="euiPageTemplate emotion-euiPageOuter-row-grow"
style="min-block-size: max(460px, 100vh); padding-block-start: 0;"
>
<div
class="emotion-euiPageInner-panelled"
id="EuiPageTemplateInner_generated-id"
/>
</div>
`;

exports[`EuiPageTemplate _EuiPageOuterProps is rendered 1`] = `
<div
class="euiPageTemplate emotion-euiPageOuter-column-grow"
Expand Down
30 changes: 20 additions & 10 deletions src/components/page_template/page_template.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,27 @@ describe('EuiPageTemplate', () => {
expect(container.firstChild).toMatchSnapshot();
});

test('_EuiPageInnerProps is rendered', () => {
const { container } = render(
<EuiPageTemplate
component="div"
contentBorder={true}
panelled={false}
mainProps={{ id: 'customID', className: 'customClassName' }}
/>
);
describe('_EuiPageInnerProps', () => {
it('is rendered', () => {
const { container } = render(
<EuiPageTemplate
component="div"
contentBorder={true}
panelled={false}
mainProps={{ id: 'customID', className: 'customClassName' }}
/>
);

expect(container.firstChild).toMatchSnapshot();
expect(container.firstChild).toMatchSnapshot();
});

it('renders as panelled', () => {
const { container } = render(
<EuiPageTemplate component="div" panelled />
);

expect(container.firstChild).toMatchSnapshot();
});
});

describe('restrict width', () => {
Expand Down
3 changes: 1 addition & 2 deletions src/components/page_template/page_template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ export const _EuiPageTemplate: FunctionComponent<EuiPageTemplateProps> = ({
parent: `#${pageInnerId}`,
});

const innerPanelled = () =>
panelled === false ? false : Boolean(sidebar.length > 0);
const innerPanelled = () => panelled ?? Boolean(sidebar.length > 0);

const innerBordered = () =>
contentBorder !== undefined ? contentBorder : Boolean(sidebar.length > 0);
Expand Down
3 changes: 3 additions & 0 deletions upcoming_changelogs/7044.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Bug fixes**

- `EuiPageTemplate` now correctly displays `panelled={true}`
Loading