Skip to content

Commit ef5cffc

Browse files
committed
feat(json-crdt-peritext-ui): 🎸 improve context menu header presentation
1 parent 35e7d65 commit ef5cffc

File tree

4 files changed

+68
-12
lines changed

4 files changed

+68
-12
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as React from 'react';
2+
import {drule, useTheme} from 'nano-theme';
3+
4+
const blockClass = drule({
5+
pd: '8px 20px',
6+
});
7+
8+
export interface ContextHeaderProps extends React.AllHTMLAttributes<any> {
9+
compact?: boolean;
10+
children?: React.ReactNode;
11+
}
12+
13+
export const ContextHeader: React.FC<ContextHeaderProps> = ({compact, children, ...rest}) => {
14+
const theme = useTheme();
15+
16+
const className =
17+
(rest.className || '') +
18+
blockClass({
19+
bg: theme.g(0, 0.05),
20+
});
21+
22+
const style: React.CSSProperties = {
23+
padding: compact ? '8px' : void 0,
24+
...rest.style,
25+
};
26+
27+
return (
28+
<div className={className} style={style}>
29+
{children}
30+
</div>
31+
);
32+
};

src/json-crdt-peritext-ui/components/ContextPaneHeader.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import * as React from 'react';
2-
import {ContextHeader} from 'nice-ui/lib/4-card/ContextMenu/ContextHeader';
2+
import {ContextHeader} from './ContextHeader';
33
import {BasicButtonBack} from 'nice-ui/lib/2-inline-block/BasicButton/BasicButtonBack';
44
import {BasicButtonClose} from 'nice-ui/lib/2-inline-block/BasicButton/BasicButtonClose';
55
import {Flex} from 'nice-ui/lib/3-list-item/Flex';
6+
import {Split} from 'nice-ui/lib/3-list-item/Split';
67

78
export interface ContextPaneHeaderProps {
9+
short?: boolean;
810
children?: React.ReactNode;
911
onBackClick?: React.MouseEventHandler;
1012
onCloseClick?: React.MouseEventHandler;
1113
}
1214

13-
export const ContextPaneHeader: React.FC<ContextPaneHeaderProps> = ({children, onBackClick, onCloseClick}) => {
15+
export const ContextPaneHeader: React.FC<ContextPaneHeaderProps> = ({short, children, onBackClick, onCloseClick}) => {
1416
let element = (
1517
<Flex style={{alignItems: 'center'}}>
1618
{!!onBackClick && <BasicButtonBack onClick={onBackClick} />}
@@ -20,15 +22,15 @@ export const ContextPaneHeader: React.FC<ContextPaneHeaderProps> = ({children, o
2022

2123
if (onCloseClick) {
2224
element = (
23-
<Flex style={{alignItems: 'center'}}>
25+
<Split style={{alignItems: 'center'}}>
2426
{element}
2527
{!!onCloseClick && <BasicButtonClose onClick={onCloseClick} />}
26-
</Flex>
28+
</Split>
2729
);
2830
}
2931

3032
return (
31-
<ContextHeader compact>
33+
<ContextHeader style={{padding: short ? '12px 16px' : '16px'}}>
3234
{element}
3335
</ContextHeader>
3436
);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as React from 'react';
2+
import {useStyles} from 'nice-ui/lib/styles/context';
3+
4+
export interface ContextPaneHeaderSepProps {}
5+
6+
export const ContextPaneHeaderSep: React.FC<ContextPaneHeaderSepProps> = () => {
7+
const style = useStyles();
8+
9+
return (
10+
<div style={{background: style.g(0, 0.05), width: '100%', height: '8px'}}>
11+
<div style={{background: style.col.mapped('bg') + '', borderRadius: '8px 8px 0 0', width: '100%', height: '8px'}} />
12+
</div>
13+
);
14+
};

src/json-crdt-peritext-ui/plugins/toolbar/config/NewLinkConfig.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,35 @@ import {BasicButtonClose} from 'nice-ui/lib/2-inline-block/BasicButton/BasicButt
1313
import {UrlDisplayCard} from '../cards/UrlDisplayCard';
1414
import {rule} from 'nano-theme';
1515
import {parseUrl} from '../../../web/util';
16+
import {ContextPaneHeaderSep} from '../../../components/ContextPaneHeaderSep';
1617
import type {SliceConfigState} from '../state/types';
1718

1819
const headerClass = rule({
20+
d: 'flex',
21+
ai: 'center',
1922
fz: '14px',
2023
us: 'none',
21-
pdb: '8px',
2224
});
2325

2426
const iconClass = rule({
25-
transform: 'scale(.8)',
2627
fz: '14px',
2728
w: '28px',
2829
h: '28px',
2930
bdrad: '6px',
31+
pd: '0',
32+
mr: '0 8px 0 0',
3033
d: 'flex',
3134
ai: 'center',
3235
jc: 'center',
3336
bg: 'rgba(0,0,0,.1)',
3437
o: .7,
35-
mr: '0 6px 0 4px',
38+
'&>div': {
39+
transform: 'scale(.9)',
40+
transformOrigin: 'center',
41+
d: 'flex',
42+
ai: 'center',
43+
jc: 'center',
44+
},
3645
});
3746

3847
export interface NewLinkConfigProps {
@@ -57,12 +66,12 @@ export const NewLinkConfig: React.FC<NewLinkConfigProps> = ({config, onSave}) =>
5766
e.preventDefault();
5867
onSave();
5968
}}>
60-
<ContextPaneHeader onCloseClick={() => toolbar.newSliceConfig.next(void 0)}>
69+
<ContextPaneHeader short onCloseClick={() => toolbar.newSliceConfig.next(void 0)}>
6170
<div className={headerClass}>
6271
{icon ? (
6372
<Flex style={{alignItems: 'center'}}>
6473
<div className={iconClass}>
65-
{icon}
74+
<div>{icon}</div>
6675
</div>
6776
{name}
6877
</Flex>
@@ -71,8 +80,7 @@ export const NewLinkConfig: React.FC<NewLinkConfigProps> = ({config, onSave}) =>
7180
)}
7281
</div>
7382
</ContextPaneHeader>
74-
75-
<div style={{background: '#fff', borderRadius: '8px 8px 0 0', margin: '-8px 0 -8px', width: '100%', height: '8px'}} />
83+
<ContextPaneHeaderSep />
7684

7785
<div style={{padding: '16px'}}>
7886
<CollaborativeInput str={href} input={(ref) => (

0 commit comments

Comments
 (0)