Skip to content

Grid ​

Grid can divide the page into equal-width blocks in the horizontal direction, used for displaying content or page navigation.

Component Type ​

Basic Usage ​

Basic usage requires specifying icon name through icon and text through text property. Default displays as one row.

html
<wd-grid clickable>
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
</wd-grid>

Content Slot ​

Customize grid content through wd-grid-item default slot.

html
<wd-grid>
  <wd-grid-item>
    <image class="img" :src="joy" />
  </wd-grid-item>
  <wd-grid-item>
    <image class="img" :src="joy" />
  </wd-grid-item>
  <wd-grid-item>
    <image class="img" :src="joy" />
  </wd-grid-item>
</wd-grid>
scss
.img {
  width: 100%;
  height: 90px;
}

Component Variant ​

Custom Column Count ​

Customize grid column count through column property. When this property is not defined, default displays as one row.

html
<wd-grid :column="3">
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
</wd-grid>

Square Grid ​

Enable square grid property through square. At this time, each GridItem has equal width and height.

Note: After enabling square, it is not recommended to customize GridItem height through styles.

html
<wd-grid square :column="4" border :gutter="10">
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
</wd-grid>

Component Style ​

Custom Background Color ​

Customize grid background color through bg-color property.

html
<wd-grid bg-color="rgba(0, 0, 0, 0.02)">
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
</wd-grid>

Enable Border ​

Enable border line display through border property.

html
<wd-grid border :column="3">
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
</wd-grid>

Set Grid Gap ​

Set distance between grids through gutter property.

html
<wd-grid :gutter="10" :column="4">
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
  <wd-grid-item icon="image" text="Text" />
</wd-grid>

Tip Information ​

After setting is-dot property, a small red dot will be displayed in the upper right corner of the icon. Badge display content can also be set through value, max.

html
<wd-grid>
  <wd-grid-item is-dot icon="gift" text="Text" />
  <wd-grid-item value="100" :max="99" icon="desktop" text="Text" />
</wd-grid>

Layout Capability ​

Horizontal Layout ​

Set content arrangement direction through direction property, default is vertical (vertical), can be set to horizontal (horizontal). Cooperate with reverse property to swap icon and text positions.

html
<wd-grid direction="horizontal" :column="2">
  <wd-grid-item icon="image" text="Icon on Left" />
  <wd-grid-item icon="settings" text="Settings Option" />
</wd-grid>

<wd-grid direction="horizontal" reverse :column="2" border>
  <wd-grid-item icon="image" text="Icon on Right" />
  <wd-grid-item icon="settings" text="Settings Option" />
</wd-grid>

Special Style ​

Icon Slot ​

Customize icon position content through named slot icon.

html
<wd-grid>
  <wd-grid-item text="Text" icon-size="36px">
    <template #icon>
      <image class="slot-img" :src="joy" />
    </template>
  </wd-grid-item>
</wd-grid>

Text Slot ​

Customize text position content through named slot text.

html
<wd-grid>
  <wd-grid-item icon="image">
    <template #text>
      <view class="text">Custom Text Slot</view>
    </template>
  </wd-grid-item>
</wd-grid>

Custom Style ​

Deeply customize styles through custom-class or external style classes. If text is too long and you want to display in single line with ellipsis, you can set ellipsis to true.

html
<wd-grid>
  <wd-grid-item custom-class="custom-item" ellipsis icon="search-line" text="This is a custom styled grid item This is a custom styled grid item This is a custom styled grid item" />
</wd-grid>
scss
:deep(.custom-item) {
  color: #e2231a;
  text-align: left !important;
}

Enable clickable state through clickable property, and set page jump through url and link-type properties.

html
<wd-grid clickable>
  <wd-grid-item link-type="navigateTo" url="/pages/button/Index" icon="edit" text="Navigate to ..." />
</wd-grid>

Grid Attributes ​

ParameterDescriptionTypeDefault Value
columnColumn countnumber-
borderWhether to show borderbooleanfalse
gutterSpacing between grids, default unit is pxnumber-
squareWhether to fix grid as squarebooleanfalse
clickableWhether to enable grid click feedbackbooleanfalse
bg-colorBackground color settingstring-
hover-classSpecify grid-item pressed style classstring'wd-grid-item__content--hover'
centerWhether to center grid content displaybooleantrue
directionGrid content arrangement direction, optional values are horizontal, verticalstring'vertical'
reverseWhether to swap icon and text positionsbooleanfalse
icon-sizeIcon size, default unit is pxstring'28px'
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

GridItem Attributes ​

ParameterDescriptionTypeDefault Value
textText contentstring-
ellipsisWhether to hide overflow and show ellipsisbooleanfalse
iconIcon name, optional values see wd-icon componentstring-
icon-colorIcon colorstring-
icon-prefixIcon class name prefixstring-
css-iconCSS icon, see Icon component for usageboolean | stringfalse
is-dotWhether to show small red dot in upper right corner of iconbooleanfalse
valueBadge display value in upper right corner of iconstring | number-
maxBadge maximum value in upper right corner of icon, exceeding maximum will display {max}+number99
badge-propsCustom badge properties, passed to Badge componentBadgeProps-
urlLink address to jump to after clickingstring-
link-typePage jump method, optional values are navigateTo, switchTab, reLaunch, redirectTostring'navigateTo'
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

GridItem Events ​

Method NameDescriptionParameters
clickClick (jump) event-

Grid Slot ​

nameDescription
defaultGrid content

GridItem Slot ​

nameDescription
defaultGrid item default content (customize all content)
iconIcon position content
textText position content

Grid External Style Classes ​

Class NameDescription
custom-classRoot node style

GridItem External Style Classes ​

Class NameDescription
custom-classRoot node style
custom-textText style
custom-iconIcon style

主题定制 ​

CSS 变量 ​

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置。

名称默认值描述
--wot-grid-item-font-size$typography-body-size-extra-large网格项文字字号
--wot-grid-item-line-height$typography-body-line-height-size-extra-large网格项文字行高
--wot-grid-item-bg$filled-oppo网格项背景色
--wot-grid-item-padding$padding-loose $padding-loose网格项内容内边距
--wot-grid-item-hover-bg$feedback-hover网格项悬浮背景色
--wot-grid-item-icon-size$n-32网格项图标尺寸
--wot-grid-item-icon-color$icon-secondary网格项图标颜色
--wot-grid-item-border-width$stroke-main网格项边框宽度
--wot-grid-item-border-color$border-main网格项边框颜色
--wot-grid-item-text-color$text-main网格项文字颜色
--wot-grid-item-text-spacing$spacing-super-tight网格项文字间距

Source Code ​

Documentation
• Component

Released under the MIT License.

Released under the MIT License.