Skip to content

Grid Layout Component ​

The grid component is generally used in scenarios where multiple items of the same type are displayed simultaneously. You can add badge components or icons to grid items, and it can also be extended into a horizontally swipeable carousel. Platform Differences

📌 Platform Differences ​

APP(vue)H5WeChat Mini ProgramAlipay Mini Program
✔✔✔✔

🏯 Basic Usage Examples ​

html
<!-- Global usage -->
<hy-gird :list="list"></hy-gird>
ts
import { IconConfig } from '@hy-app/ui';
import { ref } from 'vue';

// Create reactive data
const list = ref([
    {
        icon: IconConfig.CRY_FILL,
        name: 'Puppy',
    },
    {
        icon: 'https://img1.baidu.com/it/u=563605416,3386931726&fm=253',
        name: 'Kitten',
    },
    {
        icon: 'star',
        name: 'Chick',
    },
]);

Setting the Gap ​

html
<!-- Global usage -->
<hy-gird :list="list" gap="10px"></hy-gird>

Setting the Number of Grid Columns ​

html
<!-- Global usage -->
<hy-gird :list="list" col="5"></hy-gird>

Custom Slot ​

html
<template>
    <hy-grid :list="list">
        <template #default="{record}">
            <hy-image :src="record.url" width="80" height="80"></hy-image>
            <text>record.title</text>
        </template>
    </hy-grid>
</template>

<script setup="">
    import { IconConfig } from '@hy-app/ui';
    import { ref } from 'vue';

    // Create reactive data
    const list = ref([
        {
            url: IconConfig.CRY_FILL,
            title: 'Puppy',
        },
        {
            url: 'https://img1.baidu.com/it/u=563605416,3386931726&fm=253',
            title: 'Kitten',
        },
        {
            url: 'star',
            title: 'Chick',
        },
    ]);
</script>

API ​

Grid Props ​

ParameterDescriptionTypeDefault
listDatasetGridItemVo[]-
colNumber of grid columnsnumber4
sizeIcon size, defaults to px for numeric valuesnumber|string4
customKeysCustom keysCustomKeysVo{name: 'name',icon: 'icon'}
borderWhether to show grid bordersbooleanfalse
itemHeightHeight of a single grid cell, defaults to px for numeric valuesstring | number100px
alignGrid alignment; determines left, center, or right alignment when there are few itemscenter|left|rightleft
gapSpacing, defaults to px for numeric valuesstring | number0
bgColorBackground color of the gridstringtransparent
iconPropsIcon property API configuration, see Icon API for detailsHyIconProps-
customStyleCustom external styles to be usedCSSProperties-
customClassCustom external class namestring-

Events ​

Event NameDescriptionCallback Parameters
clickTriggered when a grid cell is clicked(item: GridItemVo | string)

Slots ​

Slot NameDescriptionReceived Values
defaultDefault slotrecord: GridItemVo | string

Typings ​

Type Description
ts
type GridItemVo = {
    /**
     * Icon name or image URL
     * */
    icon?: string;
    /**
     * Name
     * */
    name?: string;
    /**
     * Icon property API configuration
     * */
    iconProps?: Partial<HyIconProps>;
    /**
     * Custom content key-value pairs
     * */
    [key: string]: any;
};

type CustomKeysVo = {
    /**
     * Custom name key
     * */
    name: string;
    /**
     * Custom icon key
     * */
    icon: string;
};

CSS Variables ​

VariableDescriptionDefault
--hy-grid-hover-opacityOpacity of a grid cell when pressed0.7
--hy-grid-borderGrid cell border (right and bottom borders are synchronized)Follows --hy-border-line
12:33
battery