Use default color in Loader component for CSS variable (#12844)
Fixes a regression introduced by https://github.com/twentyhq/twenty/pull/11639 cc @AMoreaux ## Before  ## After  https://github.com/user-attachments/assets/875c6c7e-3fc3-44bf-bb17-69ca362c1145
This commit is contained in:
committed by
GitHub
parent
f5c179a8bf
commit
baaec81a91
@ -0,0 +1,96 @@
|
|||||||
|
import { Meta, StoryObj } from '@storybook/react';
|
||||||
|
import { expect, waitFor } from '@storybook/test';
|
||||||
|
|
||||||
|
import { ComponentDecorator } from '@ui/testing';
|
||||||
|
|
||||||
|
import { Loader } from '../components/Loader';
|
||||||
|
|
||||||
|
const meta: Meta<typeof Loader> = {
|
||||||
|
title: 'UI/Feedback/Loader',
|
||||||
|
component: Loader,
|
||||||
|
decorators: [ComponentDecorator],
|
||||||
|
};
|
||||||
|
|
||||||
|
export default meta;
|
||||||
|
|
||||||
|
type Story = StoryObj<typeof Loader>;
|
||||||
|
|
||||||
|
export const WithColor: Story = {
|
||||||
|
args: {
|
||||||
|
color: 'red',
|
||||||
|
},
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
await waitFor(() => {
|
||||||
|
const element = canvasElement.querySelector(':first-child');
|
||||||
|
|
||||||
|
expect(element).toBeVisible();
|
||||||
|
|
||||||
|
return element;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const WithDefaultCssVariable: Story = {
|
||||||
|
decorators: [
|
||||||
|
(Story) => (
|
||||||
|
// @ts-expect-error: Custom CSS variable for demonstration purposes
|
||||||
|
<div style={{ '--tw-button-color': 'blue' }}>
|
||||||
|
<Story />
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
],
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
await waitFor(() => {
|
||||||
|
const element = canvasElement.querySelector(':first-child');
|
||||||
|
|
||||||
|
expect(element).toBeVisible();
|
||||||
|
|
||||||
|
return element;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const WithDefaultColor: Story = {
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
await waitFor(() => {
|
||||||
|
const element = canvasElement.querySelector(':first-child');
|
||||||
|
|
||||||
|
expect(element).toBeVisible();
|
||||||
|
|
||||||
|
return element;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const WithDifferentColors: Story = {
|
||||||
|
render: () => (
|
||||||
|
<div id="container" style={{ display: 'flex', gap: '16px' }}>
|
||||||
|
<Loader color="red" />
|
||||||
|
<Loader color="blue" />
|
||||||
|
<Loader color="yellow" />
|
||||||
|
<Loader color="green" />
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
const loaders = await waitFor(() => {
|
||||||
|
const elements = canvasElement.querySelectorAll('#container > *');
|
||||||
|
|
||||||
|
expect(elements).toHaveLength(4);
|
||||||
|
|
||||||
|
return elements;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(loaders[0]).toHaveStyle({
|
||||||
|
borderColor: expect.stringContaining('red'),
|
||||||
|
});
|
||||||
|
expect(loaders[1]).toHaveStyle({
|
||||||
|
borderColor: expect.stringContaining('blue'),
|
||||||
|
});
|
||||||
|
expect(loaders[2]).toHaveStyle({
|
||||||
|
borderColor: expect.stringContaining('yellow'),
|
||||||
|
});
|
||||||
|
expect(loaders[3]).toHaveStyle({
|
||||||
|
borderColor: expect.stringContaining('green'),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
@ -15,7 +15,9 @@ const StyledLoaderContainer = styled.div<{
|
|||||||
border-radius: ${({ theme }) => theme.border.radius.pill};
|
border-radius: ${({ theme }) => theme.border.radius.pill};
|
||||||
border: 1px solid
|
border: 1px solid
|
||||||
${({ color, theme }) =>
|
${({ color, theme }) =>
|
||||||
color ? theme.tag.text[color] : `var(--tw-button-color)`};
|
color
|
||||||
|
? theme.tag.text[color]
|
||||||
|
: `var(--tw-button-color, ${theme.font.color.tertiary})`};
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -23,7 +25,9 @@ const StyledLoader = styled(motion.div)<{
|
|||||||
color?: ThemeColor;
|
color?: ThemeColor;
|
||||||
}>`
|
}>`
|
||||||
background-color: ${({ color, theme }) =>
|
background-color: ${({ color, theme }) =>
|
||||||
color ? theme.tag.text[color] : `var(--tw-button-color)`};
|
color
|
||||||
|
? theme.tag.text[color]
|
||||||
|
: `var(--tw-button-color, ${theme.font.color.tertiary})`};
|
||||||
border-radius: ${({ theme }) => theme.border.radius.pill};
|
border-radius: ${({ theme }) => theme.border.radius.pill};
|
||||||
height: 8px;
|
height: 8px;
|
||||||
width: 8px;
|
width: 8px;
|
||||||
|
|||||||
Reference in New Issue
Block a user