From df42e7510955ec9954da1e73d89830c3cc3e6f91 Mon Sep 17 00:00:00 2001 From: m7kvqbe1 Date: Tue, 22 Sep 2020 12:15:04 +0100 Subject: [PATCH] fixup! feat(Timeline): Migrate to styled-components --- .../src/components/_timeline.scss | 60 +++++++------- .../components/Timeline/TimelineHeaderRow.tsx | 5 +- .../src/components/Timeline/TimelineRow.tsx | 80 ++++++++++++++----- 3 files changed, 93 insertions(+), 52 deletions(-) diff --git a/packages/css-framework/src/components/_timeline.scss b/packages/css-framework/src/components/_timeline.scss index 2a06cedc90..e220fb642c 100644 --- a/packages/css-framework/src/components/_timeline.scss +++ b/packages/css-framework/src/components/_timeline.scss @@ -176,43 +176,43 @@ $timeline-row-header-width: 16rem; font-size: f.font-size("xs"); } -.timeline__row { - display: flex; - height: 4rem; -} +// .timeline__row { +// display: flex; +// height: 4rem; +// } // .timeline__row--short { // height: 2.5rem; // } -.timeline__row-header { - min-width: $timeline-row-header-width; - position: absolute; - left: 0; - height: inherit; - background-color: f.color("neutral", "white"); - border-right: f.spacing("px") solid $timeline-border-color; - box-shadow: inset 0px 0px 0px 0px $timeline-border-color, - 5px 0px 5px 0px rgba(0, 0, 0, 0.04); - @include m.z-index("body", 3); - justify-content: flex-end; - display: inline-flex; - align-items: center; - font-size: f.font-size("m"); - font-weight: 600; - color: f.color("neutral", "600"); - padding-right: f.spacing("8"); -} +// .timeline__row-header { +// min-width: $timeline-row-header-width; +// position: absolute; +// left: 0; +// height: inherit; +// background-color: f.color("neutral", "white"); +// border-right: f.spacing("px") solid $timeline-border-color; +// box-shadow: inset 0px 0px 0px 0px $timeline-border-color, +// 5px 0px 5px 0px rgba(0, 0, 0, 0.04); +// @include m.z-index("body", 3); +// justify-content: flex-end; +// display: inline-flex; +// align-items: center; +// font-size: f.font-size("m"); +// font-weight: 600; +// color: f.color("neutral", "600"); +// padding-right: f.spacing("8"); +// } -.timeline__row-header--header { - font-size: f.font-size("s"); - font-weight: normal; - color: f.color("neutral", "400"); -} +// .timeline__row-header--header { +// font-size: f.font-size("s"); +// font-weight: normal; +// color: f.color("neutral", "400"); +// } -.timeline__row-content { - position: relative; -} +// .timeline__row-content { +// position: relative; +// } .timeline__row-weeks-wrapper { position: relative; diff --git a/packages/react-component-library/src/components/Timeline/TimelineHeaderRow.tsx b/packages/react-component-library/src/components/Timeline/TimelineHeaderRow.tsx index f91b827c5f..7cab67f07a 100644 --- a/packages/react-component-library/src/components/Timeline/TimelineHeaderRow.tsx +++ b/packages/react-component-library/src/components/Timeline/TimelineHeaderRow.tsx @@ -1,4 +1,5 @@ import React from 'react' +import styled from 'styled-components' import { ComponentWithClass } from '../../common/ComponentWithClass' import { TimelineRow } from './TimelineRow' @@ -9,8 +10,10 @@ interface TimelineHeaderRowProps extends ComponentWithClass { renderRowHeader?: (name: string) => React.ReactElement } +const StyledTimelineHeaderRow = styled(TimelineRow)`` + export const TimelineHeaderRow: React.FC = (props) => ( - + ) TimelineHeaderRow.displayName = 'TimelineHeaderRow' diff --git a/packages/react-component-library/src/components/Timeline/TimelineRow.tsx b/packages/react-component-library/src/components/Timeline/TimelineRow.tsx index e3c2000888..04d769b949 100755 --- a/packages/react-component-library/src/components/Timeline/TimelineRow.tsx +++ b/packages/react-component-library/src/components/Timeline/TimelineRow.tsx @@ -1,8 +1,19 @@ import React from 'react' -import classNames from 'classnames' +import styled from 'styled-components' +import { + SpacingPx, + ZindexBody, + TypographyS, + TypographyM, + ColorNeutral400, + ColorNeutral600, + ColorNeutralWhite, + Spacing8, +} from '@royalnavy/design-tokens' import { ComponentWithClass } from '../../common/ComponentWithClass' import { TimelineContext, TimelineEventsProps } from '.' +import { TIMELINE_BORDER_COLOR, TIMELINE_ROW_HEADER_WIDTH } from './constants' export interface TimelineRowProps extends ComponentWithClass { children: @@ -10,43 +21,70 @@ export interface TimelineRowProps extends ComponentWithClass { | React.ReactElement[] name?: string renderRowHeader?: (name: string) => React.ReactElement - rowHeaderClassName?: string + isHeader: boolean } +const StyledTimelineRow = styled.div` + display: flex; + height: 4rem; +` + +interface RowHeaderProps { + isHeader: boolean +} + +const RowHeader = styled.div` + min-width: ${TIMELINE_ROW_HEADER_WIDTH}; + position: absolute; + left: 0; + height: inherit; + background-color: ${ColorNeutralWhite}; + border-right: ${SpacingPx} solid ${TIMELINE_BORDER_COLOR}; + box-shadow: inset 0px 0px 0px 0px ${TIMELINE_BORDER_COLOR}, + 5px 0px 5px 0px rgba(0, 0, 0, 0.04); + z-index: ${Number(ZindexBody + 3)}; + justify-content: flex-end; + display: inline-flex; + align-items: center; + font-size: ${TypographyM}; + font-weight: 600; + color: ${ColorNeutral600}; + padding-right: ${Spacing8}; + ${({ isHeader }) => + isHeader && + ` + font-size: ${TypographyS}; + font-weight: normal; + color: ${ColorNeutral400}; + `} +` + +const RowContent = styled.div` + position: relative; +` + export const TimelineRow: React.FC = ({ children, - className, name, renderRowHeader, - rowHeaderClassName, + isHeader, ...rest }) => { - const classes = classNames('timeline__row', className) - const rowHeaderClasses = classNames( - 'timeline__row-header', - rowHeaderClassName - ) - return ( {({ hasSide }) => ( -
+ {hasSide && ( -
{renderRowHeader ? renderRowHeader(name) : name} -
+ )} -
{children}
-
+ {children} + )}
)