Skip to content

Commit

Permalink
Merge pull request #1749 from dxc-technology/gomezivann/container-docs
Browse files Browse the repository at this point in the history
New Container component documentation
  • Loading branch information
Jialecl committed Jan 22, 2024
2 parents 11fed82 + 372999b commit 75f9c22
Show file tree
Hide file tree
Showing 22 changed files with 1,214 additions and 321 deletions.
18 changes: 9 additions & 9 deletions lib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@testing-library/user-event": "^13.0.0",
"@types/color": "^3.0.3",
"@types/react": "^18.0.18",
"@types/styled-components": "^5.1.29",
"@types/styled-components": "5.1.29",
"@types/uuid": "^9.0.6",
"babel-jest": "^24.8.0",
"babel-loader": "^8.0.6",
Expand All @@ -74,7 +74,7 @@
"storybook": "^7.5.3",
"storybook-addon-pseudo-states": "^2.1.2",
"styled-components": "^5.0.1",
"typescript": "^4.5.4"
"typescript": "^5.3.3"
},
"jest": {
"moduleNameMapper": {
Expand Down
27 changes: 21 additions & 6 deletions lib/src/container/Container.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ export const Chromatic = () => (
height="200px"
background={{ color: "color_purple_400" }}
border={{
top: {
width: "2px",
color: "color_blue_600",
style: "solid",
},
bottom: {
width: "thick",
color: "color_purple_600",
style: "solid",
leftRadius: "0.25rem",
rightRadius: "0.25rem",
},
}}
borderRadius="0 0 0.25rem 0.25rem"
padding="medium"
margin="large"
>
Expand All @@ -52,7 +56,8 @@ export const Chromatic = () => (
<DxcContainer
position="relative"
width="fit-content"
border={{ color: "color_purple_400", width: "2px", style: "dashed", radius: "4px" }}
border={{ color: "color_purple_400", width: "2px", style: "dashed" }}
borderRadius="0.25rem"
margin={{ bottom: "xxlarge" }}
>
<DxcContainer display="inline-block" background={{ color: "color_purple_400" }} width="50px" height="50px">
Expand All @@ -78,7 +83,8 @@ export const Chromatic = () => (
<ExampleContainer>
<DxcContainer
width="fit-content"
border={{ color: "color_purple_400", width: "2px", style: "dashed", radius: "4px" }}
border={{ color: "color_purple_400", width: "2px", style: "dashed" }}
borderRadius="0.25rem"
>
<DxcContainer
background={{ color: "color_purple_400" }}
Expand Down Expand Up @@ -146,7 +152,6 @@ export const Chromatic = () => (
padding="medium"
outline={{ width: "1px", style: "solid", color: "color_black" }}
boxShadow="10px 5px 5px #fe0123"
opacity="0.75"
>
<p style={{ margin: 0 }}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla facilisis, sapien vitae aliquam lacinia, nisl
Expand Down Expand Up @@ -178,6 +183,15 @@ export const Chromatic = () => (
<ExampleContainer>
<Listbox suggestions={["Option 1", "Option 2", "Option 3", "Option 4", "Option 5"]} />
</ExampleContainer>
<Title title="Border and outline" level={4} />
<ExampleContainer>
<DxcContainer
outline={{ color: "color_blue_400", style: "solid", offset: "2px" }}
border={{ top: { style: "solid" } }}
>
Example text
</DxcContainer>
</ExampleContainer>
</ExampleContainer>
</>
);
Expand All @@ -186,7 +200,8 @@ const Listbox = ({ suggestions = [] }: { suggestions: string[] }): JSX.Element =
<DxcContainer
boxSizing="border-box"
boxShadow="0 4px 6px -1px rgba(0, 0, 0, 0.1)"
border={{ width: "1px", style: "solid", color: "color_grey_400", radius: "0.25rem" }}
border={{ width: "1px", style: "solid", color: "color_grey_400" }}
borderRadius="0.25rem"
background={{ color: "color_white" }}
padding={{ top: "xxsmall", bottom: "xxsmall" }}
maxHeight="304px"
Expand Down
85 changes: 47 additions & 38 deletions lib/src/container/Container.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import styled from "styled-components";
import ContainerPropsType, { StyledProps } from "./types";
import ContainerPropsType, { StyledProps, BorderProperties } from "./types";
import { getCoreColorToken } from "../common/coreTokens";
import { BackgroundColorProvider } from "../BackgroundColorContext";

Expand All @@ -24,6 +24,11 @@ const DxcContainer = ({ display, width, height, overflow, ...props }: ContainerP
</BackgroundColorProvider>
);

const getBorderStyles = (direction: "top" | "bottom" | "left" | "right", borderProperties: BorderProperties) =>
`border-${direction}: ${borderProperties?.width ?? ""} ${borderProperties?.style ?? ""} ${
getCoreColorToken(borderProperties?.color) ?? ""
};`;

const Container = styled.div<StyledProps>`
box-sizing: ${({ boxSizing }) => boxSizing};
display: ${({ $display }) => $display};
Expand All @@ -41,53 +46,57 @@ const Container = styled.div<StyledProps>`
float: ${({ float }) => float};
z-index: ${({ zIndex }) => zIndex};
box-shadow: ${({ boxShadow }) => boxShadow};
outline: ${({ outline }) => `${outline?.width} ${outline?.style} ${getCoreColorToken(outline?.color)}`};
outline-offset: ${({ outline }) => outline?.offset};
margin: ${({ margin }) => (typeof margin === "string" ? `${spaces[margin]}` : "")};
background-attachment: ${({ background }) => background?.attachment};
background-clip: ${({ background }) => background?.clip};
background-color: ${({ background }) => getCoreColorToken(background?.color)};
background-image: ${({ background }) => background?.image};
background-origin: ${({ background }) => background?.origin};
background-position: ${({ background }) => background?.position};
background-repeat: ${({ background }) => background?.repeat};
background-size: ${({ background }) => background?.size};
border-radius: ${({ borderRadius }) => borderRadius};
border-width: ${({ border }) => (border && "width" in border ? `${border?.width}` : "")};
border-style: ${({ border }) => (border && "style" in border ? `${border?.style}` : "")};
border-width: ${({ border }) => (border && "color" in border ? `${getCoreColorToken(border?.color)}` : "")};
${({ border }) => {
if (border != null) {
let styles = "";
switch (true) {
case "top" in border:
styles += getBorderStyles("top", border.top);
case "right" in border:
styles += getBorderStyles("right", border.right);
case "left" in border:
styles += getBorderStyles("left", border.left);
case "bottom" in border:
styles += getBorderStyles("bottom", border.bottom);
}
return styles;
}
}};
margin: ${({ margin }) => (typeof margin === "string" ? spaces[margin] : "")};
margin-top: ${({ margin }) => (typeof margin === "object" ? spaces[margin.top] : "")};
margin-right: ${({ margin }) => (typeof margin === "object" ? spaces[margin.right] : "")};
margin-bottom: ${({ margin }) => (typeof margin === "object" ? spaces[margin.bottom] : "")};
margin-left: ${({ margin }) => (typeof margin === "object" ? spaces[margin.left] : "")};
padding: ${({ padding }) => (typeof padding === "string" ? `${spaces[padding]}` : "")};
padding-top: ${({ padding }) => (typeof padding === "object" ? spaces[padding.top] : "")};
padding-right: ${({ padding }) => (typeof padding === "object" ? spaces[padding.right] : "")};
padding-bottom: ${({ padding }) => (typeof padding === "object" ? spaces[padding.bottom] : "")};
padding-left: ${({ padding }) => (typeof padding === "object" ? spaces[padding.left] : "")};
border: ${({ border }) =>
border && "width" in border ? `${border?.width} ${border?.style} ${getCoreColorToken(border?.color)}` : ""};
border-top: ${({ border }) =>
border && "top" in border
? `${border?.top?.width} ${border?.top?.style} ${getCoreColorToken(border?.top?.color)}`
: ""};
border-right: ${({ border }) =>
border && "right" in border
? `${border?.right?.width} ${border?.right?.style} ${getCoreColorToken(border?.right?.color)}`
: ""};
border-bottom: ${({ border }) =>
border && "bottom" in border
? `${border?.bottom?.width} ${border?.bottom?.style} ${getCoreColorToken(border?.bottom?.color)}`
: ""};
border-left: ${({ border }) =>
border && "left" in border
? `${border?.left?.width} ${border?.left?.style} ${getCoreColorToken(border?.left?.color)}`
: ""};
border-radius: ${({ borderRadius }) => borderRadius};
outline: ${({ outline }) =>
`${outline?.width ?? ""} ${outline?.style ?? ""} ${getCoreColorToken(outline?.color) ?? ""}`};
outline-offset: ${({ outline }) => outline?.offset};
overflow: ${({ $overflow }) => (typeof $overflow !== "object" ? $overflow : "")};
overflow: ${({ $overflow }) => (typeof $overflow === "string" ? $overflow : "")};
overflow-x: ${({ $overflow }) => (typeof $overflow === "object" ? `${$overflow?.x}` : "")};
overflow-y: ${({ $overflow }) => (typeof $overflow === "object" ? `${$overflow?.y}` : "")};
background-attachment: ${({ background }) => background?.attachment};
background-clip: ${({ background }) => background?.clip};
background-color: ${({ background }) => getCoreColorToken(background?.color)};
background-image: ${({ background }) => background?.image};
background-origin: ${({ background }) => background?.origin};
background-position: ${({ background }) => background?.position};
background-repeat: ${({ background }) => background?.repeat};
background-size: ${({ background }) => background?.size};
padding: ${({ padding }) => (typeof padding === "string" ? spaces[padding] : "")};
padding-top: ${({ padding }) => (typeof padding === "object" ? spaces[padding.top] : "")};
padding-right: ${({ padding }) => (typeof padding === "object" ? spaces[padding.right] : "")};
padding-bottom: ${({ padding }) => (typeof padding === "object" ? spaces[padding.bottom] : "")};
padding-left: ${({ padding }) => (typeof padding === "object" ? spaces[padding.left] : "")};
`;

export default DxcContainer;
2 changes: 1 addition & 1 deletion lib/src/container/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Background = {
size?: string;
};

type BorderProperties = {
export type BorderProperties = {
width?: string;
style?: "none" | "dotted" | "dashed" | "solid" | "double" | "groove" | "ridge" | "inset" | "outset";
color?: CoreColorTokens;
Expand Down

0 comments on commit 75f9c22

Please sign in to comment.