Merge pull request #4272 from viavarejo/feature/add-classname-to-sidebaritem

Add className to the SidebarItem
This commit is contained in:
Fredrik Adelöw
2021-01-28 22:34:23 +01:00
committed by GitHub
4 changed files with 26 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/core': patch
---
Add className to the SidebarItem
+1
View File
@@ -35,6 +35,7 @@
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
"@testing-library/react-hooks": "^3.4.2",
"@types/dagre": "^0.7.44",
"@types/react": "^16.9",
"@types/react-sparklines": "^1.7.0",
@@ -22,8 +22,18 @@ import HomeIcon from '@material-ui/icons/Home';
import CreateComponentIcon from '@material-ui/icons/AddCircleOutline';
import { Sidebar } from './Bar';
import { SidebarItem } from './Items';
import { renderHook } from '@testing-library/react-hooks';
import { hexToRgb, makeStyles } from '@material-ui/core';
const useStyles = makeStyles({
spotlight: {
backgroundColor: '#2b2a2a',
},
});
async function renderSidebar() {
const { result } = renderHook(() => useStyles());
await renderInTestApp(
<Sidebar>
<SidebarItem text="Home" icon={HomeIcon} to="./" />
@@ -31,6 +41,7 @@ async function renderSidebar() {
icon={CreateComponentIcon}
onClick={() => {}}
text="Create..."
className={result.current.spotlight}
/>
</Sidebar>,
);
@@ -54,5 +65,11 @@ describe('Items', () => {
await screen.findByRole('button', { name: /create/i }),
).toBeInTheDocument();
});
it('should render a button with custom style', async () => {
expect(
await screen.findByRole('button', { name: /create/i }),
).toHaveStyle(`background-color: ${hexToRgb('2b2a2a')}`);
});
});
});
@@ -128,6 +128,7 @@ type SidebarItemBaseProps = {
text?: string;
hasNotifications?: boolean;
children?: ReactNode;
className?: string;
};
type SidebarItemButtonProps = SidebarItemBaseProps & {
@@ -154,6 +155,7 @@ export const SidebarItem = forwardRef<any, SidebarItemProps>((props, ref) => {
hasNotifications = false,
onClick,
children,
className,
} = props;
const classes = useStyles();
// XXX (@koroeskohr): unsure this is optimal. But I just really didn't want to have the item component
@@ -193,6 +195,7 @@ export const SidebarItem = forwardRef<any, SidebarItemProps>((props, ref) => {
const childProps = {
onClick,
className: clsx(
className,
classes.root,
isOpen ? classes.open : classes.closed,
isButtonItem(props) && classes.buttonItem,