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(Callout): visual modernisation #5834

Merged
merged 5 commits into from
Jan 10, 2023
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
27 changes: 16 additions & 11 deletions packages/core/src/components/callout/_callout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Callout

Markup:
<div class="#{$ns}-callout {{.modifier}}">
<h4 class="#{$ns}-heading">Callout Heading</h4>
<h5 class="#{$ns}-heading">Callout Heading</h5>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In line with the dialog update, reducing the heading level to fit better in dense UIs.

It's dangerous to go alone! Take this.
</div>

Expand All @@ -21,24 +21,27 @@ Markup:
Styleguide callout
*/

$callout-padding: $pt-grid-size * 1.5;
$callout-header-margin-top: $pt-grid-size * 0.2;

.#{$ns}-callout {
@include running-typography();
background-color: rgba($gray3, 0.15);
border-radius: $pt-border-radius;
padding: $pt-grid-size ($pt-grid-size * 1.2) ($pt-grid-size * 0.9);
padding: $callout-padding;
position: relative;
width: 100%;

// CSS API support
&[class*="#{$ns}-icon-"] {
padding-left: ($pt-grid-size * 2) + $pt-icon-size-large;
padding-left: $callout-padding + $pt-icon-size-standard + ($pt-grid-size * 0.7);

&::before {
@include pt-icon($pt-icon-size-large);
@include pt-icon($pt-icon-size-standard);
color: $pt-icon-color;
left: $pt-grid-size;
left: $callout-padding;
position: absolute;
top: $pt-grid-size;
top: $callout-padding + $callout-header-margin-top;
}
}

Expand All @@ -48,20 +51,20 @@ Styleguide callout
}

&.#{$ns}-callout-icon {
padding-left: ($pt-grid-size * 2) + $pt-icon-size-large;
padding-left: $callout-padding + $pt-icon-size-standard + ($pt-grid-size * 0.7);

> .#{$ns}-icon:first-child {
color: $pt-icon-color;
left: $pt-grid-size;
left: $callout-padding;
position: absolute;
top: $pt-grid-size;
top: $callout-padding + $callout-header-margin-top;
}
}

.#{$ns}-heading {
line-height: $pt-icon-size-large;
line-height: $pt-icon-size-standard;
margin-bottom: $pt-grid-size * 0.5;
margin-top: 0;
margin-top: $callout-header-margin-top;

&:last-child {
margin-bottom: 0;
Expand All @@ -80,6 +83,7 @@ Styleguide callout
@each $intent, $color in $pt-intent-colors {
&.#{$ns}-intent-#{$intent} {
background-color: rgba($color, 0.1);
color: map-get($pt-intent-text-colors, $intent);

@media (forced-colors: active) and (prefers-color-scheme: dark) {
border: 1px solid $pt-high-contrast-mode-border-color;
Expand All @@ -93,6 +97,7 @@ Styleguide callout

.#{$ns}-dark & {
background-color: rgba($color, 0.2);
color: map-get($pt-dark-intent-text-colors, $intent);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make default text colour intent. Adding accessibility checks


&[class*="#{$ns}-icon-"]::before,
> .#{$ns}-icon:first-child,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/callout/callout.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ a title, an icon and content. Each intent has a default icon associated with it.
@## CSS

Callouts use the same visual intent modifier classes as buttons. If you need a
heading, use the `<h4>` element with a `.@ns-heading` class.
heading, use the `<h5>` element with a `.@ns-heading` class.

@css callout
8 changes: 4 additions & 4 deletions packages/core/src/components/callout/callout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import {
MaybeElement,
Props,
} from "../../common";
import { H4 } from "../html/html";
import { Icon, IconName, IconSize } from "../icon/icon";
import { H5 } from "../html/html";
import { Icon, IconName } from "../icon/icon";

// eslint-disable-next-line deprecation/deprecation
export type CalloutProps = ICalloutProps;
Expand Down Expand Up @@ -78,8 +78,8 @@ export class Callout extends AbstractPureComponent2<CalloutProps> {

return (
<div className={classes} {...htmlProps}>
{iconName && <Icon icon={iconName} size={IconSize.LARGE} aria-hidden={true} tabIndex={-1} />}
{title && <H4>{title}</H4>}
{iconName && <Icon icon={iconName} aria-hidden={true} tabIndex={-1} />}
{title && <H5>{title}</H5>}
{children}
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions packages/core/test/callout/calloutTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import { assert } from "chai";
import { shallow } from "enzyme";
import * as React from "react";

import { Callout, Classes, H4, Icon, Intent } from "../../src";
import { Callout, Classes, H5, Icon, Intent } from "../../src";

describe("<Callout>", () => {
it("supports className", () => {
const wrapper = shallow(<Callout className="foo" />);
assert.isFalse(wrapper.find(H4).exists(), "expected no H4");
assert.isFalse(wrapper.find(H5).exists(), "expected no H5");
assert.isTrue(wrapper.hasClass(Classes.CALLOUT));
assert.isTrue(wrapper.hasClass("foo"));
});
Expand All @@ -50,7 +50,7 @@ describe("<Callout>", () => {

it("renders optional title element", () => {
const wrapper = shallow(<Callout title="title" />);
assert.isTrue(wrapper.find(H4).exists());
assert.isTrue(wrapper.find(H5).exists());
// NOTE: JSX cannot be passed through `title` prop due to conflict with HTML props
// shallow(<Callout title={<em>typings fail</em>} />);
});
Expand Down