11import React , { Fragment , createContext , useLayoutEffect , useMemo , useRef , useState } from "react" ;
2- import styled from "styled-components" ;
2+ import styled , { ThemeProvider } from "styled-components" ;
33import CoreTokens from "../common/coreTokens" ;
44import ContextualMenuPropsType , {
55 ContextualMenuContextProps ,
@@ -13,6 +13,7 @@ import ContextualMenuPropsType, {
1313import DxcDivider from "../divider/Divider" ;
1414import DxcInset from "../inset/Inset" ;
1515import MenuItem from "./MenuItem" ;
16+ import useTheme from "../useTheme" ;
1617
1718export const ContextualMenuContext = createContext < ContextualMenuContextProps | null > ( null ) ;
1819
@@ -26,8 +27,8 @@ const addIdToItems = (items: ContextualMenuPropsType["items"]): (ItemWithId | Gr
2627 isSection ( item )
2728 ? { ...item , items : innerAddIdToItems ( item . items ) }
2829 : isGroupItem ( item )
29- ? { ...item , items : innerAddIdToItems ( item . items ) }
30- : { ...item , id : accId ++ }
30+ ? { ...item , items : innerAddIdToItems ( item . items ) }
31+ : { ...item , id : accId ++ } ,
3132 ) ;
3233 } ;
3334 return innerAddIdToItems ( items ) ;
@@ -37,6 +38,7 @@ const DxcContextualMenu = ({ items }: ContextualMenuPropsType) => {
3738 const [ selectedItemId , setSelectedItemId ] = useState ( - 1 ) ;
3839 const contextualMenuRef = useRef ( null ) ;
3940 const itemsWithId = useMemo ( ( ) => addIdToItems ( items ) , [ items ] ) ;
41+ const colorsTheme = useTheme ( ) ;
4042
4143 const renderSection = ( section : SectionWithId , currentSectionIndex : number , length : number ) => (
4244 < Fragment key = { `section-${ currentSectionIndex } ` } >
@@ -67,31 +69,33 @@ const DxcContextualMenu = ({ items }: ContextualMenuPropsType) => {
6769 } , [ firstUpdate , selectedItemId ] ) ;
6870
6971 return (
70- < ContextualMenu role = "menu" ref = { contextualMenuRef } >
71- < ContextualMenuContext . Provider value = { { selectedItemId, setSelectedItemId } } >
72- { itemsWithId . map ( ( item : GroupItemWithId | ItemWithId | SectionWithId , index : number ) =>
73- "items" in item && ! ( "label" in item ) ? (
74- renderSection ( item , index , itemsWithId . length )
75- ) : (
76- < MenuItem item = { item } key = { `${ item . label } -${ index } ` } />
77- )
78- ) }
79- </ ContextualMenuContext . Provider >
80- </ ContextualMenu >
72+ < ThemeProvider theme = { colorsTheme . contextualMenu } >
73+ < ContextualMenu role = "menu" ref = { contextualMenuRef } >
74+ < ContextualMenuContext . Provider value = { { selectedItemId, setSelectedItemId } } >
75+ { itemsWithId . map ( ( item : GroupItemWithId | ItemWithId | SectionWithId , index : number ) =>
76+ "items" in item && ! ( "label" in item ) ? (
77+ renderSection ( item , index , itemsWithId . length )
78+ ) : (
79+ < MenuItem item = { item } key = { `${ item . label } -${ index } ` } />
80+ ) ,
81+ ) }
82+ </ ContextualMenuContext . Provider >
83+ </ ContextualMenu >
84+ </ ThemeProvider >
8185 ) ;
8286} ;
8387
8488const ContextualMenu = styled . ul `
8589 box-sizing: border-box;
8690 margin: 0;
87- border: 1px solid ${ CoreTokens . color_grey_200 } ;
91+ border: 1px solid ${ ( { theme } ) => theme . borderColor } ;
8892 border-radius: 0.25rem;
8993 padding: ${ CoreTokens . spacing_16 } ${ CoreTokens . spacing_8 } ;
9094 display: grid;
9195 gap: ${ CoreTokens . spacing_4 } ;
9296 min-width: 248px;
9397 max-height: 100%;
94- background-color: ${ CoreTokens . color_white } ;
98+ background-color: ${ ( { theme } ) => theme . backgroundColor } ;
9599 overflow-y: auto;
96100 &::-webkit-scrollbar {
97101 width: 8px;
@@ -118,11 +122,12 @@ const SectionList = styled.ul`
118122const Title = styled . h2 `
119123 margin: 0 0 ${ CoreTokens . spacing_4 } 0;
120124 padding: ${ CoreTokens . spacing_4 } ;
121- color: ${ CoreTokens . color_grey_900 } ;
122- font-family: ${ CoreTokens . type_sans } ;
123- font-size: ${ CoreTokens . type_scale_03 } ;
124- font-weight: ${ CoreTokens . type_semibold } ;
125- line-height: 24px;
125+ color: ${ ( { theme } ) => theme . sectionTitleFontColor } ;
126+ font-family: ${ ( { theme } ) => theme . fontFamily } ;
127+ font-size: ${ ( { theme } ) => theme . sectionTitleFontSize } ;
128+ font-style: ${ ( { theme } ) => theme . sectionTitleFontStyle } ;
129+ font-weight: ${ ( { theme } ) => theme . sectionTitleFontWeight } ;
130+ line-height: ${ ( { theme } ) => theme . sectionTitleLineHeight } ;
126131` ;
127132
128133export default DxcContextualMenu ;
0 commit comments