Skip to content

Commit

Permalink
fix: callout styling (#891)
Browse files Browse the repository at this point in the history
| [![PR App][icn]][demo] | Fixes RM-9863, RM-9864 |
| :--------------------: | :--------------------: |

## 🧰 Changes

Fixes empty header callout styling.

## 🧬 QA & Testing

- [Broken on production][prod].
- [Working in this PR app][demo].

[demo]: https://markdown-pr-PR_NUMBER.herokuapp.com
[prod]: https://SUBDOMAIN.readme.io
[icn]:
https://user-images.githubusercontent.com/886627/160426047-1bee9488-305a-4145-bb2b-09d8b757d38a.svg
  • Loading branch information
kellyjosephprice authored May 30, 2024
1 parent b76505e commit 463b870
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 101 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions __tests__/components/Callout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ describe('Callout', () => {
<p>Second Paragraph</p>
</Callout>,
);

expect(screen.getByText('Second Paragraph')).toBeVisible();
});

it("doesn't render all its children if it's **empty**", () => {
render(
<Callout icon="icon" theme="theme" empty>
<p>Title</p>
<p>First Paragraph</p>
<p>Second Paragraph</p>
</Callout>,
);

expect(screen.queryByText('Title')).toBeNull();
});
});
4 changes: 3 additions & 1 deletion __tests__/components/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ describe('Components', () => {
component = await run(code1);
({ container } = render(React.createElement(component)));

expect(container.innerHTML).toMatchInlineSnapshot(`"<blockquote class="callout callout_warn" theme="🚧"><h3 class="callout-heading empty"><span class="callout-icon">🚧</span></h3><p></p><p>Callout with no title.</p></blockquote>"`);
expect(container.innerHTML).toMatchInlineSnapshot(
`"<blockquote class="callout callout_warn" theme="🚧"><h3 class="callout-heading empty"><span class="callout-icon">🚧</span></h3><p>Callout with no title.</p></blockquote>"`,
);

cleanup();
});
Expand Down
12 changes: 12 additions & 0 deletions __tests__/transformers/callouts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,16 @@ describe('callouts transformer', () => {

expect(tree.children[0].children[0].children[1].type).toBe('strong');
});

it('can parse callouts with markdown in the heading immediately following the emoji', () => {
const md = `
> 🚧 **It works!**
>
> And, it no longer deletes your content!
`;
const tree = mdast(md);

expect(tree.children[0].data.hProperties.empty).toBe(false);
expect(tree.children[0].children[0].children[1].type).toBe('strong');
});
});
4 changes: 2 additions & 2 deletions components/Callout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const Callout = (props: Props) => {
<blockquote {...attributes} className={`callout callout_${theme}`} theme={icon}>
<h3 className={`callout-heading${empty ? ' empty' : ''}`}>
<span className="callout-icon">{icon}</span>
{empty || children[0]}
{empty || React.Children.toArray(children)[0]}
</h3>
{empty ? children : React.Children.toArray(children).slice(1)}
{React.Children.toArray(children).slice(1)}
</blockquote>
);
};
Expand Down
40 changes: 24 additions & 16 deletions components/Callout/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@mixin callout ($l-offset: 1.33rem) {
@mixin callout($l-offset: 1.33rem) {
--background: #{lighten(#dfe2e5, 8.75%)};
--border: #{lighten(#6a737d, 12.5%)};

Expand All @@ -16,32 +16,37 @@
--border: #{lighten($color, 5%)}; // should be #5bc0de
}

&_warn, &_warning {
&_warn,
&_warning {
$color: #eea236;
--background: #fcf8f2;
--title: #{$color};
--border: #{lighten($color, 5%)};
}

&_ok, &_okay, &_success {
&_ok,
&_okay,
&_success {
$color: #489e49;
--background: #f3f8f3;
--title: #{$color};
--border: #{lighten($color, 5%)}; // should be #50af51
}

&_err, &_error {
&_err,
&_error {
$color: #d43f3a;
--background: #fdf7f7;
--title: #{$color};
--border: #{lighten($color, 5%)}; // should be #d9534f
--border: #{lighten($color, 5%)}; // should be #d9534f
}

> * {
margin-left: $l-offset;
position: relative;
}
ul, ol {
ul,
ol {
padding-left: 1.3em;
}

Expand All @@ -55,18 +60,20 @@
color: var(--text);
border-color: var(--border);
border-width: 3px;
padding: 0 0 0 .8em;
padding: 0 0 0 0.8em;
}

.callout-heading {
color: var(--title, --text);
margin-bottom: calc(#{$l-offset} * .5);
margin-bottom: calc(#{$l-offset} * 0.5);

&:only-child {
margin-bottom: 0;
}

&.empty {
float: left;
margin-top: calc(#{$l-offset} * .5);
margin-top: calc(#{$l-offset} * 0.5);
.callout-icon {
line-height: 0;
}
Expand All @@ -85,8 +92,8 @@
}
.callout-icon {
float: left;
margin-left: calc(-#{$l-offset} - .5em);
margin-right: -.25rem;
margin-left: calc(-#{$l-offset} - 0.5em);
margin-right: -0.25rem;
}
}
@mixin calloutCustomIcons($R: callout) {
Expand All @@ -113,19 +120,19 @@
--emoji: unset;
&_okay {
/* thumbs up */
--icon: "\f164";
--icon: '\f164';
}
&_info {
/* info circle */
--icon: "\f05a";
--icon: '\f05a';
}
&_warn {
/* warning triangle */
--icon: "\f071";
--icon: '\f071';
}
&_error {
/* warning circle */
--icon: "\f06a";
--icon: '\f06a';
}
&_default {
/* warning circle */
Expand All @@ -135,7 +142,8 @@
}

.callout {
&.callout { // bump specificity
&.callout {
// bump specificity
@include callout;
}
@include calloutCustomIcons;
Expand Down
6 changes: 6 additions & 0 deletions docs/callout-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ Now with MDX

Much _wow_
</Callout>

>
>
> Does it still look good?!
> ❔ Does _this_ look good?!
Loading

0 comments on commit 463b870

Please sign in to comment.