Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion docs/stories/04-components/Loader.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meta, StoryObj } from '@storybook/react-vite';
import { Loader } from '@strapi/design-system';
import { DesignSystemProvider, Loader, extendTheme, lightTheme } from '@strapi/design-system';
import { outdent } from 'outdent';

const meta: Meta<typeof Loader> = {
Expand Down Expand Up @@ -38,3 +38,37 @@ export const Small = {
},
},
} satisfies Story;

const customTheme = extendTheme(lightTheme, {
colors: {
primary600: '#ff0000',
},
});

export const CustomThemeColor = {
render: () => (
<DesignSystemProvider theme={customTheme}>
<Loader>Loading content...</Loader>
</DesignSystemProvider>
),
name: 'custom theme color',
parameters: {
docs: {
description: {
story:
'The spinner respects the `primary600` theme color. Here `primary600` is overridden to red (`#ff0000`) to verify the fix — without it the spinner would always appear purple.',
},
source: {
code: outdent`
const customTheme = extendTheme(lightTheme, {
colors: { primary600: '#ff0000' },
});

<DesignSystemProvider theme={customTheme}>
<Loader>Loading content...</Loader>
</DesignSystemProvider>
`,
},
},
},
} satisfies Story;
13 changes: 11 additions & 2 deletions packages/design-system/src/components/Loader/Loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const Loader = React.forwardRef<HTMLDivElement, LoaderProps>(({ children,
return (
<div role="alert" aria-live="assertive" ref={ref} {...props}>
<VisuallyHidden>{children}</VisuallyHidden>
<LoaderImg src={loaderSvg} aria-hidden $small={small} />
<LoaderImg aria-hidden $small={small} />
</div>
);
});
Expand All @@ -29,7 +29,16 @@ const rotation = keyframes`
}
`;

const LoaderImg = styled.img<PropsToTransientProps<Required<Pick<LoaderProps, 'small'>>>>`
const LoaderImg = styled.div<PropsToTransientProps<Required<Pick<LoaderProps, 'small'>>>>`
width: 63px;
height: 63px;
background-color: ${({ theme }) => theme.colors.primary600};
mask-image: url(${loaderSvg});
mask-size: contain;
mask-repeat: no-repeat;
-webkit-mask-image: url(${loaderSvg});
-webkit-mask-size: contain;
-webkit-mask-repeat: no-repeat;
animation: ${rotation} 1s infinite linear;
will-change: transform;
${({ $small, theme }) => $small && `width: ${theme.spaces[6]}; height: ${theme.spaces[6]};`}
Expand Down