List
A List
component is used to render list items. Both the check and bullet variant render within <ul>
tags whilst the number variant uses a <ol>
tag.
Import
- React
- Angular
- Vue.js
// with @dhl-official/react-library:
import { DhlList, DhlListItem } from "@dhl-official/react-library"
// with @dhl-official/ui-libraries/react-library:
import { DhlList, DhlListItem } from "@dhl-official/ui-libraries/react-library"
If the DUIL has been installed, you can use the web component directly:
<dhl-list></dhl-list>
<dhl-list-item></dhl-list-item>
// with @dhl-official/vue-library:
import { DhlList, DhlListItem } from "@dhl-official/vue-library"
// with @dhl-official/ui-libraries/vue-library:
import { DhlList, DhlListItem } from "@dhl-official/ui-libraries/vue-library"
Code
The List
component accepts list items in two ways:
Using <dhl-list-item>
/ <DhlListItem>
The List component can be used in conjunction with ListItem to populate a List:
- React
- Angular
- Vue.js
<DhlList>
<DhlListItem>
<DhlText>
First list item
</DhlText>
</DhlListItem>
<DhlListItem>
<DhlText>
Second list item
</DhlText>
</DhlListItem>
<DhlListItem>
<DhlText>
Third list item
</DhlText>
</DhlListItem>
</DhlList>
<dhl-list>
<dhl-list-item>
<dhl-text>
First list item
</dhl-text>
</dhl-list-item>
<dhl-list-item>
<dhl-text>
Second list item
</dhl-text>
</dhl-list-item>
<dhl-list-item>
<dhl-text>
Third list item
</dhl-text>
</dhl-list-item>
</dhl-list>
<dhl-list>
<dhl-list-item>
<dhl-text>
First list item
</dhl-text>
</dhl-list-item>
<dhl-list-item>
<dhl-text>
Second list item
</dhl-text>
</dhl-list-item>
<dhl-list-item>
<dhl-text>
Third list item
</dhl-text>
</dhl-list-item>
</dhl-list>
By passing an array to list-items / listItems
You can also pass an array of strings or objects (see shape below) to populate the List
{id: string, content: string}
- React
- Angular
- Vue.js
<DhlList listItems={[{id: "1", content: "First list item"},
{id: "2", content: "Second list item"},{id: "3", content: "Third list item"} ]}/>
<dhl-list [listItems]="listItems"/>
<dhl-list
:listItems="[
{id: '1', content: 'First list item'},
{id: '2', content: 'Second list item'},
{id: '3', content: 'Third list item'} ]"
/>
Interactive Demo
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-button-${getRandomString()} |
dataTestid | data-testid | An optional prop. The test id attached to the component as a data-testid attribute. | string | undefined |
listItems | -- | An optional prop used to render a list from an array of strings or objects. The element specified with this prop are rendered after the elements added to the list via the slot. | [string \| { id: string; content: string; }] | undefined |
listStart | list-start | An optional prop used to set the start number for a list of variant "ListVariants.number" | number | 0 |
reversed | reversed | An optional prop used to render a list of variant "ListVariants.number" in reverse order. | boolean | false |
variant | variant | An optional prop to select a component design variant. | "bullet" \| "check" \| "number" | DHL_LIST.VARIANT.BULLET |
Slots
Slot | Description |
---|---|
"unnamed" | unnamed children slot intended for DhlListItem component(s) |
Dependencies
Depends on
Graph
Built by DHL User Interface Library Team!