Skip to content

Commit 893413a

Browse files
committed
Allow some customization in AnnotationTimestamps edited text
1 parent e5d277c commit 893413a

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/components/AnnotationTimestamps.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,29 @@ import {
44
formatRelativeDate,
55
formatDateTime,
66
} from '@hypothesis/frontend-shared';
7+
import classnames from 'classnames';
78
import { useEffect, useMemo, useState } from 'preact/hooks';
89

10+
/**
11+
* `subtle`: Small text with inherited font weight.
12+
* `prominent`: Bold text with inherited font size.
13+
*/
14+
export type EditedTimestampVariant = 'subtle' | 'prominent';
15+
916
export type AnnotationTimestampsProps = {
1017
annotationCreated: string;
1118
annotationUpdated: string;
1219
annotationURL?: string;
13-
/** Display a relative last-updated timestamp */
14-
withEditedTimestamp?: boolean;
20+
21+
/**
22+
* Whether a relative last-updated timestamp should be displayed or not.
23+
* - `false`: do not display edited timestamp
24+
* - `true`: display using default variant, `subtle`
25+
* - {variant_name}: display using specified variant
26+
*
27+
* Defaults to `false`.
28+
*/
29+
withEditedTimestamp?: boolean | EditedTimestampVariant;
1530
};
1631

1732
/**
@@ -72,13 +87,19 @@ export default function AnnotationTimestamps({
7287
updated && updated.relative !== created.relative
7388
? `edited ${updated.relative}`
7489
: 'edited';
90+
const editedTimestampVariant: EditedTimestampVariant =
91+
typeof withEditedTimestamp === 'string' ? withEditedTimestamp : 'subtle';
7592

7693
return (
7794
<div>
7895
{withEditedTimestamp && (
7996
<span
80-
className="text-color-text-light text-xs italic"
97+
className={classnames('text-color-text-light italic', {
98+
'text-xs': editedTimestampVariant === 'subtle',
99+
'font-bold': editedTimestampVariant === 'prominent',
100+
})}
81101
data-testid="timestamp-edited"
102+
data-variant={editedTimestampVariant}
82103
title={updated.absolute}
83104
>
84105
({editedString}){' '}

src/components/test/AnnotationTimestamps-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ describe('AnnotationTimestamps', () => {
7070
assert.include(editedTimestamp.text(), '(edited another fuzzy string)');
7171
});
7272

73+
[
74+
{ withEditedTimestamp: true, expectedVariant: 'subtle' },
75+
{ withEditedTimestamp: 'subtle', expectedVariant: 'subtle' },
76+
{ withEditedTimestamp: 'prominent', expectedVariant: 'prominent' },
77+
].forEach(({ withEditedTimestamp, expectedVariant }) => {
78+
it('renders edited timestamp with expected variant', () => {
79+
fakeFormatRelativeDate.onCall(1).returns('another fuzzy string');
80+
81+
const wrapper = createComponent({ withEditedTimestamp });
82+
83+
const editedTimestamp = wrapper
84+
.find('[data-testid="timestamp-edited"]')
85+
.getDOMNode();
86+
assert.equal(editedTimestamp.dataset.variant, expectedVariant);
87+
});
88+
});
89+
7390
it('does not render edited relative date if equivalent to created relative date', () => {
7491
fakeFormatRelativeDate.returns('equivalent fuzzy strings');
7592

0 commit comments

Comments
 (0)