* fix: add disclosure and transition * fix: keep collections expanded * fix: tune transition and collapsing conditions * fix: collectionIcon expanded props is no longer driven by expanded state * fix: sync issue * fix: managing state together * fix: remove comment * fix: simplify expanded state * fix: remove extra state * fix: remove animation and retain expanded state * fix: remove isCollectionDropped * fix: don't use ref * review suggestions * fix many functional and design issues * don't render every single document in the sidebar, just ones that the user has seen before * chore: Sidebar refinement (#3154) * stash * wip: More sidebar tweaks * Simplify draft bubble * disclosure refactor * wip wip * lint * tweak menu position * Use document emoji for starred docs where available * feat: Trigger cmd+k from sidebar (#3149) * feat: Trigger cmd+k from sidebar * Add hint when opening command bar from sidebar * fix: Clicking internal links in shared documents sometimes reroutes to Login * fix: Spacing issues on connected slack channels list * Merge * fix: Do not prefetch JS bundles on public share links * fix: Buttons show on collection empty state when user does not have permission to edit * fix: the hover area for the "collections" subheading was being obfuscated by the initial collection drop cursor * fix: top-align disclosures * fix: Disclosure color PR feedback fix: Starred no longer draggable * fix: Overflow on sidebar button * fix: Scrollbar in sidebar when command menu is open * Minor alignment issues, clarify back in settings sidebar * fix: Fade component causes SidebarButton missizing Co-authored-by: Nan Yu <thenanyu@gmail.com> Co-authored-by: Tom Moor <tom.moor@gmail.com> Co-authored-by: Nan Yu <thenanyu@gmail.com>
76 lines
1.6 KiB
TypeScript
76 lines
1.6 KiB
TypeScript
import { observable } from "mobx";
|
|
import { observer } from "mobx-react";
|
|
import * as React from "react";
|
|
import styled from "styled-components";
|
|
import User from "~/models/User";
|
|
import placeholder from "./placeholder.png";
|
|
|
|
type Props = {
|
|
src: string;
|
|
size: number;
|
|
icon?: React.ReactNode;
|
|
user?: User;
|
|
alt?: string;
|
|
showBorder?: boolean;
|
|
onClick?: React.MouseEventHandler<HTMLImageElement>;
|
|
className?: string;
|
|
};
|
|
|
|
@observer
|
|
class Avatar extends React.Component<Props> {
|
|
@observable
|
|
error: boolean;
|
|
|
|
static defaultProps = {
|
|
size: 24,
|
|
};
|
|
|
|
handleError = () => {
|
|
this.error = true;
|
|
};
|
|
|
|
render() {
|
|
const { src, icon, showBorder, ...rest } = this.props;
|
|
return (
|
|
<AvatarWrapper>
|
|
<CircleImg
|
|
onError={this.handleError}
|
|
src={this.error ? placeholder : src}
|
|
$showBorder={showBorder}
|
|
{...rest}
|
|
/>
|
|
{icon && <IconWrapper>{icon}</IconWrapper>}
|
|
</AvatarWrapper>
|
|
);
|
|
}
|
|
}
|
|
|
|
const AvatarWrapper = styled.div`
|
|
position: relative;
|
|
`;
|
|
|
|
const IconWrapper = styled.div`
|
|
display: flex;
|
|
position: absolute;
|
|
bottom: -2px;
|
|
right: -2px;
|
|
background: ${(props) => props.theme.primary};
|
|
border: 2px solid ${(props) => props.theme.background};
|
|
border-radius: 100%;
|
|
width: 20px;
|
|
height: 20px;
|
|
`;
|
|
|
|
const CircleImg = styled.img<{ size: number; $showBorder?: boolean }>`
|
|
display: block;
|
|
width: ${(props) => props.size}px;
|
|
height: ${(props) => props.size}px;
|
|
border-radius: 50%;
|
|
border: 2px solid
|
|
${(props) =>
|
|
props.$showBorder === false ? "transparent" : props.theme.background};
|
|
flex-shrink: 0;
|
|
`;
|
|
|
|
export default Avatar;
|