PromucFlow_constructor/app/client/src/components/editorComponents/Button.tsx
NandanAnantharamu 05f190c102
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
  to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
  now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 14:22:45 +05:30

145 lines
3.5 KiB
TypeScript

import React from "react";
import {
Intent,
BlueprintButtonIntentsCSS,
Skin,
} from "constants/DefaultTheme";
import styled, { css } from "styled-components";
import {
AnchorButton as BlueprintAnchorButton,
Button as BlueprintButton,
Intent as BlueprintIntent,
IconName,
MaybeElement,
IButtonProps,
} from "@blueprintjs/core";
import { Direction, Directions } from "utils/helpers";
import { omit } from "lodash";
const outline = css`
&&&&&& {
border-width: 1px;
border-style: solid;
}
`;
const buttonStyles = css<Partial<ButtonProps>>`
${BlueprintButtonIntentsCSS}
&&&& {
padding: ${props =>
props.filled || props.outline
? props.theme.spaces[2] + "px " + props.theme.spaces[3] + "px"
: 0};
background: ${props =>
props.filled || props.outline ? "inherit" : "transparent"};
width: ${props => (props.fluid ? "100%" : "auto")};
}
&&&&&& {
&.bp3-button span {
font-weight: ${props => (props.skin !== undefined ? 400 : 700)};
}
.bp3-icon svg {
width: ${props => (props.skin !== undefined ? 14 : 16)}px;
height: ${props => (props.skin !== undefined ? 14 : 16)}px;
}
&.bp3-button {
display: flex;
justify-content: ${props =>
props.skin === undefined
? "center"
: props.iconAlignment === Directions.RIGHT
? "space-between"
: "flex-start"};
}
}
${props => (props.outline ? outline : "")}
`;
const StyledButton = styled((props: IButtonProps & Partial<ButtonProps>) => (
<BlueprintButton
{...omit(props, ["iconAlignment", "fluid", "filled", "outline"])}
/>
))`
${buttonStyles}
`;
const StyledAnchorButton = styled(
(props: IButtonProps & Partial<ButtonProps>) => (
<BlueprintAnchorButton
{...omit(props, ["iconAlignment", "fluid", "filled", "outline"])}
/>
),
)`
${buttonStyles}
`;
export type ButtonProps = {
outline?: boolean;
filled?: boolean;
intent?: Intent;
text?: string;
onClick?: () => void;
href?: string;
icon?: string | MaybeElement;
iconAlignment?: Direction;
loading?: boolean;
disabled?: boolean;
size?: "large" | "small";
type?: "button" | "submit" | "reset";
className?: string;
fluid?: boolean;
skin?: Skin;
target?: string;
};
export const Button = (props: ButtonProps) => {
const icon: IconName | undefined =
props.icon &&
(props.iconAlignment === Directions.LEFT ||
props.iconAlignment === undefined)
? (props.icon as IconName)
: undefined;
const rightIcon: IconName | undefined =
props.icon && props.iconAlignment === Directions.RIGHT
? (props.icon as IconName)
: undefined;
const baseProps = {
text: props.text,
minimal: !props.filled,
outline: !!props.outline,
filled: !!props.filled,
intent: props.intent as BlueprintIntent,
large: props.size === "large",
small: props.size === "small",
loading: props.loading,
disabled: props.disabled,
type: props.type,
className: props.className,
fluid: !!props.fluid,
skin: props.skin,
iconAlignment: props.iconAlignment ? props.iconAlignment : undefined,
};
if (props.href) {
return (
<StyledAnchorButton
icon={icon}
rightIcon={rightIcon}
{...baseProps}
href={props.href}
target={props.target}
/>
);
} else
return (
<StyledButton
rightIcon={rightIcon}
icon={icon}
{...baseProps}
onClick={props.onClick}
/>
);
};
export default Button;