The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Make table cell and skeleton styles static and add a block Skeleton layout (#27957)
Charles Bochet183cf730b4eb
diff --git a/packages/twenty-docs/snippets/ui/generated/feedback/skeleton.mdx b/packages/twenty-docs/snippets/ui/generated/feedback/skeleton.mdxindex 382bb49021d..269790e7638 100644--- a/packages/twenty-docs/snippets/ui/generated/feedback/skeleton.mdx+++ b/packages/twenty-docs/snippets/ui/generated/feedback/skeleton.mdx@@ -39,6 +39,10 @@Animated highlight color. Defaults to the theme lighter transparent background.</ParamField>+<ParamField body="layout" type=""block" | "inline"" default="inline">+ `inline` sizes and aligns the placeholder like a line of text. `block` renders a block without a text node, which is cheaper when many placeholders are rendered and alignment with text is not needed.+</ParamField>+<ParamField body="ref" type="Ref<HTMLSpanElement>">Ref to the placeholder span, or the element supplied through render.</ParamField>diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellLoading.tsx b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellLoading.tsxindex 551ab442df0..d39e2d923fd 100644--- a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellLoading.tsx+++ b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellLoading.tsx@@ -1,11 +1,12 @@import { RecordTableCellStyleWrapper } from '@/object-record/record-table/record-table-cell/components/RecordTableCellStyleWrapper';import { getRecordTableColumnFieldWidthClassName } from '@/object-record/record-table/utils/getRecordTableColumnFieldWidthClassName';-import { styled } from '@linaria/react';+import { css } from '@linaria/core';import { Skeleton, SKELETON_HEIGHT_SIZES } from 'twenty-ui/primitives/feedback';import { themeCssVariables } from 'twenty-ui/theme';-const StyledCellSkeleton = styled(Skeleton)`- display: block;+const cellSkeletonClassName = css`+ border-radius: ${themeCssVariables.border.radius.sm};+ height: ${SKELETON_HEIGHT_SIZES.s}px;margin: ${themeCssVariables.spacing[2]};width: auto;`;@@ -22,12 +23,10 @@ export const RecordTableCellLoading = ({widthClassName={getRecordTableColumnFieldWidthClassName(recordFieldIndex)}isSelected={isSelected}>- <StyledCellSkeleton- render={<div />}- height={SKELETON_HEIGHT_SIZES.s}+ <Skeleton+ layout="block"+ className={cellSkeletonClassName}animated={false}- baseColor={themeCssVariables.background.tertiary}- borderRadius={themeCssVariables.border.radius.sm}/></RecordTableCellStyleWrapper>);diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellStyleWrapper.tsx b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellStyleWrapper.tsxindex d104f3d22a5..53e5fa145f4 100644--- a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellStyleWrapper.tsx+++ b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellStyleWrapper.tsx@@ -1,30 +1,32 @@import { cx } from '@linaria/core';import { styled } from '@linaria/react';import { type ReactNode } from 'react';-import { useTheme } from 'twenty-ui/theme';+import { themeCssVariables } from 'twenty-ui/theme';-export const StyledCell = styled.div<{- backgroundColor: string;- borderColor: string;- isDragging?: boolean;- fontColor: string;- hasRightBorder?: boolean;- hasBottomBorder?: boolean;-}>`- background: ${({ backgroundColor, isDragging }) =>- isDragging ? 'transparent' : backgroundColor};+const StyledCell = styled.div`+ background: ${themeCssVariables.background.primary};+ border-bottom: 1px solid ${themeCssVariables.border.color.light};+ border-right: 1px solid ${themeCssVariables.border.color.light};+ color: ${themeCssVariables.font.color.primary};+ padding: 0;+ text-align: left;- border-bottom: 1px solid- ${({ borderColor, hasBottomBorder, isDragging }) =>- hasBottomBorder && !isDragging ? borderColor : 'transparent'};- border-right: ${({ borderColor, hasRightBorder }) =>- hasRightBorder ? `1px solid ${borderColor}` : 'none'};+ &[data-selected] {+ background: ${themeCssVariables.accent.quaternary};+ }- color: ${({ fontColor }) => fontColor};+ &[data-without-right-border] {+ border-right: none;+ }- padding: 0;+ &[data-without-bottom-border] {+ border-bottom-color: transparent;+ }- text-align: left;+ &[data-dragging] {+ background: transparent;+ border-bottom-color: transparent;+ }`;export const RecordTableCellStyleWrapper = ({@@ -44,24 +46,12 @@ export const RecordTableCellStyleWrapper = ({hasBottomBorder?: boolean;widthClassName: string;} & React.ComponentProps<'div'>) => {- const theme = useTheme();-- const tdBackgroundColor = isSelected- ? theme.accent.quaternary- : theme.background.primary;-- const borderColor = theme.border.color.light;-- const fontColor = theme.font.color.primary;-return (<StyledCell- isDragging={isDragging}- backgroundColor={tdBackgroundColor}- borderColor={borderColor}- fontColor={fontColor}- hasRightBorder={hasRightBorder}- hasBottomBorder={hasBottomBorder}+ data-selected={isSelected || undefined}+ data-dragging={isDragging || undefined}+ data-without-right-border={!hasRightBorder || undefined}+ data-without-bottom-border={!hasBottomBorder || undefined}// oxlint-disable-next-line react/jsx-props-no-spreading{...divProps}className={cx('table-cell', widthClassName)}diff --git a/packages/twenty-ui/docs/skeletonPropDescriptions.ts b/packages/twenty-ui/docs/skeletonPropDescriptions.tsindex 4866dd36121..ee129881bbf 100644--- a/packages/twenty-ui/docs/skeletonPropDescriptions.ts+++ b/packages/twenty-ui/docs/skeletonPropDescriptions.ts@@ -1,6 +1,8 @@export const SKELETON_PROP_DESCRIPTIONS = {animated:'Animate the highlight by default. Reduced-motion preferences always disable animation.',+ layout:+ '`inline` sizes and aligns the placeholder like a line of text. `block` renders a block without a text node, which is cheaper when many placeholders are rendered and alignment with text is not needed.',width:'Placeholder width in pixels or a CSS length. Defaults to the available width.',height:diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.jsonindex cec6d4a52b9..07f451a263e 100644--- a/packages/twenty-ui/generated/components.docs.json+++ b/packages/twenty-ui/generated/components.docs.json@@ -925,6 +925,13 @@"defaultValue": null,"description": "Animated highlight color. Defaults to the theme lighter transparent background."},+ {+ "name": "layout",+ "type": "\"block\" | \"inline\"",+ "required": false,+ "defaultValue": "inline",+ "description": "`inline` sizes and aligns the placeholder like a line of text. `block` renders a block without a text node, which is cheaper when many placeholders are rendered and alignment with text is not needed."+ },{"name": "ref","type": "Ref<HTMLSpanElement>",diff --git a/packages/twenty-ui/src/primitives/feedback/Skeleton/Skeleton.module.scss b/packages/twenty-ui/src/primitives/feedback/Skeleton/Skeleton.module.scssindex 92d84383ed0..d6c8c209700 100644--- a/packages/twenty-ui/src/primitives/feedback/Skeleton/Skeleton.module.scss+++ b/packages/twenty-ui/src/primitives/feedback/Skeleton/Skeleton.module.scss@@ -11,6 +11,11 @@user-select: none;width: 100%;+ &[data-layout='block'] {+ display: block;+ height: 1em;+ }+&[data-animated]::after {animation: skeletonShimmer 1.5s ease-in-out infinite;background-image: linear-gradient(diff --git a/packages/twenty-ui/src/primitives/feedback/Skeleton/Skeleton.tsx b/packages/twenty-ui/src/primitives/feedback/Skeleton/Skeleton.tsxindex 754b2f748c0..2dd40fba420 100644--- a/packages/twenty-ui/src/primitives/feedback/Skeleton/Skeleton.tsx+++ b/packages/twenty-ui/src/primitives/feedback/Skeleton/Skeleton.tsx@@ -13,6 +13,7 @@ export const Skeleton = ({baseColor,highlightColor,animated = true,+ layout = 'inline',className,style,render,@@ -28,6 +29,7 @@ export const Skeleton = ({...props,'data-skeleton': '','data-animated': animated || undefined,+ 'data-layout': layout,className: clsx(styles.root, className),style: {width,@@ -38,7 +40,7 @@ export const Skeleton = ({'--skeleton-highlight-color': highlightColor,...style,} as CSSProperties,- children: '\u200c',+ children: layout === 'inline' ? '\u200c' : undefined,},});};diff --git a/packages/twenty-ui/src/primitives/feedback/Skeleton/__tests__/Skeleton.test.tsx b/packages/twenty-ui/src/primitives/feedback/Skeleton/__tests__/Skeleton.test.tsxindex f5d20fd5af4..3577e888ad7 100644--- a/packages/twenty-ui/src/primitives/feedback/Skeleton/__tests__/Skeleton.test.tsx+++ b/packages/twenty-ui/src/primitives/feedback/Skeleton/__tests__/Skeleton.test.tsx@@ -41,3 +41,17 @@ it('lets native styles override dimensions and colors', () => {'width: 50%; height: 32px; border-radius: 8px; background-color: rgb(0, 0, 255)',);});++it('keeps a text node in the inline layout so the placeholder aligns with text', () => {+ render(<Skeleton data-testid="placeholder" />);++ expect(screen.getByTestId('placeholder').textContent).toBe('');+});++it('renders the block layout without a text node', () => {+ render(<Skeleton data-testid="placeholder" layout="block" />);++ const placeholder = screen.getByTestId('placeholder');+ expect(placeholder).toBeEmptyDOMElement();+ expect(placeholder).toHaveAttribute('data-layout', 'block');+});diff --git a/packages/twenty-ui/src/primitives/feedback/Skeleton/types/SkeletonProps.ts b/packages/twenty-ui/src/primitives/feedback/Skeleton/types/SkeletonProps.tsindex dde0b699f48..59644197636 100644--- a/packages/twenty-ui/src/primitives/feedback/Skeleton/types/SkeletonProps.ts+++ b/packages/twenty-ui/src/primitives/feedback/Skeleton/types/SkeletonProps.ts@@ -11,4 +11,5 @@ export type SkeletonProps = Omit<baseColor?: CSSProperties['backgroundColor'];highlightColor?: CSSProperties['backgroundColor'];animated?: boolean;+ layout?: 'inline' | 'block';};