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

[Storybook] Add stories for more components (letter P) - Part 1 #7648

Merged
merged 20 commits into from
Apr 11, 2024
Merged
Changes from 1 commit
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
32 changes: 18 additions & 14 deletions src/components/page_template/page_template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
EuiPageSection,
EuiPageSectionProps,
EuiPageSidebar,
EuiPageSidebarProps,
} from '../page';
import { _EuiPageRestrictWidth } from '../page/_restrict_width';
import { _EuiPageBottomBorder } from '../page/_bottom_border';
Expand All @@ -41,6 +42,7 @@ import { logicalStyles } from '../../global_styling';
import { CommonProps } from '../common';

export const TemplateContext = createContext({
sidebar: {},
section: {},
header: {},
emptyPrompt: {},
Expand Down Expand Up @@ -112,23 +114,14 @@ export const _EuiPageTemplate: FunctionComponent<EuiPageTemplateProps> = ({
const sections: React.ReactElement[] = [];
const sidebar: React.ReactElement[] = [];

React.Children.toArray(children).forEach((child, index) => {
React.Children.toArray(children).forEach((child) => {
if (!React.isValidElement(child)) return; // Skip non-components

if (
child.type === EuiPageSidebar ||
child.props.__EMOTION_TYPE_PLEASE_DO_NOT_USE__ === EuiPageSidebar
child.type === _EuiPageSidebar ||
child.props.__EMOTION_TYPE_PLEASE_DO_NOT_USE__ === _EuiPageSidebar
) {
const sidebarProps = { paddingSize, responsive };

sidebar.push(
React.cloneElement(child, {
key: `sidebar${index}`,
...sidebarProps,
// Allow their props overridden by appending the child props spread at the end
...child.props,
})
);
sidebar.push(child);
mgadewoll marked this conversation as resolved.
Show resolved Hide resolved
} else {
sections.push(child);
}
Expand All @@ -151,6 +144,10 @@ export const _EuiPageTemplate: FunctionComponent<EuiPageTemplateProps> = ({

const templateContext = useMemo(() => {
mgadewoll marked this conversation as resolved.
Show resolved Hide resolved
return {
sidebar: {
paddingSize,
responsive,
},
header: {
restrictWidth,
paddingSize,
Expand All @@ -176,6 +173,7 @@ export const _EuiPageTemplate: FunctionComponent<EuiPageTemplateProps> = ({
}, [
pageInnerId,
restrictWidth,
responsive,
paddingSize,
panelled,
innerPanelled,
Expand Down Expand Up @@ -207,6 +205,12 @@ export const _EuiPageTemplate: FunctionComponent<EuiPageTemplateProps> = ({
);
};

const _EuiPageSidebar: FunctionComponent<EuiPageSidebarProps> = (props) => {
const { sidebar } = useContext(TemplateContext);

return <EuiPageSidebar {...sidebar} {...props} />;
};

const _EuiPageSection: FunctionComponent<EuiPageSectionProps> = (props) => {
const { section } = useContext(TemplateContext);

Expand Down Expand Up @@ -236,7 +240,7 @@ const _EuiPageBottomBar: FunctionComponent<_EuiPageBottomBarProps> = (
};

export const EuiPageTemplate = Object.assign(_EuiPageTemplate, {
Sidebar: EuiPageSidebar,
Sidebar: _EuiPageSidebar,
Header: _EuiPageHeader,
Section: _EuiPageSection,
BottomBar: _EuiPageBottomBar,
Expand Down