Chuyển tới nội dung chính
Phiên bản: 1.10.0

Implementation

Được sử dụng để hiển thị thông tin bổ sung hoặc để người dùng thực hiện một số hành động phụ liên quan đến nội dung chính trên màn hình, tiếp tục sử dụng tiếp một tính năng của ứng dụng

Properties

Sheet

NameTypeDefaultDescriptionMinimum Version
maskbooleanHiển thị mask khi show sheet
afterClosefunctionFunction gọi sai khi close sheet
onClosefunctionFunction gọi khi close sheet
maskClosablebooleanĐóng sheet khi click bào mask
visiblebooleanHiển thị sheet modal
unmountOnClosebooleanfalseUnmount sau khi đóng sheet modal1.6.0
titlestringTitle của sheet modal
modalStyleReact.CSSPropertiesStyle modal
maskStyleReact.CSSPropertiesStyle mask
modalClassNamestringModal class name
maskClassNamestringMask class name
widthstring | numberSheet width
heightstring | numberSheet height
descriptionstringSheet description
childrenReact.ReactNodeNội dung sheet
zIndexnumberGiá trị z-index của modal
handlerbooleanSheet handler
autoHeightbooleanfalseChiều cao của sheet ôm theo content
swipeToClosebooleanVuố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
defaultSnapPointnumberIndex 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
sheetHTMLDivElementSheet modal element
snapTo(index: number)=> voidExpand/collapse Sheet modal đến snap point cụ thể trong snapPoints đã khai báo

Sheet.Action

NameTypeDefaultDescription
dividerbooleanCó divider giữa các action
actionsActionButton[]Danh sách các action
groupDividerbooleanCó divider giữa các group action

ActionButton

NameTypeDefaultDescription
highLightbooleanNếu giá trị là true action sẽ có kiểu highlight
dangerbooleanNếu giá trị là true action sẽ có kiểu danger
onClickfunctionFunction sẽ được gọi khi click action
closebooleanAction sau khi click sẽ close modal
disabledbooleanDisable 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>
  );
}