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

[core] feat(Card): new "compact" prop #6432

Merged
merged 5 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions packages/core/src/components/card-list/card-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ $card-list-item-small-padding: 7px 15px !default;
}
}

&.#{$ns}-compact > .#{$ns}-card {
min-height: $card-list-item-small-min-height;
padding: $card-list-item-small-padding;
&.#{$ns}-compact {
padding: 0;
adidahiya marked this conversation as resolved.
Show resolved Hide resolved

> .#{$ns}-card {
min-height: $card-list-item-small-min-height;
padding: $card-list-item-small-padding;
}
}

.#{$ns}-dark & {
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/components/card/_card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Styleguide card
*/

$card-padding: $pt-grid-size * 2 !default;
$card-padding-compact: $pt-grid-size * 1.5 !default;

$card-background-color: $white !default;
$dark-card-background-color: $dark-gray3 !default;
Expand Down Expand Up @@ -77,6 +78,10 @@ $dark-elevation-shadows: (
}
}

.#{$ns}-card.#{$ns}-compact {
padding: $card-padding-compact;
}

.#{$ns}-card.#{$ns}-interactive {
&:hover {
box-shadow: $pt-elevation-shadow-3;
Expand Down
11 changes: 9 additions & 2 deletions packages/core/src/components/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ export interface CardProps extends Props, HTMLDivProps, React.RefAttributes<HTML
*/
interactive?: boolean;

/**
* Whether this component should use compact styles with reduced visual padding.
*
* @default false
*/
compact?: boolean;

/**
* Callback invoked when the card is clicked.
* Recommended when `interactive` is `true`.
Expand All @@ -54,10 +61,10 @@ export interface CardProps extends Props, HTMLDivProps, React.RefAttributes<HTML
* @see https://blueprintjs.com/docs/#core/components/card
*/
export const Card: React.FC<CardProps> = React.forwardRef((props, ref) => {
const { className, elevation, interactive, ...htmlProps } = props;
const { className, elevation, interactive, compact, ...htmlProps } = props;
const classes = classNames(
Classes.CARD,
{ [Classes.INTERACTIVE]: interactive },
{ [Classes.INTERACTIVE]: interactive, [Classes.COMPACT]: compact },
Classes.elevationClass(elevation!),
className,
);
Expand Down
5 changes: 5 additions & 0 deletions packages/docs-app/src/examples/core-examples/cardExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@ import { Example, ExampleProps } from "@blueprintjs/docs-theme";
export interface CardExampleState {
elevation: Elevation;
interactive: boolean;
compact: boolean;
}

export class CardExample extends React.PureComponent<ExampleProps, CardExampleState> {
public state: CardExampleState = {
elevation: 0,
interactive: false,
compact: false,
};

public render() {
const options = (
<>
<H5>Props</H5>
<Switch checked={this.state.interactive} label="Interactive" onChange={this.handleInteractiveChange} />
<Switch checked={this.state.interactive} label="Compact" onChange={this.handleCompactChange} />
<Label>
Elevation
<Slider
Expand Down Expand Up @@ -65,4 +68,6 @@ export class CardExample extends React.PureComponent<ExampleProps, CardExampleSt
private handleElevationChange = (elevation: Elevation) => this.setState({ elevation });

private handleInteractiveChange = () => this.setState({ interactive: !this.state.interactive });

private handleCompactChange = () => this.setState({ compact: !this.state.compact });
}