@@ -12,62 +12,20 @@ import { CheckIcon } from 'lib/icons/Check.js'
1212import { CloseIcon } from 'lib/icons/Close.js'
1313import { EditIcon } from 'lib/icons/Edit.js'
1414
15- export type SeamDeviceNameProps = {
15+ type EditableDeviceNameProps = {
1616 onEdit ?: ( newName : string ) => void
1717 editable ?: boolean
1818 tagName ?: string
1919 value : string
2020} & HTMLAttributes < HTMLElement >
2121
22- function IconButton (
23- props : PropsWithChildren < HTMLAttributes < HTMLButtonElement > >
24- ) : JSX . Element {
25- return (
26- < button
27- { ...props }
28- className = { classNames (
29- 'seam-editable-device-name-icon-button' ,
30- props . className
31- ) }
32- >
33- { props . children }
34- </ button >
35- )
36- }
37-
38- const fixName = ( name : string ) : string => {
39- return name . replace ( / \s + / g, ' ' ) . trim ( )
40- }
41-
42- type Result = { type : 'success' } | { type : 'error' ; message : string }
43-
44- const isValidName = ( name : string ) : Result => {
45- if ( name . length < 2 ) {
46- return {
47- type : 'error' ,
48- message : 'Name must be at least 2 characters long' ,
49- }
50- }
51-
52- if ( name . length > 64 ) {
53- return {
54- type : 'error' ,
55- message : 'Name must be at most 64 characters long' ,
56- }
57- }
58-
59- return {
60- type : 'success' ,
61- } as const
62- }
63-
64- export function SeamEditableDeviceName ( {
22+ export function EditableDeviceName ( {
6523 onEdit,
6624 editable = true ,
6725 tagName,
6826 value,
6927 ...props
70- } : SeamDeviceNameProps ) : JSX . Element {
28+ } : EditableDeviceNameProps ) : JSX . Element {
7129 const [ editing , setEditing ] = useState ( false )
7230 const [ errorText , setErrorText ] = useState < null | string > ( null )
7331 const [ currentValue , setCurrentValue ] = useState ( value )
@@ -206,3 +164,50 @@ function ActionButtons(props: ActionButtonsProps): JSX.Element {
206164 </ IconButton >
207165 )
208166}
167+
168+ function IconButton (
169+ props : PropsWithChildren < HTMLAttributes < HTMLButtonElement > >
170+ ) : JSX . Element {
171+ return (
172+ < button
173+ { ...props }
174+ className = { classNames (
175+ 'seam-editable-device-name-icon-button' ,
176+ props . className
177+ ) }
178+ >
179+ { props . children }
180+ </ button >
181+ )
182+ }
183+
184+ const fixName = ( name : string ) : string => {
185+ return name . replace ( / \s + / g, ' ' ) . trim ( )
186+ }
187+
188+ type Result =
189+ | { type : 'success' }
190+ | {
191+ type : 'error'
192+ message : string
193+ }
194+
195+ const isValidName = ( name : string ) : Result => {
196+ if ( name . length < 2 ) {
197+ return {
198+ type : 'error' ,
199+ message : 'Name must be at least 2 characters long' ,
200+ }
201+ }
202+
203+ if ( name . length > 64 ) {
204+ return {
205+ type : 'error' ,
206+ message : 'Name must be at most 64 characters long' ,
207+ }
208+ }
209+
210+ return {
211+ type : 'success' ,
212+ } as const
213+ }
0 commit comments