fix: fix ui problems

This commit is contained in:
QiShaoXuan 2022-08-11 18:52:31 +08:00
parent 716c9ea34c
commit 5e3f914182
4 changed files with 57 additions and 33 deletions

View File

@ -4,6 +4,7 @@ import type { AsyncBlock } from '../editor';
import { PendantPopover } from './pendant-popover'; import { PendantPopover } from './pendant-popover';
import { PendantRender } from './pendant-render'; import { PendantRender } from './pendant-render';
import { useRef } from 'react'; import { useRef } from 'react';
import { getRecastItemValue, useRecastBlockMeta } from '../recast-block';
/** /**
* @deprecated * @deprecated
*/ */
@ -16,15 +17,26 @@ export const BlockPendantProvider: FC<PropsWithChildren<BlockTagProps>> = ({
children, children,
}) => { }) => {
const triggerRef = useRef<HTMLDivElement>(); const triggerRef = useRef<HTMLDivElement>();
const { getProperties } = useRecastBlockMeta();
const properties = getProperties();
const { getValue } = getRecastItemValue(block);
const showTriggerLine =
properties.filter(property => getValue(property.id)).length === 0;
return ( return (
<Container> <Container>
{children} {children}
<StyledPendantContainer ref={triggerRef}> {showTriggerLine ? (
<PendantPopover block={block} container={triggerRef.current}> <StyledPendantContainer ref={triggerRef}>
<StyledTriggerLine /> <PendantPopover
</PendantPopover> block={block}
</StyledPendantContainer> container={triggerRef.current}
>
<StyledTriggerLine />
</PendantPopover>
</StyledPendantContainer>
) : null}
<PendantRender block={block} /> <PendantRender block={block} />
</Container> </Container>

View File

@ -81,7 +81,7 @@ export const CreatePendantPanel = ({
setFieldName(e.target.value); setFieldName(e.target.value);
}} }}
endAdornment={ endAdornment={
<Tooltip content="Help info here"> <Tooltip content="Help info here" placement="top">
<StyledInputEndAdornment> <StyledInputEndAdornment>
<HelpCenterIcon /> <HelpCenterIcon />
</StyledInputEndAdornment> </StyledInputEndAdornment>

View File

@ -70,7 +70,7 @@ export const UpdatePendantPanel = ({
setFieldName(e.target.value); setFieldName(e.target.value);
}} }}
endAdornment={ endAdornment={
<Tooltip content="Help info here"> <Tooltip content="Help info here" placement="top">
<StyledInputEndAdornment> <StyledInputEndAdornment>
<HelpCenterIcon /> <HelpCenterIcon />
</StyledInputEndAdornment> </StyledInputEndAdornment>

View File

@ -12,6 +12,7 @@ import SelectUnstyled, {
} from '@mui/base/SelectUnstyled'; } from '@mui/base/SelectUnstyled';
/* eslint-disable no-restricted-imports */ /* eslint-disable no-restricted-imports */
import PopperUnstyled from '@mui/base/PopperUnstyled'; import PopperUnstyled from '@mui/base/PopperUnstyled';
import { ArrowDropDownIcon } from '@toeverything/components/icons';
import { styled } from '../styled'; import { styled } from '../styled';
type ExtendSelectProps = { type ExtendSelectProps = {
@ -41,20 +42,29 @@ export const Select = forwardRef(function CustomSelect<TValue>(
const { width = '100%', style, listboxStyle, placeholder } = props; const { width = '100%', style, listboxStyle, placeholder } = props;
const components: SelectUnstyledProps<TValue>['components'] = { const components: SelectUnstyledProps<TValue>['components'] = {
// Root: generateStyledRoot({ width, ...style }), // Root: generateStyledRoot({ width, ...style }),
Root: forwardRef((rootProps, rootRef) => ( Root: forwardRef((rootProps, rootRef) => {
<StyledRoot const {
ref={rootRef} ownerState: { open },
{...rootProps} } = rootProps;
style={{
width, return (
...style, <StyledRoot
}} ref={rootRef}
> {...rootProps}
{rootProps.children || ( style={{
<StyledPlaceholder>{placeholder}</StyledPlaceholder> width,
)} ...style,
</StyledRoot> }}
)), >
{rootProps.children || (
<StyledPlaceholder>{placeholder}</StyledPlaceholder>
)}
<StyledSelectedArrowWrapper open={open}>
<ArrowDropDownIcon />
</StyledSelectedArrowWrapper>
</StyledRoot>
);
}),
Listbox: forwardRef((listboxProps, listboxRef) => ( Listbox: forwardRef((listboxProps, listboxRef) => (
<StyledListbox <StyledListbox
ref={listboxRef} ref={listboxRef}
@ -73,6 +83,20 @@ export const Select = forwardRef(function CustomSelect<TValue>(
RefAttributes<HTMLUListElement> RefAttributes<HTMLUListElement>
) => JSX.Element; ) => JSX.Element;
const StyledSelectedArrowWrapper = styled('div')<{ open: boolean }>(
({ open }) => ({
position: 'absolute',
top: '0',
bottom: '0',
right: '12px',
margin: 'auto',
lineHeight: '32px',
display: 'flex',
alignItems: 'center',
transform: `rotate(${open ? '180deg' : '0'})`,
})
);
const StyledRoot = styled('div')(({ theme }) => ({ const StyledRoot = styled('div')(({ theme }) => ({
height: '32px', height: '32px',
border: `1px solid ${theme.affine.palette.borderColor}`, border: `1px solid ${theme.affine.palette.borderColor}`,
@ -95,18 +119,6 @@ const StyledRoot = styled('div')(({ theme }) => ({
[`&.${selectUnstyledClasses.expanded}`]: { [`&.${selectUnstyledClasses.expanded}`]: {
borderColor: `${theme.affine.palette.primary}`, borderColor: `${theme.affine.palette.primary}`,
'&::after': {
content: '"▴"',
},
},
'&::after': {
content: '"▾"',
position: ' absolute',
top: '0',
bottom: '0',
right: '12px',
margin: 'auto',
lineHeight: '32px',
}, },
})); }));