Grid Ready
Grid component provides structure for other components using Flexbox based layout system. Grid allows nesting and defining the direction of the content.
While the Grid Item component makes it possible set additional parameters for Grid’s cells, this component can be used without <duet-grid-item/>
as well. In that case the direct child elements of Grid will be considered as Grid cells.
Examples #
<duet-grid responsive class="grid-demo">
<duet-grid-item>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
</duet-grid>
<duet-grid responsive distribution="center" class="grid-demo">
<duet-grid-item>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
</duet-grid>
<duet-grid responsive distribution="right" class="grid-demo">
<duet-grid-item>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
</duet-grid>
<duet-grid responsive distribution="space-between" class="grid-demo">
<duet-grid-item>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
</duet-grid>
<duet-grid responsive distribution="space-around" class="grid-demo">
<duet-grid-item>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
</duet-grid>
<duet-grid responsive distribution="space-evenly" class="grid-demo">
<duet-grid-item>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
</duet-grid>
<duet-grid responsive alignment="top" class="grid-demo">
<duet-grid-item>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
</duet-grid>
<duet-grid responsive alignment="center" class="grid-demo">
<duet-grid-item>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
</duet-grid>
<duet-grid responsive alignment="bottom" class="grid-demo">
<duet-grid-item>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
</duet-grid>
<duet-grid responsive alignment="stretch" class="grid-demo">
<duet-grid-item>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
</duet-grid>
<duet-grid responsive alignment="baseline" class="grid-demo">
<duet-grid-item
><div style="line-height: 1.2">Grid Item<br />with multiple<br />rows of text.</div></duet-grid-item
>
<duet-grid-item><div style="line-height: 7">Grid Item</div></duet-grid-item>
<duet-grid-item><div style="line-height: 3">Grid Item</div></duet-grid-item>
</duet-grid>
<duet-layout center>
<div slot="main">
<duet-card>
<duet-button id="bnError">toggle errors</duet-button>
<duet-button id="bnValue">toggle placeholders</duet-button>
</duet-card>
<duet-card padding="large">
<duet-fieldset label="Valitse aikaväli">
<duet-grid responsive alignment="form_distribute">
<duet-grid-item>
<duet-date-picker
name="startdate"
class="start"
expand
margin="none"
label="Label"
placeholder="test"
id="input0"
echo-placeholder
caption="test"
value="2020-06-01"
error="test"
></duet-date-picker>
</duet-grid-item>
<duet-grid-item>
<duet-icon class="icon-arrow" name="navigation-arrow-right" color="currentColor" size="x-small"></duet-icon>
</duet-grid-item>
<duet-grid-item>
<duet-date-picker
name="enddate"
class="end"
expand
margin="none"
label="Label"
direction="left"
value="2020-06-10"
error="this is a is a long error"
></duet-date-picker>
</duet-grid-item>
</duet-grid>
<hr />
<duet-grid responsive alignment="form_distribute">
<duet-grid-item>
<duet-input name="enddate" class="end" margin="none" label="Label" expand value="input"></duet-input>
</duet-grid-item>
<duet-grid-item>
<duet-date-picker
name="startdate"
class="start"
id="input2"
margin="none"
label="Label"
expand
placeholder="test"
echo-placeholder
caption="test"
value="2020-06-01"
error="test"
></duet-date-picker>
</duet-grid-item>
</duet-grid>
<hr />
<duet-grid responsive alignment="form_distribute">
<duet-grid-item>
<duet-input
name="enddate"
id="input3"
class="end"
label="Label"
margin="none"
caption="caption"
echo-placeholder
expand
placeholder="placeholder"
value="input"
></duet-input>
</duet-grid-item>
<duet-grid-item>
<duet-paragraph>some simple text</duet-paragraph>
</duet-grid-item>
</duet-grid>
<duet-grid responsive alignment="form_distribute">
<duet-grid-item>
<duet-input name="enddate" class="end" margin="none" label="Label" expand value="input" error="Something wrong happened here"></duet-input>
</duet-grid-item>
<duet-grid-item fill>
<duet-select id="duet-select_default_select" label="Kaupunki" placeholder="Valitse" margin="none"></duet-select>
</duet-grid-item>
</duet-grid>
<hr />
<duet-grid responsive alignment="form_distribute">
<duet-grid-item>
<duet-input name="enddate" class="end" margin="none" label="Label" expand value="input" error="Something wrong happened here"></duet-input>
</duet-grid-item>
<duet-grid-item>
<duet-choice-group name="beneficiary" label="Beneficiary" direction="horizontal" responsive breakpoint="medium" margin="none">
<duet-choice label="Self" type="radio" value="self"></duet-choice>
<duet-choice label="Partner" type="radio" value="with-partner"></duet-choice>
</duet-choice-group>
</duet-grid-item>
</duet-grid>
<hr />
<duet-grid responsive alignment="form_distribute">
<duet-grid-item>
<duet-input name="enddate" class="end" margin="none" label="Label" expand value="input" error="Something wrong happened here"></duet-input>
</duet-grid-item>
<duet-grid-item>
<duet-button variation="primary" margin="none">Submit</duet-button>
</duet-grid>
</duet-fieldset>
</duet-card>
</div>
</duet-layout>
<script>
const i0= document.querySelector("#input0");
const i1= document.querySelector("#input1");
const i2= document.querySelector("#input2");
const i3= document.querySelector("#input3");
const bnError= document.querySelector("#bnError");
const bnValue= document.querySelector("#bnValue");
bnError.onclick=toggleErrors
bnValue.onclick=togglePlaceholder
var hasErrors=0
var echoPlaceholders=false
function toggleErrors(){
i0.error= hasErrors ? "this is a super long error this is a super long error this is a super long error this is a super long error this is a super long error" : undefined ;
i1.error= hasErrors ? "this is a super long error this is a super long error this is a super long error this is a super long error this is a super long error" : undefined ;
i2.error= hasErrors ? "this is a super long error this is a super long error this is a super long error this is a super long error this is a super long error" : undefined ;
i3.error= hasErrors ? "this is a super long error this is a super long error this is a super long error this is a super long error this is a super long error" : undefined ;
hasErrors=!hasErrors
}
function togglePlaceholder(){
i0.setAttribute("echo-placeholder", echoPlaceholders)
i1.setAttribute("echo-placeholder", echoPlaceholders)
i2.setAttribute("echo-placeholder", echoPlaceholders)
i3.setAttribute("echo-placeholder", echoPlaceholders)
echoPlaceholders=!echoPlaceholders
}
</script>
<duet-grid responsive alignment="stretch" class="grid-demo">
<duet-grid-item fill>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
</duet-grid>
<duet-grid responsive alignment="stretch" class="grid-demo">
<duet-grid-item fill>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item min-width="300px">Grid Item</duet-grid-item>
</duet-grid>
<duet-grid responsive alignment="stretch" class="grid-demo">
<duet-grid-item fill>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item fill>Grid Item</duet-grid-item>
<duet-grid-item fill>Grid Item</duet-grid-item>
</duet-grid>
<duet-grid responsive direction="vertical" class="grid-demo">
<duet-grid-item>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
</duet-grid>
<duet-grid responsive alignment="stretch" class="grid-demo">
<duet-grid-item fill>
<duet-grid responsive alignment="stretch">
<duet-grid-item fill>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item fill>Grid Item</duet-grid-item>
<duet-grid-item fill>Grid Item</duet-grid-item>
</duet-grid>
</duet-grid-item>
<duet-grid-item>Grid Item</duet-grid-item>
</duet-grid>
<duet-layout center margin="none">
<div slot="main">
<duet-card padding="large" margin="none">
<div>
<duet-choice-group value="one" label="Asiointikieli" direction="horizontal" name="group" responsive>
<duet-choice label="Suomi" type="radio" value="one" expand></duet-choice>
<duet-choice label="Svenska" type="radio" value="two" expand></duet-choice>
<duet-choice label="English" type="radio" value="three" expand></duet-choice>
</duet-choice-group>
</div>
<duet-grid responsive>
<duet-input label="Etunimi" placeholder="Matti" expand></duet-input>
<duet-input label="Sukunimi" placeholder="Meikäläinen" expand></duet-input>
</duet-grid>
<duet-input label="Katuosoite" placeholder="Kotikatu 123" expand></duet-input>
<duet-grid responsive>
<duet-input label="Postinumero" placeholder="00100"></duet-input>
<duet-input label="Kaupunki" placeholder="Helsinki" expand></duet-input>
</duet-grid>
<duet-grid responsive>
<duet-input label="Postinumero" placeholder="00100" expand></duet-input>
<duet-input label="Kaupunki" placeholder="Helsinki"></duet-input>
</duet-grid>
<duet-grid responsive>
<duet-input label="Postinumero" placeholder="00100" expand></duet-input>
<duet-grid-item min-width="calc(33.333% + 8px)"></duet-grid-item>
</duet-grid>
</duet-card>
</div>
</duet-layout>
<duet-grid responsive breakpoint="medium" alignment="stretch" class="grid-demo">
<duet-grid-item fill>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item fill>Grid Item</duet-grid-item>
<duet-grid-item fill>Grid Item</duet-grid-item>
</duet-grid>
<duet-grid responsive breakpoint="x-large" alignment="stretch" class="grid-demo">
<duet-grid-item fill>Grid Item<br />with multiple<br />rows of text.</duet-grid-item>
<duet-grid-item fill>Grid Item</duet-grid-item>
<duet-grid-item fill>Grid Item</duet-grid-item>
</duet-grid>
<duet-grid grid-template="small">
<duet-card margin="none">small (1)</duet-card>
</duet-grid>
<duet-divider></duet-divider>
<duet-grid grid-template="medium">
<duet-card margin="none">medium (1)</duet-card>
</duet-grid>
<duet-divider></duet-divider>
<duet-grid grid-template="large">
<duet-card margin="none">large (1)</duet-card>
</duet-grid>
<duet-divider></duet-divider>
<duet-grid grid-template="sidebar-right">
<duet-card margin="none">sidebar-right (1)</duet-card>
<duet-card margin="none">(2)</duet-card>
</duet-grid>
<duet-divider></duet-divider>
<duet-grid grid-template="sidebar-left">
<duet-card margin="none">sidebar-left (1)</duet-card>
<duet-card margin="none">(2)</duet-card>
</duet-grid>
<duet-divider></duet-divider>
<duet-grid grid-template="two-columns">
<duet-card margin="none">two-columns (1)</duet-card>
<duet-card margin="none">(2)</duet-card>
</duet-grid>
<duet-divider></duet-divider>
<duet-grid grid-template="three-columns">
<duet-card margin="none">three-columns (1)</duet-card>
<duet-card margin="none">(2)</duet-card>
<duet-card margin="none">(3)</duet-card>
</duet-grid>
Properties #
Property | Attribute | Description | Type | Default |
---|---|---|---|---|
alignment | alignment | Adjusts the vertical alignment of the grid items, if set to "form_distribute" the grid will try to calculate correct paddings for any duet-input fields inside duet-grid-items, so that they align even when displaying errors. | "baseline" | "bottom" | "center" | "form_distribute" | "stretch" | "top" | "top" |
breakpoint | breakpoint | Switch the breakpoint used to trigger the content stacking. These match to similar media query tokens: $media-query-small and $media-query-medium. | "large" | "medium" | "small" | "x-large" | "x-small" | "small" |
direction | direction | Direction of the grid items. | "horizontal" | "vertical" | "horizontal" |
distribution | distribution | Adjusts the horizontal distribution of the grid items. | "center" | "default" | "left" | "right" | "space-around" | "space-between" | "space-evenly" | "default" |
gridTemplate | grid-template | CSS grid based templates that can be used to create pre-defined layouts. | "large" | "medium" | "sidebar-left" | "sidebar-right" | "small" | "three-columns" | "two-columns" | null |
mobile | mobile | Adjusts the horizontal alignment of the grid items on mobile (575px and under). | "" | "auto" | "center" | "left" | "right" | "" |
responsive | responsive | Enable or disable the automatic responsive behaviour of the grid component. Setting this option to "true" makes sure that contents are stacked vertically on mobile (575px and under). | boolean | false |
rowReverse | row-reverse | Reverse the order of the grid items when horizontal. Usefull when we want the primary item to be on bottom right on desktop, but on top on mobile and the first for screen readers. | boolean | false |
Usage #
This section includes guidelines for designers and developers about the usage of this component in different contexts.
When to use #
- When you need to provide structure for other components using Flexbox based layout system.
- When you need to stack multiple components vertically or horizontally.
When not to use #
- To build complex grids. Use CSS Grid Layout instead.
Accessibility #
This component has been validated to meet the WCAG 2.1 AA accessibility guidelines. You can find additional information regarding accessibility of this component below.
- Grid is a custom element which doesn’t have semantic meaning or any added functionality for assistive technologies.
Integration
For integration, event and theming guidelines, please see Using Components. This documentation explains how to implement and use Duet’s components across different technologies like Angular, React or Vanilla JavaScript.
Tutorials
Follow these practical tutorials to learn how to build simple page layouts using Duet’s CSS Framework, Web Components and other features:
Building Layouts
TutorialsUsing CLI Tools
TutorialsCreating Custom Patterns
TutorialsServer Side Rendering
TutorialsSharing Prototypes
TutorialsUsage With Markdown
Troubleshooting
If you experience any issues while using a component, please head over to the Support page for more guidelines and help.