-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PageTemplate and Layout component (#2219)
OKTA-721245 feat: start layout component feat: more work on layout component feat: documentation and syntax updates fix: update to storybook and component feat: add more to Storybook fix: remove unncessary MUI ScopedCssBaseline feat: add full-width story feat(odyssey-react-mui): create surface component feat(odyssey-react-mui): create stories for Grid feat(odyssey-react-mui): remove surface styling from Grid fix: small nit fixes feat(odyssey-react-mui): panes => regions fix(odyssey-react-mui): rename components and add disclaimer fix: standardize vertical layout distance refactor: update css refactor: alphabetize the imports feat: add rudimentary responsiveness to Layout refactor: improve nested selectors refactor: update based on code review Merge branch 'main' into ti-OKTA-721245-layout-component fix: update redundant type export
- Loading branch information
1 parent
5a0ed91
commit 451388d
Showing
12 changed files
with
1,445 additions
and
15 deletions.
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
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
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> | ||
<LayoutContent | ||
odysseyDesignTokens={odysseyDesignTokens} | ||
regions={mappedRegions} | ||
> | ||
{Children.toArray(children).map((child) => child)} | ||
</LayoutContent> | ||
</Box> | ||
); | ||
}; | ||
|
||
const MemoizedLayout = memo(Layout); | ||
MemoizedLayout.displayName = "Layout"; | ||
|
||
export { MemoizedLayout as Layout }; |
Oops, something went wrong.