Grid
Verwendung
Bei der Grid-Komponente handelt es sich um eine technische Komponente, die die Verwendung des Grid-CSS-Stylings erleichtert. Empfehlungen für die Verwendung finden Sie in der offiziellen Dokumentation zum CSS-Grid-Layout.
Code
import { Grid, GridItem } from '@jutro/layout';
<Grid>
<GridItem>
<span>First Item</span>
</GridItem>
<GridItem>
<span>Second Item</span>
</GridItem>
<GridItem>
<span>Third Item</span>
</GridItem>
</Grid>;
Importanweisung
import { Grid, GridItem } from '@jutro/layout';
Komponentenvertrag
Vergewissern Sie sich, dass Sie die API-Oberfläche der Design System-Komponenten und die damit verbundenen Auswirkungen und Kompromisse verstehen. Erfahren Sie mehr in unserer Einführung zur Komponenten-API.
Eigenschaften
Grid
autoRows- Typ
arrayBeschreibungDefines implicit rows.
blockPointerEvents- Typ
booleanBeschreibungIf set to
true, pointer events will be blocked. children- Typ
nodeBeschreibungChildren; preferably 'GridItem' but works with any child.
className- Typ
stringBeschreibungCSS class name for this component.
columns- Typ
string | number[]BeschreibungDefines explicit column widths.
gap- Typ
'none' | 'small' | 'medium' | 'large'BeschreibungGap size between the rows and columns.
Standardwert'medium' hgap- Typ
'none' | 'small' | 'medium' | 'large'BeschreibungHorizontal gap size between the columns. If unspecified, falls back to the
gapproperty. justifyContent- Typ
'left' | 'center' | 'right' | 'around' | 'between' | 'evenly' | 'stretch'BeschreibungJustify logic for the grid within its container.
Standardwert'stretch' justifyItems- Typ
'left' | 'center' | 'right' | 'around' | 'between' | 'evenly' | 'stretch'BeschreibungJustify logic for all items within the grid.
Standardwert'stretch' rows- Typ
string | number[]BeschreibungDefines explicit row heights.
style- Typ
React.CSSProperties | undefinedBeschreibungDOM element styles.
tag- Typ
stringBeschreibungOptional DOM tag to render.
Standardwert'div' valignItems- Typ
'top' | 'middle' | 'bottom' | 'baseline' | 'stretch'BeschreibungVertical alignment for all items within the grid.
Standardwert'stretch' vgap- Typ
'none' | 'small' | 'medium' | 'large'BeschreibungVertical gap between the rows. If unspecified, falls back to the
gapproperty. alignContentVerworfen- Typ
'start' | 'center' | 'end' | 'baseline' | 'stretch'BeschreibungAligns rows vertically within the grid container.
Standardwert'stretch' phoneVerworfen- Typ
GridBeschreibungAny Grid properties that will be used instead for the 'phone' breakpoint. Deprecated since 10.9.0.
phoneWideVerworfen- Typ
GridBeschreibungAny Grid properties that will be used instead for the 'phoneWide' breakpoint. Deprecated since 10.9.0.
repeatVerworfen- Typ
'auto-fit' | 'auto-fill' | number | stringBeschreibungLogic for how columns will be repeated.
tabletVerworfen- Typ
GridBeschreibungAny Grid properties that will be used instead for the 'tablet' breakpoint. Deprecated since 10.9.0.
valignContentVerworfen- Typ
'top' | 'middle' | 'bottom' | 'baseline' | 'stretch'BeschreibungAligns rows vertically within the grid container.
Standardwert'stretch'
GridItem
alignSelf- Typ
'top' | 'middle' | 'bottom' | 'baseline' | 'stretch'BeschreibungAligns the item horizontally within its container.
Standardwert'stretch' colSpan- Typ
number | stringBeschreibungSpecifies how many columns the element will span.
colStart- Typ
number | stringBeschreibungSpecifies a grid item's start column position within the grid.
justifySelf- Typ
'start' | 'center' | 'end' | 'stretch'BeschreibungAligns the items vertically within their containers.
Standardwert'stretch' rowSpan- Typ
number | stringBeschreibungSpecifies how many rows the element will span.
rowStart- Typ
number | stringBeschreibungSpecifies a grid item's start row position within the grid.
alignVerworfen- Typ
'start' | 'center' | 'end' | 'stretch'BeschreibungAligns the items vertically within their containers. Deprecated since 10.9.0, use
justifySelfinstead. cloneVerworfen- Typ
booleanBeschreibungRenders the child without a tag wrapper. It passes
classNames and styles directly to the child element if possible. If not possible, it falls back to wrapping with a tag (for React elements which are not valid). Deprecated since 10.9.0. fullWidthVerworfen- Typ
booleanBeschreibungIf set to
true, item takes full width of the parent grid. Ignored ifcolStartorcolSpanis specified. Deprecated since 10.9.0. phoneVerworfen- Typ
GridBeschreibungAny Grid properties that will be used instead for the 'phone' breakpoint. Deprecated since 10.9.0.
phoneWideVerworfen- Typ
GridBeschreibungAny Grid properties that will be used instead for the 'phoneWide' breakpoint. Deprecated since 10.9.0.
tabletVerworfen- Typ
GridBeschreibungAny Grid properties that will be used instead for the 'tablet' breakpoint. Deprecated since 10.9.0.
textAlignVerworfen- Typ
'top' | 'middle' | 'bottom' | 'baseline' | 'stretch'BeschreibungAligns text inside item. Deprecated since 10.9.0.
valignVerworfen- Typ
'top' | 'middle' | 'bottom' | 'baseline' | 'stretch'BeschreibungAligns the item horizontally within its container. Deprecated since 10.9.0, use
alignSelfinstead. visibleVerworfen- Typ
booleanBeschreibungSpecifies whether the
GridItemis visible. Deprecated since 10.9.0.
Hooks
Für Grid sind keine Hooks verfügbar.
Übersetzungsschlüssel
Es gibt keine Übersetzungen für Grid.
Informationen über die Verwaltung von Übersetzungen finden Sie in unserem Abschnitt über Internationalisierung.
Escape Hatches
Weitere Informationen finden Sie in unserer Dokumentation über Escape Hatches.
Beispiele
Beispiel für einen einfachen Grid-Container
Ein einfacher Jutro Grid-Container besteht aus einer Grid-Komponente mit einer Reihe von untergeordneten Komponenten. Wenn es sich bei diesen untergeordneten Elementen um GridItem-Komponenten handelt, können Sie die zusätzlichen GridItem-Eigenschaften verwenden, um das Element im Layout weiter zu steuern.
Beim Standardverhalten wird von einer Spalte ausgegangen und jedes neue Element wird einer neuen Zeile hinzugefügt.
import { Grid, GridItem } from '@jutro/layout';
<Grid>
<GridItem>
<strong>First Item</strong>
</GridItem>
<GridItem>
<strong>Second Item</strong>
</GridItem>
<GridItem>
<strong>Third Item</strong>
</GridItem>
</Grid>;
Beispiel für mehrere Spalten
Durch Definieren von Spaltenbreiten können Sie weitere Spalten hinzufügen. Standardmäßig füllen Elemente jede Spalte, bevor mit der nächsten Zeile fortgefahren wird. In diesem Beispiel werden einem zweispaltigen Grid drei Elemente hinzugefügt.
import { Grid, GridItem } from '@jutro/layout';
<Grid columns={['1fr', '1fr']}>
<GridItem>
<strong>First Item</strong>
</GridItem>
<GridItem>
<strong>Second Item</strong>
</GridItem>
<GridItem>
<strong>Third Item</strong>
</GridItem>
</Grid>;
autoRows-Beispiel
Mit der autoRows-Eigenschaft können Sie die Zeilenhöhe für Zeilen bestimmen, die im Attribut rows nicht definiert sind. Auf diese Weise können Sie die Höhe festlegen, wenn die Länge des Grids unbekannt ist. In diesem Beispiel hat die erste Zeile eine Höhe von 50 Pixeln und zusätzliche Zeilen eine Höhe von 75 Pixeln.
import { Grid, GridItem } from '@jutro/layout';
<Grid
rows={['50px']}
autoRows={['75px']}>
<GridItem>
<strong>First Item</strong>
</GridItem>
<GridItem>
<strong>Second Item</strong>
</GridItem>
<GridItem>
<strong>Third Item</strong>
</GridItem>
</Grid>;
Beispiele zur Begründung
Mit dem justifyContent-Eigenschaftssatz können Sie festlegen, wie Spalten im Grid ausgerichtet werden.
import { Grid, GridItem } from '@jutro/layout';
<Grid justifyContent="center">
<GridItem>
<strong>First Item</strong>
</GridItem>
<GridItem>
<strong>Second Item</strong>
</GridItem>
<GridItem>
<strong>Third Item</strong>
</GridItem>
</Grid>;
Mit dieser justifyItems-Eigenschaft wird festgelegt, wie Elemente in ihrem Container ausgerichtet werden.
import { Grid, GridItem } from '@jutro/layout';
<Grid justifyItems="center">
<GridItem>
<strong>First Item</strong>
</GridItem>
<GridItem>
<strong>Second Item</strong>
</GridItem>
<GridItem>
<strong>Third Item</strong>
</GridItem>
</Grid>;
Um festzulegen, wie bestimmte Elemente in ihrem Container ausgerichtet werden, verwenden Sie die justifySelf-Eigenschaft für die entsprechende GridItem.
import { Grid, GridItem } from '@jutro/layout';
<Grid>
<GridItem justifySelf="stretch">
<strong>justifySelf='stretch'</strong>
</GridItem>
<GridItem justifySelf="start">
<strong>justifySelf='start'</strong>
</GridItem>
<GridItem justifySelf="center">
<strong>justifySelf='center'</strong>
</GridItem>
<GridItem justifySelf="end">
<strong>justifySelf='end'</strong>
</GridItem>
</Grid>;
Beispiele ausrichten
Mit der alignItems-Eigenschaft legen Sie fest, wie Elemente in ihrem Container vertikal ausgerichtet werden.
import { Grid, GridItem } from '@jutro/layout';
<Grid
columns={['1fr', '1fr']}
alignItems="center">
<GridItem>
<p>
<strong>First Item</strong>
</p>
<p> </p>
</GridItem>
<GridItem>
<strong>Second Item</strong>
</GridItem>
</Grid>;
Um festzulegen, wie bestimmte Elemente in ihrem Container vertikal ausgerichtet werden, verwenden Sie die alignSelf-Eigenschaft für das entsprechende GridItem.
import { Grid, GridItem } from '@jutro/layout';
<Grid columns={['1fr', '1fr', '1fr', '1fr', '1fr']}>
<GridItem>
<p>
<strong>alignSelf='stretch'</strong>
</p>
<p> </p>
</GridItem>
<GridItem alignSelf="center">
<strong>alignSelf='center'</strong>
</GridItem>
<GridItem alignSelf="start">
<strong>alignSelf='start'</strong>
</GridItem>
<GridItem alignSelf="end">
<strong>alignSelf='end'</strong>
</GridItem>
<GridItem alignSelf="baseline">
<strong>alignSelf='baseline'</strong>
</GridItem>
</Grid>;
colSpan-Beispiel
Die Eigenschaft colSpan für ein GridItem-Element legt fest, wie viele Spalten das Element umfasst.
import { Grid, GridItem } from '@jutro/layout';
<Grid
columns={['1fr', '1fr', '1fr']}
rows={['1fr', '1fr']}
gap="large">
<GridItem colSpan="3">
<strong>First Item</strong>
</GridItem>
<GridItem>
<strong>Second Item</strong>
</GridItem>
<GridItem colSpan="2">
<strong>Third Item</strong>
</GridItem>
</Grid>;
rowSpan-Beispiel
Die Eigenschaft rowSpan für ein GridItem-Element legt fest, wie viele Zeilen das Element umfasst.
import { Grid, GridItem } from `@jutro/layout`;
<Grid columns={['1fr', '1fr']} rows={['1fr', '1fr']} gap="large">
<GridItem rowSpan="2" >
<strong>First Item</strong>
</GridItem>
<GridItem >
<strong>Second Item</strong>
</GridItem>
<GridItem >
<strong>Third Item</strong>
</GridItem>
</Grid>
colStart- und rowStart-Beispiele
Die Eigenschaften colStart und rowStart in einem GridItem-Set legen fest, in welcher Spalte bzw. Zeile das Element beginnt. In Kombination mit colSpan und rowSpan können diese Eigenschaften für eine hohe Granularität der Anpassung des Grid-Layouts verwendet werden.
import { Grid, GridItem } from `@jutro/layout`;
<Grid
columns={['1fr', '1fr', '1fr']}
rows={['1fr', '1fr', '1fr']}
gap="large"
>
<GridItem colSpan={2}>
<strong>First Item</strong>
</GridItem>
<GridItem rowSpan={2} colStart={1}>
<strong>Second Item</strong>
</GridItem>
<GridItem>
<strong>Third Item</strong>
</GridItem>
<GridItem rowSpan={2} rowStart={1} colStart={3}>
<strong>Fourth Item</strong>
</GridItem>
<GridItem colSpan={2}>
<strong>Fifth Item</strong>
</GridItem>
</Grid>
Änderungsprotokoll
10.9.0
Die folgenden Eigenschaften wurden in Version 10.9.0 abgekündigt.
| Komponente | Eigenschaft | Alternative |
|---|---|---|
| Grid | phone | Keine |
| Grid | phoneWide | Keine |
| Grid | tablet | Keine |
| Grid | repeat | Keine |
| GridItem | phone | Keine |
| GridItem | phoneWide | Keine |
| GridItem | tablet | Keine |
| GridItem | clone | Keine |
| GridItem | fullWidth | Keine |
| GridItem | visible | Keine |
| GridItem | textAlign | Keine |
| GridItem | vAlign | alignSelf |
| GridItem | align | justifySelf |