Skip to content

Commit 7c19024

Browse files
committed
feat: control input style
1 parent 85a4ecd commit 7c19024

File tree

8 files changed

+30
-27
lines changed

8 files changed

+30
-27
lines changed

apps/book-server/src/services/BookBuildService/index.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export class BookBuildService implements Service {
116116
urlSlug: book.url_slug,
117117
}),
118118
)
119+
119120
fs.writeFileSync(`${dest}/theme.config.tsx`, themeConfigTemplate({ title: book.title }))
120121

121122
const buildStdout = await this.buildTsToJs(dest)

packages/nextra-editor/src/components/sidebar/file.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { PageItem, SortableItem } from '@/nextra/normalize-pages'
66

77
import { useRouter } from 'next/router'
88
import { useMenu } from '@/contexts'
9-
import AddInputs from './sidebar-controller/add-inputs'
9+
import AddInputs from './sidebar-controller/control-input'
1010
import { classes } from './style'
1111
import { MenuItemProps } from './menu'
1212
import { useDndTree } from './sortable-tree'
@@ -21,8 +21,7 @@ export function File({ item, ...props }: FileProps): ReactElement {
2121
const route = useFSRoute()
2222
const router = useRouter()
2323

24-
const { setDraggableNodeRef, setDroppableNodeRef, attributes, isDragTarget, listeners } =
25-
props
24+
const { setDraggableNodeRef, setDroppableNodeRef, attributes, isDragTarget, listeners } = props
2625

2726
// It is possible that the item doesn't have any route - for example an external link.
2827
const active = !isDragTarget && item.route && [route, route + '/'].includes(item.route + '/')
@@ -40,11 +39,7 @@ export function File({ item, ...props }: FileProps): ReactElement {
4039
return (
4140
<>
4241
<li
43-
className={cn(
44-
classes.list,
45-
{ active },
46-
isDragTarget && classes.ghost,
47-
)}
42+
className={cn(classes.list, { active }, isDragTarget && classes.ghost)}
4843
ref={setDroppableNodeRef}
4944
>
5045
<div

packages/nextra-editor/src/components/sidebar/sidebar-controller/add-icons.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ const AddIcons = ({ className, type }: Props) => {
113113
}
114114
}
115115
}
116+
116117
addNewFolderToItem(coppeidPageMap)
117118
}
118119

packages/nextra-editor/src/components/sidebar/sidebar-controller/add-inputs.tsx renamed to packages/nextra-editor/src/components/sidebar/sidebar-controller/control-input.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Props = {
1212
type: ActionType
1313
}
1414

15-
function AddInputs({ type }: Props): ReactElement {
15+
function ControlInput({ type }: Props): ReactElement {
1616
const sidebar = useSidebar()
1717
const [title, setTitle] = useState('')
1818

@@ -65,20 +65,23 @@ function AddInputs({ type }: Props): ReactElement {
6565
return (
6666
<div
6767
ref={ref}
68-
className={cn('nx-flex nx-w-full nx-items-center nx-px-2 nx-py-1.5 [word-break:break-word]')}
68+
className={cn(
69+
'nx-flex nx-w-full nx-items-center nx-px-2 nx-py-1.5 [word-break:break-word]',
70+
'nx-transition-colors',
71+
)}
6972
onClick={onClick}
7073
>
71-
<span
72-
className={cn(
73-
'nx-text-gray-600 nx-transition-colors hover:nx-bg-gray-100 hover:nx-text-gray-900 dark:nx-text-gray-400 dark:hover:nx-bg-primary-100/5 dark:hover:nx-text-gray-50',
74-
)}
75-
>
74+
<span>
7675
{type === 'folder' && <EmptyFolderIcon />}
7776
{type === 'page' && <EmptyFileIcon />}
7877
{type === 'separator' && <SeparatorIcon />}
7978
</span>
8079
<input
81-
className={cn('focus-visible:box-shadow-none nx-ml-1 nx-w-full nx-bg-red-100 nx-px-1')}
80+
className={cn(
81+
'focus-visible:box-shadow-none nx-ml-1 nx-w-full nx-px-1 nx-py-0.5',
82+
'nx-bg-gray-100 nx-text-gray-600 ',
83+
'dark:nx-bg-primary-100/5 dark:nx-text-gray-400',
84+
)}
8285
value={title}
8386
onChange={onChange}
8487
autoFocus={true}
@@ -91,4 +94,4 @@ function AddInputs({ type }: Props): ReactElement {
9194
)
9295
}
9396

94-
export default AddInputs
97+
export default ControlInput

packages/nextra-editor/src/components/sidebar/sortable-tree/sortable-item.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ArrowRightIcon } from '@/nextra/icons'
77
import { useDndTree } from '.'
88
import { classes, indentStyle } from '../style'
99
import type { SortableItemProps } from './types'
10-
import AddInputs from '../sidebar-controller/add-inputs'
10+
import ControlInput from '../sidebar-controller/control-input'
1111

1212
export const SortableItem = forwardRef<HTMLDivElement, SortableItemProps>((props, ref) => {
1313
const { isDragging, overItem, setOverItem } = useDndTree()
@@ -30,10 +30,10 @@ export const SortableItem = forwardRef<HTMLDivElement, SortableItemProps>((props
3030
transform,
3131
} = props
3232

33-
const isAddAction = ['newPage', 'newFolder', 'newSeparator'].includes(item.type)
33+
const isControlAction = ['newPage', 'newFolder', 'newSeparator'].includes(item.type)
3434

3535
const active =
36-
!isDragging && !isAddAction && !isGhost && [route, `${route}/`].includes(item.route + '/')
36+
!isDragging && !isControlAction && !isGhost && [route, `${route}/`].includes(item.route + '/')
3737
// const isLink = 'withIndexPage' in item && item.withIndexPage
3838

3939
useEffect(() => {
@@ -68,12 +68,13 @@ export const SortableItem = forwardRef<HTMLDivElement, SortableItemProps>((props
6868
{...handleProps}
6969
className={cn(
7070
'nx-flex nx-w-full nx-items-center nx-justify-between nx-gap-2 nx-text-left',
71-
isSeparator && 'cursor-default',
71+
isSeparator && 'nx-cursor-default',
7272
isSeparator ? classes.separator : classes.link,
7373
active ? classes.active : classes.inactive,
7474
!isDragging && !active && classes.inactiveBgColor,
7575
isGhost && classes.ghost,
7676
clone && classes.clone,
77+
isControlAction && '!nx-pr-0',
7778
)}
7879
onClick={() => {
7980
if (isGhost) return
@@ -86,12 +87,12 @@ export const SortableItem = forwardRef<HTMLDivElement, SortableItemProps>((props
8687
}
8788

8889
setFocusedItem(item)
89-
if (isAddAction) return
90+
if (isControlAction) return
9091
router.push(item.route, item.route, { shallow: true })
9192
}}
9293
>
93-
{isAddAction ? (
94-
<AddInputs type={addActionMap[item.type]} />
94+
{isControlAction ? (
95+
<ControlInput type={addActionMap[item.type]} />
9596
) : (
9697
<>
9798
<div className={cn('nx-w-full nx-px-2 nx-py-1.5 [word-break:keep-all]')}>

packages/nextra-editor/src/contexts/sidebar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ export const SidebarProvider = ({ children }: { children: ReactNode }): ReactEle
8181
})
8282

8383
const reset = (originSortableItem: SortableItem[]) => {
84-
setSortableItems(originSortableItem)
84+
if (originSortableItem.length > 0) {
85+
setSortableItems(originSortableItem)
86+
}
8587
setActionActive(false)
8688
setActionComplete(false)
8789
setActionType('')

packages/nextra-editor/src/hooks/use-url-slug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const useUrlSlug = () => {
88
const pageUrlSlug = Array.isArray(query.pageUrlSlug) ? `/${query.pageUrlSlug.join('/')}` : '/'
99
const bookUrlSlug = `/${query.username}/${query.bookTitle}`
1010
const username = `/${query.username}`
11-
const fullUrlSlug = pageUrlSlug === '/' ? `${bookUrlSlug}` : `${bookUrlSlug}/${pageUrlSlug}`
11+
const fullUrlSlug = pageUrlSlug === '/' ? `${bookUrlSlug}` : `${bookUrlSlug}${pageUrlSlug}`
1212

1313
return { bookUrlSlug, pageUrlSlug, fullUrlSlug, username }
1414
}

packages/nextra-editor/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)