Skip to content

Commit

Permalink
feat: add skeleton loading placeholders for detail cards and fix sele…
Browse files Browse the repository at this point in the history
…ct field option (#157)

* Add background back to SelectField

* Add Shimmer loading to details

* Add loading states to design system
  • Loading branch information
alexieyizhe authored May 23, 2021
1 parent 092bc30 commit 12d5cae
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 18 deletions.
29 changes: 27 additions & 2 deletions src/components/Card/DetailsCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import styled from "styled-components";
import classNames from "classnames";

import Card from "src/components/Card";
import Spinner from "src/components/Spinner";
import Text from "src/components/Text";
import {
HeadingShimmer,
ParagraphShimmer,
SubheadingShimmer,
} from "src/components/Shimmer";
import SelectField, { ISelectFieldProps } from "src/components/SelectField";
import { MOBILE_MENU_MEDIA_QUERY } from "src/components/PageHeader";
import { ICardProps } from "../RawCard";
Expand Down Expand Up @@ -60,6 +64,27 @@ const Container = styled(Card)`
`}
`;

const LoadingContainer = styled.div`
display: flex;
height: 100%;
flex-direction: column;
justify-content: space-between;
margin-bottom: 12px;
& > .loadingHeading {
margin-bottom: 24px;
}
`;
const DetailsCardLoadingShimmer = () => (
<LoadingContainer>
<div className="loadingHeading">
<HeadingShimmer />
<SubheadingShimmer />
</div>
<ParagraphShimmer />
</LoadingContainer>
);

/*******************************************************************
* **Component** *
*******************************************************************/
Expand All @@ -83,7 +108,7 @@ const DetailsCard: React.FC<IDetailsCardProps> = ({
{ERROR_OCCURRED_TEXT}
</Text>
) : loading ? (
<Spinner className="loading" />
<DetailsCardLoadingShimmer />
) : (
children
)}
Expand Down
1 change: 1 addition & 0 deletions src/components/Checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const sharedStyles = css`

const disabledStyles = css`
&:disabled {
background-color: ${({ theme }) => theme.color.backgroundSecondary};
cursor: not-allowed;
}
Expand Down
16 changes: 8 additions & 8 deletions src/components/PageFooter/copy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,23 @@ const COPY = {
getSubtext,
sublinks: [
{
to: `mailto:${EMAIL}`,
label: "get in touch",
to: RouteName.DESIGN,
label: "design system",
newTab: false,
},
{
to: FEEDBACK_LINK,
label: "submit feedback",
to: "https://github.com/alexieyizhe/intern.plus",
label: "open source",
newTab: true,
},
{
to: "https://github.com/alexieyizhe/intern.plus",
label: "open source",
to: FEEDBACK_LINK,
label: "submit feedback",
newTab: true,
},
{
to: RouteName.DESIGN,
label: "design system",
to: `mailto:${EMAIL}`,
label: "get in touch",
newTab: false,
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/components/SelectField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface ISelectFieldProps
* **Utility functions/constants** *
*******************************************************************/
const renderSuggestion = (suggestion: { label: string; value: string }) => (
<Suggestion color="textTertiary" key={suggestion.value}>
<Suggestion backgroundColor="textTertiary" key={suggestion.value}>
<Text variant="subheading" color="textPrimary">
{suggestion.label}
</Text>
Expand Down
9 changes: 9 additions & 0 deletions src/components/Shimmer/HeadingShimmer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from "react";

import { Size } from "src/theme";

import Shimmer from "./Shimmer";

export const HeadingShimmer = () => (
<Shimmer width="24rem" textSize={Size.XL} />
);
11 changes: 11 additions & 0 deletions src/components/Shimmer/ParagraphShimmer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";

import Shimmer from "./Shimmer";

export const ParagraphShimmer = () => (
<>
<Shimmer />
<Shimmer />
<Shimmer width="80%" />
</>
);
53 changes: 53 additions & 0 deletions src/components/Shimmer/Shimmer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import styled from "styled-components";

import { Size } from "src/theme";

export default styled.div<{
width?: string;
height?: string;
textSize?: Size;
}>`
background: ${({ theme }) => theme.color.textTertiary};
background-image: linear-gradient(
to right,
${({ theme }) => theme.color.textTertiary} 0%,
${({ theme }) => theme.color.textSecondary} 25%,
${({ theme }) => theme.color.textTertiary} 60%,
${({ theme }) => theme.color.textTertiary} 100%
);
background-repeat: no-repeat;
background-size: 800px 104px;
display: flex;
flex: 1;
position: relative;
border-radius: ${({ theme }) => theme.borderRadius.large}px;
opacity: 0.8;
margin-bottom: 12px;
animation-duration: 1s;
animation-fill-mode: forwards;
animation-iteration-count: infinite;
animation-name: placeholderShimmer;
animation-timing-function: linear;
${({ width }) => (width ? `width: ${width}` : "")};
${({ height }) => (height ? `height: ${height}` : "")};
font-size: ${({ textSize = Size.SMALL, theme }) =>
theme.fontSize[textSize]}px;
@keyframes placeholderShimmer {
0% {
background-position: -400px 0;
}
100% {
background-position: 800px 0;
}
}
&:after {
color: transparent;
content: "a";
}
`;
9 changes: 9 additions & 0 deletions src/components/Shimmer/SubheadingShimmer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from "react";

import { Size } from "src/theme";

import Shimmer from "./Shimmer";

export const SubheadingShimmer = () => (
<Shimmer width="18rem" textSize={Size.LARGE} />
);
4 changes: 4 additions & 0 deletions src/components/Shimmer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { default as Shimmer } from "./Shimmer";
export { HeadingShimmer } from "./HeadingShimmer";
export { SubheadingShimmer } from "./SubheadingShimmer";
export { ParagraphShimmer } from "./ParagraphShimmer";
2 changes: 2 additions & 0 deletions src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export * from "./SearchResultCardDisplay";
export { default as Select } from "./Select";
export * from "./Select";

export * from "./Shimmer";

export { default as Spinner } from "./Spinner";
export * from "./Spinner";

Expand Down
4 changes: 2 additions & 2 deletions src/pages/design-system/components/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export interface ISectionProps {
heading?: string;
}

const Container = styled.div`
const Container = styled.section`
min-width: 40%;
margin: 10px 10% 50px 0;
margin: 10px 5% 50px 0;
display: inline-flex;
flex-direction: column;
Expand Down
25 changes: 20 additions & 5 deletions src/pages/design-system/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import {
TextInput,
Icon,
IconName,
Spinner,
HeadingShimmer,
ParagraphShimmer,
} from "src/components";
import { useScrollTopOnMount } from "src/shared/hooks/useScrollTopOnMount";

Expand Down Expand Up @@ -71,6 +74,12 @@ const SectionSpacer = styled.div`
}
`;

const DesignPageContainer = styled(PageContainer)`
& > section {
max-width: 45%;
}
`;

const PaletteSquare = styled(Card)`
width: 100px;
height: 100px;
Expand All @@ -80,8 +89,8 @@ const PaletteSquare = styled(Card)`
justify-content: center;
align-items: center;
${({ theme, color }) =>
color === theme.color.backgroundPrimary &&
${({ theme, backgroundColor }) =>
backgroundColor === theme.color.backgroundPrimary &&
`border: 2px solid ${theme.color.textPrimary}`};
`;

Expand All @@ -102,15 +111,15 @@ const DesignSystemPage = () => {
<title>Design system • intern+</title>
</Helmet>

<PageContainer id="design-system-page">
<DesignPageContainer id="design-system-page">
<Text variant="heading1" as="h1">
Design System
</Text>

<Section heading="Colors">
<SectionSpacer>
{(Object.values(theme.color) as string[]).map((color: string) => (
<PaletteSquare color={color} key={color}>
<PaletteSquare backgroundColor={color} key={color}>
<Text
variant="subheading"
color={
Expand Down Expand Up @@ -326,7 +335,13 @@ const DesignSystemPage = () => {
</Text>
</LandingReviewCard>
</Section>
</PageContainer>

<Section heading="Loading States">
<HeadingShimmer />
<ParagraphShimmer />
<Spinner />
</Section>
</DesignPageContainer>
</>
);
};
Expand Down

0 comments on commit 12d5cae

Please sign in to comment.