Skip to content

Commit 53b8b91

Browse files
committed
fix: gallery and text indent style
Signed-off-by: Innei <[email protected]>
1 parent cb116f9 commit 53b8b91

File tree

5 files changed

+51
-14
lines changed

5 files changed

+51
-14
lines changed

src/app/(app)/notes/[id]/page.module.css

+5-7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
margin-bottom: 4rem;
1313
}
1414

15-
ul .indent,
16-
.paragraph .indent {
15+
ul span,
16+
.paragraph span {
1717
border-bottom: 1px solid;
1818

1919
/* @apply border-accent/20 dark:border-accent/20; */
@@ -29,7 +29,7 @@
2929
display: none !important;
3030
}
3131
& {
32-
.paragraph > span.indent {
32+
.paragraph > span {
3333
margin-left: 0 !important;
3434
}
3535

@@ -71,10 +71,8 @@
7171
}
7272
}
7373

74-
.paragraph:not(:nth-child(1)) > span.indent {
75-
&:nth-child(1) {
76-
margin-left: 2rem;
77-
}
74+
.paragraph:not(:nth-child(1)) {
75+
text-indent: 2rem;
7876
}
7977

8078
main {

src/app/(app)/notes/[id]/pageExtra.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,7 @@ export const NoteHeaderMetaInfoSetting = () => {
138138
const MarkdownRenderers: { [name: string]: Partial<MarkdownToJSX.Rule> } = {
139139
text: {
140140
react(node, _, state) {
141-
return (
142-
<span className="indent" key={state?.key}>
143-
{node.content}
144-
</span>
145-
)
141+
return <span key={state?.key}>{node.content}</span>
146142
},
147143
},
148144
}

src/components/ui/gallery/Gallery.tsx

+42
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import { throttle } from '~/lib/lodash'
1010
import { useMarkdownImageRecord } from '~/providers/article/MarkdownImageRecordProvider'
1111
import { useWrappedElementSize } from '~/providers/shared/WrappedElementProvider'
1212

13+
import { MotionButtonBase } from '../button'
1314
import { FixedZoomedImage } from '../image'
15+
import { MarkdownImage } from '../markdown/renderers/image'
1416
import styles from './Gallery.module.css'
1517

1618
const IMAGE_CONTAINER_MARGIN_INSET = 60
@@ -139,6 +141,14 @@ export const Gallery: FC<GalleryProps> = (props) => {
139141
}
140142
}, [])
141143

144+
if (!images.length) {
145+
return null
146+
}
147+
if (images.length === 1) {
148+
const image = images[0]
149+
return <MarkdownImage src={image.url} alt={image.footnote} />
150+
}
151+
142152
return (
143153
<div
144154
className={clsx('w-full', 'relative', styles['root'])}
@@ -162,6 +172,38 @@ export const Gallery: FC<GalleryProps> = (props) => {
162172
})}
163173
</div>
164174

175+
{currentIndex > 0 && (
176+
<div className="pointer-events-none absolute inset-y-0 left-2 flex items-center [&_*]:duration-200">
177+
<MotionButtonBase
178+
onClick={() => {
179+
if (!containerRef) {
180+
return
181+
}
182+
const index = currentIndex - 1
183+
handleScrollTo(index)
184+
}}
185+
className="border-border pointer-events-auto flex size-6 rounded-full border bg-base-100 p-1 opacity-80 center hover:opacity-100"
186+
>
187+
<i className="icon-[mingcute--left-fill]" />
188+
</MotionButtonBase>
189+
</div>
190+
)}
191+
{currentIndex < images.length - 1 && (
192+
<div className="pointer-events-none absolute inset-y-0 right-2 flex items-center [&_*]:duration-200">
193+
<MotionButtonBase
194+
onClick={() => {
195+
if (!containerRef) {
196+
return
197+
}
198+
const index = currentIndex + 1
199+
handleScrollTo(index)
200+
}}
201+
className="border-border pointer-events-auto flex size-6 rounded-full border bg-base-100 p-1 opacity-80 center hover:opacity-100"
202+
>
203+
<i className="icon-[mingcute--right-fill]" />
204+
</MotionButtonBase>
205+
</div>
206+
)}
165207
<div className={clsx(styles['indicator'], 'space-x-2')}>
166208
{Array.from({
167209
length: images.length,

src/components/ui/markdown/renderers/image.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ import {
1818
import { Divider } from '../../divider/Divider'
1919
import { FixedZoomedImage } from '../../image/ZoomedImage'
2020

21-
export const MarkdownImage = (props: any) => {
21+
export const MarkdownImage = (props: { src: string; alt?: string }) => {
2222
const { src, alt } = props
2323
const nextProps = {
2424
...props,
2525
}
2626
nextProps.alt = alt?.replace(/^[¡!]/, '')
2727
const { w } = useWrappedElementSize()
2828

29-
const ext = src.split('.').pop()
29+
const ext = src.split('.').pop()!
3030
if (isVideoExt(ext)) {
3131
const figcaption = alt?.replace(/^[¡!]/, '')
3232
return (

storybook/vite.config.mts

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default defineConfig({
3737
__ROOT__: `"${__dirname}"`,
3838
__COMPONENT_ROOT__: `"${resolve(__dirname, '..')}"`,
3939
'process.env': { ...env },
40+
__dirname: `"${__dirname}"`,
4041
},
4142
base: '',
4243
resolve: {

0 commit comments

Comments
 (0)