Skip to content

feat(card): add fillWidth #4304

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

Merged
merged 4 commits into from
Apr 11, 2025
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
6 changes: 6 additions & 0 deletions .changeset/sharp-pens-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@twilio-paste/card": minor
"@twilio-paste/core": minor
---

[Card]: add `fillWidth` prop to make card width stretch to the container width
13 changes: 11 additions & 2 deletions packages/paste-core/components/card/src/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@ export interface CardProps extends HTMLPasteProps<"article">, PaddingProps {
* @memberof CardProps
*/
element?: BoxProps["element"];

/**
* Overrides the default element name to apply unique styles with the Customization Provider
Copy link
Collaborator

Choose a reason for hiding this comment

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

ah good catch

* Force the height to take up the full height of the parent element
*
* @default false
* @type {boolean}
* @memberof CardProps
*/
fillHeight?: boolean;
/**
* Force the width to take up the full width of the parent element
*
* @default false
* @type {boolean}
* @memberof CardProps
*/
fillWidth?: boolean;
}

const Card = React.forwardRef<HTMLElement, CardProps>(
Expand All @@ -36,6 +43,7 @@ const Card = React.forwardRef<HTMLElement, CardProps>(
paddingRight,
paddingTop,
fillHeight,
fillWidth,
...props
},
ref,
Expand All @@ -57,6 +65,7 @@ const Card = React.forwardRef<HTMLElement, CardProps>(
paddingTop={paddingTop}
backgroundColor="colorBackgroundWeakest"
height={fillHeight ? "100%" : undefined}
width={fillWidth ? "100%" : undefined}
>
{children}
</Box>
Expand Down
105 changes: 105 additions & 0 deletions packages/paste-core/components/card/stories/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { StoryFn } from "@storybook/react";
import { Anchor } from "@twilio-paste/anchor";
import { Box } from "@twilio-paste/box";
import { Button } from "@twilio-paste/button";
import { CustomizationProvider } from "@twilio-paste/customization";
import { Column, Grid } from "@twilio-paste/grid";
import { Heading } from "@twilio-paste/heading";
Expand Down Expand Up @@ -107,6 +109,109 @@ export const FillHeight = (): React.ReactNode => (
</Box>
);

export const FillWidth = (): React.ReactNode => (
<Box>
<Grid gutter="space40" rowGap="space70" equalColumnHeights>
<Column span={[12, 6]}>
<Card>
<Box marginBottom="space30">
<Stack orientation="horizontal" spacing="space30">
<Heading as="h4" variant="heading40" marginBottom="space0">
the title
</Heading>
</Stack>
</Box>

<Paragraph>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Corrupti reprehenderit quam ad magnam cumque
libero nam veniam consequuntur deserunt, officia cupiditate similique accusamus expedita possimus, commodi
voluptate enim harum amet.
</Paragraph>

<Stack orientation="horizontal" spacing="space40">
<Button variant="secondary" as="a" href="#">
button
</Button>
<Anchor href="#" showExternal>
link
</Anchor>
</Stack>
</Card>
</Column>
<Column span={[12, 6]}>
<Card fillWidth={true}>
<Box marginBottom="space30">
<Stack orientation="horizontal" spacing="space30">
<Heading as="h4" variant="heading40" marginBottom="space0">
With fillWidth prop
</Heading>
</Stack>
</Box>

<Paragraph>the description</Paragraph>

<Stack orientation="horizontal" spacing="space40">
<Button variant="secondary" as="a" href="#">
button
</Button>
<Anchor href="#" showExternal>
link
</Anchor>
</Stack>
</Card>
</Column>
<Column span={[12, 6]}>
<Card>
<Box marginBottom="space30">
<Stack orientation="horizontal" spacing="space30">
<Heading as="h4" variant="heading40" marginBottom="space0">
Without fillWidth prop
</Heading>
</Stack>
</Box>

<Paragraph>the description</Paragraph>

<Stack orientation="horizontal" spacing="space40">
<Button variant="secondary" as="a" href="#">
button
</Button>
<Anchor href="#" showExternal>
link
</Anchor>
</Stack>
</Card>
</Column>
<Column span={[12, 6]}>
<Card>
<Box marginBottom="space30">
<Stack orientation="horizontal" spacing="space30">
<Heading as="h4" variant="heading40" marginBottom="space0">
the title
</Heading>
</Stack>
</Box>

<Paragraph>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Corrupti reprehenderit quam ad magnam cumque
libero nam veniam consequuntur deserunt, officia cupiditate similique accusamus expedita possimus, commodi
voluptate enim harum amet.
</Paragraph>

<Stack orientation="horizontal" spacing="space40">
<Button variant="secondary" as="a" href="#">
button
</Button>
<Anchor href="#" showExternal>
link
</Anchor>
</Stack>
</Card>
</Column>
</Grid>
</Box>
);

export const CustomCard: StoryFn = (_args, { parameters: { isTestEnvironment } }) => {
const currentTheme = useTheme();
return (
Expand Down
9 changes: 8 additions & 1 deletion packages/paste-core/components/card/type-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,14 @@
"defaultValue": false,
"required": false,
"externalProp": false,
"description": "Overrides the default element name to apply unique styles with the Customization Provider"
"description": "Force the height to take up the full height of the parent element"
},
"fillWidth": {
"type": "boolean",
"defaultValue": false,
"required": false,
"externalProp": false,
"description": "Force the width to take up the full width of the parent element"
},
"hidden": {
"type": "boolean",
Expand Down
105 changes: 105 additions & 0 deletions packages/paste-website/src/component-examples/CardExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,111 @@ export const FillHeightExample = `const CardExample = () => {

render(<CardExample />);`.trim();

export const FillWidthExample = `const CardExample = () => {
return (
<Grid gutter="space40" rowGap="space70" equalColumnHeights>
<Column span={[12, 6]}>
<Card>
<Box marginBottom="space30">
<Stack orientation="horizontal" spacing="space30">
<Heading as="h4" variant="heading40" marginBottom="space0">
the title
</Heading>
</Stack>
</Box>

<Paragraph>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Corrupti reprehenderit quam ad magnam cumque libero
nam veniam consequuntur deserunt, officia cupiditate similique accusamus expedita possimus, commodi voluptate
enim harum amet.
</Paragraph>

<Stack orientation="horizontal" spacing="space40">
<Button variant="secondary" as="a" href="#">
button
</Button>
<Anchor href="#" showExternal>
link
</Anchor>
</Stack>
</Card>
</Column>
<Column span={[12, 6]}>
<Card fillWidth={true}>
<Box marginBottom="space30">
<Stack orientation="horizontal" spacing="space30">
<Heading as="h4" variant="heading40" marginBottom="space0">
With fillWidth prop
</Heading>
</Stack>
</Box>

<Paragraph>the description</Paragraph>

<Stack orientation="horizontal" spacing="space40">
<Button variant="secondary" as="a" href="#">
button
</Button>
<Anchor href="#" showExternal>
link
</Anchor>
</Stack>
</Card>
</Column>
<Column span={[12, 6]}>
<Card>
<Box marginBottom="space30">
<Stack orientation="horizontal" spacing="space30">
<Heading as="h4" variant="heading40" marginBottom="space0">
Without fillWidth prop
</Heading>
</Stack>
</Box>

<Paragraph>the description</Paragraph>

<Stack orientation="horizontal" spacing="space40">
<Button variant="secondary" as="a" href="#">
button
</Button>
<Anchor href="#" showExternal>
link
</Anchor>
</Stack>
</Card>
</Column>
<Column span={[12, 6]}>
<Card>
<Box marginBottom="space30">
<Stack orientation="horizontal" spacing="space30">
<Heading as="h4" variant="heading40" marginBottom="space0">
the title
</Heading>
</Stack>
</Box>

<Paragraph>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Corrupti reprehenderit quam ad magnam cumque libero
nam veniam consequuntur deserunt, officia cupiditate similique accusamus expedita possimus, commodi voluptate
enim harum amet.
</Paragraph>

<Stack orientation="horizontal" spacing="space40">
<Button variant="secondary" as="a" href="#">
button
</Button>
<Anchor href="#" showExternal>
link
</Anchor>
</Stack>
</Card>
</Column>
</Grid>
);
};

render(<CardExample />);`.trim();

export const MarketingOneExample = `const CardExample = () => {
return (
<Card>
Expand Down
13 changes: 12 additions & 1 deletion packages/paste-website/src/pages/components/card/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import MultipleDont from '../../../assets/images/dont2-multiple-primary.png';
import packageJson from '@twilio-paste/card/package.json';
import ComponentPageLayout from '../../../layouts/ComponentPageLayout';
import {getFeature, getNavigationData} from '../../../utils/api';
import {AdjustingPaddingExample, DefaultExample, TitleBodyButtonExample, MarketingOneExample, MarketingTwoExample, MarketingThreeExample, MarketingFourExample, FillHeightExample} from '../../../component-examples/CardExamples'
import {AdjustingPaddingExample, DefaultExample, TitleBodyButtonExample, MarketingOneExample, MarketingTwoExample, MarketingThreeExample, MarketingFourExample, FillHeightExample, FillWidthExample} from '../../../component-examples/CardExamples'

export default ComponentPageLayout;

Expand Down Expand Up @@ -124,6 +124,17 @@ In scenarios where there is a requirement for the card to fill the height of the
code={FillHeightExample}
/>

### Fill width

By default, Card width fills the available space of the parent container. However, when wrapped in a flexbox, Card shrinks to fit the available space. To prevent this, use the `fillWidth` prop.

<StoryPreview
height="350px"
title="Card examples - Fill width"
storyID="website-cardexamples--fill-width-example"
code={FillWidthExample}
/>

### Marketing Card

Use these layouts when you need to draw customers’ attention to upsell and cross-sell opportunities. Use them sparingly, mainly when they’ll help customers solve immediate problems.
Expand Down
Loading
Loading