Skip to content

Commit

Permalink
fix: use <Button> component for user interaction
Browse files Browse the repository at this point in the history
We have an existing button component which should
be used to handle user interactions.

The Button element uses semantically correct
HTML elements which improves usability and accessibility.

If the visual styling is a blocker then we can introduce
a new variant, however visual consistency of clickable elements
is a helpful design convention.

Bonus! This removes usage of react-icons within the core
platform and moves knowledge of icons out to the component
library layer.
  • Loading branch information
thisislawatts committed Mar 20, 2022
1 parent 0e80d88 commit 6dae56c
Showing 1 changed file with 32 additions and 36 deletions.
68 changes: 32 additions & 36 deletions src/components/Comment/Comment.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { createRef, useEffect, useState } from 'react'
import { FaTrash, FaRegEdit } from 'react-icons/fa'
import { Flex } from 'rebass/styled-components'
import { IComment } from 'src/models'
import { CommentHeader } from './CommentHeader'
Expand All @@ -26,7 +25,7 @@ export const Comment: React.FC<IProps> = ({
handleEdit,
...props
}) => {
const textRef = createRef<any>();
const textRef = createRef<any>()
const [showEditModal, setShowEditModal] = useState(false)
const [textHeight, setTextHeight] = useState(0)
const [isShowMore, setShowMore] = useState(false)
Expand All @@ -47,7 +46,7 @@ export const Comment: React.FC<IProps> = ({
}, [])

const showMore = () => {
setShowMore(!isShowMore);
setShowMore(!isShowMore)
}

return (
Expand All @@ -61,52 +60,49 @@ export const Comment: React.FC<IProps> = ({
>
<CommentHeader {...props} />
<Text
my={2}
style={{
my={2}
style={{
whiteSpace: 'pre-wrap',
wordBreak: 'break-word',
overflow: "hidden",
lineHeight: "1em",
maxHeight: isShowMore ? "max-content" : "10em",
overflow: 'hidden',
lineHeight: '1em',
maxHeight: isShowMore ? 'max-content' : '10em',
}}
ref={textRef}
>
{text}
</Text>
{textHeight > 160 &&
<a
onClick={showMore}
style={{
color: "gray",
cursor: "pointer",
fontSize: "14px",
}}
>
{isShowMore ? 'Show less' : 'Show more'}
</a>
}
{textHeight > 160 && (
<a
onClick={showMore}
style={{
color: 'gray',
cursor: 'pointer',
fontSize: '14px',
}}
>
{isShowMore ? 'Show less' : 'Show more'}
</a>
)}
<Flex ml="auto">
<AuthWrapper roleRequired="admin" additionalAdmins={[_creatorId]}>
<Text
style={{
cursor: 'pointer',
}}
mr={2}
fontSize="12px"
<Button
variant={'outline'}
small={true}
icon={'edit'}
onClick={onEditRequest}
>
edit <FaRegEdit />
</Text>
<Text
style={{
cursor: 'pointer',
alignItems: 'center',
}}
fontSize="12px"
edit
</Button>
<Button
variant={'outline'}
small={true}
icon="delete"
onClick={onDelete}
ml={2}
>
delete <FaTrash color="red" />
</Text>
delete
</Button>
</AuthWrapper>
</Flex>

Expand Down

0 comments on commit 6dae56c

Please sign in to comment.