Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/stupid-walls-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudfour/patterns': minor
---

Add support for Jetpack Markdown Block
5 changes: 5 additions & 0 deletions .changeset/tender-wasps-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudfour/patterns': minor
---

Use custom properties for Rhythm spacing to support inheritance
29 changes: 29 additions & 0 deletions src/mixins/_spacing.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@use "../compiled/tokens/scss/size";

/// Applies styles for a vertical rhythm layout object. Used by the `o-rhythm`
/// pattern and for relevant Gutenberg blocks. Makes heavy use of Heydon
/// Pickering's "lobotomized owl" selectors: By adding `margin-top` to adjacent
/// elements, we avoid impacting the layout of the container itself (which would
/// complicate alignment of adjacent columns).
/// @link https://alistapart.com/article/axiomatic-css-and-lobotomized-owls/
/// @param {Number} $space - The default space between.
@mixin vertical-rhythm($space: size.$rhythm-default) {
& > * + * {
margin-top: $space;
// Allow space to be overridden using custom properties
margin-top: var(--rhythm);
}

// Where custom properties are supported, also allow headings to receive their
// own rhythm.
@supports (--custom: properties) {
& > * + h1,
& > * + h2,
& > * + h3,
& > * + h4,
& > * + h5,
& > * + h6 {
margin-top: var(--rhythm-headings);
}
}
}
48 changes: 17 additions & 31 deletions src/objects/rhythm/rhythm.scss
Original file line number Diff line number Diff line change
@@ -1,45 +1,31 @@
@use "../../compiled/tokens/scss/size";
@use "../../mixins/spacing";

/**
* This pattern makes heavy use of Heydon Pickering's "lobotomized owl"
* selectors. By adding `margin-top` to adjacent elements, we avoid impacting
* the layout of the container itself (which would complicate alignment of
* adjacent columns).
*
* @see https://alistapart.com/article/axiomatic-css-and-lobotomized-owls/
*/

.o-rhythm > * + * {
margin-top: size.$rhythm-default;
:root {
--rhythm: #{size.$rhythm-default};
--rhythm-headings: var(--rhythm);
}

/**
* General spacing modifiers
*/
.o-rhythm {
@include spacing.vertical-rhythm(size.$rhythm-default);
}

// General spacing modifiers

.o-rhythm--compact > * + * {
margin-top: size.$rhythm-compact;
.o-rhythm--compact {
--rhythm: #{size.$rhythm-compact};
}

.o-rhythm--condensed > * + * {
margin-top: size.$rhythm-condensed;
.o-rhythm--condensed {
--rhythm: #{size.$rhythm-condensed};
}

.o-rhythm--generous > * + * {
margin-top: size.$rhythm-generous;
.o-rhythm--generous {
--rhythm: #{size.$rhythm-generous};
}

/**
* Heading modifiers
*/
// Heading modifiers

.o-rhythm--generous-headings {
& > * + h1,
& > * + h2,
& > * + h3,
& > * + h4,
& > * + h5,
& > * + h6 {
margin-top: size.$rhythm-generous;
}
--rhythm-headings: #{size.$rhythm-generous};
}
35 changes: 35 additions & 0 deletions src/objects/rhythm/rhythm.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,38 @@ behave as expected.
{articleDemo}
</Story>
</Canvas>

## Inheriting Rhythm

The vertical spacing applied by the Rhythm object only applies to direct children. In some cases, you may want elements below to inherit rhythm. This can be accomplished in two main ways.

### Via HTML

If you have access to the markup, you can add the `o-rhythm` class to the child element:

```html
<div class="o-rhythm o-rhythm--condensed">
<!-- ... -->
<div class="o-rhythm">
<!-- will also be condensed -->
</div>
<!-- ... -->
</div>
```

### Via Sass

Our project includes a `spacing.vertical-rhythm` mixin that will apply the basic object rules to any selector:

```scss
@use 'path/to/mixins/spacing';

.unchangeable-vendor-selector {
@include spacing.vertical-rhythm();
}
```

## Custom Properties

- `--rhythm`: Amount of vertical space between adjacent elements. Defaults to our `$rhythm-default` [size token](/docs/design-tokens-size--page#rhythm).
- `--rhythm-headings`: Extra space to precede headings that follow another element. Defaults to the value of `--rhythm`.
1 change: 1 addition & 0 deletions src/vendor/wordpress/_wordpress.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@use 'styles/core-blocks';
@use 'styles/jetpack-blocks';
@use 'styles/utilities';
29 changes: 29 additions & 0 deletions src/vendor/wordpress/jetpack-blocks.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Story, Canvas, Meta } from '@storybook/addon-docs/blocks';

<Meta title="Vendor/WordPress/Jetpack Blocks" />

# Jetpack Blocks

WordPress developer Automattic provides a [Jetpack](https://jetpack.com/) plugin that includes additional blocks. We support a selection of these.

## Markdown Block

The markdown block applies vertical rhythm between its children. If contained within a [Rhythm object](/docs/objects-rhythm--default-story), the markdown block will inherit the same spacing. For example, if the Rhythm object uses the `o-rhythm--generous` modifier, the markdown block will inherit the generous spacing.

See also: [Markdown Block documentation](https://jetpack.com/support/markdown/)

<Canvas>
<Story name="Markdown">
{`<div class="wp-block-jetpack-markdown">
<p>
<b>Lorem</b> <i>ipsum</i> dolor sit amet, consectetur adipiscing elit. Quisque eu ex
enim. Nunc efficitur scelerisque dolor et sollicitudin.
</p>
<p>
Donec finibus lorem elit, eu consectetur quam pellentesque sed.
Pellentesque habitant morbi tristique senectus et netus et malesuada
fames ac turpis egestas.
</p>
</div>`}
</Story>
</Canvas>
5 changes: 5 additions & 0 deletions src/vendor/wordpress/styles/_jetpack-blocks.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@use '../../../mixins/spacing';

.wp-block-jetpack-markdown {
@include spacing.vertical-rhythm();
}