@startupjs-ui/alert 0.1.3
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/CHANGELOG.md +20 -0
- package/README.mdx +195 -0
- package/index.cssx.styl +52 -0
- package/index.d.ts +28 -0
- package/index.tsx +95 -0
- package/package.json +22 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [0.1.3](https://github.com/startupjs/startupjs-ui/compare/v0.1.2...v0.1.3) (2025-12-29)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @startupjs-ui/alert
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.1.2](https://github.com/startupjs/startupjs-ui/compare/v0.1.1...v0.1.2) (2025-12-29)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* add mdx and docs packages. Refactor docs to get rid of any @startupjs/ui usage and use startupjs-ui instead ([703c926](https://github.com/startupjs/startupjs-ui/commit/703c92636efb0421ffd11783f692fc892b74018f))
|
|
20
|
+
* **alert:** refactor Alert component ([cfa59c7](https://github.com/startupjs/startupjs-ui/commit/cfa59c7e0351a082c6820addd8f3610f8d2fbe25))
|
package/README.mdx
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { Sandbox } from '@startupjs-ui/docs'
|
|
3
|
+
import Alert, { _PropsJsonSchema as AlertPropsJsonSchema } from './index'
|
|
4
|
+
import Br from '@startupjs-ui/br'
|
|
5
|
+
import Button from '@startupjs-ui/button'
|
|
6
|
+
import Div from '@startupjs-ui/div'
|
|
7
|
+
import { faFire } from '@fortawesome/free-solid-svg-icons'
|
|
8
|
+
|
|
9
|
+
# Alert
|
|
10
|
+
|
|
11
|
+
An alert displays a short, important message in a way that attracts the user's attention without interrupting the user's task.
|
|
12
|
+
|
|
13
|
+
```jsx
|
|
14
|
+
import { Alert } from 'startupjs-ui'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Simple example
|
|
18
|
+
```jsx example
|
|
19
|
+
return (
|
|
20
|
+
<Alert>
|
|
21
|
+
Message
|
|
22
|
+
</Alert>
|
|
23
|
+
)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Variants
|
|
27
|
+
|
|
28
|
+
The alert offers four severity levels that set a distinctive icon and color: `success`, `info`, `warning`, `error`. You can specify it by passing `variant` property.
|
|
29
|
+
|
|
30
|
+
```jsx example
|
|
31
|
+
return (
|
|
32
|
+
<Div>
|
|
33
|
+
<Alert variant='info'>
|
|
34
|
+
This is an info alert — check it out!
|
|
35
|
+
</Alert>
|
|
36
|
+
<Br />
|
|
37
|
+
<Alert variant='success'>
|
|
38
|
+
This is an success alert — check it out!
|
|
39
|
+
</Alert>
|
|
40
|
+
<Br />
|
|
41
|
+
<Alert variant='warning'>
|
|
42
|
+
This is an warning alert — check it out!
|
|
43
|
+
</Alert>
|
|
44
|
+
<Br />
|
|
45
|
+
<Alert variant='error'>
|
|
46
|
+
This is an error alert — check it out!
|
|
47
|
+
</Alert>
|
|
48
|
+
</Div>
|
|
49
|
+
)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Title
|
|
53
|
+
|
|
54
|
+
You can use the `title` property to display the title above the content.
|
|
55
|
+
|
|
56
|
+
```jsx example
|
|
57
|
+
return (
|
|
58
|
+
<Div>
|
|
59
|
+
<Alert
|
|
60
|
+
variant='info'
|
|
61
|
+
title='Info'
|
|
62
|
+
>
|
|
63
|
+
This is an info alert — check it out!
|
|
64
|
+
</Alert>
|
|
65
|
+
<Br />
|
|
66
|
+
<Alert
|
|
67
|
+
variant='success'
|
|
68
|
+
title='Success'
|
|
69
|
+
>
|
|
70
|
+
This is an success alert — check it out!
|
|
71
|
+
</Alert>
|
|
72
|
+
<Br />
|
|
73
|
+
<Alert
|
|
74
|
+
variant='warning'
|
|
75
|
+
title='Warning'
|
|
76
|
+
>
|
|
77
|
+
This is an warning alert — check it out!
|
|
78
|
+
</Alert>
|
|
79
|
+
<Br />
|
|
80
|
+
<Alert
|
|
81
|
+
variant='error'
|
|
82
|
+
title='Error'
|
|
83
|
+
>
|
|
84
|
+
This is an error alert — check it out!
|
|
85
|
+
</Alert>
|
|
86
|
+
</Div>
|
|
87
|
+
)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
## Icons
|
|
92
|
+
The `icon` property allows you to change the icon at the beginning of the component.
|
|
93
|
+
The `variant` prop defines the corresponding color for the icon.
|
|
94
|
+
|
|
95
|
+
Setting the `icon` property to `false` will completely remove the icon.
|
|
96
|
+
|
|
97
|
+
```jsx example
|
|
98
|
+
return (
|
|
99
|
+
<Div>
|
|
100
|
+
<Alert
|
|
101
|
+
icon={faFire}
|
|
102
|
+
variant='error'
|
|
103
|
+
>
|
|
104
|
+
Error alert with custom icon
|
|
105
|
+
</Alert>
|
|
106
|
+
<Br />
|
|
107
|
+
<Alert
|
|
108
|
+
icon={false}
|
|
109
|
+
variant='warning'
|
|
110
|
+
>
|
|
111
|
+
Warning alert without icon
|
|
112
|
+
</Alert>
|
|
113
|
+
</Div>
|
|
114
|
+
)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Actions
|
|
118
|
+
|
|
119
|
+
An alert can have an action (`onClose` prop). It is rendered after the message, at the end of the alert.
|
|
120
|
+
|
|
121
|
+
```jsx example
|
|
122
|
+
const [showFirstAlert, setShowFirstAlert] = useState(true)
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<Div>
|
|
126
|
+
{showFirstAlert && <Alert
|
|
127
|
+
variant='warning'
|
|
128
|
+
onClose={() => setShowFirstAlert(false)}
|
|
129
|
+
>
|
|
130
|
+
Warning alert with default actions
|
|
131
|
+
</Alert>}
|
|
132
|
+
<Br />
|
|
133
|
+
<Button
|
|
134
|
+
style={{ alignSelf: 'center' }}
|
|
135
|
+
disabled={showFirstAlert}
|
|
136
|
+
onPress={() => setShowFirstAlert(true)}
|
|
137
|
+
>
|
|
138
|
+
Re-Open
|
|
139
|
+
</Button>
|
|
140
|
+
</Div>
|
|
141
|
+
)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
The `renderActions` prop can be used to provide an alternative action.
|
|
145
|
+
|
|
146
|
+
```jsx example
|
|
147
|
+
const [showSecondAlert, setShowSecondAlert] = useState(true)
|
|
148
|
+
|
|
149
|
+
const renderCustomCloseButton = () => {
|
|
150
|
+
return (
|
|
151
|
+
<Button
|
|
152
|
+
color='success'
|
|
153
|
+
variant='flat'
|
|
154
|
+
size='s'
|
|
155
|
+
onPress={() => setShowSecondAlert(false)}
|
|
156
|
+
>
|
|
157
|
+
CLOSE
|
|
158
|
+
</Button>
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<Div>
|
|
164
|
+
{showSecondAlert && <Alert
|
|
165
|
+
variant='success'
|
|
166
|
+
renderActions={renderCustomCloseButton}
|
|
167
|
+
>
|
|
168
|
+
Success alert with custom actions
|
|
169
|
+
</Alert>}
|
|
170
|
+
<Br />
|
|
171
|
+
<Button
|
|
172
|
+
style={{ alignSelf: 'center' }}
|
|
173
|
+
disabled={showSecondAlert}
|
|
174
|
+
onPress={() => setShowSecondAlert(true)}
|
|
175
|
+
>
|
|
176
|
+
Re-Open
|
|
177
|
+
</Button>
|
|
178
|
+
</Div>
|
|
179
|
+
)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Sandbox
|
|
183
|
+
|
|
184
|
+
<Sandbox
|
|
185
|
+
Component={Alert}
|
|
186
|
+
propsJsonSchema={AlertPropsJsonSchema}
|
|
187
|
+
extraParams={{
|
|
188
|
+
icon: {
|
|
189
|
+
showIconSelect: true
|
|
190
|
+
}
|
|
191
|
+
}}
|
|
192
|
+
props={{
|
|
193
|
+
children: 'Message content'
|
|
194
|
+
}}
|
|
195
|
+
/>
|
package/index.cssx.styl
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
.root
|
|
2
|
+
padding 1u 2u
|
|
3
|
+
border-width 1px
|
|
4
|
+
justify-content space-between
|
|
5
|
+
radius()
|
|
6
|
+
|
|
7
|
+
&.info
|
|
8
|
+
border-color var(--color-border-primary)
|
|
9
|
+
background-color var(--color-bg-primary-transparent)
|
|
10
|
+
|
|
11
|
+
&.error
|
|
12
|
+
border-color var(--color-border-error)
|
|
13
|
+
background-color var(--color-bg-error-transparent)
|
|
14
|
+
|
|
15
|
+
&.warning
|
|
16
|
+
border-color var(--color-border-warning)
|
|
17
|
+
background-color var(--color-bg-warning-transparent)
|
|
18
|
+
|
|
19
|
+
&.success
|
|
20
|
+
border-color var(--color-border-success)
|
|
21
|
+
background-color var(--color-bg-success-transparent)
|
|
22
|
+
|
|
23
|
+
// we align height by actions
|
|
24
|
+
// since info block has height less small button
|
|
25
|
+
.information
|
|
26
|
+
padding 2px 0
|
|
27
|
+
flex-shrink 1
|
|
28
|
+
|
|
29
|
+
.icon
|
|
30
|
+
flex-shrink 0
|
|
31
|
+
|
|
32
|
+
&.info
|
|
33
|
+
color var(--color-text-primary)
|
|
34
|
+
|
|
35
|
+
&.error
|
|
36
|
+
color var(--color-text-error)
|
|
37
|
+
|
|
38
|
+
&.warning
|
|
39
|
+
color var(--color-text-warning)
|
|
40
|
+
|
|
41
|
+
&.success
|
|
42
|
+
color var(--color-text-success)
|
|
43
|
+
|
|
44
|
+
.content
|
|
45
|
+
flex-shrink 1
|
|
46
|
+
|
|
47
|
+
&.indent
|
|
48
|
+
margin-left 1.5u
|
|
49
|
+
|
|
50
|
+
.actions
|
|
51
|
+
flex-shrink 0
|
|
52
|
+
margin-left 2u
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// DO NOT MODIFY THIS FILE - IT IS AUTOMATICALLY GENERATED ON COMMITS.
|
|
3
|
+
|
|
4
|
+
import { type ReactNode } from 'react';
|
|
5
|
+
import { type DivProps } from '@startupjs-ui/div';
|
|
6
|
+
import { type IconProps } from '@startupjs-ui/icon';
|
|
7
|
+
import './index.cssx.styl';
|
|
8
|
+
declare const _default: import("react").ComponentType<AlertProps>;
|
|
9
|
+
export default _default;
|
|
10
|
+
export declare const _PropsJsonSchema: {};
|
|
11
|
+
export interface AlertProps extends Omit<DivProps, 'variant' | 'style'> {
|
|
12
|
+
/** Custom styles applied to the root view */
|
|
13
|
+
style?: DivProps['style'];
|
|
14
|
+
/** Alert visual style variant @default 'info' */
|
|
15
|
+
variant?: 'info' | 'error' | 'warning' | 'success';
|
|
16
|
+
/** Icon definition or toggle. Pass false to hide icon @default true */
|
|
17
|
+
icon?: boolean | IconProps['icon'];
|
|
18
|
+
/** Title displayed above message */
|
|
19
|
+
title?: string;
|
|
20
|
+
/** Deprecated alias for children @deprecated */
|
|
21
|
+
label?: string;
|
|
22
|
+
/** Content rendered inside Alert */
|
|
23
|
+
children?: ReactNode;
|
|
24
|
+
/** Custom actions renderer displayed at the end */
|
|
25
|
+
renderActions?: () => ReactNode;
|
|
26
|
+
/** Close handler to render default close action */
|
|
27
|
+
onClose?: () => void;
|
|
28
|
+
}
|
package/index.tsx
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { type ReactNode } from 'react'
|
|
2
|
+
import { pug, observer } from 'startupjs'
|
|
3
|
+
import { themed } from '@startupjs-ui/core'
|
|
4
|
+
import Div, { type DivProps } from '@startupjs-ui/div'
|
|
5
|
+
import Span from '@startupjs-ui/span'
|
|
6
|
+
import Icon, { type IconProps } from '@startupjs-ui/icon'
|
|
7
|
+
import { faExclamationCircle } from '@fortawesome/free-solid-svg-icons/faExclamationCircle'
|
|
8
|
+
import { faTimes } from '@fortawesome/free-solid-svg-icons/faTimes'
|
|
9
|
+
import { faCheckCircle } from '@fortawesome/free-solid-svg-icons/faCheckCircle'
|
|
10
|
+
import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons/faExclamationTriangle'
|
|
11
|
+
import { faInfoCircle } from '@fortawesome/free-solid-svg-icons/faInfoCircle'
|
|
12
|
+
import './index.cssx.styl'
|
|
13
|
+
|
|
14
|
+
const ICONS = {
|
|
15
|
+
info: faInfoCircle,
|
|
16
|
+
error: faExclamationCircle,
|
|
17
|
+
warning: faExclamationTriangle,
|
|
18
|
+
success: faCheckCircle
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default observer(themed('Alert', Alert))
|
|
22
|
+
|
|
23
|
+
export const _PropsJsonSchema = {/* AlertProps */}
|
|
24
|
+
|
|
25
|
+
export interface AlertProps extends Omit<DivProps, 'variant' | 'style'> {
|
|
26
|
+
/** Custom styles applied to the root view */
|
|
27
|
+
style?: DivProps['style']
|
|
28
|
+
/** Alert visual style variant @default 'info' */
|
|
29
|
+
variant?: 'info' | 'error' | 'warning' | 'success'
|
|
30
|
+
/** Icon definition or toggle. Pass false to hide icon @default true */
|
|
31
|
+
icon?: boolean | IconProps['icon']
|
|
32
|
+
/** Title displayed above message */
|
|
33
|
+
title?: string
|
|
34
|
+
/** Deprecated alias for children @deprecated */
|
|
35
|
+
label?: string
|
|
36
|
+
/** Content rendered inside Alert */
|
|
37
|
+
children?: ReactNode
|
|
38
|
+
/** Custom actions renderer displayed at the end */
|
|
39
|
+
renderActions?: () => ReactNode
|
|
40
|
+
/** Close handler to render default close action */
|
|
41
|
+
onClose?: () => void
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function Alert ({
|
|
45
|
+
style,
|
|
46
|
+
variant = 'info',
|
|
47
|
+
icon = true,
|
|
48
|
+
label,
|
|
49
|
+
title,
|
|
50
|
+
renderActions,
|
|
51
|
+
children,
|
|
52
|
+
onClose,
|
|
53
|
+
...props
|
|
54
|
+
}: AlertProps): ReactNode {
|
|
55
|
+
if (label) {
|
|
56
|
+
children = label
|
|
57
|
+
console.warn('[@startupjs/ui] Alert: label is DEPRECATED, use children instead.')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return pug`
|
|
61
|
+
Div.root(
|
|
62
|
+
style=style
|
|
63
|
+
vAlign='center'
|
|
64
|
+
styleName=[variant]
|
|
65
|
+
row
|
|
66
|
+
...props
|
|
67
|
+
)
|
|
68
|
+
Div.information(row vAlign='center')
|
|
69
|
+
if icon
|
|
70
|
+
Icon.icon(
|
|
71
|
+
icon=icon === true ? ICONS[variant] : icon
|
|
72
|
+
size='l'
|
|
73
|
+
styleName=[variant]
|
|
74
|
+
)
|
|
75
|
+
Div.content(styleName={ indent: icon !== false })
|
|
76
|
+
if title
|
|
77
|
+
Span(bold)= title
|
|
78
|
+
if typeof children === 'string'
|
|
79
|
+
Span= children
|
|
80
|
+
else if Array.isArray(children) && children.every(item => typeof item === 'string')
|
|
81
|
+
Span= children.join('')
|
|
82
|
+
else
|
|
83
|
+
= children
|
|
84
|
+
if renderActions
|
|
85
|
+
Div.actions
|
|
86
|
+
= renderActions()
|
|
87
|
+
else if onClose
|
|
88
|
+
Div.actions(onPress=onClose)
|
|
89
|
+
Icon.icon(
|
|
90
|
+
icon=faTimes
|
|
91
|
+
size='l'
|
|
92
|
+
styleName=[variant]
|
|
93
|
+
)
|
|
94
|
+
`
|
|
95
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@startupjs-ui/alert",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"main": "index.tsx",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@startupjs-ui/core": "^0.1.3",
|
|
12
|
+
"@startupjs-ui/div": "^0.1.3",
|
|
13
|
+
"@startupjs-ui/icon": "^0.1.3",
|
|
14
|
+
"@startupjs-ui/span": "^0.1.3"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"react": "*",
|
|
18
|
+
"react-native": "*",
|
|
19
|
+
"startupjs": "*"
|
|
20
|
+
},
|
|
21
|
+
"gitHead": "fd964ebc3892d3dd0a6c85438c0af619cc50c3f0"
|
|
22
|
+
}
|