Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the selectedIcon prop to the SidebarItem component #1574

Conversation

rgah2107
Copy link
Collaborator

fix: #1544

Changes proposed in this PR:

@nexxtway/react-rainbow

@commit-lint
Copy link

commit-lint bot commented May 20, 2020

Features

  • add the selectedIcon prop to the SidebarItem component (2e12174)

Bug Fixes

  • modify condition (43b4581)
  • optimize code (1ff80ec)
  • add new icons and modify example (e3f6e9e)
  • modify spec according to the last comments (6894b12)

Contributors

@rgah2107, @LeandroTorresSicilia

return (
<Fragment>
<StyledIcon>{icon}</StyledIcon>
{isSelected ? <StyledIcon>{selectedIcon}</StyledIcon> : <StyledIcon>{icon}</StyledIcon>}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normally we use RenderIf for all internal conditionals of the lib

@rgah2107 rgah2107 requested a review from yvmunayev May 21, 2020 04:09
Comment on lines 34 to 37
<SidebarItem icon={<DashboardPurpleIcon />} name="Dashboard" label="Dashboard" />
<SidebarItem icon={<ApplicationIcon />} name="Aplications" label="Aplications" />
<SidebarItem icon={<PuzzleIcon />} name="Components" label="Components" />
<SidebarItem icon={<MessagesIcon />} name="Messages" label="Messages" />
<SidebarItem
icon={<DashboardPurpleIcon />}
selectedIcon={<UserIcon />}
name="Dashboard"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should leave the example simple and add a new one with the selectedIcon

const isSelected = name === selectedItem;
const selectIcon = selectedIcon || icon;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking and I think you could define the icon here
const currentIcon = isSelected && !!selectedIcon ? selectedIcon : icon;

Comment on lines 59 to 60
icon={icon}
selectedIcon={selectIcon}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it does "icon = {currentIcon}" and you don't have to change the ItemContent

Comment on lines 74 to 75
icon={icon}
selectedIcon={selectIcon}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same before

Comment on lines 7 to 16
export default function ItemContent(props) {
const { label, icon, isSelected } = props;
const { label, icon, selectedIcon, isSelected } = props;
return (
<Fragment>
<StyledIcon>{icon}</StyledIcon>
<RenderIf isTrue={!!isSelected}>
<StyledIcon>{selectedIcon}</StyledIcon>
</RenderIf>
<RenderIf isTrue={!isSelected}>
<StyledIcon>{icon}</StyledIcon>
</RenderIf>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverts the changes

Comment on lines 33 to 35
<Sidebar selectedItem={selectedItem} onSelect={this.handleOnSelect} id="sidebar-1">
<SidebarItem icon={<DashboardPurpleIcon />} name="Dashboard" label="Dashboard" />
<SidebarItem icon={<ApplicationIcon />} name="Aplications" label="Aplications" />
<SidebarItem icon={<PuzzleIcon />} name="Components" label="Components" />
<SidebarItem icon={<MessagesIcon />} name="Messages" label="Messages" />
<SidebarItem
icon={<DashboardPurpleIcon />}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should leave the example simple and add a new one with the selectedIcon

@rgah2107 rgah2107 requested a review from yvmunayev May 22, 2020 14:24
);
const sidebarLink = component.find('a');
sidebarLink.simulate('click');
expect(component.find({ 'data-icon': 'clock' }).exists()).toBe(true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something internal from FontAwesome? If true then we need to change this assertion since we can't make introspection inside what we could not control, font awesome can change this behaviour and then if we update then our test take the risk to fail, instead, we should find the FontAwesomeIcon component in the tree of react components and check that the icon prop passed is faClock

@LeandroTorresSicilia LeandroTorresSicilia merged commit 30e390f into nexxtway:master May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: add the selectedIcon prop to the SidebarItem component
4 participants