diff --git a/src/components/flat-table/flat-table-header/flat-table-header-utils.js b/src/components/flat-table/flat-table-header/flat-table-header-utils.js new file mode 100644 index 0000000000..f8d6bb7c0d --- /dev/null +++ b/src/components/flat-table/flat-table-header/flat-table-header-utils.js @@ -0,0 +1,18 @@ +const getAlternativeBackgroundColor = (colorTheme) => { + switch (colorTheme) { + case "light": + return "var(--colorsActionMinor100)"; + + case "transparent-base": + return "var(--colorsUtilityMajor025)"; + + case "transparent-white": + return "var(--colorsUtilityYang100)"; + + // default theme is "dark" + default: + return "var(--colorsActionMinor550)"; + } +}; + +export default getAlternativeBackgroundColor; diff --git a/src/components/flat-table/flat-table-header/flat-table-header.component.js b/src/components/flat-table/flat-table-header/flat-table-header.component.js index 9829f85521..f849a2e504 100644 --- a/src/components/flat-table/flat-table-header/flat-table-header.component.js +++ b/src/components/flat-table/flat-table-header/flat-table-header.component.js @@ -1,9 +1,10 @@ -import React, { useLayoutEffect, useRef } from "react"; +import React, { useLayoutEffect, useRef, useContext } from "react"; import PropTypes from "prop-types"; import styledSystemPropTypes from "@styled-system/prop-types"; import StyledFlatTableHeader from "./flat-table-header.style"; import { filterStyledSystemPaddingProps } from "../../../style/utils"; +import { FlatTableThemeContext } from "../flat-table.component"; const paddingPropTypes = filterStyledSystemPaddingProps( styledSystemPropTypes.space @@ -23,6 +24,7 @@ const FlatTableHeader = ({ ...rest }) => { const ref = useRef(null); + const { colorTheme } = useContext(FlatTableThemeContext); useLayoutEffect(() => { if (ref.current && reportCellWidth) { @@ -36,6 +38,7 @@ const FlatTableHeader = ({ leftPosition={leftPosition || 0} makeCellSticky={!!reportCellWidth} align={align} + colorTheme={colorTheme} data-element="flat-table-header" colSpan={colspan} rowSpan={rowspan} diff --git a/src/components/flat-table/flat-table-header/flat-table-header.spec.js b/src/components/flat-table/flat-table-header/flat-table-header.spec.js index c6733ef015..0e16465308 100644 --- a/src/components/flat-table/flat-table-header/flat-table-header.spec.js +++ b/src/components/flat-table/flat-table-header/flat-table-header.spec.js @@ -3,6 +3,8 @@ import { mount } from "enzyme"; import FlatTableHeader from "./flat-table-header.component"; import StyledFlatTableHeader from "./flat-table-header.style"; import { assertStyleMatch } from "../../../__spec_helper__/test-utils"; +import { FlatTableThemeContext } from "../flat-table.component"; +import getAlternativeBackgroundColor from "./flat-table-header-utils"; describe("FlatTableHeader", () => { it("renders with proper width style rule when width prop is passed", () => { @@ -49,25 +51,30 @@ describe("FlatTableHeader", () => { }); describe('with the "alternativeBgColor" prop set', () => { - it('it overrides the header "background-color"', () => { - const wrapper = mount( -