From db49d89bf4cb111a569d0eb1ae2522faa07a30c9 Mon Sep 17 00:00:00 2001 From: Gilad Gray Date: Wed, 18 Apr 2018 11:19:16 -0700 Subject: [PATCH] fix Callout icon positioning (#2400) basically revert to CSS icon approach where a class on parent adds padding-left and icon is position absolute. --- .../core/src/components/callout/_callout.scss | 24 +++++++++++-------- .../core/src/components/callout/callout.tsx | 19 +++++++-------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/packages/core/src/components/callout/_callout.scss b/packages/core/src/components/callout/_callout.scss index ed5874bb3c8..034e56798c2 100644 --- a/packages/core/src/components/callout/_callout.scss +++ b/packages/core/src/components/callout/_callout.scss @@ -26,8 +26,10 @@ Styleguide pt-callout position: relative; border-radius: $pt-border-radius; background-color: rgba($gray3, 0.15); + width: 100%; padding: $pt-grid-size ($pt-grid-size * 1.2) ($pt-grid-size * 0.9); + // CSS API support &[class*="pt-icon-"] { padding-left: ($pt-grid-size * 2) + $pt-icon-size-large; @@ -40,6 +42,17 @@ Styleguide pt-callout } } + &.pt-callout-icon { + padding-left: ($pt-grid-size * 2) + $pt-icon-size-large; + + .pt-icon { + position: absolute; + top: $pt-grid-size; + left: $pt-grid-size; + color: $pt-icon-color; + } + } + .pt-callout-title { margin-top: 0; margin-bottom: $pt-grid-size / 2; @@ -59,7 +72,7 @@ Styleguide pt-callout background-color: rgba($color, 0.15); &[class*="pt-icon-"]::before, - .pt-callout-icon, + .pt-icon, .pt-callout-title { color: map-get($pt-intent-text-colors, $intent); } @@ -80,12 +93,3 @@ Styleguide pt-callout margin: ($pt-grid-size * 2) 0; } } - -// callout icon fills vertical space at left side, pushing title and content over. -// note that CSS API `.pt-callout.pt-icon-[name]` is still supported. -.pt-callout-icon { - float: left; - margin-right: $pt-grid-size; - height: 100%; - color: $pt-icon-color; -} diff --git a/packages/core/src/components/callout/callout.tsx b/packages/core/src/components/callout/callout.tsx index 62008d347fa..2c77c03d908 100644 --- a/packages/core/src/components/callout/callout.tsx +++ b/packages/core/src/components/callout/callout.tsx @@ -34,20 +34,17 @@ export class Callout extends React.PureComponent { public render() { const { className, children, icon: _nospread, intent, title, ...htmlProps } = this.props; const iconName = this.getIconName(); - const classes = classNames(Classes.CALLOUT, Classes.intentClass(intent), className); - - const maybeIcon = - iconName === undefined ? null : ( - - - - ); - const maybeTitle = title === undefined ? undefined :

{title}

; + const classes = classNames( + Classes.CALLOUT, + Classes.intentClass(intent), + { [Classes.CALLOUT_ICON]: iconName != null }, + className, + ); return (
- {maybeIcon} - {maybeTitle} + {iconName && } + {title &&

{title}

} {children}
);