1
+ "use strict" ;
2
+
3
+ Object . defineProperty ( exports , "__esModule" , {
4
+ value : true
5
+ } ) ;
6
+ exports [ "default" ] = void 0 ;
7
+
8
+ var _react = _interopRequireDefault ( require ( "react" ) ) ;
9
+
10
+ var _propTypes = _interopRequireDefault ( require ( "prop-types" ) ) ;
11
+
12
+ var _classnames = _interopRequireDefault ( require ( "classnames" ) ) ;
13
+
14
+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { "default" : obj } ; }
15
+
16
+ function _slicedToArray ( arr , i ) { return _arrayWithHoles ( arr ) || _iterableToArrayLimit ( arr , i ) || _unsupportedIterableToArray ( arr , i ) || _nonIterableRest ( ) ; }
17
+
18
+ function _nonIterableRest ( ) { throw new TypeError ( "Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method." ) ; }
19
+
20
+ function _unsupportedIterableToArray ( o , minLen ) { if ( ! o ) return ; if ( typeof o === "string" ) return _arrayLikeToArray ( o , minLen ) ; var n = Object . prototype . toString . call ( o ) . slice ( 8 , - 1 ) ; if ( n === "Object" && o . constructor ) n = o . constructor . name ; if ( n === "Map" || n === "Set" ) return Array . from ( o ) ; if ( n === "Arguments" || / ^ (?: U i | I ) n t (?: 8 | 1 6 | 3 2 ) (?: C l a m p e d ) ? A r r a y $ / . test ( n ) ) return _arrayLikeToArray ( o , minLen ) ; }
21
+
22
+ function _arrayLikeToArray ( arr , len ) { if ( len == null || len > arr . length ) len = arr . length ; for ( var i = 0 , arr2 = new Array ( len ) ; i < len ; i ++ ) { arr2 [ i ] = arr [ i ] ; } return arr2 ; }
23
+
24
+ function _iterableToArrayLimit ( arr , i ) { if ( typeof Symbol === "undefined" || ! ( Symbol . iterator in Object ( arr ) ) ) return ; var _arr = [ ] ; var _n = true ; var _d = false ; var _e = undefined ; try { for ( var _i = arr [ Symbol . iterator ] ( ) , _s ; ! ( _n = ( _s = _i . next ( ) ) . done ) ; _n = true ) { _arr . push ( _s . value ) ; if ( i && _arr . length === i ) break ; } } catch ( err ) { _d = true ; _e = err ; } finally { try { if ( ! _n && _i [ "return" ] != null ) _i [ "return" ] ( ) ; } finally { if ( _d ) throw _e ; } } return _arr ; }
25
+
26
+ function _arrayWithHoles ( arr ) { if ( Array . isArray ( arr ) ) return arr ; }
27
+
28
+ var colorSchemes = {
29
+ black : "bg-black text-gray-200 border-gray-900" ,
30
+ white : "bg-white text-gray-600 border-gray-100" ,
31
+ gray : "bg-gray-200 text-gray-800 border-gray-300" ,
32
+ red : "bg-red-200 text-red-800 border-red-300" ,
33
+ orange : "bg-orange-200 text-orange-800 border-orange-300" ,
34
+ yellow : "bg-yellow-200 text-yellow-800 border-yellow-300" ,
35
+ green : "bg-green-200 text-green-800 border-green-300" ,
36
+ teal : "bg-teal-200 text-teal-800 border-teal-300" ,
37
+ blue : "bg-blue-200 text-blue-800 border-blue-300" ,
38
+ indigo : "bg-indigo-200 text-indigo-800 border-indigo-300" ,
39
+ purple : "bg-purple-200 text-purple-800 border-purple-300" ,
40
+ pink : "bg-pink-200 text-pink-800 border-pink-300"
41
+ } ;
42
+
43
+ var Alert = function Alert ( _ref ) {
44
+ var controlled = _ref . controlled ,
45
+ color = _ref . color ,
46
+ icon = _ref . icon ,
47
+ children = _ref . children ;
48
+
49
+ var _React$useState = _react [ "default" ] . useState ( true ) ,
50
+ _React$useState2 = _slicedToArray ( _React$useState , 2 ) ,
51
+ show = _React$useState2 [ 0 ] ,
52
+ setShow = _React$useState2 [ 1 ] ;
53
+
54
+ var closeAlert = function closeAlert ( ) {
55
+ setShow ( false ) ;
56
+ } ;
57
+
58
+ if ( ! show ) {
59
+ return null ;
60
+ }
61
+
62
+ return /*#__PURE__*/ _react [ "default" ] . createElement ( "div" , {
63
+ className : ( 0 , _classnames [ "default" ] ) ( "px-5 py-3 border border-solid rounded relative mb-4" , colorSchemes [ color ] )
64
+ } , icon !== "" ? /*#__PURE__*/ _react [ "default" ] . createElement ( "span" , {
65
+ className : "text-xl inline-block mr-5 align-middle"
66
+ } , /*#__PURE__*/ _react [ "default" ] . createElement ( "i" , {
67
+ className : icon
68
+ } ) ) : null , icon ? /*#__PURE__*/ _react [ "default" ] . createElement ( "span" , {
69
+ className : "inline-block align-middle mr-8"
70
+ } , children ) : children , controlled ? null : /*#__PURE__*/ _react [ "default" ] . createElement ( "button" , {
71
+ className : "absolute bg-transparent text-2xl font-semibold leading-none right-0 top-0 outline-none focus:outline-none opacity-50 px-5 py-3 hover:opacity-75 hover:text-black" ,
72
+ onClick : closeAlert
73
+ } , /*#__PURE__*/ _react [ "default" ] . createElement ( "span" , null , "\xD7" ) ) ) ;
74
+ } ;
75
+
76
+ Alert . defaultProps = {
77
+ controlled : false ,
78
+ color : "pink" ,
79
+ icon : ""
80
+ } ;
81
+ Alert . propTypes = {
82
+ // if set to false, then a closing button will be rendered so that the alert can be closed
83
+ // if set to true, then the closing button will not be rendered
84
+ controlled : _propTypes [ "default" ] . bool ,
85
+ // set the background, border and text color for the alert
86
+ color : _propTypes [ "default" ] . oneOf ( [ "black" , "white" , "gray" , "red" , "orange" , "yellow" , "green" , "teal" , "blue" , "indigo" , "purple" , "pink" ] ) ,
87
+ // adds a font icon to the left of the message
88
+ // for example, if you have included into your project font-awesome free
89
+ // you could send "fa fa-heart"
90
+ icon : _propTypes [ "default" ] . string ,
91
+ children : _propTypes [ "default" ] . node . isRequired
92
+ } ;
93
+ var _default = Alert ;
94
+ exports [ "default" ] = _default ;
0 commit comments