@@ -2,7 +2,10 @@ import { css } from '@emotion/css';
22import { t } from '@grafana/i18n' ;
33import moment , { Moment } from 'moment-timezone' ;
44import React , { useMemo } from 'react' ;
5- import { ClockMode , ClockOptions , ClockType , TimeSettings } from 'types' ;
5+ import { ClockMode , ClockOptions , ClockStyle , ClockType , TimeSettings } from 'types' ;
6+ import { DigitalTime } from './digital/DigitalTime' ;
7+ import { getHeights } from './digital/utils' ;
8+ import { useTheme2 } from '@grafana/ui' ;
69
710function getStrings ( ) {
811 const oneYear = t ( 'components.RenderTime.getStrings.oneYear' , '1 year' ) ;
@@ -150,26 +153,31 @@ function getTimeFormat(clockType: ClockType, timeSettings: TimeSettings): string
150153 return 'HH:mm:ss' ;
151154}
152155
153- export function RenderTime ( {
154- now,
155- options,
156- targetTime,
157- err,
158- } : {
156+ interface RenderTimeProps {
159157 now : moment . Moment ;
160158 options : ClockOptions ;
161159 targetTime : moment . Moment ;
162160 err : string | null ;
163- } ) {
161+ width : number ;
162+ height : number ;
163+ }
164+
165+ export function RenderTime ( { now, options, targetTime, err, width, height } : RenderTimeProps ) {
164166 const { clockType, timeSettings, mode } = options ;
167+ const theme = useTheme2 ( ) ;
168+ const fill =
169+ options . style === ClockStyle . digital && options . digitalSettings ?. fillColor
170+ ? theme . visualization . getColorByName ( options . digitalSettings . fillColor )
171+ : '' ;
165172 const className = useMemo ( ( ) => {
166173 return css `
167174 font-size : ${ timeSettings . fontSize } ;
168175 font-family : ${ options . fontMono ? 'monospace' : '' } ;
169176 font-weight : ${ timeSettings . fontWeight } ;
177+ color : ${ fill } ;
170178 margin : 0 ;
171179 ` ;
172- } , [ options . fontMono , timeSettings . fontSize , timeSettings . fontWeight ] ) ;
180+ } , [ options . fontMono , timeSettings . fontSize , timeSettings . fontWeight , fill ] ) ;
173181
174182 let display = '' ;
175183 if ( err !== null ) {
@@ -196,5 +204,9 @@ export function RenderTime({
196204 break ;
197205 }
198206
207+ if ( options . style === ClockStyle . digital ) {
208+ return < DigitalTime text = { display } width = { width } height = { getHeights ( height , options ) . time } options = { options } /> ;
209+ }
210+
199211 return < h2 className = { className } > { display } </ h2 > ;
200212}
0 commit comments