Skip to content

Commit

Permalink
feat: updated the theming support for kpi and tc #2668
Browse files Browse the repository at this point in the history
  • Loading branch information
chandrashekhara.n authored and ssjagad committed Mar 29, 2024
1 parent 30611da commit d32a018
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 14 deletions.
2 changes: 2 additions & 0 deletions packages/dashboard/src/components/contextMenu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
borderRadiusDropdown,
colorBackgroundDropdownItemDefault,
colorBorderControlDefault,
colorTextBodyDefault,
spaceScaledXxxs,
} from '@cloudscape-design/design-tokens';

Expand Down Expand Up @@ -67,6 +68,7 @@ const Menu: React.FC<MenuProps> = ({ position, clickOutside, children }) => {
minWidth: '192px', // 128+64, just picking a width which is a multiple of 8
borderRadius: borderRadiusDropdown,
background: colorBackgroundDropdownItemDefault,
color: colorTextBodyDefault,
}}
{...attributes.popper}
onPointerDown={(e) => e.stopPropagation()} // prevent the grid from handling click events
Expand Down
2 changes: 1 addition & 1 deletion packages/dashboard/src/customization/widgets/kpi/KPI.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 27 additions & 1 deletion packages/react-components/src/components/chart/baseChart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React from 'react';
import type { MouseEvent } from 'react';
import { spaceStaticL, spaceStaticM } from '@cloudscape-design/design-tokens';
import {
colorBorderDividerSecondary,
spaceStaticL,
spaceStaticM,
} from '@cloudscape-design/design-tokens';

import { useECharts, useResizeableEChart } from '../../hooks/useECharts';
import { ChartOptions } from './types';
Expand Down Expand Up @@ -195,6 +199,27 @@ const BaseChart = ({
}
};

const legendResizerStyle = () => {
const borderThin = `1px solid ${colorBorderDividerSecondary}`;
const borderThick = `2px solid ${colorBorderDividerSecondary}`;
if (isLegendPositionBottom) {
return {
borderTop: borderThick,
borderBottom: borderThin,
};
}
if (isLegendPositionLeft) {
return {
borderLeft: borderThin,
borderRight: borderThick,
};
}
return {
borderLeft: borderThick,
borderRight: borderThin,
};
};

return (
<div
className={`base-chart-container ${options.legend?.position}-position`}
Expand All @@ -214,6 +239,7 @@ const BaseChart = ({
? 'react-resizable-handle react-resizable-handle-se'
: ''
}
style={options.legend?.visible ? legendResizerStyle() : {}}
data-gesture='resize'
/>
}
Expand Down
6 changes: 0 additions & 6 deletions packages/react-components/src/components/chart/chart.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
cursor: ew-resize;
background-image: url("./assets/horizontalSliderIcon.svg");
background-position: center;
border-left: 2px solid #e9ebed;
border-right: 1px solid #e9ebed;
}

.bottom-position .react-resizable-handle-se {
Expand All @@ -31,8 +29,6 @@
cursor: ns-resize;
background-image: url("./assets/verticalSliderIcon.svg");
border: unset;
border-top: 2px solid #e9ebed;
border-bottom: 1px solid #e9ebed;
}

.base-chart-element {
Expand Down Expand Up @@ -62,8 +58,6 @@
right: unset;
left: 0;
border: unset;
border-right: 2px solid #e9ebed;
border-left: 1px solid #e9ebed;
}

.base-chart-left-legend {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import {
colorBackgroundLayoutToggleActive,
colorTextHomeHeaderDefault,
colorBorderDividerSecondary,
colorTextBodyDefault,
spaceStaticS,
spaceStaticXl,
spaceStaticXs,
Expand Down Expand Up @@ -31,7 +32,7 @@ export const Timestamp = ({
}: TimestampProps) => {
const timestampStyle = {
...styleProps,
borderTop: `${spaceStaticXxxs} solid ${colorTextHomeHeaderDefault}`,
borderTop: `${spaceStaticXxxs} solid ${colorBorderDividerSecondary}`,
padding: `0 ${spaceStaticS} ${spaceStaticXxxs} ${spaceStaticXs}`,
fontSize: `10px`,
color: `${colorBackgroundLayoutToggleActive}`,
Expand All @@ -46,6 +47,7 @@ export const Timestamp = ({
className='base-chart-timestamp'
style={{
paddingTop: spaceStaticXxs,
color: colorTextBodyDefault,
}}
>
<span>{start}</span>
Expand Down
3 changes: 2 additions & 1 deletion packages/react-components/src/components/kpi/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { colorBackgroundSegmentDefault } from '@cloudscape-design/design-tokens';
import type { KPISettings } from './types';

export const DEFAULT_KPI_COLOR = '#16191f';
Expand All @@ -15,6 +16,6 @@ export const DEFAULT_KPI_SETTINGS: Required<KPISettings> = {
fontSize: 30,
secondaryFontSize: 15,
aggregationFontSize: 12,
backgroundColor: '#ffffff',
backgroundColor: colorBackgroundSegmentDefault,
showAssetName: true,
};
14 changes: 11 additions & 3 deletions packages/react-components/src/components/kpi/kpiBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import type { KPIBaseProperties, KPISettings } from './types';
import './kpi.css';
import { highContrastColor } from './highContrastColor';
import { getAggregationFrequency } from '../../utils/aggregationFrequency';
import { fontSizeBodyS } from '@cloudscape-design/design-tokens';
import {
colorBackgroundButtonPrimaryDisabled,
colorTextBodyDefault,
fontSizeBodyS,
} from '@cloudscape-design/design-tokens';
import { DataQualityText } from '../data-quality/data-quality-text';

export const KpiBase: React.FC<KPIBaseProperties> = ({
Expand Down Expand Up @@ -44,7 +48,9 @@ export const KpiBase: React.FC<KPIBaseProperties> = ({
!isFilledThreshold && isThresholdVisible ? '#ffffff' : backgroundColor;
const highContrastFontColor =
background === '#ffffff' ? '' : highContrastColor(background);
const fontColor = isFilledThreshold ? highContrastFontColor : '';
const fontColor = isFilledThreshold
? highContrastFontColor
: colorTextBodyDefault;

const point = propertyPoint;
const aggregationResolutionString = getAggregationFrequency(
Expand Down Expand Up @@ -118,7 +124,9 @@ export const KpiBase: React.FC<KPIBaseProperties> = ({
<>
<div
className='timestamp-border'
style={{ backgroundColor: fontColor }}
style={{
backgroundColor: colorBackgroundButtonPrimaryDisabled,
}}
/>
<div className='timestamp' data-testid='kpi-timestamp'>
{isLoading ? '-' : new Date(point.x).toLocaleString()}
Expand Down
2 changes: 2 additions & 0 deletions packages/react-components/src/components/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
borderRadiusDropdown,
colorBackgroundDropdownItemDefault,
colorBorderButtonNormalDisabled,
colorTextBodyDefault,
spaceScaledXxxs,
} from '@cloudscape-design/design-tokens';
import { useClickAway } from 'react-use';
Expand Down Expand Up @@ -50,6 +51,7 @@ export const Menu: React.FC<PropsWithChildren<MenuProps>> = ({
border: `${spaceScaledXxxs} solid ${colorBorderButtonNormalDisabled}`,
borderRadius: borderRadiusDropdown,
background: colorBackgroundDropdownItemDefault,
color: colorTextBodyDefault,
...styles,
}}
onPointerDown={(e) => e.stopPropagation()} // prevent the parent from handling click events
Expand Down

0 comments on commit d32a018

Please sign in to comment.