1- import {
2- properties ,
3- Resource ,
4- useCanWrite ,
5- useString ,
6- useTitle ,
7- } from '@tomic/react' ;
1+ import { Resource , useCanWrite , useTitle } from '@tomic/react' ;
82import React , { useEffect , useRef , useState } from 'react' ;
93import { useHotkeys } from 'react-hotkeys-hook' ;
104import { FaEdit } from 'react-icons/fa' ;
@@ -13,28 +7,26 @@ import styled, { css } from 'styled-components';
137export interface EditableTitleProps {
148 resource : Resource ;
159 /** Uses `name` by default */
16- propertyURL ?: string ;
1710 parentRef ?: React . RefObject < HTMLInputElement > ;
1811}
1912
13+ const opts = {
14+ commit : true ,
15+ validate : false ,
16+ } ;
17+
2018export function EditableTitle ( {
2119 resource,
22- propertyURL,
2320 parentRef,
2421 ...props
2522} : EditableTitleProps ) : JSX . Element {
26- propertyURL = propertyURL || properties . name ;
27- const [ text , setText ] = useString ( resource , propertyURL , {
28- commit : true ,
29- validate : false ,
30- } ) ;
23+ const [ text , setText ] = useTitle ( resource , Infinity , opts ) ;
3124 const [ isEditing , setIsEditing ] = useState ( false ) ;
3225
3326 const innerRef = useRef < HTMLInputElement > ( null ) ;
3427 const ref = parentRef || innerRef ;
3528
3629 const [ canEdit ] = useCanWrite ( resource ) ;
37- const [ starndardTitle ] = useTitle ( resource ) ;
3830
3931 useHotkeys (
4032 'enter' ,
@@ -48,7 +40,7 @@ export function EditableTitle({
4840 setIsEditing ( true ) ;
4941 }
5042
51- const placeholder = 'set a title' ;
43+ const placeholder = canEdit ? 'set a title' : 'Untitled ';
5244
5345 useEffect ( ( ) => {
5446 ref . current ?. focus ( ) ;
@@ -77,7 +69,7 @@ export function EditableTitle({
7769 subtle = { ! ! canEdit && ! text }
7870 >
7971 < >
80- { text ? text : canEdit ? placeholder : starndardTitle || 'Untitled' }
72+ { text || placeholder }
8173 { canEdit && < Icon /> }
8274 </ >
8375 </ Title >
@@ -86,7 +78,6 @@ export function EditableTitle({
8678
8779const TitleShared = css `
8880 line-height: 1.1;
89- width: 100%;
9081` ;
9182
9283interface TitleProps {
@@ -98,6 +89,7 @@ const Title = styled.h1<TitleProps>`
9889 ${ TitleShared }
9990 display: flex;
10091 align-items: center;
92+ gap: ${ p => p . theme . margin } rem;
10193 justify-content: space-between;
10294 cursor: pointer;
10395 cursor: ${ props => ( props . canEdit ? 'pointer' : 'initial' ) } ;
@@ -129,8 +121,7 @@ const TitleInput = styled.input`
129121
130122const Icon = styled ( FaEdit ) `
131123 opacity: 0;
132- margin-left: auto;
133-
124+ font-size: 0.8em;
134125 ${ Title } :hover & {
135126 opacity: 0.5;
136127
0 commit comments