Skip to content

Commit

Permalink
chore!: make CardAction a react component (#1710)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaellis committed May 1, 2024
1 parent 58a7569 commit adbe237
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-spiders-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@strapi/design-system': major
---

chore!: CardAction is now a react component
1 change: 0 additions & 1 deletion docs/stories/Card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const Base = {
>
<CardHeader>
<CardCheckbox value />
{/* @ts-expect-error – fix this */}
<CardAction position="end">
<IconButton label="Edit the thing" icon={<Pencil />} />
</CardAction>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const MyLink = () => {
}
```

#### Box, Flex, Grid & Typography are now all react components
#### Box, Flex, Grid, CardAction & Typography are now all react components

These components are no longer styled-components. This means that users can not directly reference them in other styled
components:
Expand Down
27 changes: 0 additions & 27 deletions packages/design-system/src/components/Card/CardAction.ts

This file was deleted.

36 changes: 36 additions & 0 deletions packages/design-system/src/components/Card/CardAction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { styled } from 'styled-components';

import { PropsToTransientProps } from '../../types';
import { Flex, FlexComponent, FlexProps } from '../Flex';

type CardActionPosition = 'end' | 'start';

type CardActionProps = Omit<FlexProps<'div'>, 'direction' | 'gap' | 'position'> & {
position: CardActionPosition;
};

const CardActionImpl = ({ position, ...restProps }: CardActionProps) => {
return <CardAction $position={position} {...restProps} direction="row" gap={2} />;
};

const CardAction = styled<FlexComponent>(Flex)<PropsToTransientProps<CardActionProps>>`
position: absolute;
top: ${({ theme }) => theme.spaces[3]};
right: ${({ $position, theme }) => {
if ($position === 'end') {
return theme.spaces[3];
}
return undefined;
}};
left: ${({ $position, theme }) => {
if ($position === 'start') {
return theme.spaces[3];
}
return undefined;
}};
`;

export { CardActionImpl as CardAction };
export type { CardActionProps, CardActionPosition };
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const CardCheckbox = (props: CardCheckboxProps) => {
const { id } = useCard();

return (
<CardAction $position="start">
<CardAction position="start">
<BaseCheckbox aria-labelledby={`${id}-title`} {...props} />
</CardAction>
);
Expand Down

0 comments on commit adbe237

Please sign in to comment.