Skip to content

Commit 0b1bb51

Browse files
committed
feat(json-crdt-peritext-ui): 🎸 make delete button locked initially
1 parent 1ff587a commit 0b1bb51

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as React from 'react';
2+
import BasicButton from 'nice-ui/lib/2-inline-block/BasicButton';
3+
import {Iconista} from 'nice-ui/lib/icons/Iconista';
4+
import {BasicTooltip} from 'nice-ui/lib/4-card/BasicTooltip';
5+
import {useT} from 'use-t';
6+
7+
export interface SoftLockedDeleteButtonProps {
8+
onDelete: () => void;
9+
}
10+
11+
export const SoftLockedDeleteButton: React.FC<SoftLockedDeleteButtonProps> = ({onDelete}) => {
12+
const [t] = useT();
13+
const [locked, setLocked] = React.useState(true);
14+
15+
return (
16+
<BasicTooltip renderTooltip={() => locked ? t('Unlock delete') : t('Delete')}>
17+
<BasicButton size={32} rounder onClick={() => {
18+
if (locked) {
19+
setLocked(false);
20+
return;
21+
}
22+
onDelete();
23+
}}>
24+
<Iconista set={'lucide'} icon={'trash'} width={16} height={16} style={{opacity: locked ? .5 : 1}} />
25+
</BasicButton>
26+
</BasicTooltip>
27+
);
28+
};

src/json-crdt-peritext-ui/plugins/toolbar/formatting/FormattingsManagePane/FormattingDisplay.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {FormattingPane} from '../FormattingPane';
1616
import {ContextSep} from 'nice-ui/lib/4-card/ContextMenu';
1717
import {ButtonSeparator} from '../../../../components/ButtonSeparator';
1818
import {FormattingEditForm} from './FormattingEditForm';
19+
import {SoftLockedDeleteButton} from '../../components/SoftLockedDeleteButton';
1920

2021
export interface FormattingDisplayProps {
2122
formatting: SavedFormatting;
@@ -46,17 +47,13 @@ export const FormattingDisplay: React.FC<FormattingDisplayProps> = ({formatting,
4647
</Flex>
4748
) : (
4849
<Flex style={{justifyContent: 'flex-end', alignItems: 'center'}}>
49-
<BasicTooltip renderTooltip={() => t('Delete')}>
50-
<BasicButton size={32} rounder onClick={() => {
51-
surface.events.et.format({
52-
at: formatting.range,
53-
action: 'del',
54-
});
55-
onClose?.();
56-
}}>
57-
<Iconista set={'lucide'} icon={'trash'} width={16} height={16} />
58-
</BasicButton>
59-
</BasicTooltip>
50+
<SoftLockedDeleteButton onDelete={() => {
51+
surface.events.et.format({
52+
at: formatting.range,
53+
action: 'del',
54+
});
55+
onClose?.();
56+
}} />
6057
<Space horizontal size={-2} />
6158
<ButtonSeparator />
6259
<Space horizontal size={-2} />

0 commit comments

Comments
 (0)