Added FavoriteButton component
Summary: I've added a favorite button component. The FavoriteButton is a toggle button that has a gold favorited state and an outlined non-favorited state. This is passed in as a prop. Reviewed By: jknoxville Differential Revision: D16418215 fbshipit-source-id: b695ea223d5a543df6bf1e588dc6756f9e84e8e1
This commit is contained in:
committed by
Facebook Github Bot
parent
eeeb32efa9
commit
c6f9d1cb18
47
src/plugins/navigation/components/FavoriteButton.js
Normal file
47
src/plugins/navigation/components/FavoriteButton.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2018-present Facebook.
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
* @format
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {styled} from 'flipper';
|
||||||
|
import {IconButton} from './';
|
||||||
|
|
||||||
|
type Props = {|
|
||||||
|
onClick?: () => void,
|
||||||
|
highlighted: boolean,
|
||||||
|
size: 8 | 10 | 12 | 16 | 18 | 20 | 24 | 32,
|
||||||
|
|};
|
||||||
|
|
||||||
|
const FavoriteButtonContainer = styled('div')({
|
||||||
|
position: 'relative',
|
||||||
|
'>:first-child': {
|
||||||
|
position: 'absolute',
|
||||||
|
},
|
||||||
|
'>:last-child': {
|
||||||
|
position: 'relative',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default (props: Props) => {
|
||||||
|
const {highlighted, onClick, ...iconButtonProps} = props;
|
||||||
|
return (
|
||||||
|
<FavoriteButtonContainer>
|
||||||
|
{highlighted ? (
|
||||||
|
<IconButton
|
||||||
|
outline={false}
|
||||||
|
color="#FFD700"
|
||||||
|
icon="star"
|
||||||
|
{...iconButtonProps}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
<IconButton
|
||||||
|
outline={true}
|
||||||
|
icon="star"
|
||||||
|
onClick={onClick}
|
||||||
|
{...iconButtonProps}
|
||||||
|
/>
|
||||||
|
</FavoriteButtonContainer>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import {styled} from 'flipper';
|
import {styled} from 'flipper';
|
||||||
import {parseURIParameters} from '../util/uri';
|
import {parseURIParameters} from '../util/uri';
|
||||||
import {IconButton} from './';
|
import {IconButton, FavoriteButton} from './';
|
||||||
|
|
||||||
type Props = {|
|
type Props = {|
|
||||||
uri: ?string,
|
uri: ?string,
|
||||||
@@ -64,7 +64,11 @@ export default (props: Props) => {
|
|||||||
return (
|
return (
|
||||||
<NavigationInfoBoxContainer>
|
<NavigationInfoBoxContainer>
|
||||||
<div className="icon-container">
|
<div className="icon-container">
|
||||||
<IconButton icon="star" outline={true} size={16} />
|
<FavoriteButton
|
||||||
|
highlighted={false}
|
||||||
|
size={16}
|
||||||
|
onClick={() => props.onFavorite(uri)}
|
||||||
|
/>
|
||||||
<IconButton
|
<IconButton
|
||||||
icon="eye"
|
icon="eye"
|
||||||
size={16}
|
size={16}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
Toolbar,
|
Toolbar,
|
||||||
Glyph,
|
Glyph,
|
||||||
} from 'flipper';
|
} from 'flipper';
|
||||||
import {IconButton} from './';
|
import {IconButton, FavoriteButton} from './';
|
||||||
|
|
||||||
type Props = {|
|
type Props = {|
|
||||||
onFavorite: (query: string) => void,
|
onFavorite: (query: string) => void,
|
||||||
@@ -29,12 +29,12 @@ const IconContainer = styled('div')({
|
|||||||
display: 'inline-flex',
|
display: 'inline-flex',
|
||||||
height: '16px',
|
height: '16px',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
'>*': {
|
'': {
|
||||||
marginLeft: 10,
|
marginLeft: 10,
|
||||||
'.icon-button': {
|
'.icon-button': {
|
||||||
height: 16,
|
height: 16,
|
||||||
},
|
},
|
||||||
img: {
|
'img,div': {
|
||||||
verticalAlign: 'top',
|
verticalAlign: 'top',
|
||||||
alignItems: 'none',
|
alignItems: 'none',
|
||||||
},
|
},
|
||||||
@@ -86,10 +86,9 @@ class SearchBar extends Component<Props, State> {
|
|||||||
outline={true}
|
outline={true}
|
||||||
onClick={() => this.navigateTo(this.state.query)}
|
onClick={() => this.navigateTo(this.state.query)}
|
||||||
/>
|
/>
|
||||||
<IconButton
|
<FavoriteButton
|
||||||
icon="star"
|
|
||||||
size={16}
|
size={16}
|
||||||
outline={true}
|
highlighted={false}
|
||||||
onClick={() => this.favorite(this.state.query)}
|
onClick={() => this.favorite(this.state.query)}
|
||||||
/>
|
/>
|
||||||
</IconContainer>
|
</IconContainer>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
* @flow strict-local
|
* @flow strict-local
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
export {default as FavoriteButton} from './FavoriteButton';
|
||||||
export {default as IconButton} from './IconButton';
|
export {default as IconButton} from './IconButton';
|
||||||
export {default as NavigationInfoBox} from './NavigationInfoBox';
|
export {default as NavigationInfoBox} from './NavigationInfoBox';
|
||||||
export {default as ScrollableFlexColumn} from './ScrollableFlexColumn';
|
export {default as ScrollableFlexColumn} from './ScrollableFlexColumn';
|
||||||
|
|||||||
Reference in New Issue
Block a user