-
Notifications
You must be signed in to change notification settings - Fork 34
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
PageTemplate and Layout component #2219
Merged
Merged
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
fac7853
feat: start layout component
trevoring-okta 0a1cd83
feat: more work on layout component
trevoring-okta 2f7ca88
feat: documentation and syntax updates
trevoring-okta baded28
fix: update to storybook and component
trevoring-okta cba53dc
feat: add more to Storybook
trevoring-okta 2a8f9a2
fix: remove unncessary MUI ScopedCssBaseline
trevoring-okta 5c3c1b5
feat: add full-width story
trevoring-okta 3da76c1
feat(odyssey-react-mui): create surface component
bryancunningham-okta 762febb
feat(odyssey-react-mui): create stories for Grid
bryancunningham-okta ed431aa
feat(odyssey-react-mui): remove surface styling from Grid
bryancunningham-okta 24d9734
fix: small nit fixes
trevoring-okta 5341d2b
feat(odyssey-react-mui): panes => regions
bryancunningham-okta 28662cb
fix(odyssey-react-mui): rename components and add disclaimer
bryancunningham-okta 9192e28
fix: standardize vertical layout distance
jordankoschei-okta 4337437
refactor: update css
jordankoschei-okta db40151
refactor: alphabetize the imports
jordankoschei-okta 5ee9de1
feat: add rudimentary responsiveness to Layout
jordankoschei-okta 286a346
refactor: improve nested selectors
jordankoschei-okta 7b046a4
refactor: update based on code review
jordankoschei-okta af78af3
Merge branch 'main' into ti-OKTA-721245-layout-component
jordankoschei-okta f7b20d1
fix: update redundant type export
jordankoschei-okta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/*! | ||
* Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved. | ||
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") | ||
* | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* | ||
* See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
import { memo, ReactNode } from "react"; | ||
import styled from "@emotion/styled"; | ||
import { Paper as MuiPaper } from "@mui/material"; | ||
|
||
import { | ||
DesignTokens, | ||
useOdysseyDesignTokens, | ||
} from "./OdysseyDesignTokensContext"; | ||
|
||
const StyledContainer = styled(MuiPaper, { | ||
shouldForwardProp: (prop) => prop !== "odysseyDesignTokens", | ||
})<{ | ||
odysseyDesignTokens: DesignTokens; | ||
}>(({ odysseyDesignTokens }) => ({ | ||
borderRadius: odysseyDesignTokens.Spacing4, | ||
padding: odysseyDesignTokens.Spacing4, | ||
})); | ||
|
||
export type SurfaceProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
const Surface = ({ children }: SurfaceProps) => { | ||
const odysseyDesignTokens = useOdysseyDesignTokens(); | ||
|
||
return ( | ||
<StyledContainer odysseyDesignTokens={odysseyDesignTokens}> | ||
{children} | ||
</StyledContainer> | ||
); | ||
}; | ||
|
||
const MemoizedSurface = memo(Surface); | ||
MemoizedSurface.displayName = "Surface"; | ||
|
||
export { MemoizedSurface as Surface }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/*! | ||
* Copyright (c) 2024-present, Okta, Inc. and/or its affiliates. All rights reserved. | ||
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") | ||
* | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* | ||
* See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
import { Children, ReactNode, memo } from "react"; | ||
import styled from "@emotion/styled"; | ||
|
||
import { Box } from "../Box"; | ||
import { | ||
DesignTokens, | ||
useOdysseyDesignTokens, | ||
} from "../OdysseyDesignTokensContext"; | ||
|
||
type SupportedRegionRatios = | ||
| [1] | ||
| [1, 1] | ||
| [1, 2] | ||
| [2, 1] | ||
| [1, 3] | ||
| [3, 1] | ||
| [1, 1, 1] | ||
| [1, 1, 1, 1]; | ||
|
||
export type LayoutProps = { | ||
/** | ||
* The supported region ratios for the Grid. Each number is a fractional unit that is mapped to the 'fr' CSS unit. | ||
* e.g. [2, 1] defines a 2/3, 1/3 layout and [1, 1, 1] defines a 1/3, 1/3, 1/3 layout | ||
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_grid_layout/Basic_concepts_of_grid_layout#the_fr_unit | ||
*/ | ||
regions: SupportedRegionRatios; | ||
/** | ||
* The content of the Grid. May be a `string` or any other `ReactNode` or array of `ReactNode`s. | ||
*/ | ||
children?: ReactNode; | ||
}; | ||
|
||
interface LayoutContentProps { | ||
odysseyDesignTokens: DesignTokens; | ||
regions: string; | ||
} | ||
|
||
const LayoutContent = styled("div", { | ||
shouldForwardProp: (prop) => | ||
!["odysseyDesignTokens", "regions"].includes(prop), | ||
})<LayoutContentProps>(({ odysseyDesignTokens, regions }) => ({ | ||
display: "grid", | ||
gridTemplateColumns: regions, | ||
gridColumnGap: odysseyDesignTokens.Spacing4, | ||
columnGap: odysseyDesignTokens.Spacing4, | ||
|
||
"& + &": { | ||
marginBlockStart: odysseyDesignTokens.Spacing4, | ||
}, | ||
})); | ||
|
||
const Layout = ({ regions, children }: LayoutProps) => { | ||
const odysseyDesignTokens = useOdysseyDesignTokens(); | ||
const mappedRegions = regions | ||
.map((region) => `minmax(0, ${region}fr)`) | ||
.join(" "); | ||
|
||
return ( | ||
<Box> | ||
jordankoschei-okta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<LayoutContent | ||
odysseyDesignTokens={odysseyDesignTokens} | ||
regions={mappedRegions} | ||
> | ||
{Children.toArray(children).map((child) => child)} | ||
</LayoutContent> | ||
</Box> | ||
); | ||
}; | ||
|
||
const MemoizedLayout = memo(Layout); | ||
MemoizedLayout.displayName = "Layout"; | ||
|
||
export { MemoizedLayout as Layout }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
/*! | ||
* Copyright (c) 2024-present, Okta, Inc. and/or its affiliates. All rights reserved. | ||
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") | ||
* | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* | ||
* See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
import { memo, ReactElement, ReactNode } from "react"; | ||
import styled from "@emotion/styled"; | ||
|
||
import { | ||
DesignTokens, | ||
useOdysseyDesignTokens, | ||
} from "../OdysseyDesignTokensContext"; | ||
import { DocumentationIcon } from "../icons.generated"; | ||
import { Heading4, Subordinate } from "../Typography"; | ||
import { Link } from "../Link"; | ||
|
||
export type PageTemplateProps = { | ||
/** | ||
* The title of the layout to be situated in the layout header | ||
*/ | ||
title?: string; | ||
/** | ||
* A supplementary description to be situated in the layout header | ||
*/ | ||
description?: string; | ||
/** | ||
* The destination for a documentation `Link` to be situated in the layout header | ||
*/ | ||
documentationLink?: string; | ||
/** | ||
* The text for a documentation `Link` to be situated in the layout header | ||
*/ | ||
documentationText?: string; | ||
/** | ||
* An optional `Drawer` object. Can be of variant 'temporary' or 'persistent'. | ||
*/ | ||
drawer?: ReactElement; | ||
/** | ||
* An optional `Button` object to be situated in the layout header. Should almost always be of variant `primary`. | ||
*/ | ||
primaryCallToActionComponent?: ReactElement; | ||
/** | ||
* An optional `Button` object to be situated in the layout header, alongside the `callToActionPrimaryComponent`. | ||
*/ | ||
secondaryCallToActionComponent?: ReactElement; | ||
/** | ||
* An optional `Button` object to be situated in the layout header, alongside the other two `callToAction` components. | ||
*/ | ||
tertiaryCallToActionComponent?: ReactElement; | ||
/** | ||
* The content of the layout. May be a `string` or any other `ReactNode` or array of `ReactNode`s. Will often be `Grid` objects. | ||
*/ | ||
children?: ReactNode; | ||
/** | ||
* When set to `true`, the layout expands past its max width of 1440px and spans the entire available screen width. | ||
*/ | ||
isFullWidth?: boolean; | ||
}; | ||
|
||
type TemplateContentProps = { | ||
odysseyDesignTokens: DesignTokens; | ||
isDrawerOpen?: boolean; | ||
drawerVariant?: string; | ||
}; | ||
|
||
const TemplateContainer = styled("div", { | ||
shouldForwardProp: (prop) => | ||
prop !== "odysseyDesignTokens" && prop !== "isFullWidth", | ||
})<{ | ||
odysseyDesignTokens: DesignTokens; | ||
isFullWidth: boolean; | ||
}>(({ odysseyDesignTokens, isFullWidth }) => ({ | ||
maxWidth: isFullWidth | ||
? "100%" | ||
: `calc(1440px + ${odysseyDesignTokens.Spacing6} + ${odysseyDesignTokens.Spacing6})`, | ||
marginInline: isFullWidth ? odysseyDesignTokens.Spacing6 : "auto", | ||
padding: odysseyDesignTokens.Spacing6, | ||
})); | ||
|
||
const TemplateHeader = styled("div")(() => ({ | ||
display: "flex", | ||
alignItems: "flex-end", | ||
justifyContent: "space-between", | ||
})); | ||
|
||
const TemplateHeaderPrimaryContent = styled("div")(() => ({ | ||
[".MuiTypography-root:last-child"]: { | ||
marginBlockEnd: "0", | ||
}, | ||
})); | ||
|
||
const TemplateHeaderSecondaryContent = styled("div", { | ||
shouldForwardProp: (prop) => prop !== "odysseyDesignTokens", | ||
})<{ | ||
odysseyDesignTokens: DesignTokens; | ||
}>(({ odysseyDesignTokens }) => ({ | ||
alignItems: "flex-end", | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: odysseyDesignTokens.Spacing2, | ||
minHeight: odysseyDesignTokens.Spacing7, | ||
justifyContent: "center", | ||
})); | ||
|
||
const TemplateHeaderButtons = styled("div", { | ||
shouldForwardProp: (prop) => prop !== "odysseyDesignTokens", | ||
})<{ | ||
odysseyDesignTokens: DesignTokens; | ||
}>(({ odysseyDesignTokens }) => ({ | ||
display: "flex", | ||
gap: odysseyDesignTokens.Spacing2, | ||
})); | ||
|
||
const TemplateContent = styled("div", { | ||
shouldForwardProp: (prop) => | ||
!["odysseyDesignTokens", "isDrawerOpen", "drawerVariant"].includes(prop), | ||
})<TemplateContentProps>( | ||
({ odysseyDesignTokens, isDrawerOpen, drawerVariant }) => ({ | ||
"@keyframes animate-drawer-open": { | ||
"0%": { | ||
gridTemplateColumns: "minmax(0, 1fr) 0", | ||
}, | ||
"100%": { | ||
gridTemplateColumns: "minmax(0, 1fr) 360px", | ||
}, | ||
}, | ||
"@keyframes animate-drawer-close": { | ||
"0%": { | ||
gridTemplateColumns: "minmax(0, 1fr) 360px", | ||
}, | ||
"100%": { | ||
gridTemplateColumns: "minmax(0, 1fr) 0", | ||
}, | ||
}, | ||
display: "grid", | ||
gridGap: | ||
drawerVariant === "persistent" && !isDrawerOpen | ||
? 0 | ||
: odysseyDesignTokens.Spacing4, | ||
gap: | ||
drawerVariant === "persistent" && !isDrawerOpen | ||
? 0 | ||
: odysseyDesignTokens.Spacing4, | ||
marginBlock: odysseyDesignTokens.Spacing4, | ||
gridTemplateColumns: | ||
drawerVariant === "persistent" | ||
? isDrawerOpen | ||
? "minmax(0, 1fr) 360px" | ||
: "minmax(0, 1fr) 0" | ||
: "minmax(0, 1fr)", | ||
animation: | ||
drawerVariant === "persistent" && isDrawerOpen | ||
? "animate-drawer-open 225ms cubic-bezier(0, 0, 0.2, 1)" | ||
: "animate-drawer-close 225ms cubic-bezier(0, 0, 0.2, 1)", | ||
}), | ||
); | ||
|
||
const PageTemplate = ({ | ||
title, | ||
description, | ||
documentationLink, | ||
documentationText, | ||
primaryCallToActionComponent, | ||
secondaryCallToActionComponent, | ||
tertiaryCallToActionComponent, | ||
children, | ||
drawer, | ||
isFullWidth = false, | ||
}: PageTemplateProps) => { | ||
const odysseyDesignTokens = useOdysseyDesignTokens(); | ||
const { isOpen: isDrawerOpen, variant: drawerVariant } = drawer?.props ?? {}; | ||
|
||
return ( | ||
<TemplateContainer | ||
odysseyDesignTokens={odysseyDesignTokens} | ||
isFullWidth={isFullWidth} | ||
> | ||
<TemplateHeader> | ||
<TemplateHeaderPrimaryContent> | ||
{title && <Heading4>{title}</Heading4>} | ||
{description && <Subordinate>{description}</Subordinate>} | ||
</TemplateHeaderPrimaryContent> | ||
|
||
<TemplateHeaderSecondaryContent | ||
odysseyDesignTokens={odysseyDesignTokens} | ||
> | ||
{documentationLink && ( | ||
<Link href={documentationLink} icon={<DocumentationIcon />}> | ||
{documentationText} | ||
</Link> | ||
)} | ||
{(primaryCallToActionComponent || | ||
secondaryCallToActionComponent || | ||
tertiaryCallToActionComponent) && ( | ||
<TemplateHeaderButtons odysseyDesignTokens={odysseyDesignTokens}> | ||
{tertiaryCallToActionComponent} | ||
{secondaryCallToActionComponent} | ||
{primaryCallToActionComponent} | ||
</TemplateHeaderButtons> | ||
)} | ||
</TemplateHeaderSecondaryContent> | ||
</TemplateHeader> | ||
<TemplateContent | ||
odysseyDesignTokens={odysseyDesignTokens} | ||
isDrawerOpen={isDrawerOpen} | ||
drawerVariant={drawerVariant} | ||
> | ||
{children} | ||
{drawer} | ||
</TemplateContent> | ||
</TemplateContainer> | ||
); | ||
}; | ||
|
||
const MemoizedPageTemplate = memo(PageTemplate); | ||
MemoizedPageTemplate.displayName = "PageTemplate"; | ||
|
||
export { MemoizedPageTemplate as PageTemplate }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ import { | |
CssBaseline, | ||
OdysseyProvider, | ||
} from "@okta/odyssey-react-mui"; | ||
import { ScopedCssBaseline } from "@mui/material"; | ||
import { ThemeProvider as StorybookThemeProvider } from "@storybook/theming"; | ||
import type { Decorator } from "@storybook/react"; | ||
import * as odysseyTokens from "@okta/odyssey-design-tokens"; | ||
|
@@ -25,9 +24,7 @@ export const MuiThemeDecorator: Decorator = (Story, context) => { | |
<StorybookThemeProvider theme={odysseyTheme}> | ||
<CssBaseline /> | ||
<div style={styles} lang={locale}> | ||
<ScopedCssBaseline> | ||
<Story /> | ||
</ScopedCssBaseline> | ||
Comment on lines
-28
to
-30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Talked with @bryancunningham-okta , this MUI imported |
||
<Story /> | ||
</div> | ||
</StorybookThemeProvider> | ||
</OdysseyProvider> | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this to Labs.