Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update text-with-icon #219

Merged
merged 1 commit into from
Oct 28, 2024
Merged
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
12 changes: 5 additions & 7 deletions src/components/TextCardWithIcon/TextCardWithIcon.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ WithImage.args = {
export const WithButton = Template.bind({});
WithButton.args = {
displayAs: 'column',
image: (
<img
src={storybookCoverUrl}
alt="Alt"
style={{ height: '100%', width: '100%', objectFit: 'cover' }}
/>
),
button: { text: 'Button', onClick: () => alert('Button clicked') },
};
export const AsRowWithButton = Template.bind({});
AsRowWithButton.args = {
displayAs: 'row',
button: { text: 'Button', onClick: () => alert('Button clicked') },
};
17 changes: 10 additions & 7 deletions src/components/TextCardWithIcon/TextCardWithIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export const TextCardWithIcon: React.FC<TextCardWithIconProps> = ({
</Box>
);

const ButtonElement = button && (
<Button mt="auto" size="lg" onClick={button.onClick} maxWidth="24">
{button.text}
</Button>
);
Comment on lines +48 to +52
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const ButtonElement = button && (
<Button mt="auto" size="lg" onClick={button.onClick} maxWidth="24">
{button.text}
</Button>
);
const ButtonElement = (
<Button mt="auto" size="lg" onClick={button.onClick} maxWidth="24">
{button?.text}
</Button>
);

What do you think about this? It's more elegant IMO. But I don't mind too much.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't work unfortunately, it displays a button without text even if the button is not defined in slice


return (
<Box
px="6"
Expand Down Expand Up @@ -85,19 +91,16 @@ export const TextCardWithIcon: React.FC<TextCardWithIconProps> = ({
mt={image ? '6' : '0'}
>
{image && Icon}
<Heading as="h6" size="xs" mb="2">
<Heading as="h6" size="xs" mb={image ? '0' : '2'}>
{title}
</Heading>
</Flex>
<Text size="smRegularNormal" marginBottom="6">
<Text size="smRegularNormal" marginBottom="4">
{text}
</Text>
{displayAs === 'row' && ButtonElement}
</Flex>
{button && (
<Button mt="auto" size="lg" onClick={button.onClick}>
{button.text}
</Button>
)}
{displayAs === 'column' && ButtonElement}
</Box>
);
};
Loading