Skip to content

Commit

Permalink
add data-readonly attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
AsaiToshiya authored and fiatjaf committed Aug 29, 2024
1 parent 97d5707 commit a0f7358
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ You can pass special attributes to that `<script>` tag, such as
- `data-skip="/"`, an **optional** path of your website to skip rendering the widgets in. The default is `"/"`.
- `data-owner="reference"`, an **optional** string with the post owner's public key in hex, `npub1` or `nprofile1` format.
- `data-placeholder="reference"`, an **optional** string with the placeholder for the textarea
- `data-readonly="true"`, an **optional** boolean to turn off new comments

Custom CSS variables for styling:

Expand Down
2 changes: 2 additions & 0 deletions embeddable/embed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const skip = script.dataset.skip || '/'
const owner = script.dataset.owner || ''
const customBase = script.dataset.customBase
const placeholder = script.dataset.placeholder || ''
const readonly = script.dataset.readonly === 'true'

const container = document.createElement('div')
container.style.width = '100%'
Expand All @@ -24,5 +25,6 @@ root.render(
relays={relays}
owner={owner}
placeholder={placeholder}
readonly={readonly}
/>
)
6 changes: 4 additions & 2 deletions src/NoComment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export function NoComment({
owner,
skip,
customBase,
placeholder
placeholder,
readonly
}) {
let customBaseTag = useMemo(() => {
if (customBase) {
Expand Down Expand Up @@ -147,7 +148,7 @@ export function NoComment({

return (
<Container>
{editor()}
{!readonly && editor()}

<div>
{threads?.map(thread => (
Expand All @@ -157,6 +158,7 @@ export function NoComment({
metadata={metadata}
relays={chosenRelays}
replyForm={editor}
readonly={readonly}
/>
))}
</div>
Expand Down
6 changes: 4 additions & 2 deletions src/Thread.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export default function Thread({
metadata,
relays,
replyForm,
level = 0
level = 0,
readonly
}) {
const [expanded, setExpanded] = useState(false)
return (
Expand All @@ -48,7 +49,7 @@ export default function Thread({
>
{dayjs(thread.created_at * 1000).from(new Date())}
</CommentDate>
<ReplyButton onClick={() => setExpanded(!expanded)} />
{!readonly && <ReplyButton onClick={() => setExpanded(!expanded)} />}
</div>
<CommentContent>{thread.content}</CommentContent>
{expanded && <ReplyWrap>{replyForm(thread.id)}</ReplyWrap>}
Expand All @@ -65,6 +66,7 @@ export default function Thread({
relays={relays}
level={level + 1}
replyForm={replyForm}
readonly={readonly}
/>
))}
</div>
Expand Down

0 comments on commit a0f7358

Please sign in to comment.