From 660387a338320f5401be1f49e27da8cb1292a444 Mon Sep 17 00:00:00 2001 From: Victor Genaev Date: Wed, 20 Dec 2023 14:45:13 +0100 Subject: [PATCH] fix(TimelineStep): move subLabel below timeline --- .../src/Timeline/TimelineContext.tsx | 9 ++++++-- .../components/TimelineStepDesktop.tsx | 23 ++++++++++++++----- .../src/Timeline/TimelineStep/index.tsx | 3 ++- .../orbit-components/src/Timeline/index.tsx | 11 ++++++++- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/packages/orbit-components/src/Timeline/TimelineContext.tsx b/packages/orbit-components/src/Timeline/TimelineContext.tsx index 7ddca79add..0e9475e792 100644 --- a/packages/orbit-components/src/Timeline/TimelineContext.tsx +++ b/packages/orbit-components/src/Timeline/TimelineContext.tsx @@ -13,6 +13,7 @@ interface Context { interface StepContext { index: number; last: boolean; + hasSubLabelMargin?: boolean; } export const TimelineStatusContext = React.createContext({ @@ -24,6 +25,7 @@ export const TimelineStatusContext = React.createContext({ export const TimelineStepContext = React.createContext({ index: 0, last: false, + hasSubLabelMargin: false, }); export const TimelineStatusProvider = ({ children, direction }) => { @@ -37,8 +39,11 @@ export const TimelineStatusProvider = ({ children, direction }) => { return {children}; }; -export const TimelineStepProvider = ({ children, index, last }) => { - const value = React.useMemo(() => ({ index, last }), [index, last]); +export const TimelineStepProvider = ({ children, index, last, hasSubLabelMargin }) => { + const value = React.useMemo( + () => ({ index, last, hasSubLabelMargin }), + [index, last, hasSubLabelMargin], + ); return {children}; }; diff --git a/packages/orbit-components/src/Timeline/TimelineStep/components/TimelineStepDesktop.tsx b/packages/orbit-components/src/Timeline/TimelineStep/components/TimelineStepDesktop.tsx index 0a8a9161f9..cc422b8615 100644 --- a/packages/orbit-components/src/Timeline/TimelineStep/components/TimelineStepDesktop.tsx +++ b/packages/orbit-components/src/Timeline/TimelineStep/components/TimelineStepDesktop.tsx @@ -9,6 +9,7 @@ import Text from "../../../Text"; import Stack from "../../../Stack"; import defaultTheme from "../../../defaultTheme"; import type { Props as StepProps, Type } from "../types"; +import useTheme from "../../../hooks/useTheme"; const StyledDescription = styled.div<{ active?: boolean }>` ${({ theme, active }) => css` @@ -28,6 +29,7 @@ interface Props extends StepProps { last: boolean; prevType: Type; nextType: Type; + hasSubLabelMargin?: boolean; } const TimelineStepDesktop = ({ @@ -39,14 +41,12 @@ const TimelineStepDesktop = ({ active, label, subLabel, + hasSubLabelMargin, }: Props) => { + const theme = useTheme(); + return ( - - - {subLabel} - - @@ -59,8 +59,19 @@ const TimelineStepDesktop = ({ /> + {subLabel && ( + + + {subLabel} + + + )} - + {label} diff --git a/packages/orbit-components/src/Timeline/TimelineStep/index.tsx b/packages/orbit-components/src/Timeline/TimelineStep/index.tsx index d881d21f63..928ba34e06 100644 --- a/packages/orbit-components/src/Timeline/TimelineStep/index.tsx +++ b/packages/orbit-components/src/Timeline/TimelineStep/index.tsx @@ -27,7 +27,7 @@ const getActiveState = ({ const TimelineStep = ({ children, label, subLabel, type, active }: Props) => { const { types, setTypes, isColumnOnDesktop } = useStatuses(); - const { index, last } = useStep(); + const { index, last, hasSubLabelMargin } = useStep(); const { isDesktop } = useMediaQuery(); const nextType = types[index + 1]; @@ -57,6 +57,7 @@ const TimelineStep = ({ children, label, subLabel, type, active }: Props) => { { return isDesktop ? "row" : "column"; }; + const hasSubLabelMargin = React.useMemo( + () => childrenArr.some(child => React.isValidElement(child) && child.props.subLabel), + [childrenArr], + ); + return childrenArr && childrenArr.length > 0 ? ( @@ -37,7 +42,11 @@ const Timeline = ({ children, spaceAfter, direction, dataTest, id }: Props) => { {React.Children.map(childrenArr, (child, i) => { if (React.isValidElement(child)) { return ( - + {child} );