From ea752b25411343475fcff00b3427ee7d764b5769 Mon Sep 17 00:00:00 2001 From: jpveooys <66470099+jpveooys@users.noreply.github.com> Date: Fri, 9 Oct 2020 14:37:24 +0100 Subject: [PATCH] fix(Timeline): Forward className prop The `Timeline` had a `className` prop that wasn't used. This forwards it to the root child component so library users can override styles more easily. The prop was also added to the docs. --- .../src/library/pages/timeline/index.md | 19 +++++++++++++++++++ .../src/components/Timeline/Timeline.tsx | 8 +++++++- .../Timeline/__tests__/Timeline.test.tsx | 19 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/packages/docs-site/src/library/pages/timeline/index.md b/packages/docs-site/src/library/pages/timeline/index.md index 561b727faa..ec35ea9b75 100644 --- a/packages/docs-site/src/library/pages/timeline/index.md +++ b/packages/docs-site/src/library/pages/timeline/index.md @@ -668,6 +668,25 @@ Here you will find comprehensive API documentation for the Timeline Components. +
+
+

className

+ String +
+
+
+
Default Value
+
+ - +
+
+
+
Description
+

Custom CSS class to add to the component.

+
+
+
+
diff --git a/packages/react-component-library/src/components/Timeline/Timeline.tsx b/packages/react-component-library/src/components/Timeline/Timeline.tsx index 3616169cc1..3c2f083e76 100755 --- a/packages/react-component-library/src/components/Timeline/Timeline.tsx +++ b/packages/react-component-library/src/components/Timeline/Timeline.tsx @@ -1,4 +1,5 @@ import React from 'react' +import classNames from 'classnames' import styled from 'styled-components' import { selectors } from '@royalnavy/design-tokens' @@ -132,6 +133,7 @@ const StyledHeader = styled.div`` export const Timeline: React.FC = ({ children, + className, dayWidth, hasSide, startDate, @@ -182,7 +184,11 @@ export const Timeline: React.FC = ({ startDate={startDate} today={today} > - + { jest.clearAllMocks() }) + describe('when a custom className is provided', () => { + beforeEach(() => { + wrapper = render( + + + {} + + ) + }) + + it('adds the custom CSS class to the component', () => { + expect(wrapper.getByTestId('timeline')).toHaveClass('test-class-name') + }) + }) + describe('when no data is provided', () => { beforeEach(() => { wrapper = render(