8000 Column styling, and rounded corners per viewport in the kit by Klehm · Pull Request #104 · Klehm/content-blocks-project · GitHub
[go: up one dir, main page]

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
3 changes: 2 additions & 1 deletion CLAUDE.md

Large diffs are not rendered by default.

42 changes: 35 additions & 7 deletions apps/content-blocks-sandbox/src/Ai/DemoAiProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function generateContent(ContentRequest $request): array
$this->hero($subject, $types, $layouts),
$this->features($types, $layouts),
$this->faq($types),
$this->closing($subject, $types),
$this->closing($subject, $types, $request->schema->schema, $request->schema->palette),
];

return ['sections' => \array_slice(array_values(array_filter($sections)), 0, $request->maxSections)];
Expand Down Expand Up @@ -163,16 +163,44 @@ private function faq(array $types): ?array
}

/**
* @param list<string> $types
* Two columns when the schema lets a column be styled: the pitch on a
* light, rounded panel, the button beside it, centred.
*
* @param list<string> $types
* @param array<string, mixed> $schema
* @param list<array<string, mixed>> $palette
*
* @return array<string, mixed>
*/
private function closing(string $subject, array $types): array
private function closing(string $subject, array $types, array $schema, array $palette): array
{
return self::section('full', [], [[
self::block($types, 'title', ['text' => 'Ready? ' . $subject, 'size' => 'h2', 'tag' => 'h2']),
self::block($types, 'button', ['text' => 'Buy now', 'url' => '/buy', 'variant' => 'primary', 'size' => 'lg']),
]]);
$title = self::block($types, 'title', ['text' => 'Ready? ' . $subject, 'size' => 'h2', 'tag' => 'h2']);
$button = self::block($types, 'button', ['text' => 'Buy now', 'url' => '/buy', 'variant' => 'primary', 'size' => 'lg']);
if (!isset($schema['$defs']['columnStyling'])) {
return self::section('full', [], [[$title, $button]]);
}

$light = '#f1f5f9';
foreach ($palette as $color) {
if (($color['tone'] ?? null) === 'light' && preg_match('/^#[0-9a-f]{6}$/i', (string) ($color['color'] ?? '')) === 1) {
$light = $color['color'];
break;
}
}
$pad = static fn (int $px): array => ['top' => $px, 'right' => $px, 'bottom' => $px, 'left' => $px, 'linked' => true];

$section = self::section('full', [], [[$title], [$button]]);
$section['layout'] = 'two_cols';
$section['columns'][0]['preset'] = 'col-8';
$section['columns'][0]['settings'] = ['styling' => [
'padding' => ['desktop' => $pad(40), 'mobile' => $pad(24)],
'backgroundColor' => $light,
'borderRadius' => ['desktop' => $pad(16), 'mobile' => $pad(12)],
]];
$section['columns'][1]['preset'] = 'col-4';
$section['columns'][1]['settings'] = ['styling' => ['verticalAlign' => 'center']];

return $section;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions docs/.vitepress/data/blocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@
"newTab": false,
"caption": "",
"borderRadius": {
"linked": true
"desktop": {
"linked": true
}
}
}
},
Expand Down Expand Up @@ -168,7 +170,9 @@
"columns": 3,
"fit": "cover",
"borderRadius": {
"linked": true
"desktop": {
"linked": true
}
},
"items": [
{
Expand Down
2 changes: 2 additions & 0 deletions docs/guide/content-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ No model and no vendor SDK ship with the package: the schema is what you hand to

The JSON Schema of each block's `data` is **derived from the block's own form**, the same form that validates the data when an editor saves it. Field types, the values a choice offers, `Length`, `Count` and `Range` limits, collections and their entries, labels and help texts all come from there. A host's block form extensions and the block styling fields come along. When you change a form, the schema changes with it.

Section settings come from the section form, and a column's `settings.styling` from the fields of the sidebar's *Columns style* tab ([styling a column](./styling.md#styling-a-column)). A column keeps only the core styling keys, so a host's `StylingType` extension shows up in the section's styling, never in a column's. Column styling is left out of the schema wherever the tab is hidden: `styling.section: false`, `structure.columns: false`, or `sections: hidden`.

The schema still guides the model; it does not vouch for what comes back. Generated content goes back in through the paste path, which replays each block through its form: an undeclared key is dropped, and a refused value falls back to the type's default. From the builder that is the **Generate** button; from a pipeline it is `content-blocks:ai:apply`. See [AI actions](./ai.md).

## Block purposes
Expand Down
4 changes: 3 additions & 1 deletion docs/guide/headless.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ With `klehm/content-blocks-i18n` installed, the locale works exactly as on the H
"span": 6,
"width": null,
"label": "Overview",
"styling": null,
"blocks": [
{
"id": 133,
Expand Down Expand Up @@ -112,14 +113,15 @@ With `klehm/content-blocks-i18n` installed, the locale works exactly as on the H
| `sections[].settings` | The settings the HTML render reads: the style preset merged underneath, values equal to their default left out. |
| `columns[].span` | The width on the 12-unit grid, from `preset`. `width` is the custom weight from the *Column widths* field, `null` for equal widths. |
| `columns[].label` | The column's title, shown by the tabs and accordion displays. |
| `columns[].styling` | The column's own [styling](./styling.md#styling-a-column) as stored (padding, background, radius, vertical alignment), `null` when it has none. |
| `blocks[].data` | The block's data, after the [data resolvers](./rendering.md#changing-what-a-block-renders) and the [block normalizers](#what-a-block-sends). |
| `order` | The position on tablet / mobile among siblings when an editor reordered them for that viewport. `null` means the desktop order. |

The order is the order of the arrays. Soft-deleted sections, columns and blocks are left out of the preview, as with `cb_chrome=0`.

Collection entries keep their `_id`, stable across edits, so a client can use it as a key. With `fallback_lang` on, the i18n package's `_lang` / `_block_lang` markers are in `data` too ([Translation](./translation.md)).

There is no class name, inline style or markup anywhere: presentation is the client's. The [kit's tokens](../kit/#the-kits-own-tokens) and the values in `settings.styling` are what you style from.
There is no class name, inline style or markup anywhere: presentation is the client's. The [kit's tokens](../kit/#the-kits-own-tokens), the values in `settings.styling` and `columns[].styling` are what you style from.

## What a block sends

Expand Down
40 changes: 40 additions & 0 deletions docs/guide/styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,46 @@ The tone class follows the veil: from 40% opacity the section is
`cb-section--bg-dark` or `-light` after the veil's colour. Under a fainter veil
the photo decides, so no tone class is set.

## Styling a column

The section sidebar has a **Columns style** tab with one panel per column:
padding (per viewport), background colour, background image (with size,
position and veil, as for a section), rounded corners and vertical alignment
of the column's content. A column with none of these set renders exactly as
before.

Rounded corners are set per corner and per viewport, like padding per side,
with the same ⛓ link to set all four at once. Each viewport holds
`{top, right, bottom, left, linked}` in `border-radius` order (`top` is the
top-left corner, `right` the top-right one), the shape of the kit's image
radius, capped at 200px. A corner left empty on tablet or mobile keeps the
wider viewport's value, and the page only gets `--cb-c-radius-t` /
`--cb-c-radius-m` where they differ.

A styled column gets `cb-col--styled` (plus `cb-col--bg-image` and a tone
class `cb-col--bg-dark` / `-light`, under the same rules as a section) and its
blocks move into a wrapper, which carries the padding and the background:

```html
<div class="cb-col cb-col--col-6 cb-col--styled cb-col--bg-dark" style="--cb-c-bg:#1e293b;…">
<div class="cb-col__inner">
<div class="cb-block">…</div>
</div>
</div>
```

The wrapper is there because a column's width comes from `flex-grow`: padding
on the column itself would make it wider than its neighbours. If your
stylesheet reaches blocks with `.cb-col > .cb-block`, write
`.cb-col .cb-block` instead, or it will miss the blocks of a styled column.

The background image goes through your `ImageUrlResolverInterface` at the
column's share of 1920px (never under 800px). Export/import and
`content-blocks:assets:gc` treat it like a section's.

The tab is hidden when section styling is off (`styling: false` or
`styling: { section: false }`) and when `structure.columns` is `false`.

## Text alignment and max width of a block

A block's **Style** tab has three layout fields besides spacing and colour:
Expand Down
4 changes: 3 additions & 1 deletion docs/internals/content-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ Keys a type declares in `getDefaultData()` without a field are added, typed from

The document has a vocabulary (`layouts`, `palette`, `sectionStyles`, `blocks`, `examples`) and a pure JSON Schema (`schema`). Keeping them apart keeps the JSON Schema free of non-standard keywords: providers' structured-output modes reject keywords they do not know, and the vocabulary is prose a model reads, not constraints it is held to.

Shared subtrees are written once under `$defs` (`blockStyling`, `sectionSettings`), so the 19 kit blocks do not each repeat 2 KB of spacing fields. The block union is a `oneOf` on `type` (`const`), one `$defs` entry per type.
Shared subtrees are written once under `$defs` (`blockStyling`, `sectionSettings`, `columnStyling`), so the 19 kit blocks do not each repeat 2 KB of spacing fields, nor the columns of a section their styling.

`columnStyling` is mapped from a `StylingType` built with `ColumnStylesType::STYLING_OPTIONS` and pruned by `ColumnStylesType::keepColumnFields()`, the same two steps as the sidebar tab. Without the pruning, a host extension sniffing `include_background_image` (the sandbox's ornaments) would add fields that `ColumnSettings::sanitize()` drops on the way in: the schema would offer what is silently lost. `sanitize()` accepts a whole float (`40.0`) as an integer, since that is how some JSON writers say 40. The block union is a `oneOf` on `type` (`const`), one `$defs` entry per type.

## Examples from the section library

Expand Down
18 changes: 18 additions & 0 deletions docs/internals/kit.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,21 @@ effect. For the same reason, overridden fields are named explicitly rather than
left to be inferred.

Long choice lists (the icon set) are truncated in the table to stay readable.

## A radius per viewport

The image and gallery `borderRadius` is a `ResponsiveBoxSpacingType` with
`corners: true`: four corners per viewport, in `border-radius` order (`top` is
the top-left corner). `CornerRadius::values()` resolves it for the views, a
corner left empty inheriting the wider viewport's, a viewport with nothing set
left out so the stylesheet default stands (the gallery's 6px). The kit's own
breakpoints apply (768 / 540, those of the image height per viewport).

Data stored before had one set of corners, `{top, right, bottom, left}`. It is
read as the desktop value everywhere, with no migration: by the form (a model
transformer, `AbstractKitBlock::readOlderRadius()`, so opening the block or
pasting it keeps the radius), by the views and by `KitJsonNormalizer`, which
hands a client the per-viewport shape whatever the block's age. A desktop-only
image radius still renders as the inline `border-radius` it always did; only a
value that changes with the viewport goes through `--cb-kit-img-r(-t|-m)` and
the `cb-kit-image__img--vp-radius` class.
71 changes: 71 additions & 0 deletions docs/internals/rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,77 @@ those columns are still there, so switching an accordion to tabs keeps the open
panel as the open tab, and a rename or a display toggle updates in place. Adding or removing a column changes the row itself, so it
reloads the preview and remounts the sidebar.

## Column styling

A column can have its own padding, background (colour, image, veil), rounded
corners and vertical alignment. Spacing and colour used to stop at the section,
so a coloured "card" next to a plain column meant a custom block.

**Stored beside the label, under `styling`**, in the column's
`draft_settings`, so the publish twin, Discard, undo, cloning, the clipboard,
templates and import all carry it with no new column or migration.
`ColumnSettings::sanitize()` is the gate, since those payloads come from
outside: known keys only (`ColumnSettings::STYLING_KEYS`), scalars or the
spacing box's arrays, everything else dropped. `borderRadius` is a
`ResponsiveBoxSpacingType` with `corners: true` (corner labels, `max` 200),
each viewport stored `{top, right, bottom, left}` in `border-radius` order like
the kit's image. The decorator resolves the inheritance per corner itself and
writes one shorthand per viewport (`--cb-c-radius`, `-t`, `-m`), a repeat left
out: per-corner variables would be twelve fallback chains for a value that
rarely changes. A bare number or one set of corners, the shapes it had earlier
on this branch, reads as the desktop value. The decorator re-checks every
value at render time, as the section one does.

**Edited from the section sidebar, not by selecting a column.** A column is not
a selection target in the preview: making it one would mean a new sidebar kind,
a click arbitration with the blocks inside it, a clipboard scope and a tree
node that edits. The section sidebar gets a *Columns style* tab with one panel
per live column. The fields belong to the section form (`columnStyles`, keyed
`c{id}`), so a change goes through the section's own save: one request, one
undo step covering the section and its columns
(`JournalScope::sectionAndColumns()`), and the section's preview markup comes
back with it, which matters for the next point. `SectionSidebarController`
strips `columnStyles` from the section's settings and writes each column's.
The tab follows the section's styling switch (`styling.section`) and
`structure.columns`.

**Padding cannot sit on `.cb-col`.** Columns are `flex: N 1 0` (see
[Column presets are spans](#column-presets-are-spans)): with a zero basis, a
column's padding is added on top of its share of the row, so a `col-6` with
40px each side ends 80px wider than its `col-6` neighbour. A styled column
therefore renders its blocks inside a `.cb-col__inner` wrapper, which carries
the padding, background, radius and veil, and fills the column's height (it
is a flex child of a flex column).

**Only a styled column gets the wrapper.** An unstyled one is byte for byte
what it was, so a host selector like `.cb-col > .cb-block` keeps working on
every page that does not use the feature, and both immutability nets stay put.
The cost is two shapes of column, and it falls on code that walks into one:

- CSS: the inner is a flex column too (so a block's `alignSelf` still
works), and the order-per-viewport rule covers `.cb-col__inner > .cb-block`.
- The overlay puts a block into `blockContainer(column)` (the inner when there
is one) when it inserts or moves one into a column.
- `patchSection` adds or removes the wrapper around the column's existing
children when a save styles or un-styles a column, rather than reloading.

The variables are set on `.cb-col` (`--cb-c-*`, namespaced so blocks never
inherit them) and read by the inner; the classes `cb-col--styled`,
`cb-col--bg-image` and the tone `cb-col--bg-dark|light` go on `.cb-col` too,
so a host targets the column it already knows.

**The image is resolved at the column's width.** The background-image logic
(resolver, `url("…")` escaping, scheme check, size/position whitelists, veil,
tone from a veil of 40% or more) moved out of `StylingSectionDecorator` into
`BackgroundImage`, shared by both decorators. A section asks the resolver for
1920px; a column asks for its span's share of that, never under 800px, since
a column stacks to the full width on a phone.

**A column's image is an asset like any other.** `ContentAreaAssetReferenceProvider`
reads column settings, so `assets:gc` keeps the file; the exporter tokenizes
column settings like section ones, and the import rewrites them. Before this,
column settings only held a label, and neither had a reason to look.

## Section tabs

*Spike — the rules below are what the prototype does, not settled design.*
Expand Down
2 changes: 1 addition & 1 deletion docs/kit/blocks/gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Initial values for a new block. Override per host with `defaults:`.
| `layout` | `grid` |
| `columns` | `3` |
| `fit` | `cover` |
| `borderRadius` | `{"linked":true}` |
| `borderRadius` | `{"desktop":{"linked":true}}` |
| `items` | `[{"src":"","alt":"","caption":"","url":"","newTab":false}]` |

#### Example
Expand Down
2 changes: 1 addition & 1 deletion docs/kit/blocks/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Initial values for a new block. Override per host with `defaults:`.
| `url` | `''` |
| `newTab` | `false` |
| `caption` | `''` |
| `borderRadius` | `{"linked":true}` |
| `borderRadius` | `{"desktop":{"linked":true}}` |

#### Example

Expand Down
11 changes: 11 additions & 0 deletions packages/content-blocks-kit/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- **Rounded corners per viewport** on the image and the gallery: the field has
the desktop / tablet / mobile tabs of a padding, a corner left empty keeping
the wider viewport's value (kit breakpoints, 768 / 540). Each corner is
labelled as one (↖ ↗ ↘ ↙) rather than Top / Right / Bottom / Left, given a
core with the `corners` option of `BoxSpacingType` (an older one keeps the
side labels). `borderRadius` is now `{desktop, tablet, mobile}`, each
`{top, right, bottom, left, linked}`; a radius stored before, one set of
corners, reads as the desktop one in the form, the views and the headless
JSON (which always hands out the new shape), with no migration. A
desktop-only image radius renders as before.

- **Open in a new tab** on a card's button, a gallery image's link and the
image block's link (`newTab`), as the button blocks already had.
- **An image's height per screen.** With a fixed custom height, *Height on
Expand Down
14 changes: 14 additions & 0 deletions packages/content-blocks-kit/assets/styles/kit.css
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,19 @@
.cb-kit-image--size-full .cb-kit-image__img { width: 100%; }
/* Heights per viewport, written as variables by the view. */
.cb-kit-image__img--vp-height { height: var(--cb-kit-img-h); }
/* Corners per viewport, same breakpoints; a desktop-only radius is inline. */
.cb-kit-image__img--vp-radius { border-radius: var(--cb-kit-img-r, 0); }
@media (max-width: 768px) {
.cb-kit-image__img--vp-height { height: var(--cb-kit-img-h-t, var(--cb-kit-img-h)); }
.cb-kit-image__img--vp-radius { border-radius: var(--cb-kit-img-r-t, var(--cb-kit-img-r, 0)); }
}
@media (max-width: 540px) {
.cb-kit-image__img--vp-height {
height: var(--cb-kit-img-h-m, var(--cb-kit-img-h-t, var(--cb-kit-img-h)));
}
.cb-kit-image__img--vp-radius {
border-radius: var(--cb-kit-img-r-m, var(--cb-kit-img-r-t, var(--cb-kit-img-r, 0)));
}
}
.cb-kit-image__caption { margin-top: .4rem; font-size: .875rem; color: #6b7280; }
.cb-kit-muted { color: #6b7280; }
Expand All @@ -236,6 +242,14 @@
.cb-kit-gallery { --cb-kit-cols: 3; --cb-kit-fit: cover; }
.cb-kit-gallery__item { margin: 0; }
.cb-kit-gallery__img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: var(--cb-kit-fit, cover); border-radius: var(--cb-kit-radius, 6px); }
@media (max-width: 768px) {
.cb-kit-gallery__img { border-radius: var(--cb-kit-radius-t, var(--cb-kit-radius, 6px)); }
}
@media (max-width: 540px) {
.cb-kit-gallery__img {
border-radius: var(--cb-kit-radius-m, var(--cb-kit-radius-t, var(--cb-kit-radius, 6px)));
}
}
.cb-kit-gallery__caption { margin-top: .35rem; text-align: center; font-size: .85rem; color: #6b7280; }
.cb-kit-gallery--grid { display: grid; gap: 1rem; grid-template-columns: repeat(var(--cb-kit-cols, 3), minmax(0, 1fr)); }
@media (max-width: 640px) { .cb-kit-gallery--grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
Expand Down
Loading
0