對話框是一種模態視窗,它會出現在應用程式內容的前面,以提供重要資訊或提示使用者做出決定。
包含下列元件
Dialog
- 對話框元素DialogButton
- 對話框按鈕元素名稱 | 類型 | 預設值 | 描述 |
---|---|---|---|
背景 | 布林值 | true | 啟用快顯視窗背景(後面的深色半透明圖層) |
按鈕 | ReactNode | 對話框按鈕內容 | |
色彩 | 物件 | 具有 Tailwind CSS 色彩類別的物件 | |
colors.bgIos | 字串 | 'bg-white dark:bg-neutral-800' | iOS 主題中的對話框背景色彩 |
colors.bgMaterial | 字串 | 'bg-md-light-surface-3 dark:bg-md-dark-surface-3' | iOS 主題中的對話框背景色彩 |
colors.contentTextIos | 字串 | '' | iOS 主題中的內容文字色彩 |
colors.contentTextMaterial | 字串 | 'text-md-light-on-surface-variant dark:text-md-dark-on-surface-variant' | Material 主題中的內容文字色彩 |
colors.titleIos | 字串 | '' | iOS 主題中的標題文字色彩 |
colors.titleMaterial | 字串 | 'text-md-light-on-surface dark:text-md-dark-on-surface' | Material 主題中的標題文字色彩 |
元件 | 字串 | 'div' | 元件的 HTML 元素 |
內容 | ReactNode | 對話框主要內容 | |
已開啟 | 布林值 | false | 允許開啟/關閉快顯視窗並設定其初始狀態 |
sizeIos | 字串 | 'w-[16.875rem]' | iOS 主題的 Tailwind CSS 大小類別 |
sizeMaterial | 字串 | 'w-[19.5rem]' | Material 主題的 Tailwind CSS 大小類別 |
標題 | ReactNode | 對話框標題內容 | |
titleFontSizeIos | 字串 | 'text-[18px]' | iOS 主題的標題字型大小 Tailwind CSS 類別 |
titleFontSizeMaterial | 字串 | 'text-[24px]' | Material 主題的標題字型大小 Tailwind CSS 類別 |
半透明 | 布林值 | true | 在 iOS 主題中使對話框背景變為半透明 (使用 |
onBackdropClick | function(e) | 背景元素上的點擊處理常式 |
名稱 | 類型 | 預設值 | 描述 |
---|---|---|---|
色彩 | 物件 | 具有 Tailwind CSS 色彩類別的物件 | |
colors.activeBgIos | 字串 | 'active:bg-black active:bg-opacity-10 dark:active:bg-white dark:active:bg-opacity-10' | iOS 主題中的啟用/按下狀態背景色彩 |
colors.disabledTextIos | 字串 | 'text-black text-opacity-30 dark:text-white dark:text-opacity-30' | iOS 主題中的停用按鈕文字色彩 |
colors.textIos | 字串 | ''text-primary | iOS 主題中的文字色彩 |
元件 | 字串 | 'button' | 元件的 HTML 元素 |
停用 | 布林值 | false | 使按鈕停用 |
強 | 布林值 | false | 使按鈕在 iOS 主題中加粗,在 Material 主題中填滿,覆寫 |
strongIos | 布林值 | false | 使按鈕在 iOS 主題中加粗 |
strongMaterial | 布林值 | false | 使按鈕在 Material 主題中填滿 |
onClick | function(e) | DialogButton 點擊處理常式 |
import React, { useState } from 'react';import {Page,Navbar,NavbarBackLink,Dialog,DialogButton,Block,List,ListItem,Radio,Button,} from 'konsta/react';export default function DialogPage() {const [basicOpened, setBasicOpened] = useState(false);const [alertOpened, setAlertOpened] = useState(false);const [confirmOpened, setConfirmOpened] = useState(false);const [listOpened, setListOpened] = useState(false);const [radioValue, setRadioValue] = useState('batman');return (<Page><Navbartitle="Dialog"/><Block strong inset className="space-y-4"><p>Dialog is a type of modal window that appears in front of app contentto provide critical information, or prompt for a decision to be made.</p></Block><Block strong inset><p className="grid grid-cols-2 md:grid-cols-4 gap-4"><Button rounded onClick={() => setBasicOpened(true)}>Basic</Button><Button rounded onClick={() => setAlertOpened(true)}>Alert</Button><Button rounded onClick={() => setConfirmOpened(true)}>Confirm</Button><Button rounded onClick={() => setListOpened(true)}>List</Button></p></Block><Dialogopened={basicOpened}onBackdropClick={() => setBasicOpened(false)}title="Dialog Title"content="Dialog is a type of modal window that appears in front of app content to provide critical information, or prompt for a decision to be made."buttons={<><DialogButton onClick={() => setBasicOpened(false)}>Action 2</DialogButton><DialogButton onClick={() => setBasicOpened(false)}>Action 1</DialogButton></>}/><Dialogopened={alertOpened}onBackdropClick={() => setAlertOpened(false)}title="Konsta UI"content="Hello world!"buttons={<DialogButton onClick={() => setAlertOpened(false)}>Ok</DialogButton>}/><Dialogopened={confirmOpened}onBackdropClick={() => setConfirmOpened(false)}title="Konsta UI"content="All good today?"buttons={<><DialogButton onClick={() => setConfirmOpened(false)}>No</DialogButton><DialogButton strong onClick={() => setConfirmOpened(false)}>Yes</DialogButton></>}/><Dialogopened={listOpened}onBackdropClick={() => setListOpened(false)}title="Your super hero"content={<List nested className="-mx-4"><ListItemlabeltitle="Batman"after={<Radiocomponent="div"value="batman"checked={radioValue === 'batman'}onChange={() => setRadioValue('batman')}/>}/><ListItemlabeltitle="Spider-man"after={<Radiocomponent="div"value="spiderman"checked={radioValue === 'spiderman'}onChange={() => setRadioValue('spiderman')}/>}/><ListItemlabeltitle="Hulk"after={<Radiocomponent="div"value="hulk"checked={radioValue === 'hulk'}onChange={() => setRadioValue('hulk')}/>}/></List>}buttons={<DialogButton onClick={() => setListOpened(false)}>Confirm</DialogButton>}/></Page>);}