1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 21:06:42 +07:00

added placeholders

This commit is contained in:
Fedor Katurov 2021-04-21 12:58:44 +07:00
parent 44ab426915
commit b4b138e90f
16 changed files with 239 additions and 117 deletions

View file

@ -0,0 +1,35 @@
import React, { FC, useMemo } from 'react';
import { Placeholder, PlaceholderProps } from '~/components/placeholders/Placeholder';
import styles from './styles.module.scss';
import { Group } from '~/components/containers/Group';
type Props = PlaceholderProps & {
lines?: number;
wordsLimit?: number;
};
const Paragraph: FC<Props> = ({ lines = 3, wordsLimit = 12, ...props }) => {
const iters = useMemo(
() =>
[...new Array(lines)].map(() =>
[...new Array(Math.ceil(Math.random() * wordsLimit))].map((_, i) => i)
),
[lines, wordsLimit]
);
console.log({ iters });
return (
<Group>
{iters.map(words => (
<div className={styles.para}>
{words.map(word => (
<Placeholder key={word} width={`${Math.round(Math.random() * 120) + 60}px`} active />
))}
</div>
))}
</Group>
);
};
export { Paragraph };

View file

@ -0,0 +1,12 @@
@import "src/styles/variables";
.para {
display: flex;
flex-wrap: wrap;
div {
display: inline-flex;
margin-right: $gap;
margin-top: $gap;
}
}

View file

@ -1,28 +0,0 @@
import React, { FC } from 'react';
import { Placeholder } from '~/components/placeholders/Placeholder';
import styles from './styles.module.scss';
import { Group } from '~/components/containers/Group';
const ParagraphPlaceholder = ({}) => (
<Group>
<div className={styles.para}>
<Placeholder width="120px" />
<Placeholder width="60px" />
<Placeholder width="30px" />
<Placeholder width="70px" />
<Placeholder width="160px" />
<Placeholder width="30px" />
</div>
<div className={styles.para}>
<Placeholder width="40px" />
<Placeholder width="30px" />
<Placeholder width="120px" />
<Placeholder width="70px" />
<Placeholder width="160px" />
<Placeholder width="30px" />
</div>
</Group>
);
export { ParagraphPlaceholder };

View file

@ -1,12 +0,0 @@
@import "src/styles/variables";
.para {
display: grid;
grid-template-columns: auto;
grid-auto-columns: auto;
grid-template-rows: 1fr;
grid-column-gap: $gap;
grid-auto-flow: column;
div { display: inline-flex; margin-right: $gap; }
}

View file

@ -1,14 +1,31 @@
import React, { FC } from 'react';
import styles from './styles.module.scss';
import classNames from 'classnames';
interface IProps {
export interface PlaceholderProps {
width?: string;
height?: number;
color?: string;
active?: boolean;
loading?: boolean;
}
const Placeholder: FC<IProps> = ({ width = '120px', height, color }) => (
<div className={styles.placeholder} style={{ height, color, width }} />
);
const Placeholder: FC<PlaceholderProps> = ({
width = '120px',
height,
color,
active,
children,
loading = true,
}) => {
return active ? (
<div
className={classNames(styles.placeholder, { [styles.loading]: loading })}
style={{ height, color, width }}
/>
) : (
<>{children}</>
);
};
export { Placeholder };

View file

@ -1,8 +1,31 @@
@import "src/styles/variables";
@keyframes fade {
0% {
opacity: 0;
}
100% {
opacity: 0.05;
}
}
.placeholder {
height: 1em;
width: 120px;
background: $placeholder_bg;
border-radius: 1em;
position: relative;
overflow: hidden;
&::after {
content: ' ';
width: 200%;
height: 100%;
position: absolute;
top: 0;
left: 0;
background: white;
animation: fade 0.5s infinite alternate;
border-radius: 1em;
}
}