|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +import { Meta, StoryFn } from '@storybook/react'; |
| 20 | +import { Layout, Row, Col, Card } from 'antd-v5'; |
| 21 | +import ErrorAlert from './ErrorAlert'; |
| 22 | + |
| 23 | +const { Content } = Layout; |
| 24 | + |
| 25 | +const longDescription = `This is a detailed description to test long content display. |
| 26 | +Line breaks are included here to demonstrate pre-wrap styling. |
| 27 | +This is useful for verbose error messages.`; |
| 28 | + |
| 29 | +const sqlErrorDescription = `SQL Error: Syntax error near unexpected token. |
| 30 | +Please check your query and ensure it follows the correct syntax.`; |
| 31 | + |
| 32 | +const detailsExample = `Additional details about the issue are provided here. |
| 33 | +This content is shown when the user clicks "Show more".`; |
| 34 | + |
| 35 | +const ErrorCard: React.FC<{ children: React.ReactNode }> = ({ children }) => ( |
| 36 | + <Card>{children}</Card> |
| 37 | +); |
| 38 | + |
| 39 | +export default { |
| 40 | + title: 'Components/ErrorAlert', |
| 41 | + component: ErrorAlert, |
| 42 | +} as Meta; |
| 43 | + |
| 44 | +export const Gallery: StoryFn = () => ( |
| 45 | + <Layout> |
| 46 | + <Content style={{ padding: '24px' }}> |
| 47 | + <h2>Non-Compact Errors</h2> |
| 48 | + <Row gutter={[16, 16]}> |
| 49 | + <Col xs={48} sm={24} md={16} lg={16} xl={12}> |
| 50 | + <ErrorCard> |
| 51 | + <ErrorAlert message="Only message props was passed here" /> |
| 52 | + </ErrorCard> |
| 53 | + </Col> |
| 54 | + <Col xs={48} sm={24} md={16} lg={16} xl={12}> |
| 55 | + <ErrorCard> |
| 56 | + <ErrorAlert |
| 57 | + errorType="Database Connection Error" |
| 58 | + type="warning" |
| 59 | + message="Failed to connect to database" |
| 60 | + descriptionDetails={detailsExample} |
| 61 | + descriptionDetailsCollapsed |
| 62 | + /> |
| 63 | + </ErrorCard> |
| 64 | + </Col> |
| 65 | + <Col xs={48} sm={24} md={16} lg={16} xl={12}> |
| 66 | + <ErrorCard> |
| 67 | + <ErrorAlert |
| 68 | + errorType="Error" |
| 69 | + message="SQL Syntax Error - No defaults set here" |
| 70 | + description={sqlErrorDescription} |
| 71 | + descriptionDetails={detailsExample} |
| 72 | + descriptionDetailsCollapsed |
| 73 | + descriptionPre |
| 74 | + /> |
| 75 | + </ErrorCard> |
| 76 | + </Col> |
| 77 | + <Col xs={48} sm={24} md={16} lg={16} xl={12}> |
| 78 | + <ErrorCard> |
| 79 | + <ErrorAlert |
| 80 | + errorType="Error" |
| 81 | + message="See the details below" |
| 82 | + type="error" |
| 83 | + description={longDescription} |
| 84 | + descriptionDetails={detailsExample} |
| 85 | + descriptionDetailsCollapsed={false} |
| 86 | + /> |
| 87 | + </ErrorCard> |
| 88 | + </Col> |
| 89 | + <Col xs={48} sm={24} md={16} lg={16} xl={12}> |
| 90 | + <ErrorCard> |
| 91 | + <ErrorAlert |
| 92 | + errorType="Informational Warning" |
| 93 | + message="This is a non-pre-wrap styled description" |
| 94 | + type="info" |
| 95 | + description={longDescription} |
| 96 | + descriptionDetails={detailsExample} |
| 97 | + descriptionDetailsCollapsed={false} |
| 98 | + descriptionPre={false} |
| 99 | + /> |
| 100 | + </ErrorCard> |
| 101 | + </Col> |
| 102 | + <Col xs={24} sm={12} md={8} lg={8} xl={6}> |
| 103 | + <ErrorCard> |
| 104 | + <ErrorAlert |
| 105 | + errorType="Error" |
| 106 | + message="Something went wrong" |
| 107 | + type="error" |
| 108 | + /> |
| 109 | + </ErrorCard> |
| 110 | + </Col> |
| 111 | + <Col xs={24} sm={12} md={8} lg={8} xl={6}> |
| 112 | + <ErrorCard> |
| 113 | + <ErrorAlert |
| 114 | + errorType="Warning" |
| 115 | + message="Be cautious" |
| 116 | + type="warning" |
| 117 | + /> |
| 118 | + </ErrorCard> |
| 119 | + </Col> |
| 120 | + </Row> |
| 121 | + <h2>Compact Errors (with Modal)</h2> |
| 122 | + <Row gutter={[16, 16]}> |
| 123 | + <Col xs={24} sm={12} md={8} lg={8} xl={6}> |
| 124 | + <ErrorCard> |
| 125 | + <ErrorAlert |
| 126 | + errorType="Error" |
| 127 | + message="Compact mode example" |
| 128 | + type="error" |
| 129 | + compact |
| 130 | + descriptionDetailsCollapsed |
| 131 | + description={sqlErrorDescription} |
| 132 | + descriptionDetails={detailsExample} |
| 133 | + /> |
| 134 | + </ErrorCard> |
| 135 | + </Col> |
| 136 | + <Col xs={24} sm={12} md={8} lg={8} xl={6}> |
| 137 | + <ErrorCard> |
| 138 | + <ErrorAlert |
| 139 | + errorType="Warning" |
| 140 | + message="Compact mode example" |
| 141 | + type="warning" |
| 142 | + compact |
| 143 | + descriptionDetails={detailsExample} |
| 144 | + descriptionDetailsCollapsed |
| 145 | + /> |
| 146 | + </ErrorCard> |
| 147 | + </Col> |
| 148 | + </Row> |
| 149 | + </Content> |
| 150 | + </Layout> |
| 151 | +); |
0 commit comments