-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
252 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
apps/app/src/client/components/PageComment/LikeButtons.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@use '@growi/core-styles/scss/bootstrap/init' as bs; | ||
@use '@growi/ui/scss/atoms/btn-muted'; | ||
@use './button-styles'; | ||
|
||
.btn-group-like-for-comment :global { | ||
.btn-like-for-comment { | ||
@extend %btn-basis; | ||
} | ||
.btn-like-for-comment.toggle-btn-like { | ||
padding-right: 3px; | ||
} | ||
.total-counts { | ||
@extend %btn-total-counts-basis; | ||
|
||
padding-left: 5px; | ||
} | ||
} | ||
|
||
// == Colors | ||
.btn-group-like-for-comment :global { | ||
.btn-like-for-comment { | ||
@include btn-muted.colorize(bs.$blue); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
apps/app/src/client/components/PageComment/LikeButtons.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import type { FC } from 'react'; | ||
import React, { useState, useCallback } from 'react'; | ||
|
||
import type { IUser } from '@growi/core'; | ||
import { useTranslation } from 'next-i18next'; | ||
import { UncontrolledTooltip, Popover, PopoverBody } from 'reactstrap'; | ||
|
||
|
||
import UserPictureList from '../Common/UserPictureList'; | ||
|
||
import styles from './LikeButtons.module.scss'; | ||
import popoverStyles from './user-list-popover.module.scss'; | ||
|
||
type LikeButtonsProps = { | ||
|
||
sumOfLikers: number, | ||
likers: IUser[], | ||
commentId: string, | ||
|
||
isGuestUser?: boolean, | ||
isLiked?: boolean, | ||
onLikeClicked?: ()=>void, | ||
} | ||
|
||
const LikeButtons: FC<LikeButtonsProps> = (props: LikeButtonsProps) => { | ||
const { t } = useTranslation(); | ||
|
||
const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
|
||
const togglePopover = () => { | ||
setIsPopoverOpen(!isPopoverOpen); | ||
}; | ||
|
||
const { | ||
isGuestUser, isLiked, sumOfLikers, onLikeClicked, commentId, | ||
} = props; | ||
|
||
const getTooltipMessage = useCallback(() => { | ||
|
||
if (isLiked) { | ||
return 'tooltip.cancel_like'; | ||
} | ||
return 'tooltip.like'; | ||
}, [isLiked]); | ||
|
||
return ( | ||
<div className={`btn-group btn-group-like-for-comment ${styles['btn-group-like-for-comment']}`} role="group" aria-label="Like buttons for comment"> | ||
<button | ||
type="button" | ||
id={`like-button-${commentId}`} | ||
onClick={onLikeClicked} | ||
className={`btn btn-like-for-comment toggle-btn-like | ||
${isLiked ? 'active' : ''} ${isGuestUser ? 'disabled' : ''}`} | ||
> | ||
<span className={`material-symbols-outlined ${isLiked ? 'fill' : ''}`}>favorite</span> | ||
</button> | ||
|
||
<UncontrolledTooltip data-testid={`like-button-tooltip-${commentId}`} target={`like-button-${commentId}`} autohide={false} fade={false}> | ||
{t(getTooltipMessage())} | ||
</UncontrolledTooltip> | ||
|
||
<button | ||
type="button" | ||
id={`co-total-likes-${commentId}`} | ||
className={`btn btn-like-for-comment | ||
total-counts ${isLiked ? 'active' : ''}`} | ||
> | ||
{sumOfLikers} | ||
</button> | ||
<Popover placement="bottom" isOpen={isPopoverOpen} target={`co-total-likes-${commentId}`} toggle={togglePopover} trigger="legacy"> | ||
<PopoverBody className={`user-list-popover ${popoverStyles['user-list-popover']}`}> | ||
<div className="px-2 text-end user-list-content text-truncate text-muted"> | ||
{props.likers?.length ? <UserPictureList users={props.likers} /> : t('No users have liked this yet.')} | ||
</div> | ||
</PopoverBody> | ||
</Popover> | ||
</div> | ||
); | ||
|
||
}; | ||
|
||
export default LikeButtons; |
17 changes: 17 additions & 0 deletions
17
apps/app/src/client/components/PageComment/_button-styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@use '@growi/core-styles/scss/bootstrap/init' as bs; | ||
|
||
%btn-basis { | ||
--bs-btn-padding-x: 6px; | ||
--bs-btn-padding-y: 6px; | ||
--bs-btn-line-height: 1em; | ||
--bs-btn-border-width: 0; | ||
--bs-btn-box-shadow: none; | ||
} | ||
|
||
%btn-total-counts-basis { | ||
--bs-btn-font-size: 13px; | ||
} | ||
|
||
%text-total-counts-basis { | ||
font-size: 13px; | ||
} |
5 changes: 5 additions & 0 deletions
5
apps/app/src/client/components/PageComment/user-list-popover.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@use '@growi/ui/scss/molecules/user-list-popover'; | ||
|
||
.user-list-popover :global { | ||
@extend %user-list-popover | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters