Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui v2: horizontal rule #723

Merged
merged 4 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions frontend/packages/core/src/Resolver/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import styled from "styled-components";
import { Button } from "../button";
import { useWizardContext } from "../Contexts";
import { CompressedError, Error } from "../error";
import { HorizontalRule } from "../horizontal-rule";
import Loadable from "../loading";

import { fetchResourceSchemas, resolveResource } from "./fetch";
Expand All @@ -15,10 +16,6 @@ import { QueryResolver, SchemaResolver } from "./input";
import type { DispatchAction } from "./state";
import { ResolverAction, useResolverState } from "./state";

const Spacer = styled.div`
margin: 10px;
`;

const Form = styled.form`
align-items: center;
display: flex;
Expand Down Expand Up @@ -130,11 +127,7 @@ const Resolver: React.FC<ResolverProps> = ({ type, searchLimit, onResolve, varia
/>
</Form>
)}
{variant === "dual" && (
<>
<Spacer />- OR -
</>
)}
{variant === "dual" && <HorizontalRule>OR</HorizontalRule>}
{(variant === "dual" || variant === "schema") && (
<Form onSubmit={validation.handleSubmit(submitHandler)} noValidate>
<SchemaResolver
Expand Down
49 changes: 49 additions & 0 deletions frontend/packages/core/src/horizontal-rule.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as React from "react";
import styled from "@emotion/styled";

const HorizontalRuleBase = ({ children, ...props }: HorizontalRuleProps) => (
<div {...props}>
<div className="line">
<span />
</div>
{React.Children.count(children) > 0 && <div className="content">{children}</div>}
<div className="line">
<span />
</div>
</div>
);

export type HorizontalRuleProps = {
children: React.ReactNode;
};

const StyledHorizontalRule = styled(HorizontalRuleBase)({
alignItems: "center",
display: "flex",
flexDirection: "row",
width: "100%",

".line": {
flex: "1 1 auto",
},

".line > span": {
display: "block",
borderTop: "1px solid rgba(13, 16, 48, 0.12)",
},

".content": {
padding: "0 30px",
fontWeight: "bold",
color: "rgba(13, 16, 48, 0.38)",
textTransform: "uppercase",
display: "inline-flex",
alignItems: "center",
},
});

export const HorizontalRule = ({ children }: HorizontalRuleProps) => (
<StyledHorizontalRule>{children}</StyledHorizontalRule>
);

export default HorizontalRule;
31 changes: 31 additions & 0 deletions frontend/packages/core/src/stories/horizontal-rule.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from "react";
import ErrorIcon from "@material-ui/icons/Error";
import type { Meta } from "@storybook/react";

import type { HorizontalRuleProps } from "../horizontal-rule";
import { HorizontalRule } from "../horizontal-rule";

export default {
title: "Core/HorizontalRule",
component: HorizontalRule,
} as Meta;

const Template = (props: HorizontalRuleProps) => <HorizontalRule {...props} />;

export const Basic = Template.bind({});
Basic.args = {
children: "OR",
};

export const WithIcon = Template.bind({});
WithIcon.args = {
children: (
<>
<ErrorIcon />
&nbsp;Proceed with caution
</>
),
};

export const WithoutText = Template.bind({});
WithoutText.args = {};
danielhochman marked this conversation as resolved.
Show resolved Hide resolved