-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support custom icon and clearIcon props (#297)
* test: add and configure jest-dom * feat(datepicker): allow custom icon and clear icon as components * test(datepicker): assert that custom icons work as expected * chore(stories): add selects for custom icon and clearIcon props * chore: improve type-checking and add story for custom icons * docs: add icon and clearIcon props to README
- Loading branch information
1 parent
33cbf6e
commit eb28dbf
Showing
11 changed files
with
280 additions
and
42 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
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 @@ | ||
import '@testing-library/jest-dom'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react'; | ||
import { Icon as SUIIcon } from 'semantic-ui-react'; | ||
import { SemanticDatepickerProps } from '../types'; | ||
|
||
type CustomIconProps = { | ||
clearIcon: SemanticDatepickerProps['clearIcon']; | ||
icon: SemanticDatepickerProps['icon']; | ||
isClearIconVisible: boolean; | ||
onClear: () => void; | ||
onClick: () => void; | ||
}; | ||
|
||
const CustomIcon = ({ | ||
clearIcon, | ||
icon, | ||
isClearIconVisible, | ||
onClear, | ||
onClick, | ||
}: CustomIconProps) => { | ||
if (isClearIconVisible && clearIcon && React.isValidElement(clearIcon)) { | ||
return React.cloneElement(clearIcon, { | ||
'data-testid': 'datepicker-icon', | ||
onClick: onClear, | ||
}); | ||
} | ||
|
||
if (isClearIconVisible && clearIcon && !React.isValidElement(clearIcon)) { | ||
return ( | ||
<SUIIcon | ||
data-testid="datepicker-icon" | ||
link | ||
name={clearIcon} | ||
onClick={onClear} | ||
/> | ||
); | ||
} | ||
|
||
if (icon && React.isValidElement(icon)) { | ||
return React.cloneElement(icon, { | ||
'data-testid': 'datepicker-icon', | ||
onClick, | ||
}); | ||
} | ||
|
||
return ( | ||
<SUIIcon data-testid="datepicker-icon" link name={icon} onClick={onClick} /> | ||
); | ||
}; | ||
|
||
CustomIcon.defaultProps = { | ||
clearIcon: 'close', | ||
icon: 'calendar', | ||
}; | ||
|
||
export default CustomIcon; |
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
Oops, something went wrong.
eb28dbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: