Skip to content

Commit

Permalink
Update components
Browse files Browse the repository at this point in the history
  • Loading branch information
AlonGvili committed Nov 5, 2019
1 parent ce1bed2 commit 87e3eee
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 57 deletions.
45 changes: 45 additions & 0 deletions src/Components/avatar/avatar.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from "react";
import { Avatar } from "antd";
import useDashboardEvent from "../Hooks/useDashboardEvent.jsx";


const AntdAvatar = props => {
const [state, reload] = useDashboardEvent(props.id, props);
const { content, attributes } = state;

const contentProps = {
children: content
}

const imageProps = {
src: attributes.src,
srcSet: attributes.srcSet,
alt: attributes.alt
}

const iconProps = {
children: UniversalDashboard.renderComponent(content)
}

let propsToUse
switch(attributes.parameterSet){
case 'Icon':
propsToUse = {...iconProps}
break
case 'Image':
propsToUse = {...imageProps}
break
case 'Content':
propsToUse = {...contentProps}
break
default:
console.log('No ParameterSet Was Selected!, Please Select One Of The Following: Content,Image,Icon')
break
}

return (
<Avatar {...attributes} {...propsToUse} />
);
};

export default AntdAvatar;
26 changes: 18 additions & 8 deletions src/Components/badge/badge.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@ const AntdBadge = props => {
const [state, reload] = useDashboardEvent(props.id, props);
const { content, attributes } = state;

const countProps = {
count: attributes.count,
showZero: attributes.showZero,
overflowCount: attributes.overflowCount,
style: attributes.style
}

const dotProps = {
color: attributes.color,
text: attributes.text,
status: attributes.status,
dot: attributes.dot
}

const propsToUse = attributes.count ? { ...countProps } : { ...dotProps }
return (
<Badge {...attributes} count={attributes.count}>
{UniversalDashboard.renderComponent(content)}
<ReactInterval
callback={reload}
timeout={attributes.refreshInterval}
enabled={attributes.autoRefresh}
/>
</Badge>
<Badge
{...propsToUse}
children={UniversalDashboard.renderComponent(content)} />
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/Components/button/button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const AntdButton = props => {

return (
<Button
{...attributes}
{...attributes}
htmlType="button"
type={attributes.buttonType}
onClick={onClick}
Expand Down
5 changes: 2 additions & 3 deletions src/Components/drawer/drawer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ const AntdDrawer = props => {
<Drawer
{...attributes}
onClose={onClose}
>
{UniversalDashboard.renderComponent(content)}
</Drawer>
children={UniversalDashboard.renderComponent(content)}
/>
<ReactInterval
callback={reload}
timeout={props.refreshInterval}
Expand Down
2 changes: 2 additions & 0 deletions src/Components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import AntdRadio from "./radio/radio"
import AntdRadioButton from "./radio/radio-button"
import AntdRadioGroup from "./radio/radio-group"
import AntdCopyToClipboard from "./copy-to-clipboard/copy-to-clipboard"
import AntdAvatar from "./avatar/avatar"
// const AntdCollapsed = lazy(() =>
// import(/* webpackChunkName: "AntdCollapsed" */ "./Utils/collapse")
// ); - Still in development
Expand Down Expand Up @@ -72,4 +73,5 @@ UniversalDashboard.register("ud-antd-radio", AntdRadio);
UniversalDashboard.register("ud-antd-radio-button", AntdRadioButton);
UniversalDashboard.register("ud-antd-radio-group", AntdRadioGroup);
UniversalDashboard.register("ud-antd-copy-button", AntdCopyToClipboard);
UniversalDashboard.register("ud-antd-avatar", AntdAvatar);
// UniversalDashboard.register("ud-antd-collapsed", AntdCollapsed); - Still in development
2 changes: 0 additions & 2 deletions src/Scripts/New-UDAntdAutoCompete.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ function New-UDAntdAutoComplete {
placeholder = $placeholder
value = $value
onBlur = $onBlur
# onChange = $onChange
onFocus = $onFocus
onSearch = $onSearch
# onSelect = $onSelect
defaultOpen = $defaultOpen.IsPresent
open = $open.IsPresent
onDropdownVisibleChange = $onDropdownVisibleChange
Expand Down
60 changes: 60 additions & 0 deletions src/Scripts/New-UDAntdAvatar.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function New-UDAntdAvatar {
[CmdletBinding(DefaultParameterSetName = 'Icon')]
[OutputType('UDAntd.Avatar')]
Param(
[Parameter()]
[string]$Id = (New-Guid).ToString(),
[Parameter()]
[string]$ClassName,
[Parameter()]
[ValidateSet('circle', 'square')]
[string]$Shape,
[Parameter()]
[ValidateSet('small', 'default', 'large')]
[string]$Size,
[Parameter()]
[hashtable]$Style,
[Parameter()]
[scriptblock]$OnError,
[Parameter(ParameterSetName = 'Icon')]
[object]$Icon,
[Parameter(ParameterSetName = 'Image')]
[string]$Alt,
[Parameter(ParameterSetName = 'Image')]
[string]$Src,
[Parameter(ParameterSetName = 'Image')]
[string[]]$SrcSet,
[Parameter(ParameterSetName = 'Content')]
[object]$Content
)
End {
if ($null -ne $OnError) {
if ($OnError -is [scriptblock] -or $OnError -is [UniversalDashboard.Models.Endpoint]) {
$OnError = New-UDEndpoint -Endpoint $OnError -Id ($Id + "OnError")
}
}

if($PSCmdlet.ParameterSetName.Contains('Icon')){
$Content = $Icon
}

$UDAntdAvatar = @{
assetId = $AssetId
isPlugin = $true
type = "ud-antd-avatar"
id = $Id
className = $ClassName
style = $Style
size = $Size
src = $Src
srcSet = $SrcSet
shape = $Shape
alt = $Alt
content = $Content
parameterSet = $PSCmdlet.ParameterSetName
hasCallBack = $null -ne $OnError
}
$UDAntdAvatar.PSTypeNames.Insert(0, 'UDAntd.Avatar')
$UDAntdAvatar
}
}
84 changes: 41 additions & 43 deletions src/Scripts/New-UDAntdBadge.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,58 @@
General notes
#>
function New-UDAntdBadge {
[CmdletBinding(DefaultParameterSetName = 'Count')]
param(
[Parameter()]
[string]$Id = (New-Guid).ToString(),
[Parameter()]
[string]$ClassName,
[Parameter()]
[ValidateSet('success', 'processing', 'default ', 'error', 'warning')]

[Parameter(ParameterSetName = 'Dot')]
[ValidateSet('success', 'processing', 'default', 'error', 'warning')]
[string]$Status,
[Parameter()]
[string]$Title,
[Parameter()]

[Parameter(ParameterSetName = 'Dot')]
[string]$Text,
[Parameter()]
[int]$OverflowCount,
[Parameter()]
[int[]]$OffSet,
[Parameter()]
[scriptblock]$Count,
[Parameter()]
[object]$Content,
[Parameter()]

[Parameter(ParameterSetName = 'Count')]
[int]$OverflowCount = 9999,

[Parameter(ParameterSetName = 'Count')]
[int]$Count,

[Parameter(ParameterSetName = 'Count')]
[hashtable]$Style,

[Parameter(ParameterSetName = 'Count')]
[switch]$ShowZero,
[Parameter()]

[Parameter(ParameterSetName = 'Dot')]
[switch]$Dot,
[Parameter(ParameterSetName = 'Color')]

[Parameter(ParameterSetName = 'Dot')]
[string]$Color,
[Parameter(ParameterSetName = 'PresetColors')]

[Parameter(ParameterSetName = 'Dot')]
[ValidateSet('pink', 'red', 'yellow', 'orange', 'cyan', 'green', 'blue', 'purple', 'geekblue', 'magenta', 'volcano', 'gold', 'lime')]
[string]$PresetColor,
[string]$PresetColor,

[Parameter()]
[hashtable]$Style,
[string]$Id = (New-Guid).ToString(),
[Parameter()]
[int]$RefreshInterval = 5000,
[string]$ClassName,
[Parameter()]
[switch]$AutoRefresh,
[string]$Title,
[Parameter()]
[switch]$IsEndpoint

[int[]]$OffSet,
[Parameter()]
[object]$Content
)

End {

if ($null -ne $Count -and $IsEndpoint) {
if ($Count -is [scriptblock]) {
$Endpoint = New-UDEndpoint -Endpoint $Count -Id $Id
}
elseif ($Count -isnot [UniversalDashboard.Models.Endpoint]) {
throw "Count must be a script block or UDEndpoint"
}
}
if ($PSBoundParameters.ContainsKey('Color')) {
$SelectedColor = $Color
}
else {
$SelectedColor = $PresetColor
}

@{
assetId = $AssetId
Expand All @@ -77,17 +79,13 @@ function New-UDAntdBadge {
showZero = $ShowZero.IsPresent
dot = $Dot.IsPresent
overflowCount = $OverflowCount
count = $Count.Invoke()
count = $Count
status = $Status
color = $PresetColor
color = $SelectedColor
style = $Style
title = $Title
text = $Text
autoRefresh = $AutoRefresh.IsPresent
isEndpoint = $IsEndpoint.IsPresent
refreshInterval = $RefreshInterval
content = $Content
text = $Text
content = $Content
}

}
}
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ $manifestParameters = @{
"New-UDAntdRadioButton"
"New-UDAntdRadioGroup"
"New-UDAntdCopyToClipboard"
"New-UDAntdAvatar"
)
}

Expand Down

0 comments on commit 87e3eee

Please sign in to comment.