Skip to content

Commit 4d69b87

Browse files
authored
Merge pull request #2346 from dxc-technology/PelayoFelgueroso/missing-attributes
Expose Container ref and Flex fullHeight
2 parents 0a4df06 + 8665786 commit 4d69b87

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

apps/website/screens/components/container/code/ContainerCodePage.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,14 @@ const sections = [
361361
<TableCode>'static'</TableCode>
362362
</td>
363363
</tr>
364+
<tr>
365+
<td>ref</td>
366+
<td>
367+
<TableCode>{"React.Ref<HTMLDivElement>"}</TableCode>
368+
</td>
369+
<td>Reference to the component.</td>
370+
<td>-</td>
371+
</tr>
364372
<tr>
365373
<td>width</td>
366374
<td>

apps/website/screens/components/flex/code/FlexCodePage.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ const sections = [
135135
<TableCode>'row'</TableCode>
136136
</td>
137137
</tr>
138+
<tr>
139+
<td>fullHeight</td>
140+
<td>
141+
<TableCode>boolean</TableCode>
142+
</td>
143+
<td>If true, the component will take the full height of its parent container.</td>
144+
<td>
145+
<TableCode>false</TableCode>
146+
</td>
147+
</tr>
138148
<tr>
139149
<td>gap</td>
140150
<td>

packages/lib/src/container/Container.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import styled from "@emotion/styled";
22
import ContainerPropsType, { BorderProperties, StyledProps } from "./types";
3+
import { forwardRef } from "react";
34

45
const getBorderStyles = (direction: "top" | "bottom" | "left" | "right", borderProperties: BorderProperties) =>
56
`border-${direction}: ${borderProperties.width ?? ""} ${borderProperties.style ?? ""} ${
@@ -82,6 +83,10 @@ const Container = styled.div<StyledProps>`
8283
padding-left: ${({ padding }) => (typeof padding === "object" && padding.left ? padding.left : "")};
8384
`;
8485

85-
export default function DxcContainer({ display, width, height, overflow, ...props }: ContainerPropsType) {
86-
return <Container $display={display} $width={width} $height={height} $overflow={overflow} {...props} />;
87-
}
86+
const DxcContainer = forwardRef<HTMLDivElement, ContainerPropsType>(
87+
({ display, width, height, overflow, ...props }, ref) => {
88+
return <Container ref={ref} $display={display} $width={width} $height={height} $overflow={overflow} {...props} />;
89+
}
90+
);
91+
92+
export default DxcContainer;

packages/lib/src/flex/Flex.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ const Flex = () => (
113113
</DxcFlex>
114114
</DxcFlex>
115115
</Container>
116+
<Title title="Full Height" level={4} />
117+
<div style={{ height: "300px", backgroundColor: "#f2eafa", margin: "2.5rem" }}>
118+
<DxcFlex fullHeight justifyContent="center" alignItems="center">
119+
<Placeholder />
120+
</DxcFlex>
121+
</div>
116122
</>
117123
);
118124

packages/lib/src/flex/Flex.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const Flex = styled.div<StyledProps>`
99
${typeof props.alignSelf === "string" ? `align-self: ${props.alignSelf};` : ""}
1010
${typeof props.$basis === "string" ? `flex-basis: ${props.$basis};` : ""}
1111
${typeof props.$direction === "string" ? `flex-direction: ${props.$direction};` : ""}
12+
${props.$fullHeight ? "height: 100%;" : ""}
1213
${typeof props.$gap === "string" ? `gap: ${props.$gap};` : ""}
1314
${typeof props.$gap === "object" ? `column-gap: ${props.$gap.columnGap}; row-gap: ${props.$gap.rowGap};` : ""}
1415
${typeof props.$grow === "number" ? `flex-grow: ${props.$grow};` : ""}
@@ -19,7 +20,7 @@ const Flex = styled.div<StyledProps>`
1920
`}
2021
`;
2122

22-
const DxcFlex = ({ basis, direction, gap, grow, order, shrink, wrap, ...props }: FlexPropsType) => (
23+
const DxcFlex = ({ basis, direction, fullHeight = false, gap, grow, order, shrink, wrap, ...props }: FlexPropsType) => (
2324
<Flex
2425
$basis={basis}
2526
$direction={direction}
@@ -28,6 +29,7 @@ const DxcFlex = ({ basis, direction, gap, grow, order, shrink, wrap, ...props }:
2829
$order={order}
2930
$shrink={shrink}
3031
$wrap={wrap}
32+
$fullHeight={fullHeight}
3133
{...props}
3234
/>
3335
);

packages/lib/src/flex/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ type Props = CommonProps & {
8585
* See MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/order
8686
*/
8787
order?: number;
88+
/**
89+
* If true, the flex container will take the full height of its parent.
90+
*/
91+
fullHeight?: boolean;
8892
/**
8993
* Sets the flex-grow CSS property.
9094
*
@@ -117,6 +121,7 @@ export type StyledProps = CommonProps & {
117121
$direction?: "row" | "row-reverse" | "column" | "column-reverse";
118122
$wrap?: "nowrap" | "wrap" | "wrap-reverse";
119123
$gap?: Gap;
124+
$fullHeight?: boolean;
120125
$order?: number;
121126
$grow?: number;
122127
$shrink?: number;

0 commit comments

Comments
 (0)