ghost-portal/packages/react-components/src/Menu/Item.tsx
Jaco e214c0fde8
Additional styled injection changes to components (#8809)
* Additional styled injection changes to components

* Couple more

* One from claims (previously missed)

* Adjust

* Fix some build issues

* Final build adjustments

* Adjust address whitepace

* Adjust bounties
2023-01-15 13:25:59 +02:00

65 lines
1.3 KiB
TypeScript

// Copyright 2017-2023 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ItemProps } from './types';
import React, { useCallback } from 'react';
import styled from 'styled-components';
import Icon from '../Icon';
function Item ({ children, className = '', icon, isDisabled, label, onClick }: ItemProps): React.ReactElement<ItemProps> {
const _onClick = useCallback(
(): void => {
!isDisabled && onClick && onClick();
},
[isDisabled, onClick]
);
return (
<StyledDiv
className={`ui--Menu__Item ${className}${icon ? ' hasIcon' : ''}${isDisabled ? ' isDisabled' : ''}`}
onClick={_onClick}
>
{icon && (
<Icon
color='darkGray'
icon={icon}
/>
)}
{label}{children}
</StyledDiv>
);
}
const StyledDiv = styled.div`
align-items: center;
cursor: pointer;
display: flex;
flex-direction: row;
font-size: var(--font-size-small);
line-height: 0.93rem;
padding: 0.5rem 1rem;
position: relative;
&:last-child {
margin-bottom: 0;
}
&.hasIcon {
padding-left: 2.6rem;
}
.ui--Icon {
position: absolute;
left: 1rem;
}
&.isDisabled {
cursor: default;
opacity: 0.5;
}
`;
export default React.memo(Item);