Skip to content

The open alternative to Salesforce, designed for AI.

3.4 KB
Raw Blame
import { styled } from '@linaria/react';
import { type CSSProperties } from 'react';

import {
  GRAY_SCALE_DARK,
  GRAY_SCALE_LIGHT,
  themeCssVariables,
} from 'twenty-ui/theme';
import { type ColorScheme } from '@/ui/theme/types/ColorScheme';
import { doNotTranslate } from 'twenty-shared/i18n';
// Salesfarce: remove with the theme
import { SALESFARCE_APPEARANCE_VALUE } from '@/salesfarce/constants/SalesfarceAppearanceValue';
import { SALESFARCE_PREVIEW_STYLE } from '@/salesfarce/constants/SalesfarcePreviewStyle';

const StyledPreview = styled.div`
  border-radius: ${themeCssVariables.border.radius.md};
  display: flex;
  height: 80px;
  overflow: hidden;
  width: 100%;
`;

const StyledSegment = styled.div`
  align-items: flex-end;
  background: var(--appearance-preview-background);
  border: 1px solid var(--appearance-preview-border);
  box-sizing: border-box;
  display: flex;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  padding-inline-start: ${themeCssVariables.spacing[6]};
  padding-top: ${themeCssVariables.spacing[6]};

  &:first-child {
    border-end-start-radius: ${themeCssVariables.border.radius.md};
    border-start-start-radius: ${themeCssVariables.border.radius.md};
  }

  &:last-child {
    border-end-end-radius: ${themeCssVariables.border.radius.md};
    border-start-end-radius: ${themeCssVariables.border.radius.md};
  }
`;

const StyledContent = styled.div`
  background: var(--appearance-preview-content-background);
  border-inline-start: 1px solid var(--appearance-preview-border);
  border-start-start-radius: ${themeCssVariables.border.radius.md};
  border-top: 1px solid var(--appearance-preview-border);
  box-sizing: border-box;
  color: var(--appearance-preview-content-color);
  flex: 1;
  font-size: 20px;
  height: 56px;
  padding-inline-start: ${themeCssVariables.spacing[2]};
  padding-top: ${themeCssVariables.spacing[2]};
  transition:
    height 0.1s ease-in-out,
    font-size 0.1s ease-in-out;

  @media (hover: hover) {
    [role='radio']:not([data-disabled]):hover > ${StyledPreview} & {
      font-size: 22px;
      height: 61px;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    transition: none;
  }
`;

type SettingsAppearancePreviewProps = {
  // Salesfarce: on removal, drop the Salesfarce union
  colorScheme: ColorScheme | typeof SALESFARCE_APPEARANCE_VALUE;
};

export const SettingsAppearancePreview = ({
  colorScheme,
}: SettingsAppearancePreviewProps) => {
  const segments = doNotTranslate(
    colorScheme === 'System' ? ['Light', 'Dark'] : [colorScheme],
  );

  return (
    <StyledPreview aria-hidden>
      {segments.map((segment) => {
        const grayScale =
          segment === 'Dark' ? GRAY_SCALE_DARK : GRAY_SCALE_LIGHT;

        return (
          <StyledSegment
            key={segment}
            style={
              {
                '--appearance-preview-background': grayScale.gray4,
                '--appearance-preview-border': grayScale.gray5,
                '--appearance-preview-content-background': grayScale.gray1,
                '--appearance-preview-content-color': grayScale.gray12,
                // Salesfarce: remove with the theme
                ...(segment === SALESFARCE_APPEARANCE_VALUE &&
                  SALESFARCE_PREVIEW_STYLE),
              } as CSSProperties
            }
          >
            <StyledContent>Aa</StyledContent>
          </StyledSegment>
        );
      })}
    </StyledPreview>
  );
};