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
7 changes: 7 additions & 0 deletions shared/properties/i18n/messages/de/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions shared/properties/i18n/messages/en/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions shared/properties/i18n/messages/es/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions shared/properties/i18n/messages/fr/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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é',
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions shared/properties/i18n/messages/ptBR/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
28 changes: 27 additions & 1 deletion src/features/style/GridControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 (
<div className="embed-editor_size-row embed-editor_bg-row-top">
<GroupLabel
Expand All @@ -344,6 +366,8 @@ function GridTracksRow({ props, onConfigure }: { props: GridControlsProps; onCon
earlier tracks' sizes. Per-track values live behind the configure gear. */}
<CountField
value={countTracks(columnsRaw)}
held={columnsHeld}
title={columnsRaw}
busy={busy}
ariaLabel={translate('style.gridControls.gridColumns')}
onCommit={(count) => setProp('grid-template-columns', repeatTracks(count, NEW_COLUMN), false)}
Expand All @@ -358,6 +382,8 @@ function GridTracksRow({ props, onConfigure }: { props: GridControlsProps; onCon
<div className="embed-editor_gap-cell">
<CountField
value={countTracks(rowsRaw)}
held={rowsHeld}
title={rowsRaw}
busy={busy}
ariaLabel={translate('style.gridControls.gridRows')}
onCommit={(count) => setProp('grid-template-rows', repeatTracks(count, NEW_ROW), false)}
Expand Down
31 changes: 30 additions & 1 deletion src/features/style/GridFlowControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="embed-editor_grid-count">
<input className="u-input embed-editor_size-input" value={held} readOnly disabled aria-label={ariaLabel} title={title} />
<CountSteppers busy step={() => undefined} />
</div>
);
}
return <CountInput value={value} busy={busy} ariaLabel={ariaLabel} onCommit={onCommit} />;
}

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(() => {
Expand Down
50 changes: 50 additions & 0 deletions src/features/style/GridSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<label
className={`embed-editor_switch ${on ? 'is-on' : ''}`}
title={on ? translate('style.gridSettings.subgridOn') : translate('style.gridSettings.subgridOff')}
>
<input
type="checkbox"
role="switch"
checked={on}
disabled={busy}
aria-label={axis === 'column' ? translate('style.gridSettings.subgridColumns') : translate('style.gridSettings.subgridRows')}
onChange={(event) => onChange(event.target.checked)}
/>
{/* i18n-ignore: the CSS keyword the switch writes, kept as written like repeat(). */}
<span className="embed-editor_switch-label">subgrid</span>
</label>
);
}

// 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]);

Expand All @@ -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
Expand All @@ -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}
/>
Expand Down Expand Up @@ -380,6 +427,7 @@ function TrackSectionHead({
setProp,
tracksCanHold,
asExpression,
subgrid,
onToggleExpression,
onAdd,
}: {
Expand All @@ -391,6 +439,7 @@ function TrackSectionHead({
setProp: SetProp;
tracksCanHold: boolean;
asExpression: boolean;
subgrid: ReturnType<typeof useSubgridSwitch>;
onToggleExpression: () => void;
onAdd: () => void;
}) {
Expand Down Expand Up @@ -419,6 +468,7 @@ function TrackSectionHead({
axis={axis}
onChange={(next) => switchRepeat({ next, prop, list, setProp })}
/>
<SubgridSwitch on={subgrid.on} busy={busy} axis={axis} onChange={(next) => (next ? subgrid.switchOn() : subgrid.switchOff())} />
<ExpressionToggle title={title} axis={axis} busy={busy} tracksCanHold={tracksCanHold} asExpression={asExpression} onToggle={onToggleExpression} />
{asExpression ? undefined : (
<button
Expand Down
21 changes: 21 additions & 0 deletions src/features/style/model/gridTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,30 @@ export function canEditAsTracks(value: string): boolean {
if (tracks.length === 1 && /^var\(/i.test(tracks[0] ?? '')) {
return false;
}
// A repeat() that parsing left whole has no number for its count. auto-fill and
// auto-fit are counts the editors keep; a variable (`repeat(var(--columns), 1fr)`,
// Lumos's Grid) is one they cannot show, so it reads as a single strange track.
if (tracks.some((track) => /^repeat\(/i.test(track) && !/^repeat\(\s*auto-(fill|fit)\s*,/i.test(track))) {
return false;
}
return true;
}

/** Why a Columns or Rows count is held: the axis is a subgrid, or a value no count can say. */
export type HeldTrackCount = 'subgrid' | 'custom';

/**
* Why the Columns and Rows counts cannot show a value, or undefined when they can.
* Writing a count would replace the value with N plain tracks, so the count holds
* a label for this kind instead and the grid settings edit the value.
*/
export function heldTrackCount(value: string): HeldTrackCount | undefined {
if (canEditAsTracks(value)) {
return undefined;
}
return /\bsubgrid\b/i.test(value) ? 'subgrid' : 'custom';
}

/** The same tracks as a `repeat()`, or '' when they differ and it cannot say them. */
export function asRepeat(value: string): string {
const tracks = parseTrackList(value);
Expand Down
Loading
Loading