Nhảy tới nội dung

Sheet

Sheet component: Tạo bottom sheet modal

Properties

Sheet

NameTypeDefaultDescriptionMinimum Version
maskboolean

Hiển thị mask khi show sheet

afterClosefunction

Function gọi sai khi close sheet

onClosefunction

Function gọi khi close sheet

maskClosableboolean

Đóng sheet khi click bào mask

visibleboolean

Hiển thị sheet modal

unmountOnClosebooleanfalseUnmount sau khi đóng sheet modal1.6.0
titlestring

Title của sheet modal

modalStyleReact.CSSProperties

Style modal

maskStyleReact.CSSProperties

Style mask

modalClassNamestring

Modal class name

maskClassNamestring

Mask class name

widthstring | number

Sheet width

heightstring | number

Sheet height

descriptionstring

Sheet description

childrenReact.ReactNode

Nội dung sheet

zIndexnumber

Giá trị z-index của modal

handlerboolean

Sheet handler

autoHeightbooleanfalse

Chiều cao của sheet ôm theo content

swipeToCloseboolean

Vuốt xuống để đóng sheet modal

snapPointsnumber[] |
({sheetModalHeight}) => number[]

Các snap points là vị trí của action sheet tính theo thuộc tính bottom css

  • number[]: các snap points tính theo %, với 1 (100%) -> 0(0%)
  • ({sheetModalHeight}) => number[]: callback function với arg chứa chiều cao của sheet, cần return mảng các snap points tính theo px
defaultSnapPointnumber

Index của snapPoints mặc định khi mở sheet modal

onSnap(snapPoint: number) => voidcallback function khi expand/collapse đến một snap point mới
refSheetRefSheet modal ref

Type

SheetRef

NameTypeDefaultDescription
sheetHTMLDivElement

Sheet modal element

snapTo(index: number)=> void

Expand/collapse Sheet modal đến snap point cụ thể trong snapPoints đã khai báo

Sheet.Action

NameTypeDefaultDescription
dividerboolean

Có divider giữa các action

actionsActionButton[]

Danh sách các action

groupDividerboolean

Có divider giữa các group action

ActionButton

NameTypeDefaultDescription
highLightboolean

Nếu giá trị là true action sẽ có kiểu highlight

dangerboolean

Nếu giá trị là true action sẽ có kiểu danger

onClickfunction

Function sẽ được gọi khi click action

closeboolean

Action sau khi click sẽ close modal

disabledboolean

Disable action

Example

import React, { useRef, useState } from 'react';
import { Button, Sheet, Text, Box, Page } from 'zmp-ui';

export default function Demo() {
  const [sheetVisible, setSheetVisible] = useState(false);
  const [actionSheetVisible, setActionSheetVisible] = useState(false);
  return (
    <Page className='section-container'>
      <Text.Title size='small'>Bottom Sheet</Text.Title>
      <Box mt={4}>
        <Button
          variant='secondary'
          fullWidth
          onClick={() => {
            setActionSheetVisible(true);
          }}
        >
          Bottom Action Sheet
        </Button>
      </Box>
      <Box mt={4}>
        <Button
          variant='secondary'
          fullWidth
          onClick={() => {
            setSheetVisible(true);
          }}
        >
          Custom Bottom Sheet
        </Button>
      </Box>

      <Sheet
        visible={sheetVisible}
        onClose={() => setSheetVisible(false)}
        autoHeight
        mask
        handler
        swipeToClose
      >
        <Box p={4} className='custom-bottom-sheet' flex flexDirection='column'>
          <Box className='bottom-sheet-cover'>
            <img alt='Bottom Sheet' src={''} />
          </Box>
          <Box my={4}>
            <Text.Title>
              Cho phép Starbucks Coffee xác định vị trí của bạn
            </Text.Title>
          </Box>
          <Box className='bottom-sheet-body' style={{ overflowY: 'auto' }}>
            <Text>
              Starbucks Coffee sẽ sử dụng vị trí của bạn để hỗ trợ giao nhận
              hàng, tìm kiếm dịch vụ, bạn bè quanh bạn, hoặc các dịch vụ liên
              quan đến địa điểm khác.
            </Text>
          </Box>
          <Box flex flexDirection='row' mt={1}>
            <Box style={{ flex: 1 }} pr={1}>
              <Button
                fullWidth
                variant='secondary'
                onClick={() => {
                  setSheetVisible(false);
                }}
              >
                Để sau
              </Button>
            </Box>
            <Box style={{ flex: 1 }} pl={1}>
              <Button
                fullWidth
                onClick={() => {
                  setSheetVisible(false);
                }}
              >
                Cho phép
              </Button>
            </Box>
          </Box>
        </Box>
      </Sheet>

      <Sheet.Actions
        mask
        visible={actionSheetVisible}
        title='This is title, it can be one line or two line'
        onClose={() => setActionSheetVisible(false)}
        swipeToClose
        actions={[
          [
            { text: 'Sample Menu', close: true },
            { text: 'Sample Menu', close: true },
            {
              text: 'Negative Menu',
              danger: true,
              close: true
            }
          ],
          [{ text: 'Cancel', close: true }]
        ]}
      />
    </Page>
  );
}