diff --git a/shared/properties/i18n/messages/de/style.ts b/shared/properties/i18n/messages/de/style.ts index 5911b9e00..903b14b35 100644 --- a/shared/properties/i18n/messages/de/style.ts +++ b/shared/properties/i18n/messages/de/style.ts @@ -391,6 +391,7 @@ export const messages = { 'style.gridControls.gridColumns': 'Grid-Spalten', // review 'style.gridControls.gridRows': 'Grid-Zeilen', // review 'style.gridControls.rows': 'Zeilen', + 'style.gridControls.subgrid': 'Subgrid', // same 'style.gridFlowControls.autoFlow': 'Grid-Auto-Flow', // review 'style.gridFlowControls.autoFlowPlaceholder': 'z. B. row dense', 'style.gridFlowControls.custom': 'Benutzerdefiniert', @@ -439,6 +440,12 @@ export const messages = { 'style.gridSettings.repeatColumns': 'repeat() für Spalten verwenden', 'style.gridSettings.repeatRows': 'repeat() für Zeilen verwenden', 'style.gridSettings.rows': 'Zeilen', + 'style.gridSettings.subgridColumns': 'subgrid für Spalten verwenden', // review + 'style.gridSettings.subgridOff': + 'Diese Tracks vom übergeordneten Grid übernehmen. Dafür braucht es ein übergeordnetes Grid, dessen Tracks dieses Element überspannt.', // review + 'style.gridSettings.subgridOn': + 'Diese Tracks kommen vom übergeordneten Grid. Dafür braucht es ein übergeordnetes Grid, dessen Tracks dieses Element überspannt.', // review + 'style.gridSettings.subgridRows': 'subgrid für Zeilen verwenden', // review 'style.gridSettings.writeAsRepeat': 'Diese Tracks als repeat() schreiben', 'style.gridSettings.writtenAsRepeat': 'Geschrieben als repeat({tracks}, …)', 'style.layerList.dragToReorder': 'Zum Sortieren ziehen', diff --git a/shared/properties/i18n/messages/en/style.ts b/shared/properties/i18n/messages/en/style.ts index aaa13c2ac..2fdf23ea6 100644 --- a/shared/properties/i18n/messages/en/style.ts +++ b/shared/properties/i18n/messages/en/style.ts @@ -386,6 +386,7 @@ export const messages = { 'style.gridControls.gridColumns': 'Grid columns', 'style.gridControls.gridRows': 'Grid rows', 'style.gridControls.rows': 'Rows', + 'style.gridControls.subgrid': 'Subgrid', 'style.gridFlowControls.autoFlow': 'Grid auto flow', 'style.gridFlowControls.autoFlowPlaceholder': 'e.g. row dense', 'style.gridFlowControls.custom': 'Custom', @@ -434,6 +435,10 @@ export const messages = { 'style.gridSettings.repeatColumns': 'Use repeat() for columns', 'style.gridSettings.repeatRows': 'Use repeat() for rows', 'style.gridSettings.rows': 'Rows', + 'style.gridSettings.subgridColumns': 'Use subgrid for columns', + 'style.gridSettings.subgridOff': 'Take these tracks from the parent grid. It needs a grid parent, with this element spanning its tracks.', + 'style.gridSettings.subgridOn': 'These tracks come from the parent grid. It needs a grid parent, with this element spanning its tracks.', + 'style.gridSettings.subgridRows': 'Use subgrid for rows', 'style.gridSettings.writeAsRepeat': 'Write these tracks as repeat()', 'style.gridSettings.writtenAsRepeat': 'Written as repeat({tracks}, …)', 'style.layerList.dragToReorder': 'Drag to reorder', diff --git a/shared/properties/i18n/messages/es/style.ts b/shared/properties/i18n/messages/es/style.ts index 2b08fb57a..35424395c 100644 --- a/shared/properties/i18n/messages/es/style.ts +++ b/shared/properties/i18n/messages/es/style.ts @@ -390,6 +390,7 @@ export const messages = { 'style.gridControls.gridColumns': 'Columnas del grid', // review 'style.gridControls.gridRows': 'Filas del grid', // review 'style.gridControls.rows': 'Filas', + 'style.gridControls.subgrid': 'Subgrid', // same 'style.gridFlowControls.autoFlow': 'Flujo automático del grid', // review 'style.gridFlowControls.autoFlowPlaceholder': 'p. ej. row dense', 'style.gridFlowControls.custom': 'Personalizado', @@ -438,6 +439,10 @@ export const messages = { 'style.gridSettings.repeatColumns': 'Usar repeat() para las columnas', 'style.gridSettings.repeatRows': 'Usar repeat() para las filas', 'style.gridSettings.rows': 'Filas', + 'style.gridSettings.subgridColumns': 'Usar subgrid para las columnas', // review + 'style.gridSettings.subgridOff': 'Tomar estos tracks del grid padre. Necesita un grid padre, con este elemento abarcando sus tracks.', // review + 'style.gridSettings.subgridOn': 'Estos tracks vienen del grid padre. Necesita un grid padre, con este elemento abarcando sus tracks.', // review + 'style.gridSettings.subgridRows': 'Usar subgrid para las filas', // review 'style.gridSettings.writeAsRepeat': 'Escribir estos tracks como repeat()', 'style.gridSettings.writtenAsRepeat': 'Escrito como repeat({tracks}, …)', 'style.layerList.dragToReorder': 'Arrastra para reordenar', diff --git a/shared/properties/i18n/messages/fr/style.ts b/shared/properties/i18n/messages/fr/style.ts index 7936220c8..475179761 100644 --- a/shared/properties/i18n/messages/fr/style.ts +++ b/shared/properties/i18n/messages/fr/style.ts @@ -392,6 +392,7 @@ export const messages = { 'style.gridControls.gridColumns': 'Colonnes de la grille', // review 'style.gridControls.gridRows': 'Lignes de la grille', // review 'style.gridControls.rows': 'Lignes', + 'style.gridControls.subgrid': 'Subgrid', // same 'style.gridFlowControls.autoFlow': 'Flux automatique de la grille', // review 'style.gridFlowControls.autoFlowPlaceholder': 'p. ex. row dense', 'style.gridFlowControls.custom': 'Personnalisé', @@ -440,6 +441,10 @@ export const messages = { 'style.gridSettings.repeatColumns': 'Utiliser repeat() pour les colonnes', 'style.gridSettings.repeatRows': 'Utiliser repeat() pour les lignes', 'style.gridSettings.rows': 'Lignes', + 'style.gridSettings.subgridColumns': 'Utiliser subgrid pour les colonnes', // review + 'style.gridSettings.subgridOff': 'Prendre ces pistes dans la grille parente. Il faut une grille parente, que cet élément couvre sur ses pistes.', // review + 'style.gridSettings.subgridOn': 'Ces pistes viennent de la grille parente. Il faut une grille parente, que cet élément couvre sur ses pistes.', // review + 'style.gridSettings.subgridRows': 'Utiliser subgrid pour les lignes', // review 'style.gridSettings.writeAsRepeat': 'Écrire ces pistes avec repeat()', 'style.gridSettings.writtenAsRepeat': 'Écrit sous la forme repeat({tracks}, …)', 'style.layerList.dragToReorder': 'Faites glisser pour réordonner', diff --git a/shared/properties/i18n/messages/ptBR/style.ts b/shared/properties/i18n/messages/ptBR/style.ts index 71253eb32..630c9446e 100644 --- a/shared/properties/i18n/messages/ptBR/style.ts +++ b/shared/properties/i18n/messages/ptBR/style.ts @@ -390,6 +390,7 @@ export const messages = { 'style.gridControls.gridColumns': 'Colunas do grid', // review 'style.gridControls.gridRows': 'Linhas do grid', // review 'style.gridControls.rows': 'Linhas', + 'style.gridControls.subgrid': 'Subgrid', // same 'style.gridFlowControls.autoFlow': 'Fluxo automático do grid', // review 'style.gridFlowControls.autoFlowPlaceholder': 'ex.: row dense', 'style.gridFlowControls.custom': 'Personalizado', @@ -438,6 +439,10 @@ export const messages = { 'style.gridSettings.repeatColumns': 'Usar repeat() para as colunas', 'style.gridSettings.repeatRows': 'Usar repeat() para as linhas', 'style.gridSettings.rows': 'Linhas', + 'style.gridSettings.subgridColumns': 'Usar subgrid para as colunas', // review + 'style.gridSettings.subgridOff': 'Pegar estes tracks do grid pai. Precisa de um grid pai, com este elemento ocupando os tracks dele.', // review + 'style.gridSettings.subgridOn': 'Estes tracks vêm do grid pai. Precisa de um grid pai, com este elemento ocupando os tracks dele.', // review + 'style.gridSettings.subgridRows': 'Usar subgrid para as linhas', // review 'style.gridSettings.writeAsRepeat': 'Escrever estes tracks como repeat()', 'style.gridSettings.writtenAsRepeat': 'Escrito como repeat({tracks}, …)', 'style.layerList.dragToReorder': 'Arraste para reordenar', diff --git a/src/features/style/GridControls.tsx b/src/features/style/GridControls.tsx index 8603ff3cd..4dcf5db18 100644 --- a/src/features/style/GridControls.tsx +++ b/src/features/style/GridControls.tsx @@ -12,6 +12,7 @@ import type { ResolvedProp } from './model/resolved'; import { useHighlight } from './model/computedStyle'; import { commitInPlace } from './model/commitInPlace'; import { countTracks, NEW_COLUMN, NEW_ROW, repeatTracks, isUniformTracks } from './gridTracks'; +import { heldTrackCount, type HeldTrackCount } from './model/gridTemplate'; import { GRID_ITEM_ALIGN, gridKeyword, GridAlignIcon, X_ALIGN_ICONS, Y_ALIGN_ICONS, xAlignLabels, yAlignLabels, cap, CustomizeIcon } from './GridIcons'; import { GridDirectionControl, GridContentControl, CountField } from './GridFlowControls'; import { displayOf, displayText, parseImportant } from './model/styleDisplay'; @@ -266,6 +267,22 @@ function writeText(setProp: SetProp, prop: string, text: string): void { setProp(prop, parsed.value, parsed.important); } +// The text a held Columns or Rows count shows in place of a number. +function heldCountLabel(held: HeldTrackCount | undefined, translate: Translator): string | undefined { + switch (held) { + case undefined: + return undefined; + case 'subgrid': + return translate('style.gridControls.subgrid'); + case 'custom': + return translate('style.gridControls.custom'); + default: { + const exhaustive: never = held; + return exhaustive; + } + } +} + function resolvedValue(read: Read, prop: string): string { const resolved = read(prop); if (!resolved) { @@ -327,9 +344,14 @@ function GridTracksRow({ props, onConfigure }: { props: GridControlsProps; onCon }; const columnsRaw = resolvedValue(read, 'grid-template-columns'); const rowsRaw = resolvedValue(read, 'grid-template-rows'); + // A value with no count (subgrid, a variable for the list or its count, a keyword) + // holds its counter, and the grid settings edit it as an expression. + const columnsHeld = heldCountLabel(heldTrackCount(columnsRaw), translate); + const rowsHeld = heldCountLabel(heldTrackCount(rowsRaw), translate); // The gear lights up when a track list isn't just N equal tracks — those can't be // represented as a count, so per-track sizing / reordering lives in the modal. - const customTracks = (!!columnsRaw && !isUniformTracks(columnsRaw)) || (!!rowsRaw && !isUniformTracks(rowsRaw)); + const customTracks = + columnsHeld !== undefined || rowsHeld !== undefined || (!!columnsRaw && !isUniformTracks(columnsRaw)) || (!!rowsRaw && !isUniformTracks(rowsRaw)); return (
setProp('grid-template-columns', repeatTracks(count, NEW_COLUMN), false)} @@ -358,6 +382,8 @@ function GridTracksRow({ props, onConfigure }: { props: GridControlsProps; onCon
setProp('grid-template-rows', repeatTracks(count, NEW_ROW), false)} diff --git a/src/features/style/GridFlowControls.tsx b/src/features/style/GridFlowControls.tsx index 2a192295d..02a9231b7 100644 --- a/src/features/style/GridFlowControls.tsx +++ b/src/features/style/GridFlowControls.tsx @@ -297,7 +297,36 @@ export function ContentPresetItems({ pickPreset }: { pickPreset: (option: string export const clampCount = (count: number) => Math.min(500, Math.max(1, count)); // A whole-number track-count field with ▲▼ steppers (Webflow's Columns/Rows inputs). -export function CountField({ value, busy, ariaLabel, onCommit }: { value: number; busy: boolean; ariaLabel: string; onCommit: (n: number) => void }) { +// `held` is shown in place of a count the value does not have (heldTrackCount): +// the field cannot be typed in or stepped, so no count overwrites the value, and +// the full value is its tooltip. +export function CountField({ + value, + held, + title, + busy, + ariaLabel, + onCommit, +}: { + value: number; + held?: string | undefined; + title?: string | undefined; + busy: boolean; + ariaLabel: string; + onCommit: (n: number) => void; +}) { + if (held !== undefined) { + return ( +
+ + undefined} /> +
+ ); + } + return ; +} + +function CountInput({ value, busy, ariaLabel, onCommit }: { value: number; busy: boolean; ariaLabel: string; onCommit: (n: number) => void }) { const [text, setText] = useState(value > 0 ? String(value) : ''); const focused = useRef(false); useEffect(() => { diff --git a/src/features/style/GridSettings.tsx b/src/features/style/GridSettings.tsx index 1c35e7899..ad582f920 100644 --- a/src/features/style/GridSettings.tsx +++ b/src/features/style/GridSettings.tsx @@ -164,6 +164,51 @@ function RepeatSwitch({ ); } +// The subgrid switch: this axis takes its tracks, lines and gap from the parent +// grid. It only lines up with the parent when the parent is a grid and this +// element spans the parent's tracks, which the tooltip says. +function SubgridSwitch({ on, busy, axis, onChange }: { on: boolean; busy: boolean; axis: 'column' | 'row'; onChange: (on: boolean) => void }) { + const translate = useTranslate(); + return ( + + ); +} + +// Switching subgrid on remembers the value it replaces, so switching it off while +// the settings are open puts that value back; with nothing to put back, off clears +// the property and the axis is an ordinary track list again. +function useSubgridSwitch({ prop, list, setProp, clearProp }: { prop: string; list: TrackList; setProp: SetProp; clearProp: ClearProp }) { + const on = /^subgrid\b/i.test(list.rawTemplate); + const [replaced, setReplaced] = useState<{ value: string; important: boolean } | undefined>(undefined); + const switchOn = () => { + setReplaced(list.rawTemplate ? { value: list.rawTemplate, important: list.important } : undefined); + setProp(prop, 'subgrid', list.important); + }; + const switchOff = () => { + if (replaced) { + setProp(prop, replaced.value, replaced.important); + setReplaced(undefined); + } else { + clearProp(prop); + } + }; + return { on, switchOn, switchOff }; +} + // Whether a list is several copies of one track — the only lists a repeat() can say. const sameTracks = (list: string[]) => list.length > 1 && list.every((x) => x === list[0]); @@ -173,6 +218,7 @@ function TrackSection({ title, prop, axis, setProp, labels }: TrackSectionProps) const translate = useTranslate(); const { busy, clearProp } = labels; const list = useTrackList({ prop, setProp, labels }); + const subgrid = useSubgridSwitch({ prop, list, setProp, clearProp }); const { tracks, rawTemplate, important } = list; // Editing the value as text rather than as tracks. Asked for with the braces // — or forced, when the value is one the track list cannot hold: showing @@ -197,6 +243,7 @@ function TrackSection({ title, prop, axis, setProp, labels }: TrackSectionProps) setProp={setProp} tracksCanHold={tracksCanHold} asExpression={asExpression} + subgrid={subgrid} onToggleExpression={() => setExpression((wasOn) => !wasOn)} onAdd={edits.add} /> @@ -380,6 +427,7 @@ function TrackSectionHead({ setProp, tracksCanHold, asExpression, + subgrid, onToggleExpression, onAdd, }: { @@ -391,6 +439,7 @@ function TrackSectionHead({ setProp: SetProp; tracksCanHold: boolean; asExpression: boolean; + subgrid: ReturnType; onToggleExpression: () => void; onAdd: () => void; }) { @@ -419,6 +468,7 @@ function TrackSectionHead({ axis={axis} onChange={(next) => switchRepeat({ next, prop, list, setProp })} /> + (next ? subgrid.switchOn() : subgrid.switchOff())} /> {asExpression ? undefined : (