f896e304999380412326cd1f01f1ebf78d52edb3
[arvados-workbench2.git] / src / views-components / favorite-star / favorite-star.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from "react";
6 import { FavoriteIcon } from "../../components/icon/icon";
7 import { connect } from "react-redux";
8 import { RootState } from "../../store/store";
9 import { withStyles, StyleRulesCallback, WithStyles } from "@material-ui/core";
10
11 type CssRules = "icon";
12
13 const styles: StyleRulesCallback<CssRules> = theme => ({
14     icon: {
15         fontSize: "inherit"
16     }
17 });
18
19 const mapStateToProps = (state: RootState, props: { resourceUuid: string; className?: string; }) => ({
20     ...props,
21     visible: state.favorites[props.resourceUuid],
22 });
23
24 export const FavoriteStar = connect(mapStateToProps)(
25     withStyles(styles)((props: { visible: boolean; className?: string; } & WithStyles<CssRules>) =>
26         props.visible ? <FavoriteIcon className={props.className || props.classes.icon} /> : null
27     ));