GridCell
The DhlGridCell component is used to position elements within a DhlGridContainer by defining the number of columns the DhlGridCell
spans from a given starting column.
Import
- React
- Angular
- Vue.js
// with @dhl-official/react-library:
import { DhlGridCell } from "@dhl-official/react-library"
// with @dhl-official/ui-libraries/react-library:
import { DhlGridCell } from "@dhl-official/ui-libraries/react-library"
If the DUIL has been installed, you can use the web component directly:
<dhl-grid-cell></dhl-grid-cell>
// with @dhl-official/vue-library:
import { DhlGridCell } from "@dhl-official/vue-library"
// with @dhl-official/ui-libraries/vue-library:
import { DhlGridCell } from "@dhl-official/ui-libraries/vue-library"
Code
- React
- Angular
- Vue.js
<DhlGridContainer>
<DhlGridCell>Foo</DhlGridCell>
</DhlGridContainer>
<dhl-grid-container>
<dhl-grid-cell>Foo</dhl-grid-cell>
</dhl-grid-container>
<dhl-grid-container>
<dhl-grid-cell>Foo</dhl-grid-cell>
</dhl-grid-container>
Usage
Defining Responsive Behaviour
The number of columns that a DhlGridCell can span across can be specified for 4 viewports, at the following respective viewports:
To specify the number of columns for a DhlGridCell to span across for each viewport, the spanColumns prop is used.
The spanColumns prop can take either an Array type or a Number type.
Passing a single number value to spanColumns
Supplying the spanColumns prop with a single Number will result in the DhlGridCell spanning across an equal amount of columns across ALL of the previously mentioned viewports.
In the example below, a DhlGridContainer is used to hold a DhlGridCell. By default, the DhlGridContainer holds 12 columns.
Default Grid Cell
By giving spanColumns a single value of 12, the DhlGridCell will therefore span across all 12 columns at every viewport.
Passing an array of values to spanColumns
You can specify exactly how many columns a DhlGridCell should span for each viewport by supplying the spanColumns prop with an Array of numbers.
The index of the array maps to the previously defined viewport breakpoints.
Responsive Grid Cell
const responsiveColumns = [3, 6, 8, 12];
<DhlGridContainer columns={responsiveColumns}>
{/* Grid Children... */}
</DhlGridContainer>;
This will result in a DhlGridCell that spans across the following number of columns at each breakpoint:
- small : 12 columns
- medium: 8 columns
- large: 6 columns
- xlarge: 3 columns
If an array is specified, but values are not provided for all viewports, then the number of columns to span across will be inherited from the last specified viewport.
Inheriting Grid Cell
const responsiveColumns = [3, 6];
<DhlGridContainer columns={responsiveColumns}>
{/* Grid Children... */}
</DhlGridContainer>;
To prevent this behaviour, you can pass
unsetas a value in the array for any viewport.
Defining the starting column of a DhlGridCell
To define in which column the DhlGridCell should start, use the startColumn prop. The startColumn prop follows the same responsive mechanism as
the spanColumns prop i.e. resposive behaviour can be set individually for each viewport by passing startColumn an Array or for all viewports by passing a single Number.
Start Column DhlGridCell
For example, above is a single DhlGridCell within a DhlGridContainerw with the following properties:
At the
smallviewport, theDhlGridCellspans across all 12 (default number of columns) columns of theDhlGridContainer.At the remaining viewports, the
DhlGridCellspans across 4 columns.At the
smallviewport, theDhlGridCellstarts at column 2.At the remaining viewports, the
DhlGridCellstarts at column 9 and spans for 4 columns.
Overflow can be hidden by setting the isOverflowHidden prop to true.
Example use-cases
The example use-case below uses three DhlGridCell wrapped Button's that span responsively - taking the full 12 columns at the smallest
viewport to simulate a stack display. All remaining viewports span 6 columns.
The gap between rows has been set to 40px. The DhlGridContainer holds DhlGridCell.
<DhlGridContainer>
<DhlGridCell spanColumns={[12, 6]}>
<!-- dhl-grid-cell content -->
</DhlGridCell>
<DhlGridCell spanColumns={[12, 6]}>
<!-- dhl-grid-cell content -->
</DhlGridCell>
<DhlGridCell spanColumns={[12, 6]}>
<!-- dhl-grid-cell content -->
</DhlGridCell>
</DhlGridContainer>
Readme
Properties
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
dataClassName | data-class-name | An optional class name prop for the component. | string | undefined |
dataId | data-id | An optional prop. Gives a valid HTML ID attribute value for the component. | string | dhl-grid-cell-${getRandomString()} |
dataTestid | data-testid | An optional prop. The test id attached to the component as a data-testid attribute. | string | undefined |
isOverflowHidden | is-overflow-hidden | An optional flag to configure overflow display | boolean | undefined |
spanColumns | span-columns | An optional prop that sets the number of grid columns\ Please note: Value can be of type number or array.\ If specified as number, the value is used for all viewport If specified as array, the values are used for the viewport in the following order:\ 0 = small.\ 1 = medium,\ 2 = large viewport,\ 3 = xlarge viewport.\ Use "unset" in larger viewport to ignore settings from smaller viewport | number \| number[] \| string \| string[] | undefined |
startColumn | start-column | An optional prop that sets the position of the cell by specifying at what grid column the cell should be displayed.\ Please note: Value can be of type number or array.\ If specified as number, the value is used for all viewport If specified as array, the values are used for the viewport in the following order:\ 0 = small.\ 1 = medium,\ 2 = large viewport,\ 3 = xlarge viewport.\ Use "unset" in larger viewport to ignore settings from smaller viewport | number \| number[] \| string \| string[] | undefined |
Slots
| Slot | Description |
|---|---|
"unnamed" | unnamed children slot for GridCell content |
Dependencies
Used by
- dhl-copy-text
- dhl-footer
- dhl-page-headline
- dhl-stage
- dhl-stage-action-box
- dhl-stage-intro
- dhl-stage-numbers
- dhl-stage-tiles
Graph
Built by DHL User Interface Library Team!