coreui-free-react-admin-template
252 строки · 9.7 Кб
1import React, { useRef, useState } from 'react'2import {3CCard,4CCardHeader,5CCardBody,6CButton,7CRow,8CCol,9CToast,10CToastBody,11CToastClose,12CToastHeader,13CToaster,14} from '@coreui/react'15import { DocsExample } from 'src/components'16
17const ExampleToast = () => {18const [toast, addToast] = useState(0)19const toaster = useRef()20const exampleToast = (21<CToast title="CoreUI for React.js">22<CToastHeader closeButton>23<svg24className="rounded me-2"25width="20"26height="20"27xmlns="http://www.w3.org/2000/svg"28preserveAspectRatio="xMidYMid slice"29focusable="false"30role="img"31>32<rect width="100%" height="100%" fill="#007aff"></rect>33</svg>34<strong className="me-auto">CoreUI for React.js</strong>35<small>7 min ago</small>36</CToastHeader>37<CToastBody>Hello, world! This is a toast message.</CToastBody>38</CToast>39)40return (41<>42<CButton color="primary" onClick={() => addToast(exampleToast)}>43Send a toast
44</CButton>45<CToaster ref={toaster} push={toast} placement="top-end" />46</>47)48}
49
50const Toasts = () => {51return (52<CRow>53<CCol xs={12}>54<CCard className="mb-4">55<CCardHeader>56<strong>React Toast</strong> <small>Basic</small>57</CCardHeader>58<CCardBody>59<p className="text-body-secondary small">60Toasts are as flexible as you need and have very little required markup. At a minimum,61we require a single element to contain your “toasted” content and strongly encourage a
62dismiss button.63</p>64<DocsExample href="components/toast">65<CToast autohide={false} visible={true}>66<CToastHeader closeButton>67<svg68className="rounded me-2"69width="20"70height="20"71xmlns="http://www.w3.org/2000/svg"72preserveAspectRatio="xMidYMid slice"73focusable="false"74role="img"75>76<rect width="100%" height="100%" fill="#007aff"></rect>77</svg>78<strong className="me-auto">CoreUI for React.js</strong>79<small>7 min ago</small>80</CToastHeader>81<CToastBody>Hello, world! This is a toast message.</CToastBody>82</CToast>83</DocsExample>84<DocsExample href="components/toast">{ExampleToast()}</DocsExample>85</CCardBody>86</CCard>87</CCol>88<CCol xs={12}>89<CCard className="mb-4">90<CCardHeader>91<strong>React Toast</strong> <small>Translucent</small>92</CCardHeader>93<CCardBody>94<p className="text-body-secondary small">95Toasts are slightly translucent to blend in with what's below them.96</p>97<DocsExample href="components/toast#translucent" tabContentClassName="bg-dark">98<CToast autohide={false} visible={true}>99<CToastHeader closeButton>100<svg101className="rounded me-2"102width="20"103height="20"104xmlns="http://www.w3.org/2000/svg"105preserveAspectRatio="xMidYMid slice"106focusable="false"107role="img"108>109<rect width="100%" height="100%" fill="#007aff"></rect>110</svg>111<strong className="me-auto">CoreUI for React.js</strong>112<small>7 min ago</small>113</CToastHeader>114<CToastBody>Hello, world! This is a toast message.</CToastBody>115</CToast>116</DocsExample>117</CCardBody>118</CCard>119</CCol>120<CCol xs={12}>121<CCard className="mb-4">122<CCardHeader>123<strong>React Toast</strong> <small>Stacking</small>124</CCardHeader>125<CCardBody>126<p className="text-body-secondary small">127You can stack toasts by wrapping them in a toast container, which will vertically add128some spacing.129</p>130<DocsExample href="components/toast#stacking">131<CToaster className="position-static">132<CToast autohide={false} visible={true}>133<CToastHeader closeButton>134<svg135className="rounded me-2"136width="20"137height="20"138xmlns="http://www.w3.org/2000/svg"139preserveAspectRatio="xMidYMid slice"140focusable="false"141role="img"142>143<rect width="100%" height="100%" fill="#007aff"></rect>144</svg>145<strong className="me-auto">CoreUI for React.js</strong>146<small>7 min ago</small>147</CToastHeader>148<CToastBody>Hello, world! This is a toast message.</CToastBody>149</CToast>150<CToast autohide={false} visible={true}>151<CToastHeader closeButton>152<svg153className="rounded me-2"154width="20"155height="20"156xmlns="http://www.w3.org/2000/svg"157preserveAspectRatio="xMidYMid slice"158focusable="false"159role="img"160>161<rect width="100%" height="100%" fill="#007aff"></rect>162</svg>163<strong className="me-auto">CoreUI for React.js</strong>164<small>7 min ago</small>165</CToastHeader>166<CToastBody>Hello, world! This is a toast message.</CToastBody>167</CToast>168</CToaster>169</DocsExample>170</CCardBody>171</CCard>172</CCol>173<CCol xs={12}>174<CCard className="mb-4">175<CCardHeader>176<strong>React Toast</strong> <small>Custom content</small>177</CCardHeader>178<CCardBody>179<p className="text-body-secondary small">180Customize your toasts by removing sub-components, tweaking them with{' '}181<a href="https://coreui.io/docs/utilities/api">utilities</a>, or by adding your own182markup. Here we've created a simpler toast by removing the default{' '}183<code><CToastHeader></code>, adding a custom hide icon from{' '}184<a href="https://coreui.io/icons/">CoreUI Icons</a>, and using some{' '}185<a href="https://coreui.io/docs/utilities/flex">flexbox utilities</a> to adjust the186layout.187</p>188<DocsExample href="components/toast#custom-content">189<CToast autohide={false} className="align-items-center" visible={true}>190<div className="d-flex">191<CToastBody>Hello, world! This is a toast message.</CToastBody>192<CToastClose className="me-2 m-auto" />193</div>194</CToast>195</DocsExample>196<p className="text-body-secondary small">197Alternatively, you can also add additional controls and components to toasts.198</p>199<DocsExample href="components/toast#custom-content">200<CToast autohide={false} visible={true}>201<CToastBody>202Hello, world! This is a toast message.203<div className="mt-2 pt-2 border-top">204<CButton type="button" color="primary" size="sm">205Take action
206</CButton>207<CToastClose as={CButton} color="secondary" size="sm" className="ms-1">208Close
209</CToastClose>210</div>211</CToastBody>212</CToast>213</DocsExample>214</CCardBody>215</CCard>216</CCol>217<CCol xs={12}>218<CCard className="mb-4">219<CCardHeader>220<strong>React Toast</strong> <small>Custom content</small>221</CCardHeader>222<CCardBody>223<p className="text-body-secondary small">224Building on the above example, you can create different toast color schemes with our{' '}225<a href="https://coreui.io/docs/utilities/colors">color</a> and{' '}226<a href="https://coreui.io/docs/utilities/background">background</a> utilities. Here227we've set <code>color="primary"</code> and added <code>.text-white</code>{' '}228class to the <code><Ctoast></code>, and then set <code>white</code> property to229our close button. For a crisp edge, we remove the default border with{' '}230<code>.border-0</code>.231</p>232<DocsExample href="components/toast#color-schemes">233<CToast234autohide={false}235color="primary"236className="text-white align-items-center"237visible={true}238>239<div className="d-flex">240<CToastBody>Hello, world! This is a toast message.</CToastBody>241<CToastClose className="me-2 m-auto" white />242</div>243</CToast>244</DocsExample>245</CCardBody>246</CCard>247</CCol>248</CRow>249)250}
251
252export default Toasts253