🔥 隆重推出我們的新專案 t0ggles - 您終極的專案管理工具! 🔥

Dialog React 元件

對話框是一種模態視窗,它會出現在應用程式內容的前面,以提供重要資訊或提示使用者做出決定。

對話框元件

包含下列元件

  • 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 主題中使對話框背景變為半透明 (使用 backdrop-filter: blur)

onBackdropClickfunction(e)

背景元素上的點擊處理常式

DialogButton 屬性

名稱類型預設值描述
色彩物件

具有 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 主題中填滿,覆寫 strongIosstrongMaterial

strongIos布林值false

使按鈕在 iOS 主題中加粗

strongMaterial布林值false

使按鈕在 Material 主題中填滿

onClickfunction(e)

DialogButton 點擊處理常式

範例

Dialog.jsx
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>
<Navbar
title="Dialog"
/>
<Block strong inset className="space-y-4">
<p>
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.
</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>
<Dialog
opened={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>
</>
}
/>
<Dialog
opened={alertOpened}
onBackdropClick={() => setAlertOpened(false)}
title="Konsta UI"
content="Hello world!"
buttons={
<DialogButton onClick={() => setAlertOpened(false)}>Ok</DialogButton>
}
/>
<Dialog
opened={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>
</>
}
/>
<Dialog
opened={listOpened}
onBackdropClick={() => setListOpened(false)}
title="Your super hero"
content={
<List nested className="-mx-4">
<ListItem
label
title="Batman"
after={
<Radio
component="div"
value="batman"
checked={radioValue === 'batman'}
onChange={() => setRadioValue('batman')}
/>
}
/>
<ListItem
label
title="Spider-man"
after={
<Radio
component="div"
value="spiderman"
checked={radioValue === 'spiderman'}
onChange={() => setRadioValue('spiderman')}
/>
}
/>
<ListItem
label
title="Hulk"
after={
<Radio
component="div"
value="hulk"
checked={radioValue === 'hulk'}
onChange={() => setRadioValue('hulk')}
/>
}
/>
</List>
}
buttons={
<DialogButton onClick={() => setListOpened(false)}>
Confirm
</DialogButton>
}
/>
</Page>
);
}
程式碼授權條款為 MIT.
2022 © Konsta UI 作者 nolimits4web.