@memori.ai/ui 1.0.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -0
- package/dist/components/Alert/Alert.d.ts +18 -0
- package/dist/components/Alert/index.d.ts +2 -0
- package/dist/components/Button/Button.d.ts +27 -0
- package/dist/components/Button/index.d.ts +2 -0
- package/dist/components/ButtonBase/ButtonBase.d.ts +28 -0
- package/dist/components/ButtonBase/index.d.ts +3 -0
- package/dist/components/Card/Card.d.ts +13 -0
- package/dist/components/Card/index.d.ts +2 -0
- package/dist/components/Checkbox/Checkbox.d.ts +11 -0
- package/dist/components/Checkbox/index.d.ts +2 -0
- package/dist/components/ConfirmDialog/ConfirmDialog.d.ts +12 -0
- package/dist/components/ConfirmDialog/index.d.ts +2 -0
- package/dist/components/Drawer/Drawer.d.ts +32 -0
- package/dist/components/Drawer/index.d.ts +2 -0
- package/dist/components/Dropdown/Dropdown.d.ts +11 -0
- package/dist/components/Dropdown/index.d.ts +2 -0
- package/dist/components/Expandable/Expandable.d.ts +15 -0
- package/dist/components/Expandable/helpers.d.ts +3 -0
- package/dist/components/Expandable/index.d.ts +2 -0
- package/dist/components/InputBase/InputBase.d.ts +49 -0
- package/dist/components/InputBase/index.d.ts +3 -0
- package/dist/components/Modal/Modal.d.ts +16 -0
- package/dist/components/Modal/index.d.ts +2 -0
- package/dist/components/Select/Select.d.ts +16 -0
- package/dist/components/Select/index.d.ts +2 -0
- package/dist/components/Slider/Slider.d.ts +12 -0
- package/dist/components/Slider/index.d.ts +2 -0
- package/dist/components/Spin/Spin.d.ts +9 -0
- package/dist/components/Spin/index.d.ts +2 -0
- package/dist/components/Tooltip/Tooltip.d.ts +11 -0
- package/dist/components/Tooltip/index.d.ts +2 -0
- package/dist/i18n/I18nWrapper.d.ts +6 -0
- package/dist/icons/AI.d.ts +5 -0
- package/dist/icons/Alert.d.ts +5 -0
- package/dist/icons/ArrowUp.d.ts +5 -0
- package/dist/icons/Bug.d.ts +5 -0
- package/dist/icons/Chat.d.ts +5 -0
- package/dist/icons/ChevronDown.d.ts +5 -0
- package/dist/icons/ChevronLeft.d.ts +5 -0
- package/dist/icons/ChevronRight.d.ts +5 -0
- package/dist/icons/ChevronUp.d.ts +5 -0
- package/dist/icons/Clear.d.ts +5 -0
- package/dist/icons/Close.d.ts +6 -0
- package/dist/icons/Code.d.ts +5 -0
- package/dist/icons/Copy.d.ts +5 -0
- package/dist/icons/DeepThought.d.ts +5 -0
- package/dist/icons/Delete.d.ts +5 -0
- package/dist/icons/Document.d.ts +5 -0
- package/dist/icons/Download.d.ts +5 -0
- package/dist/icons/Edit.d.ts +5 -0
- package/dist/icons/Expand.d.ts +5 -0
- package/dist/icons/Eye.d.ts +5 -0
- package/dist/icons/EyeInvisible.d.ts +5 -0
- package/dist/icons/Facebook.d.ts +5 -0
- package/dist/icons/Feedback.d.ts +5 -0
- package/dist/icons/File.d.ts +5 -0
- package/dist/icons/FileExcel.d.ts +5 -0
- package/dist/icons/FilePdf.d.ts +5 -0
- package/dist/icons/FileWord.d.ts +5 -0
- package/dist/icons/Fullscreen.d.ts +5 -0
- package/dist/icons/FullscreenExit.d.ts +5 -0
- package/dist/icons/Group.d.ts +5 -0
- package/dist/icons/History.d.ts +6 -0
- package/dist/icons/Image.d.ts +4 -0
- package/dist/icons/Info.d.ts +5 -0
- package/dist/icons/Link.d.ts +5 -0
- package/dist/icons/Linkedin.d.ts +5 -0
- package/dist/icons/Loading.d.ts +6 -0
- package/dist/icons/Logout.d.ts +5 -0
- package/dist/icons/Mail.d.ts +5 -0
- package/dist/icons/MapMarker.d.ts +5 -0
- package/dist/icons/MenuHorizontal.d.ts +6 -0
- package/dist/icons/MenuVertical.d.ts +6 -0
- package/dist/icons/Message.d.ts +5 -0
- package/dist/icons/Microphone.d.ts +5 -0
- package/dist/icons/Minus.d.ts +5 -0
- package/dist/icons/MinusCircle.d.ts +5 -0
- package/dist/icons/PaperClip.d.ts +5 -0
- package/dist/icons/Picture.d.ts +5 -0
- package/dist/icons/Plus.d.ts +5 -0
- package/dist/icons/Preview.d.ts +4 -0
- package/dist/icons/Print.d.ts +6 -0
- package/dist/icons/QuestionHelp.d.ts +5 -0
- package/dist/icons/Refresh.d.ts +5 -0
- package/dist/icons/SelectIcon.d.ts +5 -0
- package/dist/icons/Send.d.ts +5 -0
- package/dist/icons/Setting.d.ts +5 -0
- package/dist/icons/Share.d.ts +5 -0
- package/dist/icons/Sound.d.ts +5 -0
- package/dist/icons/SoundDeactivated.d.ts +5 -0
- package/dist/icons/Telegram.d.ts +5 -0
- package/dist/icons/ThumbDown.d.ts +5 -0
- package/dist/icons/ThumbUp.d.ts +5 -0
- package/dist/icons/Translation.d.ts +5 -0
- package/dist/icons/Twitter.d.ts +5 -0
- package/dist/icons/Upload.d.ts +4 -0
- package/dist/icons/User.d.ts +5 -0
- package/dist/icons/Warning.d.ts +5 -0
- package/dist/icons/WhatsApp.d.ts +5 -0
- package/dist/index.d.ts +13 -0
- package/dist/memori-ai-ui.css +2 -0
- package/dist/memori-ai-ui.es.js +6400 -0
- package/dist/memori-ai-ui.umd.js +23 -0
- package/package.json +97 -0
- package/src/components/Alert/Alert.css +95 -0
- package/src/components/Alert/Alert.stories.tsx +156 -0
- package/src/components/Alert/Alert.test.tsx +122 -0
- package/src/components/Alert/Alert.tsx +124 -0
- package/src/components/Alert/__snapshots__/Alert.test.tsx.snap +67 -0
- package/src/components/Alert/index.tsx +2 -0
- package/src/components/Button/Button.css +173 -0
- package/src/components/Button/Button.stories.tsx +173 -0
- package/src/components/Button/Button.test.tsx +80 -0
- package/src/components/Button/Button.tsx +104 -0
- package/src/components/Button/__snapshots__/Button.test.tsx.snap +204 -0
- package/src/components/Button/index.tsx +2 -0
- package/src/components/ButtonBase/ButtonBase.stories.tsx +194 -0
- package/src/components/ButtonBase/ButtonBase.tsx +84 -0
- package/src/components/ButtonBase/index.tsx +3 -0
- package/src/components/ButtonBase/styles.module.css +135 -0
- package/src/components/Card/Card.css +67 -0
- package/src/components/Card/Card.stories.tsx +104 -0
- package/src/components/Card/Card.test.tsx +67 -0
- package/src/components/Card/Card.tsx +58 -0
- package/src/components/Card/__snapshots__/Card.test.tsx.snap +321 -0
- package/src/components/Card/index.tsx +2 -0
- package/src/components/Checkbox/Checkbox.css +114 -0
- package/src/components/Checkbox/Checkbox.stories.tsx +77 -0
- package/src/components/Checkbox/Checkbox.test.tsx +50 -0
- package/src/components/Checkbox/Checkbox.tsx +61 -0
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +131 -0
- package/src/components/Checkbox/index.tsx +2 -0
- package/src/components/ConfirmDialog/ConfirmDialog.css +44 -0
- package/src/components/ConfirmDialog/ConfirmDialog.stories.tsx +235 -0
- package/src/components/ConfirmDialog/ConfirmDialog.test.tsx +129 -0
- package/src/components/ConfirmDialog/ConfirmDialog.tsx +73 -0
- package/src/components/ConfirmDialog/__snapshots__/ConfirmDialog.test.tsx.snap +11 -0
- package/src/components/ConfirmDialog/index.tsx +2 -0
- package/src/components/Details/Details.css +66 -0
- package/src/components/Details/Details.stories.tsx +67 -0
- package/src/components/Drawer/Drawer.css +210 -0
- package/src/components/Drawer/Drawer.stories.tsx +275 -0
- package/src/components/Drawer/Drawer.test.tsx +158 -0
- package/src/components/Drawer/Drawer.tsx +242 -0
- package/src/components/Drawer/__snapshots__/Drawer.test.tsx.snap +21 -0
- package/src/components/Drawer/index.tsx +2 -0
- package/src/components/Dropdown/Dropdown.css +177 -0
- package/src/components/Dropdown/Dropdown.stories.tsx +73 -0
- package/src/components/Dropdown/Dropdown.test.tsx +88 -0
- package/src/components/Dropdown/Dropdown.tsx +88 -0
- package/src/components/Dropdown/__snapshots__/Dropdown.test.tsx.snap +141 -0
- package/src/components/Dropdown/index.tsx +2 -0
- package/src/components/Expandable/Expandable.css +15 -0
- package/src/components/Expandable/Expandable.stories.tsx +196 -0
- package/src/components/Expandable/Expandable.test.tsx +143 -0
- package/src/components/Expandable/Expandable.tsx +122 -0
- package/src/components/Expandable/__snapshots__/Expandable.test.tsx.snap +199 -0
- package/src/components/Expandable/helpers.ts +16 -0
- package/src/components/Expandable/index.tsx +2 -0
- package/src/components/InputBase/InputBase.stories.tsx +237 -0
- package/src/components/InputBase/InputBase.tsx +105 -0
- package/src/components/InputBase/index.tsx +3 -0
- package/src/components/InputBase/styles.module.css +96 -0
- package/src/components/Modal/Modal.css +95 -0
- package/src/components/Modal/Modal.stories.tsx +184 -0
- package/src/components/Modal/Modal.test.tsx +129 -0
- package/src/components/Modal/Modal.tsx +124 -0
- package/src/components/Modal/__snapshots__/Modal.test.tsx.snap +17 -0
- package/src/components/Modal/index.tsx +2 -0
- package/src/components/Select/Select.css +134 -0
- package/src/components/Select/Select.stories.tsx +85 -0
- package/src/components/Select/Select.test.tsx +85 -0
- package/src/components/Select/Select.tsx +84 -0
- package/src/components/Select/__snapshots__/Select.test.tsx.snap +261 -0
- package/src/components/Select/index.tsx +2 -0
- package/src/components/Slider/Slider.css +194 -0
- package/src/components/Slider/Slider.stories.tsx +85 -0
- package/src/components/Slider/Slider.test.tsx +55 -0
- package/src/components/Slider/Slider.tsx +157 -0
- package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +419 -0
- package/src/components/Slider/index.tsx +2 -0
- package/src/components/Spin/Spin.css +31 -0
- package/src/components/Spin/Spin.stories.tsx +65 -0
- package/src/components/Spin/Spin.test.tsx +47 -0
- package/src/components/Spin/Spin.tsx +34 -0
- package/src/components/Spin/__snapshots__/Spin.test.tsx.snap +193 -0
- package/src/components/Spin/index.tsx +2 -0
- package/src/components/Table/Table.css +130 -0
- package/src/components/Table/Table.stories.tsx +274 -0
- package/src/components/Tooltip/Tooltip.css +160 -0
- package/src/components/Tooltip/Tooltip.stories.tsx +136 -0
- package/src/components/Tooltip/Tooltip.test.tsx +110 -0
- package/src/components/Tooltip/Tooltip.tsx +46 -0
- package/src/components/Tooltip/__snapshots__/Tooltip.test.tsx.snap +163 -0
- package/src/components/Tooltip/index.tsx +2 -0
- package/src/components/definitions.stories.tsx +150 -0
- package/src/i18n/I18nWrapper.tsx +13 -0
- package/src/i18n/i18n.ts +34 -0
- package/src/icons/AI.tsx +38 -0
- package/src/icons/Alert.tsx +31 -0
- package/src/icons/ArrowUp.tsx +28 -0
- package/src/icons/Bug.tsx +81 -0
- package/src/icons/Chat.tsx +30 -0
- package/src/icons/ChevronDown.tsx +26 -0
- package/src/icons/ChevronLeft.tsx +28 -0
- package/src/icons/ChevronRight.tsx +28 -0
- package/src/icons/ChevronUp.tsx +24 -0
- package/src/icons/Clear.tsx +23 -0
- package/src/icons/Close.tsx +30 -0
- package/src/icons/Code.tsx +30 -0
- package/src/icons/Copy.tsx +30 -0
- package/src/icons/DeepThought.tsx +38 -0
- package/src/icons/Delete.tsx +23 -0
- package/src/icons/Document.tsx +52 -0
- package/src/icons/Download.tsx +23 -0
- package/src/icons/Edit.tsx +17 -0
- package/src/icons/Expand.tsx +23 -0
- package/src/icons/Eye.tsx +17 -0
- package/src/icons/EyeInvisible.tsx +24 -0
- package/src/icons/Facebook.tsx +23 -0
- package/src/icons/Feedback.tsx +27 -0
- package/src/icons/File.tsx +17 -0
- package/src/icons/FileExcel.tsx +23 -0
- package/src/icons/FilePdf.tsx +23 -0
- package/src/icons/FileWord.tsx +23 -0
- package/src/icons/Fullscreen.tsx +23 -0
- package/src/icons/FullscreenExit.tsx +23 -0
- package/src/icons/Group.tsx +30 -0
- package/src/icons/History.tsx +33 -0
- package/src/icons/Image.tsx +37 -0
- package/src/icons/Info.tsx +37 -0
- package/src/icons/Link.tsx +17 -0
- package/src/icons/Linkedin.tsx +23 -0
- package/src/icons/Loading.tsx +28 -0
- package/src/icons/Logout.tsx +33 -0
- package/src/icons/Mail.tsx +17 -0
- package/src/icons/MapMarker.tsx +26 -0
- package/src/icons/MenuHorizontal.tsx +29 -0
- package/src/icons/MenuVertical.tsx +29 -0
- package/src/icons/Message.tsx +23 -0
- package/src/icons/Microphone.tsx +23 -0
- package/src/icons/Minus.tsx +23 -0
- package/src/icons/MinusCircle.tsx +24 -0
- package/src/icons/PaperClip.tsx +23 -0
- package/src/icons/Picture.tsx +23 -0
- package/src/icons/Plus.tsx +18 -0
- package/src/icons/Preview.tsx +31 -0
- package/src/icons/Print.tsx +37 -0
- package/src/icons/QuestionHelp.tsx +34 -0
- package/src/icons/Refresh.tsx +30 -0
- package/src/icons/SelectIcon.tsx +28 -0
- package/src/icons/Send.tsx +17 -0
- package/src/icons/Setting.tsx +23 -0
- package/src/icons/Share.tsx +23 -0
- package/src/icons/Sound.tsx +23 -0
- package/src/icons/SoundDeactivated.tsx +27 -0
- package/src/icons/Telegram.tsx +26 -0
- package/src/icons/ThumbDown.tsx +29 -0
- package/src/icons/ThumbUp.tsx +29 -0
- package/src/icons/Translation.tsx +24 -0
- package/src/icons/Twitter.tsx +23 -0
- package/src/icons/Upload.tsx +34 -0
- package/src/icons/User.tsx +17 -0
- package/src/icons/Warning.tsx +27 -0
- package/src/icons/WhatsApp.tsx +24 -0
- package/src/icons/icons.stories.css +5 -0
- package/src/icons/icons.stories.tsx +110 -0
- package/src/icons/loading.css +14 -0
- package/src/index.ts +15 -0
- package/src/styles/utils.css +17 -0
- package/src/styles.css +4 -0
- package/src/theme/variables.css +110 -0
- package/src/vite-env.d.ts +6 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react'
|
|
3
|
+
import Alert from './Alert'
|
|
4
|
+
import Button from '../Button/Button'
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'UI/Alert',
|
|
8
|
+
component: Alert,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
argTypes: {
|
|
11
|
+
type: {
|
|
12
|
+
control: {
|
|
13
|
+
type: 'select',
|
|
14
|
+
options: ['success', 'warning', 'error', 'info'],
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
title: {
|
|
18
|
+
control: {
|
|
19
|
+
type: 'text',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
description: {
|
|
23
|
+
control: {
|
|
24
|
+
type: 'text',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
open: {
|
|
28
|
+
control: {
|
|
29
|
+
type: 'boolean',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
closable: {
|
|
33
|
+
control: {
|
|
34
|
+
type: 'boolean',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
width: {
|
|
38
|
+
control: {
|
|
39
|
+
type: 'text',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
parameters: {
|
|
44
|
+
controls: { expanded: true },
|
|
45
|
+
},
|
|
46
|
+
render: args => {
|
|
47
|
+
const [isOpen, setIsOpen] = React.useState(!!args.open)
|
|
48
|
+
return (
|
|
49
|
+
<>
|
|
50
|
+
<Button onClick={() => setIsOpen(true)}>Show Alert</Button>
|
|
51
|
+
<Alert
|
|
52
|
+
{...args}
|
|
53
|
+
open={isOpen}
|
|
54
|
+
onClose={() => setIsOpen(false)}
|
|
55
|
+
/>
|
|
56
|
+
</>
|
|
57
|
+
)
|
|
58
|
+
},
|
|
59
|
+
} satisfies Meta<typeof Alert>
|
|
60
|
+
|
|
61
|
+
export default meta
|
|
62
|
+
|
|
63
|
+
type Story = StoryObj<typeof meta>
|
|
64
|
+
|
|
65
|
+
export const Default: Story = {
|
|
66
|
+
args: {
|
|
67
|
+
open: false,
|
|
68
|
+
type: 'info',
|
|
69
|
+
title: 'Information',
|
|
70
|
+
description: 'This is an informative alert message.',
|
|
71
|
+
onClose: () => {},
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const Success: Story = {
|
|
76
|
+
args: {
|
|
77
|
+
open: true,
|
|
78
|
+
onClose: () => {},
|
|
79
|
+
type: 'success',
|
|
80
|
+
title: 'Success!',
|
|
81
|
+
description: 'Operation completed successfully.',
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const Warning: Story = {
|
|
86
|
+
args: {
|
|
87
|
+
open: true,
|
|
88
|
+
onClose: () => {},
|
|
89
|
+
type: 'warning',
|
|
90
|
+
title: 'Warning',
|
|
91
|
+
description: 'Please review this important warning message.',
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const Error: Story = {
|
|
96
|
+
args: {
|
|
97
|
+
open: true,
|
|
98
|
+
onClose: () => {},
|
|
99
|
+
type: 'error',
|
|
100
|
+
title: 'Error',
|
|
101
|
+
description: 'An error occurred while processing your request.',
|
|
102
|
+
},
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const WithAction: Story = {
|
|
106
|
+
args: {
|
|
107
|
+
open: true,
|
|
108
|
+
onClose: () => {},
|
|
109
|
+
type: 'info',
|
|
110
|
+
title: 'Update Available',
|
|
111
|
+
description: 'A new version is available.',
|
|
112
|
+
action: <Button primary>Update Now</Button>,
|
|
113
|
+
},
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export const NonClosable: Story = {
|
|
117
|
+
args: {
|
|
118
|
+
open: true,
|
|
119
|
+
onClose: () => {},
|
|
120
|
+
type: 'warning',
|
|
121
|
+
title: 'Important Notice',
|
|
122
|
+
description: 'This message cannot be dismissed.',
|
|
123
|
+
closable: false,
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const CustomWidth: Story = {
|
|
128
|
+
args: {
|
|
129
|
+
open: true,
|
|
130
|
+
onClose: () => {},
|
|
131
|
+
type: 'info',
|
|
132
|
+
title: 'Custom Width',
|
|
133
|
+
description: 'This alert has a custom width.',
|
|
134
|
+
width: '500px',
|
|
135
|
+
},
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export const WithoutDescription: Story = {
|
|
139
|
+
args: {
|
|
140
|
+
open: true,
|
|
141
|
+
onClose: () => {},
|
|
142
|
+
type: 'success',
|
|
143
|
+
title: 'Operation Successful',
|
|
144
|
+
},
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export const AutoDismiss: Story = {
|
|
148
|
+
args: {
|
|
149
|
+
open: true,
|
|
150
|
+
onClose: () => {},
|
|
151
|
+
type: 'success',
|
|
152
|
+
title: 'Auto Dismiss',
|
|
153
|
+
description: 'This alert will dismiss automatically after 3 seconds.',
|
|
154
|
+
duration: 3000,
|
|
155
|
+
},
|
|
156
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest'
|
|
3
|
+
import { render, screen, fireEvent, act } from '@testing-library/react'
|
|
4
|
+
import Alert from './Alert'
|
|
5
|
+
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
// Mock setTimeout/clearTimeout
|
|
8
|
+
vi.useFakeTimers()
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
vi.useRealTimers()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
describe('Alert Component', () => {
|
|
16
|
+
it('renders Alert unchanged', () => {
|
|
17
|
+
const { container } = render(
|
|
18
|
+
<Alert
|
|
19
|
+
open={false}
|
|
20
|
+
onClose={vi.fn()}
|
|
21
|
+
title="Test Alert"
|
|
22
|
+
/>,
|
|
23
|
+
)
|
|
24
|
+
expect(container).toMatchSnapshot()
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('renders Alert open unchanged', () => {
|
|
28
|
+
const { container } = render(
|
|
29
|
+
<Alert
|
|
30
|
+
open={true}
|
|
31
|
+
onClose={vi.fn()}
|
|
32
|
+
title="Test Alert"
|
|
33
|
+
/>,
|
|
34
|
+
)
|
|
35
|
+
expect(container).toMatchSnapshot()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('calls onClose when close button is clicked', () => {
|
|
39
|
+
const onClose = vi.fn()
|
|
40
|
+
const { container } = render(
|
|
41
|
+
<Alert
|
|
42
|
+
open={true}
|
|
43
|
+
closable={true}
|
|
44
|
+
onClose={onClose}
|
|
45
|
+
title="Test Alert"
|
|
46
|
+
/>,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
const closeButton = container.querySelector(
|
|
50
|
+
'[title="close"]',
|
|
51
|
+
) as HTMLElement
|
|
52
|
+
fireEvent.click(closeButton)
|
|
53
|
+
expect(onClose).toHaveBeenCalled()
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('auto-dismisses after duration', () => {
|
|
57
|
+
const onClose = vi.fn()
|
|
58
|
+
render(
|
|
59
|
+
<Alert
|
|
60
|
+
open={true}
|
|
61
|
+
onClose={onClose}
|
|
62
|
+
title="Test Alert"
|
|
63
|
+
duration={3000}
|
|
64
|
+
/>,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
act(() => {
|
|
68
|
+
vi.advanceTimersByTime(3000)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
expect(onClose).toHaveBeenCalled()
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('renders with custom width', () => {
|
|
75
|
+
const { container } = render(
|
|
76
|
+
<Alert
|
|
77
|
+
open={true}
|
|
78
|
+
onClose={vi.fn()}
|
|
79
|
+
title="Test Alert"
|
|
80
|
+
width="500px"
|
|
81
|
+
/>,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
const style = window.getComputedStyle(container.firstChild as Element)
|
|
85
|
+
expect(style.getPropertyValue('--memori-alert--width')).toBe('500px')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('renders with action button', () => {
|
|
89
|
+
const actionClick = vi.fn()
|
|
90
|
+
render(
|
|
91
|
+
<Alert
|
|
92
|
+
open={true}
|
|
93
|
+
onClose={vi.fn()}
|
|
94
|
+
title="Test Alert"
|
|
95
|
+
action={<button onClick={actionClick}>Action</button>}
|
|
96
|
+
/>,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
const actionButton = screen.getByText('Action')
|
|
100
|
+
fireEvent.click(actionButton)
|
|
101
|
+
expect(actionClick).toHaveBeenCalled()
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('cleans up timer on unmount', () => {
|
|
105
|
+
const onClose = vi.fn()
|
|
106
|
+
const { unmount } = render(
|
|
107
|
+
<Alert
|
|
108
|
+
open={true}
|
|
109
|
+
onClose={onClose}
|
|
110
|
+
title="Test Alert"
|
|
111
|
+
duration={3000}
|
|
112
|
+
/>,
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
unmount()
|
|
116
|
+
act(() => {
|
|
117
|
+
setTimeout(() => {
|
|
118
|
+
expect(onClose).not.toHaveBeenCalled()
|
|
119
|
+
}, 3000)
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
})
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { FC, JSX } from 'react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { Transition } from '@headlessui/react'
|
|
4
|
+
import cx from 'classnames'
|
|
5
|
+
import Close from '../../icons/Close'
|
|
6
|
+
import Button from '../Button/Button'
|
|
7
|
+
import { useTranslation } from 'react-i18next'
|
|
8
|
+
|
|
9
|
+
export type AlertType = 'success' | 'warning' | 'error' | 'info'
|
|
10
|
+
|
|
11
|
+
import './Alert.css'
|
|
12
|
+
|
|
13
|
+
export interface Props {
|
|
14
|
+
open?: boolean
|
|
15
|
+
onClose: (value: boolean) => void
|
|
16
|
+
className?: string
|
|
17
|
+
title?: string | JSX.Element | React.ReactNode
|
|
18
|
+
description?: string | JSX.Element | React.ReactNode
|
|
19
|
+
children?: JSX.Element | React.ReactNode
|
|
20
|
+
type?: AlertType
|
|
21
|
+
icon?: JSX.Element | React.ReactNode
|
|
22
|
+
closable?: boolean
|
|
23
|
+
duration?: number | null
|
|
24
|
+
action?: JSX.Element | React.ReactNode
|
|
25
|
+
width?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const Alert: FC<Props> = ({
|
|
29
|
+
open = false,
|
|
30
|
+
onClose,
|
|
31
|
+
className,
|
|
32
|
+
title,
|
|
33
|
+
description,
|
|
34
|
+
children,
|
|
35
|
+
type = 'info',
|
|
36
|
+
icon,
|
|
37
|
+
closable = true,
|
|
38
|
+
duration = null,
|
|
39
|
+
action,
|
|
40
|
+
width = '400px',
|
|
41
|
+
}: Props) => {
|
|
42
|
+
const { t } = useTranslation()
|
|
43
|
+
|
|
44
|
+
// Auto-close functionality
|
|
45
|
+
React.useEffect(() => {
|
|
46
|
+
if (duration && open) {
|
|
47
|
+
const timer = setTimeout(() => {
|
|
48
|
+
onClose(false)
|
|
49
|
+
}, duration)
|
|
50
|
+
return () => clearTimeout(timer)
|
|
51
|
+
}
|
|
52
|
+
}, [duration, open, onClose])
|
|
53
|
+
|
|
54
|
+
const getTypeStyles = (type: AlertType) => {
|
|
55
|
+
switch (type) {
|
|
56
|
+
case 'success':
|
|
57
|
+
return 'memori-alert--success'
|
|
58
|
+
case 'warning':
|
|
59
|
+
return 'memori-alert--warning'
|
|
60
|
+
case 'error':
|
|
61
|
+
return 'memori-alert--error'
|
|
62
|
+
default:
|
|
63
|
+
return 'memori-alert--info'
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<Transition
|
|
69
|
+
show={open}
|
|
70
|
+
as={React.Fragment}
|
|
71
|
+
appear
|
|
72
|
+
>
|
|
73
|
+
<div className={cx('memori-alert', getTypeStyles(type), className)}>
|
|
74
|
+
<style
|
|
75
|
+
dangerouslySetInnerHTML={{
|
|
76
|
+
__html: `
|
|
77
|
+
.memori-alert {
|
|
78
|
+
--memori-alert--width: ${width};
|
|
79
|
+
}
|
|
80
|
+
`,
|
|
81
|
+
}}
|
|
82
|
+
/>
|
|
83
|
+
<Transition.Child
|
|
84
|
+
as={React.Fragment}
|
|
85
|
+
enter="ease-out duration-300"
|
|
86
|
+
enterFrom="opacity-0 translate-y-4"
|
|
87
|
+
enterTo="opacity-100 translate-y-0"
|
|
88
|
+
leave="ease-in duration-200"
|
|
89
|
+
leaveFrom="opacity-100 translate-y-0"
|
|
90
|
+
leaveTo="opacity-0 translate-y-4"
|
|
91
|
+
>
|
|
92
|
+
<div className="memori-alert--container">
|
|
93
|
+
{icon && <div className="memori-alert--icon">{icon}</div>}
|
|
94
|
+
|
|
95
|
+
<div className="memori-alert--content">
|
|
96
|
+
{title && <div className="memori-alert--title">{title}</div>}
|
|
97
|
+
{description && (
|
|
98
|
+
<div className="memori-alert--description">{description}</div>
|
|
99
|
+
)}
|
|
100
|
+
{children}
|
|
101
|
+
</div>
|
|
102
|
+
|
|
103
|
+
<div className="memori-alert--actions">
|
|
104
|
+
{action && <div className="memori-alert--action">{action}</div>}
|
|
105
|
+
{closable && (
|
|
106
|
+
<Button
|
|
107
|
+
ghost
|
|
108
|
+
padded
|
|
109
|
+
shape="circle"
|
|
110
|
+
icon={<Close />}
|
|
111
|
+
title={t('close') || 'Close alert'}
|
|
112
|
+
onClick={() => onClose(false)}
|
|
113
|
+
className="memori-alert--close"
|
|
114
|
+
/>
|
|
115
|
+
)}
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
</Transition.Child>
|
|
119
|
+
</div>
|
|
120
|
+
</Transition>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export default Alert
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`Alert Component > renders Alert open unchanged 1`] = `
|
|
4
|
+
<div>
|
|
5
|
+
<div
|
|
6
|
+
class="memori-alert memori-alert--info"
|
|
7
|
+
data-closed=""
|
|
8
|
+
data-enter=""
|
|
9
|
+
data-transition=""
|
|
10
|
+
style=""
|
|
11
|
+
>
|
|
12
|
+
<style>
|
|
13
|
+
|
|
14
|
+
.memori-alert {
|
|
15
|
+
--memori-alert--width: 400px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
</style>
|
|
19
|
+
<div
|
|
20
|
+
class="memori-alert--container ease-out duration-300 opacity-0 translate-y-4"
|
|
21
|
+
data-closed=""
|
|
22
|
+
data-enter=""
|
|
23
|
+
data-transition=""
|
|
24
|
+
style=""
|
|
25
|
+
>
|
|
26
|
+
<div
|
|
27
|
+
class="memori-alert--content"
|
|
28
|
+
>
|
|
29
|
+
<div
|
|
30
|
+
class="memori-alert--title"
|
|
31
|
+
>
|
|
32
|
+
Test Alert
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
<div
|
|
36
|
+
class="memori-alert--actions"
|
|
37
|
+
>
|
|
38
|
+
<button
|
|
39
|
+
class="memori-button memori-button--ghost memori-button--circle memori-button--padded memori-button--icon-only memori-alert--close"
|
|
40
|
+
title="close"
|
|
41
|
+
>
|
|
42
|
+
<span
|
|
43
|
+
class="memori-button--icon"
|
|
44
|
+
>
|
|
45
|
+
<svg
|
|
46
|
+
aria-hidden="true"
|
|
47
|
+
focusable="false"
|
|
48
|
+
role="img"
|
|
49
|
+
viewBox="0 0 1024 1024"
|
|
50
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
51
|
+
>
|
|
52
|
+
<path
|
|
53
|
+
d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"
|
|
54
|
+
fill="currentColor"
|
|
55
|
+
stroke="none"
|
|
56
|
+
stroke-width="0"
|
|
57
|
+
/>
|
|
58
|
+
</svg>
|
|
59
|
+
</span>
|
|
60
|
+
</button>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
exports[`Alert Component > renders Alert unchanged 1`] = `<div />`;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
.memori-button {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
justify-content: center;
|
|
5
|
+
padding: 4px 15px;
|
|
6
|
+
border: 1px solid var(--memori-button-border-color, #d9d9d9);
|
|
7
|
+
border-radius: var(--memori-button-radius, 5px);
|
|
8
|
+
background: var(--memori-button-bg, #fff);
|
|
9
|
+
box-shadow: var(--memori-button-box-shadow);
|
|
10
|
+
color: var(--memori-button-text, #333);
|
|
11
|
+
font-family: var(--memori-font-family);
|
|
12
|
+
font-size: 14px;
|
|
13
|
+
transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.memori-button--active {
|
|
17
|
+
background: var(--memori-primary);
|
|
18
|
+
color: var(--memori-primary-text);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.memori-button:hover {
|
|
22
|
+
box-shadow:
|
|
23
|
+
0 2px 0 rgb(0 0 0 / 2%),
|
|
24
|
+
0 4px 8px rgb(0 0 0 / 4%);
|
|
25
|
+
color: #333;
|
|
26
|
+
cursor: pointer;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.memori-button:hover,
|
|
30
|
+
.memori-button:focus {
|
|
31
|
+
border-color: var(--memori-primary);
|
|
32
|
+
color: var(--memori-primary);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.memori-button:focus {
|
|
36
|
+
outline-color: var(--memori-primary);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.memori-button:active {
|
|
40
|
+
box-shadow: inset var(--memori-button-box-shadow);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.memori-button--padded {
|
|
44
|
+
padding: var(--memori-button-padding);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.memori-button--block {
|
|
48
|
+
display: block;
|
|
49
|
+
width: 100%;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.memori-button--primary {
|
|
53
|
+
background: var(--memori-primary);
|
|
54
|
+
color: var(--memori-primary-text);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.memori-button--primary:hover,
|
|
58
|
+
.memori-button--primary:focus {
|
|
59
|
+
color: var(--memori-primary-text);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.memori-button--primary:active {
|
|
63
|
+
transform: scale(0.95);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.memori-button--outlined {
|
|
67
|
+
border-color: var(--memori-primary);
|
|
68
|
+
background: none;
|
|
69
|
+
color: var(--memori-primary);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.memori-button--outlined:hover,
|
|
73
|
+
.memori-button--outlined:focus {
|
|
74
|
+
border-color: var(--memori-primary);
|
|
75
|
+
background-color: var(--memori-primary);
|
|
76
|
+
color: var(--memori-primary-text);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.memori-button--outlined:active {
|
|
80
|
+
transform: scale(0.95);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.memori-button--ghost {
|
|
84
|
+
border: 1px solid transparent;
|
|
85
|
+
background: none;
|
|
86
|
+
box-shadow: none;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.memori-button--ghost:hover,
|
|
90
|
+
.memori-button--ghost:focus {
|
|
91
|
+
border-color: transparent;
|
|
92
|
+
background: rgb(0 0 0 / 4%);
|
|
93
|
+
box-shadow:
|
|
94
|
+
0 2px 0 rgb(0 0 0 / 2%),
|
|
95
|
+
0 4px 8px rgb(0 0 0 / 4%);
|
|
96
|
+
color: inherit;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.memori-button--ghost:focus {
|
|
100
|
+
border: 1px solid var(--memori-primary);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.memori-button--square {
|
|
104
|
+
border-radius: 0;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.memori-button--rounded {
|
|
108
|
+
border-radius: var(--memori-button-radius);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.memori-button--danger {
|
|
112
|
+
border-color: var(--memori-error-color);
|
|
113
|
+
background: rgb(0 0 0 / 2%);
|
|
114
|
+
color: var(--memori-error-color);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.memori-button--danger:hover,
|
|
118
|
+
.memori-button--danger:focus {
|
|
119
|
+
border-color: var(--memori-error-color);
|
|
120
|
+
background-color: var(--memori-error-color);
|
|
121
|
+
color: #fff;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.memori-button--danger.memori-button--ghost {
|
|
125
|
+
border-color: transparent;
|
|
126
|
+
background: none;
|
|
127
|
+
box-shadow: none;
|
|
128
|
+
color: var(--memori-error-color);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.memori-button--danger.memori-button--ghost:hover,
|
|
132
|
+
.memori-button--danger.memori-button--ghost:focus {
|
|
133
|
+
border-color: var(--memori-error-color);
|
|
134
|
+
background: rgb(0 0 0 / 2%);
|
|
135
|
+
box-shadow:
|
|
136
|
+
0 2px 0 rgb(0 0 0 / 2%),
|
|
137
|
+
0 4px 8px rgb(0 0 0 / 4%);
|
|
138
|
+
color: var(--memori-error-color);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.memori-button--circle {
|
|
142
|
+
padding: 0.75em;
|
|
143
|
+
border-radius: 50%;
|
|
144
|
+
aspect-ratio: 1/1;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.memori-button--icon {
|
|
148
|
+
display: inline-flex;
|
|
149
|
+
color: currentcolor;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.memori-button--icon svg {
|
|
153
|
+
width: 1.25em;
|
|
154
|
+
height: 1.25em;
|
|
155
|
+
fill: currentcolor;
|
|
156
|
+
font-size: 1em;
|
|
157
|
+
line-height: 1;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.memori-button--icon svg[fill='none'] {
|
|
161
|
+
fill: none;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.memori-button--with-icon .memori-button--icon {
|
|
165
|
+
margin-right: 0.5em;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.memori-button[disabled] {
|
|
169
|
+
background: var(--memori-button-disabled-bg, #ccc);
|
|
170
|
+
color: var(--memori-button-disabled-color, #000);
|
|
171
|
+
cursor: not-allowed;
|
|
172
|
+
opacity: 0.5;
|
|
173
|
+
}
|