Skip to content

Commit

Permalink
feat: updated lib export
Browse files Browse the repository at this point in the history
  • Loading branch information
ogheneovo12 committed Feb 26, 2024
1 parent 32c275d commit 24d52b3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 43 deletions.
45 changes: 2 additions & 43 deletions src/lib/components/DocumentEditor/document-editor.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,8 @@
import { Meta, StoryFn } from '@storybook/react'
import React from 'react'
import { Descendant } from 'slate'
import { DocumentEditor, DocumentEditorProps } from '.'
import { Meta } from '@storybook/react'
import { StoryFn } from '@storybook/react'
import { defaultDocumentFeatures, initialEditorValue } from '../DocumentEditor/defaultComponentFeatures'
import { Descendant } from 'slate'
import { component } from '../component-blocks'
import { useState, useEffect } from 'react'

function ImageUploadPreview({ defaultValue }: { defaultValue: any }) {
const [image, setImage] = useState(null) // To store the uploaded image
const [preview, setPreview] = useState<string | null>(defaultValue?.image?.url ?? '') // To store the URL of the preview image

// Update the preview when image state changes
useEffect(() => {
if (image) {
const reader = new FileReader()
reader.onloadend = () => {
setPreview(reader.result as string)
}
reader.readAsDataURL(image)
} else {
setPreview(null)
}
}, [image])

const handleImageChange = (e) => {
const file = e.target.files[0]
if (file && file.type.substr(0, 5) === 'image') {
setImage(file)
} else {
setImage(null)
}
}

return (
<div>
<input type="file" accept="image/*" onChange={handleImageChange} />
{preview ? (
<img src={preview} alt="Image preview" style={{ width: '100%', height: 'auto' }} />
) : (
<p>No image selected</p>
)}
</div>
)
}

// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
const meta: Meta<typeof DocumentEditor> = {
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './DocumentEditor'
export * from './DocumentEditor/defaultComponentFeatures'
export * from './component-blocks'

0 comments on commit 24d52b3

Please sign in to comment.