1.1 KB43 lines
Blame
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8import type {Placement} from 'isl-components/Tooltip';
9
10import {Tooltip} from 'isl-components/Tooltip';
11import {t} from './i18n';
12
13type CommitTitleProps = React.HTMLAttributes<HTMLDivElement> & {
14 commitMessage: string;
15 tooltipPlacement?: Placement;
16};
17
18/** One line commit message with tooltip about full message. */
19export function CommitTitle(props: CommitTitleProps) {
20 const {commitMessage, tooltipPlacement, ...restProps} = props;
21 const title = commitMessage.split('\n')[0];
22 const trimmed = commitMessage.trim();
23 if (trimmed === '') {
24 return null;
25 }
26
27 const divElement = <div {...restProps}>{title}</div>;
28 if (title === trimmed) {
29 // No need to use a tooltip.
30 return divElement;
31 } else {
32 return (
33 <Tooltip placement={tooltipPlacement} title={title}>
34 {divElement}
35 </Tooltip>
36 );
37 }
38}
39
40export function temporaryCommitTitle() {
41 return t('Temporary Commit at $time', {replace: {$time: new Date().toLocaleString()}});
42}
43