FormattedDate component can be hidden
This commit is contained in:
@@ -2,20 +2,22 @@
|
|||||||
interface Props {
|
interface Props {
|
||||||
className?: string;
|
className?: string;
|
||||||
date: Date | string;
|
date: Date | string;
|
||||||
|
hidden?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
let { className, date } = Astro.props;
|
let { className, date, hidden } = Astro.props;
|
||||||
if (typeof(date) === 'string') {
|
if (typeof(date) === 'string') {
|
||||||
date = new Date(date);
|
date = new Date(date);
|
||||||
}
|
}
|
||||||
---
|
const dateStr =
|
||||||
|
|
||||||
<time datetime={date.toISOString()} class={className ?? ''}>
|
|
||||||
{
|
|
||||||
date.toLocaleDateString('en-GB', {
|
date.toLocaleDateString('en-GB', {
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
month: 'long',
|
month: 'long',
|
||||||
day: 'numeric',
|
day: 'numeric',
|
||||||
})
|
});
|
||||||
}
|
---
|
||||||
</time>
|
|
||||||
|
{ hidden
|
||||||
|
? <time datetime={date.toISOString()} class={className ?? ''} hidden>{dateStr}</time>
|
||||||
|
: <time datetime={date.toISOString()} class={className ?? ''}>{dateStr}</time>
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user