-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: [TECH-1539] Use Capture-UI IconButton (#3415)
- Loading branch information
1 parent
6020d77
commit 5fee4d4
Showing
16 changed files
with
170 additions
and
63 deletions.
There are no files selected for viewing
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
2 changes: 1 addition & 1 deletion
2
src/core_modules/capture-core/components/ListView/ColumnSelector/ColumnSelector.component.js
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
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
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
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
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
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
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
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
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
70 changes: 43 additions & 27 deletions
70
src/core_modules/capture-ui/IconButton/IconButton.component.js
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,33 +1,49 @@ | ||
// @flow | ||
import React, { useCallback } from 'react'; | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import classes from './iconButton.module.css'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import { colors } from '@dhis2/ui'; | ||
import type { Props } from './iconButton.types'; | ||
|
||
export const IconButton = ({ children, className, dataTest, onClick, ...passOnProps }: Props) => { | ||
const handleKeyDown = useCallback((event: SyntheticKeyboardEvent<HTMLSpanElement>) => { | ||
if ([' ', 'Enter', 'Spacebar'].includes(event.key)) { | ||
onClick(event); | ||
} | ||
}, [onClick]); | ||
const styles = { | ||
button: { | ||
cursor: 'pointer', | ||
borderRadius: '3px', | ||
border: 'none', | ||
background: 'transparent', | ||
display: 'flex', | ||
alignItems: 'center', | ||
padding: '2px', | ||
justifyContent: 'center', | ||
color: colors.grey700, | ||
'&:hover': { | ||
background: colors.grey200, | ||
color: colors.grey800, | ||
}, | ||
'&:focus': { | ||
outline: 'solid', | ||
background: colors.grey200, | ||
color: colors.grey800, | ||
}, | ||
'&.disabled': { | ||
color: colors.grey500, | ||
cursor: 'not-allowed', | ||
}, | ||
}, | ||
}; | ||
|
||
const handleMouseDown = useCallback((event: SyntheticMouseEvent<HTMLSpanElement>) => { | ||
event.preventDefault(); | ||
}, []); | ||
const IconButtonPlain = ({ children, className, dataTest, onClick, disabled, classes, ...passOnProps }: Props) => ( | ||
<button | ||
{...passOnProps} | ||
onClick={onClick} | ||
disabled={disabled} | ||
data-test={dataTest} | ||
className={cx(classes.button, { disabled, ...(className ? { [className]: true } : {}) })} | ||
type="button" | ||
tabIndex="0" | ||
> | ||
{children} | ||
</button> | ||
); | ||
|
||
return ( | ||
<span | ||
{...passOnProps} | ||
onClick={onClick} | ||
data-test={dataTest} | ||
className={cx(classes.button, className)} | ||
type="button" | ||
role="button" | ||
tabIndex="0" | ||
onKeyDown={handleKeyDown} | ||
onMouseDown={handleMouseDown} | ||
> | ||
{children} | ||
</span> | ||
); | ||
}; | ||
export const IconButton = withStyles(styles)(IconButtonPlain); |
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 |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
outline-width: 1px; | ||
outline-offset: 0px; | ||
} | ||
|
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
88 changes: 88 additions & 0 deletions
88
src/core_modules/capture-ui/Icons/ChevronIcon.component.js
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// @flow | ||
import React, { useState, useEffect } from 'react'; | ||
import { IconButton } from 'capture-ui'; | ||
import cx from 'classnames'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import { colors, spacersNum, IconChevronUp24 } from '@dhis2/ui'; | ||
|
||
type ChevronIconProps = { | ||
open: boolean, | ||
dataTest?: string, | ||
onOpen: () => void, | ||
onClose: () => void, | ||
disabled?: boolean, | ||
...CssClasses, | ||
}; | ||
|
||
const styles = { | ||
toggleButton: { | ||
margin: `0 0 0 ${spacersNum.dp4}px`, | ||
height: '24px', | ||
borderRadius: '3px', | ||
color: colors.grey600, | ||
'&:hover': { | ||
background: colors.grey200, | ||
color: colors.grey800, | ||
}, | ||
'&.open': { | ||
animation: 'flipOpen 200ms normal forwards linear', | ||
}, | ||
'&.close': { | ||
animation: 'flipClose 200ms normal forwards linear', | ||
}, | ||
'&.closeinit': { | ||
transform: 'rotateX(180deg)', | ||
}, | ||
'&.disabled': { | ||
color: colors.grey400, | ||
cursor: 'not-allowed', | ||
}, | ||
}, | ||
'@keyframes flipOpen': { | ||
from: { transform: 'rotateX(180deg)' }, | ||
to: { transform: 'rotateX(0)' }, | ||
}, | ||
'@keyframes flipClose': { | ||
from: { transform: 'rotateX(0)' }, | ||
to: { transform: 'rotateX(180deg)' }, | ||
}, | ||
}; | ||
|
||
const ChevronIconPlain = ({ open, onOpen, onClose, dataTest, disabled, classes }: ChevronIconProps) => { | ||
const [postEffectOpen, setPostEffectOpenStatus] = useState(open); | ||
const [animationsReady, setAnimationsReadyStatus] = useState(false); | ||
|
||
const handleClick = () => { | ||
if (disabled) { | ||
return null; | ||
} | ||
return open ? onClose() : onOpen(); | ||
}; | ||
|
||
useEffect(() => { | ||
if (!animationsReady) { | ||
setAnimationsReadyStatus(true); | ||
} | ||
|
||
setPostEffectOpenStatus(open); | ||
}, [open, animationsReady]); | ||
|
||
return ( | ||
<IconButton | ||
dataTest={dataTest} | ||
className={cx(classes.toggleButton, { | ||
closeinit: !animationsReady && !postEffectOpen, | ||
open: animationsReady && postEffectOpen, | ||
close: animationsReady && !postEffectOpen, | ||
disabled, | ||
})} | ||
onClick={handleClick} | ||
disabled={disabled} | ||
> | ||
<IconChevronUp24 /> | ||
</IconButton> | ||
); | ||
}; | ||
|
||
export const ChevronIcon = withStyles(styles)(ChevronIconPlain); | ||
|
Oops, something went wrong.