Skip to content

Commit

Permalink
Merge pull request #491 from kinvolk/plugins-in-style
Browse files Browse the repository at this point in the history
plugins: Show how to use styles inside a plugin
  • Loading branch information
joaquimrocha authored Apr 20, 2022
2 parents d22f568 + b7ba608 commit 69f83dc
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions plugins/examples/pod-counter/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
import React from 'react';
import { Headlamp, Plugin, Registry, K8s } from '@kinvolk/headlamp-plugin/lib';
import { Headlamp, K8s, Plugin, Registry } from '@kinvolk/headlamp-plugin/lib';
import { Typography } from '@material-ui/core';

import { makeStyles } from '@material-ui/styles';
import React from 'react';
// import { SectionBox } from '@kinvolk/headlamp-plugin/lib/CommonComponents';

const useStyle = makeStyles(() => ({
pods: {
fontStyle: 'italic',
},
}));

function PodCounter() {
const classes = useStyle();
const [pods, error] = K8s.ResourceClasses.Pod.useList();
const msg = pods === null ? 'Loading…' : pods.length.toString();

return (
<Typography color="textPrimary">{!error ? `# Pods: ${msg}` : 'Uh, pods!?'}</Typography>
<Typography color="textPrimary" className={classes.pods}>
{!error ? `# Pods: ${msg}` : 'Uh, pods!?'}
</Typography>
);
}

class PodCounterPlugin extends Plugin {
initialize(registry: Registry) {
registry.registerAppBarAction('pod-counter-action', () =>
<PodCounter />
);

registry.registerAppBarAction('pod-counter-action', () => <PodCounter />);
return true;
}
}
Expand Down

0 comments on commit 69f83dc

Please sign in to comment.