UNPKG

@wordpress/editor

Version:
71 lines (70 loc) 2.69 kB
/** * WordPress dependencies */ import { __experimentalVStack as VStack } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { dateI18n, getSettings as getDateSettings } from '@wordpress/date'; import { useEntityProp, store as coreStore } from '@wordpress/core-data'; import { useSelect } from '@wordpress/data'; import { store as blockEditorStore } from '@wordpress/block-editor'; /** * Render author information for a comment. * * @param {Object} props - Component properties. * @param {string} props.avatar - URL of the author's avatar. * @param {string} props.name - Name of the author. * @param {string} props.date - Date of the comment. * * @return {React.ReactNode} The JSX element representing the author's information. */ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; function CommentAuthorInfo({ avatar, name, date }) { const dateSettings = getDateSettings(); const [dateTimeFormat = dateSettings.formats.time] = useEntityProp('root', 'site', 'time_format'); const { currentUserAvatar, currentUserName } = useSelect(select => { var _userData$avatar_urls; const userData = select(coreStore).getCurrentUser(); const { getSettings } = select(blockEditorStore); const { __experimentalDiscussionSettings } = getSettings(); const defaultAvatar = __experimentalDiscussionSettings?.avatarURL; return { currentUserAvatar: (_userData$avatar_urls = userData?.avatar_urls[48]) !== null && _userData$avatar_urls !== void 0 ? _userData$avatar_urls : defaultAvatar, currentUserName: userData?.name }; }, []); const currentDate = new Date(); return /*#__PURE__*/_jsxs(_Fragment, { children: [/*#__PURE__*/_jsx("img", { src: avatar !== null && avatar !== void 0 ? avatar : currentUserAvatar, className: "editor-collab-sidebar-panel__user-avatar" // translators: alt text for user avatar image , alt: __('User avatar'), width: 32, height: 32 }), /*#__PURE__*/_jsxs(VStack, { spacing: "0", children: [/*#__PURE__*/_jsx("span", { className: "editor-collab-sidebar-panel__user-name", children: name !== null && name !== void 0 ? name : currentUserName }), /*#__PURE__*/_jsx("time", { dateTime: dateI18n('c', date !== null && date !== void 0 ? date : currentDate), className: "editor-collab-sidebar-panel__user-time", children: dateI18n(dateTimeFormat, date !== null && date !== void 0 ? date : currentDate) })] })] }); } export default CommentAuthorInfo; //# sourceMappingURL=comment-author-info.js.map