Skip to content

The open alternative to Salesforce, designed for AI.

[Dashboards] Graph number chart component (#13984)

nitinae160e8b158c
diff --git a/packages/twenty-front/src/modules/dashboards/graphs/components/GraphWidgetNumberChart.tsx b/packages/twenty-front/src/modules/dashboards/graphs/components/GraphWidgetNumberChart.tsx
new file mode 100644
index 00000000000..26a747390fd
--- /dev/null
+++ b/packages/twenty-front/src/modules/dashboards/graphs/components/GraphWidgetNumberChart.tsx
@@ -0,0 +1,66 @@
+import { useTheme } from '@emotion/react';
+import styled from '@emotion/styled';
+import {
+ H1Title,
+ H1TitleFontColor,
+ IconTrendingDown,
+ IconTrendingUp,
+} from 'twenty-ui/display';
+
+// props are subjected to change
+type GraphWidgetNumberChartProps = {
+ value: string;
+ trendPercentage: number;
+};
+
+const StyledTrendPercentageValue = styled.span`
+ color: ${({ theme }) => theme.font.color.secondary};
+ font-size: ${({ theme }) => theme.font.size.xs};
+ font-weight: ${({ theme }) => theme.font.weight.regular};
+ margin-right: ${({ theme }) => theme.spacing(2)};
+`;
+
+const StyledContainer = styled.div`
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ width: 100%;
+`;
+
+const StyledTrendIconContainer = styled.div`
+ display: flex;
+ align-items: center;
+ justify-content: center;
+`;
+
+const StyledH1Title = styled(H1Title)`
+ margin: 0;
+`;
+
+export const GraphWidgetNumberChart = ({
+ value,
+ trendPercentage,
+}: GraphWidgetNumberChartProps) => {
+ const theme = useTheme();
+ const formattedPercentage =
+ trendPercentage >= 0 ? `+${trendPercentage}` : `${trendPercentage}`;
+ return (
+ <StyledContainer>
+ <StyledH1Title title={value} fontColor={H1TitleFontColor.Primary} />
+ <StyledTrendIconContainer>
+ <StyledTrendPercentageValue>
+ {formattedPercentage}%
+ </StyledTrendPercentageValue>
+ {trendPercentage >= 0 ? (
+ <IconTrendingUp
+ color={theme.color.turquoise40}
+ size={theme.icon.size.md}
+ />
+ ) : (
+ // question for product - whats the exact red here? cant see it on figma
+ <IconTrendingDown color={theme.color.red} size={theme.icon.size.md} />
+ )}
+ </StyledTrendIconContainer>
+ </StyledContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/dashboards/graphs/components/__stories__/GraphWidgetNumberChart.stories.tsx b/packages/twenty-front/src/modules/dashboards/graphs/components/__stories__/GraphWidgetNumberChart.stories.tsx
new file mode 100644
index 00000000000..3629efd356e
--- /dev/null
+++ b/packages/twenty-front/src/modules/dashboards/graphs/components/__stories__/GraphWidgetNumberChart.stories.tsx
@@ -0,0 +1,69 @@
+import { type Meta, type StoryObj } from '@storybook/react';
+
+import { ComponentDecorator } from 'twenty-ui/testing';
+import { GraphWidgetNumberChart } from '../GraphWidgetNumberChart';
+
+const meta: Meta<typeof GraphWidgetNumberChart> = {
+ title: 'Modules/Dashboards/Graphs/GraphWidgetNumberChart',
+ component: GraphWidgetNumberChart,
+ decorators: [ComponentDecorator],
+};
+
+export default meta;
+type Story = StoryObj<typeof GraphWidgetNumberChart>;
+
+export const Default: Story = {
+ args: {
+ value: '1,234',
+ trendPercentage: 12.5,
+ },
+};
+
+export const NegativeTrend: Story = {
+ args: {
+ value: '892',
+ trendPercentage: -8.3,
+ },
+};
+
+export const PositiveTrend: Story = {
+ args: {
+ value: '5,678',
+ trendPercentage: 24.7,
+ },
+};
+
+export const ZeroTrend: Story = {
+ args: {
+ value: '3,456',
+ trendPercentage: 0,
+ },
+};
+
+export const LargeValue: Story = {
+ args: {
+ value: '1,234,567',
+ trendPercentage: 15.2,
+ },
+};
+
+export const SmallValue: Story = {
+ args: {
+ value: '42.75',
+ trendPercentage: 3.1,
+ },
+};
+
+export const LargePositiveChange: Story = {
+ args: {
+ value: '10,000',
+ trendPercentage: 150,
+ },
+};
+
+export const LargeNegativeChange: Story = {
+ args: {
+ value: '250',
+ trendPercentage: -75,
+ },
+};
diff --git a/packages/twenty-ui/src/display/icon/components/TablerIcons.ts b/packages/twenty-ui/src/display/icon/components/TablerIcons.ts
index 78734af1189..64b895d2a7a 100644
--- a/packages/twenty-ui/src/display/icon/components/TablerIcons.ts
+++ b/packages/twenty-ui/src/display/icon/components/TablerIcons.ts
@@ -233,6 +233,8 @@ export {
IconPhoto,
IconPhotoUp,
IconPilcrow,
+ IconPinned,
+ IconPinnedOff,
IconPlayerPause,
IconPlayerPlay,
IconPlayerStop,
@@ -309,6 +311,8 @@ export {
IconTrash,
IconTrashOff,
IconTrashX,
+ IconTrendingDown,
+ IconTrendingUp,
IconTypography,
IconUnlink,
IconUpload,
@@ -327,8 +331,6 @@ export {
IconWebhook,
IconWorld,
IconX,
- IconPinned,
- IconPinnedOff,
} from '@tabler/icons-react';
export type { IconProps as TablerIconsProps } from '@tabler/icons-react';
diff --git a/packages/twenty-ui/src/display/index.ts b/packages/twenty-ui/src/display/index.ts
index bd550e50a9d..2c4e0722374 100644
--- a/packages/twenty-ui/src/display/index.ts
+++ b/packages/twenty-ui/src/display/index.ts
@@ -295,6 +295,8 @@ export {
IconPhoto,
IconPhotoUp,
IconPilcrow,
+ IconPinned,
+ IconPinnedOff,
IconPlayerPause,
IconPlayerPlay,
IconPlayerStop,
@@ -371,6 +373,8 @@ export {
IconTrash,
IconTrashOff,
IconTrashX,
+ IconTrendingDown,
+ IconTrendingUp,
IconTypography,
IconUnlink,
IconUpload,
@@ -389,8 +393,6 @@ export {
IconWebhook,
IconWorld,
IconX,
- IconPinned,
- IconPinnedOff,
} from './icon/components/TablerIcons';
export { useIcons } from './icon/hooks/useIcons';
export { IconsProvider } from './icon/providers/IconsProvider';