import React, { PropsWithChildren } from 'react'; import { css, cx } from '@emotion/css'; import { GrafanaTheme, SelectableValue, getTimeZoneInfo } from '@grafana/data'; import { useTheme } from '../../../themes/ThemeContext'; import { stylesFactory } from '../../../themes/stylesFactory'; import { Icon } from '../../Icon/Icon'; import { TimeZoneOffset } from './TimeZoneOffset'; import { TimeZoneDescription } from './TimeZoneDescription'; import { TimeZoneTitle } from './TimeZoneTitle'; import { isString } from 'lodash'; interface Props { isFocused: boolean; isSelected: boolean; innerProps: any; data: SelectableZone; } const offsetClassName = 'tz-utc-offset'; export interface SelectableZone extends SelectableValue { searchIndex: string; } export const WideTimeZoneOption: React.FC> = (props, ref) => { const { children, innerProps, data, isSelected, isFocused } = props; const theme = useTheme(); const styles = getStyles(theme); const timestamp = Date.now(); const containerStyles = cx(styles.container, isFocused && styles.containerFocused); if (!isString(data.value)) { return null; } return (
{isSelected && ( )}
); }; export const CompactTimeZoneOption: React.FC> = (props, ref) => { const { children, innerProps, data, isSelected, isFocused } = props; const theme = useTheme(); const styles = getStyles(theme); const timestamp = Date.now(); const containerStyles = cx(styles.container, isFocused && styles.containerFocused); if (!isString(data.value)) { return null; } return (
{isSelected && ( )}
); }; const getStyles = stylesFactory((theme: GrafanaTheme) => { const offsetHoverBg = theme.isDark ? theme.palette.gray05 : theme.palette.white; return { container: css` display: flex; align-items: center; flex-direction: row; flex-shrink: 0; white-space: nowrap; cursor: pointer; border-left: 2px solid transparent; padding: 6px 8px 4px; &:hover { background: ${theme.colors.dropdownOptionHoverBg}; span.${offsetClassName} { background: ${offsetHoverBg}; } } `, containerFocused: css` background: ${theme.colors.dropdownOptionHoverBg}; border-image: linear-gradient(#f05a28 30%, #fbca0a 99%); border-image-slice: 1; border-style: solid; border-top: 0; border-right: 0; border-bottom: 0; border-left-width: 2px; span.${offsetClassName} { background: ${offsetHoverBg}; } `, body: css` display: flex; font-weight: ${theme.typography.weight.semibold}; flex-direction: column; flex-grow: 1; `, row: css` display: flex; flex-direction: row; `, leftColumn: css` flex-grow: 1; text-overflow: ellipsis; `, rightColumn: css` justify-content: flex-end; align-items: center; `, wideRow: css` display: flex; flex-direction: row; align-items: baseline; `, spacer: css` margin-left: 6px; `, }; });