1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00

added flow shade

This commit is contained in:
Fedor Katurov 2021-10-05 18:13:01 +07:00
parent 57d803f4d8
commit 59ca076287
7 changed files with 56 additions and 2 deletions

View file

@ -9,6 +9,7 @@ import { Icon } from '~/components/input/Icon';
import { PRESETS } from '~/constants/urls'; import { PRESETS } from '~/constants/urls';
import { NODE_TYPES } from '~/redux/node/constants'; import { NODE_TYPES } from '~/redux/node/constants';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { CellShade } from '~/components/flow/CellShade';
const THUMBNAIL_SIZES = { const THUMBNAIL_SIZES = {
horizontal: PRESETS.small_hero, horizontal: PRESETS.small_hero,
@ -26,7 +27,6 @@ interface IProps {
const Cell: FC<IProps> = ({ const Cell: FC<IProps> = ({
node: { id, title, thumbnail, type, flow, description }, node: { id, title, thumbnail, type, flow, description },
can_edit, can_edit,
onSelect,
onChangeCellView, onChangeCellView,
}) => { }) => {
const ref = useRef(null); const ref = useRef(null);
@ -112,6 +112,8 @@ const Cell: FC<IProps> = ({
)} )}
<Link className={classNames(styles.face)} to={`/post${id}`}> <Link className={classNames(styles.face)} to={`/post${id}`}>
<CellShade color={flow.dominant_color} />
<div className={styles.face_content}> <div className={styles.face_content}>
{!text && <div className={classNames(styles.title, titleSize)}>{title || '...'}</div>} {!text && <div className={classNames(styles.title, titleSize)}>{title || '...'}</div>}

View file

@ -195,7 +195,6 @@
left: 0; left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
background: linear-gradient(5deg, transparentize($content_bg, 0), transparentize($content_bg, 1));
z-index: 2; z-index: 2;
border-radius: $cell_radius; border-radius: $cell_radius;
padding: $gap / 2; padding: $gap / 2;

View file

@ -0,0 +1,26 @@
import React, { FC, useMemo } from 'react';
import styles from './styles.module.scss';
import { DEFAULT_DOMINANT_COLOR } from '~/constants/node';
import { convertHexToRGBA } from '~/utils/color';
import { DivProps } from '~/utils/types';
import classNames from 'classnames';
interface Props extends DivProps {
color?: string;
}
const CellShade: FC<Props> = ({ color, ...rest }) => {
const background = useMemo(() => {
if (!color || color === DEFAULT_DOMINANT_COLOR) {
return undefined;
}
return `linear-gradient(10deg, ${color} 30px, ${convertHexToRGBA(color, 0.2)} 200px)`;
}, [color]);
return (
<div {...rest} className={classNames(rest.className, styles.shade)} style={{ background }} />
);
};
export { CellShade };

View file

@ -0,0 +1,12 @@
@import "~/styles/variables";
.shade {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(5deg, transparentize($content_bg, 0), transparentize($content_bg, 1));
pointer-events: none;
touch-action: none;
}

1
src/constants/node.ts Normal file
View file

@ -0,0 +1 @@
export const DEFAULT_DOMINANT_COLOR = '#000000';

View file

@ -133,6 +133,7 @@ export interface INode {
flow: { flow: {
display: 'single' | 'vertical' | 'horizontal' | 'quadro'; display: 'single' | 'vertical' | 'horizontal' | 'quadro';
show_description: boolean; show_description: boolean;
dominant_color?: string;
}; };
tags: ITag[]; tags: ITag[];

13
src/utils/color.ts Normal file
View file

@ -0,0 +1,13 @@
export const convertHexToRGBA = (hexCode, opacity) => {
let hex = hexCode.replace('#', '');
if (hex.length === 3) {
hex = `${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}`;
}
const r = parseInt(hex.substring(0, 2), 16);
const g = parseInt(hex.substring(2, 4), 16);
const b = parseInt(hex.substring(4, 6), 16);
return `rgba(${r},${g},${b},${opacity})`;
};