refactor: update component styles

This commit is contained in:
lawvs
2022-08-09 21:04:44 +08:00
parent 50270f87ed
commit 8d1da35b56
2 changed files with 44 additions and 121 deletions

View File

@@ -1,20 +1,18 @@
import styles from './tree-item.module.scss';
import { AddIcon, MoreIcon } from '@toeverything/components/icons';
import {
MuiSnackbar as Snackbar,
Cascader,
CascaderItemProps,
MuiDivider as Divider,
MuiClickAwayListener as ClickAwayListener,
IconButton,
MuiClickAwayListener as ClickAwayListener,
MuiSnackbar as Snackbar,
styled,
} from '@toeverything/components/ui';
import React from 'react';
import { NavLink, useNavigate } from 'react-router-dom';
import { copyToClipboard } from '@toeverything/utils';
import { services, TemplateFactory } from '@toeverything/datasource/db-service';
import { NewFromTemplatePortal } from './NewFromTemplatePortal';
import { useFlag } from '@toeverything/datasource/feature-flags';
import { MoreIcon, AddIcon } from '@toeverything/components/icons';
import { copyToClipboard } from '@toeverything/utils';
import React from 'react';
import { useNavigate } from 'react-router-dom';
import { TreeItemMoreActions } from './styles';
const MESSAGES = {
COPY_LINK_SUCCESS: 'Copyed link to clipboard',
@@ -47,6 +45,10 @@ function DndTreeItemMoreActions(props: ActionsProps) {
set_alert_open(false);
};
const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {
if (anchorEl) {
setAnchorEl(null);
return;
}
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
@@ -246,10 +248,11 @@ function DndTreeItemMoreActions(props: ActionsProps) {
return (
<ClickAwayListener onClickAway={() => handleClose()}>
<div>
<div className={styles['TreeItemMoreActions']}>
<TreeItemMoreActions>
<StyledAction>
<IconButton
size="small"
hoverColor="#E0E6EB"
onClick={handle_new_child_page}
>
<AddIcon />
@@ -262,14 +265,15 @@ function DndTreeItemMoreActions(props: ActionsProps) {
<MoreIcon />
</IconButton>
</StyledAction>
</div>
</TreeItemMoreActions>
<Cascader
items={menuList}
anchorEl={anchorEl}
placement="right-start"
open={open}
onClose={handleClose}
></Cascader>
/>
<Snackbar
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
open={alert_open}

View File

@@ -1,21 +1,22 @@
import React, {
forwardRef,
type CSSProperties,
type HTMLAttributes,
} from 'react';
import { useParams, Link } from 'react-router-dom';
import cx from 'clsx';
import { CloseIcon } from '@toeverything/components/common';
import {
ArrowDropDownIcon,
ArrowRightIcon,
} from '@toeverything/components/icons';
import { forwardRef, type HTMLAttributes } from 'react';
import { useParams } from 'react-router-dom';
import styles from './tree-item.module.scss';
import { useFlag } from '@toeverything/datasource/feature-flags';
import MoreActions from './MoreActions';
import { useTheme } from '@toeverything/components/ui';
import {
ActionButton,
Counter,
TextLink,
TreeItemContainer,
TreeItemContent,
Wrapper,
} from './styles';
export type TreeItemProps = {
/** The main text to display on this line */
value: string;
@@ -67,56 +68,34 @@ export const TreeItem = forwardRef<HTMLDivElement, TreeItemProps>(
'BooleanPageTreeItemMoreActions',
true
);
const theme = useTheme();
return (
<li
<Wrapper
ref={wrapperRef}
className={cx(
styles['Wrapper'],
clone && styles['clone'],
ghost && styles['ghost'],
indicator && styles['indicator'],
disableSelection && styles['disableSelection'],
disableInteraction && styles['disableInteraction']
)}
style={
{
'--spacing': `${indentationWidth * depth}px`,
paddingTop: 0,
paddingBottom: 0,
} as CSSProperties
}
clone={clone}
ghost={ghost}
disableSelection={disableSelection}
disableInteraction={disableInteraction}
spacing={`${indentationWidth * depth}px`}
{...props}
>
<div
ref={ref}
className={styles['TreeItem']}
style={style}
title={value}
>
<Action onClick={onCollapse}>
<TreeItemContainer ref={ref} style={style} title={value}>
<ActionButton tabIndex={0} onClick={onCollapse}>
{childCount !== 0 &&
(collapsed ? (
<ArrowRightIcon />
) : (
<ArrowDropDownIcon />
))}
</Action>
</ActionButton>
<div className={styles['ItemContent']}>
<Link
className={styles['Text']}
{...handleProps}
<TreeItemContent {...handleProps}>
<TextLink
to={`/${workspace_id}/${pageId}`}
style={{
...(pageId === page_id && {
color: theme.affine.palette.primary,
}),
}}
active={pageId === page_id}
>
{value}
</Link>
</TextLink>
{BooleanPageTreeItemMoreActions && (
<MoreActions
workspaceId={workspace_id}
@@ -127,71 +106,11 @@ export const TreeItem = forwardRef<HTMLDivElement, TreeItemProps>(
{/*{!clone && onRemove && <Remove onClick={onRemove} />}*/}
{clone && childCount && childCount > 1 ? (
<span className={styles['Count']}>
{childCount}
</span>
<Counter>{childCount}</Counter>
) : null}
</div>
</div>
</li>
</TreeItemContent>
</TreeItemContainer>
</Wrapper>
);
}
);
export interface ActionProps extends React.HTMLAttributes<HTMLButtonElement> {
active?: {
fill: string;
background: string;
};
// cursor?: CSSProperties['cursor'];
cursor?: 'pointer' | 'grab';
}
/** Customizable buttons */
export function Action({
active,
className,
cursor,
style,
...props
}: ActionProps) {
return (
<button
{...props}
className={cx(styles['Action'], className)}
tabIndex={0}
style={
{
...style,
'--fill': active?.fill,
'--background': active?.background,
} as CSSProperties
}
/>
);
}
export function Handle(props: ActionProps) {
return (
<Action cursor="grab" data-cypress="draggable-handle" {...props}>
<ArrowDropDownIcon />
</Action>
);
}
export function Remove(props: ActionProps) {
return (
<Action
{...props}
active={{
fill: 'rgba(255, 70, 70, 0.95)',
background: 'rgba(255, 70, 70, 0.1)',
}}
>
<CloseIcon style={{ fontSize: 12 }} />
{/* <svg width="8" viewBox="0 0 22 22" xmlns="http://www.w3.org/2000/svg">
<path d="M2.99998 -0.000206962C2.7441 -0.000206962 2.48794 0.0972617 2.29294 0.292762L0.292945 2.29276C-0.0980552 2.68376 -0.0980552 3.31682 0.292945 3.70682L7.58591 10.9998L0.292945 18.2928C-0.0980552 18.6838 -0.0980552 19.3168 0.292945 19.7068L2.29294 21.7068C2.68394 22.0978 3.31701 22.0978 3.70701 21.7068L11 14.4139L18.2929 21.7068C18.6829 22.0978 19.317 22.0978 19.707 21.7068L21.707 19.7068C22.098 19.3158 22.098 18.6828 21.707 18.2928L14.414 10.9998L21.707 3.70682C22.098 3.31682 22.098 2.68276 21.707 2.29276L19.707 0.292762C19.316 -0.0982383 18.6829 -0.0982383 18.2929 0.292762L11 7.58573L3.70701 0.292762C3.51151 0.0972617 3.25585 -0.000206962 2.99998 -0.000206962Z" />
</svg> */}
</Action>
);
}