-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
50 deletions.
There are no files selected for viewing
27 changes: 19 additions & 8 deletions
27
vuu-ui/packages/vuu-layout/src/layout-header/ActionButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 51 additions & 42 deletions
93
vuu-ui/packages/vuu-shell/src/connection-status/ConnectionStatusIcon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,58 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import cx from 'classnames'; | ||
import './ConnectionStatusIcon.css'; | ||
import React, { useEffect, useState } from "react"; | ||
import cx from "clsx"; | ||
|
||
type connectionStatus = 'connected' | 'reconnected' | 'connecting' | 'disconnected'; | ||
import "./ConnectionStatusIcon.css"; | ||
|
||
type connectionStatus = | ||
| "connected" | ||
| "reconnected" | ||
| "connecting" | ||
| "disconnected"; | ||
|
||
interface ConnectionStatusProps { | ||
connectionStatus: connectionStatus | ||
className?: string; | ||
props?: unknown; | ||
element?: string; | ||
connectionStatus: connectionStatus; | ||
className?: string; | ||
props?: unknown; | ||
element?: string; | ||
} | ||
|
||
export const ConnectionStatusIcon = ({ connectionStatus, className, element = 'span', ...props}: ConnectionStatusProps) => { | ||
const [classBase, setClassBase] = useState<string>('vuuConnectingStatus'); | ||
useEffect(() => { | ||
switch(connectionStatus) { | ||
case 'connected': | ||
case 'reconnected': | ||
setClassBase('vuuActiveStatus'); | ||
break; | ||
case 'connecting': | ||
setClassBase('vuuConnectingStatus'); | ||
break; | ||
case 'disconnected': | ||
setClassBase('vuuDisconnectedStatus'); | ||
break; | ||
default: | ||
break; | ||
} | ||
}, [connectionStatus]); | ||
export const ConnectionStatusIcon = ({ | ||
connectionStatus, | ||
className, | ||
element = "span", | ||
...props | ||
}: ConnectionStatusProps) => { | ||
const [classBase, setClassBase] = useState<string>("vuuConnectingStatus"); | ||
useEffect(() => { | ||
switch (connectionStatus) { | ||
case "connected": | ||
case "reconnected": | ||
setClassBase("vuuActiveStatus"); | ||
break; | ||
case "connecting": | ||
setClassBase("vuuConnectingStatus"); | ||
break; | ||
case "disconnected": | ||
setClassBase("vuuDisconnectedStatus"); | ||
break; | ||
default: | ||
break; | ||
} | ||
}, [connectionStatus]); | ||
|
||
const statusIcon = React.createElement ( | ||
element, | ||
{ | ||
...props, | ||
className: cx('vuuStatus vuuIcon', classBase, className) | ||
}, | ||
) | ||
const statusIcon = React.createElement(element, { | ||
...props, | ||
className: cx("vuuStatus vuuIcon", classBase, className), | ||
}); | ||
|
||
return ( | ||
<> | ||
<div className='vuuStatus-container salt-theme'> | ||
{statusIcon} | ||
<div className='vuuStatus-text'>Status: {connectionStatus.toUpperCase()}</div> | ||
</div> | ||
</> | ||
) | ||
} | ||
return ( | ||
<> | ||
<div className="vuuStatus-container salt-theme"> | ||
{statusIcon} | ||
<div className="vuuStatus-text"> | ||
Status: {connectionStatus.toUpperCase()} | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; |